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

Commit fbc3b814 authored by Chienyuan's avatar Chienyuan Committed by android-build-merger
Browse files

Merge "Disconnect current device when maxium connected bluetooth audio device is 1"

am: e7715212

Change-Id: Ic822478a603efe9c9b54eb814fbbb345ca9ace39
parents 5f27295c e7715212
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");