diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index c9da87fbee..bd33fc5eef 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -28,6 +28,7 @@ import android.Manifest; import android.animation.Animator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; @@ -1618,16 +1619,17 @@ public class Helper { } } - static boolean getMIUIAutostart(Context context) { + // 0=allowed, 1=denied + static Integer getMIUIAutostart(Context context) { try { + @SuppressLint("PrivateApi") Class c = Class.forName("android.miui.AppOpsUtils"); Method m = c.getDeclaredMethod("getApplicationAutoStart", Context.class, String.class); m.setAccessible(true); - Integer result = (Integer) m.invoke(null, context, context.getPackageName()); - return (result != null && result.equals(0)); + return (Integer) m.invoke(null, context, context.getPackageName()); } catch (Throwable ex) { Log.w(ex); - return false; + return null; } } diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 52253ab551..e2b601d487 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -2005,9 +2005,10 @@ public class Log { Build.VERSION.RELEASE, Build.VERSION.SDK_INT, Helper.getTargetSdk(context))); String miui = Helper.getMIUIVersion(); - boolean autostart = (miui != null && Helper.getMIUIAutostart(context)); - sb.append(String.format("MIUI: %s autostart=%b\r\n", - miui == null ? "-" : miui, autostart)); + Integer autostart = (miui == null ? null : Helper.getMIUIAutostart(context)); + sb.append(String.format("MIUI: %s autostart: %s\r\n", + miui == null ? "-" : miui, + autostart == null ? "?" : Boolean.toString(autostart == 0))); boolean reporting = prefs.getBoolean("crash_reports", false); if (reporting || BuildConfig.TEST_RELEASE) {