AudioService: Fix setting LeAudio volume after VoIP call
When mode changes to NORMAL but the USAGE_VOICE_COMMUNICATION is still present in the playback streams the mode change would trigger volume update but would still use STREAM_VOICE_CALL volume level and the music content will be resumed with voice call volume, possibly with higher and potentially harmful volume level. This change relies on mode change to get stream type from the mode and therefor restores the right volume right away, without relying on the onPlaybackConfigChange() which seems to be happening to late while the loud music with the conversation volume level already reached the listener. Bug: 247659576 Tag: #feature Test: manually testing with VoIP call while streaming media Change-Id: Ie2225b7e92e0d3f7146e9266caf8bda81eddad03
This commit is contained in:
@@ -4014,7 +4014,8 @@ public class AudioService extends IAudioService.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private void setLeAudioVolumeOnModeUpdate(int mode, int device) {
|
||||
private void setLeAudioVolumeOnModeUpdate(int mode, int device, int streamType, int index,
|
||||
int maxIndex) {
|
||||
switch (mode) {
|
||||
case AudioSystem.MODE_IN_COMMUNICATION:
|
||||
case AudioSystem.MODE_IN_CALL:
|
||||
@@ -4032,16 +4033,15 @@ public class AudioService extends IAudioService.Stub
|
||||
// (like the outgoing call) the value of 'device' is not DEVICE_OUT_BLE_*
|
||||
// even when BLE is connected.
|
||||
if (!AudioSystem.isLeAudioDeviceType(device)) {
|
||||
Log.w(TAG, "setLeAudioVolumeOnModeUpdate got unexpected device=" + device
|
||||
+ ", forcing to device=" + AudioSystem.DEVICE_OUT_BLE_HEADSET);
|
||||
device = AudioSystem.DEVICE_OUT_BLE_HEADSET;
|
||||
}
|
||||
|
||||
final int streamType = getBluetoothContextualVolumeStream(mode);
|
||||
final int index = mStreamStates[streamType].getIndex(device);
|
||||
final int maxIndex = mStreamStates[streamType].getMaxIndex();
|
||||
|
||||
if (DEBUG_VOL) {
|
||||
Log.d(TAG, "setLeAudioVolumeOnModeUpdate postSetLeAudioVolumeIndex index="
|
||||
+ index + " maxIndex=" + maxIndex + " streamType=" + streamType);
|
||||
Log.d(TAG, "setLeAudioVolumeOnModeUpdate postSetLeAudioVolumeIndex device="
|
||||
+ device + ", mode=" + mode + ", index=" + index + " maxIndex=" + maxIndex
|
||||
+ " streamType=" + streamType);
|
||||
}
|
||||
mDeviceBroker.postSetLeAudioVolumeIndex(index, maxIndex, streamType);
|
||||
mDeviceBroker.postApplyVolumeOnDevice(streamType, device, "setLeAudioVolumeOnModeUpdate");
|
||||
@@ -5412,10 +5412,18 @@ public class AudioService extends IAudioService.Stub
|
||||
mModeLogger.log(new PhoneStateEvent(requesterPackage, requesterPid,
|
||||
requestedMode, pid, mode));
|
||||
|
||||
int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
|
||||
int device = getDeviceForStream(streamType);
|
||||
int index = mStreamStates[mStreamVolumeAlias[streamType]].getIndex(device);
|
||||
setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true,
|
||||
final int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
|
||||
final int device = getDeviceForStream(streamType);
|
||||
final int streamAlias = mStreamVolumeAlias[streamType];
|
||||
|
||||
if (DEBUG_MODE) {
|
||||
Log.v(TAG, "onUpdateAudioMode: streamType=" + streamType
|
||||
+ ", streamAlias=" + streamAlias);
|
||||
}
|
||||
|
||||
final int index = mStreamStates[streamAlias].getIndex(device);
|
||||
final int maxIndex = mStreamStates[streamAlias].getMaxIndex();
|
||||
setStreamVolumeInt(streamAlias, index, device, true,
|
||||
requesterPackage, true /*hasModifyAudioSettings*/);
|
||||
|
||||
updateStreamVolumeAlias(true /*updateVolumes*/, requesterPackage);
|
||||
@@ -5423,7 +5431,7 @@ public class AudioService extends IAudioService.Stub
|
||||
// change of mode may require volume to be re-applied on some devices
|
||||
updateAbsVolumeMultiModeDevices(previousMode, mode);
|
||||
|
||||
setLeAudioVolumeOnModeUpdate(mode, device);
|
||||
setLeAudioVolumeOnModeUpdate(mode, device, streamAlias, index, maxIndex);
|
||||
|
||||
// when entering RINGTONE, IN_CALL or IN_COMMUNICATION mode, clear all SCO
|
||||
// connections not started by the application changing the mode when pid changes
|
||||
|
||||
Reference in New Issue
Block a user