Add null check for IM#getInputDevice(id) in IMMS

InputManager#getInputDevice can return null. Always null-check.

Fix: 240606389
Test: atest CtsInputMethodTestCases
Change-Id: I7593d26f839520c10944ce6b3746b611ccaeaf64
This commit is contained in:
Taran Singh
2022-07-28 15:46:11 -07:00
parent 953c2f9b58
commit 433a1ad2b8

View File

@@ -4360,7 +4360,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
im.registerInputDeviceListener(new InputManager.InputDeviceListener() {
@Override
public void onInputDeviceAdded(int deviceId) {
if (isStylusDevice(im.getInputDevice(deviceId))) {
InputDevice device = im.getInputDevice(deviceId);
if (device != null && isStylusDevice(device)) {
add(deviceId);
}
}
@@ -4372,7 +4373,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
@Override
public void onInputDeviceChanged(int deviceId) {
if (isStylusDevice(im.getInputDevice(deviceId))) {
InputDevice device = im.getInputDevice(deviceId);
if (device == null) {
return;
}
if (isStylusDevice(device)) {
add(deviceId);
} else {
remove(deviceId);
@@ -4471,8 +4476,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
if (!im.isInputDeviceEnabled(id)) {
continue;
}
InputDevice inputDevice = im.getInputDevice(id);
if (isStylusDevice(inputDevice)) {
InputDevice device = im.getInputDevice(id);
if (device != null && isStylusDevice(device)) {
stylusIds.add(id);
}
}