Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c04dd89f authored by Marie Janssen's avatar Marie Janssen
Browse files

AVRCP: use only one MediaController from a package

Some players have more than one active MediaController for some reason,
and onActiveSessionsChanged returns them both.  In this case, the first
one in the list should be considered the "active" one for that player.

Test: use com.zentertain.music.player and see metadata propogate
Bug: 63058319
Change-Id: I4e72182b36642b84835275b0ded9648a38bde78b
parent 528cd807
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -57,9 +57,11 @@ import com.android.bluetooth.Utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

@@ -1582,9 +1584,15 @@ public final class Avrcp {
                @Override
                public void onActiveSessionsChanged(
                        List<android.media.session.MediaController> newControllers) {
                    Set<String> updatedPackages = new HashSet<String>();
                    // Update the current players
                    for (android.media.session.MediaController controller : newControllers) {
                        String packageName = controller.getPackageName();
                        if (DEBUG) Log.v(TAG, "ActiveSession: " + MediaController.wrap(controller));
                        // Only use the first (highest priority) controller from each package
                        if (updatedPackages.contains(packageName)) continue;
                        addMediaPlayerController(controller);
                        updatedPackages.add(packageName);
                    }

                    if (newControllers.size() > 0 && getAddressedPlayerInfo() == null) {