{"record":{"id":"ccbb129dc7a8e4d5","repo":"MuntashirAkon/AppManager","slug":"package-not-installed-appdetailsviewmodel","errorCode":null,"errorMessage":"Package not installed","messagePattern":"Package not installed","errorType":"exception","errorClass":"PackageManager.NameNotFoundException","httpStatus":null,"severity":"warning","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/details/AppDetailsViewModel.java","lineNumber":1144,"sourceCode":"                // All signatures are fetched using PackageUtils where a fallback method is used in case the PackageInfo\n                // didn't load any signature. So, we should be safe from any harm.\n                mPackageInfo = mPackageManager.getPackageArchiveInfo(mApkPath, PackageManager.GET_PERMISSIONS\n                        | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS\n                        | PackageManager.GET_SERVICES | MATCH_DISABLED_COMPONENTS | PackageManager.GET_CONFIGURATIONS\n                        | PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.GET_URI_PERMISSION_PATTERNS\n                        | PackageManager.GET_META_DATA);\n                if (mPackageInfo == null) {\n                    throw new PackageManager.NameNotFoundException(\"Package cannot be parsed\");\n                }\n                if (mInstalledPackageInfo == null) {\n                    Log.d(TAG, \"%s not installed for user %d\", mPackageName, mUserId);\n                }\n                mPackageInfo.applicationInfo.sourceDir = mApkPath;\n                mPackageInfo.applicationInfo.publicSourceDir = mApkPath;\n            } else {\n                mPackageInfo = mInstalledPackageInfo;\n                if (mPackageInfo == null) {\n                    throw new PackageManager.NameNotFoundException(\"Package not installed\");\n                }\n            }\n            mIsPackageExistLiveData.postValue(mIsPackageExist = true);\n        } catch (PackageManager.NameNotFoundException e) {\n            Log.e(TAG, e);\n            mIsPackageExistLiveData.postValue(mIsPackageExist = false);\n        } catch (Throwable e) {\n            Log.e(TAG, e);\n        } finally {\n            mPackageChanged.postValue(true);\n        }\n    }\n\n    @WorkerThread\n    @Nullable\n    private PackageInfo getPackageInfoInternal() {\n        try {\n            mPackageInfoWatcher.await();","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/details/AppDetailsViewModel.java#L1126-L1162","documentation":"In the non-external-APK branch of package loading, the ViewModel uses mInstalledPackageInfo fetched earlier with MATCH_UNINSTALLED_PACKAGES. If that cached info is null — meaning no package entry exists even as an uninstalled/data-only record for the user — it throws PackageManager.NameNotFoundException('Package not installed'). The catch marks mIsPackageExist=false and posts that to the UI.","triggerScenarios":"Calling the ViewModel's package-load path for a package name that isn't installed at all for mUserId: never installed, fully uninstalled without data, or wrong userId queried; also if the earlier mInstalledPackageInfo lookup failed (e.g. the 293 error path reset it to null).","commonSituations":"Opening details for a stale package name from a shortcut/history; querying a work-profile-only app from the main user; race where app is uninstalled between listing and opening details.","solutions":["Verify installation with pm.getPackageInfo(name, 0) before opening details","Query the correct userId (e.g. use UserHandleCompat for the profile where the app is installed)","Handle the ViewModel's mIsPackageExist LiveData=false state gracefully in the UI","Refresh/re-check if a race with uninstall is possible"],"exampleFix":"// before\nviewModel.setPackage(stalePkg, userId); // NameNotFoundException\n// after\ntry {\n    pm.getPackageInfoAsUser(stalePkg, 0, userId);\n    viewModel.setPackage(stalePkg, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    navigateBackWithMessage(\"Package not installed for this user\");\n}","handlingStrategy":"try-catch","validationCode":"try {\n    pm.getPackageInfoAsUser(pkg, 0, userId);\n    boolean installed = true;\n} catch (PackageManager.NameNotFoundException e) { boolean installed = false; }","typeGuard":"boolean isInstalledForUser(PackageManager pm, String pkg, int userId) {\n    try { pm.getPackageInfoAsUser(pkg, 0, userId); return true; }\n    catch (PackageManager.NameNotFoundException e) { return false; }\n}","tryCatchPattern":"try {\n    viewModel.setPackage(pkg, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    // observe viewModel.getIsPackageExist() == false and show 'not installed' UI\n}","preventionTips":["Observe mIsPackageExist LiveData and handle the false state in UI","Query the correct user/profile (work profile apps live on another userId)","Re-check installation after PACKAGE_REMOVED broadcasts"],"tags":["android","package-manager","not-installed"],"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-14T11:17:12.474Z"}