camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/compat/workaround/ForceCloseCaptureSession.java
/**
     * For b/144817309, the onClosed() callback on
     * {@link android.hardware.camera2.CameraCaptureSession.StateCallback}
     * might not be invoked if the capture session is not the latest one. To align the fixed
     * framework behavior, we manually call the onClosed() when a new CameraCaptureSession is
     * created.
     */
For b/144817309, the onClosed() callback on
android.hardware.camera2.CameraCaptureSession.StateCallback
might not be invoked if the capture session is not the latest one. To align the fixed
framework behavior, we manually call the onClosed() when a new CameraCaptureSession is
created.
For b / 144817309 the onClosed () callback on android . hardware . camera2 . CameraCaptureSession . StateCallback might not be invoked if the capture session is not the latest one . To align the fixed framework behavior we manually call the onClosed () when a new CameraCaptureSession is created .
public void onSessionConfigured(@NonNull SynchronizedCaptureSession session,
            @NonNull List<SynchronizedCaptureSession> creatingSessions,
            @NonNull List<SynchronizedCaptureSession> sessions,
            @NonNull OnConfigured onConfigured) {
        if (shouldForceClose()) {
            Set<SynchronizedCaptureSession> staleCreatingSessions = new LinkedHashSet<>();
            for (SynchronizedCaptureSession s : creatingSessions) {
                if (s == session) {
                    break;
                }
                staleCreatingSessions.add(s);
            }
            forceOnConfigureFailed(staleCreatingSessions);
        }
        onConfigured.run(session);
        if (shouldForceClose()) {
            Set<SynchronizedCaptureSession> openedSessions = new LinkedHashSet<>();
            for (SynchronizedCaptureSession s : sessions) {
                if (s == session) {
                    break;
                }
                openedSessions.add(s);
            }
            forceOnClosed(openedSessions);
        }
    }
public void onSessionConfigured ( @ NonNull SynchronizedCaptureSession session , @ NonNull List < SynchronizedCaptureSession > creatingSessions , @ NonNull List < SynchronizedCaptureSession > sessions , @ NonNull OnConfigured onConfigured ) { if ( shouldForceClose ( ) ) { Set < SynchronizedCaptureSession > staleCreatingSessions = new LinkedHashSet < > ( ) ; for ( SynchronizedCaptureSession s : creatingSessions ) { if ( s == session ) { break ; } staleCreatingSessions . add ( s ) ; } forceOnConfigureFailed ( staleCreatingSessions ) ; } onConfigured . run ( session ) ; if ( shouldForceClose ( ) ) { Set < SynchronizedCaptureSession > openedSessions = new LinkedHashSet < > ( ) ; for ( SynchronizedCaptureSession s : sessions ) { if ( s == session ) { break ; } openedSessions . add ( s ) ; } forceOnClosed ( openedSessions ) ; } }
For b/144817309, the onClosed() callback on
 {@link android.hardware.camera2.CameraCaptureSession.StateCallback}
 might not be invoked if the capture session is not the latest one.
For b / 144817309 the onClosed () callback on { @link android . hardware . camera2 . CameraCaptureSession . StateCallback } might not be invoked if the capture session is not the latest one .
// Collect the sessions that started configuring before the current session. The // current session and the session that starts configure after the current session // are not included since they don't need to be closed. // Once the CaptureSession is configured, the stale CaptureSessions should not have // chance to complete the configuration flow. Force change to configure fail since // the configureFail will treat the CaptureSession is closed. More detail please see // b/158540776. // Once the new CameraCaptureSession is created, all the previous opened // CameraCaptureSession can be treated as closed (more detail in b/144817309), // trigger its associated StateCallback#onClosed callback to finish the // session close flow. // The entrySet keys of the LinkedHashMap should be insertion-ordered, so we // get the previous capture sessions by iterate it from the beginning.