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

Commit e1a22b97 authored by Brian Lindahl's avatar Brian Lindahl
Browse files

Add resource overlay for disabling color fade screen off transitions

Some devices are unable to support a high quality color fade, because
the screenshot used to generate the color fade effect does not
accurately represent what the user is seeing on the display.

Bug: 348349233
Test: atest DisplayStateControllerTest
Flag: NONE trivial change
Change-Id: I83e52b5e1ebe7a27803bb1b8a729e1c500d76925
parent 505ac56c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1607,6 +1607,10 @@
         brightness value and will repeat for the following ramp if autobrightness is enabled. -->
    <bool name="config_skipScreenOnBrightnessRamp">false</bool>

    <!-- Whether or not to skip a color fade transition to black when the display transitions to
         STATE_OFF. Setting this to true will skip the color fade transition. -->
    <bool name="config_skipScreenOffTransition">false</bool>

    <!-- Allow automatic adjusting of the screen brightness while dozing in low power state. -->
    <bool name="config_allowAutoBrightnessWhileDozing">false</bool>

+1 −0
Original line number Diff line number Diff line
@@ -2045,6 +2045,7 @@
  <java-symbol type="bool" name="config_unplugTurnsOnScreen" />
  <java-symbol type="bool" name="config_usbChargingMessage" />
  <java-symbol type="bool" name="config_skipScreenOnBrightnessRamp" />
  <java-symbol type="bool" name="config_skipScreenOffTransition" />
  <java-symbol type="bool" name="config_allowAutoBrightnessWhileDozing" />
  <java-symbol type="bool" name="config_allowTheaterModeWakeFromUnplug" />
  <java-symbol type="bool" name="config_allowTheaterModeWakeFromGesture" />
+7 −6
Original line number Diff line number Diff line
@@ -521,6 +521,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            BrightnessTracker brightnessTracker, BrightnessSetting brightnessSetting,
            Runnable onBrightnessChangeRunnable, HighBrightnessModeMetadata hbmMetadata,
            boolean bootCompleted, DisplayManagerFlags flags) {
        final Resources resources = context.getResources();

        mFlags = flags;
        mInjector = injector != null ? injector : new Injector();
        mClock = mInjector.getClock();
@@ -540,7 +542,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mDisplayPowerProximityStateController = mInjector.getDisplayPowerProximityStateController(
                mWakelockController, mDisplayDeviceConfig, mHandler.getLooper(),
                () -> updatePowerState(), mDisplayId, mSensorManager);
        mDisplayStateController = new DisplayStateController(mDisplayPowerProximityStateController);
        mDisplayStateController = new DisplayStateController(
            mDisplayPowerProximityStateController,
            resources.getBoolean(R.bool.config_skipScreenOffTransition));
        mTag = TAG + "[" + mDisplayId + "]";
        mThermalBrightnessThrottlingDataId =
                logicalDisplay.getDisplayInfoLocked().thermalBrightnessThrottlingDataId;
@@ -574,17 +578,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                Settings.Global.getUriFor(Settings.Global.Wearable.BEDTIME_MODE),
                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);

        final Resources resources = context.getResources();

        // DOZE AND DIM SETTINGS
        mScreenBrightnessDozeConfig = BrightnessUtils.clampAbsoluteBrightness(
                mDisplayDeviceConfig.getDefaultDozeBrightness());
        loadBrightnessRampRates();
        mSkipScreenOnBrightnessRamp = resources.getBoolean(
                R.bool.config_skipScreenOnBrightnessRamp);
        mDozeScaleFactor = context.getResources().getFraction(
                R.fraction.config_screenAutoBrightnessDozeScaleFactor,
                1, 1);
        mDozeScaleFactor = resources.getFraction(
                R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1);

        Runnable modeChangeCallback = () -> {
            sendUpdatePowerState();
+9 −5
Original line number Diff line number Diff line
@@ -31,14 +31,17 @@ import java.io.PrintWriter;
 * clients about the changes
 */
public class DisplayStateController {
    private DisplayPowerProximityStateController mDisplayPowerProximityStateController;
    private final DisplayPowerProximityStateController mDisplayPowerProximityStateController;
    private final boolean mShouldSkipScreenOffTransition;
    private boolean mPerformScreenOffTransition = false;
    private int mDozeStateOverride = Display.STATE_UNKNOWN;
    private int mDozeStateOverrideReason = Display.STATE_REASON_UNKNOWN;

    public DisplayStateController(DisplayPowerProximityStateController
            displayPowerProximityStateController) {
    public DisplayStateController(
            DisplayPowerProximityStateController displayPowerProximityStateController,
            boolean shouldSkipScreenOffTransition) {
        this.mDisplayPowerProximityStateController = displayPowerProximityStateController;
        this.mShouldSkipScreenOffTransition = shouldSkipScreenOffTransition;
    }

    /**
@@ -65,7 +68,7 @@ public class DisplayStateController {
        switch (displayPowerRequest.policy) {
            case DisplayManagerInternal.DisplayPowerRequest.POLICY_OFF:
                state = Display.STATE_OFF;
                mPerformScreenOffTransition = true;
                mPerformScreenOffTransition = !mShouldSkipScreenOffTransition;
                break;
            case DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE:
                if (mDozeStateOverride != Display.STATE_UNKNOWN) {
@@ -117,7 +120,8 @@ public class DisplayStateController {
    public void dump(PrintWriter pw) {
        pw.println("DisplayStateController:");
        pw.println("-----------------------");
        pw.println("  mPerformScreenOffTransition:" + mPerformScreenOffTransition);
        pw.println("  mShouldSkipScreenOffTransition=" + mShouldSkipScreenOffTransition);
        pw.println("  mPerformScreenOffTransition=" + mPerformScreenOffTransition);
        pw.println("  mDozeStateOverride=" + mDozeStateOverride);

        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
+35 −1
Original line number Diff line number Diff line
@@ -52,7 +52,9 @@ public final class DisplayStateControllerTest {
    @Before
    public void before() {
        MockitoAnnotations.initMocks(this);
        mDisplayStateController = new DisplayStateController(mDisplayPowerProximityStateController);
        final boolean shouldSkipScreenOffTransition = false;
        mDisplayStateController = new DisplayStateController(
                mDisplayPowerProximityStateController, /* shouldSkipScreenOffTransition= */ false);
    }

    @Test
@@ -236,6 +238,38 @@ public final class DisplayStateControllerTest {
        assertTrue(Display.STATE_REASON_OFFLOAD == stateAndReason.second);
    }

    @Test
    public void shouldPerformScreenOffTransition_whenRequestedOffAndNotConfiguredToSkip_true() {
        mDisplayStateController = new DisplayStateController(
                mDisplayPowerProximityStateController, /* shouldSkipScreenOffTransition= */ false);
        when(mDisplayPowerProximityStateController.isScreenOffBecauseOfProximity()).thenReturn(
                false);
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);

        displayPowerRequest.policy = DisplayManagerInternal.DisplayPowerRequest.POLICY_OFF;
        displayPowerRequest.policyReason = Display.STATE_REASON_KEY;
        mDisplayStateController.updateDisplayState(
                displayPowerRequest, DISPLAY_ENABLED, !DISPLAY_IN_TRANSITION);
        assertEquals(true, mDisplayStateController.shouldPerformScreenOffTransition());
    }

    @Test
    public void shouldPerformScreenOffTransition_whenRequestedOffAndConfiguredToSkip_false() {
        mDisplayStateController = new DisplayStateController(
                mDisplayPowerProximityStateController, /* shouldSkipScreenOffTransition= */ true);
        when(mDisplayPowerProximityStateController.isScreenOffBecauseOfProximity()).thenReturn(
                false);
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);

        displayPowerRequest.policy = DisplayManagerInternal.DisplayPowerRequest.POLICY_OFF;
        displayPowerRequest.policyReason = Display.STATE_REASON_KEY;
        mDisplayStateController.updateDisplayState(
                displayPowerRequest, DISPLAY_ENABLED, !DISPLAY_IN_TRANSITION);
        assertEquals(false, mDisplayStateController.shouldPerformScreenOffTransition());
    }

    private void validDisplayState(int policy, int displayState, boolean isEnabled,
            boolean isInTransition) {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(