Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79fa4630 authored by RoboErik's avatar RoboErik
Browse files

API changes to sessions

Changes requested by API Council review. A second CL will refactor
TransportController and TransportPerformer based on feedback.

Change-Id: Ie26a7d01d7021232a66c2edf1eb58120437fdfde
parent eb61eb78
Loading
Loading
Loading
Loading
+46 −54
Original line number Diff line number Diff line
@@ -14583,6 +14583,7 @@ package android.media {
    method public long getLong(java.lang.String);
    method public android.media.Rating getRating(java.lang.String);
    method public java.lang.String getString(java.lang.String);
    method public java.util.Set<java.lang.String> keySet();
    method public int size();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
@@ -15720,16 +15721,16 @@ package android.media.session {
  public final class MediaController {
    method public void addCallback(android.media.session.MediaController.Callback);
    method public void addCallback(android.media.session.MediaController.Callback, android.os.Handler);
    method public boolean dispatchMediaButtonEvent(android.view.KeyEvent);
    method public static android.media.session.MediaController fromToken(android.media.session.MediaSessionToken);
    method public android.media.session.TransportController getTransportController();
    method public void removeCallback(android.media.session.MediaController.Callback);
    method public void sendCommand(java.lang.String, android.os.Bundle, android.os.ResultReceiver);
    method public void sendMediaButton(int);
    method public void sendControlCommand(java.lang.String, android.os.Bundle, android.os.ResultReceiver);
  }
  public static abstract class MediaController.Callback {
    ctor public MediaController.Callback();
    method public void onEvent(java.lang.String, android.os.Bundle);
    method public void onSessionEvent(java.lang.String, android.os.Bundle);
  }
  public final class MediaSession {
@@ -15740,36 +15741,27 @@ package android.media.session {
    method public boolean isActive();
    method public void release();
    method public void removeCallback(android.media.session.MediaSession.Callback);
    method public void sendEvent(java.lang.String, android.os.Bundle);
    method public void sendSessionEvent(java.lang.String, android.os.Bundle);
    method public void setActive(boolean);
    method public void setFlags(int);
    method public void setLaunchPendingIntent(android.app.PendingIntent);
    method public void useLocalPlayback(int);
    method public void useRemotePlayback(android.media.session.RemoteVolumeProvider);
    method public void setPlaybackToLocal(int);
    method public void setPlaybackToRemote(android.media.session.RemoteVolumeProvider);
    field public static final int FLAG_HANDLES_MEDIA_BUTTONS = 1; // 0x1
    field public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 2; // 0x2
  }
  public static abstract class MediaSession.Callback {
    ctor public MediaSession.Callback();
    method public void onCommand(java.lang.String, android.os.Bundle, android.os.ResultReceiver);
    method public void onMediaButton(android.content.Intent);
  }
  public final class MediaSessionInfo implements android.os.Parcelable {
    method public int describeContents();
    method public java.lang.String getId();
    method public java.lang.String getPackageName();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    method public void onControlCommand(java.lang.String, android.os.Bundle, android.os.ResultReceiver);
    method public void onMediaButtonEvent(android.content.Intent);
  }
  public final class MediaSessionManager {
    method public android.media.session.MediaSession createSession(java.lang.String);
    method public java.util.List<android.media.session.MediaController> getActiveSessions(android.content.ComponentName);
  }
  public class MediaSessionToken implements android.os.Parcelable {
  public final class MediaSessionToken implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
@@ -15781,49 +15773,50 @@ package android.media.session {
    method public int describeContents();
    method public long getActions();
    method public long getBufferPosition();
    method public java.lang.String getErrorMessage();
    method public java.lang.CharSequence getErrorMessage();
    method public float getPlaybackRate();
    method public long getPosition();
    method public float getRate();
    method public int getState();
    method public void setActions(long);
    method public void setBufferPosition(long);
    method public void setErrorMessage(java.lang.String);
    method public void setErrorMessage(java.lang.CharSequence);
    method public void setState(int, long, float);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final long ACTION_FASTFORWARD = 64L; // 0x40L
    field public static final long ACTION_NEXT_ITEM = 32L; // 0x20L
    field public static final long ACTION_FAST_FORWARD = 64L; // 0x40L
    field public static final long ACTION_PAUSE = 2L; // 0x2L
    field public static final long ACTION_PLAY = 4L; // 0x4L
    field public static final long ACTION_PLAY_PAUSE = 512L; // 0x200L
    field public static final long ACTION_PREVIOUS_ITEM = 16L; // 0x10L
    field public static final long ACTION_RATING = 128L; // 0x80L
    field public static final long ACTION_REWIND = 8L; // 0x8L
    field public static final long ACTION_SEEK_TO = 256L; // 0x100L
    field public static final long ACTION_SET_RATING = 128L; // 0x80L
    field public static final long ACTION_SKIP_TO_NEXT = 32L; // 0x20L
    field public static final long ACTION_SKIP_TO_PREVIOUS = 16L; // 0x10L
    field public static final long ACTION_STOP = 1L; // 0x1L
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final long PLAYBACK_POSITION_UNKNOWN = -1L; // 0xffffffffffffffffL
    field public static final int PLAYSTATE_BUFFERING = 6; // 0x6
    field public static final int PLAYSTATE_ERROR = 7; // 0x7
    field public static final int PLAYSTATE_FAST_FORWARDING = 4; // 0x4
    field public static final int PLAYSTATE_NONE = 0; // 0x0
    field public static final int PLAYSTATE_PAUSED = 2; // 0x2
    field public static final int PLAYSTATE_PLAYING = 3; // 0x3
    field public static final int PLAYSTATE_REWINDING = 5; // 0x5
    field public static final int PLAYSTATE_SKIPPING_BACKWARDS = 9; // 0x9
    field public static final int PLAYSTATE_SKIPPING_FORWARDS = 10; // 0xa
    field public static final int PLAYSTATE_STOPPED = 1; // 0x1
    field public static final int STATE_BUFFERING = 6; // 0x6
    field public static final int STATE_ERROR = 7; // 0x7
    field public static final int STATE_FAST_FORWARDING = 4; // 0x4
    field public static final int STATE_NONE = 0; // 0x0
    field public static final int STATE_PAUSED = 2; // 0x2
    field public static final int STATE_PLAYING = 3; // 0x3
    field public static final int STATE_REWINDING = 5; // 0x5
    field public static final int STATE_SKIPPING_TO_NEXT = 10; // 0xa
    field public static final int STATE_SKIPPING_TO_PREVIOUS = 9; // 0x9
    field public static final int STATE_STOPPED = 1; // 0x1
  }
  public abstract class RemoteVolumeProvider {
    ctor public RemoteVolumeProvider(int, int);
    method public abstract int getCurrentVolume();
    method public final int getFlags();
    method public final int getMaxVolume();
    method public final void notifyVolumeChanged();
    method public void onAdjustVolume(int);
    method public void onSetVolume(int);
    field public static final int FLAG_VOLUME_ABSOLUTE = 2; // 0x2
    field public static final int FLAG_VOLUME_RELATIVE = 1; // 0x1
    method public void onAdjustVolumeBy(int);
    method public abstract int onGetCurrentVolume();
    method public void onSetVolumeTo(int);
    field public static final int VOLUME_CONTROL_ABSOLUTE = 4; // 0x4
    field public static final int VOLUME_CONTROL_FIXED = 1; // 0x1
    field public static final int VOLUME_CONTROL_RELATIVE = 2; // 0x2
  }
  public final class TransportController {
@@ -15833,14 +15826,14 @@ package android.media.session {
    method public android.media.MediaMetadata getMetadata();
    method public android.media.session.PlaybackState getPlaybackState();
    method public int getRatingType();
    method public void next();
    method public void pause();
    method public void play();
    method public void previous();
    method public void rate(android.media.Rating);
    method public void removeStateListener(android.media.session.TransportController.TransportStateListener);
    method public void rewind();
    method public void seekTo(long);
    method public void setRating(android.media.Rating);
    method public void skipToNext();
    method public void skipToPrevious();
    method public void stop();
  }
@@ -15851,24 +15844,23 @@ package android.media.session {
  }
  public final class TransportPerformer {
    method public void addListener(android.media.session.TransportPerformer.Listener);
    method public void addListener(android.media.session.TransportPerformer.Listener, android.os.Handler);
    method public void removeListener(android.media.session.TransportPerformer.Listener);
    method public final void setMetadata(android.media.MediaMetadata);
    method public final void setPlaybackState(android.media.session.PlaybackState);
    method public void addCallback(android.media.session.TransportPerformer.Callback);
    method public void addCallback(android.media.session.TransportPerformer.Callback, android.os.Handler);
    method public void removeCallback(android.media.session.TransportPerformer.Callback);
    method public void setMetadata(android.media.MediaMetadata);
    method public void setPlaybackState(android.media.session.PlaybackState);
  }
  public static abstract class TransportPerformer.Listener {
    ctor public TransportPerformer.Listener();
  public static abstract class TransportPerformer.Callback {
    ctor public TransportPerformer.Callback();
    method public void onFastForward();
    method public void onNext();
    method public void onPause();
    method public void onPlay();
    method public void onPrevious();
    method public void onRate(android.media.Rating);
    method public void onRewind();
    method public void onRouteFocusChange(int);
    method public void onSeekTo(long);
    method public void onSetRating(android.media.Rating);
    method public void onSkipToNext();
    method public void onSkipToPrevious();
    method public void onStop();
  }
+11 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.SparseArray;

import java.util.Set;

/**
 * Contains metadata about an item, such as the title, artist, etc.
 */
@@ -300,6 +302,15 @@ public final class MediaMetadata implements Parcelable {
        return mBundle.size();
    }

    /**
     * Returns a Set containing the Strings used as keys in this metadata.
     *
     * @return a Set of String keys
     */
    public Set<String> keySet() {
        return mBundle.keySet();
    }

    /**
     * Helper for getting the String key used by {@link MediaMetadata} from the
     * integer key that {@link MediaMetadataEditor} uses.
+2 −2
Original line number Diff line number Diff line
@@ -1317,7 +1317,7 @@ public class RemoteControlClient
    }

    // USE_SESSIONS
    private TransportPerformer.Listener mTransportListener = new TransportPerformer.Listener() {
    private TransportPerformer.Callback mTransportListener = new TransportPerformer.Callback() {

        @Override
        public void onSeekTo(long pos) {
@@ -1325,7 +1325,7 @@ public class RemoteControlClient
        }

        @Override
        public void onRate(Rating rating) {
        public void onSetRating(Rating rating) {
            if ((mTransportControlFlags & FLAG_KEY_MEDIA_RATING) != 0) {
                if (mEventHandler != null) {
                    mEventHandler.sendMessage(mEventHandler.obtainMessage(
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.view.KeyEvent;
 */
interface ISessionController {
    void sendCommand(String command, in Bundle extras, in ResultReceiver cb);
    void sendMediaButton(in KeyEvent mediaButton);
    boolean sendMediaButton(in KeyEvent mediaButton);
    void registerCallbackListener(in ISessionControllerCallback cb);
    void unregisterCallbackListener(in ISessionControllerCallback cb);
    boolean isTransportControlEnabled();
+15 −14
Original line number Diff line number Diff line
@@ -103,24 +103,25 @@ public final class MediaController {
    }

    /**
     * Send the specified media button to the session. Only media keys can be
     * sent using this method.
     * Send the specified media button event to the session. Only media keys can
     * be sent by this method, other keys will be ignored.
     *
     * @param keycode The media button keycode, such as
     *            {@link KeyEvent#KEYCODE_MEDIA_PLAY}.
     * @param keyEvent The media button event to dispatch.
     * @return true if the event was sent to the session, false otherwise.
     */
    public void sendMediaButton(int keycode) {
        if (!KeyEvent.isMediaKey(keycode)) {
            throw new IllegalArgumentException("May only send media buttons through "
                    + "sendMediaButton");
    public boolean dispatchMediaButtonEvent(KeyEvent keyEvent) {
        if (keyEvent == null) {
            throw new IllegalArgumentException("KeyEvent may not be null");
        }
        if (!KeyEvent.isMediaKey(keyEvent.getKeyCode())) {
            return false;
        }
        // TODO do something better than key down/up events
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, keycode);
        try {
            mSessionBinder.sendMediaButton(event);
            return mSessionBinder.sendMediaButton(keyEvent);
        } catch (RemoteException e) {
            Log.d(TAG, "Dead object in sendMediaButton", e);
        }
        return false;
    }

    /**
@@ -171,7 +172,7 @@ public final class MediaController {
     * @param params Any parameters to include with the command
     * @param cb The callback to receive the result on
     */
    public void sendCommand(String command, Bundle params, ResultReceiver cb) {
    public void sendControlCommand(String command, Bundle params, ResultReceiver cb) {
        if (TextUtils.isEmpty(command)) {
            throw new IllegalArgumentException("command cannot be null or empty");
        }
@@ -282,7 +283,7 @@ public final class MediaController {
         *
         * @param event
         */
        public void onEvent(String event, Bundle extras) {
        public void onSessionEvent(String event, Bundle extras) {
        }

        /**
@@ -354,7 +355,7 @@ public final class MediaController {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_EVENT:
                    mCallback.onEvent((String) msg.obj, msg.getData());
                    mCallback.onSessionEvent((String) msg.obj, msg.getData());
                    break;
                case MSG_ROUTE:
                    mCallback.onRouteChanged((RouteInfo) msg.obj);
Loading