1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-09 17:00:32 +00:00

refactor isTv

This commit is contained in:
Thonsi 2023-06-18 18:24:32 +05:30 committed by GitHub
parent 3c87462203
commit ed21707afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.util; package org.schabi.newpipe.util;
import static android.content.Context.INPUT_SERVICE; import static android.content.Context.INPUT_SERVICE;
import static android.content.Context.UI_MODE_SERVICE;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.UiModeManager; import android.app.UiModeManager;
@ -57,8 +58,11 @@ public final class DeviceUtils {
final PackageManager pm = App.getApp().getPackageManager(); final PackageManager pm = App.getApp().getPackageManager();
// from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check // from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check
boolean isTv = ContextCompat.getSystemService(context, UiModeManager.class) @Nullable
.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION UiModeManager uiModeManager =
(UiModeManager) context.getApplicationContext().getSystemService(UI_MODE_SERVICE);
boolean isTv = uiModeManager != null
&& uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION
|| isFireTv() || isFireTv()
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK); || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);