AudioService: more stringent on dropping ACTION_AUDIO_BECOMING_NOISY

Drop ACTION_AUDIO_BECOMING_NOISY only when there is no more audio
  focus users.

Bug: 129983099
Test: see bug
Change-Id: I899301754ba1506598b1be1cb5605bc3b53e3942
This commit is contained in:
Jean-Michel Trivi
2019-04-13 17:11:50 -07:00
parent f98ada2290
commit c1adecd66a
4 changed files with 17 additions and 2 deletions

View File

@@ -406,6 +406,10 @@ import java.util.ArrayList;
mAudioService.checkVolumeCecOnHdmiConnection(state, caller); mAudioService.checkVolumeCecOnHdmiConnection(state, caller);
} }
/*package*/ boolean hasAudioFocusUsers() {
return mAudioService.hasAudioFocusUsers();
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Message handling on behalf of helper classes // Message handling on behalf of helper classes
/*package*/ void postBroadcastScoConnectionState(int state) { /*package*/ void postBroadcastScoConnectionState(int state) {

View File

@@ -819,11 +819,12 @@ public final class AudioDeviceInventory {
if (((device == musicDevice) || mDeviceBroker.isInCommunication()) if (((device == musicDevice) || mDeviceBroker.isInCommunication())
&& (device == devices) && !mDeviceBroker.hasMediaDynamicPolicy() && (device == devices) && !mDeviceBroker.hasMediaDynamicPolicy()
&& ((musicDevice & AudioSystem.DEVICE_OUT_REMOTE_SUBMIX) == 0)) { && ((musicDevice & AudioSystem.DEVICE_OUT_REMOTE_SUBMIX) == 0)) {
if (!AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0 /*not looking in past*/)) { if (!AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0 /*not looking in past*/)
&& !mDeviceBroker.hasAudioFocusUsers()) {
// no media playback, not a "becoming noisy" situation, otherwise it could cause // no media playback, not a "becoming noisy" situation, otherwise it could cause
// the pausing of some apps that are playing remotely // the pausing of some apps that are playing remotely
AudioService.sDeviceLogger.log((new AudioEventLogger.StringEvent( AudioService.sDeviceLogger.log((new AudioEventLogger.StringEvent(
"dropping ACTION_AUDIO_BECOMING_NOISY, no media playback")).printLog(TAG)); "dropping ACTION_AUDIO_BECOMING_NOISY")).printLog(TAG));
return 0; return 0;
} }
mDeviceBroker.postBroadcastBecomingNoisy(); mDeviceBroker.postBroadcastBecomingNoisy();

View File

@@ -5580,6 +5580,10 @@ public class AudioService extends IAudioService.Stub
return mMediaFocusControl.getFocusRampTimeMs(focusGain, attr); return mMediaFocusControl.getFocusRampTimeMs(focusGain, attr);
} }
/*package*/ boolean hasAudioFocusUsers() {
return mMediaFocusControl.hasAudioFocusUsers();
}
//========================================================================================== //==========================================================================================
private boolean readCameraSoundForced() { private boolean readCameraSoundForced() {
return SystemProperties.getBoolean("audio.camerasound.force", false) || return SystemProperties.getBoolean("audio.camerasound.force", false) ||

View File

@@ -162,6 +162,12 @@ public class MediaFocusControl implements PlayerFocusEnforcer {
} }
} }
/*package*/ boolean hasAudioFocusUsers() {
synchronized (mAudioFocusLock) {
return !mFocusStack.empty();
}
}
/** /**
* Discard the current audio focus owner. * Discard the current audio focus owner.
* Notify top of audio focus stack that it lost focus (regardless of possibility to reassign * Notify top of audio focus stack that it lost focus (regardless of possibility to reassign