Merge "Disable bmgr if BMS is not running"

This commit is contained in:
Annie Meng
2018-06-06 10:30:33 +00:00
committed by Android (Google) Code Review

View File

@@ -71,9 +71,7 @@ public final class Bmgr {
return;
}
mBmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
if (mBmgr == null) {
System.err.println(BMGR_NOT_RUNNING_ERR);
if (!isBmgrActive()) {
return;
}
@@ -150,6 +148,27 @@ public final class Bmgr {
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";
}