MIUI autostart

This commit is contained in:
M66B 2023-08-30 18:45:07 +02:00
parent 7b3ad21639
commit d9e42c2126
2 changed files with 10 additions and 7 deletions

View File

@ -28,6 +28,7 @@ import android.Manifest;
import android.animation.Animator; import android.animation.Animator;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityOptions; 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 { try {
@SuppressLint("PrivateApi")
Class<?> c = Class.forName("android.miui.AppOpsUtils"); Class<?> c = Class.forName("android.miui.AppOpsUtils");
Method m = c.getDeclaredMethod("getApplicationAutoStart", Context.class, String.class); Method m = c.getDeclaredMethod("getApplicationAutoStart", Context.class, String.class);
m.setAccessible(true); m.setAccessible(true);
Integer result = (Integer) m.invoke(null, context, context.getPackageName()); return (Integer) m.invoke(null, context, context.getPackageName());
return (result != null && result.equals(0));
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
return false; return null;
} }
} }

View File

@ -2005,9 +2005,10 @@ public class Log {
Build.VERSION.RELEASE, Build.VERSION.SDK_INT, Helper.getTargetSdk(context))); Build.VERSION.RELEASE, Build.VERSION.SDK_INT, Helper.getTargetSdk(context)));
String miui = Helper.getMIUIVersion(); String miui = Helper.getMIUIVersion();
boolean autostart = (miui != null && Helper.getMIUIAutostart(context)); Integer autostart = (miui == null ? null : Helper.getMIUIAutostart(context));
sb.append(String.format("MIUI: %s autostart=%b\r\n", sb.append(String.format("MIUI: %s autostart: %s\r\n",
miui == null ? "-" : miui, autostart)); miui == null ? "-" : miui,
autostart == null ? "?" : Boolean.toString(autostart == 0)));
boolean reporting = prefs.getBoolean("crash_reports", false); boolean reporting = prefs.getBoolean("crash_reports", false);
if (reporting || BuildConfig.TEST_RELEASE) { if (reporting || BuildConfig.TEST_RELEASE) {