diff options
| author | Ayush Sharma <ayushsha@google.com> | 2021-08-10 11:36:07 +0000 |
|---|---|---|
| committer | Ayush Sharma <ayushsha@google.com> | 2021-08-13 21:14:13 +0000 |
| commit | c152198ed4dfaa2a89a5827fdaa24dd3ef66bbba (patch) | |
| tree | 9416a52e7276c7c8364579ff4abae0eb9e84ab81 | |
| parent | 52d87ab5325f4863d9c75236d2590a81624f0438 (diff) | |
Construct ESIDCalculator class object just once
Construct EnterpriseSpecificIdCalculator object just once and out
of DevicePolicyManagerService class wide lock, to stop the deadlock, as
ESIDCalculator constructor depends on telephony and wifi service, which
in turn could be calling to DPMS trying to hold the lock causing the
deadlock.
Bug: 191741106
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testEnrollmentSpecificIdCorrectCalculation com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testEnrollmentSpecificIdCorrectCalculation com.android.cts.devicepolicy.MixedDeviceOwnerTest#testEnrollmentSpecificIdEmptyAndMultipleSet com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testEnrollmentSpecificIdEmptyAndMultipleSet
Change-Id: I5ec2ae6f476fcc7ca2a3114f8133653cfbbd349b
| -rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 6a259657cca6..c994807a0c10 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -648,6 +648,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private final DevicePolicyCacheImpl mPolicyCache = new DevicePolicyCacheImpl(); private final DeviceStateCacheImpl mStateCache = new DeviceStateCacheImpl(); + private final Object mESIDInitilizationLock = new Object(); + private EnterpriseSpecificIdCalculator mEsidCalculator; /** * Contains (package-user) pairs to remove. An entry (p, u) implies that removal of package p @@ -1473,6 +1475,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return new LockPatternUtils(mContext); } + EnterpriseSpecificIdCalculator newEnterpriseSpecificIdCalculator() { + return new EnterpriseSpecificIdCalculator(mContext); + } + boolean storageManagerIsFileBasedEncryptionEnabled() { return StorageManager.isFileEncryptedNativeOnly(); } @@ -16930,6 +16936,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { Slogf.i(LOG_TAG, "Setting Enterprise ID to %s for user %d", organizationId, userId); + synchronized (mESIDInitilizationLock) { + if (mEsidCalculator == null) { + mInjector.binderWithCleanCallingIdentity(() -> { + mEsidCalculator = mInjector.newEnterpriseSpecificIdCalculator(); + }); + } + } + final String ownerPackage; synchronized (getLockObject()) { final ActiveAdmin owner = getDeviceOrProfileOwnerAdminLocked(userId); @@ -16947,16 +16961,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { "The organization ID has been previously set to a different value and cannot " + "be changed"); final String dpcPackage = owner.info.getPackageName(); - mInjector.binderWithCleanCallingIdentity(() -> { - EnterpriseSpecificIdCalculator esidCalculator = - new EnterpriseSpecificIdCalculator(mContext); - - final String esid = esidCalculator.calculateEnterpriseId(dpcPackage, - organizationId); - owner.mOrganizationId = organizationId; - owner.mEnrollmentSpecificId = esid; - saveSettingsLocked(userId); - }); + final String esid = mEsidCalculator.calculateEnterpriseId(dpcPackage, + organizationId); + owner.mOrganizationId = organizationId; + owner.mEnrollmentSpecificId = esid; + saveSettingsLocked(userId); } DevicePolicyEventLogger |
