Use local status for convert profile

When converting and filtering the list of audio profile from native to Java, if we reuse the global jStatus for the profiles loop, a wrong value for the last element can propagate as the global return value. Using a local status fixes the issue.

Bug: 246759253
Change-Id: Ifd2bd3cb2b2252c08055c95375fe499e3f23ce02
Test:  atest DirectAudioProfilesForAttributesTest
(cherry picked from commit 4469c2a063)
Merged-In: Ifd2bd3cb2b2252c08055c95375fe499e3f23ce02
This commit is contained in:
Dorin Drimus
2022-09-16 10:07:57 +00:00
committed by Cherrypicker Worker
parent d5d35fb282
commit cefd74bb6e

View File

@@ -2937,13 +2937,14 @@ static jint android_media_AudioSystem_getDirectProfilesForAttributes(JNIEnv *env
for (const auto &audioProfile : audioProfiles) {
jobject jAudioProfile;
jStatus = convertAudioProfileFromNative(env, &jAudioProfile, &audioProfile, false);
if (jStatus == AUDIO_JAVA_BAD_VALUE) {
jint jConvertProfileStatus = convertAudioProfileFromNative(
env, &jAudioProfile, &audioProfile, false);
if (jConvertProfileStatus == AUDIO_JAVA_BAD_VALUE) {
// skipping Java layer unsupported audio formats
continue;
}
if (jStatus != AUDIO_JAVA_SUCCESS) {
return jStatus;
if (jConvertProfileStatus != AUDIO_JAVA_SUCCESS) {
return jConvertProfileStatus;
}
env->CallBooleanMethod(jAudioProfilesList, gArrayListMethods.add, jAudioProfile);
env->DeleteLocalRef(jAudioProfile);