summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2014-05-13 10:13:04 -0700
committerRoboErik <epastern@google.com>2014-05-14 13:19:48 -0700
commit4646d288821d62fdfe481be67d8b7fed7d7eabd8 (patch)
treeac21a45a6ad5829708056e375dd530f107224dd7 /media/java
parent515396a6b5ee3eab57fed87ee0f4aa63783e2e61 (diff)
downloadframeworks_base-4646d288821d62fdfe481be67d8b7fed7d7eabd8.zip
frameworks_base-4646d288821d62fdfe481be67d8b7fed7d7eabd8.tar.gz
frameworks_base-4646d288821d62fdfe481be67d8b7fed7d7eabd8.tar.bz2
Add UserRecords to separate user interactions
Each user record maintains the list of sessions and providers that are running under that user. Lifecycle for providers has been modified to stop discovery when the user is no longer current but keep the binder connection open so long as there's a session that has selected a route from that provider. When a user is stopped all providers on that user will be unbound even if they were still in use. Change-Id: Iadf1efded3415f7ecf384d3a73513883de9c86b0
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/session/ISession.aidl1
-rw-r--r--media/java/android/media/session/ISessionCallback.aidl1
-rw-r--r--media/java/android/media/session/Session.java71
3 files changed, 69 insertions, 4 deletions
diff --git a/media/java/android/media/session/ISession.aidl b/media/java/android/media/session/ISession.aidl
index 3ff07d9..096550f 100644
--- a/media/java/android/media/session/ISession.aidl
+++ b/media/java/android/media/session/ISession.aidl
@@ -40,6 +40,7 @@ interface ISession {
boolean setRoute(in RouteInfo route);
void setRouteOptions(in List<RouteOptions> options);
void connectToRoute(in RouteInfo route, in RouteOptions options);
+ void disconnectFromRoute(in RouteInfo route);
void sendRouteCommand(in RouteCommand event, in ResultReceiver cb);
// These commands are for the TransportPerformer
diff --git a/media/java/android/media/session/ISessionCallback.aidl b/media/java/android/media/session/ISessionCallback.aidl
index f04cbcc..1552513 100644
--- a/media/java/android/media/session/ISessionCallback.aidl
+++ b/media/java/android/media/session/ISessionCallback.aidl
@@ -31,6 +31,7 @@ oneway interface ISessionCallback {
void onMediaButton(in Intent mediaButtonIntent);
void onRequestRouteChange(in RouteInfo route);
void onRouteConnected(in RouteInfo route, in RouteOptions options);
+ void onRouteDisconnected(in RouteInfo route, int reason);
void onRouteStateChange(int state);
void onRouteEvent(in RouteEvent event);
diff --git a/media/java/android/media/session/Session.java b/media/java/android/media/session/Session.java
index 194679e7..2ffced6 100644
--- a/media/java/android/media/session/Session.java
+++ b/media/java/android/media/session/Session.java
@@ -86,10 +86,39 @@ public final class Session {
*/
public static final int FLAG_EXCLUSIVE_GLOBAL_PRIORITY = 1 << 16;
+ /**
+ * Indicates the session was disconnected because the user that the session
+ * belonged to is stopping.
+ */
+ public static final int DISCONNECT_REASON_USER_STOPPING = 1;
+
+ /**
+ * Indicates the session was disconnected because the provider disconnected
+ * the route.
+ */
+ public static final int DISCONNECT_REASON_PROVIDER_DISCONNECTED = 2;
+
+ /**
+ * Indicates the session was disconnected because the route has changed.
+ */
+ public static final int DISCONNECT_REASON_ROUTE_CHANGED = 3;
+
+ /**
+ * Indicates the session was disconnected because the session owner
+ * requested it disconnect.
+ */
+ public static final int DISCONNECT_REASON_SESSION_DISCONNECTED = 4;
+
+ /**
+ * Indicates the session was disconnected because it was destroyed.
+ */
+ public static final int DISCONNECT_REASON_SESSION_DESTROYED = 5;
+
private static final int MSG_MEDIA_BUTTON = 1;
private static final int MSG_COMMAND = 2;
private static final int MSG_ROUTE_CHANGE = 3;
private static final int MSG_ROUTE_CONNECTED = 4;
+ private static final int MSG_ROUTE_DISCONNECTED = 5;
private static final String KEY_COMMAND = "command";
private static final String KEY_EXTRAS = "extras";
@@ -302,11 +331,15 @@ public final class Session {
/**
* Disconnect from the current route. After calling you will be switched
* back to the default route.
- *
- * @param route The route to disconnect from.
*/
- public void disconnect(RouteInfo route) {
- // TODO
+ public void disconnect() {
+ if (mRoute != null) {
+ try {
+ mBinder.disconnectFromRoute(mRoute.getRouteInfo());
+ } catch (RemoteException e) {
+ Log.wtf(TAG, "Error disconnecting from route");
+ }
+ }
}
/**
@@ -406,6 +439,16 @@ public final class Session {
}
}
+ private void postRouteDisconnected(RouteInfo route, int reason) {
+ synchronized (mLock) {
+ if (mRoute != null && TextUtils.equals(mRoute.getRouteInfo().getId(), route.getId())) {
+ for (int i = mCallbacks.size() - 1; i >= 0; i--) {
+ mCallbacks.get(i).post(MSG_ROUTE_DISCONNECTED, mRoute, reason);
+ }
+ }
+ }
+ }
+
/**
* Receives commands or updates from controllers and routes. An app can
* specify what commands and buttons it supports by setting them on the
@@ -467,6 +510,11 @@ public final class Session {
* <p>
* Valid reasons are:
* <ul>
+ * <li>{@link #DISCONNECT_REASON_USER_STOPPING}</li>
+ * <li>{@link #DISCONNECT_REASON_PROVIDER_DISCONNECTED}</li>
+ * <li>{@link #DISCONNECT_REASON_ROUTE_CHANGED}</li>
+ * <li>{@link #DISCONNECT_REASON_SESSION_DISCONNECTED}</li>
+ * <li>{@link #DISCONNECT_REASON_SESSION_DESTROYED}</li>
* </ul>
*
* @param route The route that disconnected
@@ -520,6 +568,14 @@ public final class Session {
}
@Override
+ public void onRouteDisconnected(RouteInfo route, int reason) {
+ Session session = mMediaSession.get();
+ if (session != null) {
+ session.postRouteDisconnected(route, reason);
+ }
+ }
+
+ @Override
public void onPlay() throws RemoteException {
Session session = mMediaSession.get();
if (session != null) {
@@ -668,6 +724,9 @@ public final class Session {
case MSG_ROUTE_CONNECTED:
mCallback.onRouteConnected((Route) msg.obj);
break;
+ case MSG_ROUTE_DISCONNECTED:
+ mCallback.onRouteDisconnected((Route) msg.obj, msg.arg1);
+ break;
}
}
}
@@ -675,6 +734,10 @@ public final class Session {
public void post(int what, Object obj) {
obtainMessage(what, obj).sendToTarget();
}
+
+ public void post(int what, Object obj, int arg1) {
+ obtainMessage(what, arg1, 0, obj).sendToTarget();
+ }
}
private static final class Command {