summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Wang <jaywang@codeaurora.org>2016-07-07 10:59:24 -0700
committerSteve Kondik <steve@cyngn.com>2016-08-25 21:55:20 -0700
commit7ea546719246f15d23b7271514e7c95017a96b2b (patch)
tree05a4271981f227c452825c13df5b5818b934be56
parentda621f4cfb1d6c10136d26950baae6ac56bab049 (diff)
downloadandroid_packages_apps_Snap-7ea546719246f15d23b7271514e7c95017a96b2b.zip
android_packages_apps_Snap-7ea546719246f15d23b7271514e7c95017a96b2b.tar.gz
android_packages_apps_Snap-7ea546719246f15d23b7271514e7c95017a96b2b.tar.bz2
SnapdragonCamera: Fix race condition when opening cameras
Fix race condition between surface ready and camera opened that was causing createSession to be called twice for same device. CRs-Fixed: 1019361 Change-Id: Ieb62b394f1cf83cc83e2b9e290ce6758e2ade377
-rw-r--r--src/com/android/camera/CaptureModule.java62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 014b059..052aea1 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -181,7 +181,7 @@ public class CaptureModule implements CameraModule, PhotoController,
// The degrees of the device rotated clockwise from its natural orientation.
private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
private boolean mFirstTimeInitialized;
- private boolean mInitialized = false;
+ private boolean mCamerasOpened = false;
private boolean mIsLinked = false;
private long mCaptureStartTime;
private boolean mPaused = true;
@@ -443,23 +443,23 @@ public class CaptureModule implements CameraModule, PhotoController,
if (mPaused) {
return;
}
+
+ mCameraDevice[id] = cameraDevice;
+ mCameraOpened[id] = true;
+
if (isBackCamera() && getCameraMode() == DUAL_MODE && id == BAYER_ID) {
Message msg = mCameraHandler.obtainMessage(OPEN_CAMERA, MONO_ID);
mCameraHandler.sendMessage(msg);
- }
- if (!mInitialized) {
- mInitialized = true;
+ } else {
+ mCamerasOpened = true;
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mUI.onCameraOpened(mCameraIdList);
}
});
+ createSessions();
}
-
- mCameraDevice[id] = cameraDevice;
- mCameraOpened[id] = true;
- createSession(id);
}
@Override
@@ -467,8 +467,9 @@ public class CaptureModule implements CameraModule, PhotoController,
int id = Integer.parseInt(cameraDevice.getId());
Log.d(TAG, "onDisconnected " + id);
cameraDevice.close();
- mCameraDevice = null;
+ mCameraDevice[id] = null;
mCameraOpenCloseLock.release();
+ mCamerasOpened = false;
}
@Override
@@ -478,6 +479,7 @@ public class CaptureModule implements CameraModule, PhotoController,
cameraDevice.close();
mCameraDevice[id] = null;
mCameraOpenCloseLock.release();
+ mCamerasOpened = false;
if (null != mActivity) {
mActivity.finish();
}
@@ -489,6 +491,7 @@ public class CaptureModule implements CameraModule, PhotoController,
Log.d(TAG, "onClosed " + id);
mCameraDevice[id] = null;
mCameraOpenCloseLock.release();
+ mCamerasOpened = false;
}
};
@@ -663,6 +666,26 @@ public class CaptureModule implements CameraModule, PhotoController,
}
}
+ private void createSessions() {
+ if (mPaused || !mCamerasOpened || !mSurfaceReady) return;
+ if (isBackCamera()) {
+ switch (getCameraMode()) {
+ case DUAL_MODE:
+ createSession(BAYER_ID);
+ createSession(MONO_ID);
+ break;
+ case BAYER_MODE:
+ createSession(BAYER_ID);
+ break;
+ case MONO_MODE:
+ createSession(MONO_ID);
+ break;
+ }
+ } else {
+ createSession(FRONT_ID);
+ }
+ }
+
private void createSession(final int id) {
if (mPaused || !mCameraOpened[id] || !mSurfaceReady) return;
Log.d(TAG, "createSession " + id);
@@ -1328,7 +1351,7 @@ public class CaptureModule implements CameraModule, PhotoController,
for (int i = 0; i < MAX_NUM_CAM; i++) {
if (null != mCaptureSession[i]) {
- if (mIsLinked) {
+ if (mIsLinked && mCamerasOpened) {
unLinkBayerMono(i);
try {
mCaptureSession[i].capture(mPreviewRequestBuilder[i].build(), null,
@@ -1760,7 +1783,7 @@ public class CaptureModule implements CameraModule, PhotoController,
@Override
public void onSingleTapUp(View view, int x, int y) {
- if (mPaused || mCameraDevice == null || !mFirstTimeInitialized || !mAutoFocusRegionSupported
+ if (mPaused || !mCamerasOpened || !mFirstTimeInitialized || !mAutoFocusRegionSupported
|| !mAutoExposureRegionSupported || !isTouchToFocusAllowed()) {
return;
}
@@ -1879,22 +1902,7 @@ public class CaptureModule implements CameraModule, PhotoController,
}
Log.d(TAG, "onPreviewUIReady");
mSurfaceReady = true;
- if (isBackCamera()) {
- switch (getCameraMode()) {
- case DUAL_MODE:
- createSession(BAYER_ID);
- createSession(MONO_ID);
- break;
- case BAYER_MODE:
- createSession(BAYER_ID);
- break;
- case MONO_MODE:
- createSession(MONO_ID);
- break;
- }
- } else {
- createSession(FRONT_ID);
- }
+ createSessions();
}
@Override