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

Commit 82ad7a23 authored by William Escande's avatar William Escande
Browse files

Do not bind to media players for wear os

Disable BrowsablePlayerConnector here as:
1. Not a regular use case of Wear OS
2. Registering to all players is a very loading task for watches

Bug: 263323082
Bug: 186059821
Test: play/pause music from a BT headset
(cherry picked from commit 8e59adf1c0a19871b27a1df4eb798e0bd8178c4e)
Change-Id: Id8b0e393bef7ae64f3abb4cf52b7aeb684266739
parent 6cd9a9b2
Loading
Loading
Loading
Loading
+37 −21
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -145,10 +146,45 @@ public class MediaPlayerList {
                mContext.getMainExecutor(), mMediaKeyEventSessionChangedListener);
    }

    private void constructCurrentPlayers() {
        // Construct the list of current players
        d("Initializing list of current media players");
        List<android.media.session.MediaController> controllers =
                mMediaSessionManager.getActiveSessions(null);

        for (android.media.session.MediaController controller : controllers) {
            addMediaPlayer(controller);
        }

        // If there were any active players and we don't already have one due to the Media
        // Framework Callbacks then set the highest priority one to active
        if (mActivePlayerId == 0 && mMediaPlayers.size() > 0) {
            String packageName = mMediaSessionManager.getMediaKeyEventSessionPackageName();
            if (!TextUtils.isEmpty(packageName) && haveMediaPlayer(packageName)) {
                Log.i(TAG, "Set active player to MediaKeyEvent session = " + packageName);
                setActivePlayer(mMediaPlayerIds.get(packageName));
            } else {
                Log.i(TAG, "Set active player to first default");
                setActivePlayer(1);
            }
        }
    }

    public void init(MediaUpdateCallback callback) {
        Log.v(TAG, "Initializing MediaPlayerList");
        mCallback = callback;

        if (!SystemProperties.getBoolean("bluetooth.avrcp.browsable_media_player.enabled", true)) {
            // Allow to disable BrowsablePlayerConnector with systemproperties.
            // This is useful when for watches because:
            //   1. It is not a regular use case
            //   2. Registering to all players is a very loading task

            Log.i(TAG, "init: without Browsable Player");
            constructCurrentPlayers();
            return;
        }

        // Build the list of browsable players and afterwards, build the list of media players
        Intent intent = new Intent(android.service.media.MediaBrowserService.SERVICE_INTERFACE);
        List<ResolveInfo> playerList =
@@ -184,27 +220,7 @@ public class MediaPlayerList {
                            });
                }

                // Construct the list of current players
                d("Initializing list of current media players");
                List<android.media.session.MediaController> controllers =
                        mMediaSessionManager.getActiveSessions(null);

                for (android.media.session.MediaController controller : controllers) {
                    addMediaPlayer(controller);
                }

                // If there were any active players and we don't already have one due to the Media
                // Framework Callbacks then set the highest priority one to active
                if (mActivePlayerId == 0 && mMediaPlayers.size() > 0) {
                    String packageName = mMediaSessionManager.getMediaKeyEventSessionPackageName();
                    if (!TextUtils.isEmpty(packageName) && haveMediaPlayer(packageName)) {
                        Log.i(TAG, "Set active player to MediaKeyEvent session = " + packageName);
                        setActivePlayer(mMediaPlayerIds.get(packageName));
                    } else {
                        Log.i(TAG, "Set active player to first default");
                        setActivePlayer(1);
                    }
                }
                constructCurrentPlayers();
            });
    }