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

Commit adb27e22 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Automerger Merge Worker
Browse files

Merge "BondStateMachine: Handle UUID_UPDATE in PendingCommandState" am:...

Merge "BondStateMachine: Handle UUID_UPDATE in PendingCommandState" am: 808a2d86 am: 47277383 am: bed5bfcd

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2031763



Change-Id: I18821f59218970fdb1596536fdefc974b316fb4e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4516bc97 bed5bfcd
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -180,7 +180,6 @@ final class BondStateMachine extends StateMachine {
        }
    }


    private class PendingCommandState extends State {
        private final ArrayList<BluetoothDevice> mDevices = new ArrayList<BluetoothDevice>();

@@ -195,9 +194,9 @@ final class BondStateMachine extends StateMachine {

            DeviceProperties devProp = mRemoteDevices.getDeviceProperties(dev);
            boolean result = false;
            if (mDevices.contains(dev) && msg.what != CANCEL_BOND
                    && msg.what != BONDING_STATE_CHANGE && msg.what != SSP_REQUEST
                    && msg.what != PIN_REQUEST) {
            if ((mDevices.contains(dev) || mPendingBondedDevices.contains(dev))
                    && msg.what != CANCEL_BOND && msg.what != BONDING_STATE_CHANGE
                    && msg.what != SSP_REQUEST && msg.what != PIN_REQUEST) {
                deferMessage(msg);
                return true;
            }
@@ -279,7 +278,6 @@ final class BondStateMachine extends StateMachine {
                        sendDisplayPinIntent(devProp.getAddress(), 0,
                                BluetoothDevice.PAIRING_VARIANT_PIN);
                    }

                    break;
                default:
                    Log.e(TAG, "Received unhandled event:" + msg.what);
@@ -288,7 +286,6 @@ final class BondStateMachine extends StateMachine {
            if (result) {
                mDevices.add(dev);
            }

            return true;
        }
    }
@@ -317,7 +314,6 @@ final class BondStateMachine extends StateMachine {
                }
                return true;
            }

        }
        return false;
    }
+39 −0
Original line number Diff line number Diff line
@@ -140,6 +140,45 @@ public class BondStateMachineTest {
        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES_2), anyInt());
    }

    @Test
    public void testUuidUpdateWithPendingDevice() {
        mRemoteDevices.reset();
        mBondStateMachine.mPendingBondedDevices.clear();

        RemoteDevices.DeviceProperties pendingDeviceProperties =
                mRemoteDevices.addDeviceProperties(TEST_BT_ADDR_BYTES_2);
        BluetoothDevice pendingDevice = pendingDeviceProperties.getDevice();
        Assert.assertNotNull(pendingDevice);
        mBondStateMachine.sendIntent(pendingDevice, BOND_BONDED, TEST_BOND_REASON, false);

        RemoteDevices.DeviceProperties testDeviceProperties =
                mRemoteDevices.addDeviceProperties(TEST_BT_ADDR_BYTES);
        testDeviceProperties.mUuids = TEST_UUIDS;
        BluetoothDevice testDevice = testDeviceProperties.getDevice();
        Assert.assertNotNull(testDevice);

        Message bondingMsg = mBondStateMachine.obtainMessage(BondStateMachine.BONDING_STATE_CHANGE);
        bondingMsg.obj = testDevice;
        bondingMsg.arg1 = BOND_BONDING;
        bondingMsg.arg2 = AbstractionLayer.BT_STATUS_RMT_DEV_DOWN;
        mBondStateMachine.sendMessage(bondingMsg);

        pendingDeviceProperties.mUuids = TEST_UUIDS;
        Message uuidUpdateMsg = mBondStateMachine.obtainMessage(BondStateMachine.UUID_UPDATE);
        uuidUpdateMsg.obj = pendingDevice;

        mBondStateMachine.sendMessage(uuidUpdateMsg);

        Message bondedMsg = mBondStateMachine.obtainMessage(BondStateMachine.BONDING_STATE_CHANGE);
        bondedMsg.obj = testDevice;
        bondedMsg.arg1 = BOND_BONDED;
        bondedMsg.arg2 = AbstractionLayer.BT_STATUS_SUCCESS;
        mBondStateMachine.sendMessage(bondedMsg);

        TestUtils.waitForLooperToFinishScheduledTask(mBondStateMachine.getHandler().getLooper());
        Assert.assertTrue(mBondStateMachine.mPendingBondedDevices.isEmpty());
    }

    @Test
    public void testSendIntent() {
        int badBondState = 42;