AudioService: fix call volume switching from speaker to hearing aid

Apply either VOICE_CALL or MUSIC stream volume according to current
audio mode when an hearing aid device is connected.

Bug: 129886903
Test: call with hearing aid and turn speakerphone on and off
Change-Id: I76dfb0ee8f867a720d12e6574ad72e159bfe0c26
This commit is contained in:
Eric Laurent
2019-04-26 14:41:32 -07:00
parent ba5b5d3b95
commit 0cf98c7aec
3 changed files with 28 additions and 11 deletions

View File

@@ -723,7 +723,8 @@ import com.android.internal.annotations.GuardedBy;
case MSG_IL_SET_HEARING_AID_CONNECTION_STATE:
synchronized (mDeviceStateLock) {
mDeviceInventory.onSetHearingAidConnectionState(
(BluetoothDevice) msg.obj, msg.arg1);
(BluetoothDevice) msg.obj, msg.arg1,
mAudioService.getHearingAidStreamType());
}
break;
case MSG_BT_HEADSET_CNCT_FAILED:

View File

@@ -236,7 +236,7 @@ public final class AudioDeviceInventory {
}
/*package*/ void onSetHearingAidConnectionState(BluetoothDevice btDevice,
@AudioService.BtProfileConnectionState int state) {
@AudioService.BtProfileConnectionState int state, int streamType) {
String address = btDevice.getAddress();
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
address = "";
@@ -253,7 +253,7 @@ public final class AudioDeviceInventory {
if (isConnected && state != BluetoothProfile.STATE_CONNECTED) {
makeHearingAidDeviceUnavailable(address);
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
makeHearingAidDeviceAvailable(address, BtHelper.getName(btDevice),
makeHearingAidDeviceAvailable(address, BtHelper.getName(btDevice), streamType,
"onSetHearingAidConnectionState");
}
}
@@ -719,10 +719,11 @@ public final class AudioDeviceInventory {
}
@GuardedBy("mConnectedDevices")
private void makeHearingAidDeviceAvailable(String address, String name, String eventSource) {
final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(AudioSystem.STREAM_MUSIC,
private void makeHearingAidDeviceAvailable(
String address, String name, int streamType, String eventSource) {
final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType,
AudioSystem.DEVICE_OUT_HEARING_AID);
mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, AudioSystem.STREAM_MUSIC);
mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, streamType);
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_HEARING_AID,
AudioSystem.DEVICE_STATE_AVAILABLE, address, name,
@@ -732,7 +733,7 @@ public final class AudioDeviceInventory {
new DeviceInfo(AudioSystem.DEVICE_OUT_HEARING_AID, name,
address, AudioSystem.AUDIO_FORMAT_DEFAULT));
mDeviceBroker.postAccessoryPlugMediaUnmute(AudioSystem.DEVICE_OUT_HEARING_AID);
mDeviceBroker.postApplyVolumeOnDevice(AudioSystem.STREAM_MUSIC,
mDeviceBroker.postApplyVolumeOnDevice(streamType,
AudioSystem.DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable");
setCurrentAudioRouteNameIfPossible(name);
}

View File

@@ -2078,6 +2078,22 @@ public class AudioService extends IAudioService.Stub
}
}
/*package*/ int getHearingAidStreamType() {
return getHearingAidStreamType(mMode);
}
private int getHearingAidStreamType(int mode) {
switch (mode) {
case AudioSystem.MODE_IN_COMMUNICATION:
case AudioSystem.MODE_IN_CALL:
return AudioSystem.STREAM_VOICE_CALL;
case AudioSystem.MODE_NORMAL:
default:
break;
}
return AudioSystem.STREAM_MUSIC;
}
/**
* Manage an audio mode change for audio devices that use an "absolute volume" model,
* i.e. the framework sends the full scale signal, and the actual volume for the use case
@@ -2087,14 +2103,10 @@ public class AudioService extends IAudioService.Stub
if (oldMode == newMode) {
return;
}
int streamType = AudioSystem.STREAM_MUSIC;
switch (newMode) {
case AudioSystem.MODE_IN_COMMUNICATION:
case AudioSystem.MODE_IN_CALL:
streamType = AudioSystem.STREAM_VOICE_CALL;
break;
case AudioSystem.MODE_NORMAL:
streamType = AudioSystem.STREAM_MUSIC;
break;
case AudioSystem.MODE_RINGTONE:
// not changing anything for ringtone
@@ -2105,6 +2117,9 @@ public class AudioService extends IAudioService.Stub
// don't know what to do in this case, better bail
return;
}
int streamType = getHearingAidStreamType(newMode);
final int device = AudioSystem.getDevicesForStream(streamType);
if ((device & mAbsVolumeMultiModeCaseDevices) == 0) {
return;