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

Commit 66ce0276 authored by Piyush Mehrotra's avatar Piyush Mehrotra Committed by Automerger Merge Worker
Browse files

Merge changes from topic "br-cts-hsum" into udc-dev am: 82a2b5e9 am: 60c20b6b

parents b7344b48 60c20b6b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ public class Bmgr {

        try {
            boolean enable = Boolean.parseBoolean(arg);
            mBmgr.setAutoRestore(enable);
            mBmgr.setAutoRestoreForUser(userId, enable);
            System.out.println(
                    "Auto restore is now "
                            + (enable ? "enabled" : "disabled")
+3 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public final class Backup {
    }

    public void run(String[] args) {
        Log.d(TAG, "Called run() with args: " + String.join(" ", args));
        if (mBackupManager == null) {
            Log.e(TAG, "Can't obtain Backup Manager binder");
            return;
@@ -70,6 +71,8 @@ public final class Backup {
            return;
        }

        Log.d(TAG, "UserId : " + userId);

        String arg = nextArg();
        if (arg.equals("backup")) {
            doBackup(OsConstants.STDOUT_FILENO, userId);
+59 −27
Original line number Diff line number Diff line
@@ -813,7 +813,7 @@ public class BackupManagerService extends IBackupManager.Stub {
        }
        UserBackupManagerService userBackupManagerService =
                getServiceForUserIfCallerHasPermission(
                        UserHandle.USER_SYSTEM, "hasBackupPassword()");
                        userId, "hasBackupPassword()");

        return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
    }
@@ -1515,34 +1515,45 @@ public class BackupManagerService extends IBackupManager.Stub {

    @VisibleForTesting
    void dumpWithoutCheckingPermission(FileDescriptor fd, PrintWriter pw, String[] args) {
        int userId = binderGetCallingUserId();
        if (!isUserReadyForBackup(userId)) {
            pw.println("Inactive");
            return;
        }
        int argIndex = 0;

        if (args != null) {
            for (String arg : args) {
                if ("-h".equals(arg)) {
                    pw.println("'dumpsys backup' optional arguments:");
                    pw.println("  -h       : this help text");
                    pw.println("  a[gents] : dump information about defined backup agents");
                    pw.println("  transportclients : dump information about transport clients");
                    pw.println("  transportstats : dump transport statts");
                    pw.println("  users    : dump the list of users for which backup service "
                            + "is running");
        String op = nextArg(args, argIndex);
        argIndex++;

        if ("--help".equals(op)) {
            showDumpUsage(pw);
            return;
                } else if ("users".equals(arg.toLowerCase())) {
        }
        if ("users".equals(op)) {
            pw.print(DUMP_RUNNING_USERS_MESSAGE);
            for (int i = 0; i < mUserServices.size(); i++) {
                        pw.print(" " + mUserServices.keyAt(i));
                UserBackupManagerService userBackupManagerService =
                        getServiceForUserIfCallerHasPermission(mUserServices.keyAt(i),
                                "dump()");
                if (userBackupManagerService != null) {
                    pw.print(" " + userBackupManagerService.getUserId());
                }
            }
            pw.println();
            return;
        }
        if ("--user".equals(op)) {
            String userArg = nextArg(args, argIndex);
            argIndex++;
            if (userArg == null) {
                showDumpUsage(pw);
                return;
            }
            int userId = UserHandle.parseUserArg(userArg);
            UserBackupManagerService userBackupManagerService =
                    getServiceForUserIfCallerHasPermission(userId, "dump()");
            if (userBackupManagerService != null) {
                userBackupManagerService.dump(fd, pw, args);
            }

            return;
        }
        if (op == null || "agents".startsWith(op) || "transportclients".equals(op)
                || "transportstats".equals(op)) {
            for (int i = 0; i < mUserServices.size(); i++) {
                UserBackupManagerService userBackupManagerService =
                        getServiceForUserIfCallerHasPermission(mUserServices.keyAt(i), "dump()");
@@ -1550,6 +1561,27 @@ public class BackupManagerService extends IBackupManager.Stub {
                    userBackupManagerService.dump(fd, pw, args);
                }
            }
            return;
        }

        showDumpUsage(pw);
    }

    private String nextArg(String[] args, int argIndex) {
        if (argIndex >= args.length) {
            return null;
        }
        return args[argIndex];
    }

    private static void showDumpUsage(PrintWriter pw) {
        pw.println("'dumpsys backup' optional arguments:");
        pw.println("  --help    : this help text");
        pw.println("  a[gents] : dump information about defined backup agents");
        pw.println("  transportclients : dump information about transport clients");
        pw.println("  transportstats : dump transport stats");
        pw.println("  users    : dump the list of users for which backup service is running");
        pw.println("  --user <userId> : dump information for user userId");
    }

    /**
@@ -1654,7 +1686,7 @@ public class BackupManagerService extends IBackupManager.Stub {
     * @param message A message to include in the exception if it is thrown.
     */
    void enforceCallingPermissionOnUserId(@UserIdInt int userId, String message) {
        if (Binder.getCallingUserHandle().getIdentifier() != userId) {
        if (binderGetCallingUserId() != userId) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
        }
+1 −11
Original line number Diff line number Diff line
@@ -2797,11 +2797,6 @@ public class UserBackupManagerService {
            boolean includeSystem, boolean compress, boolean doKeyValue, String[] pkgList) {
        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "adbBackup");

        final int callingUserHandle = UserHandle.getCallingUserId();
        if (callingUserHandle != UserHandle.USER_SYSTEM) {
            throw new IllegalStateException("Backup supported only for the device owner");
        }

        // Validate
        if (!doAllApps) {
            if (!includeShared) {
@@ -2972,11 +2967,6 @@ public class UserBackupManagerService {
    public void adbRestore(ParcelFileDescriptor fd) {
        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "adbRestore");

        final int callingUserHandle = UserHandle.getCallingUserId();
        if (callingUserHandle != UserHandle.USER_SYSTEM) {
            throw new IllegalStateException("Restore supported only for the device owner");
        }

        final long oldId = Binder.clearCallingIdentity();

        try {
@@ -3085,7 +3075,7 @@ 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));
        } catch (ActivityNotFoundException e) {
            return false;
        }
+7 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import static org.testng.Assert.expectThrows;

@@ -118,6 +119,10 @@ public class BackupManagerServiceRoboTest {
        mShadowUserManager.addUser(mUserOneId, "mUserOneId", 0);
        mShadowUserManager.addUser(mUserTwoId, "mUserTwoId", 0);

        when(mUserSystemService.getUserId()).thenReturn(UserHandle.USER_SYSTEM);
        when(mUserOneService.getUserId()).thenReturn(mUserOneId);
        when(mUserTwoService.getUserId()).thenReturn(mUserTwoId);

        mShadowContext.grantPermissions(BACKUP);
        mShadowContext.grantPermissions(INTERACT_ACROSS_USERS_FULL);

@@ -1469,9 +1474,9 @@ public class BackupManagerServiceRoboTest {
        File testFile = createTestFile();
        FileDescriptor fileDescriptor = new FileDescriptor();
        PrintWriter printWriter = new PrintWriter(testFile);
        String[] args = {"1", "2"};
        ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM));

        String[] args = {"--user", "0"};
        backupManagerService.dump(fileDescriptor, printWriter, args);

        verify(mUserSystemService).dump(fileDescriptor, printWriter, args);
@@ -1485,8 +1490,8 @@ public class BackupManagerServiceRoboTest {
        File testFile = createTestFile();
        FileDescriptor fileDescriptor = new FileDescriptor();
        PrintWriter printWriter = new PrintWriter(testFile);
        String[] args = {"1", "2"};

        String[] args = {"--user", "10"};
        backupManagerService.dump(fileDescriptor, printWriter, args);

        verify(mUserOneService, never()).dump(fileDescriptor, printWriter, args);
Loading