From 176dc1fc039faf3c5ef71bb69539ac50112f120e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaffie?= Date: Mon, 23 Mar 2020 18:00:01 -0700 Subject: [PATCH] [AudioServer][Strategies] Fix Min/Max index overwritting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a strategy holds 2 stream types, following the same volume group (aka same volume curves), when audioservice initializes, it may overwritte the Min/max for the volume group. This is due to the fact that the second stream type is not recognized and falls back on default volume group (aka Music). So, Min/max are overwritten with music Min/max. This CL fixes the bug by formatting correctly the AudioAttributesGroups of a product strategy by checking not only the volume group id but also the stream type. Bug: 136121584 Test: build & run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioProductStrategyTest run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioVolumeGroupTest run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioVolumeGroupChangeHandlerTest run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testPermissionsForVolumePerAttributes run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testGetAndValidateProductStrategies run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testGetAndValidateVolumeGroups run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testSetGetVolumePerAttributesWithInvalidAttributes run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testSetGetVolumePerAttributes run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testVolumeGroupCallback Change-Id: I3aab572ef4daeecce13bbcef6278edcc42b7d594 Signed-off-by: François Gaffie --- .../android_media_AudioProductStrategies.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/jni/android_media_AudioProductStrategies.cpp b/core/jni/android_media_AudioProductStrategies.cpp index 17a02b24c6979..34be2a52344d1 100644 --- a/core/jni/android_media_AudioProductStrategies.cpp +++ b/core/jni/android_media_AudioProductStrategies.cpp @@ -85,10 +85,23 @@ static jint convertAudioProductStrategiesFromNative( jStrategyId = static_cast(strategy.getId()); // Audio Attributes Group array - std::map > groups; + int attrGroupIndex = 0; + std::map > groups; for (const auto &attr : strategy.getAudioAttributes()) { - int attrGroupId = attr.getGroupId(); - groups[attrGroupId].push_back(attr); + int groupId = attr.getGroupId(); + int streamType = attr.getStreamType(); + const auto &iter = std::find_if(begin(groups), end(groups), + [groupId, streamType](const auto &iter) { + const auto &frontAttr = iter.second.front(); + return frontAttr.getGroupId() == groupId && frontAttr.getStreamType() == streamType; + }); + // Same Volume Group Id and same stream type + if (iter != end(groups)) { + groups[iter->first].push_back(attr); + } else { + // Add a new Group of AudioAttributes for this product strategy + groups[attrGroupIndex++].push_back(attr); + } } numAttributesGroups = groups.size(); @@ -97,7 +110,7 @@ static jint convertAudioProductStrategiesFromNative( for (const auto &iter : groups) { std::vector audioAttributesGroups = iter.second; jint numAttributes = audioAttributesGroups.size(); - jint jGroupId = iter.first; + jint jGroupId = audioAttributesGroups.front().getGroupId(); jint jLegacyStreamType = audioAttributesGroups.front().getStreamType(); jStatus = JNIAudioAttributeHelper::getJavaArray(env, &jAudioAttributes, numAttributes);