diff options
author | Lingfeng Yang <lfy@google.com> | 2016-05-03 21:12:45 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-05-03 21:12:45 +0000 |
commit | 2f7ebdd05b9076f81fcecfae5f5f679eb7bcb681 (patch) | |
tree | e90afac0a3f1b2a989412bdaa656b835d0eea93e | |
parent | 8e2f0e48cb3d2209f1cf818b6cf8c4bd95645783 (diff) | |
parent | 892f4f594d0a158ef57ea0e2493822bc005edd49 (diff) | |
download | packages_apps_LegacyCamera-2f7ebdd05b9076f81fcecfae5f5f679eb7bcb681.zip packages_apps_LegacyCamera-2f7ebdd05b9076f81fcecfae5f5f679eb7bcb681.tar.gz packages_apps_LegacyCamera-2f7ebdd05b9076f81fcecfae5f5f679eb7bcb681.tar.bz2 |
Prevent camera app crashes on changing hw.camera.* settings am: 996546fcf4
am: 892f4f594d
* commit '892f4f594d0a158ef57ea0e2493822bc005edd49':
Prevent camera app crashes on changing hw.camera.* settings
Change-Id: Ic45745e8911c8ba7240be749b453e0d770b3ac18
-rw-r--r-- | src/com/android/camera/Camera.java | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 2ca7944..b50ab18 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1085,7 +1085,21 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void getPreferredCameraId() { mPreferences = new ComboPreferences(this); CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal()); - mCameraId = CameraSettings.readPreferredCameraId(mPreferences); + + mNumberOfCameras = CameraHolder.instance().getNumberOfCameras(); + int attemptedCameraId = CameraSettings.readPreferredCameraId(mPreferences); + + // It is possible that the user can connect/disconnect cameras + // between device boots. + // We need to check that the preferred camera ID + // does not refer to a disconnected camera. + if (attemptedCameraId >= mNumberOfCameras) { + Log.v(TAG, "Preferred camera (id= " + attemptedCameraId + + ") missing. Defaulting to the first one"); + mCameraId = 0; + } else { + mCameraId = attemptedCameraId; + } // Testing purpose. Launch a specific camera through the intent extras. int intentCameraId = Util.getCameraFacingIntentExtras(this); @@ -1144,7 +1158,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener, mPreferences.setLocalId(this, mCameraId); CameraSettings.upgradeLocalPreferences(mPreferences.getLocal()); - mNumberOfCameras = CameraHolder.instance().getNumberOfCameras(); mQuickCapture = getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false); // we need to reset exposure for the preview |