OSDN Git Service

Add a way to get the package/pid of the session
authorRoboErik <epastern@google.com>
Sun, 8 Jun 2014 18:15:01 +0000 (11:15 -0700)
committerRoboErik <epastern@google.com>
Sun, 8 Jun 2014 20:20:43 +0000 (13:20 -0700)
We need a package/pid to connect a session to a notification. This
adds a way to get those from the controller of a session.

Change-Id: I7700a341beebd46116dfb7dc82f1a667c718e728

media/java/android/media/session/ISessionController.aidl
media/java/android/media/session/MediaController.java
media/java/android/media/session/MediaSessionInfo.aidl [new file with mode: 0644]
media/java/android/media/session/MediaSessionInfo.java
services/core/java/com/android/server/media/MediaSessionRecord.java

index 9ce0692..7c03907 100644 (file)
@@ -19,6 +19,7 @@ import android.content.Intent;
 import android.media.MediaMetadata;
 import android.media.Rating;
 import android.media.session.ISessionControllerCallback;
+import android.media.session.MediaSessionInfo;
 import android.media.session.PlaybackState;
 import android.os.Bundle;
 import android.os.ResultReceiver;
@@ -35,6 +36,7 @@ interface ISessionController {
     void unregisterCallbackListener(in ISessionControllerCallback cb);
     boolean isTransportControlEnabled();
     void showRoutePicker();
+    MediaSessionInfo getSessionInfo();
 
     // These commands are for the TransportController
     void play();
index caff1ad..57a0a54 100644 (file)
@@ -246,6 +246,21 @@ public final class MediaController {
         }
     }
 
+    /**
+     * Get the info for the session this controller is connected to.
+     *
+     * @return The session info for the connected session.
+     * @hide
+     */
+    public MediaSessionInfo getSessionInfo() {
+        try {
+            return mSessionBinder.getSessionInfo();
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error in getSessionInfo.", e);
+        }
+        return null;
+    }
+
     /*
      * @hide
      */
diff --git a/media/java/android/media/session/MediaSessionInfo.aidl b/media/java/android/media/session/MediaSessionInfo.aidl
new file mode 100644 (file)
index 0000000..63dca9a
--- /dev/null
@@ -0,0 +1,18 @@
+/* Copyright 2014, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+package android.media.session;
+
+parcelable MediaSessionInfo;
index f701211..4dc1c09 100644 (file)
@@ -26,18 +26,21 @@ import android.os.Parcelable;
 public final class MediaSessionInfo implements Parcelable {
     private final String mId;
     private final String mPackageName;
+    private final int mPid;
 
     /**
      * @hide
      */
-    public MediaSessionInfo(String id, String packageName) {
+    public MediaSessionInfo(String id, String packageName, int pid) {
         mId = id;
         mPackageName = packageName;
+        mPid = pid;
     }
 
     private MediaSessionInfo(Parcel in) {
         mId = in.readString();
         mPackageName = in.readString();
+        mPid = in.readInt();
     }
 
     /**
@@ -58,9 +61,13 @@ public final class MediaSessionInfo implements Parcelable {
         return mId;
     }
 
+    public int getPid() {
+        return mPid;
+    }
+
     @Override
     public String toString() {
-        return "SessionInfo {id=" + mId + ", pkg=" + mPackageName + "}";
+        return "SessionInfo {id=" + mId + ", pkg=" + mPackageName + ", pid=" + mPid + "}";
     }
 
     @Override
@@ -72,6 +79,7 @@ public final class MediaSessionInfo implements Parcelable {
     public void writeToParcel(Parcel dest, int flags) {
         dest.writeString(mId);
         dest.writeString(mPackageName);
+        dest.writeInt(mPid);
     }
 
     public static final Parcelable.Creator<MediaSessionInfo> CREATOR
index 737ffda..835b094 100644 (file)
@@ -130,7 +130,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
         mOwnerPid = ownerPid;
         mOwnerUid = ownerUid;
         mUserId = userId;
-        mSessionInfo = new MediaSessionInfo(UUID.randomUUID().toString(), ownerPackageName);
+        mSessionInfo = new MediaSessionInfo(UUID.randomUUID().toString(), ownerPackageName,
+                ownerPid);
         mTag = tag;
         mController = new ControllerStub();
         mSession = new SessionStub();
@@ -943,6 +944,11 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
         }
 
         @Override
+        public MediaSessionInfo getSessionInfo() {
+            return mSessionInfo;
+        }
+
+        @Override
         public void play() throws RemoteException {
             mSessionCb.play();
         }