Solve the issue that the injection camera cannot be injected when the stream configuration is completed and the camera device is active

It runs normally in “First call injectCamera() and then run
configureStreamsLocked()" case, but there are the following issues in
"First run configureStreamsLocked() and then call injectCamera()"
case:

- The streaming configuration of the internal camera is not stored
correctly.
  Solution: Added storeInjectionConfig() to store internal configure
when the stream configuration is completed and injectCamera() has not
been called.

- After internalPauseAndWaitLocked(), readOneCameraMetadataLocked()
will have the problem of "Cannot read camera metadata from fmq",
resulting in removeInFlightRequestIfReadyLocked() unable to completely
clear mInFlightMap. The root cause is to directly override
mResultMetadataQueue in injectionInitialize(), but the above issue
will occur when the camera device is active.
  Solution: Generate mInjectionResultMetadataQueue during
injectionInitialize(). When injecting camera, save the original
mResultMetadataQueue into mBackupResultMetadataQueue, and replace the
original mResultMetadataQueue with mInjectionResultMetadataQueue.

- When the camera device is active, injectCamera() and stopInjection()
will call internalPauseAndWaitLocked() and internalResumeLocked(), and
then they will call mStatusChanged.waitRelative(mLock, timeout) of
waitUntilStateThenRelock(). But mStatusChanged.waitRelative(mLock,
timeout)'s parameter: mutex "mLock" must be in the locked state
(https://source.corp.google.com/android/system/core/libutils/include/utils/Condition.h;l=67)
, so we need to add "Mutex::Autolock l(mLock)" here to lock the
"mLock" before calling internalPauseAndWaitLocked() or
internalResumeLocked(). If we don't do this, it may cause the mutex
"mLock" state to be out of order. After that, all functions that use
the mutex "mLock" will be in a waiting state, such as
clearStreamingRequest() called when the camera is closed.
  Solution: Added "Mutex::Autolock l(mLock)" in injectCamera() and
stopInjection().

- Unable to run stopInjection() function from app.
  Solution: First obtain the client descriptor from ActiveClientManager,
and then call clearInjectionParameters(), otherwise
mInjectionInternalCamId iscleared and the corresponding client
descriptor cannot be obtained.

Bug: 189289800
Test: Manual

Change-Id: If5ca8d7a8431d58d97214d5e6faa7a0e5013f862
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 53a696f..e67777d 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -1361,25 +1361,34 @@
         // when device is IDLE and request thread is paused.
         status_t injectCamera(
                 camera3::camera_stream_configuration& injectionConfig,
-                std::vector<uint32_t>& injectionBufferSizes);
+                const std::vector<uint32_t>& injectionBufferSizes);
 
         // Stop the injection camera and switch back to backup hal interface.
         status_t stopInjection();
 
         bool isInjecting();
 
+        bool isStreamConfigCompleteButNotInjected();
+
         const String8& getInjectedCamId() const;
 
         void getInjectionConfig(/*out*/ camera3::camera_stream_configuration* injectionConfig,
                 /*out*/ std::vector<uint32_t>* injectionBufferSizes);
 
+        // When the streaming configuration is completed and the camera device is active, but the
+        // injection camera has not yet been injected, the streaming configuration of the internal
+        // camera will be stored first.
+        void storeInjectionConfig(
+                const camera3::camera_stream_configuration& injectionConfig,
+                const std::vector<uint32_t>& injectionBufferSizes);
+
       private:
         // Configure the streams of injection camera, it need wait until the
         // output streams are created and configured to the original camera before
         // proceeding.
         status_t injectionConfigureStreams(
                 camera3::camera_stream_configuration& injectionConfig,
-                std::vector<uint32_t>& injectionBufferSizes);
+                const std::vector<uint32_t>& injectionBufferSizes);
 
         // Disconnect the injection camera and delete the hal interface.
         void injectionDisconnectImpl();
@@ -1397,6 +1406,17 @@
         // Generated injection camera hal interface.
         sp<HalInterface> mInjectedCamHalInterface;
 
+        // Backup of the original camera hal result FMQ.
+        std::unique_ptr<ResultMetadataQueue> mBackupResultMetadataQueue;
+
+        // FMQ writes the result for the injection camera. Must be guarded by
+        // mProcessCaptureResultLock.
+        std::unique_ptr<ResultMetadataQueue> mInjectionResultMetadataQueue;
+
+        // The flag indicates that the stream configuration is complete, the camera device is
+        // active, but the injection camera has not yet been injected.
+        bool mIsStreamConfigCompleteButNotInjected = false;
+
         // Copy the configuration of the internal camera.
         camera3::camera_stream_configuration mInjectionConfig;