Raise CameraDevice.close() timeout and log the error instead

Previously Camera2DeviceCloser should've thrown
TimeoutCancellationException from withTimeout. However, it became clear
that wasn't the case, and aosp/3288148 was created to mitigate the
error.

Based on production crash date, it seems that even with a 5s timeout, it
is still not an uncommon occurrence that camera device closure times
out. Given the camera framework also has a 5s timeout for camera device
closure, or more specifically for camera device dropping inflight
requests, raise the timeout to 8s.

Now given the timeout at 8s, if it still times out, log the error that
clearly gives an indication that the cameras may not work normally
again.

Bug: 374115214
Test: CameraPipe test app
Change-Id: If563285fb1ba9374d33afaae39684face988bfde
diff --git a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/Camera2DeviceCloser.kt b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/Camera2DeviceCloser.kt
index a6081aa..2da4d5f 100644
--- a/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/Camera2DeviceCloser.kt
+++ b/camera/camera-camera2-pipe/src/main/java/androidx/camera/camera2/pipe/compat/Camera2DeviceCloser.kt
@@ -96,9 +96,15 @@
                 Log.debug { "Empty capture session quirk completed" }
             }
         }
-        Threading.runBlockingChecked(threads.backgroundDispatcher, 5000L) {
+        Threading.runBlockingCheckedOrNull(threads.backgroundDispatcher, CAMERA_CLOSE_TIMEOUT_MS) {
             cameraDevice.closeWithTrace()
         }
+            ?: run {
+                Log.error {
+                    "Camera device close timed out after ${CAMERA_CLOSE_TIMEOUT_MS}ms. " +
+                        "The camera is likely in a bad state."
+                }
+            }
         if (camera2Quirks.shouldWaitForCameraDeviceOnClosed(cameraId)) {
             Log.debug { "Waiting for OnClosed from $cameraId" }
             if (androidCameraState.awaitCameraDeviceClosed(timeoutMillis = 5000)) {
@@ -158,4 +164,8 @@
         }
         sessionConfigured.await()
     }
+
+    companion object {
+        const val CAMERA_CLOSE_TIMEOUT_MS = 8_000L // 8s
+    }
 }