If BMS is not running, we should not run any bmgr commands and print an
error. This can occur after a device with a lockscreen reboots and has
not unlocked yet, as the backup service is not active before unlocking.
Bug:
80691476
Test: 1) Device with lock + adb reboot -> run any 'adb shell bmgr'
command -> prints error
2) Device with no lock + adb reboot -> run any 'adb shell bmgr' command
-> success
Change-Id: I101b61d18a637cdb945ffc4a5e989a5dd270ee32
return;
}
- mBmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
- if (mBmgr == null) {
- System.err.println(BMGR_NOT_RUNNING_ERR);
+ if (!isBmgrActive()) {
return;
}
showUsage();
}
+ private boolean isBmgrActive() {
+ mBmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
+ if (mBmgr == null) {
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ return false;
+ }
+
+ try {
+ if (!mBmgr.isBackupServiceActive(UserHandle.USER_SYSTEM)) {
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ return false;
+ }
+ } catch (RemoteException e) {
+ System.err.println(e.toString());
+ System.err.println(BMGR_NOT_RUNNING_ERR);
+ return false;
+ }
+
+ return true;
+ }
+
private String enableToString(boolean enabled) {
return enabled ? "enabled" : "disabled";
}