OSDN Git Service

AVRCP: fix crash on callback with no player
authorMarie Janssen <jamuraa@google.com>
Fri, 28 Apr 2017 01:53:43 +0000 (18:53 -0700)
committerMarie Janssen <jamuraa@google.com>
Mon, 1 May 2017 22:11:22 +0000 (15:11 -0700)
If MediaSessionService tells us there's no place for keys to go, then we
have no player.

Test: disable com.google.music, reboot
Change-Id: I2adf884f9db991975cd0ae72abf2238ce323c517
Fixes: 37681487
(cherry picked from commit 41527b2493a4ea59933c7cd4f8d1c761598509d8)

src/com/android/bluetooth/avrcp/Avrcp.java

index f589026..aa25f8b 100644 (file)
@@ -1581,8 +1581,11 @@ public final class Avrcp {
 
     private void setAddressedMediaSessionPackage(String packageName) {
         if (DEBUG) Log.v(TAG, "Setting addressed media session to " + packageName);
-        // Can't set no player, that handled by onActiveSessionsChanged
-        if (packageName == null) return;
+        if (packageName == null) {
+            // Should only happen when there's no media players, reset to no available player.
+            updateCurrentController(0, mCurrBrowsePlayerID);
+            return;
+        }
         // No change.
         if (getPackageName(mCurrAddrPlayerID).equals(packageName)) return;
         // If the player doesn't exist, we need to add it.
@@ -2653,8 +2656,12 @@ public final class Avrcp {
 
                 @Override
                 public void onAddressedPlayerChanged(ComponentName receiver) {
-                    // We only get this if there isn't an active media session.
-                    // We can still get a passthrough.
+                    if (receiver == null) {
+                        // No active sessions, and no session to revive, give up.
+                        setAddressedMediaSessionPackage(null);
+                        return;
+                    }
+                    // We can still get a passthrough which will revive this player.
                     setAddressedMediaSessionPackage(receiver.getPackageName());
                 }
             };