aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Trost <natetrost@google.com>2023-08-18 13:50:25 -0500
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-08-30 08:28:48 +0000
commit3fc90ec39d20c75f8fb4c06f720db98cdc4d3cf7 (patch)
tree0eebfb469eaae1bd4071c3c6a43b346cb38dec96
parent3be48dd5d5b21c903a571e5c2107a5586fcdb652 (diff)
downloadgamesdk-snap-temp-L45500000962841003.tar.gz
Fix rare null reference in onInputDeviceChangedsnap-temp-L45500000962841003
It appears onInputDeviceChanged can pass a device id which ends up resulting in a null InputDevice from getInputDevice. A null check was missing in a utility function, which under rare circumstances could cause a null reference exception. Bug: b/296598607 Test: Build and run game controller sample (cherry picked from https://android-review.googlesource.com/q/commit:22813edce5414b4f4585dec05713cf12bb567720) Merged-In: Ibe5e0e587f4682051f01dc717e6c9e0cdb86cd6c Change-Id: Ibe5e0e587f4682051f01dc717e6c9e0cdb86cd6c
-rw-r--r--games-controller/src/main/java/com/google/android/games/paddleboat/GameControllerManager.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/games-controller/src/main/java/com/google/android/games/paddleboat/GameControllerManager.java b/games-controller/src/main/java/com/google/android/games/paddleboat/GameControllerManager.java
index ca3f8eb8..620db847 100644
--- a/games-controller/src/main/java/com/google/android/games/paddleboat/GameControllerManager.java
+++ b/games-controller/src/main/java/com/google/android/games/paddleboat/GameControllerManager.java
@@ -206,18 +206,20 @@ public class GameControllerManager {
boolean needsMotionRanges) {
boolean isSource = false;
InputDevice inputDevice = InputDevice.getDevice(deviceId);
- int inputDeviceSources = inputDevice.getSources();
- int sourceMask = InputDevice.SOURCE_ANY & matchingSourceMask;
-
- if (inputDevice.isVirtual() == false) {
- if ((inputDeviceSources & sourceMask) != 0) {
- List<InputDevice.MotionRange> motionRanges = inputDevice.getMotionRanges();
- if (needsMotionRanges) {
- if (motionRanges.size() > 0) {
+ if (inputDevice != null) {
+ int inputDeviceSources = inputDevice.getSources();
+ int sourceMask = InputDevice.SOURCE_ANY & matchingSourceMask;
+
+ if (inputDevice.isVirtual() == false) {
+ if ((inputDeviceSources & sourceMask) != 0) {
+ List<InputDevice.MotionRange> motionRanges = inputDevice.getMotionRanges();
+ if (needsMotionRanges) {
+ if (motionRanges.size() > 0) {
+ isSource = true;
+ }
+ } else {
isSource = true;
}
- } else {
- isSource = true;
}
}
}