summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2014-07-25 16:00:52 -0700
committerRoboErik <epastern@google.com>2014-07-28 11:02:15 -0700
commit031149cd5f22bd858142633c7a763450f42793f7 (patch)
tree2a405fc0c7cae702e5d85eeb3979d560f6caca99 /cmds
parentaa4e23bbb36994708ba72c5f4c83255025d99e07 (diff)
downloadframeworks_base-031149cd5f22bd858142633c7a763450f42793f7.zip
frameworks_base-031149cd5f22bd858142633c7a763450f42793f7.tar.gz
frameworks_base-031149cd5f22bd858142633c7a763450f42793f7.tar.bz2
Add context to MediaController constructor
This also adds a convenience method to MediaSession to allow getting a controller instead of having to create and cache your own. bug:16561220 Change-Id: I87f551a7474e71f1cf2f07e0e541c3a4515cd977
Diffstat (limited to 'cmds')
-rw-r--r--cmds/media/src/com/android/commands/media/Media.java77
1 files changed, 57 insertions, 20 deletions
diff --git a/cmds/media/src/com/android/commands/media/Media.java b/cmds/media/src/com/android/commands/media/Media.java
index cb9b493..7757b91 100644
--- a/cmds/media/src/com/android/commands/media/Media.java
+++ b/cmds/media/src/com/android/commands/media/Media.java
@@ -19,10 +19,13 @@ package com.android.commands.media;
import android.app.ActivityManager;
import android.content.Context;
+import android.content.pm.ParceledListSlice;
import android.media.MediaMetadata;
import android.media.session.ISessionController;
+import android.media.session.ISessionControllerCallback;
import android.media.session.ISessionManager;
import android.media.session.MediaController;
+import android.media.session.ParcelableVolumeInfo;
import android.media.session.PlaybackState;
import android.os.Bundle;
import android.os.HandlerThread;
@@ -112,13 +115,16 @@ public class Media extends BaseCommand {
List<IBinder> sessions = mSessionService
.getSessions(null, ActivityManager.getCurrentUser());
for (IBinder session : sessions) {
- MediaController controller = new MediaController(ISessionController.Stub
- .asInterface(session));
- if (controller != null && id.equals(controller.getTag())) {
- ControllerMonitor monitor = new ControllerMonitor(controller);
- monitor.run();
- success = true;
- break;
+ 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) {
@@ -166,14 +172,14 @@ public class Media extends BaseCommand {
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
}
- class ControllerMonitor extends MediaController.Callback {
- private final MediaController mController;
+ class ControllerMonitor extends ISessionControllerCallback.Stub {
+ private final ISessionController mController;
- public ControllerMonitor(MediaController controller) {
+ public ControllerMonitor(ISessionController controller) {
mController = controller;
}
@Override
- public void onSessionEvent(String event, Bundle extras) {
+ public void onEvent(String event, Bundle extras) {
System.out.println("onSessionEvent event=" + event + ", extras=" + extras);
}
@@ -189,9 +195,33 @@ public class Media extends BaseCommand {
System.out.println("onMetadataChanged " + mmString);
}
+ @Override
+ public void onQueueChanged(ParceledListSlice queue) throws RemoteException {
+ System.out.println("onQueueChanged, size=" + queue.getList().size());
+ }
+
+ @Override
+ public void onQueueTitleChanged(CharSequence title) throws RemoteException {
+ System.out.println("onQueueTitleChange " + title);
+ }
+
+ @Override
+ public void onExtrasChanged(Bundle extras) throws RemoteException {
+ System.out.println("onExtrasChanged " + extras);
+ }
+
+ @Override
+ public void onVolumeInfoChanged(ParcelableVolumeInfo info) throws RemoteException {
+ System.out.println("onVolumeInfoChanged " + info);
+ }
+
void printUsageMessage() {
- System.out.println("V2Monitoring session " + mController.getTag()
- + "... available commands:");
+ try {
+ System.out.println("V2Monitoring session " + mController.getTag()
+ + "... available commands:");
+ } catch (RemoteException e) {
+ System.out.println("Error trying to monitor session!");
+ }
System.out.println("(q)uit: finish monitoring");
}
@@ -200,7 +230,11 @@ public class Media extends BaseCommand {
HandlerThread cbThread = new HandlerThread("MediaCb") {
@Override
protected void onLooperPrepared() {
- mController.addCallback(ControllerMonitor.this);
+ try {
+ mController.registerCallbackListener(ControllerMonitor.this);
+ } catch (RemoteException e) {
+ System.out.println("Error registering monitor callback");
+ }
}
};
cbThread.start();
@@ -232,7 +266,7 @@ public class Media extends BaseCommand {
} finally {
cbThread.getLooper().quit();
try {
- mController.removeCallback(this);
+ mController.unregisterCallbackListener(this);
} catch (Exception e) {
// ignoring
}
@@ -246,12 +280,15 @@ public class Media extends BaseCommand {
List<IBinder> sessions = mSessionService
.getSessions(null, ActivityManager.getCurrentUser());
for (IBinder session : sessions) {
- MediaController controller = new MediaController(ISessionController.Stub
- .asInterface(session));
+
+ ISessionController controller = ISessionController.Stub.asInterface(session);
if (controller != null) {
- String pkg = controller.getPackageName();
- System.out.println(" tag=" + controller.getTag()
- + ", package=" + pkg);
+ try {
+ System.out.println(" tag=" + controller.getTag()
+ + ", package=" + controller.getPackageName());
+ } catch (RemoteException e) {
+ // ignore
+ }
}
}
} catch (Exception e) {