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

Commit 4936c62e authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "HFP: Fix headset state transition on device replacement" am: 6a764425

am: ffd4de9b

Change-Id: I91a39929cb69b6e773b0e4f3d5f310bd2bdfa336
parents 0c7a7446 ffd4de9b
Loading
Loading
Loading
Loading
+23 −35
Original line number Diff line number Diff line
@@ -810,37 +810,28 @@ final class HeadsetStateMachine extends StateMachine {
                    if (mConnectedDevicesList.contains(device)) {
                        Log.w(TAG, "Connected: CONNECT, device " + device + " is connected");
                        break;
                    } else {
                        broadcastConnectionState(mCurrentDevice,
                                BluetoothProfile.STATE_DISCONNECTING,
                                BluetoothProfile.STATE_CONNECTED);
                    }
                    if (mConnectedDevicesList.size() >= max_hf_connections) {
                        BluetoothDevice DisconnectConnectedDevice = null;
                        IState CurrentAudioState = getCurrentState();
                        Log.d(TAG, "Reach to max size, disconnect one of them first");
                        /* TODO: Disconnect based on CoD */
                        DisconnectConnectedDevice = mConnectedDevicesList.get(0);

                        BluetoothDevice disconnectDevice = mConnectedDevicesList.get(0);
                        Log.d(TAG, "Connected: Reach to max size, disconnect " + disconnectDevice);
                        broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
                                BluetoothProfile.STATE_DISCONNECTED);

                        if (!disconnectHfpNative(getByteAddress(DisconnectConnectedDevice))) {
                        if (disconnectHfpNative(getByteAddress(disconnectDevice))) {
                            broadcastConnectionState(disconnectDevice,
                                    BluetoothProfile.STATE_DISCONNECTING,
                                    BluetoothProfile.STATE_CONNECTED);
                        } else {
                            Log.w(TAG, "Connected: failed to disconnect " + disconnectDevice);
                            broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                    BluetoothProfile.STATE_CONNECTING);
                            break;
                        } else {
                            broadcastConnectionState(DisconnectConnectedDevice,
                                    BluetoothProfile.STATE_DISCONNECTING,
                                    BluetoothProfile.STATE_CONNECTED);
                        }

                        synchronized (HeadsetStateMachine.this) {
                            mTargetDevice = device;
                            if (max_hf_connections == 1) {
                                transitionTo(mPending);
                            } else {
                                mMultiDisconnectDevice = DisconnectConnectedDevice;
                                mMultiDisconnectDevice = disconnectDevice;
                                transitionTo(mMultiHFPending);
                            }
                        }
@@ -1192,42 +1183,39 @@ final class HeadsetStateMachine extends StateMachine {
                        deferMessage(obtainMessage(DISCONNECT, mCurrentDevice));
                        deferMessage(obtainMessage(CONNECT, device));
                        if (disconnectAudioNative(getByteAddress(mCurrentDevice))) {
                            Log.d(TAG, "Disconnecting SCO audio for device=" + mCurrentDevice);
                            Log.d(TAG, "AudioOn: disconnecting SCO, device=" + mCurrentDevice);
                        } else {
                            Log.e(TAG, "disconnectAudioNative failed");
                            Log.e(TAG, "AudioOn: disconnect SCO failed, device=" + mCurrentDevice);
                        }
                        break;
                    }

                    if (mConnectedDevicesList.size() >= max_hf_connections) {
                        BluetoothDevice DisconnectConnectedDevice = null;
                        IState CurrentAudioState = getCurrentState();
                        Log.d(TAG, "Reach to max size, disconnect "
                                        + "one of them first");
                        DisconnectConnectedDevice = mConnectedDevicesList.get(0);
                        BluetoothDevice disconnectDevice = mConnectedDevicesList.get(0);
                        Log.d(TAG, "AudioOn: Reach to max size, disconnect " + disconnectDevice);

                        if (mActiveScoDevice.equals(DisconnectConnectedDevice)) {
                            DisconnectConnectedDevice = mConnectedDevicesList.get(1);
                        if (mActiveScoDevice.equals(disconnectDevice)) {
                            disconnectDevice = mConnectedDevicesList.get(1);
                        }

                        broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
                                BluetoothProfile.STATE_DISCONNECTED);

                        if (!disconnectHfpNative(getByteAddress(DisconnectConnectedDevice))) {
                        if (disconnectHfpNative(getByteAddress(disconnectDevice))) {
                            broadcastConnectionState(disconnectDevice,
                                    BluetoothProfile.STATE_DISCONNECTING,
                                    BluetoothProfile.STATE_CONNECTED);
                        } else {
                            Log.e(TAG, "AudioOn: Failed to disconnect " + disconnectDevice);
                            broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                    BluetoothProfile.STATE_CONNECTING);
                            break;
                        } else {
                            broadcastConnectionState(DisconnectConnectedDevice,
                                    BluetoothProfile.STATE_DISCONNECTING,
                                    BluetoothProfile.STATE_CONNECTED);
                        }

                        synchronized (HeadsetStateMachine.this) {
                            mTargetDevice = device;
                            mMultiDisconnectDevice = DisconnectConnectedDevice;
                            mMultiDisconnectDevice = disconnectDevice;
                            transitionTo(mMultiHFPending);
                            DisconnectConnectedDevice = null;
                        }
                    } else if (mConnectedDevicesList.size() < max_hf_connections) {
                        broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,