{"record":{"id":"062cd765e859bccc","repo":"MuntashirAkon/AppManager","slug":"rules-restore-is-requested-but-the-app-isn-t-installed","errorCode":null,"errorMessage":"Rules restore is requested but the app isn't installed.","messagePattern":"Rules restore is requested but the app isn't installed\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java","lineNumber":755,"sourceCode":"            }\n        }\n        // Decrypt permission file\n        try {\n            miscFile = mBackupItem.decrypt(new Path[]{miscFile})[0];\n        } catch (IOException | IndexOutOfBoundsException e) {\n            throw new BackupException(\"Failed to decrypt \" + miscFile.getName(), e);\n        }\n        try {\n            rules.loadExternalEntries(miscFile);\n        } catch (Throwable e) {\n            throw new BackupException(\"Failed to load rules from misc.\", e);\n        }\n    }\n\n    private void restoreRules() throws BackupException {\n        // Apply rules\n        if (!mIsInstalled) {\n            throw new BackupException(\"Rules restore is requested but the app isn't installed.\");\n        }\n        Path rulesFile;\n        try {\n            rulesFile = mBackupItem.getRulesFile();\n        } catch (IOException e) {\n            if (mBackupMetadata.hasRules) {\n                throw new BackupException(\"Rules file is missing.\", e);\n            } else {\n                // There are no rules, just skip\n                return;\n            }\n        }\n        if (!mRequestedFlags.skipSignatureCheck()) {\n            String checksum = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, rulesFile);\n            if (!checksum.equals(mChecksum.get(rulesFile.getName()))) {\n                throw new BackupException(\"Couldn't verify permission file.\" +\n                        \"\\nFile: \" + rulesFile +\n                        \"\\nFound: \" + checksum +","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java#L737-L773","documentation":"Thrown by restoreRules when a rules restore was requested but the target application is not installed. AppManager's rules (component blocking etc.) are stored via the system for an installed package, so applying rules to a missing package is rejected up front.","triggerScenarios":"Backup flags request rules restore but mIsInstalled is false when restoreRules runs — package absent for the given user at restore time.","commonSituations":"Restoring rules for an uninstalled app; wrong user profile (app installed on user 0 but restore targets user 10); full restore attempted after app was uninstalled following backup creation.","solutions":["Install the application first, then re-run the restore with rules enabled","Disable the rules-restore flag in the restore options","Verify the target userId matches the profile where the app is installed","Restore rules manually via AppManager's rules UI after installing the app"],"exampleFix":"// before\nnew RestoreOp(context, backupItem, new RestoreRequestFlags(/* rules */ true, ...)).runRestore();\n// after\nif (isPackageInstalled(context, pkg, userId)) {\n    new RestoreOp(context, backupItem, new RestoreRequestFlags(true, ...)).runRestore();\n} else {\n    Log.w(TAG, \"App not installed; skipping rules restore\");\n}","handlingStrategy":"validation","validationCode":"try {\n    context.getPackageManager().getPackageInfoForUser(pkg, 0, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    flags.restoreRules = false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    restoreOp.runRestore();\n} catch (BackupException e) {\n    if (e.getMessage().contains(\"app isn't installed\")) {\n        queueRulesRestoreAfterInstall();\n    } else throw e;\n}","preventionTips":["Install the app before any restore that includes rules","Match the restore target user to where the app is installed","Split restores into install → data → rules steps"],"tags":["android","backup","rules","not-installed","precondition"],"backgroundTag":"invalid-state-transition","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"}