Skip to content

Commit 5bfaeae

Browse files
author
Eric Laurent
committed
pause music playback when switching user.
AudioService sends AudioManager.ACTION_AUDIO_BECOMING_NOISY intent when notified of a user switch to pause music playback for all background users. Bug 7128886. Change-Id: I6a24409533bf40c517c43da25b9baeceb3379cb8
1 parent 2c0feea commit 5bfaeae

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

media/java/android/media/AudioService.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
154154
private static final int MSG_SET_RSX_CONNECTION_STATE = 23; // change remote submix connection
155155
private static final int MSG_SET_FORCE_RSX_USE = 24; // force remote submix audio routing
156156
private static final int MSG_CHECK_MUSIC_ACTIVE = 25;
157+
private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 26;
157158

158159
// flags for MSG_PERSIST_VOLUME indicating if current and/or last audible volume should be
159160
// persisted
@@ -3252,6 +3253,10 @@ public void handleMessage(Message msg) {
32523253
case MSG_CHECK_MUSIC_ACTIVE:
32533254
onCheckMusicActive();
32543255
break;
3256+
3257+
case MSG_BROADCAST_AUDIO_BECOMING_NOISY:
3258+
onSendBecomingNoisyIntent();
3259+
break;
32553260
}
32563261
}
32573262
}
@@ -3308,7 +3313,7 @@ private void makeA2dpDeviceAvailable(String address) {
33083313
address);
33093314
}
33103315

3311-
private void sendBecomingNoisyIntent() {
3316+
private void onSendBecomingNoisyIntent() {
33123317
sendBroadcastToAll(new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
33133318
}
33143319

@@ -3443,8 +3448,14 @@ private int checkSendBecomingNoisyIntent(int device, int state) {
34433448
}
34443449
}
34453450
if (devices == device) {
3451+
sendMsg(mAudioHandler,
3452+
MSG_BROADCAST_AUDIO_BECOMING_NOISY,
3453+
SENDMSG_REPLACE,
3454+
0,
3455+
0,
3456+
null,
3457+
0);
34463458
delay = 1000;
3447-
sendBecomingNoisyIntent();
34483459
}
34493460
}
34503461

@@ -3710,6 +3721,15 @@ public void onReceive(Context context, Intent intent) {
37103721
} else if (action.equalsIgnoreCase(Intent.ACTION_CONFIGURATION_CHANGED)) {
37113722
handleConfigurationChanged(context);
37123723
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
3724+
// attempt to stop music playabck for background user
3725+
sendMsg(mAudioHandler,
3726+
MSG_BROADCAST_AUDIO_BECOMING_NOISY,
3727+
SENDMSG_REPLACE,
3728+
0,
3729+
0,
3730+
null,
3731+
0);
3732+
// load volume settings for new user
37133733
readAudioSettings(true /*userSwitch*/);
37143734
// preserve STREAM_MUSIC volume from one user to the next.
37153735
sendMsg(mAudioHandler,

0 commit comments

Comments
 (0)