libaudiohal@aidl: Fix deadlock when stream goes away

Split the lock for accessing 'DeviceHalAidl::mCallbacks'
from the main lock 'DeviceHalAidl::mLock'. This is needed
to handle the case when the code of 'Hal2AidlMapper'
becomes the sole owner of the stream and ends up destroying
it, triggering a callbacks cleanup call. Since all calls to
'Hal2AidlMapper' are protected by 'mLock', it can not be
used for implementing exclusive access to 'mCallbacks'.
To avoid introducing deadlocks due to use of two mutexes,
the new mutex 'mCallbacksLock' is used only to guard
access to 'mCallbacks', effectively making it a synchronized
map.

Bug: 357487484
Test: atest CoreAudioHalAidlTest
Change-Id: Ic7e5314ad62954f9f8347af2049a5216cab01b7f
diff --git a/media/libaudiohal/impl/DeviceHalAidl.h b/media/libaudiohal/impl/DeviceHalAidl.h
index d925b46..1778881 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.h
+++ b/media/libaudiohal/impl/DeviceHalAidl.h
@@ -242,8 +242,11 @@
     const std::shared_ptr<::aidl::android::hardware::audio::core::IBluetoothLe> mBluetoothLe;
     const std::shared_ptr<::aidl::android::hardware::audio::core::sounddose::ISoundDose> mSoundDose;
 
+    std::mutex mCallbacksLock;
+    // Use 'mCallbacksLock' only to implement exclusive access to 'mCallbacks'. Never hold it
+    // while making any calls.
+    std::map<void*, Callbacks> mCallbacks GUARDED_BY(mCallbacksLock);
     std::mutex mLock;
-    std::map<void*, Callbacks> mCallbacks GUARDED_BY(mLock);
     std::set<audio_port_handle_t> mDeviceDisconnectionNotified GUARDED_BY(mLock);
     Hal2AidlMapper mMapper GUARDED_BY(mLock);
     LockedAccessor<Hal2AidlMapper> mMapperAccessor;