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

Commit 67e2196d authored by RoboErik's avatar RoboErik Committed by Android (Google) Code Review
Browse files

Merge "Add dump to MediaSessionService"

parents 4a261643 a278ea7c
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.media.session.SessionInfo;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.PrintWriter;

/**
 * A request to connect or discover routes with certain capabilities.
 * <p>
@@ -69,6 +71,17 @@ public final class RouteRequest implements Parcelable {
        return mOptions;
    }

    @Override
    public String toString() {
        StringBuilder bob = new StringBuilder();
        bob.append("RouteRequest {");
        bob.append("active=").append(mActive);
        bob.append(", info=").append(mSessionInfo.toString());
        bob.append(", options=").append(mOptions.toString());
        bob.append("}");
        return bob.toString();
    }

    @Override
    public int describeContents() {
        return 0;
+5 −0
Original line number Diff line number Diff line
@@ -56,6 +56,11 @@ public final class SessionInfo implements Parcelable {
        return mId;
    }

    @Override
    public String toString() {
        return "SessionInfo {id=" + mId + ", pkg=" + mPackageName + "}";
    }

    @Override
    public int describeContents() {
        return 0;
+22 −7
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.UserHandle;
import android.util.Log;
import android.util.Slog;

import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
@@ -55,13 +56,12 @@ public class MediaRouteProviderProxy {
    private final String mId;
    private final ComponentName mComponentName;
    private final int mUserId;

    private Intent mBindIntent;
    // Interfaces declared in the manifest
    private ArrayList<String> mInterfaces;
    private ArrayList<RouteConnectionRecord> mConnections = new ArrayList<RouteConnectionRecord>();
    private Handler mHandler = new Handler();
    private final ArrayList<String> mInterfaces = new ArrayList<String>();
    private final ArrayList<RouteConnectionRecord> mConnections = new ArrayList<RouteConnectionRecord>();
    private final Handler mHandler = new Handler();

    private Intent mBindIntent;
    private IRouteProvider mBinder;
    private boolean mRunning;
    private boolean mInterested;
@@ -76,7 +76,9 @@ public class MediaRouteProviderProxy {
        mId = id;
        mComponentName = component;
        mUserId = uid;
        mInterfaces = interfaces;
        if (interfaces != null) {
            mInterfaces.addAll(interfaces);
        }
        mBindIntent = new Intent(RouteProviderService.SERVICE_INTERFACE);
        mBindIntent.setComponent(mComponentName);
    }
@@ -202,7 +204,7 @@ public class MediaRouteProviderProxy {

                    if (connection != null) {
                        RouteConnectionRecord record = new RouteConnectionRecord(
                                connection);
                                connection, mComponentName.getPackageName(), mUserId);
                        mConnections.add(record);
                        if (mRouteListener != null) {
                            mRouteListener.onRouteConnected(sessionId, route, request, record);
@@ -234,6 +236,19 @@ public class MediaRouteProviderProxy {
        return mId;
    }

    public void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + mId + " " + this);
        String indent = prefix + "  ";

        pw.println(indent + "component=" + mComponentName.toString());
        pw.println(indent + "user id=" + mUserId);
        pw.println(indent + "interfaces=" + mInterfaces.toString());
        pw.println(indent + "connections=" + mConnections.toString());
        pw.println(indent + "running=" + mRunning);
        pw.println(indent + "interested=" + mInterested);
        pw.println(indent + "bound=" + mBound);
    }

    private void updateBinding() {
        if (shouldBind()) {
            bind();
+22 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.util.Pair;
import android.util.Slog;
import android.view.KeyEvent;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -226,6 +227,27 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
        mService.sessionDied(this);
    }

    public void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + mTag + " " + this);

        final String indent = prefix + "  ";
        pw.println(indent + "pid=" + mPid);
        pw.println(indent + "info=" + mSessionInfo.toString());
        pw.println(indent + "published=" + mIsPublished);
        pw.println(indent + "transport controls enabled=" + mTransportPerformerEnabled);
        pw.println(indent + "rating type=" + mRatingType);
        pw.println(indent + "controllers: " + mControllerCallbacks.size());
        pw.println(indent + "route requests {");
        int size = mRequests.size();
        for (int i = 0; i < size; i++) {
            pw.println(indent + "  " + mRequests.get(i).toString());
        }
        pw.println(indent + "}");
        pw.println(indent + "route=" + (mRoute == null ? null : mRoute.toString()));
        pw.println(indent + "connection=" + (mConnection == null ? null : mConnection.toString()));
        pw.println(indent + "params=" + (mRequest == null ? null : mRequest.toString()));
    }

    private void onDestroy() {
        mService.destroySession(this);
    }
+48 −6
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.server.media;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.routeprovider.RouteRequest;
import android.media.session.ISession;
import android.media.session.ISessionCallback;
@@ -30,13 +32,17 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.server.SystemService;
import com.android.server.Watchdog;
import com.android.server.Watchdog.Monitor;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * System implementation of MediaSessionManager
 */
public class MediaSessionService extends SystemService {
public class MediaSessionService extends SystemService implements Monitor {
    private static final String TAG = "MediaSessionService";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

@@ -69,6 +75,7 @@ public class MediaSessionService extends SystemService {
    public void onStart() {
        publishBinderService(Context.MEDIA_SESSION_SERVICE, mSessionManagerImpl);
        mRouteProviderWatcher.start();
        Watchdog.getInstance().addMonitor(this);
    }

    /**
@@ -114,14 +121,21 @@ public class MediaSessionService extends SystemService {
        }
    }

    @Override
    public void monitor() {
        synchronized (mLock) {
            // Check for deadlock
        }
    }

    void sessionDied(MediaSessionRecord session) {
        synchronized (mSessions) {
        synchronized (mLock) {
            destroySessionLocked(session);
        }
    }

    void destroySession(MediaSessionRecord session) {
        synchronized (mSessions) {
        synchronized (mLock) {
            destroySessionLocked(session);
        }
    }
@@ -160,9 +174,7 @@ public class MediaSessionService extends SystemService {
        } catch (RemoteException e) {
            throw new RuntimeException("Media Session owner died prematurely.", e);
        }
        synchronized (mSessions) {
        mSessions.add(session);
        }
        if (DEBUG) {
            Log.d(TAG, "Created session for package " + packageName + " with tag " + tag);
        }
@@ -259,6 +271,36 @@ public class MediaSessionService extends SystemService {
                Binder.restoreCallingIdentity(token);
            }
        }

        @Override
        public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
            if (getContext().checkCallingOrSelfPermission(Manifest.permission.DUMP)
                    != PackageManager.PERMISSION_GRANTED) {
                pw.println("Permission Denial: can't dump MediaSessionService from from pid="
                        + Binder.getCallingPid()
                        + ", uid=" + Binder.getCallingUid());
                return;
            }

            pw.println("MEDIA SESSION SERVICE (dumpsys media_session)");
            pw.println();

            synchronized (mLock) {
                int count = mSessions.size();
                pw.println("Sessions - have " + count + " states:");
                for (int i = 0; i < count; i++) {
                    MediaSessionRecord record = mSessions.get(i);
                    pw.println();
                    record.dump(pw, "");
                }
                pw.println("Providers:");
                count = mProviders.size();
                for (int i = 0; i < count; i++) {
                    MediaRouteProviderProxy provider = mProviders.get(i);
                    provider.dump(pw, "");
                }
            }
        }
    }

}
Loading