From fcd98c4a67322d433a82e76eea374ed1e32906ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wilczy=C5=84ski?= Date: Fri, 13 Jan 2023 15:35:46 +0000 Subject: [PATCH] Pass ambient lux to the HBM controllers of the follower DPCs - set the state of the HBM controller independently of the state of the ABC Bug: 241307705 Test: atest AutomaticBrightnessControllerTest Test: atest DisplayPowerControllerTest Test: atest DisplayPowerController2Test Change-Id: Ie1254aadd1d6a42b1305e1b18f51575ada61a60d --- .../display/AutomaticBrightnessController.java | 2 -- .../server/display/DisplayPowerController.java | 14 +++++++++++--- .../server/display/DisplayPowerController2.java | 14 +++++++++++--- .../display/DisplayPowerControllerInterface.java | 6 ++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index 05464c8100616..592daa61f36c9 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -402,7 +402,6 @@ class AutomaticBrightnessController { boolean userChangedAutoBrightnessAdjustment, int displayPolicy, boolean shouldResetShortTermModel) { mState = state; - mHbmController.setAutoBrightnessEnabled(mState); // 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 @@ -466,7 +465,6 @@ class AutomaticBrightnessController { mHandler.sendEmptyMessage(MSG_RUN_UPDATE); } - @VisibleForTesting float getAmbientLux() { return mAmbientLux; } diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index dbd2ab0cbe60d..1b156991ef42f 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -719,7 +719,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } @Override - public void setBrightnessToFollow(float leadDisplayBrightness, float nits) { + public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { + mHbmController.onAmbientLuxChange(ambientLux); if (mAutomaticBrightnessController == null || nits < 0) { mBrightnessToFollow = leadDisplayBrightness; } else { @@ -751,7 +752,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } for (int i = 0; i < followers.size(); i++) { DisplayPowerControllerInterface follower = followers.valueAt(i); - follower.setBrightnessToFollow(PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1); + follower.setBrightnessToFollow(PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1, + /* ambientLux= */ 0); } } @@ -1523,6 +1525,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mShouldResetShortTermModel); mShouldResetShortTermModel = false; } + mHbmController.setAutoBrightnessEnabled(mUseAutoBrightness + ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED + : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); if (mBrightnessTracker != null) { mBrightnessTracker.setBrightnessConfiguration(mBrightnessConfiguration); @@ -1634,9 +1639,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAppliedThrottling = false; } + float ambientLux = mAutomaticBrightnessController == null ? 0 + : mAutomaticBrightnessController.getAmbientLux(); for (int i = 0; i < displayBrightnessFollowers.size(); i++) { DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i); - follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState)); + follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState), + ambientLux); } if (updateScreenBrightnessSetting) { diff --git a/services/core/java/com/android/server/display/DisplayPowerController2.java b/services/core/java/com/android/server/display/DisplayPowerController2.java index 103a1dac4ecb1..53b7d86ca0d99 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController2.java +++ b/services/core/java/com/android/server/display/DisplayPowerController2.java @@ -1236,6 +1236,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal mShouldResetShortTermModel); mShouldResetShortTermModel = false; } + mHbmController.setAutoBrightnessEnabled(mUseAutoBrightness + ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED + : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); if (mBrightnessTracker != null) { mBrightnessTracker.setBrightnessConfiguration(mBrightnessConfiguration); @@ -1347,9 +1350,12 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal mAppliedThrottling = false; } + float ambientLux = mAutomaticBrightnessController == null ? 0 + : mAutomaticBrightnessController.getAmbientLux(); for (int i = 0; i < displayBrightnessFollowers.size(); i++) { DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i); - follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState)); + follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState), + ambientLux); } if (updateScreenBrightnessSetting) { @@ -2136,7 +2142,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal } @Override - public void setBrightnessToFollow(float leadDisplayBrightness, float nits) { + public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { + mHbmController.onAmbientLuxChange(ambientLux); if (mAutomaticBrightnessController == null || nits < 0) { mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); } else { @@ -2217,7 +2224,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal } for (int i = 0; i < followers.size(); i++) { DisplayPowerControllerInterface follower = followers.valueAt(i); - follower.setBrightnessToFollow(PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1); + follower.setBrightnessToFollow(PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1, + /* ambientLux= */ 0); } } diff --git a/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java b/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java index a95ac74b27c80..4612ec9cf2dcc 100644 --- a/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java +++ b/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java @@ -173,9 +173,11 @@ public interface DisplayPowerControllerInterface { * displays. * @param leadDisplayBrightness The brightness of the lead display in the set of concurrent * displays - * @param nits The brightness value in nits if the device supports nits + * @param nits The brightness value in nits if the device supports nits. Set to a negative + * number otherwise. + * @param ambientLux The lux value that will be passed to {@link HighBrightnessModeController} */ - void setBrightnessToFollow(float leadDisplayBrightness, float nits); + void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux); /** * Add an additional display that will copy the brightness value from this display. This is used