CSD: add logic for selecting ISoundDose interface
There are two options for supporting sound dose. 1) the hardware
implements the standalone AIDL sound dose interface together with the
legacy audio HIDL HAL or 2) the hardware implements the new sound dose
methods as part of the audio AIDL HAL. The new logic selects the
implementation to use depending on the audio HAL that is active.
Test: bluejay-userdebug logs
Bug: 264254879
Change-Id: I0af9cd31c2e97bb9c9895439f55bbfa50e87e159
diff --git a/services/audioflinger/Android.bp b/services/audioflinger/Android.bp
index 4b6d5f2..43ef311 100644
--- a/services/audioflinger/Android.bp
+++ b/services/audioflinger/Android.bp
@@ -24,7 +24,7 @@
defaults: [
"latest_android_media_audio_common_types_cpp_shared",
- "latest_android_hardware_audio_sounddose_ndk_shared",
+ "latest_android_hardware_audio_core_sounddose_ndk_shared",
],
srcs: [
@@ -111,7 +111,7 @@
export_shared_lib_headers: [
"libpermission",
- "android.hardware.audio.sounddose-V1-ndk",
+ "android.hardware.audio.core.sounddose-V1-ndk",
],
cflags: [
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index f8d7c70..7bb0fd3 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2573,7 +2573,7 @@
ALOGE("loadHwModule() error %d loading module %s", rc, name);
return AUDIO_MODULE_HANDLE_NONE;
}
- if (!mMelReporter->activateHalSoundDoseComputation(name)) {
+ if (!mMelReporter->activateHalSoundDoseComputation(name, dev)) {
ALOGW("loadHwModule() sound dose reporting is not available");
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 100d8c7..e8133d9 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -33,7 +33,6 @@
#include <sys/types.h>
#include <limits.h>
-#include <aidl/android/hardware/audio/sounddose/ISoundDoseFactory.h>
#include <android/media/BnAudioTrack.h>
#include <android/media/IAudioFlingerClient.h>
#include <android/media/IAudioTrackCallback.h>
diff --git a/services/audioflinger/MelReporter.cpp b/services/audioflinger/MelReporter.cpp
index 5ac7cde..bc5b5db 100644
--- a/services/audioflinger/MelReporter.cpp
+++ b/services/audioflinger/MelReporter.cpp
@@ -22,38 +22,37 @@
#include <android/media/ISoundDoseCallback.h>
#include <audio_utils/power.h>
-#include <android/binder_manager.h>
#include <utils/Log.h>
using aidl::android::hardware::audio::core::sounddose::ISoundDose;
-using aidl::android::hardware::audio::sounddose::ISoundDoseFactory;
namespace android {
-constexpr std::string_view kSoundDoseInterfaceModule = "/default";
-
-bool AudioFlinger::MelReporter::activateHalSoundDoseComputation(const std::string& module) {
+bool AudioFlinger::MelReporter::activateHalSoundDoseComputation(const std::string& module,
+ const sp<DeviceHalInterface>& device) {
if (mSoundDoseManager->forceUseFrameworkMel()) {
ALOGD("%s: Forcing use of internal MEL computation.", __func__);
activateInternalSoundDoseComputation();
return false;
}
- if (mSoundDoseFactory == nullptr) {
- ALOGW("%s: sound dose HAL reporting not available", __func__);
- activateInternalSoundDoseComputation();
- return false;
- }
-
- std::shared_ptr<ISoundDose> soundDoseInterface;
- auto result = mSoundDoseFactory->getSoundDose(module, &soundDoseInterface);
- if (!result.isOk()) {
- ALOGW("%s: HAL cannot provide sound dose interface for module %s",
+ ndk::SpAIBinder soundDoseBinder;
+ if (device->getSoundDoseInterface(module, &soundDoseBinder) != OK) {
+ ALOGW("%s: HAL cannot provide sound dose interface for module %s, use internal MEL",
__func__, module.c_str());
activateInternalSoundDoseComputation();
return false;
}
+ if (soundDoseBinder == nullptr) {
+ ALOGW("%s: HAL doesn't implement a sound dose interface for module %s, use internal MEL",
+ __func__, module.c_str());
+ activateInternalSoundDoseComputation();
+ return false;
+ }
+
+ std::shared_ptr<ISoundDose> soundDoseInterface = ISoundDose::fromBinder(soundDoseBinder);
+
if (!mSoundDoseManager->setHalSoundDoseInterface(soundDoseInterface)) {
ALOGW("%s: cannot activate HAL MEL reporting for module %s", __func__, module.c_str());
activateInternalSoundDoseComputation();
@@ -79,16 +78,6 @@
void AudioFlinger::MelReporter::onFirstRef() {
mAudioFlinger.mPatchCommandThread->addListener(this);
-
- std::string interface =
- std::string(ISoundDoseFactory::descriptor) + kSoundDoseInterfaceModule.data();
- AIBinder* binder = AServiceManager_checkService(interface.c_str());
- if (binder == nullptr) {
- ALOGW("%s service %s doesn't exist", __func__, interface.c_str());
- return;
- }
-
- mSoundDoseFactory = ISoundDoseFactory::fromBinder(ndk::SpAIBinder(binder));
}
bool AudioFlinger::MelReporter::shouldComputeMelForDeviceType(audio_devices_t device) {
diff --git a/services/audioflinger/MelReporter.h b/services/audioflinger/MelReporter.h
index acbc8ed..5e7f0cc 100644
--- a/services/audioflinger/MelReporter.h
+++ b/services/audioflinger/MelReporter.h
@@ -45,13 +45,16 @@
* does not support the sound dose interface for this module, the internal MEL
* calculation will be use.
*
- * For now support internal MelReporting only if the sound dose standalone HAL
- * is not implemented
+ * <p>If the device is using the audio AIDL HAL then this method will try to get the sound
+ * dose interface from IModule#getSoundDose(). Otherwise, if the legacy audio HIDL HAL is used
+ * this method will be looking for the standalone sound dose implementation. It falls back to
+ * the internal MEL computation if no valid sound dose interface can be retrieved.
*
- * @return true if the MEL reporting will be done from the sound dose HAL
- * interface
+ * @return true if the MEL reporting will be done from any sound dose HAL interface
+ * implementation, false otherwise.
*/
- bool activateHalSoundDoseComputation(const std::string& module);
+ bool activateHalSoundDoseComputation(const std::string& module,
+ const sp<DeviceHalInterface>& device);
/**
* Activates the MEL reporting from internal framework values. These are used
@@ -78,8 +81,6 @@
audio_port_handle_t deviceId);
AudioFlinger& mAudioFlinger; // does not own the object
- std::shared_ptr<::aidl::android::hardware::audio::sounddose::ISoundDoseFactory>
- mSoundDoseFactory;
sp<SoundDoseManager> mSoundDoseManager;