Add application wide capture policy
Apps were previously forced to set their allowed capture policy from
either their manifest which is not flexible or from each track which is
a very fine grain but difficult when using libraries like exoplayer.
Thus add an application level policy set with AudioManager.
Test: atest android.media.cts.AudioPlaybackCaptureTest
Bug: 111453086
Change-Id: Ic890b5b041affea757fbd3f2707ff2ce18771828
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index e8e9fa6..ee0e1bd 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -945,6 +945,9 @@
if (status != NO_ERROR) {
return status;
}
+ if (auto it = mAllowedCapturePolicies.find(uid); it != end(mAllowedCapturePolicies)) {
+ resultAttr->flags |= it->second;
+ }
*stream = mEngine->getStreamTypeForAttributes(*resultAttr);
ALOGV("%s() attributes=%s stream=%s session %d selectedDeviceId %d", __func__,
@@ -3022,6 +3025,11 @@
mPolicyMixes.dump(dst);
mAudioSources.dump(dst);
+ dst->appendFormat(" AllowedCapturePolicies:\n");
+ for (auto& policy : mAllowedCapturePolicies) {
+ dst->appendFormat(" - uid=%d flag_mask=%#x\n", policy.first, policy.second);
+ }
+
dst->appendFormat("\nPolicy Engine dump:\n");
mEngine->dump(dst);
}
@@ -3034,6 +3042,12 @@
return NO_ERROR;
}
+status_t AudioPolicyManager::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy)
+{
+ mAllowedCapturePolicies[uid] = capturePolicy;
+ return NO_ERROR;
+}
+
// This function checks for the parameters which can be offloaded.
// This can be enhanced depending on the capability of the DSP and policy
// of the system.