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

Commit be92bfa6 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Do not bind to media players for wear os"

parents 64c8d258 82ad7a23
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();
            });
    }