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

Commit 7bbd9052 authored by Sumit Bajpai's avatar Sumit Bajpai Committed by Steve Kondik
Browse files

BT: Multi HF support in Settings App.

1. The connected sinks are not disconnected from
HeadsetProfile when new sink is connecting.
2. Also return correct connection status for
specific HS.
3. Sets priority for specific HS while disconnecting.

Change-Id: I876f9810be82482cb360451343e4eb2a9f3ed668
parent a72a6874
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ final class HeadsetProfile implements LocalBluetoothProfile {
        List<BluetoothDevice> sinks = mService.getConnectedDevices();
        if (sinks != null) {
            for (BluetoothDevice sink : sinks) {
                mService.disconnect(sink);
                Log.d(TAG,"Not disconnecting device = " + sink);
            }
        }
        return mService.connect(device);
@@ -124,24 +124,33 @@ final class HeadsetProfile implements LocalBluetoothProfile {
    public boolean disconnect(BluetoothDevice device) {
        if (mService == null) return false;
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();
        if (!deviceList.isEmpty() && deviceList.get(0).equals(device)) {
        if (!deviceList.isEmpty()) {
            for (BluetoothDevice dev : deviceList) {
                if (dev.equals(device)) {
                    if (V) Log.d(TAG,"Downgrade priority as user" +
                                        "is disconnecting the headset");
                    // Downgrade priority as user is disconnecting the headset.
                    if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
                        mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
                    }
                    return mService.disconnect(device);
        } else {
            return false;
                }
            }
        }
        return false;
    }

    public int getConnectionStatus(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();

        return !deviceList.isEmpty() && deviceList.get(0).equals(device)
                ? mService.getConnectionState(device)
                : BluetoothProfile.STATE_DISCONNECTED;
        if (!deviceList.isEmpty()){
            for (BluetoothDevice dev : deviceList) {
                if (dev.equals(device)) {
                    return mService.getConnectionState(device);
                }
            }
        }
        return BluetoothProfile.STATE_DISCONNECTED;
    }

    public boolean isPreferred(BluetoothDevice device) {