Improve robustness when deleting abs volume device
Flag: com.android.media.audio.abs_volume_index_fix
Test: manual
Bug: 350103953
Change-Id: I9673b05aac488bd43803e5c88059ef71eaefb1ea
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index e5fe2d2..e456e89 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -3508,6 +3508,11 @@
bool enabled,
audio_stream_type_t streamToDriveAbs)
{
+ if (!enabled) {
+ mAbsoluteVolumeDrivingStreams.erase(deviceType);
+ return NO_ERROR;
+ }
+
audio_attributes_t attributesToDriveAbs = mEngine->getAttributesForStreamType(streamToDriveAbs);
if (attributesToDriveAbs == AUDIO_ATTRIBUTES_INITIALIZER) {
ALOGW("%s: no attributes for stream %s, bailing out", __func__,
@@ -3515,12 +3520,7 @@
return BAD_VALUE;
}
- if (enabled) {
- mAbsoluteVolumeDrivingStreams[deviceType] = attributesToDriveAbs;
- } else {
- mAbsoluteVolumeDrivingStreams.erase(deviceType);
- }
-
+ mAbsoluteVolumeDrivingStreams[deviceType] = attributesToDriveAbs;
return NO_ERROR;
}