From 1357012968f9066ea3051d83995e9bac69526c3c Mon Sep 17 00:00:00 2001
From: Jean-Michel Trivi Broadcast Action: The user has switched on advanced settings in the settings app:
@@ -2854,26 +2841,6 @@ public class Intent implements Parcelable, Cloneable {
public static final String EXTRA_USERID =
"android.intent.extra.user_id";
- /**
- * @hide (to be un-hidden)
- * An integer indicating whether the volume is to be increased (positive value) or decreased
- * (negative value). For bundled changes, the absolute value indicates the number of changes
- * in the same direction, e.g. +3 corresponds to three "volume up" changes.
- * @see #ACTION_VOLUME_UPDATE
- */
- public static final String EXTRA_VOLUME_UPDATE_DIRECTION =
- "android.intent.extra.VOLUME_UPDATE_DIRECTION";
-
- /**
- * @hide (to be un-hidden)
- * An integer indicating the new volume value, always between 0 and the value set for
- * {@link RemoteControlClient#PLAYBACKINFO_VOLUME_MAX} with
- * {@link RemoteControlClient#setPlaybackInformation(int, int)}
- * @see #ACTION_VOLUME_UPDATE
- */
- public static final String EXTRA_VOLUME_UPDATE_VALUE =
- "android.intent.extra.VOLUME_UPDATE_VALUE";
-
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Intent flags (see mFlags variable).
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 418dc52447f59..1b47602775a04 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -4243,6 +4243,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
public int mPlaybackVolumeHandling;
public int mPlaybackStream;
public int mPlaybackState;
+ public IRemoteVolumeObserver mRemoteVolumeObs;
public void resetPlaybackInfo() {
mPlaybackType = RemoteControlClient.PLAYBACK_TYPE_LOCAL;
@@ -4251,6 +4252,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
mPlaybackVolumeHandling = RemoteControlClient.DEFAULT_PLAYBACK_VOLUME_HANDLING;
mPlaybackStream = AudioManager.STREAM_MUSIC;
mPlaybackState = RemoteControlClient.PLAYSTATE_STOPPED;
+ mRemoteVolumeObs = null;
}
/** precondition: mediaIntent != null, eventReceiver != null */
@@ -4335,7 +4337,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
" -- state: " + rcse.mPlaybackState +
" -- vol handling: " + rcse.mPlaybackVolumeHandling +
" -- vol: " + rcse.mPlaybackVolume +
- " -- volMax: " + rcse.mPlaybackVolumeMax);
+ " -- volMax: " + rcse.mPlaybackVolumeMax +
+ " -- volObs: " + rcse.mRemoteVolumeObs);
+
}
}
synchronized (mMainRemote) {
@@ -5018,6 +5022,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
}
}
+ // FIXME send a message instead of updating the stack synchronously
+ public void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) {
+ synchronized(mRCStack) {
+ Iterator
The RemoteControlClient must have been previously registered with + * {@link AudioManager#registerRemoteControlClient(RemoteControlClient)}.
+ * * @param rcc RemoteControlClient associated with this route */ public void setRemoteControlClient(RemoteControlClient rcc) { mRcc = rcc; + updatePlaybackInfoOnRcc(); } /** @@ -792,6 +916,111 @@ public class MediaRouter { public void setIconResource(int resId) { setIconDrawable(sStatic.mResources.getDrawable(resId)); } + + /** + * @hide (to be un-hidden) + * Set a callback to be notified of volume update requests + * @param vcb + */ + public void setVolumeCallback(VolumeCallback vcb) { + mVcb = new VolumeCallbackInfo(vcb, this); + } + + /** + * @hide (to be un-hidden) + * Defines whether playback associated with this route is "local" + * ({@link RouteInfo#PLAYBACK_TYPE_LOCAL}) or "remote" + * ({@link RouteInfo#PLAYBACK_TYPE_REMOTE}). + * @param type + */ + public void setPlaybackType(int type) { + if (mPlaybackType != type) { + mPlaybackType = type; + setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE, type); + } + } + + /** + * @hide (to be un-hidden) + * Defines whether volume for the playback associated with this route is fixed + * ({@link RouteInfo#PLAYBACK_VOLUME_FIXED}) or can modified + * ({@link RouteInfo#PLAYBACK_VOLUME_VARIABLE}). + * @param volumeHandling + */ + public void setVolumeHandling(int volumeHandling) { + if (mVolumeHandling != volumeHandling) { + mVolumeHandling = volumeHandling; + setPlaybackInfoOnRcc( + RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING, volumeHandling); + } + } + + /** + * @hide (to be un-hidden) + * Defines at what volume the playback associated with this route is performed (for user + * feedback purposes). This information is only used when the playback is not local. + * @param volume + */ + public void setVolume(int volume) { + if (mVolume != volume) { + mVolume = volume; + setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_VOLUME, volume); + } + } + + /** + * @hide (to be un-hidden) + * Defines the maximum volume at which the playback associated with this route is performed + * (for user feedback purposes). This information is only used when the playback is not + * local. + * @param volumeMax + */ + public void setVolumeMax(int volumeMax) { + if (mVolumeMax != volumeMax) { + mVolumeMax = volumeMax; + setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_VOLUME_MAX, volumeMax); + } + } + + /** + * @hide (to be un-hidden) + * Defines over what stream type the media is presented. + * @param stream + */ + public void setPlaybackStream(int stream) { + if (mPlaybackStream != stream) { + mPlaybackStream = stream; + setPlaybackInfoOnRcc(RemoteControlClient.PLAYBACKINFO_USES_STREAM, stream); + } + } + + private void updatePlaybackInfoOnRcc() { + if ((mRcc != null) && (mRcc.getRcseId() != RemoteControlClient.RCSE_ID_UNREGISTERED)) { + mRcc.setPlaybackInformation( + RemoteControlClient.PLAYBACKINFO_VOLUME_MAX, mVolumeMax); + mRcc.setPlaybackInformation( + RemoteControlClient.PLAYBACKINFO_VOLUME, mVolume); + mRcc.setPlaybackInformation( + RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING, mVolumeHandling); + mRcc.setPlaybackInformation( + RemoteControlClient.PLAYBACKINFO_USES_STREAM, mPlaybackStream); + mRcc.setPlaybackInformation( + RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE, mPlaybackType); + // let AudioService know whom to call when remote volume needs to be updated + try { + sStatic.mAudioService.registerRemoteVolumeObserverForRcc( + mRcc.getRcseId() /* rccId */, mRemoteVolObserver /* rvo */); + } catch (RemoteException e) { + Log.e(TAG, "Error registering remote volume observer", e); + } + } + } + + private void setPlaybackInfoOnRcc(int what, int value) { + if (mRcc != null) { + mRcc.setPlaybackInformation(what, value); + } + } } /** @@ -1206,4 +1435,44 @@ public class MediaRouter { } } + + static class VolumeCallbackInfo { + public final VolumeCallback vcb; + public final RouteInfo route; + + public VolumeCallbackInfo(VolumeCallback vcb, RouteInfo route) { + this.vcb = vcb; + this.route = route; + } + } + + /** + * @hide (to be un-hidden) + * Interface for receiving events about volume changes. + * All methods of this interface will be called from the application's main thread. + * + *A VolumeCallback will only receive events relevant to routes that the callback + * was registered for.
+ * + * @see UserRouteInfo#setVolumeCallback(VolumeCallback) + */ + public static abstract class VolumeCallback { + /** + * Called when the volume for the route should be increased or decreased. + * @param info the route affected by this event + * @param direction an integer indicating whether the volume is to be increased + * (positive value) or decreased (negative value). + * For bundled changes, the absolute value indicates the number of changes + * in the same direction, e.g. +3 corresponds to three "volume up" changes. + */ + public abstract void onVolumeUpdateRequest(RouteInfo info, int direction); + /** + * Called when the volume for the route should be set to the given value + * @param info the route affected by this event + * @param volume an integer indicating the new volume value that should be used, always + * between 0 and the value set by {@link UserRouteInfo#setVolumeMax(int)}. + */ + public abstract void onVolumeSetRequest(RouteInfo info, int volume); + } + } diff --git a/media/java/android/media/RemoteControlClient.java b/media/java/android/media/RemoteControlClient.java index 5b8035e0f7308..79f9d37d36870 100644 --- a/media/java/android/media/RemoteControlClient.java +++ b/media/java/android/media/RemoteControlClient.java @@ -134,13 +134,13 @@ public class RemoteControlClient public final static int PLAYSTATE_NONE = 0; /** - * @hide (to be un-hidden) + * @hide * The default playback type, "local", indicating the presentation of the media is happening on * the same device (e.g. a phone, a tablet) as where it is controlled from. */ public final static int PLAYBACK_TYPE_LOCAL = 0; /** - * @hide (to be un-hidden) + * @hide * A playback type indicating the presentation of the media is happening on * a different device (i.e. the remote device) than where it is controlled from. */ @@ -148,7 +148,7 @@ public class RemoteControlClient private final static int PLAYBACK_TYPE_MIN = PLAYBACK_TYPE_LOCAL; private final static int PLAYBACK_TYPE_MAX = PLAYBACK_TYPE_REMOTE; /** - * @hide (to be un-hidden) + * @hide * Playback information indicating the playback volume is fixed, i.e. it cannot be controlled * from this object. An example of fixed playback volume is a remote player, playing over HDMI * where the user prefer to control the volume on the HDMI sink, rather than attenuate at the @@ -157,7 +157,7 @@ public class RemoteControlClient */ public final static int PLAYBACK_VOLUME_FIXED = 0; /** - * @hide (to be un-hidden) + * @hide * Playback information indicating the playback volume is variable and can be controlled from * this object. * @see #PLAYBACKINFO_VOLUME_HANDLING. @@ -173,34 +173,34 @@ public class RemoteControlClient //========================================== // Public keys for playback information /** - * @hide (to be un-hidden) + * @hide * Playback information that defines the type of playback associated with this * RemoteControlClient. See {@link #PLAYBACK_TYPE_LOCAL} and {@link #PLAYBACK_TYPE_REMOTE}. */ public final static int PLAYBACKINFO_PLAYBACK_TYPE = 1; /** - * @hide (to be un-hidden) + * @hide * Playback information that defines at what volume the playback associated with this * RemoteControlClient is performed. This information is only used when the playback type is not * local (see {@link #PLAYBACKINFO_PLAYBACK_TYPE}). */ public final static int PLAYBACKINFO_VOLUME = 2; /** - * @hide (to be un-hidden) + * @hide * Playback information that defines the maximum volume volume value that is supported * by the playback associated with this RemoteControlClient. This information is only used * when the playback type is not local (see {@link #PLAYBACKINFO_PLAYBACK_TYPE}). */ public final static int PLAYBACKINFO_VOLUME_MAX = 3; /** - * @hide (to be un-hidden) + * @hide * Playback information that defines how volume is handled for the presentation of the media. * @see #PLAYBACK_VOLUME_FIXED * @see #PLAYBACK_VOLUME_VARIABLE */ public final static int PLAYBACKINFO_VOLUME_HANDLING = 4; /** - * @hide (to be un-hidden) + * @hide * Playback information that defines over what stream type the media is presented. */ public final static int PLAYBACKINFO_USES_STREAM = 5; @@ -642,7 +642,7 @@ public class RemoteControlClient private int mPlaybackStream = AudioManager.STREAM_MUSIC; /** - * @hide (to be un-hidden) + * @hide * Set information describing information related to the playback of media so the system * can implement additional behavior to handle non-local playback usecases. * @param what a key to specify the type of information to set. Valid keys are @@ -713,7 +713,7 @@ public class RemoteControlClient } /** - * @hide (to be un-hidden) + * @hide * Return playback information represented as an integer value. * @param what a key to specify the type of information to retrieve. Valid keys are * {@link #PLAYBACKINFO_PLAYBACK_TYPE}, @@ -899,6 +899,13 @@ public class RemoteControlClient mRcseId = id; } + /** + * @hide + */ + public int getRcseId() { + return mRcseId; + } + private EventHandler mEventHandler; private final static int MSG_REQUEST_PLAYBACK_STATE = 1; private final static int MSG_REQUEST_METADATA = 2;