[go: nahoru, domu]

Handle abort() calls in GraphProcessorImpl.submitLoop()

GraphProcessorImpl cycles through `submitQueue` to submit requests. When
a request is submitted, GraphProcessorImpl would remove the front
request from `submitQueue`. However, `submitQueue` can actually be
cleared by CameraGraph.Session.abort() in the meantime, so `submitQueue`
can be empty() while we're trying to remove the request.

This CL adds a check so that we don't try to remove the request if
`submitQueue` has already been cleared.

Bug: 247166179
Test: ./gradlew --info :camera:integration-tests:camera-testapp-core:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=androidx.camera.integration.core.ImageCaptureTest
Change-Id: I21da2884c298383318930dab2cf0320b2801a041
diff --git a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/graph/GraphProcessor.kt b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/graph/GraphProcessor.kt
index bc6e84f..8cc6fcb 100644
--- a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/graph/GraphProcessor.kt
+++ b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/graph/GraphProcessor.kt
@@ -436,7 +436,8 @@
                 Debug.traceStop()
                 synchronized(lock) {
                     if (submitted) {
-                        check(submitQueue.removeAt(0) === burst)
+                        // submitQueue can potentially be cleared by abort() before entering here.
+                        check(submitQueue.isEmpty() || submitQueue.removeAt(0) === burst)
 
                         val nullableBurst = submitQueue.firstOrNull()
                         if (nullableBurst == null) {