Revert "Modifying Backup code to support HSUM mode." am: 91e98fcb5a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23126758

Change-Id: Id3331fae46c6407b7a9d6ce715d3bc18f3ce7baa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Wonyoung Kwak
2023-05-10 06:15:17 +00:00
committed by Automerger Merge Worker
6 changed files with 15 additions and 16 deletions

View File

@@ -253,7 +253,7 @@ public class Bmgr {
try { try {
boolean enable = Boolean.parseBoolean(arg); boolean enable = Boolean.parseBoolean(arg);
mBmgr.setAutoRestoreForUser(userId, enable); mBmgr.setAutoRestore(enable);
System.out.println( System.out.println(
"Auto restore is now " "Auto restore is now "
+ (enable ? "enabled" : "disabled") + (enable ? "enabled" : "disabled")

View File

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

View File

@@ -813,7 +813,7 @@ public class BackupManagerService extends IBackupManager.Stub {
} }
UserBackupManagerService userBackupManagerService = UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission( getServiceForUserIfCallerHasPermission(
userId, "hasBackupPassword()"); UserHandle.USER_SYSTEM, "hasBackupPassword()");
return userBackupManagerService != null && userBackupManagerService.hasBackupPassword(); return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
} }

View File

@@ -2797,6 +2797,11 @@ public class UserBackupManagerService {
boolean includeSystem, boolean compress, boolean doKeyValue, String[] pkgList) { boolean includeSystem, boolean compress, boolean doKeyValue, String[] pkgList) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "adbBackup"); 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 // Validate
if (!doAllApps) { if (!doAllApps) {
if (!includeShared) { if (!includeShared) {
@@ -2967,6 +2972,11 @@ public class UserBackupManagerService {
public void adbRestore(ParcelFileDescriptor fd) { public void adbRestore(ParcelFileDescriptor fd) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "adbRestore"); 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(); final long oldId = Binder.clearCallingIdentity();
try { try {
@@ -3075,7 +3085,7 @@ public class UserBackupManagerService {
"com.android.backupconfirm.BackupRestoreConfirmation"); "com.android.backupconfirm.BackupRestoreConfirmation");
confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token); confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
confIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); confIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivityAsUser(confIntent, UserHandle.of(mUserId)); mContext.startActivityAsUser(confIntent, UserHandle.SYSTEM);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
return false; return false;
} }

View File

@@ -33,7 +33,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf; import static org.robolectric.Shadows.shadowOf;
import static org.testng.Assert.expectThrows; import static org.testng.Assert.expectThrows;
@@ -119,10 +118,6 @@ public class BackupManagerServiceRoboTest {
mShadowUserManager.addUser(mUserOneId, "mUserOneId", 0); mShadowUserManager.addUser(mUserOneId, "mUserOneId", 0);
mShadowUserManager.addUser(mUserTwoId, "mUserTwoId", 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(BACKUP);
mShadowContext.grantPermissions(INTERACT_ACROSS_USERS_FULL); mShadowContext.grantPermissions(INTERACT_ACROSS_USERS_FULL);
@@ -1474,9 +1469,9 @@ public class BackupManagerServiceRoboTest {
File testFile = createTestFile(); File testFile = createTestFile();
FileDescriptor fileDescriptor = new FileDescriptor(); FileDescriptor fileDescriptor = new FileDescriptor();
PrintWriter printWriter = new PrintWriter(testFile); PrintWriter printWriter = new PrintWriter(testFile);
String[] args = {"1", "2"};
ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM)); ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM));
String[] args = {"--user", "0"};
backupManagerService.dump(fileDescriptor, printWriter, args); backupManagerService.dump(fileDescriptor, printWriter, args);
verify(mUserSystemService).dump(fileDescriptor, printWriter, args); verify(mUserSystemService).dump(fileDescriptor, printWriter, args);
@@ -1490,8 +1485,8 @@ public class BackupManagerServiceRoboTest {
File testFile = createTestFile(); File testFile = createTestFile();
FileDescriptor fileDescriptor = new FileDescriptor(); FileDescriptor fileDescriptor = new FileDescriptor();
PrintWriter printWriter = new PrintWriter(testFile); PrintWriter printWriter = new PrintWriter(testFile);
String[] args = {"1", "2"};
String[] args = {"--user", "10"};
backupManagerService.dump(fileDescriptor, printWriter, args); backupManagerService.dump(fileDescriptor, printWriter, args);
verify(mUserOneService, never()).dump(fileDescriptor, printWriter, args); verify(mUserOneService, never()).dump(fileDescriptor, printWriter, args);

View File

@@ -618,7 +618,6 @@ public class BackupManagerServiceTest {
@Test @Test
public void testDumpForOneUser_callerDoesNotHaveInteractAcrossUsersFullPermission_ignored() { public void testDumpForOneUser_callerDoesNotHaveInteractAcrossUsersFullPermission_ignored() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true); mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER); simulateUserUnlocked(NON_SYSTEM_USER);
@@ -638,7 +637,6 @@ public class BackupManagerServiceTest {
@Test @Test
public void public void
testDumpForOneUser_callerHasInteractAcrossUsersFullPermission_dumpsOnlySpecifiedUser() { testDumpForOneUser_callerHasInteractAcrossUsersFullPermission_dumpsOnlySpecifiedUser() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true); mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER); simulateUserUnlocked(NON_SYSTEM_USER);
@@ -650,7 +648,6 @@ public class BackupManagerServiceTest {
@Test @Test
public void testDumpForAllUsers_callerHasInteractAcrossUsersFullPermission_dumpsAllUsers() { public void testDumpForAllUsers_callerHasInteractAcrossUsersFullPermission_dumpsAllUsers() {
createBackupManagerServiceAndUnlockSystemUser();
mService.setBackupServiceActive(NON_SYSTEM_USER, true); mService.setBackupServiceActive(NON_SYSTEM_USER, true);
simulateUserUnlocked(NON_SYSTEM_USER); simulateUserUnlocked(NON_SYSTEM_USER);