CSD: fix logic for new patches with CSD HAL path
The mActiveDevices is configured with every new patch and is used to
make the connection between the received csd callbacks and the
registered devices. The logic for new patches in onCreatePatch needs to
be retained even when the HAL path is enabled for CSD.
Test: manual test
Bug: 272260521
Change-Id: Ia27c4ffe6113ea2a56bd412a14cbf6dfc20a622c
diff --git a/services/audioflinger/MelReporter.cpp b/services/audioflinger/MelReporter.cpp
index 496aedc..5a3bcdc 100644
--- a/services/audioflinger/MelReporter.cpp
+++ b/services/audioflinger/MelReporter.cpp
@@ -147,10 +147,6 @@
ALOGV("%s csd is disabled", __func__);
return;
}
- if (useHalSoundDoseInterface()) {
- ALOGV("%s using HAL sound dose, ignore new patch", __func__);
- return;
- }
ALOGV("%s: handle %d mHalHandle %d device sink %08x",
__func__, handle, patch.mHalHandle,
@@ -199,7 +195,7 @@
ALOGI("%s add stream %d that uses device %d for CSD, nr of streams: %d", __func__,
patch.streamHandle, deviceHandle, mActiveDevices[deviceHandle]);
- if (outputThread != nullptr) {
+ if (outputThread != nullptr && !useHalSoundDoseInterface_l()) {
outputThread->startMelComputation_l(mSoundDoseManager->getOrCreateProcessorForDevice(
deviceHandle,
patch.streamHandle,
@@ -271,7 +267,7 @@
}
}
- if (outputThread != nullptr) {
+ if (outputThread != nullptr && !useHalSoundDoseInterface_l()) {
outputThread->stopMelComputation_l();
}
}
@@ -287,13 +283,8 @@
return std::nullopt;
}
-bool AudioFlinger::MelReporter::useHalSoundDoseInterface() {
- bool useHalSoundDoseInterface = !mSoundDoseManager->forceUseFrameworkMel();
- {
- std::lock_guard _l(mLock);
- useHalSoundDoseInterface &= mUseHalSoundDoseInterface;
- }
- return useHalSoundDoseInterface;
+bool AudioFlinger::MelReporter::useHalSoundDoseInterface_l() {
+ return !mSoundDoseManager->forceUseFrameworkMel() & mUseHalSoundDoseInterface;
}
std::string AudioFlinger::MelReporter::dump() {
diff --git a/services/audioflinger/MelReporter.h b/services/audioflinger/MelReporter.h
index 81a307a..2bc33f2 100644
--- a/services/audioflinger/MelReporter.h
+++ b/services/audioflinger/MelReporter.h
@@ -98,7 +98,7 @@
std::optional<audio_patch_handle_t>
activePatchStreamHandle_l(audio_io_handle_t streamHandle) REQUIRES(mLock);
- bool useHalSoundDoseInterface();
+ bool useHalSoundDoseInterface_l() REQUIRES(mLock);
AudioFlinger& mAudioFlinger; // does not own the object
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index 827f7d4..f94ab1e 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -216,7 +216,7 @@
if (id == AUDIO_PORT_HANDLE_NONE) {
ALOGI("%s: no mapped id for audio device with type %d and address %s",
__func__, in_audioDevice.type.type,
- in_audioDevice.address.get<AudioDeviceAddress::id>().c_str());
+ in_audioDevice.address.toString().c_str());
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
soundDoseManager->onMomentaryExposure(in_currentDbA, id);
@@ -243,7 +243,7 @@
if (id == AUDIO_PORT_HANDLE_NONE) {
ALOGI("%s: no mapped id for audio device with type %d and address %s",
__func__, in_audioDevice.type.type,
- in_audioDevice.address.get<AudioDeviceAddress::id>().c_str());
+ in_audioDevice.address.toString().c_str());
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
// TODO: introduce timestamp in onNewMelValues callback