Merge "Fix media_session shell commands" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
63104b024e
@@ -1179,8 +1179,15 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
@Override
|
@Override
|
||||||
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
|
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
|
||||||
String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
|
String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
|
||||||
(new MediaShellCommand()).exec(this, in, out, err, args, callback,
|
String[] packageNames =
|
||||||
resultReceiver);
|
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
|
@Override
|
||||||
|
|||||||
@@ -47,15 +47,19 @@ import java.util.List;
|
|||||||
* ShellCommand for MediaSessionService.
|
* ShellCommand for MediaSessionService.
|
||||||
*/
|
*/
|
||||||
public class MediaShellCommand extends ShellCommand {
|
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 ActivityThread sThread;
|
||||||
private static MediaSessionManager sMediaSessionManager;
|
private static MediaSessionManager sMediaSessionManager;
|
||||||
|
|
||||||
|
private final String mPackageName;
|
||||||
private ISessionManager mSessionService;
|
private ISessionManager mSessionService;
|
||||||
private PrintWriter mWriter;
|
private PrintWriter mWriter;
|
||||||
private PrintWriter mErrorWriter;
|
private PrintWriter mErrorWriter;
|
||||||
private InputStream mInput;
|
private InputStream mInput;
|
||||||
|
|
||||||
|
public MediaShellCommand(String packageName) {
|
||||||
|
mPackageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onCommand(String cmd) {
|
public int onCommand(String cmd) {
|
||||||
mWriter = getOutPrintWriter();
|
mWriter = getOutPrintWriter();
|
||||||
@@ -110,7 +114,7 @@ public class MediaShellCommand extends ShellCommand {
|
|||||||
mWriter.println();
|
mWriter.println();
|
||||||
mWriter.println("media_session dispatch: dispatch a media key to the system.");
|
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(" 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 list-sessions: print a list of the current sessions.");
|
||||||
mWriter.println("media_session monitor: monitor updates to the specified session.");
|
mWriter.println("media_session monitor: monitor updates to the specified session.");
|
||||||
mWriter.println(" Use the tag from list-sessions.");
|
mWriter.println(" Use the tag from list-sessions.");
|
||||||
@@ -120,7 +124,8 @@ public class MediaShellCommand extends ShellCommand {
|
|||||||
|
|
||||||
private void sendMediaKey(KeyEvent event) {
|
private void sendMediaKey(KeyEvent event) {
|
||||||
try {
|
try {
|
||||||
mSessionService.dispatchMediaKeyEvent(PACKAGE_NAME, false, event, false);
|
mSessionService.dispatchMediaKeyEvent(
|
||||||
|
mPackageName, /* asSystemService= */ false, event, /* needWakeLock= */ false);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user