From 3d7833776cd82b60178ddf3ee2c6c4fdbb8f28ae Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 1 Apr 2022 13:38:21 -0700 Subject: [PATCH] Add nullability annotations to some InputDevice APIs In a previous CL, we fixed a null dereference bug. Here, we add the nullability annotations. Bug: 227733127 Test: build only Change-Id: I8db92e6c95993d0e1715632fac55f3d30e3c4d37 --- core/api/current.txt | 4 ++-- core/java/android/hardware/input/InputManager.java | 1 + core/java/android/view/InputDevice.java | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 4955860900521..c5ab512cfb3b0 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -18530,7 +18530,7 @@ package android.hardware.fingerprint { package android.hardware.input { public final class InputManager { - method public android.view.InputDevice getInputDevice(int); + method @Nullable public android.view.InputDevice getInputDevice(int); method public int[] getInputDeviceIds(); method @FloatRange(from=0, to=1) public float getMaximumObscuringOpacityForTouch(); method public void registerInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener, android.os.Handler); @@ -48166,7 +48166,7 @@ package android.view { method @NonNull public android.hardware.BatteryState getBatteryState(); method public int getControllerNumber(); method public String getDescriptor(); - method public static android.view.InputDevice getDevice(int); + method @Nullable public static android.view.InputDevice getDevice(int); method public static int[] getDeviceIds(); method public int getId(); method public android.view.KeyCharacterMap getKeyCharacterMap(); diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 194566dddc475..bc6736fbea468 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -346,6 +346,7 @@ public final class InputManager { * @param id The device id. * @return The input device or null if not found. */ + @Nullable public InputDevice getInputDevice(int id) { synchronized (mInputDevicesLock) { populateInputDevicesLocked(); diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index 7d5603994efaf..addbab07c4789 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -18,6 +18,7 @@ package android.view; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; @@ -517,6 +518,7 @@ public final class InputDevice implements Parcelable { * @param id The device id. * @return The input device or null if not found. */ + @Nullable public static InputDevice getDevice(int id) { return InputManager.getInstance().getInputDevice(id); }