From 870cf7fb7e8ee1635b747989f9eb4d9e58a0870c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 25 Sep 2023 21:59:13 +0200 Subject: [PATCH] Battery optimizations: check smartwatch --- .../main/java/eu/faircode/email/Helper.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index c8410f21ae..bbfe41197f 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -187,6 +187,7 @@ public class Helper { private static Boolean hasWebView = null; private static Boolean hasPlayStore = null; private static Boolean hasValidFingerprint = null; + private static Boolean isSmartwatch = null; static final float LOW_LIGHT = 0.6f; @@ -611,7 +612,7 @@ public class Helper { static Boolean isIgnoringOptimizations(Context context) { try { - if (isArc()) + if (isArc() || isWatch(context)) return true; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) @@ -1563,6 +1564,25 @@ public class Helper { return (Build.DEVICE != null) && Build.DEVICE.matches(".+_cheets|cheets_.+"); } + static boolean isWatch(Context context) { + if (isSmartwatch == null) + isSmartwatch = _isWatch(context); + return isSmartwatch; + } + + private static boolean _isWatch(Context context) { + try { + UiModeManager uimm = Helper.getSystemService(context, UiModeManager.class); + if (uimm == null) + return false; + int uiModeType = uimm.getCurrentModeType(); + return (uiModeType == Configuration.UI_MODE_TYPE_WATCH); + } catch (Throwable ex) { + Log.e(ex); + return false; + } + } + static boolean isStaminaEnabled(Context context) { // https://dontkillmyapp.com/sony if (!isSony())