Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4c14673 authored by Satoshi Niwa's avatar Satoshi Niwa
Browse files

Fix Backup/Restore confirmation dialog for HSUM multi-user scenarios.

This CL ensures correct backup/restore confirmation flow in
multi-user environments with non-system users, including HSUM.

Problem: Backup operations initiated for a secondary user would fail
because key logic was hardcoded to act on UserHandle.SYSTEM (user 0).
This led to two specific issues:
- The backup confirmation UI was launched for user 0 and subsequently blocked by ActivityTaskManager if a different user was in the foreground.
- Binder calls like hasBackupPassword() were incorrectly routed to user 0's profile, causing a SecurityException when called from an app running as a secondary user.

Solution:
- UserBackupManagerService now launches the confirmation UI for the user it is managing (mUserId).
- BackupManagerService directs password-related binder calls to the profile of the calling user.

Bug: 410032204
Bug: 420527847
Test: atest CtsBackupHostTestCases
Test: atest GtsBackupHostTestCases
Test: atest BackupManagerServiceTest
Flag: TEST_ONLY
Change-Id: I62b3f6de8061107e7233e9b76c0a077010b81c50
parent d0dba9b0
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -800,8 +800,7 @@ public class BackupManagerService extends IBackupManager.Stub implements BackupM
            return false;
        }
        UserBackupManagerService userBackupManagerService =
                getServiceForUserIfCallerHasPermission(
                        UserHandle.USER_SYSTEM, "setBackupPassword()");
                getServiceForUserIfCallerHasPermission(userId, "setBackupPassword()");

        return userBackupManagerService != null
                && userBackupManagerService.setBackupPassword(currentPassword, newPassword);
@@ -815,8 +814,7 @@ public class BackupManagerService extends IBackupManager.Stub implements BackupM
            return false;
        }
        UserBackupManagerService userBackupManagerService =
                getServiceForUserIfCallerHasPermission(
                        UserHandle.USER_SYSTEM, "hasBackupPassword()");
                getServiceForUserIfCallerHasPermission(userId, "hasBackupPassword()");

        return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
    }
+3 −1
Original line number Diff line number Diff line
@@ -2820,6 +2820,7 @@ public class UserBackupManagerService {
        }
    }

    @SuppressWarnings("AndroidFrameworkRequiresPermission")
    private boolean startConfirmationUi(int token, String action) {
        try {
            Intent confIntent = new Intent(action);
@@ -2828,7 +2829,8 @@ public class UserBackupManagerService {
                    "com.android.backupconfirm.BackupRestoreConfirmation");
            confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
            confIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            mContext.startActivityAsUser(confIntent, UserHandle.SYSTEM);
            mContext.startActivityAsUser(confIntent, UserHandle.of(mUserId));
            Slog.i(TAG, mLogIdMsg + "Starting confirmation UI");
        } catch (ActivityNotFoundException e) {
            return false;
        }