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

Commit 0b4bd7aa authored by Eric Laurent's avatar Eric Laurent
Browse files

Reapply "audio policy: improve sharing input logic to prevent tem..."

This reverts commit 11eb356c.

Bug: 303079083
Test: atest audiopolicy_tests:AudioPolicyManagerInputPreemptionTest
Flag: com.android.media.audioserver.fix_input_sharing_logic
Change-Id: I4061eb1081cf608238ee865b1f399d236b62d3c0
parent cb10d6dc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -3235,7 +3235,8 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(const sp<DeviceDescripto
            //  - Preempt and input if:
            //     - It has only strictly lower priority use cases than the new client
            //     - It has equal priority use cases than the new client, was not
            //     opened thanks to preemption or has been active since opened.
            //     opened thanks to preemption, is not routed to the same device than the device to
            //     consider or has been active since opened.
            //  - Order the preemption candidates by inactive first and priority second
            sp<AudioInputDescriptor> closeCandidate;
            int leastCloseRank = INT_MAX;
@@ -3253,7 +3254,7 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(const sp<DeviceDescripto
                int topPrio = source_priority(topPrioClient->source());
                if (topPrio < source_priority(attributes.source)
                      || (topPrio == source_priority(attributes.source)
                          && !desc->isPreemptor())) {
                          && !(desc->isPreemptor() || desc->getDevice() == device))) {
                    int closeRank = (desc->isActive() ? sCloseActive : 0) + topPrio;
                    if (closeRank < leastCloseRank) {
                        leastCloseRank = closeRank;
+28 −0
Original line number Diff line number Diff line
@@ -4714,6 +4714,34 @@ TEST_F_WITH_FLAGS(
    EXPECT_EQ(input1, input2);
}

TEST_F_WITH_FLAGS(
        AudioPolicyManagerInputPreemptionTest,
        SameDeviceAndSourceReusesInput,
        REQUIRES_FLAGS_ENABLED(
        ACONFIG_FLAG(com::android::media::audioserver, fix_input_sharing_logic))
) {
    mClient->resetInputApiCallsCounters();

    audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
    attr.source = AUDIO_SOURCE_VOICE_RECOGNITION;
    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
    audio_io_handle_t input1 = AUDIO_PORT_HANDLE_NONE;
    ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input1, TEST_SESSION_ID, 1, &selectedDeviceId,
                                            AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO,
                                            k48000SamplingRate));

    EXPECT_EQ(1, mClient->getOpenInputCallsCount());

    audio_io_handle_t input2 = AUDIO_PORT_HANDLE_NONE;
    ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input2, OTHER_SESSION_ID, 1, &selectedDeviceId,
                                            AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO,
                                            k48000SamplingRate));

    EXPECT_EQ(1, mClient->getOpenInputCallsCount());
    EXPECT_EQ(0, mClient->getCloseInputCallsCount());
    EXPECT_EQ(input1, input2);
}

TEST_F_WITH_FLAGS(
        AudioPolicyManagerInputPreemptionTest,
        LesserPriorityReusesInput,