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

Commit 76e69b06 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Clamp brightness before saving it"

parents f0568174 f2140181
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2672,10 +2672,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    public void setBrightness(float brightnessValue, int userSerial) {
        // Update the setting, which will eventually call back into DPC to have us actually update
        // the display with the new value.
        float clampedBrightnessValue = clampScreenBrightness(brightnessValue);
        mBrightnessSetting.setUserSerial(userSerial);
        mBrightnessSetting.setBrightness(brightnessValue);
        mBrightnessSetting.setBrightness(clampedBrightnessValue);
        if (mDisplayId == Display.DEFAULT_DISPLAY && mPersistBrightnessNitsForDefaultDisplay) {
            float nits = convertToNits(brightnessValue);
            float nits = convertToNits(clampedBrightnessValue);
            if (nits >= 0) {
                mBrightnessSetting.setBrightnessNitsForDefaultDisplay(nits);
            }
+2 −1
Original line number Diff line number Diff line
@@ -2185,7 +2185,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal

    @Override
    public void setBrightness(float brightnessValue, int userSerial) {
        mDisplayBrightnessController.setBrightness(brightnessValue, userSerial);
        mDisplayBrightnessController.setBrightness(clampScreenBrightness(brightnessValue),
                userSerial);
    }

    @Override
+10 −0
Original line number Diff line number Diff line
@@ -1086,6 +1086,16 @@ public final class DisplayPowerController2Test {
                .getThermalBrightnessThrottlingDataMapByThrottlingId();
    }

    @Test
    public void testSetBrightness_BrightnessShouldBeClamped() {
        float clampedBrightness = 0.6f;
        when(mHolder.hbmController.getCurrentBrightnessMax()).thenReturn(clampedBrightness);

        mHolder.dpc.setBrightness(PowerManager.BRIGHTNESS_MAX);

        verify(mHolder.brightnessSetting).setBrightness(clampedBrightness);
    }

    /**
     * Creates a mock and registers it to {@link LocalServices}.
     */
+10 −0
Original line number Diff line number Diff line
@@ -1092,6 +1092,16 @@ public final class DisplayPowerControllerTest {
                .getThermalBrightnessThrottlingDataMapByThrottlingId();
    }

    @Test
    public void testSetBrightness_BrightnessShouldBeClamped() {
        float clampedBrightness = 0.6f;
        when(mHolder.hbmController.getCurrentBrightnessMax()).thenReturn(clampedBrightness);

        mHolder.dpc.setBrightness(PowerManager.BRIGHTNESS_MAX);

        verify(mHolder.brightnessSetting).setBrightness(clampedBrightness);
    }

    /**
     * Creates a mock and registers it to {@link LocalServices}.
     */