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

Commit dcbe9fbb authored by Chen Bai's avatar Chen Bai Committed by Android (Google) Code Review
Browse files

Merge "brightness: fix conditions for using doze brightness" into main

parents 4e4b677b 7842c143
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1279,8 +1279,9 @@ public class AutomaticBrightnessController {
    private boolean shouldApplyDozeScaleFactor() {
        // We don't apply the doze scale factor if we have a designated brightness curve for doze.
        return (mDisplayManagerFlags.isNormalBrightnessForDozeParameterEnabled()
                ? !mUseNormalBrightnessForDoze && mDisplayPolicy == POLICY_DOZE
                : Display.isDozeState(mDisplayState)) && getMode() != AUTO_BRIGHTNESS_MODE_DOZE;
                ? (!mUseNormalBrightnessForDoze && mDisplayPolicy == POLICY_DOZE)
                        || Display.isDozeState(mDisplayState) : Display.isDozeState(mDisplayState))
                && getMode() != AUTO_BRIGHTNESS_MODE_DOZE;
    }

    private class ShortTermModel {
+9 −4
Original line number Diff line number Diff line
@@ -1357,6 +1357,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mDisplayStateController.shouldPerformScreenOffTransition());
        state = mPowerState.getScreenState();

        // Use doze brightness if one of following is true:
        // 1. The target `state` isDozeState.
        // 2. Doze power request(POLICY_DOZE) if there's no exception(useNormalBrightnessForDoze).
        final boolean useDozeBrightness = mFlags.isNormalBrightnessForDozeParameterEnabled()
                ? (!mPowerRequest.useNormalBrightnessForDoze && mPowerRequest.policy == POLICY_DOZE)
                        || Display.isDozeState(state) : Display.isDozeState(state);

        DisplayBrightnessState displayBrightnessState = mDisplayBrightnessController
                .updateBrightness(mPowerRequest, state, mDisplayOffloadSession);
        float brightnessState = displayBrightnessState.getBrightness();
@@ -1399,7 +1406,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    && !mAutomaticBrightnessController.isInIdleMode()) {
                // Set sendUpdate to false, we're already in updatePowerState() so there's no need
                // to trigger it again
                mAutomaticBrightnessController.switchMode(Display.isDozeState(state)
                mAutomaticBrightnessController.switchMode(useDozeBrightness
                        ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT,
                        /* sendUpdate= */ false);
            }
@@ -1472,9 +1479,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            brightnessState = clampScreenBrightness(brightnessState);
        }

        if (mFlags.isNormalBrightnessForDozeParameterEnabled()
                ? !mPowerRequest.useNormalBrightnessForDoze && mPowerRequest.policy == POLICY_DOZE
                : Display.isDozeState(state)) {
        if (useDozeBrightness) {
            // TODO(b/329676661): Introduce a config property to choose between this brightness
            //  strategy and DOZE_DEFAULT
            // On some devices, when auto-brightness is disabled and the device is dozing, we use
+3 −3
Original line number Diff line number Diff line
@@ -510,10 +510,10 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2
                && mAutomaticBrightnessController != null
                && !mAutomaticBrightnessController.isInIdleMode()) {

            boolean shouldUseDozeMode =
            final boolean shouldUseDozeMode =
                    mDisplayManagerFlags.isNormalBrightnessForDozeParameterEnabled()
                            ? !useNormalBrightnessForDoze && policy == POLICY_DOZE
                            : Display.isDozeState(state);
                            ? (!useNormalBrightnessForDoze && policy == POLICY_DOZE)
                                    || Display.isDozeState(state) : Display.isDozeState(state);
            mAutomaticBrightnessController.switchMode(shouldUseDozeMode
                    ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT, sendUpdate);
        }
+42 −0
Original line number Diff line number Diff line
@@ -2126,6 +2126,48 @@ public final class DisplayPowerControllerTest {
                /* ignoreAnimationLimits= */ anyBoolean());
    }

    @Test
    public void testManualBrightness_stateDozePolicyOnUseNormalBrightnessForDozeTrue_brightnessDoze() {
        when(mDisplayManagerFlagsMock.isDisplayOffloadEnabled()).thenReturn(true);
        when(mDisplayManagerFlagsMock.isNormalBrightnessForDozeParameterEnabled()).thenReturn(true);
        mHolder.dpc.setDisplayOffloadSession(mDisplayOffloadSession);
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        float brightness = 0.277f;
        when(mHolder.displayPowerState.getColorFadeLevel()).thenReturn(1.0f);
        when(mHolder.brightnessSetting.getBrightness()).thenReturn(brightness);
        when(mHolder.hbmController.getCurrentBrightnessMax())
                .thenReturn(PowerManager.BRIGHTNESS_MAX);
        when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_ON);
        // Start with state=DOZE.
        when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_DOZE);
        DisplayPowerRequest dprInit = new DisplayPowerRequest();
        dprInit.policy = DisplayPowerRequest.POLICY_DOZE;
        mHolder.dpc.requestPowerState(dprInit, /* waitForNegativeProximity= */ false);
        advanceTime(1); // Run updatePowerState; initialize to DOZE
        // Go to state=ON. But state change would be blocked. so, state=DOZE.
        when(mDisplayOffloadSession.blockScreenOn(any())).thenReturn(true);
        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.dozeScreenState = Display.STATE_ON;
        dpr.policy = DisplayPowerRequest.POLICY_BRIGHT;
        dpr.useNormalBrightnessForDoze = true;
        mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
        advanceTime(1); // Run updatePowerState; process turning on.

        ArgumentCaptor<BrightnessSetting.BrightnessSettingListener> listenerCaptor =
                ArgumentCaptor.forClass(BrightnessSetting.BrightnessSettingListener.class);
        verify(mHolder.brightnessSetting).registerListener(listenerCaptor.capture());
        BrightnessSetting.BrightnessSettingListener listener = listenerCaptor.getValue();
        listener.onBrightnessChanged(brightness);
        advanceTime(1); // Send messages, run updatePowerState

        // When state=DOZE, force doze brightness regardless the requested policy.
        verify(mHolder.animator).animateTo(eq(brightness * DOZE_SCALE_FACTOR),
                /* linearSecondTarget= */ anyFloat(), /* rate= */ anyFloat(),
                /* ignoreAnimationLimits= */ anyBoolean());
    }

    @Test
    public void testDozeManualBrightness_AbcIsNull() {
        when(mDisplayManagerFlagsMock.isDisplayOffloadEnabled()).thenReturn(true);
+5 −5
Original line number Diff line number Diff line
@@ -397,9 +397,9 @@ public class AutomaticBrightnessStrategyTest {
        mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_DOZE,
                allowAutoBrightnessWhileDozing, brightnessReason, policy,
                useNormalBrightnessForDoze, lastUserSetBrightness, userSetBrightnessChanged);
        // 1st AUTO_BRIGHTNESS_MODE_DEFAULT
        verify(mAutomaticBrightnessController).switchMode(
                AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT,
        // 3rd AUTO_BRIGHTNESS_MODE_DOZE
        verify(mAutomaticBrightnessController, times(3)).switchMode(
                AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DOZE,
                /* sendUpdate= */ false);

        // Validate interaction when automaticBrightnessController is in non-idle mode, display
@@ -407,8 +407,8 @@ public class AutomaticBrightnessStrategyTest {
        mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_ON,
                allowAutoBrightnessWhileDozing, brightnessReason, policy,
                useNormalBrightnessForDoze, lastUserSetBrightness, userSetBrightnessChanged);
        // 2nd AUTO_BRIGHTNESS_MODE_DEFAULT
        verify(mAutomaticBrightnessController, times(2)).switchMode(
        // AUTO_BRIGHTNESS_MODE_DEFAULT
        verify(mAutomaticBrightnessController).switchMode(
                AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT,
                /* sendUpdate= */ false);
    }