audio policy: fix camera shutter sound
Fix regression in camera shutter sound when system stream
volume is 0.
Bug: 132696227
Test: repro steps in bug.
Test: regressions when camera sound is enforced
Change-Id: I76b4a5ee041f97c5f771c003bf4f99327d797096
diff --git a/services/audiopolicy/engine/common/src/EngineBase.cpp b/services/audiopolicy/engine/common/src/EngineBase.cpp
index 530a2e4..07a7e65 100644
--- a/services/audiopolicy/engine/common/src/EngineBase.cpp
+++ b/services/audiopolicy/engine/common/src/EngineBase.cpp
@@ -70,20 +70,7 @@
audio_stream_type_t EngineBase::getStreamTypeForAttributes(const audio_attributes_t &attr) const
{
- audio_stream_type_t engineStream = mProductStrategies.getStreamTypeForAttributes(attr);
- // ensure the audibility flag for sonification is honored for stream types
- // Note this is typically implemented in the product strategy configuration files, but is
- // duplicated here for safety.
- if (attr.usage == AUDIO_USAGE_ASSISTANCE_SONIFICATION
- && ((attr.flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) != 0)) {
- engineStream = AUDIO_STREAM_ENFORCED_AUDIBLE;
- }
- // ensure the ENFORCED_AUDIBLE stream type reflects the "force use" setting:
- if ((getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)
- && (engineStream == AUDIO_STREAM_ENFORCED_AUDIBLE)) {
- return AUDIO_STREAM_SYSTEM;
- }
- return engineStream;
+ return mProductStrategies.getStreamTypeForAttributes(attr);
}
audio_attributes_t EngineBase::getAttributesForStreamType(audio_stream_type_t stream) const
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index c430488..575a6c2 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -777,6 +777,12 @@
// check for device and output changes triggered by new force usage
checkForDeviceAndOutputChanges();
+ // force client reconnection to reevaluate flag AUDIO_FLAG_AUDIBILITY_ENFORCED
+ if (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM) {
+ mpClientInterface->invalidateStream(AUDIO_STREAM_SYSTEM);
+ mpClientInterface->invalidateStream(AUDIO_STREAM_ENFORCED_AUDIBLE);
+ }
+
//FIXME: workaround for truncated touch sounds
// to be removed when the problem is handled by system UI
uint32_t delayMs = 0;
@@ -910,6 +916,13 @@
}
*dstAttr = mEngine->getAttributesForStreamType(srcStream);
}
+
+ // Only honor audibility enforced when required. The client will be
+ // forced to reconnect if the forced usage changes.
+ if (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
+ dstAttr->flags &= ~AUDIO_FLAG_AUDIBILITY_ENFORCED;
+ }
+
return NO_ERROR;
}