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

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

Fix auto-brightness in doze

- AutomaticBrightnessController was incorrectly disabling auto-brightness in doze even if the config allowed it.

- We should rely on the policy and not the display state - when we enter doze, the first power request has policy DOZE but the display state is still ON.

Bug: 322974128
Bug: 304339170
Test: atest DisplayPowerControllerTest
Test: atest AutomaticBrightnessStrategyTest
Test: atest AutomaticBrightnessControllerTest
Change-Id: Ie04184b6cca91c9a96c360d72fbbf59cfb8ecf59
parent f320e4b5
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -463,12 +463,6 @@ public class AutomaticBrightnessController {
            boolean userChangedAutoBrightnessAdjustment, int displayPolicy,
            boolean shouldResetShortTermModel) {
        mState = state;
        // While dozing, the application processor may be suspended which will prevent us from
        // receiving new information from the light sensor. On some devices, we may be able to
        // switch to a wake-up light sensor instead but for now we will simply disable the sensor
        // and hold onto the last computed screen auto brightness.  We save the dozing flag for
        // debugging purposes.
        boolean dozing = (displayPolicy == DisplayPowerRequest.POLICY_DOZE);
        boolean changed = setBrightnessConfiguration(configuration, shouldResetShortTermModel);
        changed |= setDisplayPolicy(displayPolicy);
        if (userChangedAutoBrightnessAdjustment) {
@@ -482,10 +476,10 @@ public class AutomaticBrightnessController {
        }
        final boolean userInitiatedChange =
                userChangedBrightness || userChangedAutoBrightnessAdjustment;
        if (userInitiatedChange && enable && !dozing) {
        if (userInitiatedChange && enable) {
            prepareBrightnessAdjustmentSample();
        }
        changed |= setLightSensorEnabled(enable && !dozing);
        changed |= setLightSensorEnabled(enable);

        if (mIsBrightnessThrottled != mBrightnessThrottler.isThrottled()) {
            // Maximum brightness has changed, so recalculate display brightness.
+1 −2
Original line number Diff line number Diff line
@@ -1485,8 +1485,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        }

        // Use default brightness when dozing unless overridden.
        if ((Float.isNaN(brightnessState))
                && Display.isDozeState(state)) {
        if (Float.isNaN(brightnessState) && mPowerRequest.policy == POLICY_DOZE) {
            rawBrightnessState = mScreenBrightnessDozeConfig;
            brightnessState = clampScreenBrightness(rawBrightnessState);
            mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_DEFAULT);
+3 −2
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.display.brightness.strategy;

import static android.hardware.display.DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE;

import android.annotation.Nullable;
import android.content.Context;
import android.hardware.display.BrightnessConfiguration;
@@ -102,8 +104,7 @@ public class AutomaticBrightnessStrategy {
            boolean allowAutoBrightnessWhileDozingConfig, int brightnessReason, int policy,
            float lastUserSetScreenBrightness, boolean userSetBrightnessChanged) {
        final boolean autoBrightnessEnabledInDoze =
                allowAutoBrightnessWhileDozingConfig
                        && Display.isDozeState(targetDisplayState);
                allowAutoBrightnessWhileDozingConfig && policy == POLICY_DOZE;
        mIsAutoBrightnessEnabled = shouldUseAutoBrightness()
                && (targetDisplayState == Display.STATE_ON || autoBrightnessEnabledInDoze)
                && brightnessReason != BrightnessReason.REASON_OVERRIDE
+21 −0
Original line number Diff line number Diff line
@@ -1727,6 +1727,27 @@ public final class DisplayPowerControllerTest {
                /* ignoreAnimationLimits= */ anyBoolean());
    }

    @Test
    public void testDefaultDozeBrightness() {
        float brightness = 0.121f;
        when(mPowerManagerMock.getBrightnessConstraint(
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_DOZE)).thenReturn(brightness);
        mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID);
        when(mHolder.displayPowerState.getColorFadeLevel()).thenReturn(1.0f);
        when(mHolder.automaticBrightnessController.getAutomaticScreenBrightness(
                any(BrightnessEvent.class))).thenReturn(PowerManager.BRIGHTNESS_INVALID_FLOAT);
        when(mHolder.hbmController.getCurrentBrightnessMax())
                .thenReturn(PowerManager.BRIGHTNESS_MAX);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.policy = DisplayPowerRequest.POLICY_DOZE;
        mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
        advanceTime(1); // Run updatePowerState

        verify(mHolder.animator).animateTo(eq(brightness), /* linearSecondTarget= */ anyFloat(),
                eq(BRIGHTNESS_RAMP_RATE_FAST_INCREASE), eq(false));
    }

    /**
     * Creates a mock and registers it to {@link LocalServices}.
     */
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public class AutomaticBrightnessStrategyTest {
        mAutomaticBrightnessStrategy.setUseAutoBrightness(true);
        int targetDisplayState = Display.STATE_DOZE;
        boolean allowAutoBrightnessWhileDozing = true;
        int brightnessReason = BrightnessReason.REASON_DOZE;
        int brightnessReason = BrightnessReason.REASON_UNKNOWN;
        int policy = DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE;
        float lastUserSetBrightness = 0.2f;
        boolean userSetBrightnessChanged = true;