diff options
author | Lingfeng Yang <lfy@google.com> | 2016-05-03 21:07:59 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-05-03 21:07:59 +0000 |
commit | 892f4f594d0a158ef57ea0e2493822bc005edd49 (patch) | |
tree | e90afac0a3f1b2a989412bdaa656b835d0eea93e | |
parent | 8e2f0e48cb3d2209f1cf818b6cf8c4bd95645783 (diff) | |
parent | 996546fcf4058d98d9aceecb4086283e17ae6c9d (diff) | |
download | packages_apps_LegacyCamera-892f4f594d0a158ef57ea0e2493822bc005edd49.zip packages_apps_LegacyCamera-892f4f594d0a158ef57ea0e2493822bc005edd49.tar.gz packages_apps_LegacyCamera-892f4f594d0a158ef57ea0e2493822bc005edd49.tar.bz2 |
Prevent camera app crashes on changing hw.camera.* settings
am: 996546fcf4
* commit '996546fcf4058d98d9aceecb4086283e17ae6c9d':
Prevent camera app crashes on changing hw.camera.* settings
Change-Id: I372bf5a00f021c89abda49966bc12eaca97a80c5
-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 |