Merge "Get OperationType from transport" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
04501d566e
@@ -19,7 +19,6 @@ package com.android.commands.bmgr;
|
|||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.app.backup.BackupManager;
|
import android.app.backup.BackupManager;
|
||||||
import android.app.backup.BackupManager.OperationType;
|
|
||||||
import android.app.backup.BackupManagerMonitor;
|
import android.app.backup.BackupManagerMonitor;
|
||||||
import android.app.backup.BackupProgress;
|
import android.app.backup.BackupProgress;
|
||||||
import android.app.backup.BackupTransport;
|
import android.app.backup.BackupTransport;
|
||||||
@@ -667,7 +666,7 @@ public class Bmgr {
|
|||||||
|
|
||||||
// The rest of the 'list' options work with a restore session on the current transport
|
// The rest of the 'list' options work with a restore session on the current transport
|
||||||
try {
|
try {
|
||||||
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
|
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
|
||||||
if (mRestore == null) {
|
if (mRestore == null) {
|
||||||
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
|
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
|
||||||
return;
|
return;
|
||||||
@@ -822,7 +821,7 @@ public class Bmgr {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
boolean didRestore = false;
|
boolean didRestore = false;
|
||||||
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
|
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
|
||||||
if (mRestore == null) {
|
if (mRestore == null) {
|
||||||
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
|
System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -361,36 +361,7 @@ public class BackupManager {
|
|||||||
try {
|
try {
|
||||||
// All packages, current transport
|
// All packages, current transport
|
||||||
IRestoreSession binder =
|
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) {
|
if (binder != null) {
|
||||||
session = new RestoreSession(mContext, binder);
|
session = new RestoreSession(mContext, binder);
|
||||||
}
|
}
|
||||||
@@ -801,7 +772,7 @@ public class BackupManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.BACKUP)
|
@RequiresPermission(android.Manifest.permission.BACKUP)
|
||||||
public int requestBackup(String[] packages, BackupObserver observer) {
|
public int requestBackup(String[] packages, BackupObserver observer) {
|
||||||
return requestBackup(packages, observer, null, 0, OperationType.BACKUP);
|
return requestBackup(packages, observer, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -826,31 +797,6 @@ public class BackupManager {
|
|||||||
@RequiresPermission(android.Manifest.permission.BACKUP)
|
@RequiresPermission(android.Manifest.permission.BACKUP)
|
||||||
public int requestBackup(String[] packages, BackupObserver observer,
|
public int requestBackup(String[] packages, BackupObserver observer,
|
||||||
BackupManagerMonitor monitor, int flags) {
|
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();
|
checkServiceBinder();
|
||||||
if (sService != null) {
|
if (sService != null) {
|
||||||
try {
|
try {
|
||||||
@@ -860,8 +806,7 @@ public class BackupManager {
|
|||||||
BackupManagerMonitorWrapper monitorWrapper = monitor == null
|
BackupManagerMonitorWrapper monitorWrapper = monitor == null
|
||||||
? null
|
? null
|
||||||
: new BackupManagerMonitorWrapper(monitor);
|
: new BackupManagerMonitorWrapper(monitor);
|
||||||
return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags,
|
return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags);
|
||||||
operationType);
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "requestBackup() couldn't connect");
|
Log.e(TAG, "requestBackup() couldn't connect");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -547,11 +547,9 @@ interface IBackupManager {
|
|||||||
* set can be restored.
|
* set can be restored.
|
||||||
* @param transportID The name of the transport to use for the restore operation.
|
* @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.
|
* 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.
|
* @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
|
* Notify the backup manager that a BackupAgent has completed the operation
|
||||||
@@ -680,7 +678,7 @@ interface IBackupManager {
|
|||||||
* {@link android.app.backup.IBackupManager.requestBackupForUser} for the calling user id.
|
* {@link android.app.backup.IBackupManager.requestBackupForUser} for the calling user id.
|
||||||
*/
|
*/
|
||||||
int requestBackup(in String[] packages, IBackupObserver observer, IBackupManagerMonitor monitor,
|
int requestBackup(in String[] packages, IBackupObserver observer, IBackupManagerMonitor monitor,
|
||||||
int flags, int operationType);
|
int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all running backups. After this call returns, no currently running backups will
|
* Cancel all running backups. After this call returns, no currently running backups will
|
||||||
|
|||||||
@@ -1245,10 +1245,9 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IRestoreSession beginRestoreSessionForUser(
|
public IRestoreSession beginRestoreSessionForUser(
|
||||||
int userId, String packageName, String transportID,
|
int userId, String packageName, String transportID) throws RemoteException {
|
||||||
@OperationType int operationType) throws RemoteException {
|
|
||||||
return isUserReadyForBackup(userId)
|
return isUserReadyForBackup(userId)
|
||||||
? beginRestoreSession(userId, packageName, transportID, operationType) : null;
|
? beginRestoreSession(userId, packageName, transportID) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1257,15 +1256,13 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public IRestoreSession beginRestoreSession(
|
public IRestoreSession beginRestoreSession(
|
||||||
@UserIdInt int userId, String packageName, String transportName,
|
@UserIdInt int userId, String packageName, String transportName) {
|
||||||
@OperationType int operationType) {
|
|
||||||
UserBackupManagerService userBackupManagerService =
|
UserBackupManagerService userBackupManagerService =
|
||||||
getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");
|
getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");
|
||||||
|
|
||||||
return userBackupManagerService == null
|
return userBackupManagerService == null
|
||||||
? null
|
? null
|
||||||
: userBackupManagerService.beginRestoreSession(packageName, transportName,
|
: userBackupManagerService.beginRestoreSession(packageName, transportName);
|
||||||
operationType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1350,15 +1347,15 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
if (!isUserReadyForBackup(userId)) {
|
if (!isUserReadyForBackup(userId)) {
|
||||||
return BackupManager.ERROR_BACKUP_NOT_ALLOWED;
|
return BackupManager.ERROR_BACKUP_NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
return requestBackup(userId, packages, observer, monitor, flags, OperationType.BACKUP);
|
return requestBackup(userId, packages, observer, monitor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int requestBackup(String[] packages, IBackupObserver observer,
|
public int requestBackup(String[] packages, IBackupObserver observer,
|
||||||
IBackupManagerMonitor monitor, int flags, @OperationType int operationType)
|
IBackupManagerMonitor monitor, int flags)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
return requestBackup(binderGetCallingUserId(), packages,
|
return requestBackup(binderGetCallingUserId(), packages,
|
||||||
observer, monitor, flags, operationType);
|
observer, monitor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1370,15 +1367,13 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
String[] packages,
|
String[] packages,
|
||||||
IBackupObserver observer,
|
IBackupObserver observer,
|
||||||
IBackupManagerMonitor monitor,
|
IBackupManagerMonitor monitor,
|
||||||
int flags,
|
int flags) {
|
||||||
@OperationType int operationType) {
|
|
||||||
UserBackupManagerService userBackupManagerService =
|
UserBackupManagerService userBackupManagerService =
|
||||||
getServiceForUserIfCallerHasPermission(userId, "requestBackup()");
|
getServiceForUserIfCallerHasPermission(userId, "requestBackup()");
|
||||||
|
|
||||||
return userBackupManagerService == null
|
return userBackupManagerService == null
|
||||||
? BackupManager.ERROR_BACKUP_NOT_ALLOWED
|
? BackupManager.ERROR_BACKUP_NOT_ALLOWED
|
||||||
: userBackupManagerService.requestBackup(packages, observer, monitor, flags,
|
: userBackupManagerService.requestBackup(packages, observer, monitor, flags);
|
||||||
operationType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.AtomicFile;
|
import android.util.AtomicFile;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -127,6 +128,7 @@ import com.android.server.backup.params.RestoreParams;
|
|||||||
import com.android.server.backup.restore.ActiveRestoreSession;
|
import com.android.server.backup.restore.ActiveRestoreSession;
|
||||||
import com.android.server.backup.restore.PerformUnifiedRestoreTask;
|
import com.android.server.backup.restore.PerformUnifiedRestoreTask;
|
||||||
import com.android.server.backup.transport.TransportClient;
|
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.transport.TransportNotRegisteredException;
|
||||||
import com.android.server.backup.utils.BackupEligibilityRules;
|
import com.android.server.backup.utils.BackupEligibilityRules;
|
||||||
import com.android.server.backup.utils.BackupManagerMonitorUtils;
|
import com.android.server.backup.utils.BackupManagerMonitorUtils;
|
||||||
@@ -1858,21 +1860,12 @@ public class UserBackupManagerService {
|
|||||||
return requestBackup(packages, observer, null, flags);
|
return requestBackup(packages, observer, null, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests a backup for the inputted {@code packages} with a specified {@link
|
|
||||||
* 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
|
* Requests a backup for the inputted {@code packages} with a specified {@link
|
||||||
* IBackupManagerMonitor} and {@link OperationType}.
|
* IBackupManagerMonitor} and {@link OperationType}.
|
||||||
*/
|
*/
|
||||||
public int requestBackup(String[] packages, IBackupObserver observer,
|
public int requestBackup(String[] packages, IBackupObserver observer,
|
||||||
IBackupManagerMonitor monitor, int flags, @OperationType int operationType) {
|
IBackupManagerMonitor monitor, int flags) {
|
||||||
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "requestBackup");
|
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "requestBackup");
|
||||||
|
|
||||||
if (packages == null || packages.length < 1) {
|
if (packages == null || packages.length < 1) {
|
||||||
@@ -1903,13 +1896,16 @@ public class UserBackupManagerService {
|
|||||||
|
|
||||||
final TransportClient transportClient;
|
final TransportClient transportClient;
|
||||||
final String transportDirName;
|
final String transportDirName;
|
||||||
|
int operationType;
|
||||||
try {
|
try {
|
||||||
transportDirName =
|
transportDirName =
|
||||||
mTransportManager.getTransportDirName(
|
mTransportManager.getTransportDirName(
|
||||||
mTransportManager.getCurrentTransportName());
|
mTransportManager.getCurrentTransportName());
|
||||||
transportClient =
|
transportClient =
|
||||||
mTransportManager.getCurrentTransportClientOrThrow("BMS.requestBackup()");
|
mTransportManager.getCurrentTransportClientOrThrow("BMS.requestBackup()");
|
||||||
} catch (TransportNotRegisteredException e) {
|
operationType = getOperationTypeFromTransport(transportClient);
|
||||||
|
} catch (TransportNotRegisteredException | TransportNotAvailableException
|
||||||
|
| RemoteException e) {
|
||||||
BackupObserverUtils.sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
|
BackupObserverUtils.sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
|
||||||
monitor = BackupManagerMonitorUtils.monitorEvent(monitor,
|
monitor = BackupManagerMonitorUtils.monitorEvent(monitor,
|
||||||
BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_IS_NULL,
|
BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_IS_NULL,
|
||||||
@@ -4024,15 +4020,13 @@ public class UserBackupManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Hand off a restore session. */
|
/** Hand off a restore session. */
|
||||||
public IRestoreSession beginRestoreSession(String packageName, String transport,
|
public IRestoreSession beginRestoreSession(String packageName, String transport) {
|
||||||
@OperationType int operationType) {
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.v(
|
Slog.v(
|
||||||
TAG,
|
TAG,
|
||||||
addUserIdToLogMessage(
|
addUserIdToLogMessage(
|
||||||
mUserId,
|
mUserId,
|
||||||
"beginRestoreSession: pkg=" + packageName + " transport=" + transport
|
"beginRestoreSession: pkg=" + packageName + " transport=" + transport));
|
||||||
+ "operationType=" + operationType));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean needPermission = true;
|
boolean needPermission = true;
|
||||||
@@ -4073,6 +4067,17 @@ 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) {
|
synchronized (this) {
|
||||||
if (mActiveRestoreSession != null) {
|
if (mActiveRestoreSession != null) {
|
||||||
Slog.i(
|
Slog.i(
|
||||||
@@ -4356,6 +4361,34 @@ public class UserBackupManagerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
@OperationType int getOperationTypeFromTransport(TransportClient transportClient)
|
||||||
|
throws TransportNotAvailableException, RemoteException {
|
||||||
|
if (!shouldUseNewBackupEligibilityRules()) {
|
||||||
|
// Return the default to stick to the legacy behaviour.
|
||||||
|
return OperationType.BACKUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean shouldUseNewBackupEligibilityRules() {
|
||||||
|
return FeatureFlagUtils.isEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_USE_NEW_BACKUP_ELIGIBILITY_RULES);
|
||||||
|
}
|
||||||
|
|
||||||
private static String addUserIdToLogMessage(int userId, String message) {
|
private static String addUserIdToLogMessage(int userId, String message) {
|
||||||
return "[UserID:" + userId + "] " + message;
|
return "[UserID:" + userId + "] " + message;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import static org.testng.Assert.expectThrows;
|
|||||||
|
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.backup.BackupManager.OperationType;
|
|
||||||
import android.app.backup.IBackupManagerMonitor;
|
import android.app.backup.IBackupManagerMonitor;
|
||||||
import android.app.backup.IBackupObserver;
|
import android.app.backup.IBackupObserver;
|
||||||
import android.app.backup.IFullBackupRestoreObserver;
|
import android.app.backup.IFullBackupRestoreObserver;
|
||||||
@@ -874,8 +873,7 @@ public class BackupManagerServiceRoboTest {
|
|||||||
SecurityException.class,
|
SecurityException.class,
|
||||||
() ->
|
() ->
|
||||||
backupManagerService.requestBackup(
|
backupManagerService.requestBackup(
|
||||||
mUserTwoId, packages, observer, monitor, 0,
|
mUserTwoId, packages, observer, monitor, 0));
|
||||||
OperationType.BACKUP));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -893,11 +891,9 @@ public class BackupManagerServiceRoboTest {
|
|||||||
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
||||||
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
|
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. */
|
/** Test that the backup service routes methods correctly to the user that requests it. */
|
||||||
@@ -910,11 +906,9 @@ public class BackupManagerServiceRoboTest {
|
|||||||
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
||||||
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
|
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. */
|
/** Test that the backup service routes methods correctly to the user that requests it. */
|
||||||
@@ -927,11 +921,9 @@ public class BackupManagerServiceRoboTest {
|
|||||||
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
|
||||||
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1092,11 +1084,9 @@ public class BackupManagerServiceRoboTest {
|
|||||||
registerUser(backupManagerService, mUserOneId, mUserOneService);
|
registerUser(backupManagerService, mUserOneId, mUserOneService);
|
||||||
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
|
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. */
|
/** Test that the backup service does not route methods for non-registered users. */
|
||||||
@@ -1106,11 +1096,9 @@ public class BackupManagerServiceRoboTest {
|
|||||||
registerUser(backupManagerService, mUserOneId, mUserOneService);
|
registerUser(backupManagerService, mUserOneId, mUserOneService);
|
||||||
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
|
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. */
|
/** Test that the backup service routes methods correctly to the user that requests it. */
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
|||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.backup.BackupAgent;
|
||||||
import android.app.backup.BackupManager.OperationType;
|
import android.app.backup.BackupManager.OperationType;
|
||||||
import android.app.backup.IBackupManagerMonitor;
|
import android.app.backup.IBackupManagerMonitor;
|
||||||
import android.app.backup.IBackupObserver;
|
import android.app.backup.IBackupObserver;
|
||||||
@@ -30,6 +31,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import com.android.internal.backup.IBackupTransport;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
@@ -56,6 +58,7 @@ public class UserBackupManagerServiceTest {
|
|||||||
@Mock IBackupObserver mBackupObserver;
|
@Mock IBackupObserver mBackupObserver;
|
||||||
@Mock PackageManager mPackageManager;
|
@Mock PackageManager mPackageManager;
|
||||||
@Mock TransportClient mTransportClient;
|
@Mock TransportClient mTransportClient;
|
||||||
|
@Mock IBackupTransport mBackupTransport;
|
||||||
@Mock BackupEligibilityRules mBackupEligibilityRules;
|
@Mock BackupEligibilityRules mBackupEligibilityRules;
|
||||||
|
|
||||||
|
|
||||||
@@ -132,6 +135,33 @@ public class UserBackupManagerServiceTest {
|
|||||||
assertThat(params.mBackupEligibilityRules).isEqualTo(mBackupEligibilityRules);
|
assertThat(params.mBackupEligibilityRules).isEqualTo(mBackupEligibilityRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetOperationTypeFromTransport_returnsMigrationForMigrationTransport()
|
||||||
|
throws Exception {
|
||||||
|
// This is a temporary flag to control the new behaviour until it's ready to be fully
|
||||||
|
// rolled out.
|
||||||
|
mService.shouldUseNewBackupEligibilityRules = true;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private static PackageInfo getPackageInfo(String packageName) {
|
private static PackageInfo getPackageInfo(String packageName) {
|
||||||
PackageInfo packageInfo = new PackageInfo();
|
PackageInfo packageInfo = new PackageInfo();
|
||||||
packageInfo.applicationInfo = new ApplicationInfo();
|
packageInfo.applicationInfo = new ApplicationInfo();
|
||||||
@@ -141,6 +171,7 @@ public class UserBackupManagerServiceTest {
|
|||||||
|
|
||||||
private static class TestBackupService extends UserBackupManagerService {
|
private static class TestBackupService extends UserBackupManagerService {
|
||||||
boolean isEnabledStatePersisted = false;
|
boolean isEnabledStatePersisted = false;
|
||||||
|
boolean shouldUseNewBackupEligibilityRules = false;
|
||||||
|
|
||||||
TestBackupService(Context context, PackageManager packageManager) {
|
TestBackupService(Context context, PackageManager packageManager) {
|
||||||
super(context, packageManager);
|
super(context, packageManager);
|
||||||
@@ -158,5 +189,10 @@ public class UserBackupManagerServiceTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void updateStateOnBackupEnabled(boolean wasEnabled, boolean enable) {}
|
void updateStateOnBackupEnabled(boolean wasEnabled, boolean enable) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean shouldUseNewBackupEligibilityRules() {
|
||||||
|
return shouldUseNewBackupEligibilityRules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user