summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java74
1 files changed, 32 insertions, 42 deletions
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
index 680ccfc57ddf..76b905d8985f 100644
--- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
+++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
@@ -64,6 +64,10 @@ public class Bmgr {
private static final String BMGR_NOT_RUNNING_ERR =
"Error: Could not access the Backup Manager. Is the system running?";
+ private static final String BMGR_NOT_ACTIVATED_FOR_USER =
+ "Error: Backup Manager is not activated for user ";
+ private static final String BMGR_ERR_NO_RESTORESESSION_FOR_USER =
+ "Error: Could not get restore session for user ";
private static final String TRANSPORT_NOT_RUNNING_ERR =
"Error: Could not access the backup transport. Is the system running?";
private static final String PM_NOT_RUNNING_ERR =
@@ -190,15 +194,19 @@ public class Bmgr {
showUsage();
}
- boolean isBackupActive(@UserIdInt int userId) {
+ private void handleRemoteException(RemoteException e) {
+ System.err.println(e.toString());
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ }
+
+ private boolean isBackupActive(@UserIdInt int userId) {
try {
if (!mBmgr.isBackupServiceActive(userId)) {
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ System.err.println(BMGR_NOT_ACTIVATED_FOR_USER + userId);
return false;
}
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
return false;
}
@@ -214,8 +222,7 @@ public class Bmgr {
System.out.println("Backup Manager currently "
+ activatedToString(mBmgr.isBackupServiceActive(userId)));
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -230,8 +237,7 @@ public class Bmgr {
System.out.println("Backup Manager currently "
+ enableToString(isEnabled));
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -250,8 +256,7 @@ public class Bmgr {
showUsage();
return;
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -259,8 +264,7 @@ public class Bmgr {
try {
mBmgr.backupNowForUser(userId);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -274,8 +278,7 @@ public class Bmgr {
try {
mBmgr.dataChangedForUser(userId, pkg);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -292,8 +295,7 @@ public class Bmgr {
mBmgr.fullTransportBackupForUser(
userId, allPkgs.toArray(new String[allPkgs.size()]));
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
}
@@ -421,8 +423,7 @@ public class Bmgr {
try {
filteredPackages = mBmgr.filterAppsEligibleForBackupForUser(userId, packages);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
backupNowPackages(userId, Arrays.asList(filteredPackages), nonIncrementalBackup,
monitorState);
@@ -455,8 +456,7 @@ public class Bmgr {
System.err.println("Unable to run backup");
}
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -506,8 +506,7 @@ public class Bmgr {
try {
mBmgr.cancelBackupsForUser(userId);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
return;
}
@@ -537,8 +536,7 @@ public class Bmgr {
}
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -569,8 +567,7 @@ public class Bmgr {
}
});
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
return;
}
@@ -598,8 +595,7 @@ public class Bmgr {
mBmgr.clearBackupDataForUser(userId, transport, pkg);
System.out.println("Wiped backup data for " + pkg + " on " + transport);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -632,8 +628,7 @@ public class Bmgr {
observer.waitForCompletion(30*1000L);
System.out.println("Initialization result: " + observer.result);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -648,7 +643,7 @@ public class Bmgr {
try {
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
if (mRestore == null) {
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
return;
}
@@ -658,8 +653,7 @@ public class Bmgr {
mRestore.endRestoreSession();
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -686,8 +680,7 @@ public class Bmgr {
System.out.println(pad + t);
}
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -805,7 +798,7 @@ public class Bmgr {
boolean didRestore = false;
mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
if (mRestore == null) {
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
return;
}
RestoreSet[] sets = null;
@@ -851,8 +844,7 @@ public class Bmgr {
System.out.println("done");
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -865,8 +857,7 @@ public class Bmgr {
}
}
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}
@@ -886,8 +877,7 @@ public class Bmgr {
+ " for user "
+ userId);
} catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ handleRemoteException(e);
}
}