MuntashirAkon/AppManager · error · RemoteException

Backup only allowed for current user

Error message

Backup only allowed for current user

What it means

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.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/compat/BackupCompat.java:89

    }

    public static boolean hasBackupPassword() {
        try {
            return getBackupManager().hasBackupPassword();
        } catch (RemoteException e) {
            return ExUtils.rethrowFromSystemServer(e);
        }
    }

    @SuppressWarnings("deprecation")
    public static void adbBackup(@UserIdInt int userId, ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs,
                                 boolean includeShared, boolean doWidgets, boolean allApps, boolean allIncludesSystem,
                                 boolean doCompress, boolean doKeyValue, String[] packageNames) throws RemoteException {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            getBackupManager().adbBackup(userId, fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);
        } else {
            if (UserHandleHidden.myUserId() != userId) {
                throw new RemoteException("Backup only allowed for current user");
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                getBackupManager().adbBackup(fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);
            } else {
                getBackupManager().fullBackup(fd, includeApks, includeObbs, includeShared, doWidgets, allApps, allIncludesSystem, doCompress, packageNames);
            }
        }
    }

    @SuppressWarnings("deprecation")
    public static void adbRestore(@UserIdInt int userId, ParcelFileDescriptor fd) throws RemoteException {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            getBackupManager().adbRestore(userId, fd);
        } else {
            if (UserHandleHidden.myUserId() != userId) {
                throw new RemoteException("Backup only allowed for current user");
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Pass UserHandleHidden.myUserId() (the current user) as userId on devices below Android Q.
  2. Require Android Q+ (SDK 29) for cross-user adb backup; gate the feature with Build.VERSION check.
  3. Run the operation in the target user's context (e.g. via adb shell am --user <id>) instead of passing a foreign userId.
  4. Inform the user that per-user backup is unsupported below Android 10.

Example fix

// before
BackupCompat.adbBackup(targetUserId, fd, true, true, true, false, false, true, false, false, pkgs);
// after
int userId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
        ? targetUserId : UserHandleHidden.myUserId();
BackupCompat.adbBackup(userId, fd, true, true, true, false, false, true, false, false, pkgs);
Defensive patterns

Strategy: validation

Validate before calling

int effective = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? targetUserId : UserHandleHidden.myUserId();
if (effective != targetUserId)
    Log.w(TAG, "adbBackup for other users unsupported below Android Q; falling back to current user");

Try / catch

try {
    BackupCompat.adbBackup(userId, fd, ...);
} catch (RemoteException e) {
    if ("Backup only allowed for current user".equals(e.getMessage())) {
        // retry with UserHandleHidden.myUserId() or disable feature on < Q
    } else throw e;
}

Prevention

When it happens

Trigger: Calling BackupCompat.adbBackup(userId, fd, ...) with a userId different from the current user (UserHandleHidden.myUserId()) while running on Android P (SDK 28) or lower.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/c59ef4d125b470bb. Report an issue: GitHub.