CSD: forward the native MEL exposure to AudioService

Added new aidl interface for the communication between the
SoundDoseManager and the SoundDoseHelper. Currently only the momentary
exposure warning is reported.

Test: manual
Bug: 257238734
Change-Id: I61560f81fedd31c30c39d676b7adf0ce087b495c
diff --git a/services/audioflinger/sounddose/Android.bp b/services/audioflinger/sounddose/Android.bp
index 5c72fba..6149472 100644
--- a/services/audioflinger/sounddose/Android.bp
+++ b/services/audioflinger/sounddose/Android.bp
@@ -17,6 +17,7 @@
     ],
 
     shared_libs: [
+        "audioflinger-aidl-cpp",
         "libaudioutils",
         "libbase",
         "liblog",
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index 0a69c52..86fb3a4 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -123,6 +123,23 @@
           __func__,
           deviceId,
           currentMel);
+
+    sp<media::ISoundDoseCallback> soundDoseCallback;
+    {
+        std::lock_guard _l(mLock);
+        soundDoseCallback = mSoundDoseCallback;
+    }
+
+    if (soundDoseCallback != nullptr) {
+        mSoundDoseCallback->onMomentaryExposure(currentMel, deviceId);
+    }
+}
+
+void SoundDoseManager::registerSoundDoseCallback(const sp<media::ISoundDoseCallback>& callback) {
+    ALOGV("%s: Register ISoundDoseCallback", __func__);
+
+    std::lock_guard _l(mLock);
+    mSoundDoseCallback = callback;
 }
 
 std::string SoundDoseManager::dump() const
diff --git a/services/audioflinger/sounddose/SoundDoseManager.h b/services/audioflinger/sounddose/SoundDoseManager.h
index 5934d2e..754b569 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.h
+++ b/services/audioflinger/sounddose/SoundDoseManager.h
@@ -17,6 +17,7 @@
 
 #pragma once
 
+#include <android/media/ISoundDoseCallback.h>
 #include <audio_utils/MelProcessor.h>
 #include <audio_utils/MelAggregator.h>
 #include <mutex>
@@ -71,6 +72,9 @@
 
     std::string dump() const;
 
+    /** \brief Registers the interface for passing callbacks to the AudioService. */
+    void registerSoundDoseCallback(const sp<media::ISoundDoseCallback>& callback);
+
     // used for testing
     size_t getCachedMelRecordsSize() const;
 
@@ -91,6 +95,8 @@
                        wp<audio_utils::MelProcessor>> mActiveProcessors GUARDED_BY(mLock);
 
     float mRs2Value GUARDED_BY(mLock);
+
+    sp<media::ISoundDoseCallback> mSoundDoseCallback GUARDED_BY(mLock);
 };
 
 }  // namespace android
diff --git a/services/audioflinger/sounddose/tests/Android.bp b/services/audioflinger/sounddose/tests/Android.bp
index d1779c2..a886663 100644
--- a/services/audioflinger/sounddose/tests/Android.bp
+++ b/services/audioflinger/sounddose/tests/Android.bp
@@ -15,6 +15,7 @@
     ],
 
     shared_libs: [
+        "audioflinger-aidl-cpp",
         "libaudioutils",
         "libbase",
         "liblog",