Guard against null input device in StylusDeviceUpdater

Bug: 279170207
Test: StylusDeviceUpdaterTest
Change-Id: Ib4a3f12eaceb87370c800a9dc7eda819c706cd3b
This commit is contained in:
Vania Januar
2023-04-27 15:51:13 +01:00
parent 85e5174132
commit a1af049378
2 changed files with 27 additions and 1 deletions

View File

@@ -100,6 +100,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
@Override
public void onInputDeviceAdded(int deviceId) {
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
if (inputDevice == null) return;
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)
&& !inputDevice.isExternal()) {
try {
@@ -121,7 +123,10 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
@Override
public void onInputDeviceChanged(int deviceId) {
if (mInputManager.getInputDevice(deviceId).supportsSource(InputDevice.SOURCE_STYLUS)) {
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
if (inputDevice == null) return;
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)) {
forceUpdate();
}
}
@@ -189,6 +194,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
boolean hasConnectedBluetoothStylusDevice() {
for (int deviceId : mInputManager.getInputDeviceIds()) {
InputDevice device = mInputManager.getInputDevice(deviceId);
if (device == null) continue;
if (device.supportsSource(InputDevice.SOURCE_STYLUS)
&& mInputManager.getInputDeviceBluetoothAddress(deviceId) != null) {
return true;