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

Commit d1287f5e authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Fix bug in handling connect/disconnect multiple devices.

Multiple HID devices can be connected. There is no pointing
maintaining the global state. Check individual device state.

Bug: 3350904

Change-Id: I03d9a6015e39e4f9d7f68cc8bbdb19731129b4e6
parent 8eca7a1e
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -102,7 +102,6 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
    private BluetoothDevice mDevice;
    private BluetoothDevice mDevice;
    private int mHeadsetState = BluetoothProfile.STATE_DISCONNECTED;
    private int mHeadsetState = BluetoothProfile.STATE_DISCONNECTED;
    private int mA2dpState = BluetoothProfile.STATE_DISCONNECTED;
    private int mA2dpState = BluetoothProfile.STATE_DISCONNECTED;
    private int mHidState = BluetoothProfile.STATE_DISCONNECTED;


    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        @Override
@@ -140,7 +139,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
                int newState = intent.getIntExtra(BluetoothInputDevice.EXTRA_INPUT_DEVICE_STATE, 0);
                int newState = intent.getIntExtra(BluetoothInputDevice.EXTRA_INPUT_DEVICE_STATE, 0);
                int oldState =
                int oldState =
                    intent.getIntExtra(BluetoothInputDevice.EXTRA_PREVIOUS_INPUT_DEVICE_STATE, 0);
                    intent.getIntExtra(BluetoothInputDevice.EXTRA_PREVIOUS_INPUT_DEVICE_STATE, 0);
                mHidState = newState;

                if (oldState == BluetoothInputDevice.STATE_CONNECTED &&
                if (oldState == BluetoothInputDevice.STATE_CONNECTED &&
                    newState == BluetoothInputDevice.STATE_DISCONNECTED) {
                    newState == BluetoothInputDevice.STATE_DISCONNECTED) {
                    sendMessage(DISCONNECT_HID_INCOMING);
                    sendMessage(DISCONNECT_HID_INCOMING);
@@ -286,7 +285,8 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
                        sendMessage(DISCONNECT_A2DP_OUTGOING);
                        sendMessage(DISCONNECT_A2DP_OUTGOING);
                        deferMessage(message);
                        deferMessage(message);
                        break;
                        break;
                    } else if (mHidState != BluetoothInputDevice.STATE_DISCONNECTED) {
                    } else if (mService.getInputDeviceState(mDevice) !=
                            BluetoothInputDevice.STATE_DISCONNECTED) {
                        sendMessage(DISCONNECT_HID_OUTGOING);
                        sendMessage(DISCONNECT_HID_OUTGOING);
                        deferMessage(message);
                        deferMessage(message);
                        break;
                        break;
+2 −1
Original line number Original line Diff line number Diff line
@@ -1755,7 +1755,8 @@ public class BluetoothService extends IBluetooth.Stub {
                                                "Need BLUETOOTH_ADMIN permission");
                                                "Need BLUETOOTH_ADMIN permission");


        String objectPath = getObjectPathFromAddress(device.getAddress());
        String objectPath = getObjectPathFromAddress(device.getAddress());
        if (objectPath == null || getConnectedInputDevices().size() == 0) {
        if (objectPath == null ||
                getInputDeviceState(device) == BluetoothInputDevice.STATE_DISCONNECTED) {
            return false;
            return false;
        }
        }
        BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());
        BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());