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

Commit ae970028 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: remove glitch when registering dynamic policies

Bypass systematic playback client route evaluation when connecting a
remote submix output device used by a recorder dysnamic policy as no
rerouting is needed in this case.

Bug: 115429872
Bug: 123986127
Test: play music with GPM on Android TV and use the BLE remote
Test: use the BLE remote on Android TV

Change-Id: I285d416f54ff398d23742086fcd8c9f511cd289b
parent 5a523197
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -209,7 +209,26 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t deviceT
            return BAD_VALUE;
        }

        checkForDeviceAndOutputChanges([&]() {
        // No need to evaluate playback routing when connecting a remote submix
        // output device used by a dynamic policy of type recorder as no
        // playback use case is affected.
        bool doCheckForDeviceAndOutputChanges = true;
        if (device->type() == AUDIO_DEVICE_OUT_REMOTE_SUBMIX
                && strncmp(device_address, "0", AUDIO_DEVICE_MAX_ADDRESS_LEN) != 0) {
            for (audio_io_handle_t output : outputs) {
                sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(output);
                if (desc->mPolicyMix != nullptr
                        && desc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS
                        && strncmp(device_address,
                                   desc->mPolicyMix->mDeviceAddress.string(),
                                   AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
                    doCheckForDeviceAndOutputChanges = false;
                    break;
                }
            }
        }

        auto checkCloseOutputs = [&]() {
            // outputs must be closed after checkOutputForAllStrategies() is executed
            if (!outputs.isEmpty()) {
                for (audio_io_handle_t output : outputs) {
@@ -226,7 +245,13 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t deviceT
                return true;
            }
            return false;
        });
        };

        if (doCheckForDeviceAndOutputChanges) {
            checkForDeviceAndOutputChanges(checkCloseOutputs);
        } else {
            checkCloseOutputs();
        }

        if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
            DeviceVector newDevices = getNewOutputDevices(mPrimaryOutput, false /*fromCache*/);