From: Gabriel Nava Date: Thu, 28 May 2015 16:36:23 +0000 (-0700) Subject: Fix for unusable camera after quick pause/resume and HDR+ switch (camera-Haleakala) X-Git-Tag: android-x86-6.0-r3~37^2~9 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e6b00bf3c0319cba17ce23161402568c8e3c3547;p=android-x86%2Fpackages-apps-Camera2.git Fix for unusable camera after quick pause/resume and HDR+ switch (camera-Haleakala) - 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 --- diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 79dfe09d7..a3f728c9d 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -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. diff --git a/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java b/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java index 458cb5a8c..f966bfd53 100644 --- a/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java +++ b/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java @@ -159,7 +159,7 @@ class GenericOneCameraImpl implements OneCamera { public void onFailure(@Nonnull Throwable throwable) { listener.onSetupFailed(); } - }, mMainExecutor); + }); } @Override