From ed21707afba8fbcb1bf33659f26b9f28a4ec5c62 Mon Sep 17 00:00:00 2001 From: Thonsi <10291398+thonsi@users.noreply.github.com> Date: Sun, 18 Jun 2023 18:24:32 +0530 Subject: [PATCH] refactor isTv --- .../main/java/org/schabi/newpipe/util/DeviceUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java index f656c6144..a68a3e9f6 100644 --- a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.util; import static android.content.Context.INPUT_SERVICE; +import static android.content.Context.UI_MODE_SERVICE; import android.annotation.SuppressLint; import android.app.UiModeManager; @@ -57,8 +58,11 @@ public final class DeviceUtils { final PackageManager pm = App.getApp().getPackageManager(); // from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check - boolean isTv = ContextCompat.getSystemService(context, UiModeManager.class) - .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION + @Nullable + UiModeManager uiModeManager = + (UiModeManager) context.getApplicationContext().getSystemService(UI_MODE_SERVICE); + boolean isTv = uiModeManager != null + && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION || isFireTv() || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);