Commit aa4e23bb authored by RoboErik's avatar RoboErik

Add getPackageName to MediaController

This removes the MediaSessionInfo class and adds a method on the
controller to get the package name. This also converts code that
depended on the session's UUID to use the token for comparison or
the Tag in the case of test code that needs a string identifier.

Change-Id: Icb8dc76c70e23e897da8fd07651c524b96372bf9
parent b214efbb
......@@ -213,6 +213,7 @@ $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framew
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/framework.* $(PRODUCT_OUT)/system/framework2.*)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework-base_intermediates)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/docs/api-stubs-timestamp)
# ******************************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST ABOVE THIS BANNER
......
......@@ -16580,6 +16580,7 @@ package android.media.session {
method public long getFlags();
method public android.app.PendingIntent getLaunchActivity();
method public android.media.MediaMetadata getMetadata();
method public java.lang.String getPackageName();
method public android.media.session.PlaybackState getPlaybackState();
method public java.util.List<android.media.session.MediaSession.Track> getQueue();
method public int getRatingType();
......@@ -23,12 +23,10 @@ import android.media.MediaMetadata;
import android.media.session.ISessionController;
import android.media.session.ISessionManager;
import android.media.session.MediaController;
import android.media.session.MediaSessionInfo;
import android.media.session.PlaybackState;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
......@@ -62,14 +60,14 @@ public class Media extends BaseCommand {
"usage: media [subcommand] [options]\n" +
" media dispatch KEY\n" +
" media list-sessions\n" +
" media monitor <sessionId>\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 sessionId from list-sessions.\n"
" Use the tag from list-sessions.\n"
);
}
......@@ -116,7 +114,7 @@ public class Media extends BaseCommand {
for (IBinder session : sessions) {
MediaController controller = new MediaController(ISessionController.Stub
.asInterface(session));
if (controller != null && controller.getSessionInfo().getId().equals(id)) {
if (controller != null && id.equals(controller.getTag())) {
ControllerMonitor monitor = new ControllerMonitor(controller);
monitor.run();
success = true;
......@@ -192,7 +190,7 @@ public class Media extends BaseCommand {
}
void printUsageMessage() {
System.out.println("V2Monitoring session " + mController.getSessionInfo().getId()
System.out.println("V2Monitoring session " + mController.getTag()
+ "... available commands:");
System.out.println("(q)uit: finish monitoring");
}
......@@ -251,9 +249,9 @@ public class Media extends BaseCommand {
MediaController controller = new MediaController(ISessionController.Stub
.asInterface(session));
if (controller != null) {
MediaSessionInfo info = controller.getSessionInfo();
System.out.println(" id=" + info.getId() + ", package="
+ info.getPackageName());
String pkg = controller.getPackageName();
System.out.println(" tag=" + controller.getTag()
+ ", package=" + pkg);
}
}
} catch (Exception e) {
......
......@@ -214,7 +214,7 @@ import java.util.List;
public String getRemoteControlClientPackageName() {
if (USE_SESSIONS) {
synchronized (mInfoLock) {
return mCurrentSession != null ? mCurrentSession.getSessionInfo().getPackageName()
return mCurrentSession != null ? mCurrentSession.getPackageName()
: null;
}
} else {
......@@ -980,8 +980,8 @@ import java.util.List;
0 /* genId */, 1 /* clearing */, null /* obj */, 0 /* delay */);
}
} else if (mCurrentSession == null
|| !controller.getSessionInfo().getId()
.equals(mCurrentSession.getSessionInfo().getId())) {
|| !controller.getSessionToken()
.equals(mCurrentSession.getSessionToken())) {
if (mCurrentSession != null) {
mCurrentSession.removeCallback(mSessionCb);
}
......
......@@ -23,7 +23,6 @@ import android.media.Rating;
import android.media.routing.IMediaRouterDelegate;
import android.media.routing.IMediaRouterStateCallback;
import android.media.session.ISessionControllerCallback;
import android.media.session.MediaSessionInfo;
import android.media.session.ParcelableVolumeInfo;
import android.media.session.PlaybackState;
import android.media.session.MediaSession;
......@@ -44,7 +43,8 @@ interface ISessionController {
void registerCallbackListener(in ISessionControllerCallback cb);
void unregisterCallbackListener(in ISessionControllerCallback cb);
boolean isTransportControlEnabled();
MediaSessionInfo getSessionInfo();
String getPackageName();
String getTag();
PendingIntent getLaunchPendingIntent();
long getFlags();
ParcelableVolumeInfo getVolumeAttributes();
......
......@@ -71,7 +71,8 @@ public final class MediaController {
private final Object mLock = new Object();
private boolean mCbRegistered = false;
private MediaSessionInfo mInfo;
private String mPackageName;
private String mTag;
private final TransportControls mTransportControls;
......@@ -371,20 +372,36 @@ public final class MediaController {
}
/**
* Get the info for the session this controller is connected to.
* Get the session owner's package name.
*
* @return The session info for the connected session.
* @return The package name of of the session owner.
*/
public String getPackageName() {
if (mPackageName == null) {
try {
mPackageName = mSessionBinder.getPackageName();
} catch (RemoteException e) {
Log.d(TAG, "Dead object in getPackageName.", e);
}
}
return mPackageName;
}
/**
* Get the session's tag for debugging purposes.
*
* @return The session's tag.
* @hide
*/
public MediaSessionInfo getSessionInfo() {
if (mInfo == null) {
public String getTag() {
if (mTag == null) {
try {
mInfo = mSessionBinder.getSessionInfo();
mTag = mSessionBinder.getTag();
} catch (RemoteException e) {
Log.e(TAG, "Error in getSessionInfo.", e);
Log.d(TAG, "Dead object in getTag.", e);
}
}
return mInfo;
return mTag;
}
/*
......
......@@ -715,6 +715,7 @@ public final class MediaSession {
* the session.
*/
public static final class Token implements Parcelable {
private ISessionController mBinder;
/**
......@@ -734,6 +735,31 @@ public final class MediaSession {
dest.writeStrongBinder(mBinder.asBinder());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((mBinder == null) ? 0 : mBinder.asBinder().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Token other = (Token) obj;
if (mBinder == null) {
if (other.mBinder != null)
return false;
} else if (!mBinder.asBinder().equals(other.mBinder.asBinder()))
return false;
return true;
}
ISessionController getBinder() {
return mBinder;
}
......
/* 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;
/*
* Copyright (C) 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;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Information about a media session, including the owner's package name.
*
* @hide
*/
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, int pid) {
mId = id;
mPackageName = packageName;
mPid = pid;
}
private MediaSessionInfo(Parcel in) {
mId = in.readString();
mPackageName = in.readString();
mPid = in.readInt();
}
/**
* Get the package name of the owner of this session.
*
* @return The owner's package name
*/
public String getPackageName() {
return mPackageName;
}
/**
* Get the unique id for this session.
*
* @return The id for the session.
*/
public String getId() {
return mId;
}
public int getPid() {
return mPid;
}
@Override
public String toString() {
return "SessionInfo {id=" + mId + ", pkg=" + mPackageName + ", pid=" + mPid + "}";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mId);
dest.writeString(mPackageName);
dest.writeInt(mPid);
}
public static final Parcelable.Creator<MediaSessionInfo> CREATOR
= new Parcelable.Creator<MediaSessionInfo>() {
@Override
public MediaSessionInfo createFromParcel(Parcel in) {
return new MediaSessionInfo(in);
}
@Override
public MediaSessionInfo[] newArray(int size) {
return new MediaSessionInfo[size];
}
};
}
......@@ -369,7 +369,7 @@ public class MediaSessionLegacyHelper {
SessionHolder holder = mSessions.get(pi);
if (holder == null && createIfMissing) {
MediaSession session;
session = new MediaSession(mContext, TAG);
session = new MediaSession(mContext, TAG + "-" + pi.getCreatorPackage());
session.setActive(true);
holder = new SessionHolder(session, pi);
mSessions.put(pi, holder);
......
......@@ -1659,7 +1659,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
continue;
default:
// now to see if we have one like this
final String pkg = aController.getSessionInfo().getPackageName();
final String pkg = aController.getPackageName();
for (int i = 0; i < N; i++) {
final Entry entry = mNotificationData.get(i);
......
......@@ -34,14 +34,9 @@ import android.media.session.ISessionController;
import android.media.session.ISessionControllerCallback;
import android.media.session.MediaController;
import android.media.session.MediaSession;
import android.media.session.MediaSessionInfo;
import android.media.session.ParcelableVolumeInfo;
import android.media.session.PlaybackState;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaMetadata;
import android.media.Rating;
import android.media.VolumeProvider;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
......@@ -86,7 +81,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
private final int mOwnerPid;
private final int mOwnerUid;
private final int mUserId;
private final MediaSessionInfo mSessionInfo;
private final String mPackageName;
private final String mTag;
private final ControllerStub mController;
private final SessionStub mSession;
......@@ -131,8 +126,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
mOwnerPid = ownerPid;
mOwnerUid = ownerUid;
mUserId = userId;
mSessionInfo = new MediaSessionInfo(UUID.randomUUID().toString(), ownerPackageName,
ownerPid);
mPackageName = ownerPackageName;
mTag = tag;
mController = new ControllerStub();
mSession = new SessionStub();
......@@ -166,8 +160,17 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
*
* @return Info that identifies this session.
*/
public MediaSessionInfo getSessionInfo() {
return mSessionInfo;
public String getPackageName() {
return mPackageName;
}
/**
* Get the tag for the session.
*
* @return The session's tag.
*/
public String getTag() {
return mTag;
}
/**
......@@ -409,9 +412,10 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
pw.println(prefix + mTag + " " + this);
final String indent = prefix + " ";
// We print the hashcode for matching with the list in user records
pw.println(indent + "ownerPid=" + mOwnerPid + ", ownerUid=" + mOwnerUid
+ ", userId=" + mUserId);
pw.println(indent + "info=" + mSessionInfo.toString());
pw.println(indent + "package=" + mPackageName);
pw.println(indent + "active=" + mIsActive);
pw.println(indent + "flags=" + mFlags);
pw.println(indent + "rating type=" + mRatingType);
......@@ -420,6 +424,11 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
pw.println(indent + "metadata:" + getShortMetadataString());
}
@Override
public String toString() {
return mPackageName + "/" + mTag;
}
private String getShortMetadataString() {
int fields = mMetadata == null ? 0 : mMetadata.size();
String title = mMetadata == null ? null : mMetadata
......@@ -928,8 +937,13 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
}
@Override
public MediaSessionInfo getSessionInfo() {
return mSessionInfo;
public String getPackageName() {
return mPackageName;
}
@Override
public String getTag() {
return mTag;
}
@Override
......
......@@ -516,9 +516,9 @@ public class MediaSessionService extends SystemService implements Monitor {
int size = mSessions.size();
pw.println(indent + size + " Sessions:");
for (int i = 0; i < size; i++) {
// Just print the session info, the full session dump will
// Just print the short version, the full session dump will
// already be in the list of all sessions.
pw.println(indent + mSessions.get(i).getSessionInfo());
pw.println(indent + mSessions.get(i).toString());
}
}
}
......@@ -759,9 +759,9 @@ public class MediaSessionService extends SystemService implements Monitor {
private void dispatchAdjustVolumeLocked(int suggestedStream, int direction, int flags,
MediaSessionRecord session) {
if (DEBUG) {
String sessionInfo = session == null ? null : session.getSessionInfo().toString();
Log.d(TAG, "Adjusting session " + sessionInfo + " by " + direction + ". flags=" + flags
+ ", suggestedStream=" + suggestedStream);
String description = session == null ? null : session.toString();
Log.d(TAG, "Adjusting session " + description + " by " + direction + ". flags="
+ flags + ", suggestedStream=" + suggestedStream);
}
if (session == null) {
......@@ -824,7 +824,7 @@ public class MediaSessionService extends SystemService implements Monitor {
MediaSessionRecord session) {
if (session != null) {
if (DEBUG) {
Log.d(TAG, "Sending media key to " + session.getSessionInfo());
Log.d(TAG, "Sending media key to " + session.toString());
}
if (needWakeLock) {
mKeyEventReceiver.aquireWakeLockLocked();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment