Skip to content

Commit 643e337

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "No playback and music widget from other user on user switch" into jb-mr1-dev
2 parents c712079 + f4a8eb2 commit 643e337

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

media/java/android/media/AudioService.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,14 +3913,17 @@ public void onReceive(Context context, Intent intent) {
39133913
} else if (action.equalsIgnoreCase(Intent.ACTION_CONFIGURATION_CHANGED)) {
39143914
handleConfigurationChanged(context);
39153915
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
3916-
// attempt to stop music playabck for background user
3916+
// attempt to stop music playback for background user
39173917
sendMsg(mAudioHandler,
39183918
MSG_BROADCAST_AUDIO_BECOMING_NOISY,
39193919
SENDMSG_REPLACE,
39203920
0,
39213921
0,
39223922
null,
39233923
0);
3924+
// the current audio focus owner is no longer valid
3925+
discardAudioFocusOwner();
3926+
39243927
// load volume settings for new user
39253928
readAudioSettings(true /*userSwitch*/);
39263929
// preserve STREAM_MUSIC volume from one user to the next.
@@ -3965,6 +3968,32 @@ public void onCallStateChanged(int state, String incomingNumber) {
39653968
}
39663969
};
39673970

3971+
/**
3972+
* Discard the current audio focus owner.
3973+
* Notify top of audio focus stack that it lost focus (regardless of possibility to reassign
3974+
* focus), remove it from the stack, and clear the remote control display.
3975+
*/
3976+
private void discardAudioFocusOwner() {
3977+
synchronized(mAudioFocusLock) {
3978+
if (!mFocusStack.empty() && (mFocusStack.peek().mFocusDispatcher != null)) {
3979+
// notify the current focus owner it lost focus after removing it from stack
3980+
FocusStackEntry focusOwner = mFocusStack.pop();
3981+
try {
3982+
focusOwner.mFocusDispatcher.dispatchAudioFocusChange(
3983+
AudioManager.AUDIOFOCUS_LOSS, focusOwner.mClientId);
3984+
} catch (RemoteException e) {
3985+
Log.e(TAG, "Failure to signal loss of audio focus due to "+ e);
3986+
e.printStackTrace();
3987+
}
3988+
focusOwner.unlinkToDeath();
3989+
// clear RCD
3990+
synchronized(mRCStack) {
3991+
clearRemoteControlDisplay_syncAfRcs();
3992+
}
3993+
}
3994+
}
3995+
}
3996+
39683997
private void notifyTopOfAudioFocusStack() {
39693998
// notify the top of the stack it gained focus
39703999
if (!mFocusStack.empty() && (mFocusStack.peek().mFocusDispatcher != null)) {
@@ -4036,7 +4065,9 @@ private void dumpFocusStack(PrintWriter pw) {
40364065
Iterator<FocusStackEntry> stackIterator = mFocusStack.iterator();
40374066
while(stackIterator.hasNext()) {
40384067
FocusStackEntry fse = stackIterator.next();
4039-
pw.println(" source:" + fse.mSourceRef + " -- client: " + fse.mClientId
4068+
pw.println(" source:" + fse.mSourceRef
4069+
+ " -- pack: " + fse.mPackageName
4070+
+ " -- client: " + fse.mClientId
40404071
+ " -- duration: " + fse.mFocusChangeType
40414072
+ " -- uid: " + fse.mCallingUid
40424073
+ " -- stream: " + fse.mStreamType);
@@ -4718,6 +4749,7 @@ private void dumpRCStack(PrintWriter pw) {
47184749
while(stackIterator.hasNext()) {
47194750
RemoteControlStackEntry rcse = stackIterator.next();
47204751
pw.println(" pi: " + rcse.mMediaIntent +
4752+
" -- pack: " + rcse.mCallingPackageName +
47214753
" -- ercvr: " + rcse.mReceiverComponent +
47224754
" -- client: " + rcse.mRcClient +
47234755
" -- uid: " + rcse.mCallingUid +

0 commit comments

Comments
 (0)