{"record":{"id":"cd9ac30f2220d7c7","repo":"MuntashirAkon/AppManager","slug":"could-not-clear-data-of-package-pair","errorCode":null,"errorMessage":"Could not clear data of package ${pair}","messagePattern":"Could not clear data of package (.+?)","errorType":"exception","errorClass":"AndroidException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java","lineNumber":555,"sourceCode":"        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {\n            try {\n                pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId(), false);\n            } catch (NoSuchMethodError e) {\n                // Fall back to the old API\n                pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId());\n            }\n        } else pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId());\n        //noinspection SynchronizationOnLocalVariableOrMethodParameter\n        synchronized (obs) {\n            while (!obs.isCompleted()) {\n                try {\n                    obs.wait(500);\n                } catch (InterruptedException ignore) {\n                }\n            }\n        }\n        if (!obs.isSuccessful()) {\n            throw new AndroidException(\"Could not clear data of package \" + pair);\n        }\n        BroadcastUtils.sendPackageAltered(ContextUtils.getContext(), new String[]{pair.getPackageName()});\n    }\n\n    @RequiresPermission(ManifestCompat.permission.CLEAR_APP_USER_DATA)\n    public static boolean clearApplicationUserData(@NonNull String packageName, @UserIdInt int userId) {\n        try {\n            clearApplicationUserData(new UserPackagePair(packageName, userId));\n            return true;\n        } catch (AndroidException | SecurityException e) {\n            e.printStackTrace();\n            return false;\n        }\n    }\n\n    @RequiresPermission(allOf = {\n            Manifest.permission.DELETE_CACHE_FILES,\n            \"android.permission.INTERNAL_DELETE_CACHE_FILES\"","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java#L537-L573","documentation":"The internal helper that clears application user data spawns an IPackageDataObserver and waits (obs.wait(500)) for the framework callback. If the observer never reports success (clearApplicationUserData failed, was rejected, or never completed), an AndroidException(\"Could not clear data of package <pair>\") is thrown where <pair> describes package/user.","triggerScenarios":"Calling clearApplicationUserData(packageName, userId) where the OS refuses or fails the clear (permission denied, package missing, observer timeout without success).","commonSituations":"Clearing data of another app without CLEAR_APP_USER_DATA/system privileges; package uninstalled mid-operation; the clear callback timing out or never firing on some OEM ROMs.","solutions":["Catch AndroidException and surface a failure message / retry option.","Verify the app holds android.permission.CLEAR_APP_USER_DATA (or runs as root/shell).","Confirm the package exists for the target user before clearing.","Increase wait tolerance or handle the observer timeout explicitly if callbacks are slow on the device."],"exampleFix":"// before\nPackageManagerCompat.clearApplicationUserData(pkg, userId);\n// after\ntry {\n    PackageManagerCompat.clearApplicationUserData(pkg, userId);\n} catch (AndroidException e) {\n    Log.w(TAG, \"Clear data failed for \" + pkg + \": \" + e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"try { pm.getPackageInfoAsUser(pkg, 0, userId); } catch (PackageManager.NameNotFoundException e) { return; }\nint granted = ContextCompat.checkSelfPermission(ctx, \"android.permission.CLEAR_APP_USER_DATA\");\nif (granted != PackageManager.PERMISSION_GRANTED) return;","typeGuard":null,"tryCatchPattern":"try {\n    PackageManagerCompat.clearApplicationUserData(pkg, userId);\n} catch (AndroidException e) {\n    Log.w(TAG, \"Clear data failed: \" + e.getMessage());\n}","preventionTips":["Hold CLEAR_APP_USER_DATA or run privileged","Verify package exists for user","Account for slow/missing callbacks on OEM ROMs"],"tags":["android","clear-data","package-manager"],"backgroundTag":"operation-failed","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"}