diff options
authorEmilian Peev <>2015-06-02 14:50:30 +0300
committerArne Coucheron <>2018-01-27 00:41:42 +0100
commit2351f5b56a3571b0bb9f75dc4b355a86ceef5709 (patch)
parentcc4130a5923c70ba11c00146ec18c8766cb4e18e (diff)
Snapdragon Camera: Avoid possible race condition
Camera open and preview start are currently executed in a separate thread different from the main handler thread. If the main thread tries to switch the camera immediately after the open camera thread starts a race condition is possible. This race condition can lead to a failing assert in CameraHolder which can receive two camera open requests one after another. To resolve this the main handler thread needs to check whether an open camera thread got initialized and started previously. If the check is positive, it needs to wait until the separate thread finishes before proceeding with the camera switch sequence. Change-Id: I409e3158bc976120de31540351ea8e55fddbca46
1 files changed, 9 insertions, 0 deletions
diff --git a/src/com/android/camera/ b/src/com/android/camera/
index f48dca8..9056d87 100644
--- a/src/com/android/camera/
+++ b/src/com/android/camera/
@@ -762,6 +762,15 @@ public class PhotoModule
mSnapshotOnIdle = false;
+ try {
+ if (mOpenCameraThread != null) {
+ mOpenCameraThread.join();
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ mOpenCameraThread = null;
// from onPause
try {
if (mOpenCameraThread != null) {