MuntashirAkon/AppManager · warning · IllegalStateException

Package is not installed for the user

Error message

Package is not installed for the user

What it means

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.

Solutions

  1. Prune rule entries for packages not installed for the target user before calling removeAllRules
  2. Verify installation with packageManager.getPackageInfoAsUser for each user handle and skip missing ones
  3. Ignore the logged message if acceptable — the rule entry is skipped, not fatal — and remove leftover rules manually
  4. Reinstall the app for that user, then remove rules

Example fix

// before
ComponentUtils.removeAllRules(packageName, new int[]{userHandle});
// after
if (pm.getPackageInfoAsUser(packageName, 0, userHandle) != null) {
    ComponentUtils.removeAllRules(packageName, new int[]{userHandle});
} else {
    ComponentsBlocker.getInstance(packageName, userHandle).delete();
}
Defensive patterns

Strategy: validation

Validate before calling

for (int user : userIds) {
    try {
        pm.getPackageInfoAsUser(packageName, 0, user);
    } catch (NameNotFoundException e) {
        ComponentsBlocker.getInstance(packageName, user).delete(); // prune stale rules
        continue;
    }
}

Type guard

boolean isInstalledForUser(PackageManager pm, String pkg, int userId) {
    try {
        pm.getPackageInfoAsUser(pkg, 0, userId);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

Try / catch

try {
    ComponentUtils.removeAllRules(packageName, userIds);
} catch (IllegalStateException e) {
    Log.w(TAG, "Skipping rules for uninstalled package/user", e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/bcc78dc36c8bbc64. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/rules/compontents/ComponentUtils.java:207

            } catch (Exception e) {
                e.printStackTrace();
            }
            // Grant configured permissions
            PackageInfo packageInfo = null;
            try {
                packageInfo = PackageManagerCompat.getPackageInfo(packageName,
                        PackageManager.GET_PERMISSIONS
                                | PackageManagerCompat.MATCH_STATIC_SHARED_AND_SDK_LIBRARIES,
                        userHandle);
            } catch (Throwable e) {
                Log.e(TAG, "Cannot resolve package %s for user %d", e, packageName, userHandle);
            }
            PackageManagerPermissionController permissionController =
                    PackageManagerPermissionController.getInstance();
            for (PermissionRule entry : cb.getAll(PermissionRule.class)) {
                try {
                    if (packageInfo == null) {
                        throw new IllegalStateException("Package is not installed for the user");
                    }
                    permissionController.setPlatformGranted(packageInfo, entry.name, userHandle,
                            true);
                    cb.removeEntry(entry);
                } catch (Throwable e) {
                    Log.e(TAG, "Cannot grant permission %s for package %s", e, entry.name,
                            packageName);
                }
            }
        }
    }

    @NonNull
    public static HashMap<String, RuleType> getIFWRulesForPackage(@NonNull String packageName) {
        return getIFWRulesForPackage(packageName, Paths.get(ComponentsBlocker.SYSTEM_RULES_PATH));
    }

    @VisibleForTesting

View on GitHub (pinned to 0152f468fc)