summaryrefslogtreecommitdiff
path: root/services/backup/java
diff options
context:
space:
mode:
authorBernardo Rufino <brufino@google.com>2019-08-15 12:13:35 +0100
committerBernardo Rufino <brufino@google.com>2019-08-15 14:41:48 +0100
commitf410de02e25e5a75300f3d15720c17abf0cafde5 (patch)
treebf365b59d7e053affaa0739ff8237962c9ee0403 /services/backup/java
parenta83c2e086574951adc02c6e9e725d396ea818587 (diff)
Move adb backup/restore operations to Trampoline
From BMS. Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest Bug: 135661048 Change-Id: I7f839a37780c5164878fd9640486c209f99620cc
Diffstat (limited to 'services/backup/java')
-rw-r--r--services/backup/java/com/android/server/backup/BackupManagerService.java95
-rw-r--r--services/backup/java/com/android/server/backup/Trampoline.java106
2 files changed, 92 insertions, 109 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 707b09a591d1..bd30a86dcee1 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -20,10 +20,8 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
-import android.app.backup.IFullBackupRestoreObserver;
import android.content.Context;
import android.os.IBinder;
-import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.util.SparseArray;
@@ -91,99 +89,6 @@ public class BackupManagerService {
// TODO (b/118520567): Stop hardcoding system user when we pass in user id as a parameter
// ---------------------------------------------
- // ADB BACKUP/RESTORE OPERATIONS
- // ---------------------------------------------
-
- /** Sets the backup password used when running adb backup. */
- public boolean setBackupPassword(String currentPassword, String newPassword) {
- UserBackupManagerService userBackupManagerService =
- getServiceForUserIfCallerHasPermission(
- UserHandle.USER_SYSTEM, "setBackupPassword()");
-
- return userBackupManagerService != null
- && userBackupManagerService.setBackupPassword(currentPassword, newPassword);
- }
-
- /** Returns {@code true} if adb backup was run with a password, else returns {@code false}. */
- public boolean hasBackupPassword() {
- UserBackupManagerService userBackupManagerService =
- getServiceForUserIfCallerHasPermission(
- UserHandle.USER_SYSTEM, "hasBackupPassword()");
-
- return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
- }
-
- /**
- * Used by 'adb backup' to run a backup pass for packages {@code packageNames} supplied via the
- * command line, writing the resulting data stream to the supplied {@code fd}. This method is
- * synchronous and does not return to the caller until the backup has been completed. It
- * requires on-screen confirmation by the user.
- */
- public void adbBackup(
- @UserIdInt int userId,
- ParcelFileDescriptor fd,
- boolean includeApks,
- boolean includeObbs,
- boolean includeShared,
- boolean doWidgets,
- boolean doAllApps,
- boolean includeSystem,
- boolean doCompress,
- boolean doKeyValue,
- String[] packageNames) {
- UserBackupManagerService userBackupManagerService =
- getServiceForUserIfCallerHasPermission(userId, "adbBackup()");
-
- if (userBackupManagerService != null) {
- userBackupManagerService.adbBackup(
- fd,
- includeApks,
- includeObbs,
- includeShared,
- doWidgets,
- doAllApps,
- includeSystem,
- doCompress,
- doKeyValue,
- packageNames);
- }
- }
-
- /**
- * Used by 'adb restore' to run a restore pass reading from the supplied {@code fd}. This method
- * is synchronous and does not return to the caller until the restore has been completed. It
- * requires on-screen confirmation by the user.
- */
- public void adbRestore(@UserIdInt int userId, ParcelFileDescriptor fd) {
- UserBackupManagerService userBackupManagerService =
- getServiceForUserIfCallerHasPermission(userId, "adbRestore()");
-
- if (userBackupManagerService != null) {
- userBackupManagerService.adbRestore(fd);
- }
- }
-
- /**
- * Confirm that the previously requested adb backup/restore operation can proceed. This is used
- * to require a user-facing disclosure about the operation.
- */
- public void acknowledgeAdbBackupOrRestore(
- @UserIdInt int userId,
- int token,
- boolean allow,
- String currentPassword,
- String encryptionPassword,
- IFullBackupRestoreObserver observer) {
- UserBackupManagerService userBackupManagerService =
- getServiceForUserIfCallerHasPermission(userId, "acknowledgeAdbBackupOrRestore()");
-
- if (userBackupManagerService != null) {
- userBackupManagerService.acknowledgeAdbBackupOrRestore(
- token, allow, currentPassword, encryptionPassword, observer);
- }
- }
-
- // ---------------------------------------------
// SERVICE OPERATIONS
// ---------------------------------------------
diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java
index 0522102f3786..109d6369fcc1 100644
--- a/services/backup/java/com/android/server/backup/Trampoline.java
+++ b/services/backup/java/com/android/server/backup/Trampoline.java
@@ -722,16 +722,33 @@ public class Trampoline extends IBackupManager.Stub {
return userBackupManagerService != null && userBackupManagerService.isBackupEnabled();
}
+ /** Sets the backup password used when running adb backup. */
@Override
- public boolean setBackupPassword(String currentPw, String newPw) throws RemoteException {
+ public boolean setBackupPassword(String currentPassword, String newPassword) {
int userId = binderGetCallingUserId();
- return (isUserReadyForBackup(userId)) && mService.setBackupPassword(currentPw, newPw);
+ if (!isUserReadyForBackup(userId)) {
+ return false;
+ }
+ UserBackupManagerService userBackupManagerService =
+ getServiceForUserIfCallerHasPermission(
+ UserHandle.USER_SYSTEM, "setBackupPassword()");
+
+ return userBackupManagerService != null
+ && userBackupManagerService.setBackupPassword(currentPassword, newPassword);
}
+ /** Returns {@code true} if adb backup was run with a password, else returns {@code false}. */
@Override
public boolean hasBackupPassword() throws RemoteException {
int userId = binderGetCallingUserId();
- return (isUserReadyForBackup(userId)) && mService.hasBackupPassword();
+ if (!isUserReadyForBackup(userId)) {
+ return false;
+ }
+ UserBackupManagerService userBackupManagerService =
+ getServiceForUserIfCallerHasPermission(
+ UserHandle.USER_SYSTEM, "hasBackupPassword()");
+
+ return userBackupManagerService != null && userBackupManagerService.hasBackupPassword();
}
@Override
@@ -759,13 +776,43 @@ public class Trampoline extends IBackupManager.Stub {
}
}
- public 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 (isUserReadyForBackup(userId)) {
- mService.adbBackup(userId, fd, includeApks, includeObbs, includeShared, doWidgets,
- allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);
+ /**
+ * Used by 'adb backup' to run a backup pass for packages {@code packageNames} supplied via the
+ * command line, writing the resulting data stream to the supplied {@code fd}. This method is
+ * synchronous and does not return to the caller until the backup has been completed. It
+ * requires on-screen confirmation by the user.
+ */
+ @Override
+ public void adbBackup(
+ @UserIdInt int userId,
+ ParcelFileDescriptor fd,
+ boolean includeApks,
+ boolean includeObbs,
+ boolean includeShared,
+ boolean doWidgets,
+ boolean doAllApps,
+ boolean includeSystem,
+ boolean doCompress,
+ boolean doKeyValue,
+ String[] packageNames) {
+ if (!isUserReadyForBackup(userId)) {
+ return;
+ }
+ UserBackupManagerService userBackupManagerService =
+ getServiceForUserIfCallerHasPermission(userId, "adbBackup()");
+
+ if (userBackupManagerService != null) {
+ userBackupManagerService.adbBackup(
+ fd,
+ includeApks,
+ includeObbs,
+ includeShared,
+ doWidgets,
+ doAllApps,
+ includeSystem,
+ doCompress,
+ doKeyValue,
+ packageNames);
}
}
@@ -789,10 +836,21 @@ public class Trampoline extends IBackupManager.Stub {
}
}
+ /**
+ * Used by 'adb restore' to run a restore pass reading from the supplied {@code fd}. This method
+ * is synchronous and does not return to the caller until the restore has been completed. It
+ * requires on-screen confirmation by the user.
+ */
@Override
- public void adbRestore(@UserIdInt int userId, ParcelFileDescriptor fd) throws RemoteException {
- if (isUserReadyForBackup(userId)) {
- mService.adbRestore(userId, fd);
+ public void adbRestore(@UserIdInt int userId, ParcelFileDescriptor fd) {
+ if (!isUserReadyForBackup(userId)) {
+ return;
+ }
+ UserBackupManagerService userBackupManagerService =
+ getServiceForUserIfCallerHasPermission(userId, "adbRestore()");
+
+ if (userBackupManagerService != null) {
+ userBackupManagerService.adbRestore(fd);
}
}
@@ -806,11 +864,31 @@ public class Trampoline extends IBackupManager.Stub {
IFullBackupRestoreObserver observer)
throws RemoteException {
if (isUserReadyForBackup(userId)) {
- mService.acknowledgeAdbBackupOrRestore(userId, token, allow,
+ acknowledgeAdbBackupOrRestore(userId, token, allow,
curPassword, encryptionPassword, observer);
}
}
+ /**
+ * Confirm that the previously requested adb backup/restore operation can proceed. This is used
+ * to require a user-facing disclosure about the operation.
+ */
+ public void acknowledgeAdbBackupOrRestore(
+ @UserIdInt int userId,
+ int token,
+ boolean allow,
+ String currentPassword,
+ String encryptionPassword,
+ IFullBackupRestoreObserver observer) {
+ UserBackupManagerService userBackupManagerService =
+ getServiceForUserIfCallerHasPermission(userId, "acknowledgeAdbBackupOrRestore()");
+
+ if (userBackupManagerService != null) {
+ userBackupManagerService.acknowledgeAdbBackupOrRestore(
+ token, allow, currentPassword, encryptionPassword, observer);
+ }
+ }
+
@Override
public void acknowledgeFullBackupOrRestore(int token, boolean allow, String curPassword,
String encryptionPassword, IFullBackupRestoreObserver observer)