diff options
author | Charlie Boutier <charliebout@google.com> | 2023-11-10 18:04:55 +0000 |
---|---|---|
committer | Charlie Boutier <charliebout@google.com> | 2023-11-14 00:51:41 +0000 |
commit | 28ba74c4f5f5828105f7008f4665d601f136dc32 (patch) | |
tree | 1bd07ee284e5f16cc9c176ceb432934b764962a3 /src | |
parent | eb6d1f4b8a294a4c32591a45dd60861cd09b60e9 (diff) | |
download | Telecomm-28ba74c4f5f5828105f7008f4665d601f136dc32.tar.gz |
Hearing Aid: Connect route when right HA is connected first
Allow the hearings aid to properly connect to the audio route when the
right hearing aid is connected first.
Add some Unit tests to cover this case.
Bug: 308045084
Bug: 306075809
Test: atest TelecomUnitTests:com.android.server.telecom.tests.BluetoothRouteManagerTest
Test: manual tests with HAs
Test: manual tests with a Bluetooth speaker
Change-Id: I0e59a5f9d50ca69c36d7dad0fd7d9ef44a751829
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java index 6cf6ae432..941d2ec97 100644 --- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java @@ -45,6 +45,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -134,7 +135,8 @@ public class BluetoothRouteManager extends StateMachine { @Override public void enter() { BluetoothDevice erroneouslyConnectedDevice = getBluetoothAudioConnectedDevice(); - if (erroneouslyConnectedDevice != null) { + if (erroneouslyConnectedDevice != null && + !erroneouslyConnectedDevice.equals(mHearingAidActiveDeviceCache)) { Log.w(LOG_TAG, "Entering AudioOff state but device %s appears to be connected. " + "Switching to audio-on state for that device.", erroneouslyConnectedDevice); // change this to just transition to the new audio on state @@ -252,6 +254,27 @@ public class BluetoothRouteManager extends StateMachine { SomeArgs args = (SomeArgs) msg.obj; String address = (String) args.arg2; boolean switchingBtDevices = !Objects.equals(mDeviceAddress, address); + + if (switchingBtDevices == true) { // check if it is an hearing aid pair + BluetoothAdapter bluetoothAdapter = mDeviceManager.getBluetoothAdapter(); + if (bluetoothAdapter != null) { + List<BluetoothDevice> activeHearingAids = + bluetoothAdapter.getActiveDevices(BluetoothProfile.HEARING_AID); + for (BluetoothDevice hearingAid : activeHearingAids) { + if (hearingAid != null) { + String hearingAidAddress = hearingAid.getAddress(); + if (hearingAidAddress != null) { + if (hearingAidAddress.equals(address) || + hearingAidAddress.equals(mDeviceAddress)) { + switchingBtDevices = false; + break; + } + } + } + } + + } + } try { switch (msg.what) { case NEW_DEVICE_CONNECTED: @@ -863,12 +886,18 @@ public class BluetoothRouteManager extends StateMachine { : mDeviceManager.isHearingAidSetAsCommunicationDevice(); if (bluetoothHearingAid != null) { if (isHearingAidSetForCommunication) { - for (BluetoothDevice device : bluetoothAdapter.getActiveDevices( - BluetoothProfile.HEARING_AID)) { - if (device != null) { - hearingAidActiveDevice = device; - activeDevices++; - break; + List<BluetoothDevice> hearingAidsActiveDevices = bluetoothAdapter.getActiveDevices( + BluetoothProfile.HEARING_AID); + if (hearingAidsActiveDevices.contains(mHearingAidActiveDeviceCache)) { + hearingAidActiveDevice = mHearingAidActiveDeviceCache; + activeDevices++; + } else { + for (BluetoothDevice device : hearingAidsActiveDevices) { + if (device != null) { + hearingAidActiveDevice = device; + activeDevices++; + break; + } } } } |