Merge "Handling case when device returned from InputManager is null" into udc-dev

This commit is contained in:
Michał Brzeziński
2023-04-20 11:25:04 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ constructor(
}
private fun isPhysicalFullKeyboard(deviceId: Int): Boolean {
val device = inputManager.getInputDevice(deviceId)
val device = inputManager.getInputDevice(deviceId) ?: return false
return !device.isVirtual && device.isFullKeyboard
}

View File

@@ -95,6 +95,16 @@ class KeyboardRepositoryTest : SysuiTestCase() {
assertThat(isKeyboardConnected).isTrue()
}
@Test
fun emitsDisconnected_whenDeviceWithIdDoesNotExist() =
testScope.runTest {
val deviceListener = captureDeviceListener()
val isKeyboardConnected by collectLastValue(underTest.keyboardConnected)
deviceListener.onInputDeviceAdded(NULL_DEVICE_ID)
assertThat(isKeyboardConnected).isFalse()
}
@Test
fun emitsDisconnected_whenKeyboardDisconnects() =
testScope.runTest {
@@ -172,6 +182,7 @@ class KeyboardRepositoryTest : SysuiTestCase() {
private const val VIRTUAL_FULL_KEYBOARD_ID = 2
private const val PHYSICAL_NOT_FULL_KEYBOARD_ID = 3
private const val ANOTHER_PHYSICAL_FULL_KEYBOARD_ID = 4
private const val NULL_DEVICE_ID = 5
private val INPUT_DEVICES_MAP: Map<Int, InputDevice> =
mapOf(