From 3bca09f3086e82e12f36b1c045054e2dcd1c7b43 Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Wed, 6 Jun 2018 16:11:09 +0100 Subject: [PATCH] Start SecurityLogMonitor after broadcasts are allowed. Otherwise if boot takes long enough, DO broadcast will be sent while ActivityManagerSerivce is not ready, causing IllegalStateException. Change-Id: I6b55ed45ed7b1f3ed9ad6ec20695907b4fa6f3b1 Fixes: 109746888 Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.DeviceOwnerTest#testSecurityLoggingWithSingleUser Test: provisioned TestDPC as DO in SuW, enabled logging. --- .../server/devicepolicy/DevicePolicyManagerService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index c370a00586feb..b74a582db2de4 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -2353,8 +2353,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final String value = Boolean.toString(hasDeviceOwner); mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, value); Slog.i(LOG_TAG, "Set ro.device_owner property to " + value); + } + } - if (hasDeviceOwner && mInjector.securityLogGetLoggingEnabledProperty()) { + private void maybeStartSecurityLogMonitorOnActivityManagerReady() { + synchronized (getLockObject()) { + if (mInjector.securityLogIsLoggingEnabled()) { mSecurityLogMonitor.start(); mInjector.runCryptoSelfTest(); maybePauseDeviceWideLoggingLocked(); @@ -3353,6 +3357,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { loadAdminDataAsync(); mOwners.systemReady(); break; + case SystemService.PHASE_ACTIVITY_MANAGER_READY: + maybeStartSecurityLogMonitorOnActivityManagerReady(); + break; case SystemService.PHASE_BOOT_COMPLETED: ensureDeviceOwnerUserStarted(); // TODO Consider better place to do this. break;