BondStateMachine: avoid adding device to mDevices
Currently, BondStateMachine will add the device to mDevices list if the device is not found in that list when the bond state is changed to BOND_NONE or BOND_BONDED. Since the action for a device in mDevices may get deferred based on its type, this may cause some problems: Suppose two devices (A and B) has already been paired, and consider the following sequence: 1. removeBond() on A is called, and then the state machine will transit into PendingCommandState, and A will not be added into mDevices according to the current logic. 2. removeBond() on B is called, and then it will be added into mDevices. 3. The event about the bond state of A changed to BOND_NONE comes, since A is not in mDevices, it will be added to the list. 4. The event about the bond state of B changed to BOND_NONE comes, B will be removed from mDevices, and the state machine will not go back to StableState since mDevices is not empty now. Two problems may happen at the end of this example: a) The state machine is leaving in PendingCommandState, while there are no devices are in bonding/unbonding state; b) The further createBond() requests will be deferred since A is still in mDevices list. The only usage of mDevices is to avoid sending some commands when the device is performing another action. It does not make sense that the event of the state of a device changed to BOND_BONDED or BOND_NONE could add this device into the list. Also added a unit test for the above scenario. Test: the new added unit test passed, and it will fail without this patch. Test: atest BondStateMachineTest Change-Id: I41f5eeb101a88e9afb45c1760b017363d0a08814
Loading
Please register or sign in to comment