Loading android/app/src/com/android/bluetooth/btservice/BondStateMachine.java +3 −7 Original line number Diff line number Diff line Loading @@ -180,7 +180,6 @@ final class BondStateMachine extends StateMachine { } } private class PendingCommandState extends State { private final ArrayList<BluetoothDevice> mDevices = new ArrayList<BluetoothDevice>(); Loading @@ -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; } Loading Loading @@ -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); Loading @@ -288,7 +286,6 @@ final class BondStateMachine extends StateMachine { if (result) { mDevices.add(dev); } return true; } } Loading Loading @@ -317,7 +314,6 @@ final class BondStateMachine extends StateMachine { } return true; } } return false; } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading
android/app/src/com/android/bluetooth/btservice/BondStateMachine.java +3 −7 Original line number Diff line number Diff line Loading @@ -180,7 +180,6 @@ final class BondStateMachine extends StateMachine { } } private class PendingCommandState extends State { private final ArrayList<BluetoothDevice> mDevices = new ArrayList<BluetoothDevice>(); Loading @@ -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; } Loading Loading @@ -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); Loading @@ -288,7 +286,6 @@ final class BondStateMachine extends StateMachine { if (result) { mDevices.add(dev); } return true; } } Loading Loading @@ -317,7 +314,6 @@ final class BondStateMachine extends StateMachine { } return true; } } return false; } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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; Loading