{"record":{"id":"d709e9909a3ed534","repo":"MuntashirAkon/AppManager","slug":"keystore-restore-is-requested-but-the-app-isn-t-installed","errorCode":null,"errorMessage":"KeyStore restore is requested but the app isn't installed.","messagePattern":"KeyStore 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":418,"sourceCode":"            try {\n                mPackageInfo = PackageManagerCompat.getPackageInfo(mPackageName, GET_SIGNING_CERTIFICATES\n                        | PackageManagerCompat.MATCH_STATIC_SHARED_AND_SDK_LIBRARIES, mUserId);\n                mUid = Objects.requireNonNull(mPackageInfo.applicationInfo).uid;\n                mIsInstalled = true;\n            } catch (Exception e) {\n                throw new BackupException(\"Apparently the install wasn't complete in the previous section.\", e);\n            }\n        }\n    }\n\n    private void restoreKeyStore() throws BackupException {\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {\n            // keystore v2 is not supported.\n            Log.w(TAG, \"Ignoring KeyStore backups for %s\", mPackageName);\n            return;\n        }\n        if (mPackageInfo == null) {\n            throw new BackupException(\"KeyStore restore is requested but the app isn't installed.\");\n        }\n        Path[] keyStoreFiles = mBackupItem.getKeyStoreFiles();\n        if (keyStoreFiles.length == 0) {\n            throw new BackupException(\"KeyStore files should've existed but they didn't\");\n        }\n        if (!mRequestedFlags.skipSignatureCheck()) {\n            String checksum;\n            for (Path file : keyStoreFiles) {\n                checksum = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, file);\n                if (!checksum.equals(mChecksum.get(file.getName()))) {\n                    throw new BackupException(\"KeyStore file verification failed.\" +\n                            \"\\nFile: \" + file +\n                            \"\\nFound: \" + checksum +\n                            \"\\nRequired: \" + mChecksum.get(file.getName()));\n                }\n            }\n        }\n        // Decrypt sources","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java#L400-L436","documentation":"restoreKeyStore restores app key store files, but only if the app is installed (mPackageInfo != null). On Android < S, if the package info was never populated (app not installed/restored), AppManager refuses to restore KeyStore data and throws this error, because keystores belong to a UID that must exist.","triggerScenarios":"restoreKeyStore is invoked with mPackageInfo == null: KeyStore restore was requested in flags but the app was not installed (restoreData/restoreApk failed or was skipped, or the app simply is not present on the device).","commonSituations":"Restoring only KeyStore without restoring the app; the APK install step failed earlier; running on Android < 12 where keystore v1 restore requires an installed app; users disabled/blocked the app before restore.","solutions":["Restore/install the app first so mPackageInfo is populated, then retry KeyStore restore.","Uncheck the KeyStore option if you only want data restore without keystore files.","On Android 12+ note keystore backup/restore is skipped entirely (v2 unsupported).","Fix earlier restore failures (installation errors) before attempting keystore restore."],"exampleFix":"// before\nrestoreKeyStore();\n// after\nif (mPackageInfo != null) {\n    restoreKeyStore();\n} else {\n    Log.w(TAG, \"Skipping KeyStore restore: app not installed\");\n}","handlingStrategy":"type-guard","validationCode":"if (mPackageInfo == null || !mIsInstalled) skipKeyStoreRestore();","typeGuard":"boolean canRestoreKeyStore(PackageInfo pi) { return pi != null && pi.applicationInfo != null; }","tryCatchPattern":"if (mPackageInfo == null) { throw new BackupException(\"KeyStore restore is requested but the app isn't installed.\"); } // callers: catch BackupException and skip keystore step gracefully","preventionTips":["Always install the app before requesting KeyStore restore","Check the requested flags match what the backup actually contains","Handle Android 12+ where keystore restore is unsupported","Surface keystore-skip as a warning instead of failing the whole restore"],"tags":["android","keystore","backup-restore"],"backgroundTag":"missing-required-argument","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"}