{"record":{"id":"bcc78dc36c8bbc64","repo":"MuntashirAkon/AppManager","slug":"package-is-not-installed-for-the-user","errorCode":null,"errorMessage":"Package is not installed for the user","messagePattern":"Package is not installed for the user","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/rules/compontents/ComponentUtils.java","lineNumber":207,"sourceCode":"            } catch (Exception e) {\n                e.printStackTrace();\n            }\n            // Grant configured permissions\n            PackageInfo packageInfo = null;\n            try {\n                packageInfo = PackageManagerCompat.getPackageInfo(packageName,\n                        PackageManager.GET_PERMISSIONS\n                                | PackageManagerCompat.MATCH_STATIC_SHARED_AND_SDK_LIBRARIES,\n                        userHandle);\n            } catch (Throwable e) {\n                Log.e(TAG, \"Cannot resolve package %s for user %d\", e, packageName, userHandle);\n            }\n            PackageManagerPermissionController permissionController =\n                    PackageManagerPermissionController.getInstance();\n            for (PermissionRule entry : cb.getAll(PermissionRule.class)) {\n                try {\n                    if (packageInfo == null) {\n                        throw new IllegalStateException(\"Package is not installed for the user\");\n                    }\n                    permissionController.setPlatformGranted(packageInfo, entry.name, userHandle,\n                            true);\n                    cb.removeEntry(entry);\n                } catch (Throwable e) {\n                    Log.e(TAG, \"Cannot grant permission %s for package %s\", e, entry.name,\n                            packageName);\n                }\n            }\n        }\n    }\n\n    @NonNull\n    public static HashMap<String, RuleType> getIFWRulesForPackage(@NonNull String packageName) {\n        return getIFWRulesForPackage(packageName, Paths.get(ComponentsBlocker.SYSTEM_RULES_PATH));\n    }\n\n    @VisibleForTesting","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/rules/compontents/ComponentUtils.java#L189-L225","documentation":"ComponentUtils.removeAllRules resets permission rules by re-granting platform permissions per user. If the package's PackageInfo is null — meaning the package is not installed for that userHandle — the reset cannot proceed and IllegalStateException('Package is not installed for the user') is thrown, then caught, logged, and the entry is skipped.","triggerScenarios":"Removing all rules for a package/user combination where getPackageInfo returns null: the app was uninstalled for that user (e.g. removed from a work profile) but rule entries still exist in ComponentsBlocker.","commonSituations":"Stale rules left over after uninstalling or disabling an app for a secondary user; importing rules for packages that reference apps not present on the new device; multi-user setups where the app is installed only for user 0.","solutions":["Prune rule entries for packages not installed for the target user before calling removeAllRules","Verify installation with packageManager.getPackageInfoAsUser for each user handle and skip missing ones","Ignore the logged message if acceptable — the rule entry is skipped, not fatal — and remove leftover rules manually","Reinstall the app for that user, then remove rules"],"exampleFix":"// before\nComponentUtils.removeAllRules(packageName, new int[]{userHandle});\n// after\nif (pm.getPackageInfoAsUser(packageName, 0, userHandle) != null) {\n    ComponentUtils.removeAllRules(packageName, new int[]{userHandle});\n} else {\n    ComponentsBlocker.getInstance(packageName, userHandle).delete();\n}","handlingStrategy":"validation","validationCode":"for (int user : userIds) {\n    try {\n        pm.getPackageInfoAsUser(packageName, 0, user);\n    } catch (NameNotFoundException e) {\n        ComponentsBlocker.getInstance(packageName, user).delete(); // prune stale rules\n        continue;\n    }\n}","typeGuard":"boolean isInstalledForUser(PackageManager pm, String pkg, int userId) {\n    try {\n        pm.getPackageInfoAsUser(pkg, 0, userId);\n        return true;\n    } catch (NameNotFoundException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    ComponentUtils.removeAllRules(packageName, userIds);\n} catch (IllegalStateException e) {\n    Log.w(TAG, \"Skipping rules for uninstalled package/user\", e);\n}","preventionTips":["Prune rule entries when an app is uninstalled or disabled for a user","Check installation per user handle before rule operations","Clean up ComponentsBlocker entries during import if the target package is absent"],"tags":["android","rules","multi-user","stale-data"],"backgroundTag":"entity-not-found","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}