Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa35b718 authored by “Ayush's avatar “Ayush Committed by Ayush Sharma
Browse files

Construct EnterpriseSpecificIdCalculator only once after the boot phase

is completed.

Construct the EnterpriseSpecificIdCalculator object after boot phase is
complete, as some of the dependencies(telephony and wifi service) for
this class are not properly initialized before that.

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: I20927cdc6844591f12d390ced7f1471733602a81
parent 764792b6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13736,6 +13736,8 @@ public class DevicePolicyManager {
     *
     * It is recommended that the Enterprise ID is at least 6 characters long, and no more than
     * 64 characters.
     * This API is supposed to be called only after the boot phase is complete,
     * throws {@link IllegalStateException} if called before boot phase is complete.
     *
     * @param enterpriseId An identifier of the organization this work profile or device is
     *                     enrolled into.
+12 −4
Original line number Diff line number Diff line
@@ -649,6 +649,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private final DevicePolicyCacheImpl mPolicyCache = new DevicePolicyCacheImpl();
    private final DeviceStateCacheImpl mStateCache = new DeviceStateCacheImpl();
    private EnterpriseSpecificIdCalculator mEsidCalculator;
    /**
     * Contains (package-user) pairs to remove. An entry (p, u) implies that removal of package p
@@ -1454,6 +1455,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            return new LockPatternUtils(mContext);
        }
        EnterpriseSpecificIdCalculator newEnterpriseSpecificIdCalculator() {
            return new EnterpriseSpecificIdCalculator(mContext);
        }
        boolean storageManagerIsFileBasedEncryptionEnabled() {
            return StorageManager.isFileEncryptedNativeOnly();
        }
@@ -3102,6 +3107,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                factoryResetIfDelayedEarlier();
                ensureDeviceOwnerUserStarted(); // TODO Consider better place to do this.
                // This is constructed here as EnterpriseSpecificIdCalculator depends on telephony
                // and wifi service and these services are only fully available at this stage.
                mEsidCalculator = mInjector.newEnterpriseSpecificIdCalculator();
                break;
        }
    }
@@ -16899,6 +16908,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setOrganizationIdForUser(
            @NonNull String callerPackage, @NonNull String organizationId, int userId) {
        Preconditions.checkState(mEsidCalculator != null,
                "setOrganizationIdForUser can't be called before boot phase completion");
        if (!mHasFeature) {
            return;
        }
@@ -16932,10 +16943,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                            + "be changed");
            final String dpcPackage = owner.info.getPackageName();
            mInjector.binderWithCleanCallingIdentity(() -> {
                EnterpriseSpecificIdCalculator esidCalculator =
                        new EnterpriseSpecificIdCalculator(mContext);
                final String esid = esidCalculator.calculateEnterpriseId(dpcPackage,
                final String esid = mEsidCalculator.calculateEnterpriseId(dpcPackage,
                        organizationId);
                owner.mOrganizationId = organizationId;
                owner.mEnrollmentSpecificId = esid;
+11 −5
Original line number Diff line number Diff line
@@ -51,13 +51,19 @@ class EnterpriseSpecificIdCalculator {

    EnterpriseSpecificIdCalculator(Context context) {
        TelephonyManager telephonyService = context.getSystemService(TelephonyManager.class);
        Preconditions.checkState(telephonyService != null, "Unable to access telephony service");
        if (telephonyService != null) {
            mImei = telephonyService.getImei(0);
            mMeid = telephonyService.getMeid(0);
        } else {
            mImei = "";
            mMeid = "";
        }
        mSerialNumber = Build.getSerial();
        WifiManager wifiManager = context.getSystemService(WifiManager.class);
        Preconditions.checkState(wifiManager != null, "Unable to access WiFi service");
        final String[] macAddresses = wifiManager.getFactoryMacAddresses();
        String[] macAddresses = null;
        if (wifiManager != null) {
            macAddresses = wifiManager.getFactoryMacAddresses();
        }
        if (macAddresses == null || macAddresses.length == 0) {
            mMacAddress = "";
        } else {