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

Commit 04b9ae39 authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Save brightness changes when mode switched to manual

Bug: 328601668
Test: Disable auto-brightness, set brightness to x, enable auto-brightness (it will change brightness to y), disable auto-brightness (brightness stays at y), reboot the device and see that the current brightness is y and not x.
Test: atest DisplayPowerControllerTest
Flag: EXEMPT bugfix
Change-Id: I5b8982b2757023cf6012642c1cd0c66f8c1bd2b1
parent eda5a4f2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -149,6 +149,13 @@ public class BrightnessSetting {
        }
    }

    /**
     * Flush the brightness update that has been made to the persistent data store.
     */
    public void saveIfNeeded() {
        mPersistentDataStore.saveIfNeeded();
    }

    /**
     * @return The brightness for the default display in nits. Used when the underlying display
     * device has changed but we want to persist the nit value.
+5 −0
Original line number Diff line number Diff line
@@ -2484,6 +2484,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
        mAutomaticBrightnessStrategy.setUseAutoBrightness(screenBrightnessModeSetting
                == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        if (screenBrightnessModeSetting == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
            // In manual mode, all brightness changes should be saved immediately.
            mDisplayBrightnessController.saveBrightnessIfNeeded();
        }
    }


+7 −0
Original line number Diff line number Diff line
@@ -338,6 +338,13 @@ public final class DisplayBrightnessController {
        setBrightness(brightnessValue, maxBrightness);
    }

    /**
     * Flush the brightness update that has been made to the persistent data store.
     */
    public void saveBrightnessIfNeeded() {
        mBrightnessSetting.saveIfNeeded();
    }

    /**
     * Sets the current screen brightness, and notifies the BrightnessSetting about the change.
     */
+14 −0
Original line number Diff line number Diff line
@@ -2213,6 +2213,20 @@ public final class DisplayPowerControllerTest {
                /* ignoreAnimationLimits= */ anyBoolean());
    }

    @Test
    public void testManualBrightnessModeSavesBrightness() {
        DisplayPowerRequest dpr = new DisplayPowerRequest();
        mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
        advanceTime(1); // Initialize

        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        advanceTime(1);

        verify(mHolder.brightnessSetting).saveIfNeeded();
    }

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