Merge "Update brightness nits to keep brightnessFloat same when RBC toggled" into tm-dev am: 2f8fc626c3 am: 06305bb550

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18889029

Change-Id: I60c17c12d2057cf29e54e30bc712dec910cf2b8a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-06-16 09:05:55 +00:00
committed by Automerger Merge Worker
3 changed files with 32 additions and 20 deletions

View File

@@ -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 {

View File

@@ -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();
}
/**

View File

@@ -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<SensorEventListener> 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