{"record":{"id":"c9c51874b52a1594","repo":"MuntashirAkon/AppManager","slug":"app-manager-does-not-have-the-required-permission","errorCode":null,"errorMessage":"App Manager does not have the required permission ","messagePattern":"App Manager does not have the required permission ","errorType":"exception","errorClass":"SecurityException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/self/SelfPermissions.java","lineNumber":291,"sourceCode":"        }\n        if (uid != Process.myUid()) {\n            try {\n                return PackageManagerCompat.getPackageManager().checkUidPermission(permissionName, uid)\n                        == PackageManager.PERMISSION_GRANTED;\n            } catch (RemoteException ignore) {\n            }\n        }\n        return checkSelfPermission(permissionName);\n    }\n\n    public static boolean checkSelfPermission(@NonNull String permissionName) {\n        return ContextCompat.checkSelfPermission(ContextUtils.getContext(), permissionName)\n                == PackageManager.PERMISSION_GRANTED;\n    }\n\n    public static void requireSelfPermission(@NonNull String permissionName) throws SecurityException {\n        if (!checkSelfPermission(permissionName)) {\n            throw new SecurityException(\"App Manager does not have the required permission \" + permissionName);\n        }\n    }\n\n    @NonNull\n    public static String getCallingPackage(int callingUid) {\n        if (callingUid == Ops.ROOT_UID || callingUid == Ops.SHELL_UID) {\n            return SHELL_PACKAGE_NAME;\n        }\n        if (callingUid == Ops.SYSTEM_UID) {\n            return \"android\";\n        }\n        return BuildConfig.APPLICATION_ID;\n    }\n}\n","sourceCodeStart":273,"sourceCodeEnd":306,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/self/SelfPermissions.java#L273-L306","documentation":"requireSelfPermission is an assertion helper: it checks whether App Manager itself holds the given permission and throws SecurityException(\"App Manager does not have the required permission \" + permissionName) if not. It converts a soft permission check into a hard failure for operations that cannot proceed safely.","triggerScenarios":"Calling requireSelfPermission for a permission that is not granted — not declared in the manifest, a special/AppOps permission (e.g. PACKAGE_USAGE_STATS, storage) not granted by the user, or revoked by the user or the system.","commonSituations":"Special permissions requiring manual grant in Settings, missing uses-permission manifest entries after refactoring, OS upgrades resetting special app-access grants, work/restricted profiles.","solutions":["Declare the permission in AndroidManifest.xml if it is a normal/install-time permission.","Request the permission at runtime or direct the user to the special-app-access Settings screen before calling.","Check with checkSelfPermission() first and degrade gracefully instead of asserting blindly.","Verify on-device (adb shell appops get / dumpsys package) that the permission or op is actually granted."],"exampleFix":"// before\nSelfPermissions.requireSelfPermission(Manifest.permission.PACKAGE_USAGE_STATS);\n// after\nif (!SelfPermissions.checkSelfPermission(Manifest.permission.PACKAGE_USAGE_STATS)) {\n    // prompt user to grant Usage Access in Settings, or skip the feature\n    return;\n}\nSelfPermissions.requireSelfPermission(Manifest.permission.PACKAGE_USAGE_STATS);","handlingStrategy":"try-catch","validationCode":"boolean granted = ContextCompat.checkSelfPermission(ctx, permissionName)\n        == PackageManager.PERMISSION_GRANTED;\nif (!granted) {\n    // request the grant or route the user to Settings before proceeding\n}","typeGuard":null,"tryCatchPattern":"try {\n    SelfPermissions.requireSelfPermission(permissionName);\n    // proceed with privileged operation\n} catch (SecurityException e) {\n    // permissionName is in e.getMessage(); request grant or disable the feature\n}","preventionTips":["Declare every permission requireSelfPermission may assert in AndroidManifest.xml.","For special permissions (Usage Access, etc.), guide the user to Settings instead of asserting blindly.","Re-check permissions on every app resume; grants can be revoked anytime.","Never call requireSelfPermission in startup paths that must not fail."],"tags":["android","permissions","security"],"backgroundTag":"permission-denied","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}