audio: Add IStreamCommon.prepareToClose method

This method is needed to implement HAL modules that
are proxies for other subsystems, for example
the "bluetooth" and "r_submix" modules. This method
replaces string parameters "exiting=1" and "closing=true"
which the framework sends to streams prior to closing
them in order to unblock the I/O thread of the stream.

Bug: 270731693
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I3d13fe34535ab853c9f8237a08c31cdafadbb390
Merged-In: I3d13fe34535ab853c9f8237a08c31cdafadbb390
diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp
index 193c793..871480b 100644
--- a/audio/aidl/default/Stream.cpp
+++ b/audio/aidl/default/Stream.cpp
@@ -660,6 +660,16 @@
 }
 
 template <class Metadata>
+ndk::ScopedAStatus StreamCommonImpl<Metadata>::prepareToClose() {
+    LOG(DEBUG) << __func__;
+    if (!isClosed()) {
+        return ndk::ScopedAStatus::ok();
+    }
+    LOG(ERROR) << __func__ << ": stream was closed";
+    return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
+}
+
+template <class Metadata>
 void StreamCommonImpl<Metadata>::stopWorker() {
     if (auto commandMQ = mContext.getCommandMQ(); commandMQ != nullptr) {
         LOG(DEBUG) << __func__ << ": asking the worker to exit...";