Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b3f8004 authored by Sol Boucher's avatar Sol Boucher Committed by Solomon Boucher
Browse files

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
parent 5b29e12c
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -446,8 +446,13 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {


            @Override
            @Override
            public void onUnconfigured(CameraDevice camera) {
            public void onUnconfigured(CameraDevice camera) {
                synchronized (session) {
                    // Ignore #onUnconfigured before #close is called
                    if (mClosed) {
                        mUnconfigureDrainer.taskFinished();
                        mUnconfigureDrainer.taskFinished();
                    }
                    }
                }
            }
        };
        };


    }
    }
+7 −7
Original line number Original line Diff line number Diff line
@@ -101,11 +101,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onOpened(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onOpened(CameraDeviceImpl.this);
                    sessionListener.onOpened(CameraDeviceImpl.this);
                }
                }
                mDeviceListener.onOpened(CameraDeviceImpl.this);
            }
            }
        }
        }
    };
    };
@@ -114,11 +114,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onUnconfigured(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onUnconfigured(CameraDeviceImpl.this);
                    sessionListener.onUnconfigured(CameraDeviceImpl.this);
                }
                }
                mDeviceListener.onUnconfigured(CameraDeviceImpl.this);
            }
            }
        }
        }
    };
    };
@@ -127,11 +127,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onActive(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onActive(CameraDeviceImpl.this);
                    sessionListener.onActive(CameraDeviceImpl.this);
                }
                }
                mDeviceListener.onActive(CameraDeviceImpl.this);
            }
            }
        }
        }
    };
    };
@@ -140,11 +140,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onBusy(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onBusy(CameraDeviceImpl.this);
                    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() {
    private final Runnable mCallOnClosed = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
            mDeviceListener.onClosed(CameraDeviceImpl.this);
            StateListener sessionListener = mSessionStateListener;
            StateListener sessionListener = mSessionStateListener;
            if (sessionListener != null) {
            if (sessionListener != null) {
                sessionListener.onClosed(CameraDeviceImpl.this);
                sessionListener.onClosed(CameraDeviceImpl.this);
            }
            }
            mDeviceListener.onClosed(CameraDeviceImpl.this);
        }
        }
    };
    };


@@ -164,11 +164,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onIdle(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onIdle(CameraDeviceImpl.this);
                    sessionListener.onIdle(CameraDeviceImpl.this);
                }
                }
                mDeviceListener.onIdle(CameraDeviceImpl.this);
            }
            }
        }
        }
    };
    };
@@ -177,11 +177,11 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        @Override
        @Override
        public void run() {
        public void run() {
            if (!CameraDeviceImpl.this.isClosed()) {
            if (!CameraDeviceImpl.this.isClosed()) {
                mDeviceListener.onDisconnected(CameraDeviceImpl.this);
                StateListener sessionListener = mSessionStateListener;
                StateListener sessionListener = mSessionStateListener;
                if (sessionListener != null) {
                if (sessionListener != null) {
                    sessionListener.onDisconnected(CameraDeviceImpl.this);
                    sessionListener.onDisconnected(CameraDeviceImpl.this);
                }
                }
                mDeviceListener.onDisconnected(CameraDeviceImpl.this);
            }
            }
        }
        }
    };
    };