A2DP MediaSession active state management and NPE
UIs (such as SystemUI) depend on MediaSession.isActive state to
determine whether to show it on the overview (or shades). Currently we
are keeping the session active ever since the first bluetooth connect (A2DP) happens.
This change makes the session to be active when the device connects and
the first play happens (i.e. the play state of remote device
irrespective of who initated it) and in-active when device disconnects.
Also, avoid a NPE that may happen due to races between delay in
broadcasts and accesing bluetooth state machine.
Bug: b/
28345602
Bug: b/
28330860
Change-Id: Id7686308ada0b608b959258d137772ee5f24c18f
(cherry picked from commit
faa30bec93650414fb90b60b5a488b32dd54b9ac)