From d039a763d95884958c46e44510a47731d667f305 Mon Sep 17 00:00:00 2001 From: Piotr WilczyƄski Date: Fri, 23 Feb 2024 14:41:43 +0000 Subject: Initial doze brightness for offload Use the last observed lux and the doze curve to set the initial doze brightness before the offload session takes over. Rely on the policy rather than the state - in the first doze power request, the policy is doze but the state is still ON. Switch to doze auto-brightness mode immediately rather than posting on the handler - we need this so that we get the correct brightness value. Bug: 325627091 Test: atest AutomaticBrightnessControllerTest Test: atest BrightnessEventTest Test: atest BrightnessReasonTest Test: atest AutomaticBrightnessStrategyTest Test: atest DisplayPowerControllerTest Change-Id: I9aaaa1d8b5bb09d5ce5dbe53453bcd28aae2dd8f --- .../display/AutomaticBrightnessController.java | 53 +++++++++++++++++++--- .../server/display/DisplayPowerController.java | 26 +++++++++-- .../server/display/brightness/BrightnessEvent.java | 36 +++++++++++++-- .../display/brightness/BrightnessReason.java | 5 +- .../strategy/AutomaticBrightnessStrategy.java | 17 +++++++ .../display/AutomaticBrightnessControllerTest.java | 31 +++++++++++++ .../server/display/DisplayPowerControllerTest.java | 29 ++++++++++++ .../display/brightness/BrightnessEventTest.java | 23 ++++++---- .../strategy/AutomaticBrightnessStrategyTest.java | 6 +++ 9 files changed, 201 insertions(+), 25 deletions(-) diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index 082776ad6085..fb4976d3cef2 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -16,6 +16,7 @@ package com.android.server.display; +import static com.android.server.display.BrightnessMappingStrategy.INVALID_LUX; import static com.android.server.display.config.DisplayBrightnessMappingConfig.autoBrightnessModeToString; import android.annotation.IntDef; @@ -202,7 +203,7 @@ public class AutomaticBrightnessController { private float mScreenBrighteningThreshold; private float mScreenDarkeningThreshold; // The most recent light sample. - private float mLastObservedLux; + private float mLastObservedLux = INVALID_LUX; // The time of the most light recent sample. private long mLastObservedLuxTime; @@ -403,8 +404,8 @@ public class AutomaticBrightnessController { brightnessEvent.setFlags(brightnessEvent.getFlags() | (!mAmbientLuxValid ? BrightnessEvent.FLAG_INVALID_LUX : 0) | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE - ? BrightnessEvent.FLAG_DOZE_SCALE : 0) - | (isInIdleMode() ? BrightnessEvent.FLAG_IDLE_CURVE : 0)); + ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); + brightnessEvent.setAutoBrightnessMode(getMode()); } if (!mAmbientLuxValid) { @@ -420,6 +421,35 @@ public class AutomaticBrightnessController { return mRawScreenAutoBrightness; } + /** + * Get the automatic screen brightness based on the last observed lux reading. Used e.g. when + * entering doze - we disable the light sensor, invalidate the lux, but we still need to set + * the initial brightness in doze mode. + */ + public float getAutomaticScreenBrightnessBasedOnLastObservedLux( + BrightnessEvent brightnessEvent) { + if (mLastObservedLux == INVALID_LUX) { + return PowerManager.BRIGHTNESS_INVALID_FLOAT; + } + + float brightness = mCurrentBrightnessMapper.getBrightness(mLastObservedLux, + mForegroundAppPackageName, mForegroundAppCategory); + if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) { + brightness *= mDozeScaleFactor; + } + + if (brightnessEvent != null) { + brightnessEvent.setLux(mLastObservedLux); + brightnessEvent.setRecommendedBrightness(brightness); + brightnessEvent.setFlags(brightnessEvent.getFlags() + | (mLastObservedLux == INVALID_LUX ? BrightnessEvent.FLAG_INVALID_LUX : 0) + | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE + ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); + brightnessEvent.setAutoBrightnessMode(getMode()); + } + return brightness; + } + public boolean hasValidAmbientLux() { return mAmbientLuxValid; } @@ -539,7 +569,7 @@ public class AutomaticBrightnessController { } private boolean setScreenBrightnessByUser(float lux, float brightness) { - if (lux == BrightnessMappingStrategy.INVALID_LUX || Float.isNaN(brightness)) { + if (lux == INVALID_LUX || Float.isNaN(brightness)) { return false; } mCurrentBrightnessMapper.addUserDataPoint(lux, brightness); @@ -564,6 +594,15 @@ public class AutomaticBrightnessController { return false; } + /** + * @return The auto-brightness mode of the current mapping strategy. Different modes use + * different brightness curves. + */ + @AutomaticBrightnessController.AutomaticBrightnessMode + public int getMode() { + return mCurrentBrightnessMapper.getMode(); + } + public boolean isInIdleMode() { return mCurrentBrightnessMapper.getMode() == AUTO_BRIGHTNESS_MODE_IDLE; } @@ -1236,12 +1275,12 @@ public class AutomaticBrightnessController { // light. // The anchor determines what were the light levels when the user has set their preference, // and we use a relative threshold to determine when to revert to the OEM curve. - private float mAnchor = BrightnessMappingStrategy.INVALID_LUX; + private float mAnchor = INVALID_LUX; private float mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; private boolean mIsValid = false; private void reset() { - mAnchor = BrightnessMappingStrategy.INVALID_LUX; + mAnchor = INVALID_LUX; mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; mIsValid = false; } @@ -1265,7 +1304,7 @@ public class AutomaticBrightnessController { private boolean maybeReset(float currentLux) { // If the short term model was invalidated and the change is drastic enough, reset it. // Otherwise, we revalidate it. - if (!mIsValid && mAnchor != BrightnessMappingStrategy.INVALID_LUX) { + if (!mIsValid && mAnchor != INVALID_LUX) { if (mCurrentBrightnessMapper.shouldResetShortTermModel(currentLux, mAnchor)) { resetShortTermModel(); } else { diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 1ca3923b325c..d40465b20ca2 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -16,6 +16,8 @@ package com.android.server.display; +import static android.hardware.display.DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE; + import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT; import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DOZE; import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_IDLE; @@ -37,7 +39,6 @@ import android.hardware.display.AmbientBrightnessDayStats; import android.hardware.display.BrightnessChangeEvent; import android.hardware.display.BrightnessConfiguration; import android.hardware.display.BrightnessInfo; -import android.hardware.display.DisplayManagerInternal; import android.hardware.display.DisplayManagerInternal.DisplayOffloadSession; import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks; import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest; @@ -1376,7 +1377,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Switch to doze auto-brightness mode if needed if (mFlags.areAutoBrightnessModesEnabled() && mAutomaticBrightnessController != null && !mAutomaticBrightnessController.isInIdleMode()) { - setAutomaticScreenBrightnessMode(Display.isDozeState(state) + mAutomaticBrightnessController.switchMode(mPowerRequest.policy == POLICY_DOZE ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT); } @@ -1464,6 +1465,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false); } + // If there's an offload session and auto-brightness is on, we need to set the initial doze + // brightness using the doze auto-brightness curve before the offload session starts + // controlling the brightness. + if (Float.isNaN(brightnessState) && mFlags.areAutoBrightnessModesEnabled() + && mFlags.isDisplayOffloadEnabled() + && mPowerRequest.policy == POLICY_DOZE + && mDisplayOffloadSession != null + && mAutomaticBrightnessStrategy.shouldUseAutoBrightness()) { + rawBrightnessState = mAutomaticBrightnessController + .getAutomaticScreenBrightnessBasedOnLastObservedLux(mTempBrightnessEvent); + if (BrightnessUtils.isValidBrightnessValue(rawBrightnessState)) { + brightnessState = clampScreenBrightness(rawBrightnessState); + mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_INITIAL); + } + } + // Use default brightness when dozing unless overridden. if ((Float.isNaN(brightnessState)) && Display.isDozeState(state)) { @@ -1616,7 +1633,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // if doze or suspend state is requested, we want to finish brightnes animation fast // to allow state animation to start - if (mPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE + if (mPowerRequest.policy == POLICY_DOZE && (mPowerRequest.dozeScreenState == Display.STATE_UNKNOWN // dozing || mPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND || mPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND)) { @@ -1715,6 +1732,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mTempBrightnessEvent.setTime(System.currentTimeMillis()); mTempBrightnessEvent.setBrightness(brightnessState); mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId); + mTempBrightnessEvent.setDisplayState(state); mTempBrightnessEvent.setReason(mBrightnessReason); mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode()); @@ -2888,7 +2906,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call (flags & BrightnessEvent.FLAG_INVALID_LUX) > 0, (flags & BrightnessEvent.FLAG_DOZE_SCALE) > 0, (flags & BrightnessEvent.FLAG_USER_SET) > 0, - (flags & BrightnessEvent.FLAG_IDLE_CURVE) > 0, + event.getAutoBrightnessMode() == AUTO_BRIGHTNESS_MODE_IDLE, (flags & BrightnessEvent.FLAG_LOW_POWER_MODE) > 0); } } diff --git a/services/core/java/com/android/server/display/brightness/BrightnessEvent.java b/services/core/java/com/android/server/display/brightness/BrightnessEvent.java index d4d1bae78a33..5423b74711a2 100644 --- a/services/core/java/com/android/server/display/brightness/BrightnessEvent.java +++ b/services/core/java/com/android/server/display/brightness/BrightnessEvent.java @@ -16,11 +16,16 @@ package com.android.server.display.brightness; +import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT; +import static com.android.server.display.config.DisplayBrightnessMappingConfig.autoBrightnessModeToString; + import android.hardware.display.BrightnessInfo; import android.os.PowerManager; import android.os.SystemClock; +import android.view.Display; import com.android.internal.annotations.VisibleForTesting; +import com.android.server.display.AutomaticBrightnessController; import java.text.SimpleDateFormat; import java.util.Date; @@ -33,7 +38,6 @@ public final class BrightnessEvent { public static final int FLAG_INVALID_LUX = 0x2; public static final int FLAG_DOZE_SCALE = 0x4; public static final int FLAG_USER_SET = 0x8; - public static final int FLAG_IDLE_CURVE = 0x10; public static final int FLAG_LOW_POWER_MODE = 0x20; private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS"); @@ -41,6 +45,7 @@ public final class BrightnessEvent { private BrightnessReason mReason = new BrightnessReason(); private int mDisplayId; private String mPhysicalDisplayId; + private int mDisplayState; private long mTime; private float mLux; private float mPreThresholdLux; @@ -58,6 +63,8 @@ public final class BrightnessEvent { private int mAdjustmentFlags; private boolean mAutomaticBrightnessEnabled; private String mDisplayBrightnessStrategyName; + @AutomaticBrightnessController.AutomaticBrightnessMode + private int mAutoBrightnessMode; public BrightnessEvent(BrightnessEvent that) { copyFrom(that); @@ -77,6 +84,7 @@ public final class BrightnessEvent { mReason.set(that.getReason()); mDisplayId = that.getDisplayId(); mPhysicalDisplayId = that.getPhysicalDisplayId(); + mDisplayState = that.mDisplayState; mTime = that.getTime(); // Lux values mLux = that.getLux(); @@ -98,6 +106,7 @@ public final class BrightnessEvent { // Auto-brightness setting mAutomaticBrightnessEnabled = that.isAutomaticBrightnessEnabled(); mDisplayBrightnessStrategyName = that.getDisplayBrightnessStrategyName(); + mAutoBrightnessMode = that.mAutoBrightnessMode; } /** @@ -107,6 +116,7 @@ public final class BrightnessEvent { mReason = new BrightnessReason(); mTime = SystemClock.uptimeMillis(); mPhysicalDisplayId = ""; + mDisplayState = Display.STATE_UNKNOWN; // Lux values mLux = 0; mPreThresholdLux = 0; @@ -127,6 +137,7 @@ public final class BrightnessEvent { // Auto-brightness setting mAutomaticBrightnessEnabled = true; mDisplayBrightnessStrategyName = ""; + mAutoBrightnessMode = AUTO_BRIGHTNESS_MODE_DEFAULT; } /** @@ -143,6 +154,7 @@ public final class BrightnessEvent { return mReason.equals(that.mReason) && mDisplayId == that.mDisplayId && mPhysicalDisplayId.equals(that.mPhysicalDisplayId) + && mDisplayState == that.mDisplayState && Float.floatToRawIntBits(mLux) == Float.floatToRawIntBits(that.mLux) && Float.floatToRawIntBits(mPreThresholdLux) == Float.floatToRawIntBits(that.mPreThresholdLux) @@ -163,7 +175,8 @@ public final class BrightnessEvent { && mFlags == that.mFlags && mAdjustmentFlags == that.mAdjustmentFlags && mAutomaticBrightnessEnabled == that.mAutomaticBrightnessEnabled - && mDisplayBrightnessStrategyName.equals(that.mDisplayBrightnessStrategyName); + && mDisplayBrightnessStrategyName.equals(that.mDisplayBrightnessStrategyName) + && mAutoBrightnessMode == that.mAutoBrightnessMode; } /** @@ -177,6 +190,7 @@ public final class BrightnessEvent { + "BrightnessEvent: " + "disp=" + mDisplayId + ", physDisp=" + mPhysicalDisplayId + + ", displayState=" + Display.stateToString(mDisplayState) + ", brt=" + mBrightness + ((mFlags & FLAG_USER_SET) != 0 ? "(user_set)" : "") + ", initBrt=" + mInitialBrightness + ", rcmdBrt=" + mRecommendedBrightness @@ -192,7 +206,8 @@ public final class BrightnessEvent { + ", flags=" + flagsToString() + ", reason=" + mReason.toString(mAdjustmentFlags) + ", autoBrightness=" + mAutomaticBrightnessEnabled - + ", strategy=" + mDisplayBrightnessStrategyName; + + ", strategy=" + mDisplayBrightnessStrategyName + + ", autoBrightnessMode=" + autoBrightnessModeToString(mAutoBrightnessMode); } @Override @@ -232,6 +247,10 @@ public final class BrightnessEvent { this.mPhysicalDisplayId = mPhysicalDisplayId; } + public void setDisplayState(int state) { + mDisplayState = state; + } + public float getLux() { return mLux; } @@ -374,6 +393,16 @@ public final class BrightnessEvent { this.mAutomaticBrightnessEnabled = mAutomaticBrightnessEnabled; } + @AutomaticBrightnessController.AutomaticBrightnessMode + public int getAutoBrightnessMode() { + return mAutoBrightnessMode; + } + + public void setAutoBrightnessMode( + @AutomaticBrightnessController.AutomaticBrightnessMode int mode) { + mAutoBrightnessMode = mode; + } + /** * A utility to stringify flags from a BrightnessEvent * @return Stringified flags from BrightnessEvent @@ -384,7 +413,6 @@ public final class BrightnessEvent { + ((mFlags & FLAG_RBC) != 0 ? "rbc " : "") + ((mFlags & FLAG_INVALID_LUX) != 0 ? "invalid_lux " : "") + ((mFlags & FLAG_DOZE_SCALE) != 0 ? "doze_scale " : "") - + ((mFlags & FLAG_IDLE_CURVE) != 0 ? "idle_curve " : "") + ((mFlags & FLAG_LOW_POWER_MODE) != 0 ? "low_power_mode " : ""); } } diff --git a/services/core/java/com/android/server/display/brightness/BrightnessReason.java b/services/core/java/com/android/server/display/brightness/BrightnessReason.java index bc443a8167ab..fc95d15ae6f4 100644 --- a/services/core/java/com/android/server/display/brightness/BrightnessReason.java +++ b/services/core/java/com/android/server/display/brightness/BrightnessReason.java @@ -40,7 +40,8 @@ public final class BrightnessReason { public static final int REASON_SCREEN_OFF_BRIGHTNESS_SENSOR = 9; public static final int REASON_FOLLOWER = 10; public static final int REASON_OFFLOAD = 11; - public static final int REASON_MAX = REASON_OFFLOAD; + public static final int REASON_DOZE_INITIAL = 12; + public static final int REASON_MAX = REASON_DOZE_INITIAL; public static final int MODIFIER_DIMMED = 0x1; public static final int MODIFIER_LOW_POWER = 0x2; @@ -207,6 +208,8 @@ public final class BrightnessReason { return "follower"; case REASON_OFFLOAD: return "offload"; + case REASON_DOZE_INITIAL: + return "doze_initial"; default: return Integer.toString(reason); } diff --git a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java index 3e6e09da9753..8eaecef6e562 100644 --- a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java +++ b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java @@ -266,6 +266,23 @@ public class AutomaticBrightnessStrategy { return brightness; } + /** + * Get the automatic screen brightness based on the last observed lux reading. Used e.g. when + * entering doze - we disable the light sensor, invalidate the lux, but we still need to set + * the initial brightness in doze mode. + * @param brightnessEvent Event object to populate with details about why the specific + * brightness was chosen. + */ + public float getAutomaticScreenBrightnessBasedOnLastObservedLux( + BrightnessEvent brightnessEvent) { + float brightness = (mAutomaticBrightnessController != null) + ? mAutomaticBrightnessController + .getAutomaticScreenBrightnessBasedOnLastObservedLux(brightnessEvent) + : PowerManager.BRIGHTNESS_INVALID_FLOAT; + adjustAutomaticBrightnessStateIfValid(brightness); + return brightness; + } + /** * Gets the auto-brightness adjustment flag change reason */ diff --git a/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java b/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java index 418b78cd696b..9c9aeeaadb71 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java @@ -16,6 +16,7 @@ package com.android.server.display; +import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED; import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED; import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT; import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_IDLE; @@ -1016,4 +1017,34 @@ public class AutomaticBrightnessControllerTest { listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500)); assertEquals(500, mController.getAmbientLux(), EPSILON); } + + @Test + public void testBrightnessBasedOnLastObservedLux() throws Exception { + ArgumentCaptor listenerCaptor = + ArgumentCaptor.forClass(SensorEventListener.class); + verify(mSensorManager).registerListener(listenerCaptor.capture(), eq(mLightSensor), + eq(INITIAL_LIGHT_SENSOR_RATE * 1000), any(Handler.class)); + SensorEventListener listener = listenerCaptor.getValue(); + + // Set up system to return 0.3f as a brightness value + float lux = 100.0f; + // Brightness as float (from 0.0f to 1.0f) + float normalizedBrightness = 0.3f; + when(mAmbientBrightnessThresholds.getBrighteningThreshold(lux)).thenReturn(lux); + when(mAmbientBrightnessThresholds.getDarkeningThreshold(lux)).thenReturn(lux); + when(mBrightnessMappingStrategy.getBrightness(eq(lux), eq(null), anyInt())) + .thenReturn(normalizedBrightness); + when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT); + when(mBrightnessThrottler.isThrottled()).thenReturn(true); + + // Send a new sensor value, disable the sensor and verify + listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, (int) lux)); + mController.configure(AUTO_BRIGHTNESS_DISABLED, /* configuration= */ null, + /* brightness= */ 0, /* userChangedBrightness= */ false, /* adjustment= */ 0, + /* userChanged= */ false, DisplayPowerRequest.POLICY_BRIGHT, + /* shouldResetShortTermModel= */ true); + assertEquals(normalizedBrightness, + mController.getAutomaticScreenBrightnessBasedOnLastObservedLux( + /* brightnessEvent= */ null), EPSILON); + } } diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java index 57b86324e171..6437846bf540 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java @@ -1665,6 +1665,35 @@ public final class DisplayPowerControllerTest { /* luxTimestamps= */ any()); } + @Test + public void testInitialDozeBrightness() { + when(mDisplayManagerFlagsMock.areAutoBrightnessModesEnabled()).thenReturn(true); + when(mDisplayManagerFlagsMock.isDisplayOffloadEnabled()).thenReturn(true); + mHolder.dpc.setDisplayOffloadSession(mDisplayOffloadSession); + Settings.System.putInt(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing, false); + float brightness = 0.277f; + when(mHolder.displayPowerState.getColorFadeLevel()).thenReturn(1.0f); + when(mHolder.automaticBrightnessController + .getAutomaticScreenBrightnessBasedOnLastObservedLux(any(BrightnessEvent.class))) + .thenReturn(brightness); + when(mHolder.hbmController.getCurrentBrightnessMax()) + .thenReturn(PowerManager.BRIGHTNESS_MAX); + when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_DOZE); + + 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(), /* rate= */ anyFloat(), + /* ignoreAnimationLimits= */ anyBoolean()); + } + /** * Creates a mock and registers it to {@link LocalServices}. */ diff --git a/services/tests/displayservicetests/src/com/android/server/display/brightness/BrightnessEventTest.java b/services/tests/displayservicetests/src/com/android/server/display/brightness/BrightnessEventTest.java index c0c63c69add8..060f99b4317a 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/brightness/BrightnessEventTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/brightness/BrightnessEventTest.java @@ -16,9 +16,12 @@ package com.android.server.display.brightness; +import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_IDLE; + import static org.junit.Assert.assertEquals; import android.hardware.display.BrightnessInfo; +import android.view.Display; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -39,6 +42,7 @@ public final class BrightnessEventTest { mBrightnessEvent.setReason( getReason(BrightnessReason.REASON_DOZE, BrightnessReason.MODIFIER_LOW_POWER)); mBrightnessEvent.setPhysicalDisplayId("test"); + mBrightnessEvent.setDisplayState(Display.STATE_ON); mBrightnessEvent.setLux(100.0f); mBrightnessEvent.setPreThresholdLux(150.0f); mBrightnessEvent.setTime(System.currentTimeMillis()); @@ -55,6 +59,7 @@ public final class BrightnessEventTest { mBrightnessEvent.setAdjustmentFlags(0); mBrightnessEvent.setAutomaticBrightnessEnabled(true); mBrightnessEvent.setDisplayBrightnessStrategyName(DISPLAY_BRIGHTNESS_STRATEGY_NAME); + mBrightnessEvent.setAutoBrightnessMode(AUTO_BRIGHTNESS_MODE_IDLE); } @Test @@ -69,20 +74,20 @@ public final class BrightnessEventTest { public void testToStringWorksAsExpected() { String actualString = mBrightnessEvent.toString(false); String expectedString = - "BrightnessEvent: disp=1, physDisp=test, brt=0.6, initBrt=25.0, rcmdBrt=0.6," - + " preBrt=NaN, lux=100.0, preLux=150.0, hbmMax=0.62, hbmMode=off, rbcStrength=-1," - + " thrmMax=0.65, powerFactor=0.2, wasShortTermModelActive=true, flags=," - + " reason=doze [ low_pwr ], autoBrightness=true, strategy=" - + DISPLAY_BRIGHTNESS_STRATEGY_NAME; + "BrightnessEvent: disp=1, physDisp=test, displayState=ON, brt=0.6, initBrt=25.0," + + " rcmdBrt=0.6, preBrt=NaN, lux=100.0, preLux=150.0, hbmMax=0.62, hbmMode=off," + + " rbcStrength=-1, thrmMax=0.65, powerFactor=0.2, wasShortTermModelActive=true," + + " flags=, reason=doze [ low_pwr ], autoBrightness=true, strategy=" + + DISPLAY_BRIGHTNESS_STRATEGY_NAME + ", autoBrightnessMode=idle"; assertEquals(expectedString, actualString); } @Test public void testFlagsToString() { mBrightnessEvent.reset(); - mBrightnessEvent.setFlags(mBrightnessEvent.getFlags() | BrightnessEvent.FLAG_IDLE_CURVE); + mBrightnessEvent.setFlags(mBrightnessEvent.getFlags() | BrightnessEvent.FLAG_RBC); String actualString = mBrightnessEvent.flagsToString(); - String expectedString = "idle_curve "; + String expectedString = "rbc "; assertEquals(expectedString, actualString); } @@ -90,10 +95,10 @@ public final class BrightnessEventTest { public void testFlagsToString_multipleFlags() { mBrightnessEvent.reset(); mBrightnessEvent.setFlags(mBrightnessEvent.getFlags() - | BrightnessEvent.FLAG_IDLE_CURVE + | BrightnessEvent.FLAG_RBC | BrightnessEvent.FLAG_LOW_POWER_MODE); String actualString = mBrightnessEvent.flagsToString(); - String expectedString = "idle_curve low_power_mode "; + String expectedString = "rbc low_power_mode "; assertEquals(expectedString, actualString); } diff --git a/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java b/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java index 5408e1143330..886780655de2 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java @@ -359,11 +359,17 @@ public class AutomaticBrightnessStrategyTest { AutomaticBrightnessController.class); when(automaticBrightnessController.getAutomaticScreenBrightness(any(BrightnessEvent.class))) .thenReturn(automaticScreenBrightness); + when(automaticBrightnessController.getAutomaticScreenBrightnessBasedOnLastObservedLux( + any(BrightnessEvent.class))) + .thenReturn(automaticScreenBrightness); mAutomaticBrightnessStrategy.setAutomaticBrightnessController( automaticBrightnessController); assertEquals(automaticScreenBrightness, mAutomaticBrightnessStrategy.getAutomaticScreenBrightness( new BrightnessEvent(DISPLAY_ID)), 0.0f); + assertEquals(automaticScreenBrightness, + mAutomaticBrightnessStrategy.getAutomaticScreenBrightnessBasedOnLastObservedLux( + new BrightnessEvent(DISPLAY_ID)), 0.0f); } @Test -- cgit v1.2.3-59-g8ed1b