Camera2OneCameraManagerImpl: fix NPE when only one camera is available
* AOSP 10 introduced a crash on devices with only one camera that was
not present on AOSP 9. This was introduced in commit 8b07da, which
added cache to the result of `findCameraId()`, but did not check if
the value is null before adding to cache. Code elsewhere checked the
result of `findCameraId()` to avoid NPEs, but the function itself
would crash if it were ever to return null due to this regression.
* Fixed by simply wrapping the addition to cache in a null check.
Change-Id: I01730cf6d2ffb7a82cc243de7313f1a955afd6bf
diff --git a/src/com/android/camera/one/v2/Camera2OneCameraManagerImpl.java b/src/com/android/camera/one/v2/Camera2OneCameraManagerImpl.java
index 031c610..283ac67 100644
--- a/src/com/android/camera/one/v2/Camera2OneCameraManagerImpl.java
+++ b/src/com/android/camera/one/v2/Camera2OneCameraManagerImpl.java
@@ -145,7 +145,9 @@
id = findFirstBackCameraId();
}
- mCameraFacingCache.put(facing, id);
+ if (id != null) {
+ mCameraFacingCache.put(facing, id);
+ }
return id;
}