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

Commit b08a6f51 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix media_session shell commands" into tm-dev am: 63104b02

parents 6b4f3a74 63104b02
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1179,8 +1179,15 @@ public class MediaSessionService extends SystemService implements Monitor {
        @Override
        public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
                String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
            (new MediaShellCommand()).exec(this, in, out, err, args, callback,
                    resultReceiver);
            String[] packageNames =
                    mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
            String packageName = packageNames != null && packageNames.length > 0
                    ? packageNames[0]
                    : "com.android.shell"; // We should not need this branch, but defaulting to the
                                           // current shell package name for robustness. See
                                           // b/227109905.
            new MediaShellCommand(packageName)
                    .exec(this, in, out, err, args, callback, resultReceiver);
        }

        @Override
+9 −4
Original line number Diff line number Diff line
@@ -47,15 +47,19 @@ import java.util.List;
 * ShellCommand for MediaSessionService.
 */
public class MediaShellCommand extends ShellCommand {
    // This doesn't belongs to any package. Setting the package name to empty string.
    private static final String PACKAGE_NAME = "";
    private static ActivityThread sThread;
    private static MediaSessionManager sMediaSessionManager;

    private final String mPackageName;
    private ISessionManager mSessionService;
    private PrintWriter mWriter;
    private PrintWriter mErrorWriter;
    private InputStream mInput;

    public MediaShellCommand(String packageName) {
        mPackageName = packageName;
    }

    @Override
    public int onCommand(String cmd) {
        mWriter = getOutPrintWriter();
@@ -110,7 +114,7 @@ public class MediaShellCommand extends ShellCommand {
        mWriter.println();
        mWriter.println("media_session dispatch: dispatch a media key to the system.");
        mWriter.println("                KEY may be: play, pause, play-pause, mute, headsethook,");
        mWriter.println("                stop, next, previous, rewind, record, fast-forword.");
        mWriter.println("                stop, next, previous, rewind, record, fast-forward.");
        mWriter.println("media_session list-sessions: print a list of the current sessions.");
        mWriter.println("media_session monitor: monitor updates to the specified session.");
        mWriter.println("                       Use the tag from list-sessions.");
@@ -120,7 +124,8 @@ public class MediaShellCommand extends ShellCommand {

    private void sendMediaKey(KeyEvent event) {
        try {
            mSessionService.dispatchMediaKeyEvent(PACKAGE_NAME, false, event, false);
            mSessionService.dispatchMediaKeyEvent(
                    mPackageName, /* asSystemService= */ false, event, /* needWakeLock= */ false);
        } catch (RemoteException e) {
        }
    }