diff options
Diffstat (limited to 'src/com/android')
-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 f7de7f6..254db28 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1089,7 +1089,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); @@ -1148,7 +1162,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 |