OSDN Git Service

Fix for unusable camera after quick pause/resume and HDR+ switch (camera-Haleakala)
authorGabriel Nava <gnava@google.com>
Thu, 28 May 2015 16:36:23 +0000 (09:36 -0700)
committerGabriel Nava <gnava@google.com>
Thu, 28 May 2015 23:17:49 +0000 (16:17 -0700)
- Removing the hack for b/18854352
- Running the camera reopen camera operations and onReadyForCapture callback in a non-UI thread to avoid dead-locks

Bug: 21025113
Change-Id: I5545148769d92e5a87ffa9b693397fd7737edee6

src/com/android/camera/CaptureModule.java
src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java

index 79dfe09..a3f728c 100644 (file)
@@ -24,6 +24,7 @@ import android.graphics.SurfaceTexture;
 import android.location.Location;
 import android.media.MediaActionSound;
 import android.net.Uri;
+import android.os.AsyncTask;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.SystemClock;
@@ -148,8 +149,8 @@ public class CaptureModule extends CameraModule implements
     private OneCamera mCamera;
     /** The selected picture size. */
     private Size mPictureSize;
-    /** Held when opening or closing the camera. */
-    private final Semaphore mCameraOpenCloseLock = new Semaphore(1);
+    /** Fair semaphore held when opening or closing the camera. */
+    private final Semaphore mCameraOpenCloseLock = new Semaphore(1, true);
     /** The direction the currently opened camera is facing to. */
     private Facing mCameraFacing;
     /** Whether HDR Scene mode is currently enabled. */
@@ -644,8 +645,15 @@ public class CaptureModule extends CameraModule implements
         if (mPaused) {
             return;
         }
-        closeCamera();
-        openCameraAndStartPreview();
+        AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
+            @Override
+            public void run() {
+                closeCamera();
+                if(!mAppController.isPaused()) {
+                    openCameraAndStartPreview();
+                }
+            }
+        });
     }
 
     private SurfaceTexture getPreviewSurfaceTexture() {
@@ -694,13 +702,6 @@ public class CaptureModule extends CameraModule implements
         mHdrSceneEnabled = !mStickyGcamCamera && mAppController.getSettingsManager().getBoolean(
               SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR);
 
-        // The lock only exists for HDR and causes trouble for non-HDR
-        // OneCameras.
-        // TODO: Fix for removing the locks completely is tracked at b/17985028
-        if (!mHdrPlusEnabled) {
-            mCameraOpenCloseLock.release();
-        }
-
         // This means we are resuming with an existing preview texture. This
         // means we will never get the onSurfaceTextureAvailable call. So we
         // have to open the camera and start the preview here.
index 458cb5a..f966bfd 100644 (file)
@@ -159,7 +159,7 @@ class GenericOneCameraImpl implements OneCamera {
             public void onFailure(@Nonnull Throwable throwable) {
                 listener.onSetupFailed();
             }
-        }, mMainExecutor);
+        });
     }
 
     @Override