Skip to content

Commit 1357012

Browse files
committed
Remote volume handling in MediaRouter
Extend MediaRouter.UserRouteInfo to enable setting playback information, which includes volume. When the user route instance has a RemoteControlClient, forward any playback information to it. Enable specifying a callback to be notified of volume events on the route. Extend MediaRouter.RouteInfo to enable retrieving playback information. Update RemoteControlClient javadoc to reflect which parts of the API are not intended to be made public. Change-Id: I59d728eb61747af6c8c89d53f0faeb07940594c3
1 parent fe54cb6 commit 1357012

File tree

7 files changed

+352
-60
lines changed

7 files changed

+352
-60
lines changed

Android.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ LOCAL_SRC_FILES += \
193193
location/java/android/location/INetInitiatedListener.aidl \
194194
media/java/android/media/IAudioService.aidl \
195195
media/java/android/media/IAudioFocusDispatcher.aidl \
196-
media/java/android/media/IAudioRoutesObserver.aidl \
196+
media/java/android/media/IAudioRoutesObserver.aidl \
197197
media/java/android/media/IMediaScannerListener.aidl \
198198
media/java/android/media/IMediaScannerService.aidl \
199199
media/java/android/media/IRemoteControlClient.aidl \
200200
media/java/android/media/IRemoteControlDisplay.aidl \
201+
media/java/android/media/IRemoteVolumeObserver.aidl \
201202
media/java/android/media/IRingtonePlayer.aidl \
202203
telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl \
203204
telephony/java/com/android/internal/telephony/IPhoneSubInfo.aidl \

core/java/android/content/Intent.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,19 +2152,6 @@ public static Intent createChooser(Intent target, CharSequence title) {
21522152
public static final String ACTION_USB_AUDIO_DEVICE_PLUG =
21532153
"android.intent.action.USB_AUDIO_DEVICE_PLUG";
21542154

2155-
/**
2156-
* @hide (to be un-hidden)
2157-
* Broadcast Action: the volume handled by the receiver should be updated based on the
2158-
* mutually exclusive extras, {@link #EXTRA_VOLUME_UPDATE_DIRECTION}
2159-
* and {@link #EXTRA_VOLUME_UPDATE_VALUE}.
2160-
*
2161-
* @see #EXTRA_VOLUME_UPDATE_DIRECTION
2162-
* @see #EXTRA_VOLUME_UPDATE_VALUE
2163-
* @see android.media.RemoteControlClient
2164-
*/
2165-
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2166-
public static final String ACTION_VOLUME_UPDATE = "android.intent.action.VOLUME_UPDATE";
2167-
21682155
/**
21692156
* <p>Broadcast Action: The user has switched on advanced settings in the settings app:</p>
21702157
* <ul>
@@ -2854,26 +2841,6 @@ public static Intent createChooser(Intent target, CharSequence title) {
28542841
public static final String EXTRA_USERID =
28552842
"android.intent.extra.user_id";
28562843

2857-
/**
2858-
* @hide (to be un-hidden)
2859-
* An integer indicating whether the volume is to be increased (positive value) or decreased
2860-
* (negative value). For bundled changes, the absolute value indicates the number of changes
2861-
* in the same direction, e.g. +3 corresponds to three "volume up" changes.
2862-
* @see #ACTION_VOLUME_UPDATE
2863-
*/
2864-
public static final String EXTRA_VOLUME_UPDATE_DIRECTION =
2865-
"android.intent.extra.VOLUME_UPDATE_DIRECTION";
2866-
2867-
/**
2868-
* @hide (to be un-hidden)
2869-
* An integer indicating the new volume value, always between 0 and the value set for
2870-
* {@link RemoteControlClient#PLAYBACKINFO_VOLUME_MAX} with
2871-
* {@link RemoteControlClient#setPlaybackInformation(int, int)}
2872-
* @see #ACTION_VOLUME_UPDATE
2873-
*/
2874-
public static final String EXTRA_VOLUME_UPDATE_VALUE =
2875-
"android.intent.extra.VOLUME_UPDATE_VALUE";
2876-
28772844
// ---------------------------------------------------------------------
28782845
// ---------------------------------------------------------------------
28792846
// Intent flags (see mFlags variable).

media/java/android/media/AudioService.java

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4243,6 +4243,7 @@ private static class RemoteControlStackEntry {
42434243
public int mPlaybackVolumeHandling;
42444244
public int mPlaybackStream;
42454245
public int mPlaybackState;
4246+
public IRemoteVolumeObserver mRemoteVolumeObs;
42464247

42474248
public void resetPlaybackInfo() {
42484249
mPlaybackType = RemoteControlClient.PLAYBACK_TYPE_LOCAL;
@@ -4251,6 +4252,7 @@ public void resetPlaybackInfo() {
42514252
mPlaybackVolumeHandling = RemoteControlClient.DEFAULT_PLAYBACK_VOLUME_HANDLING;
42524253
mPlaybackStream = AudioManager.STREAM_MUSIC;
42534254
mPlaybackState = RemoteControlClient.PLAYSTATE_STOPPED;
4255+
mRemoteVolumeObs = null;
42544256
}
42554257

42564258
/** precondition: mediaIntent != null, eventReceiver != null */
@@ -4335,7 +4337,9 @@ private void dumpRCCStack(PrintWriter pw) {
43354337
" -- state: " + rcse.mPlaybackState +
43364338
" -- vol handling: " + rcse.mPlaybackVolumeHandling +
43374339
" -- vol: " + rcse.mPlaybackVolume +
4338-
" -- volMax: " + rcse.mPlaybackVolumeMax);
4340+
" -- volMax: " + rcse.mPlaybackVolumeMax +
4341+
" -- volObs: " + rcse.mRemoteVolumeObs);
4342+
43394343
}
43404344
}
43414345
synchronized (mMainRemote) {
@@ -5018,6 +5022,20 @@ public void setPlaybackInfoForRcc(int rccId, int what, int value) {
50185022
}
50195023
}
50205024

5025+
// FIXME send a message instead of updating the stack synchronously
5026+
public void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) {
5027+
synchronized(mRCStack) {
5028+
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
5029+
while(stackIterator.hasNext()) {
5030+
RemoteControlStackEntry rcse = stackIterator.next();
5031+
if (rcse.mRccId == rccId) {
5032+
rcse.mRemoteVolumeObs = rvo;
5033+
break;
5034+
}
5035+
}
5036+
}
5037+
}
5038+
50215039
/**
50225040
* Checks if a remote client is active on the supplied stream type. Update the remote stream
50235041
* volume state if found and playing
@@ -5100,23 +5118,24 @@ private void sendVolumeUpdateToRemote(int rccId, int direction) {
51005118
// only handling discrete events
51015119
return;
51025120
}
5103-
String packageForRcc = null;
5121+
IRemoteVolumeObserver rvo = null;
51045122
synchronized (mRCStack) {
51055123
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
51065124
while(stackIterator.hasNext()) {
51075125
RemoteControlStackEntry rcse = stackIterator.next();
51085126
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
51095127
if (rcse.mRccId == rccId) {
5110-
packageForRcc = rcse.mReceiverComponent.getPackageName();
5128+
rvo = rcse.mRemoteVolumeObs;
51115129
break;
51125130
}
51135131
}
51145132
}
5115-
if (packageForRcc != null) {
5116-
Intent intent = new Intent(Intent.ACTION_VOLUME_UPDATE);
5117-
intent.putExtra(Intent.EXTRA_VOLUME_UPDATE_DIRECTION, direction);
5118-
intent.setPackage(packageForRcc);
5119-
mContext.sendBroadcast(intent);
5133+
if (rvo != null) {
5134+
try {
5135+
rvo.dispatchRemoteVolumeUpdate(direction, -1);
5136+
} catch (RemoteException e) {
5137+
Log.e(TAG, "Error dispatching relative volume update", e);
5138+
}
51205139
}
51215140
}
51225141

@@ -5147,23 +5166,24 @@ public void setRemoteStreamVolume(int vol) {
51475166
}
51485167
rccId = mMainRemote.mRccId;
51495168
}
5150-
String packageForRcc = null;
5169+
IRemoteVolumeObserver rvo = null;
51515170
synchronized (mRCStack) {
51525171
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
51535172
while(stackIterator.hasNext()) {
51545173
RemoteControlStackEntry rcse = stackIterator.next();
51555174
if (rcse.mRccId == rccId) {
51565175
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
5157-
packageForRcc = rcse.mReceiverComponent.getPackageName();
5176+
rvo = rcse.mRemoteVolumeObs;
51585177
break;
51595178
}
51605179
}
51615180
}
5162-
if (packageForRcc != null) {
5163-
Intent intent = new Intent(Intent.ACTION_VOLUME_UPDATE);
5164-
intent.putExtra(Intent.EXTRA_VOLUME_UPDATE_VALUE, vol);
5165-
intent.setPackage(packageForRcc);
5166-
mContext.sendBroadcast(intent);
5181+
if (rvo != null) {
5182+
try {
5183+
rvo.dispatchRemoteVolumeUpdate(0, vol);
5184+
} catch (RemoteException e) {
5185+
Log.e(TAG, "Error dispatching absolute volume update", e);
5186+
}
51675187
}
51685188
}
51695189

media/java/android/media/IAudioService.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.media.IAudioFocusDispatcher;
2424
import android.media.IAudioRoutesObserver;
2525
import android.media.IRemoteControlClient;
2626
import android.media.IRemoteControlDisplay;
27+
import android.media.IRemoteVolumeObserver;
2728
import android.media.IRingtonePlayer;
2829
import android.net.Uri;
2930
import android.view.KeyEvent;
@@ -135,6 +136,7 @@ interface IAudioService {
135136
oneway void setPlaybackInfoForRcc(int rccId, int what, int value);
136137
int getRemoteStreamMaxVolume();
137138
int getRemoteStreamVolume();
139+
oneway void registerRemoteVolumeObserverForRcc(int rccId, in IRemoteVolumeObserver rvo);
138140

139141
void startBluetoothSco(IBinder cb);
140142
void stopBluetoothSco(IBinder cb);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.media;
18+
19+
20+
/**
21+
* AIDL for the AudioService to report requests for remote volume update requests.
22+
* @hide
23+
*/
24+
oneway interface IRemoteVolumeObserver {
25+
void dispatchRemoteVolumeUpdate(int direction, int value);
26+
}

0 commit comments

Comments
 (0)