Merge changes Icf98465f,Ib9db3274 into androidx-main

* changes:
  Set ThreadConfig from CameraX to CameraPipe
  Close ImageProxy in ImageAnalysis tests
diff --git a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/Camera2CameraControlDeviceTest.kt b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/Camera2CameraControlDeviceTest.kt
index 95ed3c0..2ce4722 100644
--- a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/Camera2CameraControlDeviceTest.kt
+++ b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/Camera2CameraControlDeviceTest.kt
@@ -404,7 +404,9 @@
         }.build().apply {
             // set analyzer to make it active.
             setAnalyzer(Dispatchers.Default.asExecutor()) {
-                // Fake analyzer, do nothing.
+                // Fake analyzer, do nothing. Close the ImageProxy immediately to prevent the
+                // closing of the CameraDevice from being stuck.
+                it.close()
             }
         }
 
@@ -477,7 +479,9 @@
         useCase: UseCase = ImageAnalysis.Builder().build().apply {
             // set analyzer to make it active.
             setAnalyzer(Dispatchers.Default.asExecutor()) {
-                // Fake analyzer, do nothing.
+                // Fake analyzer, do nothing. Close the ImageProxy immediately to prevent the
+                // closing of the CameraDevice from being stuck.
+                it.close()
             }
         }
     ) {
diff --git a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/CameraControlAdapterDeviceTest.kt b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/CameraControlAdapterDeviceTest.kt
index a9e2aeb..10e7fc0 100644
--- a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/CameraControlAdapterDeviceTest.kt
+++ b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/CameraControlAdapterDeviceTest.kt
@@ -111,7 +111,9 @@
     private val imageAnalysis = ImageAnalysis.Builder().build().apply {
         // set analyzer to make it active.
         setAnalyzer(Dispatchers.Default.asExecutor()) {
-            // Fake analyzer, do nothing.
+            // Fake analyzer, do nothing. Close the ImageProxy immediately to prevent the closing
+            // of the CameraDevice from being stuck.
+            it.close()
         }
     }
 
diff --git a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/EvCompDeviceTest.kt b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/EvCompDeviceTest.kt
index b1781dd..fe02a63 100644
--- a/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/EvCompDeviceTest.kt
+++ b/camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/EvCompDeviceTest.kt
@@ -258,7 +258,9 @@
             ImageAnalysis.Builder().build().apply {
                 // set analyzer to make it active.
                 setAnalyzer(Dispatchers.Default.asExecutor()) {
-                    // Fake analyzer, do nothing.
+                    // Fake analyzer, do nothing. Close the ImageProxy immediately to prevent the
+                    // closing of the CameraDevice from being stuck.
+                    it.close()
                 }
             },
         )
diff --git a/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/config/CameraAppConfig.kt b/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/config/CameraAppConfig.kt
index 2f41d39..66e6799 100644
--- a/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/config/CameraAppConfig.kt
+++ b/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/config/CameraAppConfig.kt
@@ -25,6 +25,7 @@
 import androidx.camera.camera2.pipe.integration.impl.CameraInteropStateCallbackRepository
 import androidx.camera.core.impl.CameraFactory
 import androidx.camera.core.impl.CameraThreadConfig
+import androidx.camera.core.impl.utils.executor.CameraXExecutors
 import dagger.Component
 import dagger.Module
 import dagger.Provides
@@ -40,16 +41,26 @@
         @Provides
         fun provideCameraPipe(
             context: Context,
-            cameraInteropStateCallbackRepository: CameraInteropStateCallbackRepository
-        ): CameraPipe = CameraPipe(
-            CameraPipe.Config(
-                appContext = context.applicationContext,
-                cameraInteropConfig = CameraPipe.CameraInteropConfig(
-                    cameraInteropStateCallbackRepository.deviceStateCallback,
-                    cameraInteropStateCallbackRepository.sessionStateCallback
+            cameraThreadConfig: CameraThreadConfig,
+            cameraInteropStateCallbackRepository: CameraInteropStateCallbackRepository,
+        ): CameraPipe {
+            val executor = cameraThreadConfig.cameraExecutor
+            val sequentialExecutor = CameraXExecutors.newSequentialExecutor(executor)
+            return CameraPipe(
+                CameraPipe.Config(
+                    appContext = context.applicationContext,
+                    cameraInteropConfig = CameraPipe.CameraInteropConfig(
+                        cameraInteropStateCallbackRepository.deviceStateCallback,
+                        cameraInteropStateCallbackRepository.sessionStateCallback
+                    ),
+                    threadConfig = CameraPipe.ThreadConfig(
+                        defaultLightweightExecutor = sequentialExecutor,
+                        defaultBackgroundExecutor = executor,
+                        defaultCameraExecutor = sequentialExecutor,
+                    )
                 )
             )
-        )
+        }
 
         @Provides
         fun provideCameraDevices(cameraPipe: CameraPipe): CameraDevices {
diff --git a/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/Camera2InteropIntegrationTest.kt b/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/Camera2InteropIntegrationTest.kt
index 812f339..c4eddbe 100644
--- a/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/Camera2InteropIntegrationTest.kt
+++ b/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/Camera2InteropIntegrationTest.kt
@@ -262,7 +262,9 @@
             setAnalyzer(
                 CameraXExecutors.highPriorityExecutor()
             ) {
-                // Analyzer nothing to to
+                // Fake analyzer, do nothing. Close the ImageProxy immediately to prevent the
+                // closing of the CameraDevice from being stuck.
+                it.close()
             }
         }