diff options
author | zhiwyan <quic_zhiwyan@quicinc.com> | 2021-12-30 16:45:01 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2022-01-11 17:08:10 -0800 |
commit | c29846e969a243e56aaacf63c8eb3e77bd5646d1 (patch) | |
tree | 41385da41b51c3453b620e7b1db62676efc8832e | |
parent | fd7dee6840c7b620029ff37018eb510fa30ab85b (diff) |
HFP: check and connect to active device
in case that set active device fastly between two bt device
during cs call, device that is disconnecting audio can be
set to active again and it can't connect to audio at such
case, so we need to check and connect to audio when it
becomes idle again
CRs-Fixed: 3100899
Change-Id: I871a6668634a7c0fbe11432bddeae61259b1cc9b
-rw-r--r-- | src/com/android/bluetooth/hfp/HeadsetService.java | 17 | ||||
-rw-r--r-- | src/com/android/bluetooth/hfp/HeadsetStateMachine.java | 8 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/com/android/bluetooth/hfp/HeadsetService.java b/src/com/android/bluetooth/hfp/HeadsetService.java index e1438f7a4..6528e6049 100644 --- a/src/com/android/bluetooth/hfp/HeadsetService.java +++ b/src/com/android/bluetooth/hfp/HeadsetService.java @@ -2024,6 +2024,23 @@ public class HeadsetService extends ProfileService { } if (stateMachine.getAudioState() != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) { logD("connectAudio: audio is not idle for device " + device); + /** + * add for case that device disconnecting audio has been set active again, + * then send CONNECT_AUDIO if not contained in queue and should persist audio + */ + if (mActiveDevice != null && mActiveDevice.equals(device) && + stateMachine.getAudioState() == BluetoothHeadset.STATE_AUDIO_DISCONNECTING + && !stateMachine.hasMessagesInQueue(HeadsetStateMachine.CONNECT_AUDIO) && + !stateMachine.hasDeferredMessagesInQueue(HeadsetStateMachine.CONNECT_AUDIO) + && shouldPersistAudio()) { + if (stateMachine.getIfDeviceBlacklistedForSCOAfterSLC() == true) + connDelay = 0; + + Log.i(TAG, "connectAudio: active again and connect audio after " + + connDelay + " ms"); + stateMachine.sendMessageDelayed(HeadsetStateMachine.CONNECT_AUDIO, + device, connDelay); + } return true; } if (isAudioOn()) { diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index 3676d6b32..4ddd9e4b8 100644 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -393,6 +393,14 @@ public class HeadsetStateMachine extends StateMachine { return mIsBlacklistedForSCOAfterSLC; } + public boolean hasMessagesInQueue(int what) { + return super.hasMessages(what); + } + + public boolean hasDeferredMessagesInQueue(int what) { + return super.hasDeferredMessages(what); + } + /** * Base class for states used in this state machine to share common infrastructures */ |