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

Commit c66b9ca8 authored by Sharad Sangle's avatar Sharad Sangle Committed by Gerrit - the friendly Code Review server
Browse files

policy-hal: make sure policy-hal is in sync with AOSP

 This change makes sure that changes in the base function
 are moved to custom policy if the function is derived in
 custom policy.

 Below changes are taken care

1) audio policy: fix capture indication to sound trigger service.

   Only indicate active capture to sound trigger service
   when capturing from primay HW module.

   Bug: 31826453
   Bug: 31771879
   Change-Id: Idf92393d3e7dbf926b847ab23f670e7ab5dd5248

2) audio policy: fix media volume after ringtone

   Fix regression introduced by commit 11c499a5 causing
   music volume not to be restored after ringtone playback
   over duplicated output (speaker + A2DP).

   Bug: 31539910
   Change-Id: I1c4eebea1f1a8f82ae2acfeecb9a61c437a74e25

3) audio policy: fix call volume over USB

   Make sure the cache of output device selection per strategy is updated
   also when an input device is connected or disconnected as the list of
   input devices sometimes impacts the output device selection in
   getDeviceForStrategy().

   Bug: 30659619
   Change-Id: Ie9f7bafda0074afcc803f309379c35b538f50170

4) audio policy: workaround for truncated touch sounds

   Implement workaround to avoid touch sound truncation when
   audio path or volume changes are triggered by user actions.

   Also:
      - Fix regression introduced by commit c75307b7 causing failure
      to honor playback start delay in case of path change.
      - Fix failure to report path switch delay in updateCallRouting().
      - Make sure we delay temporary mute according to requested device
      switch delay in checkDeviceMuteStrategies().

   Bug: 29528161
   Bug: 27535199
   Change-Id: Id729579b6623ee67a767055b9aca7d2e2dde8491

Change-Id: I2f0b0e51ec725a462e913432f648cb7b3cf125fe
parent 40f779be
Loading
Loading
Loading
Loading
+39 −8
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
 * Not a contribution.
 * Not a contribution.
 *
 *
 * Copyright (C) 2009 The Android Open Source Project
 * Copyright (C) 2009 The Android Open Source Project
@@ -69,6 +69,10 @@
#endif // DOLBY_END
#endif // DOLBY_END


namespace android {
namespace android {
/*audio policy: workaround for truncated touch sounds*/
//FIXME: workaround for truncated touch sounds
// to be removed when the problem is handled by system UI
#define TOUCH_SOUND_FIXED_DELAY_MS 100
#ifdef VOICE_CONCURRENCY
#ifdef VOICE_CONCURRENCY
audio_output_flags_t AudioPolicyManagerCustom::getFallBackPath()
audio_output_flags_t AudioPolicyManagerCustom::getFallBackPath()
{
{
@@ -417,6 +421,10 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d
        }
        }


        closeAllInputs();
        closeAllInputs();
        /*audio policy: fix call volume over USB*/
        // As the input device list can impact the output device selection, update
        // getDeviceForStrategy() cache
        updateDevicesAndOutputs();


        if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
        if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
            audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
            audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
@@ -1068,9 +1076,17 @@ void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
    checkOutputForAllStrategies();
    checkOutputForAllStrategies();
    updateDevicesAndOutputs();
    updateDevicesAndOutputs();


    /*audio policy: workaround for truncated touch sounds*/
    //FIXME: workaround for truncated touch sounds
    // to be removed when the problem is handled by system UI
    uint32_t delayMs = 0;
    uint32_t waitMs = 0;
    if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) {
        delayMs = TOUCH_SOUND_FIXED_DELAY_MS;
    }
    if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
    if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
        audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/);
        audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/);
        updateCallRouting(newDevice);
        waitMs = updateCallRouting(newDevice, delayMs);
    }
    }
    // Use reverse loop to make sure any low latency usecases (generally tones)
    // Use reverse loop to make sure any low latency usecases (generally tones)
    // are not routed before non LL usecases (generally music).
    // are not routed before non LL usecases (generally music).
@@ -1082,11 +1098,12 @@ void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
    for (size_t i = mOutputs.size(); i > 0; i--) {
    for (size_t i = mOutputs.size(); i > 0; i--) {
        sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1);
        sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1);
        audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/);
        audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/);
        if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || outputDesc != mPrimaryOutput) {
        if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) {
            setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE));
            waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE),
                                     delayMs);
        }
        }
        if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
        if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
            applyStreamVolumes(outputDesc, newDevice, 0, true);
            applyStreamVolumes(outputDesc, newDevice, waitMs, true);
        }
        }
    }
    }


@@ -1160,6 +1177,11 @@ status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDe
                                    dev,
                                    dev,
                                    force,
                                    force,
                                    delayMs);
                                    delayMs);
                    /*audio policy: fix media volume after ringtone*/
                    // re-apply device specific volume if not done by setOutputDevice()
                     if (!force) {
                         applyStreamVolumes(desc, dev, delayMs);
                     }
                }
                }
            }
            }
            // update the outputs if stopping one with a stream that can affect notification routing
            // update the outputs if stopping one with a stream that can affect notification routing
@@ -1266,6 +1288,10 @@ status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputD
        if (strategy == STRATEGY_SONIFICATION) {
        if (strategy == STRATEGY_SONIFICATION) {
            mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
            mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
        }
        }
        if (waitMs > muteWaitMs) {
            *delayMs = waitMs - muteWaitMs;
        }

    }
    }
    else {
    else {
        // handle special case for sonification while in call
        // handle special case for sonification while in call
@@ -2160,11 +2186,16 @@ status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,
            mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress,
            mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress,
                    MIX_STATE_MIXING);
                    MIX_STATE_MIXING);
        }
        }

        /*audio policy: fix capture indication to sound trigger service*/
        if (mInputs.activeInputsCountOnDevices() == 0) {
        // indicate active capture to sound trigger service if starting capture from a mic on
        // primary HW module
        audio_devices_t device = getNewInputDevice(input);
        audio_devices_t primaryInputDevices = availablePrimaryInputDevices();
        if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
                mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {
            SoundTrigger::setCaptureState(true);
            SoundTrigger::setCaptureState(true);
        }
        }
        setInputDevice(input, getNewInputDevice(input), true /* force */);
        setInputDevice(input, device, true /* force */);


        // automatically enable the remote submix output when input is started if not
        // automatically enable the remote submix output when input is started if not
        // used by a policy mix of type MIX_TYPE_RECORDERS
        // used by a policy mix of type MIX_TYPE_RECORDERS