Acquire lock before calling getDeviceOwnerAdminLocked

Change-Id: I318c7cea8e9b7de2dc9fa05f786524848c9c76dd
Fixes: 79418618
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index ab93a8a..6510053 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -5525,9 +5525,11 @@
         // If there is a profile owner, redirect to that; otherwise query the device owner.
         ComponentName aliasChooser = getProfileOwner(caller.getIdentifier());
         if (aliasChooser == null && caller.isSystem()) {
-            ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
-            if (deviceOwnerAdmin != null) {
-                aliasChooser = deviceOwnerAdmin.info.getComponent();
+            synchronized (getLockObject()) {
+                final ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
+                if (deviceOwnerAdmin != null) {
+                    aliasChooser = deviceOwnerAdmin.info.getComponent();
+                }
             }
         }
         if (aliasChooser == null) {