From dab2157081beedd8b545040080f181d48f556130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaffie?= Date: Fri, 25 Mar 2022 16:19:25 +0100 Subject: [PATCH] [BUG] audio: Misalignement of Native/Java AudioAttributes Native audio attributes are initialized with a default source, whereas JAVA AudioAttributes are initialized with an INVALID source. It leads to equality failure, thus preventing to identify the right strategy / volume group. This CL fixes this misalignement by using the builder constructor from AudioAttributes, thus cleaning the input source. Test: AudioVolumeGroupTest Bug: 238058094 Bug: 248287204 Merged-In: I0aa6f19bb0f448e853adcc0dacece4d69c665602 Change-Id: I0aa6f19bb0f448e853adcc0dacece4d69c665602 (cherry picked from commit 47e3b6bf552e7d82c58999ad0a68f2d82219646e) --- core/jni/android_media_AudioProductStrategies.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/jni/android_media_AudioProductStrategies.cpp b/core/jni/android_media_AudioProductStrategies.cpp index 34be2a52344d..4b563d7f3bd8 100644 --- a/core/jni/android_media_AudioProductStrategies.cpp +++ b/core/jni/android_media_AudioProductStrategies.cpp @@ -86,8 +86,8 @@ static jint convertAudioProductStrategiesFromNative( // Audio Attributes Group array int attrGroupIndex = 0; - std::map > groups; - for (const auto &attr : strategy.getAudioAttributes()) { + std::map > groups; + for (const auto &attr : strategy.getVolumeGroupAttributes()) { int groupId = attr.getGroupId(); int streamType = attr.getStreamType(); const auto &iter = std::find_if(begin(groups), end(groups), @@ -108,17 +108,17 @@ static jint convertAudioProductStrategiesFromNative( jAudioAttributesGroups = env->NewObjectArray(numAttributesGroups, gAudioAttributesGroupClass, NULL); for (const auto &iter : groups) { - std::vector audioAttributesGroups = iter.second; - jint numAttributes = audioAttributesGroups.size(); - jint jGroupId = audioAttributesGroups.front().getGroupId(); - jint jLegacyStreamType = audioAttributesGroups.front().getStreamType(); + std::vector volumeGroupAttributes = iter.second; + jint numAttributes = volumeGroupAttributes.size(); + jint jGroupId = volumeGroupAttributes.front().getGroupId(); + jint jLegacyStreamType = volumeGroupAttributes.front().getStreamType(); jStatus = JNIAudioAttributeHelper::getJavaArray(env, &jAudioAttributes, numAttributes); if (jStatus != (jint)AUDIO_JAVA_SUCCESS) { goto exit; } for (size_t j = 0; j < static_cast(numAttributes); j++) { - auto attributes = audioAttributesGroups[j].getAttributes(); + auto attributes = volumeGroupAttributes[j].getAttributes(); jStatus = JNIAudioAttributeHelper::nativeToJava(env, &jAudioAttribute, attributes); if (jStatus != AUDIO_JAVA_SUCCESS) {