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

Commit e9ee3f48 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by android-build-merger
Browse files

Camera: ensure lock ordering (device->session) am: b0025e1f am: de71f83c

am: 162c8b84

Change-Id: Ia2b36acc9f945c7ab838681f8ea63a6b94579207
parents 9d1809be 162c8b84
Loading
Loading
Loading
Loading
+86 −72
Original line number Diff line number Diff line
@@ -286,7 +286,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
    }

    @Override
    public synchronized void abortCaptures() throws CameraAccessException {
    public void abortCaptures() throws CameraAccessException {
        synchronized (this) {
            checkNotClosed();

            if (DEBUG) {
@@ -300,10 +301,15 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession

            mAborting = true;
            mAbortDrainer.taskStarted();
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            synchronized (this) {
                mDeviceImpl.flush();
                // The next BUSY -> IDLE set of transitions will mark the end of the abort.
            }
        }
    }

    @Override
    public boolean isReprocessable() {
@@ -330,7 +336,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
     * @see CameraCaptureSession#close
     */
    @Override
    public synchronized void replaceSessionClose() {
    public void replaceSessionClose() {
        synchronized (this) {
            /*
             * In order for creating new sessions to be fast, the new session should be created
             * before the old session is closed.
@@ -352,16 +359,16 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            //   configureOutputsChecked(null) has already been called.
            //
            // Do not call configureOutputsChecked(null) going forward, since it would race with the
        // configuration for the new session. If it was already called, then we don't care, since it
        // won't get called again.
            // configuration for the new session. If it was already called, then we don't care,
            // since it won't get called again.
            mSkipUnconfigure = true;

        }
        close();
    }

    @Override
    public synchronized void close() {

    public void close() {
        synchronized (this) {
            if (mClosed) {
                if (DEBUG) Log.v(TAG, mIdString + "close - reentering");
                return;
@@ -370,7 +377,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            if (DEBUG) Log.v(TAG, mIdString + "close - first time");

            mClosed = true;
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            synchronized (this) {
                /*
                 * Flush out any repeating request. Since camera is closed, no new requests
                 * can be queued, and eventually the entire request queue will be drained.
@@ -378,8 +388,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
                 * If the camera device was already closed, short circuit and do nothing; since
                 * no more internal device callbacks will fire anyway.
                 *
         * Otherwise, once stopRepeating is done, wait for camera to idle, then unconfigure the
         * camera. Once that's done, fire #onClosed.
                 * Otherwise, once stopRepeating is done, wait for camera to idle, then unconfigure
                 * the camera. Once that's done, fire #onClosed.
                 */
                try {
                    mDeviceImpl.stopRepeating();
@@ -399,10 +409,14 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession

                    // TODO: call onError instead of onClosed if this happens
                }
            }
        }

        synchronized (this) {
            // If no sequences are pending, fire #onClosed immediately
            mSequenceDrainer.beginDrain();
        }
    }

    /**
     * Whether currently in mid-abort.