From 1975021d88da6623a570a6ddab8b2397b1c0e59f Mon Sep 17 00:00:00 2001 From: Vladislav Kuzkokov Date: Wed, 28 Sep 2016 14:19:20 +0200 Subject: [PATCH] Fix backup for users hit by erroneous backup disabling BUG=31754835 Change-Id: I89dd08b7958dd8fe20d70bc50f2c89996ae46cc5 --- .../DevicePolicyManagerService.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index c2ffa9bbab15a..11d9fb8ef2a42 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -496,6 +496,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } }); } + // STOPSHIP: Remove this code once all dogfood devices are fixed. See b/31754835 + if (Intent.ACTION_BOOT_COMPLETED.equals(action) && !mOwners.hasDeviceOwner() + && !isBackupServiceEnabledInternal()) { + setBackupServiceEnabledInternal(true); + Slog.w(LOG_TAG, "Fix backup for device that is not in Device Owner mode."); + } if (Intent.ACTION_USER_UNLOCKED.equals(action) || Intent.ACTION_USER_STARTED.equals(action) || KeyChain.ACTION_STORAGE_CHANGED.equals(action)) { @@ -9317,12 +9323,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } synchronized (this) { getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); - try { - IBackupManager ibm = mInjector.getIBackupManager(); - return ibm != null && ibm.isBackupServiceActive(UserHandle.USER_SYSTEM); - } catch (RemoteException e) { - throw new IllegalStateException("Failed requesting backup service state.", e); - } + return isBackupServiceEnabledInternal(); + } + } + private boolean isBackupServiceEnabledInternal() { + try { + IBackupManager ibm = mInjector.getIBackupManager(); + return ibm != null && ibm.isBackupServiceActive(UserHandle.USER_SYSTEM); + } catch (RemoteException e) { + throw new IllegalStateException("Failed requesting backup service state.", e); } } }