summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/Camera.java17
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