Merge "Api updates to MediaSession components" into lmp-dev

This commit is contained in:
RoboErik
2014-08-20 19:48:45 +00:00
committed by Android (Google) Code Review
10 changed files with 109 additions and 82 deletions

View File

@@ -16382,16 +16382,16 @@ package android.media.session {
method public void addCallback(android.media.session.MediaController.Callback, android.os.Handler);
method public void adjustVolume(int, int);
method public boolean dispatchMediaButtonEvent(android.view.KeyEvent);
method public android.media.session.MediaController.AudioInfo getAudioInfo();
method public android.os.Bundle getExtras();
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.MediaController.PlaybackInfo getPlaybackInfo();
method public android.media.session.PlaybackState getPlaybackState();
method public java.util.List<android.media.session.MediaSession.Item> getQueue();
method public java.lang.CharSequence getQueueTitle();
method public int getRatingType();
method public android.app.PendingIntent getSessionActivity();
method public android.media.session.MediaSession.Token getSessionToken();
method public android.media.session.MediaController.TransportControls getTransportControls();
method public void removeCallback(android.media.session.MediaController.Callback);
@@ -16399,17 +16399,9 @@ package android.media.session {
method public void setVolumeTo(int, int);
}
public static final class MediaController.AudioInfo {
method public android.media.AudioAttributes getAudioAttributes();
method public int getCurrentVolume();
method public int getMaxVolume();
method public int getVolumeControl();
method public int getVolumeType();
}
public static abstract class MediaController.Callback {
ctor public MediaController.Callback();
method public void onAudioInfoChanged(android.media.session.MediaController.AudioInfo);
method public void onAudioInfoChanged(android.media.session.MediaController.PlaybackInfo);
method public void onExtrasChanged(android.os.Bundle);
method public void onMetadataChanged(android.media.MediaMetadata);
method public void onPlaybackStateChanged(android.media.session.PlaybackState);
@@ -16419,6 +16411,16 @@ package android.media.session {
method public void onSessionEvent(java.lang.String, android.os.Bundle);
}
public static final class MediaController.PlaybackInfo {
method public android.media.AudioAttributes getAudioAttributes();
method public int getCurrentVolume();
method public int getMaxVolume();
method public int getPlaybackType();
method public int getVolumeControl();
field public static final int PLAYBACK_TYPE_LOCAL = 1; // 0x1
field public static final int PLAYBACK_TYPE_REMOTE = 2; // 0x2
}
public final class MediaController.TransportControls {
method public void fastForward();
method public void pause();
@@ -16448,7 +16450,6 @@ package android.media.session {
method public void setCallback(android.media.session.MediaSession.Callback, android.os.Handler);
method public void setExtras(android.os.Bundle);
method public void setFlags(int);
method public void setLaunchActivity(android.app.PendingIntent);
method public void setMediaButtonReceiver(android.app.PendingIntent);
method public void setMetadata(android.media.MediaMetadata);
method public void setPlaybackState(android.media.session.PlaybackState);
@@ -16456,10 +16457,9 @@ package android.media.session {
method public void setPlaybackToRemote(android.media.VolumeProvider);
method public void setQueue(java.util.List<android.media.session.MediaSession.Item>);
method public void setQueueTitle(java.lang.CharSequence);
method public void setSessionActivity(android.app.PendingIntent);
field public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1; // 0x1
field public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2; // 0x2
field public static final int PLAYBACK_TYPE_LOCAL = 1; // 0x1
field public static final int PLAYBACK_TYPE_REMOTE = 2; // 0x2
}
public static abstract class MediaSession.Callback {
@@ -16506,6 +16506,7 @@ package android.media.session {
public final class MediaSessionManager {
method public void addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, android.content.ComponentName);
method public void addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, android.content.ComponentName, android.os.Handler);
method public java.util.List<android.media.session.MediaController> getActiveSessions(android.content.ComponentName);
method public void removeOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener);
}
@@ -16517,7 +16518,7 @@ package android.media.session {
public final class PlaybackState implements android.os.Parcelable {
method public int describeContents();
method public long getActions();
method public long getBufferPosition();
method public long getBufferedPosition();
method public java.util.List<android.media.session.PlaybackState.CustomAction> getCustomActions();
method public java.lang.CharSequence getErrorMessage();
method public long getLastPositionUpdateTime();
@@ -16561,7 +16562,7 @@ package android.media.session {
method public android.media.session.PlaybackState build();
method public android.media.session.PlaybackState.Builder setActions(long);
method public android.media.session.PlaybackState.Builder setActiveItem(long);
method public android.media.session.PlaybackState.Builder setBufferPosition(long);
method public android.media.session.PlaybackState.Builder setBufferedPosition(long);
method public android.media.session.PlaybackState.Builder setErrorMessage(java.lang.CharSequence);
method public android.media.session.PlaybackState.Builder setState(int, long, float, long);
method public android.media.session.PlaybackState.Builder setState(int, long, float);

View File

@@ -247,14 +247,14 @@ public final class MediaController {
}
/**
* Get the current audio info for this session.
* Get the current playback info for this session.
*
* @return The current audio info or null.
* @return The current playback info or null.
*/
public @Nullable AudioInfo getAudioInfo() {
public @Nullable PlaybackInfo getPlaybackInfo() {
try {
ParcelableVolumeInfo result = mSessionBinder.getVolumeAttributes();
return new AudioInfo(result.volumeType, result.audioAttrs, result.controlType,
return new PlaybackInfo(result.volumeType, result.audioAttrs, result.controlType,
result.maxVolume, result.currentVolume);
} catch (RemoteException e) {
@@ -269,7 +269,7 @@ public final class MediaController {
*
* @return A {@link PendingIntent} to launch UI or null.
*/
public @Nullable PendingIntent getLaunchActivity() {
public @Nullable PendingIntent getSessionActivity() {
try {
return mSessionBinder.getLaunchPendingIntent();
} catch (RemoteException e) {
@@ -293,9 +293,10 @@ public final class MediaController {
* {@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}. The flags in
* {@link AudioManager} may be used to affect the handling.
*
* @see #getAudioInfo()
* @see #getPlaybackInfo()
* @param value The value to set it to, between 0 and the reported max.
* @param flags Any flags to pass with the command.
* @param flags Flags from {@link AudioManager} to include with the volume
* request.
*/
public void setVolumeTo(int value, int flags) {
try {
@@ -314,7 +315,7 @@ public final class MediaController {
* {@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}. The flags in
* {@link AudioManager} may be used to affect the handling.
*
* @see #getAudioInfo()
* @see #getPlaybackInfo()
* @param direction The direction to adjust the volume in.
* @param flags Any flags to pass with the command.
*/
@@ -565,7 +566,7 @@ public final class MediaController {
*
* @param info The current audio info for this session.
*/
public void onAudioInfoChanged(AudioInfo info) {
public void onAudioInfoChanged(PlaybackInfo info) {
}
}
@@ -773,9 +774,19 @@ public final class MediaController {
}
/**
* Holds information about the way audio is handled for this session.
* Holds information about the current playback and how audio is handled for
* this session.
*/
public static final class AudioInfo {
public static final class PlaybackInfo {
/**
* The session uses remote playback.
*/
public static final int PLAYBACK_TYPE_REMOTE = 2;
/**
* The session uses local playback.
*/
public static final int PLAYBACK_TYPE_LOCAL = 1;
private final int mVolumeType;
private final int mVolumeControl;
private final int mMaxVolume;
@@ -785,7 +796,7 @@ public final class MediaController {
/**
* @hide
*/
public AudioInfo(int type, AudioAttributes attrs, int control, int max, int current) {
public PlaybackInfo(int type, AudioAttributes attrs, int control, int max, int current) {
mVolumeType = type;
mAudioAttrs = attrs;
mVolumeControl = control;
@@ -794,22 +805,22 @@ public final class MediaController {
}
/**
* Get the type of volume handling, either local or remote. One of:
* Get the type of playback which affects volume handling. One of:
* <ul>
* <li>{@link MediaSession#PLAYBACK_TYPE_LOCAL}</li>
* <li>{@link MediaSession#PLAYBACK_TYPE_REMOTE}</li>
* <li>{@link #PLAYBACK_TYPE_LOCAL}</li>
* <li>{@link #PLAYBACK_TYPE_REMOTE}</li>
* </ul>
*
* @return The type of volume handling this session is using.
* @return The type of playback this session is using.
*/
public int getVolumeType() {
public int getPlaybackType() {
return mVolumeType;
}
/**
* Get the audio attributes for this session. The attributes will affect
* volume handling for the session. When the volume type is
* {@link MediaSession#PLAYBACK_TYPE_REMOTE} these may be ignored by the
* {@link PlaybackInfo#PLAYBACK_TYPE_REMOTE} these may be ignored by the
* remote volume handler.
*
* @return The attributes for this session.
@@ -920,7 +931,7 @@ public final class MediaController {
public void onVolumeInfoChanged(ParcelableVolumeInfo pvi) {
MediaController controller = mController.get();
if (controller != null) {
AudioInfo info = new AudioInfo(pvi.volumeType, pvi.audioAttrs, pvi.controlType,
PlaybackInfo info = new PlaybackInfo(pvi.volumeType, pvi.audioAttrs, pvi.controlType,
pvi.maxVolume, pvi.currentVolume);
controller.postMessage(MSG_UPDATE_VOLUME, info, null);
}
@@ -958,7 +969,7 @@ public final class MediaController {
mCallback.onExtrasChanged((Bundle) msg.obj);
break;
case MSG_UPDATE_VOLUME:
mCallback.onAudioInfoChanged((AudioInfo) msg.obj);
mCallback.onAudioInfoChanged((PlaybackInfo) msg.obj);
break;
case MSG_DESTROYED:
mCallback.onSessionDestroyed();

View File

@@ -101,16 +101,6 @@ public final class MediaSession {
FLAG_EXCLUSIVE_GLOBAL_PRIORITY })
public @interface SessionFlags { }
/**
* The session uses local playback.
*/
public static final int PLAYBACK_TYPE_LOCAL = 1;
/**
* The session uses remote playback.
*/
public static final int PLAYBACK_TYPE_REMOTE = 2;
private final Object mLock = new Object();
private final MediaSession.Token mSessionToken;
@@ -215,7 +205,7 @@ public final class MediaSession {
*
* @param pi The intent to launch to show UI for this Session.
*/
public void setLaunchActivity(@Nullable PendingIntent pi) {
public void setSessionActivity(@Nullable PendingIntent pi) {
try {
mBinder.setLaunchPendingIntent(pi);
} catch (RemoteException e) {

View File

@@ -148,8 +148,29 @@ public final class MediaSessionManager {
public void addOnActiveSessionsChangedListener(
@NonNull OnActiveSessionsChangedListener sessionListener,
@Nullable ComponentName notificationListener) {
addOnActiveSessionsChangedListener(sessionListener, notificationListener, null);
}
/**
* Add a listener to be notified when the list of active sessions
* changes.This requires the
* android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by
* the calling app. You may also retrieve this list if your app is an
* enabled notification listener using the
* {@link NotificationListenerService} APIs, in which case you must pass the
* {@link ComponentName} of your enabled listener. Updates will be posted to
* the handler specified or to the caller's thread if the handler is null.
*
* @param sessionListener The listener to add.
* @param notificationListener The enabled notification listener component.
* May be null.
* @param handler The handler to post events to.
*/
public void addOnActiveSessionsChangedListener(
@NonNull OnActiveSessionsChangedListener sessionListener,
@Nullable ComponentName notificationListener, @Nullable Handler handler) {
addOnActiveSessionsChangedListener(sessionListener, notificationListener,
UserHandle.myUserId(), null);
UserHandle.myUserId(), handler);
}
/**

View File

@@ -21,7 +21,7 @@ import android.os.Parcelable;
/**
* Convenience class for passing information about the audio configuration of a
* session. The public implementation is {@link MediaController.AudioInfo}.
* session. The public implementation is {@link MediaController.PlaybackInfo}.
*
* @hide
*/

View File

@@ -217,7 +217,7 @@ public final class PlaybackState implements Parcelable {
private final int mState;
private final long mPosition;
private final long mBufferPosition;
private final long mBufferedPosition;
private final float mSpeed;
private final long mActions;
private List<PlaybackState.CustomAction> mCustomActions;
@@ -226,14 +226,14 @@ public final class PlaybackState implements Parcelable {
private final long mActiveItemId;
private PlaybackState(int state, long position, long updateTime, float speed,
long bufferPosition, long transportControls,
long bufferedPosition, long transportControls,
List<PlaybackState.CustomAction> customActions, long activeItemId,
CharSequence error) {
mState = state;
mPosition = position;
mSpeed = speed;
mUpdateTime = updateTime;
mBufferPosition = bufferPosition;
mBufferedPosition = bufferedPosition;
mActions = transportControls;
mCustomActions = new ArrayList<>(customActions);
mActiveItemId = activeItemId;
@@ -245,7 +245,7 @@ public final class PlaybackState implements Parcelable {
mPosition = in.readLong();
mSpeed = in.readFloat();
mUpdateTime = in.readLong();
mBufferPosition = in.readLong();
mBufferedPosition = in.readLong();
mActions = in.readLong();
mCustomActions = in.createTypedArrayList(CustomAction.CREATOR);
mActiveItemId = in.readLong();
@@ -258,7 +258,7 @@ public final class PlaybackState implements Parcelable {
StringBuilder bob = new StringBuilder("PlaybackState {");
bob.append("state=").append(mState);
bob.append(", position=").append(mPosition);
bob.append(", buffered position=").append(mBufferPosition);
bob.append(", buffered position=").append(mBufferedPosition);
bob.append(", speed=").append(mSpeed);
bob.append(", updated=").append(mUpdateTime);
bob.append(", actions=").append(mActions);
@@ -280,7 +280,7 @@ public final class PlaybackState implements Parcelable {
dest.writeLong(mPosition);
dest.writeFloat(mSpeed);
dest.writeLong(mUpdateTime);
dest.writeLong(mBufferPosition);
dest.writeLong(mBufferedPosition);
dest.writeLong(mActions);
dest.writeTypedList(mCustomActions);
dest.writeLong(mActiveItemId);
@@ -310,12 +310,12 @@ public final class PlaybackState implements Parcelable {
}
/**
* Get the current buffer position in ms. This is the farthest playback
* Get the current buffered position in ms. This is the farthest playback
* point that can be reached from the current position using only buffered
* content.
*/
public long getBufferPosition() {
return mBufferPosition;
public long getBufferedPosition() {
return mBufferedPosition;
}
/**
@@ -711,7 +711,7 @@ public final class PlaybackState implements Parcelable {
private int mState;
private long mPosition;
private long mBufferPosition;
private long mBufferedPosition;
private float mSpeed;
private long mActions;
private CharSequence mErrorMessage;
@@ -736,7 +736,7 @@ public final class PlaybackState implements Parcelable {
}
mState = from.mState;
mPosition = from.mPosition;
mBufferPosition = from.mBufferPosition;
mBufferedPosition = from.mBufferedPosition;
mSpeed = from.mSpeed;
mActions = from.mActions;
if (from.mCustomActions != null) {
@@ -889,15 +889,16 @@ public final class PlaybackState implements Parcelable {
}
/**
* Set the current buffer position in ms. This is the farthest playback
* point that can be reached from the current position using only
* buffered content.
* Set the current buffered position in ms. This is the farthest
* playback point that can be reached from the current position using
* only buffered content.
*
* @param bufferPosition The position in ms that playback is buffered to.
* @param bufferedPosition The position in ms that playback is buffered
* to.
* @return this
*/
public Builder setBufferPosition(long bufferPosition) {
mBufferPosition = bufferPosition;
public Builder setBufferedPosition(long bufferedPosition) {
mBufferedPosition = bufferedPosition;
return this;
}
@@ -931,7 +932,7 @@ public final class PlaybackState implements Parcelable {
* @return A new state instance.
*/
public PlaybackState build() {
return new PlaybackState(mState, mPosition, mUpdateTime, mSpeed, mBufferPosition,
return new PlaybackState(mState, mPosition, mUpdateTime, mSpeed, mBufferedPosition,
mActions, mCustomActions, mActiveItemId, mErrorMessage);
}
}

View File

@@ -37,7 +37,7 @@ import android.media.RingtoneManager;
import android.media.ToneGenerator;
import android.media.VolumeProvider;
import android.media.session.MediaController;
import android.media.session.MediaController.AudioInfo;
import android.media.session.MediaController.PlaybackInfo;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
@@ -537,7 +537,7 @@ public class VolumePanel extends Handler {
if (mStreamControls != null) {
StreamControl sc = mStreamControls.get(streamType);
if (sc != null && sc.controller != null) {
AudioInfo ai = sc.controller.getAudioInfo();
PlaybackInfo ai = sc.controller.getPlaybackInfo();
return ai.getMaxVolume();
}
}
@@ -554,7 +554,7 @@ public class VolumePanel extends Handler {
if (mStreamControls != null) {
StreamControl sc = mStreamControls.get(streamType);
if (sc != null && sc.controller != null) {
AudioInfo ai = sc.controller.getAudioInfo();
PlaybackInfo ai = sc.controller.getPlaybackInfo();
return ai.getCurrentVolume();
}
}
@@ -990,7 +990,7 @@ public class VolumePanel extends Handler {
// We still don't have one, ignore the command.
Log.w(mTag, "sent remote volume change without a controller!");
} else {
AudioInfo vi = controller.getAudioInfo();
PlaybackInfo vi = controller.getPlaybackInfo();
index = vi.getCurrentVolume();
max = vi.getMaxVolume();
if ((vi.getVolumeControl() & VolumeProvider.VOLUME_CONTROL_FIXED) != 0) {
@@ -1362,7 +1362,7 @@ public class VolumePanel extends Handler {
};
private final MediaController.Callback mMediaControllerCb = new MediaController.Callback() {
public void onAudioInfoChanged(AudioInfo info) {
public void onAudioInfoChanged(PlaybackInfo info) {
onRemoteVolumeUpdateIfShown();
}
};

View File

@@ -31,6 +31,7 @@ import android.media.session.ISessionCallback;
import android.media.session.ISessionController;
import android.media.session.ISessionControllerCallback;
import android.media.session.MediaController;
import android.media.session.MediaController.PlaybackInfo;
import android.media.session.MediaSession;
import android.media.session.ParcelableVolumeInfo;
import android.media.session.PlaybackState;
@@ -111,7 +112,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
private AudioAttributes mAudioAttrs;
private AudioManager mAudioManager;
private AudioManagerInternal mAudioManagerInternal;
private int mVolumeType = MediaSession.PLAYBACK_TYPE_LOCAL;
private int mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL;
private int mVolumeControlType = VolumeProvider.VOLUME_CONTROL_ABSOLUTE;
private int mMaxVolume = 0;
private int mCurrentVolume = 0;
@@ -237,7 +238,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
} else if (direction < -1) {
direction = -1;
}
if (mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL) {
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags, packageName,
uid);
@@ -265,7 +266,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
}
public void setVolumeTo(int value, int flags, String packageName, int uid) {
if (mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL) {
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
mAudioManagerInternal.setStreamVolumeForUid(stream, value, flags, packageName, uid);
} else {
@@ -748,8 +749,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
public void setPlaybackToLocal(AudioAttributes attributes) {
boolean typeChanged;
synchronized (mLock) {
typeChanged = mVolumeType == MediaSession.PLAYBACK_TYPE_REMOTE;
mVolumeType = MediaSession.PLAYBACK_TYPE_LOCAL;
typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_REMOTE;
mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL;
if (attributes != null) {
mAudioAttrs = attributes;
} else {
@@ -765,8 +766,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
public void setPlaybackToRemote(int control, int max) {
boolean typeChanged;
synchronized (mLock) {
typeChanged = mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL;
mVolumeType = MediaSession.PLAYBACK_TYPE_REMOTE;
typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL;
mVolumeType = PlaybackInfo.PLAYBACK_TYPE_REMOTE;
mVolumeControlType = control;
mMaxVolume = max;
}
@@ -998,7 +999,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
int type;
int max;
int current;
if (mVolumeType == MediaSession.PLAYBACK_TYPE_REMOTE) {
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_REMOTE) {
type = mVolumeControlType;
max = mMaxVolume;
current = mOptimisticVolume != -1 ? mOptimisticVolume

View File

@@ -37,6 +37,7 @@ import android.media.session.IActiveSessionsListener;
import android.media.session.ISession;
import android.media.session.ISessionCallback;
import android.media.session.ISessionManager;
import android.media.session.MediaController.PlaybackInfo;
import android.media.session.MediaSession;
import android.net.Uri;
import android.os.Binder;
@@ -814,7 +815,7 @@ public class MediaSessionService extends SystemService implements Monitor {
} else {
session.adjustVolume(direction, flags, getContext().getPackageName(),
UserHandle.myUserId());
if (session.getPlaybackType() == MediaSession.PLAYBACK_TYPE_REMOTE
if (session.getPlaybackType() == PlaybackInfo.PLAYBACK_TYPE_REMOTE
&& mRvc != null) {
try {
mRvc.remoteVolumeChanged(session.getControllerBinder(), flags);

View File

@@ -16,6 +16,7 @@
package com.android.server.media;
import android.media.session.MediaController.PlaybackInfo;
import android.media.session.PlaybackState;
import android.media.session.MediaSession;
import android.os.UserHandle;
@@ -209,7 +210,7 @@ public class MediaSessionStack {
int size = records.size();
for (int i = 0; i < size; i++) {
MediaSessionRecord record = records.get(i);
if (record.getPlaybackType() == MediaSession.PLAYBACK_TYPE_REMOTE) {
if (record.getPlaybackType() == PlaybackInfo.PLAYBACK_TYPE_REMOTE) {
return record;
}
}