Skip to content
Snippets Groups Projects
Commit 6cf0c303 authored by Piyush Mehrotra's avatar Piyush Mehrotra
Browse files

Modifying Backup code to support HSUM mode.

Bug: 266703231

Test: Run CTS/GTS tests for backup
Change-Id: I7a8d09f9f1be83ff4d9f545439f93b2c5319f007
parent da26f028
No related branches found
No related tags found
No related merge requests found
......@@ -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")
......
......@@ -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);
......
......@@ -813,7 +813,7 @@ public class BackupManagerService extends IBackupManager.Stub {
}
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(
UserHandle.USER_SYSTEM, "hasBackupPassword()");
userId, "hasBackupPassword()");
return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
}
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -618,6 +618,7 @@ public class BackupManagerServiceTest {
@Test
public void testDumpForOneUser_callerDoesNotHaveInteractAcrossUsersFullPermission_ignored() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER);
......@@ -637,6 +638,7 @@ public class BackupManagerServiceTest {
@Test
public void
testDumpForOneUser_callerHasInteractAcrossUsersFullPermission_dumpsOnlySpecifiedUser() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER);
......@@ -648,6 +650,7 @@ public class BackupManagerServiceTest {
@Test
public void testDumpForAllUsers_callerHasInteractAcrossUsersFullPermission_dumpsAllUsers() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment