Skip to content

Commit 72787c1

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Relax rules for media apps to stay on RemoteControlDisplay" into jb-mr1-dev
2 parents 39df578 + 1f9196a commit 72787c1

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

media/java/android/media/AudioService.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,9 +3660,10 @@ private void dumpFocusStack(PrintWriter pw) {
36603660
Iterator<FocusStackEntry> stackIterator = mFocusStack.iterator();
36613661
while(stackIterator.hasNext()) {
36623662
FocusStackEntry fse = stackIterator.next();
3663-
pw.println(" source:" + fse.mSourceRef + " -- client: " + fse.mClientId
3663+
pw.println(" source:" + fse.mSourceRef + " -- client: " + fse.mClientId
36643664
+ " -- duration: " + fse.mFocusChangeType
3665-
+ " -- uid: " + fse.mCallingUid);
3665+
+ " -- uid: " + fse.mCallingUid
3666+
+ " -- stream: " + fse.mStreamType);
36663667
}
36673668
}
36683669
}
@@ -4022,7 +4023,7 @@ private void filterVoiceInputKeyEvent(KeyEvent keyEvent, boolean needWakeLock) {
40224023
startVoiceBasedInteractions(needWakeLock);
40234024
break;
40244025
case VOICEBUTTON_ACTION_SIMULATE_KEY_PRESS:
4025-
if (DEBUG_RC) Log.v(TAG, " send simulated key event");
4026+
if (DEBUG_RC) Log.v(TAG, " send simulated key event, wakelock=" + needWakeLock);
40264027
sendSimulatedMediaButtonEvent(keyEvent, needWakeLock);
40274028
break;
40284029
}
@@ -4654,17 +4655,40 @@ private void checkUpdateRemoteControlDisplay_syncAfRcs(int infoChangedFlags) {
46544655
clearRemoteControlDisplay_syncAfRcs();
46554656
return;
46564657
}
4657-
// if the top of the two stacks belong to different packages, there is a mismatch, clear
4658+
4659+
// determine which entry in the AudioFocus stack to consider, and compare against the
4660+
// top of the stack for the media button event receivers : simply using the top of the
4661+
// stack would make the entry disappear from the RemoteControlDisplay in conditions such as
4662+
// notifications playing during music playback.
4663+
// crawl the AudioFocus stack until an entry is found with the following characteristics:
4664+
// - focus gain on STREAM_MUSIC stream
4665+
// - non-transient focus gain on a stream other than music
4666+
FocusStackEntry af = null;
4667+
Iterator<FocusStackEntry> stackIterator = mFocusStack.iterator();
4668+
while(stackIterator.hasNext()) {
4669+
FocusStackEntry fse = (FocusStackEntry)stackIterator.next();
4670+
if ((fse.mStreamType == AudioManager.STREAM_MUSIC)
4671+
|| (fse.mFocusChangeType == AudioManager.AUDIOFOCUS_GAIN)) {
4672+
af = fse;
4673+
break;
4674+
}
4675+
}
4676+
if (af == null) {
4677+
clearRemoteControlDisplay_syncAfRcs();
4678+
return;
4679+
}
4680+
4681+
// if the audio focus and RC owners belong to different packages, there is a mismatch, clear
46584682
if ((mRCStack.peek().mCallingPackageName != null)
4659-
&& (mFocusStack.peek().mPackageName != null)
4683+
&& (af.mPackageName != null)
46604684
&& !(mRCStack.peek().mCallingPackageName.compareTo(
4661-
mFocusStack.peek().mPackageName) == 0)) {
4685+
af.mPackageName) == 0)) {
46624686
clearRemoteControlDisplay_syncAfRcs();
46634687
return;
46644688
}
46654689
// if the audio focus didn't originate from the same Uid as the one in which the remote
46664690
// control information will be retrieved, clear
4667-
if (mRCStack.peek().mCallingUid != mFocusStack.peek().mCallingUid) {
4691+
if (mRCStack.peek().mCallingUid != af.mCallingUid) {
46684692
clearRemoteControlDisplay_syncAfRcs();
46694693
return;
46704694
}

0 commit comments

Comments
 (0)