Merge "Fix media_session shell commands" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-14 12:56:48 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 6 deletions

View File

@@ -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

View File

@@ -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) {
}
}