HFP: Fix connection colision handling
* When there is a connection collison, and remote device is trying to
connect to HFP server channel while we try to connect to remote's
server channel as a client. If the remote device succssfully connect
to us, we should drop our connection request to remote device and
accept remote device's connection request. As result, we will observe
1. Our connection request fails, this propagate up to Java layer and
also clean up any states in these layers
2. Remote connection request succeeds, this propagate up to Java layer
as well as a new incoming connection
* Added BTA_AG_COLLISION_EVT to formally handle AG collision in state
machine
* Modified bta_ag_resume_open to re-send BTA_AG_API_OPEN_EVT instead of
modifying the state machine state directly. State machine states
should only be modified by state machine handler
* Ignore RFCOMM open event if PORT_CheckConnection fails
* Added StackRfcommTest.TestConnectionCollision to reproduce this
scenario with 100% certainty
* Add static checks to HFP BTA state machine to make sure action and
event indices match enum sizes
Bug:
77224743
Test: connect to multiple remote devices with HFP, MAP and PBAP
StackRfcommTest.TestConnectionCollision
btestplans/details/158641/3975
Change-Id: Ib3652784b123abe195e7bd30421ef5f4345b1d4d
Merged-In: Ib3652784b123abe195e7bd30421ef5f4345b1d4d
(cherry picked from commit
88cc85a086bf90e1e669fd689276c6e658286af2)