The fix consists in adding a parameter to handleIncallSonification() indicating that it is called from setPhoneState() in which case the stream mute or unmute is called as many times as there are active tracks on the output.
Also change the time when handleIncallSonification() is called in setPhoneState() to make sure that both mPhoneSate and the selected device are coherent with the IN_CALL state when the fucntion is called.
* changes:
Fix bug 2146274. Modify the Audio Policy Manager to support dynamic rerouting of STREAM_VOICE_CALL streams when using AudioManager.setSpeakerphoneOn(bool) even when not in call.
to support dynamic rerouting of STREAM_VOICE_CALL streams when using
AudioManager.setSpeakerphoneOn(bool) even when not in call.
The setSpeakerphoneOn() method is mapped in the AudioPolicyManager to
a call to setForceUse for the AudioSystem::FOR_COMMUNICATION usage.
This was only updating the output device when the current mode
was MODE_IN_CALL. The change consists in changing the routing
also when there is an active stream of type AudioSystem::VOICE_CALL
as we allow that stream type to be used not just for telephony streams,
but for communications in general.
The kernel will only do it for images with an alpha plane.
Change-Id: Idcba41945ed7d17daae0a5bcc48c64a82a49dded
Signed-off-by: Dima Zavin <dima@android.com>
There was a problem in the special management of notifications while incall when using a duplicated output (with A2DP headset connected). When in call, the notifications are not played on both A2DP + speaker outputs but replaced by a tone in the device used for in call audio. When the call ends while a notification or ring tone is playing, the notification was not moved back to duplicated output (A2DP+speaker).
We must also make sure that the code that unmutes notification playback and stops the tone is called before the notification stream is moved back to duplicated output as it handles the volume and routing on hardware output only.
Also fixed a potential problem in active tracks counting when moving DTMF stream from A2DP output to hardware output when changing cal
l state.
Apply the following rules to ring tones and notifications to avoid sound level bursts in user's ears:
- always attenuate ring tones and notifications volume by 6dB
- if music is playing, always limit the volume to current music volume, with a minimum threshold at -36dB so that notification is always perceived.
Mute media streams during 2 seconds while the music is being switched from A2DP output to hardware output and before it is paused by the music application.
Also improve code readability by using pointers to output descriptors.
The fix consists in deallocating the A2DP output descriptor when the duplicated output opening fails in AudioPolicyManager::setDeviceConnectionState().
A regression on volume control was introduced by change 22899. When a volume change was requested on 2 different outputs for the same stream, the change on the second output was ignored because the requested value was the same as current one.
The fix consists in storing current stream volume for each output instead of globally for all outputs.
Modify AudioPolicyManager::setPhoneState() to force a routing command to audio output when call ends or starts even if the same device is selected.
Implement AudioHardware::setMode() to force routing change to be taken into account when phone state changes.
The problem is partly due to the fact that if music is playing in the headset, a routing change is done to play the shutter sound in both headset+speaker. When the shutter sound ends, the routing is reset to headset, but the change is immediate and there is still audio data pertaining to the shutter sound in the audio hardware buffer queue. As the shutter sound is short, sometimes none of it is output to the speaker before the audio path is reset to the headset.
Another factor is the long time taken by the audio hardware to execute some routing or volume change commands (especially in call volume). Current AudioPolicyManager design reapplies all stream volumes when the output device is changed which adds an unecessary delay in the routing command execution.
Another side problem is that althoough the music is muted while the shutter sound is played, the audio latency makes that some music is heard briefly before the shutter sound in the speaker.
In addition a regression in change 21083 broke the mute mechanism.
This fix consists in:
1 Delay the routing change when the shutter sound stops by a duration longer than the audio output latency.
2 Do not send unecessary volume changes by comparing current value with requested value.
3 Wait until the music is muted before proceding with the reset of the audio routing change when starting the shutter sound.
4 fix mute regression
AudioPolicyManager must prevent that VOICE_CALL stream volume is changed while BT SCO route is on for voice call and also that BLUETOOTH_SCO stream volume is changed when BT SCO route is off.
This rule was only applied to volume change requests coming from outside AudioPolicyManager.
Make sure that this rule applies also to internal requests.
Apparently the problem is caused by the fact that A2dpAudioStreamOut::standby() calls a2dp_stop() after the headset has been powered down.
The workaround consists in indicating to A2DP audio hardware that a close request is pending and that stanby() must be bypassed.