0

Is there some Java code to check if the ACCESS_RESTRICTED_SETTINGS permission is enabled?

enter image description here

FLASHCODER
  • 1
  • 7
  • 24

1 Answers1

0
public static boolean hasAccessRestrictedPerm(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        int mode = appOpsManager.checkOpNoThrow("android:access_restricted_settings", applicationInfo.uid, applicationInfo.packageName);
        return (mode == AppOpsManager.MODE_ALLOWED);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
FLASHCODER
  • 1
  • 7
  • 24
  • I got this error when i used this code: Caused by: java.lang.SecurityException: verifyIncomingOp: uid 11488 does not have android.permission.MANAGE_APPOPS. And also i tried to add and ask this(android.permission.MANAGE_APPOPS) permission but i can't get access to this permission. Is there any other solution for to check restricted_settings? – Divyang Divasaliwala Mar 14 '23 at 12:36
  • Android 13 not implemented these restrictions. Still is possible activate AcessibilityService for sideload apps normally. – FLASHCODER Mar 15 '23 at 13:40