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

Commit e2594d98 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "APM: Coalesce calls to check and update outputs"

parents 5b7d2948 37977159
Loading
Loading
Loading
Loading
+33 −24
Original line number Diff line number Diff line
@@ -202,10 +202,7 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device,
            return BAD_VALUE;
        }

        // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP
        // output is suspended before any tracks are moved to it
        checkA2dpSuspend();
        checkOutputForAllStrategies();
        checkForDeviceAndOutputChanges([&]() {
            // outputs must be closed after checkOutputForAllStrategies() is executed
            if (!outputs.isEmpty()) {
                for (audio_io_handle_t output : outputs) {
@@ -218,11 +215,12 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device,
                        closeOutput(output);
                    }
                }
            // check again after closing A2DP output to reset mA2dpSuspended if needed
            checkA2dpSuspend();
                // check A2DP again after closing A2DP output to reset mA2dpSuspended if needed
                return true;
            }
            return false;
        });

        updateDevicesAndOutputs();
        if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
            audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
            updateCallRouting(newDevice);
@@ -565,9 +563,7 @@ void AudioPolicyManager::setPhoneState(audio_mode_t state)
                  || (is_state_in_call(state) && (state != oldState)));

    // check for device and output changes triggered by new phone state
    checkA2dpSuspend();
    checkOutputForAllStrategies();
    updateDevicesAndOutputs();
    checkForDeviceAndOutputChanges();

    int delayMs = 0;
    if (isStateInCall(state)) {
@@ -667,9 +663,7 @@ void AudioPolicyManager::setForceUse(audio_policy_force_use_t usage,
            (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM);

    // check for device and output changes triggered by new force usage
    checkA2dpSuspend();
    checkOutputForAllStrategies();
    updateDevicesAndOutputs();
    checkForDeviceAndOutputChanges();

    //FIXME: workaround for truncated touch sounds
    // to be removed when the problem is handled by system UI
@@ -4647,6 +4641,21 @@ bool AudioPolicyManager::vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
    return true;
}

void AudioPolicyManager::checkForDeviceAndOutputChanges()
{
    checkForDeviceAndOutputChanges([](){ return false; });
}

void AudioPolicyManager::checkForDeviceAndOutputChanges(std::function<bool()> onOutputsChecked)
{
    // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP
    // output is suspended before any tracks are moved to it
    checkA2dpSuspend();
    checkOutputForAllStrategies();
    if (onOutputsChecked()) checkA2dpSuspend();
    updateDevicesAndOutputs();
}

void AudioPolicyManager::checkOutputForStrategy(routing_strategy strategy)
{
    audio_devices_t oldDevice = getDeviceForStrategy(strategy, true /*fromCache*/);
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <atomic>
#include <functional>
#include <memory>
#include <unordered_set>

@@ -410,6 +411,13 @@ protected:
        // close an input.
        void closeInput(audio_io_handle_t input);

        // runs all the checks required for accomodating changes in devices and outputs
        // if 'onOutputsChecked' callback is provided, it is executed after the outputs
        // check via 'checkOutputForAllStrategies'. If the callback returns 'true',
        // A2DP suspend status is rechecked.
        void checkForDeviceAndOutputChanges();
        void checkForDeviceAndOutputChanges(std::function<bool()> onOutputsChecked);

        // checks and if necessary changes outputs used for all strategies.
        // must be called every time a condition that affects the output choice for a given strategy
        // changes: connected device, phone state, force use...