From 70e618bdd825eb8b088d66feeefc0a7f0b06c7ed Mon Sep 17 00:00:00 2001 From: codeworkx Date: Sat, 26 Aug 2017 12:48:59 +0200 Subject: Snap: don't try to set up cameras with ids greater than MAX_NUM_CAM * fixes ArrayIndexOutOfBoundsException on setUpCameraOutputs Change-Id: I1565576b604bdcebea85d65f3c7a2b332292ed2d --- src/com/android/camera/CaptureModule.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index d52996b38..591d82df7 100755 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -2666,6 +2666,7 @@ public class CaptureModule implements CameraModule, PhotoController, CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE); try { String[] cameraIdList = manager.getCameraIdList(); + int cameraIdListLength = cameraIdList.length; //inti heifWriter and get input surface if (mSettingsManager.getSavePictureFormat() == SettingsManager.HEIF_FORMAT) { String tmpPath = mActivity.getCacheDir().getPath() + "/" + "heif.tmp"; @@ -2675,7 +2676,16 @@ public class CaptureModule implements CameraModule, PhotoController, mInitHeifWriter = createHEIFEncoder(tmpPath, mPictureSize.getWidth(), mPictureSize.getHeight(), 0,1, 85); } - for (int i = 0; i < cameraIdList.length; i++) { + + if (cameraIdListLength > MAX_NUM_CAM) + Log.w(TAG, "Number of available cameras (" + cameraIdListLength + ") exceeds " + + "max supported cameras (" + MAX_NUM_CAM + ")"); + + for (int i = 0; i < cameraIdListLength; i++) { + if (i >= MAX_NUM_CAM) { + Log.w(TAG, "Skipping set up for camera with id " + i); + break; + } String cameraId = cameraIdList[i]; CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); -- cgit v1.2.3