PBAP: HandlerThread is terminated before all tasks are completed

Usecase:
1) Establish PBAP Connection.
2) Turn Off Bluetooth.

Issue:
Tasks of Handler thread like closeService() are not
completed on BT OFF. Like Bluetooth PBAP profile state
(DISCONNECTED) is not broadcasted on BT OFF.

Reproducible Rate: 100%.

Root Cause:
HandlerThread associated with PbapHandler is terminated using
quitSafely() which causes subsequent tasks not getting handled.
As PbapStateMachine uses same HandlerThread, DISCONNECT message
sent in closeService() is not handled and thus profile state is
not broadcasted.
This bug is introduced in P through  MultiPbap commit
a08d7327b23d2c2192c2ab9f010d6f494c11699b.

Fix:
Terminate HandlerThread in closeService() once all messages of
Handler are processed and PBAP Connection state is broadcasted
from PbapStateMachine.

Test: Sanity testing with BT on/off is done.
Change-Id: I04e6a40836d78f8113b906994fb78dc64748d710
CRs-Fixed: 2350747
1 file changed