diff options
| author | 2019-04-26 14:41:32 -0700 | |
|---|---|---|
| committer | 2019-04-26 14:41:32 -0700 | |
| commit | 0cf98c7aec0535bfe0fc6d0c5173c20b0d759814 (patch) | |
| tree | 2aee5ca10ba4e55f22470994149e7ff5ab09f4b0 | |
| parent | ba5b5d3b95686058e736336029645cff7a54e45c (diff) | |
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
3 files changed, 28 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index 668af85af0a9..a0522e3971e7 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -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: diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index 3948bd858538..887c90873bdd 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -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); } diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index c34425ff17cb..507f398d2422 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -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; |