summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapish Goel <kapish@google.com>2021-02-12 11:41:34 +0000
committerKapish Goel <kapish@google.com>2021-02-12 11:41:34 +0000
commit47fc6dfc46db3236af1785f7b7c76d1235f59918 (patch)
treef7deae5be93f6912541021280464b50ebcc449cd
parentf81af9df21be3f01d4364571085048e668510d9c (diff)
Revert "Get OperationType from transport"
This reverts commit f81af9df21be3f01d4364571085048e668510d9c. Reason for revert: DroidMonitor: Potential culprit for Bug 180089773 - verifying through Forrest before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted. Change-Id: I80d3f3233e40ade3bfa89b236ba114966a137c23
-rw-r--r--cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java5
-rw-r--r--core/java/android/app/backup/BackupManager.java61
-rw-r--r--core/java/android/app/backup/IBackupManager.aidl6
-rw-r--r--services/backup/java/com/android/server/backup/BackupManagerService.java23
-rw-r--r--services/backup/java/com/android/server/backup/UserBackupManagerService.java51
-rw-r--r--services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java34
-rw-r--r--services/tests/servicestests/src/com/android/server/backup/UserBackupManagerServiceTest.java26
7 files changed, 117 insertions, 89 deletions
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
index ed717c491467..4b7eda096e54 100644
--- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
+++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
@@ -19,6 +19,7 @@ package com.android.commands.bmgr;
import android.annotation.IntDef;
import android.annotation.UserIdInt;
import android.app.backup.BackupManager;
+import android.app.backup.BackupManager.OperationType;
import android.app.backup.BackupManagerMonitor;
import android.app.backup.BackupProgress;
import android.app.backup.BackupTransport;
@@ -666,7 +667,7 @@ public class Bmgr {
// The rest of the 'list' options work with a restore session on the current transport
try {
- mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
+ mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
if (mRestore == null) {
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
return;
@@ -821,7 +822,7 @@ public class Bmgr {
try {
boolean didRestore = false;
- mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
+ mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
if (mRestore == null) {
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
return;
diff --git a/core/java/android/app/backup/BackupManager.java b/core/java/android/app/backup/BackupManager.java
index dae565e12fd7..673de8fa7c8c 100644
--- a/core/java/android/app/backup/BackupManager.java
+++ b/core/java/android/app/backup/BackupManager.java
@@ -361,7 +361,36 @@ public class BackupManager {
try {
// All packages, current transport
IRestoreSession binder =
- sService.beginRestoreSessionForUser(mContext.getUserId(), null, null);
+ sService.beginRestoreSessionForUser(mContext.getUserId(), null, null,
+ OperationType.BACKUP);
+ if (binder != null) {
+ session = new RestoreSession(mContext, binder);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "beginRestoreSession() couldn't connect");
+ }
+ }
+ return session;
+ }
+
+ /**
+ * Begin the process of restoring data from backup. See the
+ * {@link android.app.backup.RestoreSession} class for documentation on that process.
+ *
+ * @param operationType Type of the operation, see {@link OperationType}
+ *
+ * @hide
+ */
+ @RequiresPermission(android.Manifest.permission.BACKUP)
+ public RestoreSession beginRestoreSession(@OperationType int operationType) {
+ RestoreSession session = null;
+ checkServiceBinder();
+ if (sService != null) {
+ try {
+ // All packages, current transport
+ IRestoreSession binder =
+ sService.beginRestoreSessionForUser(mContext.getUserId(), null, null,
+ operationType);
if (binder != null) {
session = new RestoreSession(mContext, binder);
}
@@ -772,7 +801,7 @@ public class BackupManager {
@SystemApi
@RequiresPermission(android.Manifest.permission.BACKUP)
public int requestBackup(String[] packages, BackupObserver observer) {
- return requestBackup(packages, observer, null, 0);
+ return requestBackup(packages, observer, null, 0, OperationType.BACKUP);
}
/**
@@ -797,6 +826,31 @@ public class BackupManager {
@RequiresPermission(android.Manifest.permission.BACKUP)
public int requestBackup(String[] packages, BackupObserver observer,
BackupManagerMonitor monitor, int flags) {
+ return requestBackup(packages, observer, monitor, flags, OperationType.BACKUP);
+ }
+
+ /**
+ * Request an immediate backup, providing an observer to which results of the backup operation
+ * will be published. The Android backup system will decide for each package whether it will
+ * be full app data backup or key/value-pair-based backup.
+ *
+ * <p>If this method returns {@link BackupManager#SUCCESS}, the OS will attempt to backup all
+ * provided packages using the remote transport.
+ *
+ * @param packages List of package names to backup.
+ * @param observer The {@link BackupObserver} to receive callbacks during the backup
+ * operation. Could be {@code null}.
+ * @param monitor The {@link BackupManagerMonitorWrapper} to receive callbacks of important
+ * events during the backup operation. Could be {@code null}.
+ * @param flags {@link #FLAG_NON_INCREMENTAL_BACKUP}.
+ * @param operationType {@link OperationType}
+ * @return {@link BackupManager#SUCCESS} on success; nonzero on error.
+ * @throws IllegalArgumentException on null or empty {@code packages} param.
+ * @hide
+ */
+ @RequiresPermission(android.Manifest.permission.BACKUP)
+ public int requestBackup(String[] packages, BackupObserver observer,
+ BackupManagerMonitor monitor, int flags, @OperationType int operationType) {
checkServiceBinder();
if (sService != null) {
try {
@@ -806,7 +860,8 @@ public class BackupManager {
BackupManagerMonitorWrapper monitorWrapper = monitor == null
? null
: new BackupManagerMonitorWrapper(monitor);
- return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags);
+ return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags,
+ operationType);
} catch (RemoteException e) {
Log.e(TAG, "requestBackup() couldn't connect");
}
diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl
index bf5be95c4ab0..e1bbc08e72f3 100644
--- a/core/java/android/app/backup/IBackupManager.aidl
+++ b/core/java/android/app/backup/IBackupManager.aidl
@@ -547,9 +547,11 @@ interface IBackupManager {
* set can be restored.
* @param transportID The name of the transport to use for the restore operation.
* May be null, in which case the current active transport is used.
+ * @param operationType Type of the operation, see {@link BackupManager#OperationType}
* @return An interface to the restore session, or null on error.
*/
- IRestoreSession beginRestoreSessionForUser(int userId, String packageName, String transportID);
+ IRestoreSession beginRestoreSessionForUser(int userId, String packageName, String transportID,
+ int operationType);
/**
* Notify the backup manager that a BackupAgent has completed the operation
@@ -678,7 +680,7 @@ interface IBackupManager {
* {@link android.app.backup.IBackupManager.requestBackupForUser} for the calling user id.
*/
int requestBackup(in String[] packages, IBackupObserver observer, IBackupManagerMonitor monitor,
- int flags);
+ int flags, int operationType);
/**
* Cancel all running backups. After this call returns, no currently running backups will
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 38275f7cd348..6c30999f63a4 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -1245,9 +1245,10 @@ public class BackupManagerService extends IBackupManager.Stub {
@Override
public IRestoreSession beginRestoreSessionForUser(
- int userId, String packageName, String transportID) throws RemoteException {
+ int userId, String packageName, String transportID,
+ @OperationType int operationType) throws RemoteException {
return isUserReadyForBackup(userId)
- ? beginRestoreSession(userId, packageName, transportID) : null;
+ ? beginRestoreSession(userId, packageName, transportID, operationType) : null;
}
/**
@@ -1256,13 +1257,15 @@ public class BackupManagerService extends IBackupManager.Stub {
*/
@Nullable
public IRestoreSession beginRestoreSession(
- @UserIdInt int userId, String packageName, String transportName) {
+ @UserIdInt int userId, String packageName, String transportName,
+ @OperationType int operationType) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");
return userBackupManagerService == null
? null
- : userBackupManagerService.beginRestoreSession(packageName, transportName);
+ : userBackupManagerService.beginRestoreSession(packageName, transportName,
+ operationType);
}
@Override
@@ -1347,15 +1350,15 @@ public class BackupManagerService extends IBackupManager.Stub {
if (!isUserReadyForBackup(userId)) {
return BackupManager.ERROR_BACKUP_NOT_ALLOWED;
}
- return requestBackup(userId, packages, observer, monitor, flags);
+ return requestBackup(userId, packages, observer, monitor, flags, OperationType.BACKUP);
}
@Override
public int requestBackup(String[] packages, IBackupObserver observer,
- IBackupManagerMonitor monitor, int flags)
+ IBackupManagerMonitor monitor, int flags, @OperationType int operationType)
throws RemoteException {
return requestBackup(binderGetCallingUserId(), packages,
- observer, monitor, flags);
+ observer, monitor, flags, operationType);
}
/**
@@ -1367,13 +1370,15 @@ public class BackupManagerService extends IBackupManager.Stub {
String[] packages,
IBackupObserver observer,
IBackupManagerMonitor monitor,
- int flags) {
+ int flags,
+ @OperationType int operationType) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "requestBackup()");
return userBackupManagerService == null
? BackupManager.ERROR_BACKUP_NOT_ALLOWED
- : userBackupManagerService.requestBackup(packages, observer, monitor, flags);
+ : userBackupManagerService.requestBackup(packages, observer, monitor, flags,
+ operationType);
}
@Override
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index faec95f142eb..136cd22fad83 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -127,7 +127,6 @@ import com.android.server.backup.params.RestoreParams;
import com.android.server.backup.restore.ActiveRestoreSession;
import com.android.server.backup.restore.PerformUnifiedRestoreTask;
import com.android.server.backup.transport.TransportClient;
-import com.android.server.backup.transport.TransportNotAvailableException;
import com.android.server.backup.transport.TransportNotRegisteredException;
import com.android.server.backup.utils.BackupEligibilityRules;
import com.android.server.backup.utils.BackupManagerMonitorUtils;
@@ -1861,10 +1860,19 @@ public class UserBackupManagerService {
/**
* Requests a backup for the inputted {@code packages} with a specified {@link
- * IBackupManagerMonitor} and {@link OperationType}.
+ * IBackupManagerMonitor}.
*/
public int requestBackup(String[] packages, IBackupObserver observer,
IBackupManagerMonitor monitor, int flags) {
+ return requestBackup(packages, observer, monitor, flags, OperationType.BACKUP);
+ }
+
+ /**
+ * Requests a backup for the inputted {@code packages} with a specified {@link
+ * IBackupManagerMonitor} and {@link OperationType}.
+ */
+ public int requestBackup(String[] packages, IBackupObserver observer,
+ IBackupManagerMonitor monitor, int flags, @OperationType int operationType) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "requestBackup");
if (packages == null || packages.length < 1) {
@@ -1895,16 +1903,13 @@ public class UserBackupManagerService {
final TransportClient transportClient;
final String transportDirName;
- int operationType;
try {
transportDirName =
mTransportManager.getTransportDirName(
mTransportManager.getCurrentTransportName());
transportClient =
mTransportManager.getCurrentTransportClientOrThrow("BMS.requestBackup()");
- operationType = getOperationTypeFromTransport(transportClient);
- } catch (TransportNotRegisteredException | TransportNotAvailableException
- | RemoteException e) {
+ } catch (TransportNotRegisteredException e) {
BackupObserverUtils.sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
monitor = BackupManagerMonitorUtils.monitorEvent(monitor,
BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_IS_NULL,
@@ -4019,13 +4024,15 @@ public class UserBackupManagerService {
}
/** Hand off a restore session. */
- public IRestoreSession beginRestoreSession(String packageName, String transport) {
+ public IRestoreSession beginRestoreSession(String packageName, String transport,
+ @OperationType int operationType) {
if (DEBUG) {
Slog.v(
TAG,
addUserIdToLogMessage(
mUserId,
- "beginRestoreSession: pkg=" + packageName + " transport=" + transport));
+ "beginRestoreSession: pkg=" + packageName + " transport=" + transport
+ + "operationType=" + operationType));
}
boolean needPermission = true;
@@ -4066,17 +4073,6 @@ public class UserBackupManagerService {
}
}
- int operationType;
- try {
- operationType = getOperationTypeFromTransport(
- mTransportManager.getTransportClientOrThrow(transport, /* caller */
- "BMS.beginRestoreSession"));
- } catch (TransportNotAvailableException | TransportNotRegisteredException
- | RemoteException e) {
- Slog.w(TAG, "Failed to get operation type from transport: " + e);
- return null;
- }
-
synchronized (this) {
if (mActiveRestoreSession != null) {
Slog.i(
@@ -4360,23 +4356,6 @@ public class UserBackupManagerService {
}
}
- @VisibleForTesting
- @OperationType int getOperationTypeFromTransport(TransportClient transportClient)
- throws TransportNotAvailableException, RemoteException {
- long oldCallingId = Binder.clearCallingIdentity();
- try {
- IBackupTransport transport = transportClient.connectOrThrow(
- /* caller */ "BMS.getOperationTypeFromTransport");
- if ((transport.getTransportFlags() & BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER) != 0) {
- return OperationType.MIGRATION;
- } else {
- return OperationType.BACKUP;
- }
- } finally {
- Binder.restoreCallingIdentity(oldCallingId);
- }
- }
-
private static String addUserIdToLogMessage(int userId, String message) {
return "[UserID:" + userId + "] " + message;
}
diff --git a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java
index 2219d477630e..cbebe6984794 100644
--- a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java
+++ b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java
@@ -38,6 +38,7 @@ import static org.testng.Assert.expectThrows;
import android.annotation.UserIdInt;
import android.app.Application;
+import android.app.backup.BackupManager.OperationType;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
@@ -873,7 +874,8 @@ public class BackupManagerServiceRoboTest {
SecurityException.class,
() ->
backupManagerService.requestBackup(
- mUserTwoId, packages, observer, monitor, 0));
+ mUserTwoId, packages, observer, monitor, 0,
+ OperationType.BACKUP));
}
/**
@@ -891,9 +893,11 @@ public class BackupManagerServiceRoboTest {
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
- backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
+ backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
- verify(mUserTwoService).requestBackup(packages, observer, monitor, /* flags */ 0);
+ verify(mUserTwoService).requestBackup(packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@@ -906,9 +910,11 @@ public class BackupManagerServiceRoboTest {
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
- backupManagerService.requestBackup(mUserOneId, packages, observer, monitor, /* flags */ 0);
+ backupManagerService.requestBackup(mUserOneId, packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
- verify(mUserOneService).requestBackup(packages, observer, monitor, /* flags */ 0);
+ verify(mUserOneService).requestBackup(packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@@ -921,9 +927,11 @@ public class BackupManagerServiceRoboTest {
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
- backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
+ backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
- verify(mUserOneService, never()).requestBackup(packages, observer, monitor, /* flags */ 0);
+ verify(mUserOneService, never()).requestBackup(packages, observer, monitor, /* flags */ 0,
+ OperationType.BACKUP);
}
/**
@@ -1084,9 +1092,11 @@ public class BackupManagerServiceRoboTest {
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
- backupManagerService.beginRestoreSession(mUserOneId, TEST_PACKAGE, TEST_TRANSPORT);
+ backupManagerService.beginRestoreSession(mUserOneId, TEST_PACKAGE, TEST_TRANSPORT,
+ OperationType.BACKUP);
- verify(mUserOneService).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
+ verify(mUserOneService).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT,
+ OperationType.BACKUP);
}
/** Test that the backup service does not route methods for non-registered users. */
@@ -1096,9 +1106,11 @@ public class BackupManagerServiceRoboTest {
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
- backupManagerService.beginRestoreSession(mUserTwoId, TEST_PACKAGE, TEST_TRANSPORT);
+ backupManagerService.beginRestoreSession(mUserTwoId, TEST_PACKAGE, TEST_TRANSPORT,
+ OperationType.BACKUP);
- verify(mUserOneService, never()).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
+ verify(mUserOneService, never()).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT,
+ OperationType.BACKUP);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
diff --git a/services/tests/servicestests/src/com/android/server/backup/UserBackupManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/backup/UserBackupManagerServiceTest.java
index af11fe125a4e..b98f0257d7b7 100644
--- a/services/tests/servicestests/src/com/android/server/backup/UserBackupManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/backup/UserBackupManagerServiceTest.java
@@ -23,7 +23,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
-import android.app.backup.BackupAgent;
import android.app.backup.BackupManager.OperationType;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
@@ -31,7 +30,6 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import com.android.internal.backup.IBackupTransport;
import android.platform.test.annotations.Presubmit;
import androidx.test.runner.AndroidJUnit4;
@@ -58,7 +56,6 @@ public class UserBackupManagerServiceTest {
@Mock IBackupObserver mBackupObserver;
@Mock PackageManager mPackageManager;
@Mock TransportClient mTransportClient;
- @Mock IBackupTransport mBackupTransport;
@Mock BackupEligibilityRules mBackupEligibilityRules;
@@ -135,29 +132,6 @@ public class UserBackupManagerServiceTest {
assertThat(params.mBackupEligibilityRules).isEqualTo(mBackupEligibilityRules);
}
- @Test
- public void testGetOperationTypeFromTransport_returnsMigrationForMigrationTransport()
- throws Exception {
- when(mTransportClient.connectOrThrow(any())).thenReturn(mBackupTransport);
- when(mBackupTransport.getTransportFlags()).thenReturn(
- BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER);
-
- int operationType = mService.getOperationTypeFromTransport(mTransportClient);
-
- assertThat(operationType).isEqualTo(OperationType.MIGRATION);
- }
-
- @Test
- public void testGetOperationTypeFromTransport_returnsBackupByDefault()
- throws Exception {
- when(mTransportClient.connectOrThrow(any())).thenReturn(mBackupTransport);
- when(mBackupTransport.getTransportFlags()).thenReturn(0);
-
- int operationType = mService.getOperationTypeFromTransport(mTransportClient);
-
- assertThat(operationType).isEqualTo(OperationType.BACKUP);
- }
-
private static PackageInfo getPackageInfo(String packageName) {
PackageInfo packageInfo = new PackageInfo();
packageInfo.applicationInfo = new ApplicationInfo();