From 6764156fa1d5263856c303edbfa5f1356fb94c6c Mon Sep 17 00:00:00 2001 From: Rupesh Bansal Date: Tue, 14 Jun 2022 17:01:28 +0000 Subject: [PATCH] Update brightness nits to keep brightnessFloat same when RBC toggled Bug: 230563819 Test: Manually toggle RBC, and observe that brightness nits change, with no change in the brightness percentage. Change-Id: Icb2bff98479cc44aa773ab6e2a828bb281dedbc1 --- .../AutomaticBrightnessController.java | 12 ++++++- .../display/DisplayPowerController.java | 6 ---- .../AutomaticBrightnessControllerTest.java | 34 ++++++++++++------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index cf63b69254f83..6fd88411593f2 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -1057,7 +1057,17 @@ class AutomaticBrightnessController { public void recalculateSplines(boolean applyAdjustment, float[] adjustment) { mCurrentBrightnessMapper.recalculateSplines(applyAdjustment, adjustment); - updateAutoBrightness(true /*sendUpdate*/, false /*isManuallySet*/); + + // If rbc is turned on, off or there is a change in strength, we want to reset the short + // term model. Since the nits range at which brightness now operates has changed due to + // RBC/strength change, any short term model based on the previous range should be + // invalidated. + resetShortTermModel(); + + // When rbc is turned on, we want to accommodate this change in the short term model. + if (applyAdjustment) { + setScreenBrightnessByUser(getAutomaticScreenBrightness()); + } } private final class AutomaticBrightnessHandler extends Handler { diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index a5bb716e67b7a..d05a902c65932 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -657,12 +657,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } mIsRbcActive = mCdsi.isReduceBrightColorsActivated(); mAutomaticBrightnessController.recalculateSplines(mIsRbcActive, adjustedNits); - - // If rbc is turned on, off or there is a change in strength, we want to reset the short - // term model. Since the nits range at which brightness now operates has changed due to - // RBC/strength change, any short term model based on the previous range should be - // invalidated. - mAutomaticBrightnessController.resetShortTermModel(); } /** diff --git a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java index b0c52f1fdbb8c..9d82f1a90c778 100644 --- a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyFloat; import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -258,29 +259,36 @@ public class AutomaticBrightnessControllerTest { @Test public void testRecalculateSplines() throws Exception { // Enabling the light sensor, and setting the ambient lux to 1000 + int currentLux = 1000; 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(); - listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000)); + listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, currentLux)); - //Setting the brightnessFloat to 0.5f - float currentBrightnessFloat = 0.5f; - when(mBrightnessMappingStrategy.getBrightness(1000, - null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(currentBrightnessFloat); + // User sets brightness to 0.5f + when(mBrightnessMappingStrategy.getBrightness(currentLux, + null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(0.5f); mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */, - currentBrightnessFloat /* brightness */, false /* userChangedBrightness */, - 0 /* adjustment */, false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT); + 0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */, + false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT); - // Adjusting spline, and accordingly remapping the current 0.5f brightnessFloat to 0.3f - float updatedBrightnessFloat = 0.3f; - when(mBrightnessMappingStrategy.getBrightness(1000, - null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(updatedBrightnessFloat); - float[] adjustments = new float[]{0.2f, 0.5f}; + //Recalculating the spline with RBC enabled, verifying that the short term model is reset, + //and the interaction is learnt in short term model + float[] adjustments = new float[]{0.2f, 0.6f}; mController.recalculateSplines(true, adjustments); + verify(mBrightnessMappingStrategy).clearUserDataPoints(); verify(mBrightnessMappingStrategy).recalculateSplines(true, adjustments); - assertEquals(mController.getAutomaticScreenBrightness(), updatedBrightnessFloat, EPSILON); + verify(mBrightnessMappingStrategy, times(2)).addUserDataPoint(currentLux, 0.5f); + + clearInvocations(mBrightnessMappingStrategy); + + // Verify short term model is not learnt when RBC is disabled + mController.recalculateSplines(false, adjustments); + verify(mBrightnessMappingStrategy).clearUserDataPoints(); + verify(mBrightnessMappingStrategy).recalculateSplines(false, adjustments); + verifyNoMoreInteractions(mBrightnessMappingStrategy); } @Test