Camera: Stop waiting if device enters ERROR state

If device runs into ERROR state while being disconnected,
waitUntilDrained() should be able to return asap rather than
until timeout.

Otherwise we run into long delay and potential watchdog bite
during shutdown.

Test: Camera CTS, vendor testing
Bug: 282904703
Change-Id: Id8d328c065e00464f1e13fc537a431cbade51408
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index cfe51c7..6a6a390 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -1645,6 +1645,10 @@
     bool stateSeen = false;
     nsecs_t startTime = systemTime();
     do {
+        if (mStatus == STATUS_ERROR) {
+            // Device in error state. Return right away.
+            break;
+        }
         if (active == (mStatus == STATUS_ACTIVE) &&
             (requestThreadInvocation || !mStatusIsInternal)) {
             // Desired state is current
@@ -1674,6 +1678,11 @@
         // they are not paused. This avoids intermediate pause signals from reconfigureCamera as it
         // changes the status to active right after.
         for (size_t i = startIndex; i < mRecentStatusUpdates.size(); i++) {
+            if (mRecentStatusUpdates[i].status == STATUS_ERROR) {
+                // Device in error state. Return right away.
+                stateSeen = true;
+                break;
+            }
             if (active == (mRecentStatusUpdates[i].status == STATUS_ACTIVE) &&
                 (requestThreadInvocation || !mRecentStatusUpdates[i].isInternal)) {
                 stateSeen = true;