Loading core/java/com/android/internal/display/BrightnessSynchronizer.java +1 −2 Original line number Diff line number Diff line Loading @@ -60,8 +60,7 @@ public class BrightnessSynchronizer { private static final int MSG_RUN_UPDATE = 1; // The tolerance within which we consider brightness values approximately equal to eachother. public static final float EPSILON = 0.0001f; public static final float EPSILON = 0.0000001f; private static int sBrightnessUpdateCount = 1; private final Context mContext; Loading services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java +63 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.os.Handler; import android.os.PowerManager; import android.os.SystemClock; import android.os.test.TestLooper; import android.util.MathUtils; import android.util.SparseArray; import android.view.Display; Loading @@ -54,6 +55,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.internal.display.BrightnessUtils; import com.android.server.display.brightness.clamper.BrightnessClamperController; import com.android.server.display.config.HysteresisLevels; import com.android.server.display.feature.DisplayManagerFlags; Loading Loading @@ -797,6 +799,67 @@ public class AutomaticBrightnessControllerTest { assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getRawAutomaticScreenBrightness(), 0.0f); } /** * Tests that movement from 1% brightness to 0% brightness is possible. * Because of gamma conversion, the difference in float brightness between 0 and 1 * percent is very small and this ensures that our float-comparison (using EPSILON) * can tell the difference between the two small values. */ @Test public void testBrightnessChangeAtLowEnd() throws Exception { 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(); // Min and Max brightness may be reduced due to conditions such as ambient environment, // thermal, etc. So, lets further reduce the range of the brightness values since that // can also affect the floating-point comparison resolution. float minBrightness = 0.01f; float maxBrightness = 0.25f; float twoPercentLux = 40; float twoPercent = 0.02f; float twoPercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(twoPercent)); when(mBrightnessMappingStrategy.getBrightness(eq(twoPercentLux), eq(null), anyInt())) .thenReturn(twoPercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) twoPercentLux)); assertEquals(twoPercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(twoPercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); float onePercentLux = 20; float onePercent = 0.01f; float onePercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(onePercent)); when(mBrightnessMappingStrategy.getBrightness(anyFloat(), eq(null), anyInt())) .thenReturn(onePercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) onePercentLux)); assertEquals(onePercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(onePercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); // Make a small change down an ensure the brightness actually changes. float zeroPercentLux = 2; float zeroPercent = 0.00f; float zeroPercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(zeroPercent)); when(mBrightnessMappingStrategy.getBrightness(anyFloat(), eq(null), anyInt())) .thenReturn(zeroPercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) zeroPercentLux)); assertEquals(zeroPercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(zeroPercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); } @Test public void testGetSensorReadings() throws Exception { ArgumentCaptor<SensorEventListener> listenerCaptor = Loading Loading
core/java/com/android/internal/display/BrightnessSynchronizer.java +1 −2 Original line number Diff line number Diff line Loading @@ -60,8 +60,7 @@ public class BrightnessSynchronizer { private static final int MSG_RUN_UPDATE = 1; // The tolerance within which we consider brightness values approximately equal to eachother. public static final float EPSILON = 0.0001f; public static final float EPSILON = 0.0000001f; private static int sBrightnessUpdateCount = 1; private final Context mContext; Loading
services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java +63 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.os.Handler; import android.os.PowerManager; import android.os.SystemClock; import android.os.test.TestLooper; import android.util.MathUtils; import android.util.SparseArray; import android.view.Display; Loading @@ -54,6 +55,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.internal.display.BrightnessUtils; import com.android.server.display.brightness.clamper.BrightnessClamperController; import com.android.server.display.config.HysteresisLevels; import com.android.server.display.feature.DisplayManagerFlags; Loading Loading @@ -797,6 +799,67 @@ public class AutomaticBrightnessControllerTest { assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getRawAutomaticScreenBrightness(), 0.0f); } /** * Tests that movement from 1% brightness to 0% brightness is possible. * Because of gamma conversion, the difference in float brightness between 0 and 1 * percent is very small and this ensures that our float-comparison (using EPSILON) * can tell the difference between the two small values. */ @Test public void testBrightnessChangeAtLowEnd() throws Exception { 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(); // Min and Max brightness may be reduced due to conditions such as ambient environment, // thermal, etc. So, lets further reduce the range of the brightness values since that // can also affect the floating-point comparison resolution. float minBrightness = 0.01f; float maxBrightness = 0.25f; float twoPercentLux = 40; float twoPercent = 0.02f; float twoPercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(twoPercent)); when(mBrightnessMappingStrategy.getBrightness(eq(twoPercentLux), eq(null), anyInt())) .thenReturn(twoPercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) twoPercentLux)); assertEquals(twoPercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(twoPercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); float onePercentLux = 20; float onePercent = 0.01f; float onePercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(onePercent)); when(mBrightnessMappingStrategy.getBrightness(anyFloat(), eq(null), anyInt())) .thenReturn(onePercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) onePercentLux)); assertEquals(onePercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(onePercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); // Make a small change down an ensure the brightness actually changes. float zeroPercentLux = 2; float zeroPercent = 0.00f; float zeroPercentLinearBrightness = MathUtils.lerp(minBrightness, maxBrightness, BrightnessUtils.convertGammaToLinear(zeroPercent)); when(mBrightnessMappingStrategy.getBrightness(anyFloat(), eq(null), anyInt())) .thenReturn(zeroPercentLinearBrightness); listener.onSensorChanged(createSensorEvent(mLightSensor, (int) zeroPercentLux)); assertEquals(zeroPercentLinearBrightness, mController.getAutomaticScreenBrightness(), 0.0f); assertEquals(zeroPercentLinearBrightness, mController.getRawAutomaticScreenBrightness(), 0.0f); } @Test public void testGetSensorReadings() throws Exception { ArgumentCaptor<SensorEventListener> listenerCaptor = Loading