Finish plumbing for launch intents in sessions
This finishes out the plumbing for setting a launchable PendingIntent
on a session and getting it from a controller to launch an app's UI.
Change-Id: I0c9506e7c3f0ebf57070ca7e0d91324eb3fdd1e1
diff --git a/api/current.txt b/api/current.txt
index 292123e..9b211c2 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -16578,6 +16578,7 @@
method public android.media.routing.MediaRouter.Delegate createMediaRouterDelegate();
method public boolean dispatchMediaButtonEvent(android.view.KeyEvent);
method public long getFlags();
+ method public android.app.PendingIntent getLaunchActivity();
method public android.media.MediaMetadata getMetadata();
method public android.media.session.PlaybackState getPlaybackState();
method public java.util.List<android.media.session.MediaSession.Track> getQueue();
@@ -16641,7 +16642,7 @@
method public void setActive(boolean);
method public void setExtras(android.os.Bundle);
method public void setFlags(int);
- method public void setLaunchPendingIntent(android.app.PendingIntent);
+ method public void setLaunchActivity(android.app.PendingIntent);
method public void setMediaRouter(android.media.routing.MediaRouter);
method public void setMetadata(android.media.MediaMetadata);
method public void setPlaybackState(android.media.session.PlaybackState);
diff --git a/media/java/android/media/session/ISession.aidl b/media/java/android/media/session/ISession.aidl
index 2c190b7..0b8b0d4 100644
--- a/media/java/android/media/session/ISession.aidl
+++ b/media/java/android/media/session/ISession.aidl
@@ -15,6 +15,7 @@
package android.media.session;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.pm.ParceledListSlice;
import android.media.AudioAttributes;
@@ -37,6 +38,7 @@
void setActive(boolean active);
void setMediaRouter(in IMediaRouter router);
void setMediaButtonReceiver(in ComponentName mbr);
+ void setLaunchPendingIntent(in PendingIntent pi);
void destroy();
// These commands are for the TransportPerformer
diff --git a/media/java/android/media/session/ISessionController.aidl b/media/java/android/media/session/ISessionController.aidl
index d20b0ad5..1983095 100644
--- a/media/java/android/media/session/ISessionController.aidl
+++ b/media/java/android/media/session/ISessionController.aidl
@@ -15,6 +15,7 @@
package android.media.session;
+import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.media.MediaMetadata;
@@ -44,6 +45,7 @@
void unregisterCallbackListener(in ISessionControllerCallback cb);
boolean isTransportControlEnabled();
MediaSessionInfo getSessionInfo();
+ PendingIntent getLaunchPendingIntent();
long getFlags();
ParcelableVolumeInfo getVolumeAttributes();
void adjustVolume(int direction, int flags);
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java
index 89c61c8..776bbaa 100644
--- a/media/java/android/media/session/MediaController.java
+++ b/media/java/android/media/session/MediaController.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.PendingIntent;
import android.content.pm.ParceledListSlice;
import android.media.AudioAttributes;
import android.media.AudioManager;
@@ -241,6 +242,21 @@
}
/**
+ * Get an intent for launching UI associated with this session if one
+ * exists.
+ *
+ * @return A {@link PendingIntent} to launch UI or null.
+ */
+ public @Nullable PendingIntent getLaunchActivity() {
+ try {
+ return mSessionBinder.getLaunchPendingIntent();
+ } catch (RemoteException e) {
+ Log.wtf(TAG, "Error calling getPendingIntent.", e);
+ }
+ return null;
+ }
+
+ /**
* Get the token for the session this is connected to.
*
* @return The token for the connected session.
diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java
index 866910d..5833492 100644
--- a/media/java/android/media/session/MediaSession.java
+++ b/media/java/android/media/session/MediaSession.java
@@ -19,6 +19,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
@@ -222,12 +223,17 @@
/**
* Set an intent for launching UI for this Session. This can be used as a
- * quick link to an ongoing media screen.
+ * quick link to an ongoing media screen. The intent should be for an
+ * activity that may be started using {@link Activity#startActivity(Intent)}.
*
* @param pi The intent to launch to show UI for this Session.
*/
- public void setLaunchPendingIntent(@Nullable PendingIntent pi) {
- // TODO
+ public void setLaunchActivity(@Nullable PendingIntent pi) {
+ try {
+ mBinder.setLaunchPendingIntent(pi);
+ } catch (RemoteException e) {
+ Log.wtf(TAG, "Failure in setLaunchPendingIntent.", e);
+ }
}
/**
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index e9df507..4ceb213 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -16,6 +16,7 @@
package com.android.server.media;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -99,6 +100,7 @@
private long mFlags;
private IMediaRouter mMediaRouter;
private ComponentName mMediaButtonReceiver;
+ private PendingIntent mLaunchIntent;
// TransportPerformer fields
@@ -651,6 +653,11 @@
}
@Override
+ public void setLaunchPendingIntent(PendingIntent pi) {
+ mLaunchIntent = pi;
+ }
+
+ @Override
public void setMetadata(MediaMetadata metadata) {
mMetadata = metadata;
mHandler.post(MessageHandler.MSG_UPDATE_METADATA);
@@ -921,6 +928,11 @@
}
@Override
+ public PendingIntent getLaunchPendingIntent() {
+ return mLaunchIntent;
+ }
+
+ @Override
public long getFlags() {
return mFlags;
}