Merge "Fix crash: ArrayIndexOutOfBounds on restoring backlight" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
78a9212630
@@ -199,8 +199,11 @@ final class KeyboardBacklightController implements
|
||||
}
|
||||
if (brightness.isPresent()) {
|
||||
int brightnessValue = Math.max(0, Math.min(MAX_BRIGHTNESS, brightness.getAsInt()));
|
||||
int brightnessLevel = Arrays.binarySearch(BRIGHTNESS_VALUE_FOR_LEVEL, brightnessValue);
|
||||
updateBacklightState(inputDevice.getId(), keyboardBacklight, brightnessLevel,
|
||||
int index = Arrays.binarySearch(BRIGHTNESS_VALUE_FOR_LEVEL, brightnessValue);
|
||||
if (index < 0) {
|
||||
index = Math.min(NUM_BRIGHTNESS_CHANGE_STEPS, -(index + 1));
|
||||
}
|
||||
updateBacklightState(inputDevice.getId(), keyboardBacklight, index,
|
||||
false /* isTriggeredByKeyPress */);
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Restoring brightness level " + brightness.getAsInt());
|
||||
|
||||
@@ -250,20 +250,24 @@ class KeyboardBacklightControllerTests {
|
||||
`when`(iInputManager.getInputDevice(DEVICE_ID)).thenReturn(keyboardWithBacklight)
|
||||
`when`(iInputManager.getLights(DEVICE_ID)).thenReturn(listOf(keyboardBacklight))
|
||||
|
||||
dataStore.setKeyboardBacklightBrightness(
|
||||
keyboardWithBacklight.descriptor,
|
||||
LIGHT_ID,
|
||||
MAX_BRIGHTNESS
|
||||
)
|
||||
for (level in 1 until BRIGHTNESS_VALUE_FOR_LEVEL.size) {
|
||||
dataStore.setKeyboardBacklightBrightness(
|
||||
keyboardWithBacklight.descriptor,
|
||||
LIGHT_ID,
|
||||
BRIGHTNESS_VALUE_FOR_LEVEL[level] - 1
|
||||
)
|
||||
|
||||
keyboardBacklightController.onInputDeviceAdded(DEVICE_ID)
|
||||
keyboardBacklightController.notifyUserActivity()
|
||||
testLooper.dispatchNext()
|
||||
assertEquals(
|
||||
"Keyboard backlight level should be restored to the level saved in the data store",
|
||||
Color.argb(MAX_BRIGHTNESS, 0, 0, 0),
|
||||
lightColorMap[LIGHT_ID]
|
||||
)
|
||||
keyboardBacklightController.onInputDeviceAdded(DEVICE_ID)
|
||||
keyboardBacklightController.notifyUserActivity()
|
||||
testLooper.dispatchNext()
|
||||
assertEquals(
|
||||
"Keyboard backlight level should be restored to the level saved in the data " +
|
||||
"store",
|
||||
Color.argb(BRIGHTNESS_VALUE_FOR_LEVEL[level], 0, 0, 0),
|
||||
lightColorMap[LIGHT_ID]
|
||||
)
|
||||
keyboardBacklightController.onInputDeviceRemoved(DEVICE_ID)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user