{"record":{"id":"8bbbe6e355d567a7","repo":"MuntashirAkon/AppManager","slug":"could-not-freeze-myself","errorCode":null,"errorMessage":"Could not freeze myself.","messagePattern":"Could not freeze myself\\.","errorType":"exception","errorClass":"RemoteException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/utils/FreezeUtils.java","lineNumber":84,"sourceCode":"        // An app is frozen if one of the following operations return true: suspend, disable or hide\n        if (!applicationInfo.enabled) {\n            return true;\n        }\n        if (ApplicationInfoCompat.isSuspended(applicationInfo)) {\n            return true;\n        }\n        return ApplicationInfoCompat.isHidden(applicationInfo);\n    }\n\n    @Deprecated\n    public static void freeze(@NonNull String packageName, @UserIdInt int userId) throws RemoteException {\n        freeze(packageName, userId, Prefs.Blocking.getDefaultFreezingMethod());\n    }\n\n    public static void freeze(@NonNull String packageName, @UserIdInt int userId, @FreezeMethod int freezeType)\n            throws RemoteException {\n        if (BuildConfig.APPLICATION_ID.equals(packageName) && userId == UserHandleHidden.myUserId()) {\n            throw new RemoteException(\"Could not freeze myself.\");\n        }\n        if (freezeType == FREEZE_HIDE) {\n            if (SelfPermissions.checkSelfOrRemotePermission(ManifestCompat.permission.MANAGE_USERS)) {\n                PackageManagerCompat.hidePackage(packageName, userId, true);\n                return;\n            }\n            // No permission, fall-through\n        } else if ((freezeType == FREEZE_SUSPEND || freezeType == FREEZE_ADV_SUSPEND) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {\n            if (freezeType == FREEZE_ADV_SUSPEND) {\n                // Force-stop app\n                if (SelfPermissions.checkSelfOrRemotePermission(ManifestCompat.permission.FORCE_STOP_PACKAGES)) {\n                    PackageManagerCompat.forceStopPackage(packageName, userId);\n                }\n            }\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {\n                if (SelfPermissions.checkSelfOrRemotePermission(ManifestCompat.permission.SUSPEND_APPS)) {\n                    PackageManagerCompat.suspendPackages(new String[]{packageName}, userId, true);\n                    return;","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/utils/FreezeUtils.java#L66-L102","documentation":"FreezeUtils.freeze refuses to freeze App Manager itself: if the target packageName equals BuildConfig.APPLICATION_ID and the target userId is the current user, it throws RemoteException(\"Could not freeze myself.\") as a self-protection guard, since freezing the running app would break the caller. It is thrown before any actual freezing (hide/disable/suspend) happens.","triggerScenarios":"Calling freeze(packageName, userId, freezeType) with packageName == \"io.github.muntashirakon.AppManager\" (or whatever the build's application ID is) while userId == UserHandleHidden.myUserId().","commonSituations":"Bulk 'freeze all selected apps' operations that accidentally include App Manager; UI list filtering bugs that do not exclude the app itself; scripted/automation flows that freeze every installed package.","solutions":["Exclude the app's own package (BuildConfig.APPLICATION_ID) from the list before calling freeze","Check `BuildConfig.APPLICATION_ID.equals(packageName) && userId == UserHandleHidden.myUserId()` and skip/notify instead of freezing","Only pass a different userId when intentionally freezing a clone of the app in another profile","Catch RemoteException and surface a user-friendly message"],"exampleFix":"// before\nFreezeUtils.freeze(pkg, userId, method);\n// after\nif (!BuildConfig.APPLICATION_ID.equals(pkg) || userId != UserHandleHidden.myUserId()) {\n    FreezeUtils.freeze(pkg, userId, method);\n}","handlingStrategy":"validation","validationCode":"if (BuildConfig.APPLICATION_ID.equals(packageName) && userId == UserHandleHidden.myUserId()) {\n    return; // skip self\n}\nFreezeUtils.freeze(packageName, userId, freezeType);","typeGuard":"boolean isSelfTarget(String pkg, int userId) {\n    return BuildConfig.APPLICATION_ID.equals(pkg) && userId == UserHandleHidden.myUserId();\n}","tryCatchPattern":"try {\n    FreezeUtils.freeze(packageName, userId, freezeType);\n} catch (RemoteException e) {\n    Log.w(TAG, \"Cannot freeze: \" + e.getMessage());\n}","preventionTips":["Filter the app's own package out of bulk freeze lists at the UI layer","Unit-test bulk freeze flows against a package list containing App Manager itself","Only freeze the same package across users when explicitly intended"],"tags":["android","freeze","self-protection"],"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-14T11:17:12.474Z"}