summaryrefslogtreecommitdiff
path: root/cmds/bmgr
diff options
context:
space:
mode:
authorAnnie Meng <anniemeng@google.com>2019-01-22 15:32:25 +0000
committerAnnie Meng <anniemeng@google.com>2019-01-24 15:14:09 +0000
commitbdb8848abe9999fbd302d71f2c0ce62b9a09fd8a (patch)
treeb2c8d96aeb9ee6e07dc9434cabe619c8857b50da /cmds/bmgr
parent25b54058c0e3bb7e0630650f750092f7ccd2289f (diff)
[Multi-user] Disable backup by default in non-system users
Key changes in this CL: - Backup is now disabled by default in non-system users unless DPM activates backup for this user AND the system user is activated. This provides gating for the multi-user B&R feature. - Activation is done via an 'activate' file that is per-user (but lives in the system user directory to account for locked users). - isBackupServiceActive() handles both locked and unlocked users. - Added a bmgr command to expose isBackupServiceActive() for testing purposes and enforce appropriate permissions. Future CLs: - Handle future migration to backup on by default for non-system users - Change CTS tests to use the new bmgr command Bug: 121306407 Test: 1) atest TrampolineTest 2) Start system user -> service started; run backup and restore successfully 3) Start non-system user -> ignored; 4) adb shell bmgr --user 0 activate true -> security exception; adb shell bmgr --user 10 activate true -> security exception (work profile); adb shell bmgr --user 11 activate true/false -> creates/deletes activate file and starts/stops the service Change-Id: Ic77db9b8b2e5170dcf89bef863dac4713730797a
Diffstat (limited to 'cmds/bmgr')
-rw-r--r--cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java46
1 files changed, 39 insertions, 7 deletions
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
index 3defdc5467c8..062ba655640e 100644
--- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
+++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
@@ -102,7 +102,17 @@ public class Bmgr {
String op = nextArg();
Slog.v(TAG, "Running " + op + " for user:" + userId);
- if (!isBmgrActive(userId)) {
+ if (mBmgr == null) {
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ return;
+ }
+
+ if ("activate".equals(op)) {
+ doActivateService(userId);
+ return;
+ }
+
+ if (!isBackupActive(userId)) {
return;
}
@@ -175,12 +185,7 @@ public class Bmgr {
showUsage();
}
- boolean isBmgrActive(@UserIdInt int userId) {
- if (mBmgr == null) {
- System.err.println(BMGR_NOT_RUNNING_ERR);
- return false;
- }
-
+ boolean isBackupActive(@UserIdInt int userId) {
try {
if (!mBmgr.isBackupServiceActive(userId)) {
System.err.println(BMGR_NOT_RUNNING_ERR);
@@ -845,6 +850,27 @@ public class Bmgr {
}
}
+ private void doActivateService(int userId) {
+ String arg = nextArg();
+ if (arg == null) {
+ showUsage();
+ return;
+ }
+
+ try {
+ boolean activate = Boolean.parseBoolean(arg);
+ mBmgr.setBackupServiceActive(userId, activate);
+ System.out.println(
+ "Backup service now "
+ + (activate ? "activated" : "deactivated")
+ + " for user "
+ + userId);
+ } catch (RemoteException e) {
+ System.err.println(e.toString());
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ }
+ }
+
private String nextArg() {
if (mNextArg >= mArgs.length) {
return null;
@@ -880,6 +906,7 @@ public class Bmgr {
System.err.println(" bmgr backupnow [--monitor|--monitor-verbose] --all|PACKAGE...");
System.err.println(" bmgr cancel backups");
System.err.println(" bmgr init TRANSPORT...");
+ System.err.println(" bmgr activate BOOL");
System.err.println("");
System.err.println("The '--user' option specifies the user on which the operation is run.");
System.err.println("It must be the first argument before the operation.");
@@ -946,6 +973,11 @@ public class Bmgr {
System.err.println("");
System.err.println("The 'init' command initializes the given transports, wiping all data");
System.err.println("from their backing data stores.");
+ System.err.println("");
+ System.err.println("The 'activate' command activates or deactivates the backup service.");
+ System.err.println("If the argument is 'true' it will be activated, otherwise it will be");
+ System.err.println("deactivated. When deactivated, the service will not be running and no");
+ System.err.println("operations can be performed until activation.");
}
private static class BackupMonitor extends IBackupManagerMonitor.Stub {