From 8970010a5e9f3dc5c069f56b4147552accfcbbeb Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 1 Apr 2022 13:38:21 -0700 Subject: [PATCH] Check that InputDevice isn't null and add annotations The API 'getDevice' can return null. Let's make sure null isn't dereferenced. Also, add nullability annotations to make it easier to follow. Bug: 227733127 Test: build only Change-Id: Ice514f27d4347528d009969174f09078dfa2afac --- core/java/android/hardware/input/InputDeviceSensorManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/hardware/input/InputDeviceSensorManager.java b/core/java/android/hardware/input/InputDeviceSensorManager.java index 89db857b860b8..8a40d00327f1d 100644 --- a/core/java/android/hardware/input/InputDeviceSensorManager.java +++ b/core/java/android/hardware/input/InputDeviceSensorManager.java @@ -98,7 +98,7 @@ public class InputDeviceSensorManager implements InputManager.InputDeviceListene */ private void updateInputDeviceSensorInfoLocked(int deviceId) { final InputDevice inputDevice = InputDevice.getDevice(deviceId); - if (inputDevice.hasSensor()) { + if (inputDevice != null && inputDevice.hasSensor()) { final InputSensorInfo[] sensorInfos = mInputManager.getSensorList(deviceId); populateSensorsForInputDeviceLocked(deviceId, sensorInfos);