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

Commit c0281f10 authored by yuemingw's avatar yuemingw Committed by Yueming Wang
Browse files

Allow PO to call setSystemSetting.

As system setting is per user, we should allow PO to call it.

Bug: 77204777
Test: runtest -x services/tests/servicestests/src/
com/android/server/devicepolicy/DevicePolicyManagerTest.java

Change-Id: I84152fa04adb441955b48b676be6e792134b52c2
parent 223c864b
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -7326,11 +7326,12 @@ public class DevicePolicyManager {
    public @interface SystemSettingsWhitelist {}

    /**
     * Called by device owner to update {@link android.provider.Settings.System} settings.
     * Validation that the value of the setting is in the correct form for the setting type should
     * be performed by the caller.
     * Called by a device or profile owner to update {@link android.provider.Settings.System}
     * settings. Validation that the value of the setting is in the correct form for the setting
     * type should be performed by the caller.
     * <p>
     * The settings that can be updated with this method are:
     * The settings that can be updated by a device owner or profile owner of secondary user with
     * this method are:
     * <ul>
     * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS}</li>
     * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS_MODE}</li>
@@ -7342,7 +7343,7 @@ public class DevicePolicyManager {
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param setting The name of the setting to update.
     * @param value The value to update the setting to.
     * @throws SecurityException if {@code admin} is not a device owner.
     * @throws SecurityException if {@code admin} is not a device or profile owner.
     */
    public void setSystemSetting(@NonNull ComponentName admin,
            @NonNull @SystemSettingsWhitelist String setting, String value) {
+8 −5
Original line number Diff line number Diff line
@@ -2028,8 +2028,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            Settings.Global.putString(mContext.getContentResolver(), name, value);
        }
        void settingsSystemPutString(String name, String value) {
            Settings.System.putString(mContext.getContentResolver(), name, value);
        void settingsSystemPutStringForUser(String name, String value, int userId) {
          Settings.System.putStringForUser(
              mContext.getContentResolver(), name, value, userId);
        }
        void securityLogSetLoggingEnabledProperty(boolean enabled) {
@@ -10049,15 +10050,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        Preconditions.checkStringNotEmpty(setting, "String setting is null or empty");
        synchronized (this) {
            getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
            getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
            if (!SYSTEM_SETTINGS_WHITELIST.contains(setting)) {
                throw new SecurityException(String.format(
                        "Permission denial: device owners cannot update %1$s", setting));
            }
            mInjector.binderWithCleanCallingIdentity(() -> mInjector.settingsSystemPutString(
                    setting, value));
            final int callingUserId = mInjector.userHandleGetCallingUserId();
            mInjector.binderWithCleanCallingIdentity(() ->
                mInjector.settingsSystemPutStringForUser(setting, value, callingUserId));
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -393,8 +393,8 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi
        }

        @Override
        void settingsSystemPutString(String name, String value) {
            services.settings.settingsSystemPutString(name, value);
        void settingsSystemPutStringForUser(String name, String value, int userId) {
            services.settings.settingsSystemPutStringForUser(name, value, userId);
        }

        @Override
+10 −9
Original line number Diff line number Diff line
@@ -3454,18 +3454,19 @@ public class DevicePolicyManagerTest extends DpmTestBase {
                dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS_FOR_VR, "0"));
    }

    public void testSetSystemSettingFailWithPO() throws Exception {
        setupProfileOwner();
        assertExpectException(SecurityException.class, null, () ->
                dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS, "0"));
    }

    public void testSetSystemSetting() throws Exception {
    public void testSetSystemSettingWithDO() throws Exception {
        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        setupDeviceOwner();
        dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS, "0");
        verify(getServices().settings).settingsSystemPutString(
                Settings.System.SCREEN_BRIGHTNESS, "0");
        verify(getServices().settings).settingsSystemPutStringForUser(
                Settings.System.SCREEN_BRIGHTNESS, "0", UserHandle.USER_SYSTEM);
    }

    public void testSetSystemSettingWithPO() throws Exception {
        setupProfileOwner();
        dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS, "0");
        verify(getServices().settings).settingsSystemPutStringForUser(
            Settings.System.SCREEN_BRIGHTNESS, "0", DpmMockContext.CALLER_USER_HANDLE);
    }

    public void testSetTime() throws Exception {
+1 −1
Original line number Diff line number Diff line
@@ -419,7 +419,7 @@ public class MockSystemServices {
        public void settingsGlobalPutString(String name, String value) {
        }

        public void settingsSystemPutString(String name, String value) {
        public void settingsSystemPutStringForUser(String name, String value, int callingUserId) {
        }

        public int settingsGlobalGetInt(String name, int value) {