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

Commit 971b50bd authored by Chienyuan's avatar Chienyuan
Browse files

Disconnect current device when maxium connected bluetooth audio device is 1

Bug: 111812003
Test: 1. Developer options > Maxium connected Bluetooth device > 1.
      2. Connected 2 BT Headset respectively

Change-Id: I12a10bc6bd822375ae43c405a638080d30cde1de
parent b560d9ae
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -250,9 +250,24 @@ public class A2dpService extends ProfileService {

        synchronized (mStateMachines) {
            if (!connectionAllowedCheckMaxDevices(device)) {
                // when mMaxConnectedAudioDevices is one, disconnect current device first.
                if (mMaxConnectedAudioDevices == 1) {
                    List<BluetoothDevice> sinks = getDevicesMatchingConnectionStates(
                            new int[] {BluetoothProfile.STATE_CONNECTED,
                                    BluetoothProfile.STATE_CONNECTING,
                                    BluetoothProfile.STATE_DISCONNECTING});
                    for (BluetoothDevice sink : sinks) {
                        if (sink.equals(device)) {
                            Log.w(TAG, "Connecting to device " + device + " : disconnect skipped");
                            continue;
                        }
                        disconnect(sink);
                    }
                } else {
                    Log.e(TAG, "Cannot connect to " + device + " : too many connected devices");
                    return false;
                }
            }
            A2dpStateMachine smConnect = getOrCreateStateMachine(device);
            if (smConnect == null) {
                Log.e(TAG, "Cannot connect to " + device + " : no state machine");