Ensure that brightness level is within 0-100%.
Check whether the retrieved brightnesss value is out of range, and adjust it if necessary. Change-Id: Ieb1ccc03dcb9fa3e1ed192fcc3d217b84d4d316c Fix: 63181935 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -143,7 +143,7 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
||||
final float value = Settings.System.getFloat(mContentResolver,
|
||||
System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
|
||||
// auto brightness is between -1 and 1
|
||||
return ((value + 1)) / 2;
|
||||
return getPercentage(value, -1, 1);
|
||||
}
|
||||
final double value = Settings.System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS,
|
||||
mMinBrightness);
|
||||
@@ -151,6 +151,12 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
||||
}
|
||||
|
||||
private double getPercentage(double value, int min, int max) {
|
||||
if (value > max) {
|
||||
return 1.0;
|
||||
}
|
||||
if (value < min) {
|
||||
return 0.0;
|
||||
}
|
||||
return (value - min) / (max - min);
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.display;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -130,7 +131,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_autoBrightness_shouldSetSummaryToVrBrightness() {
|
||||
public void updateState_autoBrightness_shouldSetSummaryToAutoBrightness() {
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
@@ -143,7 +144,7 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_manualBrightness_shouldSetSummaryToVrBrightness() {
|
||||
public void updateState_manualBrightness_shouldSetSummaryToScreenBrightness() {
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
@@ -154,4 +155,45 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
|
||||
verify(mPreference).setSummary("45%");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_brightnessOutOfRange_shouldSetSummaryInRange() {
|
||||
// VR mode
|
||||
doReturn(true).when(mController).isInVrMode();
|
||||
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR, 105);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("100%");
|
||||
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR, -20);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("0%");
|
||||
|
||||
// Auto mode
|
||||
doReturn(false).when(mController).isInVrMode();
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
|
||||
reset(mPreference);
|
||||
System.putFloat(mContentResolver, System.SCREEN_AUTO_BRIGHTNESS_ADJ, 1.5f);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("100%");
|
||||
|
||||
System.putFloat(mContentResolver, System.SCREEN_AUTO_BRIGHTNESS_ADJ, -1.5f);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("0%");
|
||||
|
||||
// Manual mode
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
|
||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
|
||||
reset(mPreference);
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 115);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("100%");
|
||||
|
||||
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, -10);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("0%");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user