OSDN Git Service

camera2: Fix ordering issue between #onOpened and createCaptureSession
authorSol Boucher <solb@google.com>
Thu, 5 Jun 2014 20:47:24 +0000 (13:47 -0700)
committerSolomon Boucher <solb@google.com>
Fri, 6 Jun 2014 01:43:00 +0000 (01:43 +0000)
This resolves an issue where the CameraDevice.StateListener callbacks were
erroneously called before the CameraCaptureSession.StateListener ones,
preventing e.g. creating a capture session from the
CameraDevice.StateListener#onOpened() callback.
It also explicitly ignores CameraDevice.StateListener#onUnconfigured() calls
occurring before the first call to #close .

Bug: 15449190
Change-Id: Ic0094d53a65e42108201d7bb50734d17290fa9bf

core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
core/java/android/hardware/camera2/impl/CameraDeviceImpl.java

index f74fbaa..c3e042e 100644 (file)
@@ -446,7 +446,12 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
 
             @Override
             public void onUnconfigured(CameraDevice camera) {
-                mUnconfigureDrainer.taskFinished();
+                synchronized (session) {
+                    // Ignore #onUnconfigured before #close is called
+                    if (mClosed) {
+                        mUnconfigureDrainer.taskFinished();
+                    }
+                }
             }
         };
 
index 9795082..d4adae1 100644 (file)
@@ -101,11 +101,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onOpened(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onOpened(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onOpened(CameraDeviceImpl.this);
             }
         }
     };
@@ -114,11 +114,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onUnconfigured(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onUnconfigured(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onUnconfigured(CameraDeviceImpl.this);
             }
         }
     };
@@ -127,11 +127,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onActive(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onActive(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onActive(CameraDeviceImpl.this);
             }
         }
     };
@@ -140,11 +140,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onBusy(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onBusy(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onBusy(CameraDeviceImpl.this);
             }
         }
     };
@@ -152,11 +152,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
     private final Runnable mCallOnClosed = new Runnable() {
         @Override
         public void run() {
-            mDeviceListener.onClosed(CameraDeviceImpl.this);
             StateListener sessionListener = mSessionStateListener;
             if (sessionListener != null) {
                 sessionListener.onClosed(CameraDeviceImpl.this);
             }
+            mDeviceListener.onClosed(CameraDeviceImpl.this);
         }
     };
 
@@ -164,11 +164,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onIdle(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onIdle(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onIdle(CameraDeviceImpl.this);
             }
         }
     };
@@ -177,11 +177,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
         @Override
         public void run() {
             if (!CameraDeviceImpl.this.isClosed()) {
-                mDeviceListener.onDisconnected(CameraDeviceImpl.this);
                 StateListener sessionListener = mSessionStateListener;
                 if (sessionListener != null) {
                     sessionListener.onDisconnected(CameraDeviceImpl.this);
                 }
+                mDeviceListener.onDisconnected(CameraDeviceImpl.this);
             }
         }
     };