Merge "Make message more clear." into gb-ub-photos-denali
diff --git a/src/com/android/camera/app/CameraController.java b/src/com/android/camera/app/CameraController.java
index 88ba313..1d0c189 100644
--- a/src/com/android/camera/app/CameraController.java
+++ b/src/com/android/camera/app/CameraController.java
@@ -121,8 +121,12 @@
 
     @Override
     public void onCameraOpened(CameraManager.CameraProxy camera) {
-        mRequestingCameraId = -1;
         mCameraProxy = camera;
+        if(mRequestingCameraId == -1) {
+            // Not requesting any camera.
+            return;
+        }
+        mRequestingCameraId = -1;
         mCallbackReceiver.onCameraOpened(camera);
     }
 
@@ -170,12 +174,19 @@
 
     @Override
     public void releaseCamera(int id) {
+        if (mCameraProxy == null) {
+            if (mRequestingCameraId == -1) {
+                // Camera not requested yet.
+                Log.w(TAG, "Trying to release the camera before requesting");
+            }
+            // Camera requested but not available yet.
+            mRequestingCameraId = -1;
+            return;
+        }
         if (mCameraProxy.getCameraId() != id) {
             throw new IllegalStateException("Trying to release an unopened camera.");
         }
-        if (mRequestingCameraId != -1) {
-            mRequestingCameraId = -1;
-        }
+        mRequestingCameraId = -1;
     }
 
     public void removeCallbackReceiver() {
diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java
index c8ef3c2..d44c2a5 100644
--- a/src/com/android/camera/data/LocalMediaData.java
+++ b/src/com/android/camera/data/LocalMediaData.java
@@ -606,42 +606,43 @@
             String path = c.getString(COL_DATA);
             int width = c.getInt(COL_WIDTH);
             int height = c.getInt(COL_HEIGHT);
-            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
-            String rotation = null;
-            try {
-                retriever.setDataSource(path);
-            } catch (RuntimeException ex) {
-                // setDataSource() can cause RuntimeException beyond
-                // IllegalArgumentException. e.g: data contain *.avi file.
-                retriever.release();
-                Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:"
-                        + ex.getMessage());
-                return null;
-            }
-            rotation = retriever.extractMetadata(
-                    MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
 
             // Extracts video height/width if available. If unavailable, set to
             // 0.
             if (width == 0 || height == 0) {
+                MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+                String rotation = null;
+                try {
+                    retriever.setDataSource(path);
+                } catch (RuntimeException ex) {
+                    // setDataSource() can cause RuntimeException beyond
+                    // IllegalArgumentException. e.g: data contain *.avi file.
+                    retriever.release();
+                    Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:"
+                            + ex.getMessage());
+                    return null;
+                }
+                rotation = retriever.extractMetadata(
+                        MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
+
                 String val = retriever.extractMetadata(
                         MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
                 width = (val == null) ? 0 : Integer.parseInt(val);
                 val = retriever.extractMetadata(
                         MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
                 height = (val == null) ? 0 : Integer.parseInt(val);
-            }
-            retriever.release();
-            if (width == 0 || height == 0) {
-                // Width or height is still not available.
-                Log.e(TAG, "Unable to retrieve dimension of video:" + path);
-                return null;
-            }
-            if (rotation != null
-                    && (rotation.equals("90") || rotation.equals("270"))) {
-                int b = width;
-                width = height;
-                height = b;
+                retriever.release();
+                if (width == 0 || height == 0) {
+                    // Width or height is still not available.
+                    Log.e(TAG, "Unable to retrieve dimension of video:" + path);
+                    return null;
+                }
+                if (rotation != null
+                        && (rotation.equals("90") || rotation.equals("270"))) {
+                    int b = width;
+                    width = height;
+                    height = b;
+                }
             }
 
             long sizeInBytes = c.getLong(COL_SIZE);