Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22b31dd8 authored by Gurpreet Ghai's avatar Gurpreet Ghai Committed by Bruno Martins
Browse files

BT_Audio: Updated Check for TWS+ switch

- Race condition between disconnection of first earbud and
  connection of second earbud, the configuration of second
  earbud is ignored because it is considered a case of TWS
  switch.
- Since MM Audio removes the disconnected device from list
  after delay of ~600ms, this creates a window where a new
  connection goes unprocessed when it happens immediately
  after disconnection.
- This change fetches real time connection state from A2DP
  to overcome the race condition.

CRs-Fixed: 2606382

Change-Id: I2df8447acb1d8e1b843a49906f2f3e3993cce5d6
parent 8fbf21ed
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class BtHelper {
    private @Nullable BluetoothHearingAid mHearingAid;

    // Reference to BluetoothA2dp to query for AbsoluteVolume.
    private @Nullable BluetoothA2dp mA2dp;
    static private @Nullable BluetoothA2dp mA2dp;

    // If absolute volume is supported in AVRCP device
    private boolean mAvrcpAbsVolSupported = false;
@@ -171,13 +171,18 @@ public class BtHelper {
    /*packages*/ @NonNull static boolean isTwsPlusSwitch(@NonNull BluetoothDevice device,
                                                                 String address) {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (device == null || adapter.getRemoteDevice(address) == null ||
        BluetoothDevice connDevice = adapter.getRemoteDevice(address);
        if (device == null || connDevice == null ||
            device.getTwsPlusPeerAddress() == null) {
            return false;
        }
        if (device.isTwsPlusDevice() &&
            adapter.getRemoteDevice(address).isTwsPlusDevice() &&
            connDevice.isTwsPlusDevice() &&
            device.getTwsPlusPeerAddress().equals(address)) {
            if(mA2dp.getConnectionState(connDevice) != BluetoothProfile.STATE_CONNECTED) {
                Log.w(TAG,"Active earbud is already disconnected");
                return false;
            }
            Log.i(TAG,"isTwsPlusSwitch true");
            return true;
         }