camera2: Fix ordering issue between #onOpened and createCaptureSession
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
diff --git a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
index f74fbaa..c3e042e 100644
--- a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
@@ -446,7 +446,12 @@
@Override
public void onUnconfigured(CameraDevice camera) {
- mUnconfigureDrainer.taskFinished();
+ synchronized (session) {
+ // Ignore #onUnconfigured before #close is called
+ if (mClosed) {
+ mUnconfigureDrainer.taskFinished();
+ }
+ }
}
};
diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
index 9795082..d4adae1 100644
--- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
@@ -101,11 +101,11 @@
@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 @@
@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 @@
@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 @@
@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 @@
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 @@
@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 @@
@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);
}
}
};