2019-02-19 14:57:49 +01:00
|
|
|
package org.schabi.newpipe.util;
|
2019-02-01 14:02:28 +01:00
|
|
|
|
2019-09-20 11:23:17 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2020-04-25 11:35:15 +02:00
|
|
|
import android.app.UiModeManager;
|
|
|
|
import android.content.Context;
|
2019-09-20 11:23:17 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2020-04-25 11:35:15 +02:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.BatteryManager;
|
2019-11-16 07:06:59 +01:00
|
|
|
import android.view.KeyEvent;
|
2020-04-25 11:35:15 +02:00
|
|
|
|
2019-02-01 14:02:28 +01:00
|
|
|
import org.schabi.newpipe.App;
|
|
|
|
|
2020-04-25 11:35:15 +02:00
|
|
|
import static android.content.Context.BATTERY_SERVICE;
|
|
|
|
import static android.content.Context.UI_MODE_SERVICE;
|
|
|
|
|
2020-04-11 03:25:05 +02:00
|
|
|
public final class AndroidTvUtils {
|
2020-04-11 04:03:22 +02:00
|
|
|
private static final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv";
|
|
|
|
|
2020-04-25 11:35:15 +02:00
|
|
|
private AndroidTvUtils() {
|
|
|
|
}
|
2020-04-11 03:25:05 +02:00
|
|
|
|
2019-09-20 11:23:17 +02:00
|
|
|
@SuppressLint("InlinedApi")
|
2020-04-25 11:35:15 +02:00
|
|
|
public static boolean isTv(final Context context) {
|
|
|
|
PackageManager pm = App.getApp().getPackageManager();
|
|
|
|
|
|
|
|
|
|
|
|
// from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check
|
|
|
|
boolean isAndroidTv = ((UiModeManager) context.getSystemService(UI_MODE_SERVICE))
|
|
|
|
.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
|
|
|
|
|
|
|
|
boolean isBatteryAbsent = ((BatteryManager) context.getSystemService(BATTERY_SERVICE))
|
|
|
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) == 0;
|
|
|
|
|
|
|
|
return isAndroidTv
|
|
|
|
|| pm.hasSystemFeature(AMAZON_FEATURE_FIRE_TV)
|
|
|
|
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
|
|
|
|| pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)
|
2019-09-20 11:23:17 +02:00
|
|
|
|
2020-04-25 11:35:15 +02:00
|
|
|
//from https://stackoverflow.com/a/58932366
|
|
|
|
|| (isBatteryAbsent && !pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
|
|
|
|
&& pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
|
|
|
|
&& pm.hasSystemFeature(PackageManager.FEATURE_ETHERNET));
|
2019-02-01 14:02:28 +01:00
|
|
|
}
|
2019-11-16 07:06:59 +01:00
|
|
|
|
2020-04-11 03:25:05 +02:00
|
|
|
public static boolean isConfirmKey(final int keyCode) {
|
2019-11-16 07:06:59 +01:00
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_DPAD_CENTER:
|
|
|
|
case KeyEvent.KEYCODE_ENTER:
|
|
|
|
case KeyEvent.KEYCODE_SPACE:
|
|
|
|
case KeyEvent.KEYCODE_NUMPAD_ENTER:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-02-01 14:02:28 +01:00
|
|
|
}
|