From 433a1ad2b85d30ff03dc6a7a7f7a93620df51d54 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Thu, 28 Jul 2022 15:46:11 -0700 Subject: 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 --- .../server/inputmethod/InputMethodManagerService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index af95b4f54eb4..5318848d6a17 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -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); } } -- cgit v1.2.3-59-g8ed1b