{"record":{"id":"c59ef4d125b470bb","repo":"MuntashirAkon/AppManager","slug":"backup-only-allowed-for-current-user","errorCode":null,"errorMessage":"Backup only allowed for current user","messagePattern":"Backup only allowed for current user","errorType":"exception","errorClass":"RemoteException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/BackupCompat.java","lineNumber":89,"sourceCode":"    }\n\n    public static boolean hasBackupPassword() {\n        try {\n            return getBackupManager().hasBackupPassword();\n        } catch (RemoteException e) {\n            return ExUtils.rethrowFromSystemServer(e);\n        }\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    public static void adbBackup(@UserIdInt int userId, ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs,\n                                 boolean includeShared, boolean doWidgets, boolean allApps, boolean allIncludesSystem,\n                                 boolean doCompress, boolean doKeyValue, String[] packageNames) throws RemoteException {\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {\n            getBackupManager().adbBackup(userId, fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);\n        } else {\n            if (UserHandleHidden.myUserId() != userId) {\n                throw new RemoteException(\"Backup only allowed for current user\");\n            }\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {\n                getBackupManager().adbBackup(fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);\n            } else {\n                getBackupManager().fullBackup(fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, packageNames);\n            }\n        }\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    public static void adbRestore(@UserIdInt int userId, ParcelFileDescriptor fd) throws RemoteException {\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {\n            getBackupManager().adbRestore(userId, fd);\n        } else {\n            if (UserHandleHidden.myUserId() != userId) {\n                throw new RemoteException(\"Backup only allowed for current user\");\n            }\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/BackupCompat.java#L71-L107","documentation":"BackupCompat.adbBackup() routes to the system BackupManager; on Android < Q (SDK 29) the legacy adbBackup/fullBackup overloads have no userId parameter, so backing up a user other than the one the app is running as is impossible. The method throws RemoteException(\"Backup only allowed for current user\") when UserHandleHidden.myUserId() != userId on those older versions.","triggerScenarios":"Calling BackupCompat.adbBackup(userId, fd, ...) with a userId different from the current user (UserHandleHidden.myUserId()) while running on Android P (SDK 28) or lower.","commonSituations":"Work-profile or multi-user setups attempting to back up another user's apps on an Android 9 or older device; automation scripts hardcoding user 0 while running in a profile; code paths that worked on Android 10+ failing after downgrade.","solutions":["Pass UserHandleHidden.myUserId() (the current user) as userId on devices below Android Q.","Require Android Q+ (SDK 29) for cross-user adb backup; gate the feature with Build.VERSION check.","Run the operation in the target user's context (e.g. via adb shell am --user <id>) instead of passing a foreign userId.","Inform the user that per-user backup is unsupported below Android 10."],"exampleFix":"// before\nBackupCompat.adbBackup(targetUserId, fd, true, true, true, false, false, true, false, false, pkgs);\n// after\nint userId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q\n        ? targetUserId : UserHandleHidden.myUserId();\nBackupCompat.adbBackup(userId, fd, true, true, true, false, false, true, false, false, pkgs);","handlingStrategy":"validation","validationCode":"int effective = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? targetUserId : UserHandleHidden.myUserId();\nif (effective != targetUserId)\n    Log.w(TAG, \"adbBackup for other users unsupported below Android Q; falling back to current user\");","typeGuard":null,"tryCatchPattern":"try {\n    BackupCompat.adbBackup(userId, fd, ...);\n} catch (RemoteException e) {\n    if (\"Backup only allowed for current user\".equals(e.getMessage())) {\n        // retry with UserHandleHidden.myUserId() or disable feature on < Q\n    } else throw e;\n}","preventionTips":["Gate cross-user backup/restore features behind SDK_INT >= Q checks.","Default userId to the current user on legacy devices.","Document the pre-Q single-user limitation in the calling feature."],"tags":["android","backup","multi-user","version-compat"],"backgroundTag":"unsupported-operation","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"}