{"record":{"id":"ac9d1eef45d1952b","repo":"MuntashirAkon/AppManager","slug":"could-not-retrieve-info-for-package-s-with-flags-0x-x-for","errorCode":null,"errorMessage":"Could not retrieve info for package %s with flags 0x%X for user %d","messagePattern":"Could not retrieve info for package (.+?) with flags 0x%X for user (.+?)","errorType":"exception","errorClass":"PackageManager.NameNotFoundException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java","lineNumber":236,"sourceCode":"                                             @UserIdInt int userId)\n            throws RemoteException, PackageManager.NameNotFoundException {\n        PackageInfo info = null;\n        try {\n            info = getPackageInfoInternal(pm, packageName, flags, userId);\n        } catch (DeadObjectException e) {\n            Log.w(TAG, \"Could not fetch info for package %s and user %d with flags 0x%X, using workaround\",\n                    e, packageName, userId, flags);\n        }\n        if (info == null) {\n            // The app might not be loaded properly due parcel size limit, try to load components separately.\n            // first check the existence of the package\n            int strippedFlags = flags & ~(PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES\n                    | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_PERMISSIONS);\n            info = getPackageInfoInternal(pm, packageName, strippedFlags, userId);\n            if (info == null) {\n                // At this point, it should return package info.\n                // Returning null denotes that it failed again even after the major flags have been stripped.\n                throw new PackageManager.NameNotFoundException(String.format(\"Could not retrieve info for package %s with flags 0x%X for user %d\",\n                        packageName, strippedFlags, userId));\n            }\n            // Load info for major flags\n            ActivityInfo[] activities = null;\n            if ((flags & PackageManager.GET_ACTIVITIES) != 0) {\n                int newFlags = flags & ~(PackageManager.GET_SERVICES | PackageManager.GET_PROVIDERS\n                        | PackageManager.GET_RECEIVERS | PackageManager.GET_PERMISSIONS);\n                PackageInfo info1 = getPackageInfoInternal(pm, packageName, newFlags, userId);\n                if (info1 != null) activities = info1.activities;\n            }\n            ServiceInfo[] services = null;\n            if ((flags & PackageManager.GET_SERVICES) != 0) {\n                int newFlags = flags & ~(PackageManager.GET_ACTIVITIES | PackageManager.GET_PROVIDERS\n                        | PackageManager.GET_RECEIVERS | PackageManager.GET_PERMISSIONS);\n                PackageInfo info1 = getPackageInfoInternal(pm, packageName, newFlags, userId);\n                if (info1 != null) services = info1.services;\n            }\n            ProviderInfo[] providers = null;","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java#L218-L254","documentation":"PackageManagerCompat.getPackageInfo retries getPackageInfoInternal with major component flags (activities, services, providers, receivers, permissions) stripped. If it still returns null, the package info genuinely cannot be retrieved, so it throws PackageManager.NameNotFoundException with a formatted message including package name, stripped flags, and userId. This means the failure is not flag-related — the package is unavailable for that user.","triggerScenarios":"Calling getPackageInfo(pm, packageName, flags, userId) for a package that does not exist, is being uninstalled, or is hidden/disabled for the given user, even after retry without component flags.","commonSituations":"Race with an app updating/uninstalling; querying a package not visible on a managed profile; package name typo; querying hidden (suspend/hidden) packages without proper permissions.","solutions":["Catch PackageManager.NameNotFoundException and treat it as 'package unavailable for user'.","Verify the package exists via getInstalledPackages/listing before querying with component flags.","Check the correct userId (0 vs profile).","Retry after a short delay if a concurrent install/update may be in progress."],"exampleFix":"// before\nPackageInfo pi = PackageManagerCompat.getPackageInfo(pm, pkg, flags, userId);\n// after\nPackageInfo pi;\ntry {\n    pi = PackageManagerCompat.getPackageInfo(pm, pkg, flags, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    Log.w(TAG, \"Package unavailable: \" + pkg);\n    pi = null;\n}","handlingStrategy":"try-catch","validationCode":"boolean exists;\ntry { pm.getPackageInfoAsUser(pkg, 0, userId); exists = true; }\ncatch (PackageManager.NameNotFoundException e) { exists = false; }","typeGuard":null,"tryCatchPattern":"try {\n    PackageInfo pi = PackageManagerCompat.getPackageInfo(pm, pkg, flags, userId);\n} catch (PackageManager.NameNotFoundException e) {\n    // treat as unavailable for user\n}","preventionTips":["Verify package presence for the target user first","Retry on races with install/update","Check userId correctness"],"tags":["android","package-not-found","package-manager"],"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"}