AVRCP: Check mMediaSessionManager is not null before handling callback

While the Bluetooth is turning off and MediaPlayerList is cleaned up,
handling the unexpected onAddressedPlayerChanged() callback from the
MediaSessionManager causes the NPE. This NPE happens at
getActivePlayer().unregisterCallback() in the setActivePlayer() function
due to the return value of getActivePlayer() will be null.

Before handling the onAddressedPlayerChanged() callback, add a check of
mMediaSessionManager is not cleaned up to fix this issue.

Bug: 135727092
Test: make, tune the timing of cleaning up MediaPlayerList to hit this
issue, perform Airplane mode on/off and AVRCP related tests.

Change-Id: I7ef66d1977a6e31c989e2d1ec4a87ca8144b3778
diff --git a/src/com/android/bluetooth/avrcp/MediaPlayerList.java b/src/com/android/bluetooth/avrcp/MediaPlayerList.java
index 10d99bf..29f4cf9 100644
--- a/src/com/android/bluetooth/avrcp/MediaPlayerList.java
+++ b/src/com/android/bluetooth/avrcp/MediaPlayerList.java
@@ -626,6 +626,12 @@
                     android.media.session.MediaController controller =
                             new android.media.session.MediaController(mContext, token);
 
+                    if (mMediaSessionManager == null) {
+                        Log.w(TAG, "onAddressedPlayerChanged(Token): Unexpected callback "
+                                + "from the MediaSessionManager");
+                        return;
+                    }
+
                     if (!mMediaPlayerIds.containsKey(controller.getPackageName())) {
                         // Since we have a controller, we can try to to recover by adding the
                         // player and then setting it as active.
@@ -640,6 +646,12 @@
 
                 @Override
                 public void onAddressedPlayerChanged(ComponentName receiver) {
+                    if (mMediaSessionManager == null) {
+                        Log.w(TAG, "onAddressedPlayerChanged(Component): Unexpected callback "
+                                + "from the MediaSessionManager");
+                        return;
+                    }
+
                     if (receiver == null) {
                         return;
                     }