[BUG] Do not fallback on music group for orphan streams
When using a specific engine configuration file with custom product strategies
definition, it is possible to define a strategy without any stream type attached
to it.
In order to prevent fallback on music when considering activity of non existing
stream, this CL adds an optional fallback parameter to stream to volume source
conversion APIs.
Bug: 179759299
Bug: 187173302
Test: plays with volumes
Signed-off-by: Francois Gaffie <francois.gaffie@renault.com>
Change-Id: I0817586a5ac3f2a8be26bc9fb21ba1c079d28006
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 2487789..bfbd2f5 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1810,7 +1810,7 @@
if (stream == AUDIO_STREAM_TTS) {
ALOGV("\t found BEACON stream");
if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(
- toVolumeSource(AUDIO_STREAM_TTS) /*sourceToIgnore*/)) {
+ toVolumeSource(AUDIO_STREAM_TTS, false) /*sourceToIgnore*/)) {
return INVALID_OPERATION;
} else {
beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
@@ -2842,7 +2842,7 @@
// handled by system UI
status_t volStatus = checkAndSetVolume(
curves, vs, index, desc, curDevices,
- ((vs == toVolumeSource(AUDIO_STREAM_SYSTEM))?
+ ((vs == toVolumeSource(AUDIO_STREAM_SYSTEM, false))?
TOUCH_SOUND_FIXED_DELAY_MS : 0));
if (volStatus != NO_ERROR) {
status = volStatus;
@@ -3044,12 +3044,14 @@
bool AudioPolicyManager::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
{
- return mOutputs.isActive(toVolumeSource(stream), inPastMs);
+ auto vs = toVolumeSource(stream, false);
+ return vs != VOLUME_SOURCE_NONE ? mOutputs.isActive(vs, inPastMs) : false;
}
bool AudioPolicyManager::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
{
- return mOutputs.isActiveRemotely(toVolumeSource(stream), inPastMs);
+ auto vs = toVolumeSource(stream, false);
+ return vs != VOLUME_SOURCE_NONE ? mOutputs.isActiveRemotely(vs, inPastMs) : false;
}
bool AudioPolicyManager::isSourceActive(audio_source_t source) const
@@ -5868,7 +5870,7 @@
auto doGetOutputDevicesForVoice = [&]() {
return hasVoiceStream(streams) && (outputDesc == mPrimaryOutput ||
- outputDesc->isActive(toVolumeSource(AUDIO_STREAM_VOICE_CALL))) &&
+ outputDesc->isActive(toVolumeSource(AUDIO_STREAM_VOICE_CALL, false))) &&
(isInCall() ||
mOutputs.isStrategyActiveOnSameModule(productStrategy, outputDesc)) &&
!isStreamActive(AUDIO_STREAM_ENFORCED_AUDIBLE, 0);
@@ -5964,7 +5966,7 @@
devices.merge(curDevices);
for (audio_io_handle_t output : getOutputsForDevices(curDevices, mOutputs)) {
sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
- if (outputDesc->isActive(toVolumeSource(curStream))) {
+ if (outputDesc->isActive(toVolumeSource(curStream, false))) {
activeDevices.merge(outputDesc->devices());
}
}
@@ -6065,7 +6067,11 @@
// mute/unmute AUDIO_STREAM_TTS on all outputs
ALOGV("\t muting %d", mute);
uint32_t maxLatency = 0;
- auto ttsVolumeSource = toVolumeSource(AUDIO_STREAM_TTS);
+ auto ttsVolumeSource = toVolumeSource(AUDIO_STREAM_TTS, false);
+ if (ttsVolumeSource == VOLUME_SOURCE_NONE) {
+ ALOGV("\t no tts volume source available");
+ return 0;
+ }
for (size_t i = 0; i < mOutputs.size(); i++) {
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
setVolumeSourceMute(ttsVolumeSource, mute/*on*/, desc, 0 /*delay*/, DeviceTypeSet());
@@ -6401,11 +6407,11 @@
// louder than the accessibility prompt, the prompt cannot be heard, thus masking the touch
// exploration of the dialer UI. In this situation, bring the accessibility volume closer to
// the ringtone volume
- const auto callVolumeSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL);
- const auto ringVolumeSrc = toVolumeSource(AUDIO_STREAM_RING);
- const auto musicVolumeSrc = toVolumeSource(AUDIO_STREAM_MUSIC);
- const auto alarmVolumeSrc = toVolumeSource(AUDIO_STREAM_ALARM);
- const auto a11yVolumeSrc = toVolumeSource(AUDIO_STREAM_ACCESSIBILITY);
+ const auto callVolumeSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL, false);
+ const auto ringVolumeSrc = toVolumeSource(AUDIO_STREAM_RING, false);
+ const auto musicVolumeSrc = toVolumeSource(AUDIO_STREAM_MUSIC, false);
+ const auto alarmVolumeSrc = toVolumeSource(AUDIO_STREAM_ALARM, false);
+ const auto a11yVolumeSrc = toVolumeSource(AUDIO_STREAM_ACCESSIBILITY, false);
if (volumeSource == a11yVolumeSrc
&& (AUDIO_MODE_RINGTONE == mEngine->getPhoneState()) &&
@@ -6418,12 +6424,12 @@
// in-call: always cap volume by voice volume + some low headroom
if ((volumeSource != callVolumeSrc && (isInCall() ||
mOutputs.isActiveLocally(callVolumeSrc))) &&
- (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM) ||
+ (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM, false) ||
volumeSource == ringVolumeSrc || volumeSource == musicVolumeSrc ||
volumeSource == alarmVolumeSrc ||
- volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION) ||
- volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE) ||
- volumeSource == toVolumeSource(AUDIO_STREAM_DTMF) ||
+ volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION, false) ||
+ volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false) ||
+ volumeSource == toVolumeSource(AUDIO_STREAM_DTMF, false) ||
volumeSource == a11yVolumeSrc)) {
auto &voiceCurves = getVolumeCurves(callVolumeSrc);
int voiceVolumeIndex = voiceCurves.getVolumeIndex(deviceTypes);
@@ -6461,9 +6467,9 @@
AUDIO_DEVICE_OUT_BLE_HEADSET}).empty() &&
((volumeSource == alarmVolumeSrc ||
volumeSource == ringVolumeSrc) ||
- (volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION)) ||
- (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM)) ||
- ((volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE)) &&
+ (volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION, false)) ||
+ (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM, false)) ||
+ ((volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false)) &&
(mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_NONE))) &&
curves.canBeMuted()) {
@@ -6549,10 +6555,10 @@
outputDesc->getMuteCount(volumeSource), outputDesc->isActive(volumeSource));
return NO_ERROR;
}
- VolumeSource callVolSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL);
- VolumeSource btScoVolSrc = toVolumeSource(AUDIO_STREAM_BLUETOOTH_SCO);
- bool isVoiceVolSrc = callVolSrc == volumeSource;
- bool isBtScoVolSrc = btScoVolSrc == volumeSource;
+ VolumeSource callVolSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL, false);
+ VolumeSource btScoVolSrc = toVolumeSource(AUDIO_STREAM_BLUETOOTH_SCO, false);
+ bool isVoiceVolSrc = (volumeSource != VOLUME_SOURCE_NONE) && (callVolSrc == volumeSource);
+ bool isBtScoVolSrc = (volumeSource != VOLUME_SOURCE_NONE) && (btScoVolSrc == volumeSource);
bool isScoRequested = isScoRequestedForComm();
// do not change in call volume if bluetooth is connected and vice versa
@@ -6621,8 +6627,10 @@
for (auto attributes: mEngine->getAllAttributesForProductStrategy(strategy)) {
ALOGVV("%s() attributes %s, mute %d, output ID %d", __func__,
toString(attributes).c_str(), on, outputDesc->getId());
- VolumeSource source = toVolumeSource(attributes);
- if (std::find(begin(sourcesToMute), end(sourcesToMute), source) == end(sourcesToMute)) {
+ VolumeSource source = toVolumeSource(attributes, false);
+ if ((source != VOLUME_SOURCE_NONE) &&
+ (std::find(begin(sourcesToMute), end(sourcesToMute), source)
+ == end(sourcesToMute))) {
sourcesToMute.push_back(source);
}
}
@@ -6645,7 +6653,7 @@
if (on) {
if (!outputDesc->isMuted(volumeSource)) {
if (curves.canBeMuted() &&
- (volumeSource != toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE) ||
+ (volumeSource != toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false) ||
(mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) ==
AUDIO_POLICY_FORCE_NONE))) {
checkAndSetVolume(curves, volumeSource, 0, outputDesc, deviceTypes, delayMs);