Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a5b2e3f authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Respect config_mask in AudioPortConfig conversion

The code that converts AudioPortConfig from native to Java previously
ignored config_mask and as result risks reading bogus values from the
respective fields.
This fixes it.

Test: Audio tests from CtsMediaTests
Change-Id: I6664ea10b47ddd0f2f7843f7051c03dfe72d8383
parent ac348bde
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -1023,7 +1023,9 @@ static jint convertAudioPortConfigFromNative(JNIEnv *env,
    audio_channel_mask_t nMask;
    jint jMask;

    int gainIndex = nAudioPortConfig->gain.index;
    int gainIndex = (nAudioPortConfig->config_mask & AUDIO_PORT_CONFIG_GAIN)
            ? nAudioPortConfig->gain.index
            : -1;
    if (gainIndex >= 0) {
        ALOGV("convertAudioPortConfigFromNative gain found with index %d mode %x",
              gainIndex, nAudioPortConfig->gain.mode);
@@ -1120,7 +1122,9 @@ static jint convertAudioPortConfigFromNative(JNIEnv *env,
            goto exit;
        }
    }
    nMask = nAudioPortConfig->channel_mask;
    nMask = (nAudioPortConfig->config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK)
            ? nAudioPortConfig->channel_mask
            : AUDIO_CONFIG_BASE_INITIALIZER.channel_mask;
    if (useInMask) {
        jMask = inChannelMaskFromNative(nMask);
        ALOGV("convertAudioPortConfigFromNative IN mask java %x native %x", jMask, nMask);
@@ -1129,11 +1133,16 @@ static jint convertAudioPortConfigFromNative(JNIEnv *env,
        ALOGV("convertAudioPortConfigFromNative OUT mask java %x native %x", jMask, nMask);
    }

    *jAudioPortConfig = env->NewObject(clazz, methodID,
                                       jAudioPort,
                                       nAudioPortConfig->sample_rate,
    *jAudioPortConfig =
            env->NewObject(clazz, methodID, jAudioPort,
                           (nAudioPortConfig->config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE)
                                   ? nAudioPortConfig->sample_rate
                                   : AUDIO_CONFIG_BASE_INITIALIZER.sample_rate,
                           jMask,
                                       audioFormatFromNative(nAudioPortConfig->format),
                           audioFormatFromNative(
                                   (nAudioPortConfig->config_mask & AUDIO_PORT_CONFIG_FORMAT)
                                           ? nAudioPortConfig->format
                                           : AUDIO_CONFIG_BASE_INITIALIZER.format),
                           jAudioGainConfig);
    if (*jAudioPortConfig == NULL) {
        ALOGV("convertAudioPortConfigFromNative could not create new port config");