Merge changes I7f839a37,I11d8912b,Ia44b7b83,I47e80728

* changes:
  Move adb backup/restore operations to Trampoline
  Move restore operations to Trampoline
  Move backup operations to Trampoline
  Move settings operations to Trampoline
This commit is contained in:
Bernardo Rufino
2019-08-15 17:49:17 +00:00
committed by Android (Google) Code Review
5 changed files with 1092 additions and 1343 deletions

View File

@@ -20,18 +20,8 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.backup.BackupManager;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.IRestoreSession;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.util.SparseArray;
@@ -98,286 +88,6 @@ public class BackupManagerService {
*/
// TODO (b/118520567): Stop hardcoding system user when we pass in user id as a parameter
// ---------------------------------------------
// SETTINGS OPERATIONS
// ---------------------------------------------
/** Enable/disable the backup service. This is user-configurable via backup settings. */
public void setBackupEnabled(@UserIdInt int userId, boolean enable) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "setBackupEnabled()");
if (userBackupManagerService != null) {
userBackupManagerService.setBackupEnabled(enable);
}
}
/** Enable/disable automatic restore of app data at install time. */
public void setAutoRestore(@UserIdInt int userId, boolean autoRestore) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "setAutoRestore()");
if (userBackupManagerService != null) {
userBackupManagerService.setAutoRestore(autoRestore);
}
}
/**
* Return {@code true} if the backup mechanism is currently enabled, else returns {@code false}.
*/
public boolean isBackupEnabled(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "isBackupEnabled()");
return userBackupManagerService != null && userBackupManagerService.isBackupEnabled();
}
// ---------------------------------------------
// BACKUP OPERATIONS
// ---------------------------------------------
/** Checks if the given package {@code packageName} is eligible for backup. */
public boolean isAppEligibleForBackup(@UserIdInt int userId, String packageName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "isAppEligibleForBackup()");
return userBackupManagerService != null
&& userBackupManagerService.isAppEligibleForBackup(packageName);
}
/**
* Returns from the inputted packages {@code packages}, the ones that are eligible for backup.
*/
@Nullable
public String[] filterAppsEligibleForBackup(@UserIdInt int userId, String[] packages) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "filterAppsEligibleForBackup()");
return userBackupManagerService == null
? null
: userBackupManagerService.filterAppsEligibleForBackup(packages);
}
/**
* Run a backup pass immediately for any key-value backup applications that have declared that
* they have pending updates.
*/
public void backupNow(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "backupNow()");
if (userBackupManagerService != null) {
userBackupManagerService.backupNow();
}
}
/**
* Requests a backup for the inputted {@code packages} with a specified callback {@link
* IBackupManagerMonitor} for receiving events during the operation.
*/
public int requestBackup(
@UserIdInt int userId,
String[] packages,
IBackupObserver observer,
IBackupManagerMonitor monitor,
int flags) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "requestBackup()");
return userBackupManagerService == null
? BackupManager.ERROR_BACKUP_NOT_ALLOWED
: userBackupManagerService.requestBackup(packages, observer, monitor, flags);
}
/** Cancel all running backup operations. */
public void cancelBackups(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "cancelBackups()");
if (userBackupManagerService != null) {
userBackupManagerService.cancelBackups();
}
}
/**
* Used by the {@link JobScheduler} to run a full backup when conditions are right. The model we
* use is to perform one app backup per scheduled job execution, and to reschedule the job with
* zero latency as long as conditions remain right and we still have work to do.
*
* @return Whether ongoing work will continue. The return value here will be passed along as the
* return value to the callback {@link JobService#onStartJob(JobParameters)}.
*/
public boolean beginFullBackup(@UserIdInt int userId, FullBackupJob scheduledJob) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "beginFullBackup()");
return userBackupManagerService != null
&& userBackupManagerService.beginFullBackup(scheduledJob);
}
/**
* Used by the {@link JobScheduler} to end the current full backup task when conditions are no
* longer met for running the full backup job.
*/
public void endFullBackup(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "endFullBackup()");
if (userBackupManagerService != null) {
userBackupManagerService.endFullBackup();
}
}
/**
* Run a full backup pass for the given packages {@code packageNames}. Used by 'adb shell bmgr'.
*/
public void fullTransportBackup(@UserIdInt int userId, String[] packageNames) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "fullTransportBackup()");
if (userBackupManagerService != null) {
userBackupManagerService.fullTransportBackup(packageNames);
}
}
// ---------------------------------------------
// RESTORE OPERATIONS
// ---------------------------------------------
/**
* Used to run a restore pass for an application that is being installed. This should only be
* called from the {@link PackageManager}.
*/
public void restoreAtInstall(@UserIdInt int userId, String packageName, int token) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "restoreAtInstall()");
if (userBackupManagerService != null) {
userBackupManagerService.restoreAtInstall(packageName, token);
}
}
/**
* Begin a restore for the specified package {@code packageName} using the specified transport
* {@code transportName}.
*/
@Nullable
public IRestoreSession beginRestoreSession(
@UserIdInt int userId, String packageName, String transportName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");
return userBackupManagerService == null
? null
: userBackupManagerService.beginRestoreSession(packageName, transportName);
}
/**
* Get the restore-set token for the best-available restore set for this {@code packageName}:
* the active set if possible, else the ancestral one. Returns zero if none available.
*/
public long getAvailableRestoreToken(@UserIdInt int userId, String packageName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "getAvailableRestoreToken()");
return userBackupManagerService == null
? 0
: userBackupManagerService.getAvailableRestoreToken(packageName);
}
// ---------------------------------------------
// 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
// ---------------------------------------------

View File

@@ -33,11 +33,15 @@ import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.IRestoreSession;
import android.app.backup.ISelectBackupTransportCallback;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.FileUtils;
import android.os.Handler;
@@ -631,7 +635,7 @@ public class Trampoline extends IBackupManager.Stub {
public void restoreAtInstallForUser(int userId, String packageName, int token)
throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.restoreAtInstall(userId, packageName, token);
restoreAtInstall(userId, packageName, token);
}
}
@@ -640,11 +644,24 @@ public class Trampoline extends IBackupManager.Stub {
restoreAtInstallForUser(binderGetCallingUserId(), packageName, token);
}
/**
* Used to run a restore pass for an application that is being installed. This should only be
* called from the {@link PackageManager}.
*/
public void restoreAtInstall(@UserIdInt int userId, String packageName, int token) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "restoreAtInstall()");
if (userBackupManagerService != null) {
userBackupManagerService.restoreAtInstall(packageName, token);
}
}
@Override
public void setBackupEnabledForUser(@UserIdInt int userId, boolean isEnabled)
throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.setBackupEnabled(userId, isEnabled);
setBackupEnabled(userId, isEnabled);
}
}
@@ -653,10 +670,20 @@ public class Trampoline extends IBackupManager.Stub {
setBackupEnabledForUser(binderGetCallingUserId(), isEnabled);
}
/** Enable/disable the backup service. This is user-configurable via backup settings. */
public void setBackupEnabled(@UserIdInt int userId, boolean enable) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "setBackupEnabled()");
if (userBackupManagerService != null) {
userBackupManagerService.setBackupEnabled(enable);
}
}
@Override
public void setAutoRestoreForUser(int userId, boolean doAutoRestore) throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.setAutoRestore(userId, doAutoRestore);
setAutoRestore(userId, doAutoRestore);
}
}
@@ -665,9 +692,19 @@ public class Trampoline extends IBackupManager.Stub {
setAutoRestoreForUser(binderGetCallingUserId(), doAutoRestore);
}
/** Enable/disable automatic restore of app data at install time. */
public void setAutoRestore(@UserIdInt int userId, boolean autoRestore) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "setAutoRestore()");
if (userBackupManagerService != null) {
userBackupManagerService.setAutoRestore(autoRestore);
}
}
@Override
public boolean isBackupEnabledForUser(@UserIdInt int userId) throws RemoteException {
return isUserReadyForBackup(userId) && mService.isBackupEnabled(userId);
return isUserReadyForBackup(userId) && isBackupEnabled(userId);
}
@Override
@@ -675,22 +712,49 @@ public class Trampoline extends IBackupManager.Stub {
return isBackupEnabledForUser(binderGetCallingUserId());
}
@Override
public boolean setBackupPassword(String currentPw, String newPw) throws RemoteException {
int userId = binderGetCallingUserId();
return (isUserReadyForBackup(userId)) && mService.setBackupPassword(currentPw, newPw);
/**
* Return {@code true} if the backup mechanism is currently enabled, else returns {@code false}.
*/
public boolean isBackupEnabled(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "isBackupEnabled()");
return userBackupManagerService != null && userBackupManagerService.isBackupEnabled();
}
/** Sets the backup password used when running adb backup. */
@Override
public boolean setBackupPassword(String currentPassword, String newPassword) {
int userId = binderGetCallingUserId();
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
public void backupNowForUser(@UserIdInt int userId) throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.backupNow(userId);
backupNow(userId);
}
}
@@ -699,13 +763,56 @@ public class Trampoline extends IBackupManager.Stub {
backupNowForUser(binderGetCallingUserId());
}
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);
/**
* Run a backup pass immediately for any key-value backup applications that have declared that
* they have pending updates.
*/
public void backupNow(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "backupNow()");
if (userBackupManagerService != null) {
userBackupManagerService.backupNow();
}
}
/**
* 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);
}
}
@@ -713,14 +820,37 @@ public class Trampoline extends IBackupManager.Stub {
public void fullTransportBackupForUser(int userId, String[] packageNames)
throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.fullTransportBackup(userId, packageNames);
fullTransportBackup(userId, packageNames);
}
}
/**
* Run a full backup pass for the given packages {@code packageNames}. Used by 'adb shell bmgr'.
*/
public void fullTransportBackup(@UserIdInt int userId, String[] packageNames) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "fullTransportBackup()");
if (userBackupManagerService != null) {
userBackupManagerService.fullTransportBackup(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.
*/
@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);
}
}
@@ -734,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)
@@ -1080,8 +1230,23 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public IRestoreSession beginRestoreSessionForUser(
int userId, String packageName, String transportID) throws RemoteException {
return isUserReadyForBackup(userId) ? mService.beginRestoreSession(userId, packageName,
transportID) : null;
return isUserReadyForBackup(userId)
? beginRestoreSession(userId, packageName, transportID) : null;
}
/**
* Begin a restore for the specified package {@code packageName} using the specified transport
* {@code transportName}.
*/
@Nullable
public IRestoreSession beginRestoreSession(
@UserIdInt int userId, String packageName, String transportName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");
return userBackupManagerService == null
? null
: userBackupManagerService.beginRestoreSession(packageName, transportName);
}
@Override
@@ -1111,20 +1276,53 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public long getAvailableRestoreTokenForUser(int userId, String packageName) {
return isUserReadyForBackup(userId) ? mService.getAvailableRestoreToken(userId,
packageName) : 0;
return isUserReadyForBackup(userId) ? getAvailableRestoreToken(userId, packageName) : 0;
}
/**
* Get the restore-set token for the best-available restore set for this {@code packageName}:
* the active set if possible, else the ancestral one. Returns zero if none available.
*/
public long getAvailableRestoreToken(@UserIdInt int userId, String packageName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "getAvailableRestoreToken()");
return userBackupManagerService == null
? 0
: userBackupManagerService.getAvailableRestoreToken(packageName);
}
@Override
public boolean isAppEligibleForBackupForUser(int userId, String packageName) {
return isUserReadyForBackup(userId) && mService.isAppEligibleForBackup(userId,
return isUserReadyForBackup(userId) && isAppEligibleForBackup(userId,
packageName);
}
/** Checks if the given package {@code packageName} is eligible for backup. */
public boolean isAppEligibleForBackup(@UserIdInt int userId, String packageName) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "isAppEligibleForBackup()");
return userBackupManagerService != null
&& userBackupManagerService.isAppEligibleForBackup(packageName);
}
@Override
public String[] filterAppsEligibleForBackupForUser(int userId, String[] packages) {
return isUserReadyForBackup(userId) ? mService.filterAppsEligibleForBackup(userId,
packages) : null;
return isUserReadyForBackup(userId) ? filterAppsEligibleForBackup(userId, packages) : null;
}
/**
* Returns from the inputted packages {@code packages}, the ones that are eligible for backup.
*/
@Nullable
public String[] filterAppsEligibleForBackup(@UserIdInt int userId, String[] packages) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "filterAppsEligibleForBackup()");
return userBackupManagerService == null
? null
: userBackupManagerService.filterAppsEligibleForBackup(packages);
}
@Override
@@ -1133,7 +1331,7 @@ public class Trampoline extends IBackupManager.Stub {
if (!isUserReadyForBackup(userId)) {
return BackupManager.ERROR_BACKUP_NOT_ALLOWED;
}
return mService.requestBackup(userId, packages, observer, monitor, flags);
return requestBackup(userId, packages, observer, monitor, flags);
}
@Override
@@ -1143,10 +1341,28 @@ public class Trampoline extends IBackupManager.Stub {
observer, monitor, flags);
}
/**
* Requests a backup for the inputted {@code packages} with a specified callback {@link
* IBackupManagerMonitor} for receiving events during the operation.
*/
public int requestBackup(
@UserIdInt int userId,
String[] packages,
IBackupObserver observer,
IBackupManagerMonitor monitor,
int flags) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "requestBackup()");
return userBackupManagerService == null
? BackupManager.ERROR_BACKUP_NOT_ALLOWED
: userBackupManagerService.requestBackup(packages, observer, monitor, flags);
}
@Override
public void cancelBackupsForUser(@UserIdInt int userId) throws RemoteException {
if (isUserReadyForBackup(userId)) {
mService.cancelBackups(userId);
cancelBackups(userId);
}
}
@@ -1155,9 +1371,19 @@ public class Trampoline extends IBackupManager.Stub {
cancelBackupsForUser(binderGetCallingUserId());
}
/** Cancel all running backup operations. */
public void cancelBackups(@UserIdInt int userId) {
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "cancelBackups()");
if (userBackupManagerService != null) {
userBackupManagerService.cancelBackups();
}
}
/**
* Returns a {@link UserHandle} for the user that has {@code ancestralSerialNumber} as the
* serial number of the its ancestral work profile or null if there is no {@link
* serial number of its ancestral work profile or null if there is no {@link
* UserBackupManagerService} associated with that user.
*
* <p> The ancestral work profile is set by {@link #setAncestralSerialNumber(long)}
@@ -1225,15 +1451,38 @@ public class Trampoline extends IBackupManager.Stub {
}
}
// Full backup/restore entry points - non-Binder; called directly
// by the full-backup scheduled job
/* package */ boolean beginFullBackup(@UserIdInt int userId, FullBackupJob scheduledJob) {
return (isUserReadyForBackup(userId)) && mService.beginFullBackup(userId, scheduledJob);
/**
* Used by the {@link JobScheduler} to run a full backup when conditions are right. The model we
* use is to perform one app backup per scheduled job execution, and to reschedule the job with
* zero latency as long as conditions remain right and we still have work to do.
*
* @return Whether ongoing work will continue. The return value here will be passed along as the
* return value to the callback {@link JobService#onStartJob(JobParameters)}.
*/
public boolean beginFullBackup(@UserIdInt int userId, FullBackupJob scheduledJob) {
if (!isUserReadyForBackup(userId)) {
return false;
}
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "beginFullBackup()");
return userBackupManagerService != null
&& userBackupManagerService.beginFullBackup(scheduledJob);
}
/* package */ void endFullBackup(@UserIdInt int userId) {
if (isUserReadyForBackup(userId)) {
mService.endFullBackup(userId);
/**
* Used by the {@link JobScheduler} to end the current full backup task when conditions are no
* longer met for running the full backup job.
*/
public void endFullBackup(@UserIdInt int userId) {
if (!isUserReadyForBackup(userId)) {
return;
}
UserBackupManagerService userBackupManagerService =
getServiceForUserIfCallerHasPermission(userId, "endFullBackup()");
if (userBackupManagerService != null) {
userBackupManagerService.endFullBackup();
}
}

View File

@@ -36,9 +36,6 @@ import static org.testng.Assert.expectThrows;
import android.annotation.UserIdInt;
import android.app.Application;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.os.Process;
@@ -215,786 +212,6 @@ public class BackupManagerServiceTest {
backupManagerService.getServiceForUserIfCallerHasPermission(mUserOneId, "test"));
}
// ---------------------------------------------
// Settings tests
// ---------------------------------------------
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testSetBackupEnabled_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class,
() -> backupManagerService.setBackupEnabled(mUserTwoId, true));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testSetBackupEnabled_withPermission_propagatesForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.setBackupEnabled(mUserTwoId, true);
verify(mUserTwoService).setBackupEnabled(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetBackupEnabled_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.setBackupEnabled(mUserOneId, true);
verify(mUserOneService).setBackupEnabled(true);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetBackupEnabled_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.setBackupEnabled(mUserTwoId, true);
verify(mUserOneService, never()).setBackupEnabled(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetAutoRestore_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.setAutoRestore(mUserOneId, true);
verify(mUserOneService).setAutoRestore(true);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetAutoRestore_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.setAutoRestore(mUserTwoId, true);
verify(mUserOneService, never()).setAutoRestore(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testIsBackupEnabled_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.isBackupEnabled(mUserOneId);
verify(mUserOneService).isBackupEnabled();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testIsBackupEnabled_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.isBackupEnabled(mUserTwoId);
verify(mUserOneService, never()).isBackupEnabled();
}
// ---------------------------------------------
// Backup tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testIsAppEligibleForBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.isAppEligibleForBackup(mUserOneId, TEST_PACKAGE);
verify(mUserOneService).isAppEligibleForBackup(TEST_PACKAGE);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testIsAppEligibleForBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.isAppEligibleForBackup(mUserTwoId, TEST_PACKAGE);
verify(mUserOneService, never()).isAppEligibleForBackup(TEST_PACKAGE);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testFilterAppsEligibleForBackup_onRegisteredUser_callsMethodForUser()
throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.filterAppsEligibleForBackup(mUserOneId, packages);
verify(mUserOneService).filterAppsEligibleForBackup(packages);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testFilterAppsEligibleForBackup_onUnknownUser_doesNotPropagateCall()
throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.filterAppsEligibleForBackup(mUserTwoId, packages);
verify(mUserOneService, never()).filterAppsEligibleForBackup(packages);
}
/**
* Test verifying that {@link BackupManagerService#backupNow(int)} throws a {@link
* SecurityException} if the caller does not have INTERACT_ACROSS_USERS_FULL permission.
*/
@Test
public void testBackupNow_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(SecurityException.class, () -> backupManagerService.backupNow(mUserTwoId));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testBackupNow_withPermission_propagatesForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.backupNow(mUserTwoId);
verify(mUserTwoService).backupNow();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBackupNow_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.backupNow(mUserOneId);
verify(mUserOneService).backupNow();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBackupNow_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.backupNow(mUserTwoId);
verify(mUserOneService, never()).backupNow();
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testRequestBackup_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
expectThrows(
SecurityException.class,
() ->
backupManagerService.requestBackup(
mUserTwoId, packages, observer, monitor, 0));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testRequestBackup_withPermission_propagatesForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
verify(mUserTwoService).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRequestBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.requestBackup(mUserOneId, packages, observer, monitor, /* flags */ 0);
verify(mUserOneService).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRequestBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
verify(mUserOneService, never()).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/**
* Test verifying that {@link BackupManagerService#cancelBackups(int)} throws a {@link
* SecurityException} if the caller does not have INTERACT_ACROSS_USERS_FULL permission.
*/
@Test
public void testCancelBackups_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(SecurityException.class, () -> backupManagerService.cancelBackups(mUserTwoId));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testCancelBackups_withPermission_propagatesForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.cancelBackups(mUserTwoId);
verify(mUserTwoService).cancelBackups();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testCancelBackups_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.cancelBackups(mUserOneId);
verify(mUserOneService).cancelBackups();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testCancelBackups_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.cancelBackups(mUserTwoId);
verify(mUserOneService, never()).cancelBackups();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBeginFullBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(UserHandle.USER_SYSTEM, mUserOneService);
BackupManagerService backupManagerService = createService();
FullBackupJob job = new FullBackupJob();
backupManagerService.beginFullBackup(UserHandle.USER_SYSTEM, job);
verify(mUserOneService).beginFullBackup(job);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBeginFullBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
BackupManagerService backupManagerService = createService();
FullBackupJob job = new FullBackupJob();
backupManagerService.beginFullBackup(UserHandle.USER_SYSTEM, job);
verify(mUserOneService, never()).beginFullBackup(job);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testEndFullBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(UserHandle.USER_SYSTEM, mUserOneService);
BackupManagerService backupManagerService = createService();
backupManagerService.endFullBackup(UserHandle.USER_SYSTEM);
verify(mUserOneService).endFullBackup();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testEndFullBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
BackupManagerService backupManagerService = createService();
backupManagerService.endFullBackup(UserHandle.USER_SYSTEM);
verify(mUserOneService, never()).endFullBackup();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testFullTransportBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.fullTransportBackup(mUserOneId, packages);
verify(mUserOneService).fullTransportBackup(packages);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testFullTransportBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.fullTransportBackup(mUserTwoId, packages);
verify(mUserOneService, never()).fullTransportBackup(packages);
}
// ---------------------------------------------
// Restore tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRestoreAtInstall_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.restoreAtInstall(mUserOneId, TEST_PACKAGE, /* token */ 0);
verify(mUserOneService).restoreAtInstall(TEST_PACKAGE, /* token */ 0);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testRestoreAtInstall_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.restoreAtInstall(mUserTwoId, TEST_PACKAGE, /* token */ 0);
verify(mUserOneService, never()).restoreAtInstall(TEST_PACKAGE, /* token */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBeginRestoreSession_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.beginRestoreSession(mUserOneId, TEST_PACKAGE, TEST_TRANSPORT);
verify(mUserOneService).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBeginRestoreSession_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.beginRestoreSession(mUserTwoId, TEST_PACKAGE, TEST_TRANSPORT);
verify(mUserOneService, never()).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testGetAvailableRestoreToken_onRegisteredUser_callsMethodForUser()
throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.getAvailableRestoreToken(mUserOneId, TEST_PACKAGE);
verify(mUserOneService).getAvailableRestoreToken(TEST_PACKAGE);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testGetAvailableRestoreToken_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.getAvailableRestoreToken(mUserTwoId, TEST_PACKAGE);
verify(mUserOneService, never()).getAvailableRestoreToken(TEST_PACKAGE);
}
// ---------------------------------------------
// Adb backup/restore tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetBackupPassword_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(UserHandle.USER_SYSTEM, mUserOneService);
BackupManagerService backupManagerService = createService();
backupManagerService.setBackupPassword("currentPassword", "newPassword");
verify(mUserOneService).setBackupPassword("currentPassword", "newPassword");
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetBackupPassword_onUnknownUser_doesNotPropagateCall() throws Exception {
BackupManagerService backupManagerService = createService();
backupManagerService.setBackupPassword("currentPassword", "newPassword");
verify(mUserOneService, never()).setBackupPassword("currentPassword", "newPassword");
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testHasBackupPassword_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(UserHandle.USER_SYSTEM, mUserOneService);
BackupManagerService backupManagerService = createService();
backupManagerService.hasBackupPassword();
verify(mUserOneService).hasBackupPassword();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testHasBackupPassword_onUnknownUser_doesNotPropagateCall() throws Exception {
BackupManagerService backupManagerService = createService();
backupManagerService.hasBackupPassword();
verify(mUserOneService, never()).hasBackupPassword();
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbBackup_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class,
() ->
backupManagerService.adbBackup(
mUserTwoId,
/* parcelFileDescriptor*/ null,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
null));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbBackup_withPermission_propagatesForNonCallingUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.adbBackup(
mUserTwoId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserTwoService)
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAdbBackup_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.adbBackup(
mUserOneId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserOneService)
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAdbBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.adbBackup(
mUserTwoId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserOneService, never())
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbRestore_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class, () -> backupManagerService.adbRestore(mUserTwoId, null));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbRestore_withPermission_propagatesForNonCallingUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
registerUser(mUserTwoId, mUserTwoService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.adbRestore(mUserTwoId, parcelFileDescriptor);
verify(mUserTwoService).adbRestore(parcelFileDescriptor);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAdbRestore_onRegisteredUser_callsMethodForUser() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.adbRestore(mUserOneId, parcelFileDescriptor);
verify(mUserOneService).adbRestore(parcelFileDescriptor);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAdbRestore_onUnknownUser_doesNotPropagateCall() throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.adbRestore(mUserTwoId, parcelFileDescriptor);
verify(mUserOneService, never()).adbRestore(parcelFileDescriptor);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAcknowledgeAdbBackupOrRestore_onRegisteredUser_callsMethodForUser()
throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
IFullBackupRestoreObserver observer = mock(IFullBackupRestoreObserver.class);
backupManagerService.acknowledgeAdbBackupOrRestore(
mUserOneId,
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
verify(mUserOneService)
.acknowledgeAdbBackupOrRestore(
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAcknowledgeAdbBackupOrRestore_onUnknownUser_doesNotPropagateCall()
throws Exception {
registerUser(mUserOneId, mUserOneService);
BackupManagerService backupManagerService = createService();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
IFullBackupRestoreObserver observer = mock(IFullBackupRestoreObserver.class);
backupManagerService.acknowledgeAdbBackupOrRestore(
mUserTwoId,
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
verify(mUserOneService, never())
.acknowledgeAdbBackupOrRestore(
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
}
// ---------------------------------------------
// Lifecycle tests
// ---------------------------------------------

View File

@@ -27,13 +27,18 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf;
import static org.testng.Assert.expectThrows;
import android.annotation.UserIdInt;
import android.app.Application;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.ISelectBackupTransportCallback;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
@@ -58,6 +63,8 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContextWrapper;
import java.io.File;
/** Tests for {@link com.android.server.backup.Trampoline}. */
@RunWith(RobolectricTestRunner.class)
@Config(
@@ -72,6 +79,7 @@ import org.robolectric.shadows.ShadowContextWrapper;
public class TrampolineRoboTest {
private static final String TEST_PACKAGE = "package";
private static final String TEST_TRANSPORT = "transport";
private static final String[] ADB_TEST_PACKAGES = {TEST_PACKAGE};
private Context mContext;
private ShadowContextWrapper mShadowContext;
@@ -616,10 +624,806 @@ public class TrampolineRoboTest {
"dataManagementLabel");
}
// ---------------------------------------------
// Settings tests
// ---------------------------------------------
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testSetBackupEnabled_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class,
() -> backupManagerService.setBackupEnabled(mUserTwoId, true));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testSetBackupEnabled_withPermission_propagatesForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.setBackupEnabled(mUserTwoId, true);
verify(mUserTwoService).setBackupEnabled(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetBackupEnabled_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.setBackupEnabled(mUserOneId, true);
verify(mUserOneService).setBackupEnabled(true);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetBackupEnabled_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.setBackupEnabled(mUserTwoId, true);
verify(mUserOneService, never()).setBackupEnabled(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetAutoRestore_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.setAutoRestore(mUserOneId, true);
verify(mUserOneService).setAutoRestore(true);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetAutoRestore_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.setAutoRestore(mUserTwoId, true);
verify(mUserOneService, never()).setAutoRestore(true);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testIsBackupEnabled_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.isBackupEnabled(mUserOneId);
verify(mUserOneService).isBackupEnabled();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testIsBackupEnabled_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.isBackupEnabled(mUserTwoId);
verify(mUserOneService, never()).isBackupEnabled();
}
// ---------------------------------------------
// Backup tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testIsAppEligibleForBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.isAppEligibleForBackup(mUserOneId, TEST_PACKAGE);
verify(mUserOneService).isAppEligibleForBackup(TEST_PACKAGE);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testIsAppEligibleForBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.isAppEligibleForBackup(mUserTwoId, TEST_PACKAGE);
verify(mUserOneService, never()).isAppEligibleForBackup(TEST_PACKAGE);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testFilterAppsEligibleForBackup_onRegisteredUser_callsMethodForUser()
throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.filterAppsEligibleForBackup(mUserOneId, packages);
verify(mUserOneService).filterAppsEligibleForBackup(packages);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testFilterAppsEligibleForBackup_onUnknownUser_doesNotPropagateCall()
throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.filterAppsEligibleForBackup(mUserTwoId, packages);
verify(mUserOneService, never()).filterAppsEligibleForBackup(packages);
}
/**
* Test verifying that {@link BackupManagerService#backupNow(int)} throws a {@link
* SecurityException} if the caller does not have INTERACT_ACROSS_USERS_FULL permission.
*/
@Test
public void testBackupNow_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(SecurityException.class, () -> backupManagerService.backupNow(mUserTwoId));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testBackupNow_withPermission_propagatesForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.backupNow(mUserTwoId);
verify(mUserTwoService).backupNow();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBackupNow_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.backupNow(mUserOneId);
verify(mUserOneService).backupNow();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBackupNow_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.backupNow(mUserTwoId);
verify(mUserOneService, never()).backupNow();
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testRequestBackup_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
expectThrows(
SecurityException.class,
() ->
backupManagerService.requestBackup(
mUserTwoId, packages, observer, monitor, 0));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testRequestBackup_withPermission_propagatesForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
verify(mUserTwoService).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRequestBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.requestBackup(mUserOneId, packages, observer, monitor, /* flags */ 0);
verify(mUserOneService).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRequestBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
String[] packages = {TEST_PACKAGE};
IBackupObserver observer = mock(IBackupObserver.class);
IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.requestBackup(mUserTwoId, packages, observer, monitor, /* flags */ 0);
verify(mUserOneService, never()).requestBackup(packages, observer, monitor, /* flags */ 0);
}
/**
* Test verifying that {@link BackupManagerService#cancelBackups(int)} throws a {@link
* SecurityException} if the caller does not have INTERACT_ACROSS_USERS_FULL permission.
*/
@Test
public void testCancelBackups_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(SecurityException.class, () -> backupManagerService.cancelBackups(mUserTwoId));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testCancelBackups_withPermission_propagatesForNonCallingUser() {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.cancelBackups(mUserTwoId);
verify(mUserTwoService).cancelBackups();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testCancelBackups_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.cancelBackups(mUserOneId);
verify(mUserOneService).cancelBackups();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testCancelBackups_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.cancelBackups(mUserTwoId);
verify(mUserOneService, never()).cancelBackups();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBeginFullBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserOneService);
FullBackupJob job = new FullBackupJob();
backupManagerService.beginFullBackup(UserHandle.USER_SYSTEM, job);
verify(mUserOneService).beginFullBackup(job);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBeginFullBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
FullBackupJob job = new FullBackupJob();
backupManagerService.beginFullBackup(UserHandle.USER_SYSTEM, job);
verify(mUserOneService, never()).beginFullBackup(job);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testEndFullBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserOneService);
backupManagerService.endFullBackup(UserHandle.USER_SYSTEM);
verify(mUserOneService).endFullBackup();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testEndFullBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
backupManagerService.endFullBackup(UserHandle.USER_SYSTEM);
verify(mUserOneService, never()).endFullBackup();
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testFullTransportBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.fullTransportBackup(mUserOneId, packages);
verify(mUserOneService).fullTransportBackup(packages);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testFullTransportBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
String[] packages = {TEST_PACKAGE};
backupManagerService.fullTransportBackup(mUserTwoId, packages);
verify(mUserOneService, never()).fullTransportBackup(packages);
}
// ---------------------------------------------
// Restore tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testRestoreAtInstall_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.restoreAtInstall(mUserOneId, TEST_PACKAGE, /* token */ 0);
verify(mUserOneService).restoreAtInstall(TEST_PACKAGE, /* token */ 0);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testRestoreAtInstall_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.restoreAtInstall(mUserTwoId, TEST_PACKAGE, /* token */ 0);
verify(mUserOneService, never()).restoreAtInstall(TEST_PACKAGE, /* token */ 0);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testBeginRestoreSession_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.beginRestoreSession(mUserOneId, TEST_PACKAGE, TEST_TRANSPORT);
verify(mUserOneService).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testBeginRestoreSession_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.beginRestoreSession(mUserTwoId, TEST_PACKAGE, TEST_TRANSPORT);
verify(mUserOneService, never()).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testGetAvailableRestoreToken_onRegisteredUser_callsMethodForUser()
throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.getAvailableRestoreToken(mUserOneId, TEST_PACKAGE);
verify(mUserOneService).getAvailableRestoreToken(TEST_PACKAGE);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testGetAvailableRestoreToken_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.getAvailableRestoreToken(mUserTwoId, TEST_PACKAGE);
verify(mUserOneService, never()).getAvailableRestoreToken(TEST_PACKAGE);
}
// ---------------------------------------------
// Adb backup/restore tests
// ---------------------------------------------
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testSetBackupPassword_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserOneService);
ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM));
backupManagerService.setBackupPassword("currentPassword", "newPassword");
verify(mUserOneService).setBackupPassword("currentPassword", "newPassword");
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testSetBackupPassword_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
backupManagerService.setBackupPassword("currentPassword", "newPassword");
verify(mUserOneService, never()).setBackupPassword("currentPassword", "newPassword");
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testHasBackupPassword_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserOneService);
ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM));
backupManagerService.hasBackupPassword();
verify(mUserOneService).hasBackupPassword();
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testHasBackupPassword_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createService();
backupManagerService.hasBackupPassword();
verify(mUserOneService, never()).hasBackupPassword();
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbBackup_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class,
() ->
backupManagerService.adbBackup(
mUserTwoId,
/* parcelFileDescriptor*/ null,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
null));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbBackup_withPermission_propagatesForNonCallingUser() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.adbBackup(
mUserTwoId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserTwoService)
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAdbBackup_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.adbBackup(
mUserOneId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserOneService)
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAdbBackup_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.adbBackup(
mUserTwoId,
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
verify(mUserOneService, never())
.adbBackup(
parcelFileDescriptor,
/* includeApks */ true,
/* includeObbs */ true,
/* includeShared */ true,
/* doWidgets */ true,
/* doAllApps */ true,
/* includeSystem */ true,
/* doCompress */ true,
/* doKeyValue */ true,
ADB_TEST_PACKAGES);
}
/**
* Test that the backup services throws a {@link SecurityException} if the caller does not have
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbRestore_withoutPermission_throwsSecurityExceptionForNonCallingUser() {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
expectThrows(
SecurityException.class, () -> backupManagerService.adbRestore(mUserTwoId, null));
}
/**
* Test that the backup service does not throw a {@link SecurityException} if the caller has
* INTERACT_ACROSS_USERS_FULL permission and passes a different user id.
*/
@Test
public void testAdbRestore_withPermission_propagatesForNonCallingUser() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
registerUser(backupManagerService, mUserTwoId, mUserTwoService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ true);
backupManagerService.adbRestore(mUserTwoId, parcelFileDescriptor);
verify(mUserTwoService).adbRestore(parcelFileDescriptor);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAdbRestore_onRegisteredUser_callsMethodForUser() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
backupManagerService.adbRestore(mUserOneId, parcelFileDescriptor);
verify(mUserOneService).adbRestore(parcelFileDescriptor);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAdbRestore_onUnknownUser_doesNotPropagateCall() throws Exception {
Trampoline backupManagerService = createSystemRegisteredService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
ParcelFileDescriptor parcelFileDescriptor = getFileDescriptorForAdbTest();
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
backupManagerService.adbRestore(mUserTwoId, parcelFileDescriptor);
verify(mUserOneService, never()).adbRestore(parcelFileDescriptor);
}
private ParcelFileDescriptor getFileDescriptorForAdbTest() throws Exception {
File testFile = new File(mContext.getFilesDir(), "test");
testFile.createNewFile();
return ParcelFileDescriptor.open(testFile, ParcelFileDescriptor.MODE_READ_WRITE);
}
/** Test that the backup service routes methods correctly to the user that requests it. */
@Test
public void testAcknowledgeAdbBackupOrRestore_onRegisteredUser_callsMethodForUser()
throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false);
IFullBackupRestoreObserver observer = mock(IFullBackupRestoreObserver.class);
backupManagerService.acknowledgeAdbBackupOrRestore(
mUserOneId,
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
verify(mUserOneService)
.acknowledgeAdbBackupOrRestore(
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
}
/** Test that the backup service does not route methods for non-registered users. */
@Test
public void testAcknowledgeAdbBackupOrRestore_onUnknownUser_doesNotPropagateCall()
throws Exception {
Trampoline backupManagerService = createService();
registerUser(backupManagerService, mUserOneId, mUserOneService);
setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false);
IFullBackupRestoreObserver observer = mock(IFullBackupRestoreObserver.class);
backupManagerService.acknowledgeAdbBackupOrRestore(
mUserTwoId,
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
verify(mUserOneService, never())
.acknowledgeAdbBackupOrRestore(
/* token */ 0,
/* allow */ true,
"currentPassword",
"encryptionPassword",
observer);
}
private Trampoline createService() {
return new Trampoline(mContext);
}
private Trampoline createSystemRegisteredService() {
Trampoline trampoline = createService();
registerUser(trampoline, UserHandle.USER_SYSTEM, mock(UserBackupManagerService.class));
return trampoline;
}
private void registerUser(
Trampoline trampoline, int userId, UserBackupManagerService userBackupManagerService) {
trampoline.setBackupServiceActive(userId, true);

View File

@@ -481,164 +481,6 @@ public class TrampolineTest {
TrampolineTestable.sRememberActivatedFiles.get(NON_USER_SYSTEM), true));
}
@Test
public void restoreAtInstallForUser_forwarded() throws Exception {
mTrampoline.restoreAtInstallForUser(mUserId, PACKAGE_NAME, 123);
verify(mBackupManagerServiceMock).restoreAtInstall(mUserId, PACKAGE_NAME, 123);
}
@Test
public void restoreAtInstall_forwarded() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.restoreAtInstall(PACKAGE_NAME, 123);
verify(mBackupManagerServiceMock).restoreAtInstall(mUserId, PACKAGE_NAME, 123);
}
@Test
public void setBackupEnabledForUser_forwarded() throws Exception {
mTrampoline.setBackupEnabledForUser(mUserId, true);
verify(mBackupManagerServiceMock).setBackupEnabled(mUserId, true);
}
@Test
public void setBackupEnabled_forwardedToCallingUserId() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.setBackupEnabled(true);
verify(mBackupManagerServiceMock).setBackupEnabled(mUserId, true);
}
@Test
public void setAutoRestoreForUser_forwarded() throws Exception {
mTrampoline.setAutoRestoreForUser(mUserId, true);
verify(mBackupManagerServiceMock).setAutoRestore(mUserId, true);
}
@Test
public void setAutoRestore_forwarded() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.setAutoRestore(true);
verify(mBackupManagerServiceMock).setAutoRestore(mUserId, true);
}
@Test
public void isBackupEnabledForUser_forwarded() throws Exception {
mTrampoline.isBackupEnabledForUser(mUserId);
verify(mBackupManagerServiceMock).isBackupEnabled(mUserId);
}
@Test
public void isBackupEnabled_forwardedToCallingUserId() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.isBackupEnabled();
verify(mBackupManagerServiceMock).isBackupEnabled(mUserId);
}
@Test
public void setBackupPassword_forwarded() throws Exception {
mTrampoline.setBackupPassword(CURRENT_PASSWORD, NEW_PASSWORD);
verify(mBackupManagerServiceMock).setBackupPassword(CURRENT_PASSWORD, NEW_PASSWORD);
}
@Test
public void hasBackupPassword_forwarded() throws Exception {
mTrampoline.hasBackupPassword();
verify(mBackupManagerServiceMock).hasBackupPassword();
}
@Test
public void backupNowForUser_forwarded() throws Exception {
mTrampoline.backupNowForUser(mUserId);
verify(mBackupManagerServiceMock).backupNow(mUserId);
}
@Test
public void backupNow_forwardedToCallingUserId() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.backupNow();
verify(mBackupManagerServiceMock).backupNow(mUserId);
}
@Test
public void adbBackup_forwarded() throws Exception {
mTrampoline.adbBackup(mUserId, mParcelFileDescriptorMock, true, true,
true, true, true, true, true, true,
PACKAGE_NAMES);
verify(mBackupManagerServiceMock).adbBackup(mUserId, mParcelFileDescriptorMock, true,
true, true, true, true, true, true, true, PACKAGE_NAMES);
}
@Test
public void fullTransportBackupForUser_forwarded() throws Exception {
mTrampoline.fullTransportBackupForUser(mUserId, PACKAGE_NAMES);
verify(mBackupManagerServiceMock).fullTransportBackup(mUserId, PACKAGE_NAMES);
}
@Test
public void adbRestore_forwarded() throws Exception {
mTrampoline.adbRestore(mUserId, mParcelFileDescriptorMock);
verify(mBackupManagerServiceMock).adbRestore(mUserId, mParcelFileDescriptorMock);
}
@Test
public void acknowledgeFullBackupOrRestoreForUser_forwarded() throws Exception {
mTrampoline.acknowledgeFullBackupOrRestoreForUser(
mUserId,
123,
true,
CURRENT_PASSWORD,
ENCRYPTION_PASSWORD,
mFullBackupRestoreObserverMock);
verify(mBackupManagerServiceMock)
.acknowledgeAdbBackupOrRestore(
mUserId,
123,
true,
CURRENT_PASSWORD,
ENCRYPTION_PASSWORD,
mFullBackupRestoreObserverMock);
}
@Test
public void acknowledgeFullBackupOrRestore_forwarded() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.acknowledgeFullBackupOrRestore(123, true, CURRENT_PASSWORD, ENCRYPTION_PASSWORD,
mFullBackupRestoreObserverMock);
verify(mBackupManagerServiceMock)
.acknowledgeAdbBackupOrRestore(
mUserId,
123,
true,
CURRENT_PASSWORD,
ENCRYPTION_PASSWORD,
mFullBackupRestoreObserverMock);
}
@Test
public void selectBackupTransportAsyncForUser_beforeUserUnlocked_notifiesBackupNotAllowed()
throws Exception {
@@ -688,79 +530,6 @@ public class TrampolineTest {
// No crash.
}
@Test
public void getAvailableRestoreTokenForUser_forwarded() {
when(mBackupManagerServiceMock.getAvailableRestoreToken(mUserId, PACKAGE_NAME))
.thenReturn(123L);
assertEquals(123, mTrampoline.getAvailableRestoreTokenForUser(mUserId, PACKAGE_NAME));
verify(mBackupManagerServiceMock).getAvailableRestoreToken(mUserId, PACKAGE_NAME);
}
@Test
public void isAppEligibleForBackupForUser_forwarded() {
when(mBackupManagerServiceMock.isAppEligibleForBackup(mUserId, PACKAGE_NAME))
.thenReturn(true);
assertTrue(mTrampoline.isAppEligibleForBackupForUser(mUserId, PACKAGE_NAME));
verify(mBackupManagerServiceMock).isAppEligibleForBackup(mUserId, PACKAGE_NAME);
}
@Test
public void requestBackupForUser_forwarded() throws Exception {
when(mBackupManagerServiceMock.requestBackup(mUserId, PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123)).thenReturn(456);
assertEquals(456, mTrampoline.requestBackupForUser(mUserId, PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123));
verify(mBackupManagerServiceMock).requestBackup(mUserId, PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123);
}
@Test
public void requestBackup_forwardedToCallingUserId() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
when(mBackupManagerServiceMock.requestBackup(mUserId, PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123)).thenReturn(456);
assertEquals(456, mTrampoline.requestBackup(PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123));
verify(mBackupManagerServiceMock).requestBackup(mUserId, PACKAGE_NAMES,
mBackupObserverMock, mBackupManagerMonitorMock, 123);
}
@Test
public void cancelBackupsForUser_forwarded() throws Exception {
mTrampoline.cancelBackupsForUser(mUserId);
verify(mBackupManagerServiceMock).cancelBackups(mUserId);
}
@Test
public void cancelBackups_forwardedToCallingUserId() throws Exception {
TrampolineTestable.sCallingUserId = mUserId;
mTrampoline.cancelBackups();
verify(mBackupManagerServiceMock).cancelBackups(mUserId);
}
@Test
public void beginFullBackup_forwarded() throws Exception {
FullBackupJob fullBackupJob = new FullBackupJob();
when(mBackupManagerServiceMock.beginFullBackup(mUserId, fullBackupJob)).thenReturn(true);
assertTrue(mTrampoline.beginFullBackup(mUserId, fullBackupJob));
verify(mBackupManagerServiceMock).beginFullBackup(mUserId, fullBackupJob);
}
@Test
public void endFullBackup_forwarded() {
mTrampoline.endFullBackup(mUserId);
verify(mBackupManagerServiceMock).endFullBackup(mUserId);
}
@Test
public void dump_callerDoesNotHavePermission_ignored() {
when(mContextMock.checkCallingOrSelfPermission(