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

Commit 2092361d authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Maintain pending outgoing bonding address.

This helps us to distinguish between incoming and outgoing Bonding requests.

Change-Id: I69e6a269b7dd6aad60e6f5711cad812291a7d313
parent cc7f40a8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -457,8 +457,9 @@ class BluetoothEventLoop {
        String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
        if (address == null) return;

        if (mBluetoothService.getBondState().getBondState(address) ==
                BluetoothDevice.BOND_BONDING) {
        String pendingOutgoingAddress =
                mBluetoothService.getBondState().getPendingOutgoingBonding();
        if (address.equals(pendingOutgoingAddress)) {
            // we initiated the bonding
            BluetoothClass btClass = new BluetoothClass(mBluetoothService.getRemoteClass(address));

+24 −2
Original line number Diff line number Diff line
@@ -427,6 +427,18 @@ public class BluetoothService extends IBluetooth.Stub {
                new ArrayList<String>(Arrays.asList(
                        "Motorola IHF1000", "i.TechBlueBAND", "X5 Stereo v1.3"));

        // If this is an outgoing connection, store the address.
        // There can be only 1 pending outgoing connection at a time,
        private String mPendingOutgoingBonding;

        private synchronized void setPendingOutgoingBonding(String address) {
            mPendingOutgoingBonding = address;
        }

        public synchronized String getPendingOutgoingBonding() {
            return mPendingOutgoingBonding;
        }

        public synchronized void loadBondState() {
            if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) {
                return;
@@ -457,6 +469,15 @@ public class BluetoothService extends IBluetooth.Stub {
            if (oldState == state) {
                return;
            }

            // Check if this was an pending outgoing bonding.
            // If yes, reset the state.
            if (oldState == BluetoothDevice.BOND_BONDING) {
                if (address.equals(mPendingOutgoingBonding)) {
                    mPendingOutgoingBonding = null;
                }
            }

            if (DBG) log(address + " bond state " + oldState + " -> " + state + " (" +
                         reason + ")");
            Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
@@ -779,8 +800,7 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        address = address.toUpperCase();

        String[] bonding = mBondState.listInState(BluetoothDevice.BOND_BONDING);
        if (bonding.length > 0 && !bonding[0].equals(address)) {
        if (mBondState.getPendingOutgoingBonding() != null) {
            log("Ignoring createBond(): another device is bonding");
            // a different device is currently bonding, fail
            return false;
@@ -798,7 +818,9 @@ public class BluetoothService extends IBluetooth.Stub {
            return false;
        }

        mBondState.setPendingOutgoingBonding(address);
        mBondState.setBondState(address, BluetoothDevice.BOND_BONDING);

        return true;
    }