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

Commit 37661a43 authored by Kiran Kelageri's avatar Kiran Kelageri Committed by Bruno Martins
Browse files

Bluetooth: Unpair both earbuds on unpair.



1> On unpair initiation to primary, Initiate Unpair
   for peer secondary TWS device as well.
2> On pairing to primary earbud, Initiate connection to second
   earbud.

[wight554: updated code from LA.QSSI.11.0.r1-05600-qssi.0]

 Conflicts:
	packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java

CRs-fixed: 2230362
Change-Id: I0d0e7c3bc66d4ff24a2b767996bc1367022901d6
Signed-off-by: default avatarVolodymyr Zhdanov <wight554@gmail.com>
parent 86eb709f
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
@@ -133,6 +134,22 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        mHiSyncId = BluetoothHearingAid.HI_SYNC_ID_INVALID;
    }

    /* Gets Device for seondary TWS device
     * @param mDevice Primary TWS device  to get secondary
     * @return Description of the device
     */

    private BluetoothDevice getTwsPeerDevice() {
      BluetoothAdapter bluetoothAdapter;
      BluetoothDevice peerDevice = null;
      if (mDevice.isTwsPlusDevice()) {
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        String peerAddress = mDevice.getTwsPlusPeerAddress();
        peerDevice = bluetoothAdapter.getRemoteDevice(peerAddress);
      }
      return peerDevice;
    }

    /**
     * Describes the current device and profile for logging.
     *
@@ -381,6 +398,17 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>

        if (state != BluetoothDevice.BOND_NONE) {
            final BluetoothDevice dev = mDevice;
            if (mDevice.isTwsPlusDevice()) {
               BluetoothDevice peerDevice = getTwsPeerDevice();
               if (peerDevice != null) {
                   final boolean peersuccessful = peerDevice.removeBond();
                   if (peersuccessful) {
                       if (Utils.D) {
                           Log.d(TAG, "Command sent successfully:REMOVE_BOND " + peerDevice.getName());
                       }
                   }
                }
            }
            if (dev != null) {
                final boolean successful = dev.removeBond();
                if (successful) {
@@ -708,9 +736,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>

        refresh();

        if (bondState == BluetoothDevice.BOND_BONDED && mDevice.isBondingInitiatedLocally()) {
        if (bondState == BluetoothDevice.BOND_BONDED) {
            if (SystemProperties.getBoolean("persist.vendor.bt.connect.peer_earbud", true)) {
                Log.d(TAG, "Initiating connection to" + mDevice);
                if (mDevice.isBondingInitiatedLocally() || mDevice.isTwsPlusDevice()) {
                    connect();
                }
            } else if (mDevice.isBondingInitiatedLocally()) {
                connect();
            }
        }
    }

    public BluetoothClass getBtClass() {