HFP: Only remove state machine when device is unbonded and disconnected
SUMMARY: * Remove a state machine only when a device is both unbonded and disconnected * Add HeadsetServiceAndStateMachineTest to verify this behavior * Reject API connect() attempt when device does not have headset UUIDs DETAILS: * A state machine is no longer useful if the associated device is no longer bonded. However, sometimes the device may get disconnected after it is unbonded. Therefore, we should only remove a state machine when the device is both unbonded and disconnected. * Also, we should only allow an HeadsetService.connect() API call when there is at least one headset UUID present. * HeadsetServiceAndStateMachineTest is added to integerate both HeadsetService and HeadsetStateMachine to complete a set of semi-integration tests. This new set of tests allows us to verify whether a connect() API call will eventually trigger a connectHfp() to the native interface, utilizing all logic in the middle. * However, we do need to assume certain timing condition in such semi-integration test. 250ms is set as a limit for any state machine based message handling, which should be enough for most modern day Android devices. * We have to use AdapterService instead of BluetoothDevice to get bond state, device name, and so on since we want to be able to mock these methods and BluetoothDevice class is final. * Thus, this CL also adds a new parameter to HeadsetStateMachine during construction so that it has a reference to AdapterService suppplied through its constructor. This is to make sure that entire HFP stack uses the same reference of AdapterService obtained by HeadsetService. Bug: 72529611 Test: disconnect and then quickly unpair device Change-Id: I49ec70d60e257ffd4484e536bdb66d6da7b3b377
Loading
Please register or sign in to comment