audio: Move StreamContext ownership out from StreamCommonImpl

Upcoming implementations of the streams of the primary module
will need to change the underlying stream type depending on
the current connected device. The stream context must persist,
thus its life time must be bound to the IStreamIn/Out implementation.
Move the StreamContext instance under ownership of StreamIn/Out.

Add StreamCommonImpl::onClose so that the owner of the context
may know when it is safe to reset it.

Re-arrange the order of the arguments when creating a stream
so that the context always comes first.

Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Iaf13d4bc3a53cbfc27264d3abd1f6c417ece3941
diff --git a/audio/aidl/default/ModulePrimary.cpp b/audio/aidl/default/ModulePrimary.cpp
index f66da37..d8ea9e7 100644
--- a/audio/aidl/default/ModulePrimary.cpp
+++ b/audio/aidl/default/ModulePrimary.cpp
@@ -43,18 +43,18 @@
     return ndk::ScopedAStatus::ok();
 }
 
-ndk::ScopedAStatus ModulePrimary::createInputStream(const SinkMetadata& sinkMetadata,
-                                                    StreamContext&& context,
+ndk::ScopedAStatus ModulePrimary::createInputStream(StreamContext&& context,
+                                                    const SinkMetadata& sinkMetadata,
                                                     const std::vector<MicrophoneInfo>& microphones,
                                                     std::shared_ptr<StreamIn>* result) {
-    return createStreamInstance<StreamInStub>(result, sinkMetadata, std::move(context),
+    return createStreamInstance<StreamInStub>(result, std::move(context), sinkMetadata,
                                               microphones);
 }
 
 ndk::ScopedAStatus ModulePrimary::createOutputStream(
-        const SourceMetadata& sourceMetadata, StreamContext&& context,
+        StreamContext&& context, const SourceMetadata& sourceMetadata,
         const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) {
-    return createStreamInstance<StreamOutStub>(result, sourceMetadata, std::move(context),
+    return createStreamInstance<StreamOutStub>(result, std::move(context), sourceMetadata,
                                                offloadInfo);
 }