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

Commit 4a29c524 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Set ro.device_owner when DO is present.

Do not wait until deivce_provisioned is set. This logic is currently used
for Wear devices and since nothing except security logging now depends on
this property, we can safely set it to "true" if there is a DO on the device.

Bug: 35342467
Test: manual, setting a DO before SUW triggers setting of the property.
      property to be set.
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest

Change-Id: I2c179194fb8f0f4bef96bb21dbf2522ba99afcec
parent 7162057f
Loading
Loading
Loading
Loading
+10 −16
Original line number Diff line number Diff line
@@ -2020,12 +2020,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private void setDeviceOwnerSystemPropertyLocked() {
        final boolean deviceProvisioned =
                mInjector.settingsGlobalGetInt(Settings.Global.DEVICE_PROVISIONED, 0) != 0;
        final boolean hasDeviceOwner = mOwners.hasDeviceOwner();
        // If the device is not provisioned and there is currently no device owner, do not set the
        // read-only system property yet, since Device owner may still be provisioned. For Wear
        // devices, if there is already a device owner then it's OK to set the property to true now,
        // regardless the provision state.
        final boolean isWatchWithDeviceOwner = mIsWatch && mOwners.hasDeviceOwner();
        if (!isWatchWithDeviceOwner && !deviceProvisioned) {
        // read-only system property yet, since Device owner may still be provisioned.
        if (!hasDeviceOwner && !deviceProvisioned) {
            return;
        }
        // Still at the first stage of CryptKeeper double bounce, mOwners.hasDeviceOwner is
@@ -2034,21 +2032,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            return;
        }

        if (!TextUtils.isEmpty(mInjector.systemPropertiesGet(PROPERTY_DEVICE_OWNER_PRESENT))) {
        if (!mInjector.systemPropertiesGet(PROPERTY_DEVICE_OWNER_PRESENT, "").isEmpty()) {
            Slog.w(LOG_TAG, "Trying to set ro.device_owner, but it has already been set?");
        } else {
            if (mOwners.hasDeviceOwner()) {
                mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, "true");
                Slog.i(LOG_TAG, "Set ro.device_owner property to true");
            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 (mInjector.securityLogGetLoggingEnabledProperty()) {
            if (hasDeviceOwner && mInjector.securityLogGetLoggingEnabledProperty()) {
                mSecurityLogMonitor.start();
                maybePauseDeviceWideLoggingLocked();
            }
            } else {
                mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, "false");
                Slog.i(LOG_TAG, "Set ro.device_owner property to false");
            }
        }
    }