diff options
| author | 2024-08-02 16:24:32 +0800 | |
|---|---|---|
| committer | 2024-08-21 13:35:19 -0700 | |
| commit | cd106f5c7847ed8404f0e8010c6bf23497e6c9d4 (patch) | |
| tree | 0a3c600ffb1148f0158b73a79028edf96ecf2353 | |
| parent | 4f301b434fe8f02df4a3334019447bd320b34e90 (diff) | |
AudioService: Add makeHearingAidDeviceUnavailableLater
Currently, when Hearing Aid device becomes unavaliable due to BT adapter
disable, user can hear audio from device speaker for a split second.
This is because we make device unavaliable immediately for Hearing Aid.
Instead, it should become unavaliable after AUDIO_BECOMING_NOISY intent
is sent.
Since this is working correctly for A2DP, fix is to copy solution from
there for Hearing Aid code path, and split
makeHearingAidDeviceUnavailable into *Now and *Later versions.
Bug:361198689
Test: Disconnect Bluetooth when playing music while connected to a hearing aid, see if there is sound coming from the speaker.
Change-Id: I3446249f3dd1033079188fb87a7471456d38dab7
Signed-off-by: chenxin20 <chenxin20@xiaomi.com>
| -rw-r--r-- | services/core/java/com/android/server/audio/AudioDeviceBroker.java | 14 | ||||
| -rw-r--r-- | services/core/java/com/android/server/audio/AudioDeviceInventory.java | 20 |
2 files changed, 30 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index 09d1434b8547..e3cd9932c4c1 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -1640,6 +1640,10 @@ public class AudioDeviceBroker { sendIILMsg(MSG_IIL_BTLEAUDIO_TIMEOUT, SENDMSG_QUEUE, device, codec, address, delayMs); } + /*package*/ void setHearingAidTimeout(String address, int delayMs) { + sendLMsg(MSG_IL_BT_HEARING_AID_TIMEOUT, SENDMSG_QUEUE, address, delayMs); + } + /*package*/ void setAvrcpAbsoluteVolumeSupported(boolean supported) { synchronized (mDeviceStateLock) { mBtHelper.setAvrcpAbsoluteVolumeSupported(supported); @@ -1880,6 +1884,13 @@ public class AudioDeviceBroker { (String) msg.obj, msg.arg1, msg.arg2); } break; + case MSG_IL_BT_HEARING_AID_TIMEOUT: + // msg.obj == address of Hearing Aid device + synchronized (mDeviceStateLock) { + mDeviceInventory.onMakeHearingAidDeviceUnavailableNow( + (String) msg.obj); + } + break; case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: { final BtDeviceInfo btInfo = (BtDeviceInfo) msg.obj; @AudioSystem.AudioFormatNativeEnumForBtCodec final int codec = @@ -2155,6 +2166,7 @@ public class AudioDeviceBroker { private static final int MSG_L_SYNCHRONIZE_ADI_DEVICES_IN_INVENTORY = 58; private static final int MSG_IL_UPDATED_ADI_DEVICE_STATE = 59; private static final int MSG_L_SET_FORCE_BT_A2DP_USE_NO_MUTE = 60; + private static final int MSG_IL_BT_HEARING_AID_TIMEOUT = 61; private static boolean isMessageHandledUnderWakelock(int msgId) { switch(msgId) { @@ -2167,6 +2179,7 @@ public class AudioDeviceBroker { case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT: case MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT: case MSG_CHECK_MUTE_MUSIC: + case MSG_IL_BT_HEARING_AID_TIMEOUT: return true; default: return false; @@ -2251,6 +2264,7 @@ public class AudioDeviceBroker { case MSG_IL_BTA2DP_TIMEOUT: case MSG_IIL_BTLEAUDIO_TIMEOUT: case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: + case MSG_IL_BT_HEARING_AID_TIMEOUT: if (sLastDeviceConnectMsgTime >= time) { // add a little delay to make sure messages are ordered as expected time = sLastDeviceConnectMsgTime + 30; diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index 8d590148cab5..1f0f8c466cd5 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -961,6 +961,11 @@ public class AudioDeviceInventory { } } + /*package*/ void onMakeHearingAidDeviceUnavailableNow(String address) { + synchronized (mDevicesLock) { + makeHearingAidDeviceUnavailable(address); + } + } /** * Goes over all connected LE Audio devices in the provided group ID and @@ -1804,12 +1809,10 @@ public class AudioDeviceInventory { .set(MediaMetrics.Property.EVENT, "disconnectHearingAid") .record(); if (toRemove.size() > 0) { - /*final int delay = */ - checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, + final int delay = checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, AudioService.CONNECTION_STATE_DISCONNECTED, AudioSystem.DEVICE_NONE); toRemove.stream().forEach(deviceAddress -> - // TODO delay not used? - makeHearingAidDeviceUnavailable(deviceAddress /*, delay*/) + makeHearingAidDeviceUnavailableLater(deviceAddress, delay) ); } } @@ -2388,6 +2391,15 @@ public class AudioDeviceInventory { mDeviceBroker.postCheckCommunicationDeviceRemoval(ada); } + @GuardedBy("mDevicesLock") + private void makeHearingAidDeviceUnavailableLater( + String address, int delayMs) { + // the device will be made unavailable later, so consider it disconnected right away + mConnectedDevices.remove(DeviceInfo.makeDeviceListKey(DEVICE_OUT_HEARING_AID, address)); + // send the delayed message to make the device unavailable later + mDeviceBroker.setHearingAidTimeout(address, delayMs); + } + /** * Returns whether a device of type DEVICE_OUT_HEARING_AID is connected. * Visibility by APM plays no role |