OSDN Git Service

Start SecurityLogMonitor after broadcasts are allowed.
authorPavel Grafov <pgrafov@google.com>
Wed, 6 Jun 2018 15:11:09 +0000 (16:11 +0100)
committerPavel Grafov <pgrafov@google.com>
Thu, 7 Jun 2018 10:16:46 +0000 (11:16 +0100)
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.

services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java

index c370a00..b74a582 100644 (file)
@@ -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;