Mediapublic class Media extends com.android.internal.os.BaseCommand
Fields Summary |
---|
private android.media.session.ISessionManager | mSessionService |
Methods Summary |
---|
public static void | main(java.lang.String[] args)Command-line entry point.
(new Media()).run(args);
| public void | onRun()
mSessionService = ISessionManager.Stub.asInterface(ServiceManager.checkService(
Context.MEDIA_SESSION_SERVICE));
if (mSessionService == null) {
System.err.println(NO_SYSTEM_ERROR_CODE);
throw new AndroidException(
"Can't connect to media session service; is the system running?");
}
String op = nextArgRequired();
if (op.equals("dispatch")) {
runDispatch();
} else if (op.equals("list-sessions")) {
runListSessions();
} else if (op.equals("monitor")) {
runMonitor();
} else {
showError("Error: unknown command '" + op + "'");
return;
}
| public void | onShowUsage(java.io.PrintStream out)
out.println(
"usage: media [subcommand] [options]\n" +
" media dispatch KEY\n" +
" media list-sessions\n" +
" media monitor <tag>\n" +
"\n" +
"media dispatch: dispatch a media key to the system.\n" +
" KEY may be: play, pause, play-pause, mute, headsethook,\n" +
" stop, next, previous, rewind, record, fast-forword.\n" +
"media list-sessions: print a list of the current sessions.\n" +
"media monitor: monitor updates to the specified session.\n" +
" Use the tag from list-sessions.\n"
);
| private void | runDispatch()
String cmd = nextArgRequired();
int keycode;
if ("play".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_PLAY;
} else if ("pause".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_PAUSE;
} else if ("play-pause".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
} else if ("mute".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MUTE;
} else if ("headsethook".equals(cmd)) {
keycode = KeyEvent.KEYCODE_HEADSETHOOK;
} else if ("stop".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_STOP;
} else if ("next".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_NEXT;
} else if ("previous".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
} else if ("rewind".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_REWIND;
} else if ("record".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_RECORD;
} else if ("fast-forward".equals(cmd)) {
keycode = KeyEvent.KEYCODE_MEDIA_FAST_FORWARD;
} else {
showError("Error: unknown dispatch code '" + cmd + "'");
return;
}
final long now = SystemClock.uptimeMillis();
sendMediaKey(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keycode, 0, 0,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
sendMediaKey(new KeyEvent(now, now, KeyEvent.ACTION_UP, keycode, 0, 0,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
| private void | runListSessions()
System.out.println("Sessions:");
try {
List<IBinder> sessions = mSessionService
.getSessions(null, ActivityManager.getCurrentUser());
for (IBinder session : sessions) {
ISessionController controller = ISessionController.Stub.asInterface(session);
if (controller != null) {
try {
System.out.println(" tag=" + controller.getTag()
+ ", package=" + controller.getPackageName());
} catch (RemoteException e) {
// ignore
}
}
}
} catch (Exception e) {
System.out.println("***Error listing sessions***");
}
| private void | runMonitor()
String id = nextArgRequired();
if (id == null) {
showError("Error: must include a session id");
return;
}
boolean success = false;
try {
List<IBinder> sessions = mSessionService
.getSessions(null, ActivityManager.getCurrentUser());
for (IBinder session : sessions) {
ISessionController controller = ISessionController.Stub.asInterface(session);
try {
if (controller != null && id.equals(controller.getTag())) {
ControllerMonitor monitor = new ControllerMonitor(controller);
monitor.run();
success = true;
break;
}
} catch (RemoteException e) {
// ignore
}
}
} catch (Exception e) {
System.out.println("***Error monitoring session*** " + e.getMessage());
}
if (!success) {
System.out.println("No session found with id " + id);
}
| private void | sendMediaKey(android.view.KeyEvent event)
try {
mSessionService.dispatchMediaKeyEvent(event, false);
} catch (RemoteException e) {
}
|
|