audio policy: fix several problems with capture policy
- Fix accessibility service not able to get same policy as regular apps
when not using VOICE_RECOGNITION source b/126785297
- Make sure two captures from same app do not silence each other
(e.g two privacy sensitive captures concurrently)
- Ignore clients in idle state when considering priority active clients in
silencing logic.
- Prevent capture while in call if privileged permission CAPTURE_AUDIO_OUTPUT
is not granted
- Allow capture concurrently with privacy sensitive capture or call if
permission CAPTURE_AUDIO_OUTPUT is granted.
- Do not silence virtual sources when sensor privacy is enabled.
- Consider system persistent service as top app state.
Bug: 128419018
Bug: 126785297
Test: audio smoke tests
Change-Id: I7f8c7c511c674d4d46a815eaa7e9cf95e95cc3f9
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index a672521..ea6ca39 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -376,15 +376,17 @@
return PERMISSION_DENIED;
}
+ bool canCaptureOutput = captureAudioOutputAllowed(pid, uid);
if ((attr->source == AUDIO_SOURCE_VOICE_UPLINK ||
attr->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
attr->source == AUDIO_SOURCE_VOICE_CALL ||
attr->source == AUDIO_SOURCE_ECHO_REFERENCE) &&
- !captureAudioOutputAllowed(pid, uid)) {
+ !canCaptureOutput) {
return PERMISSION_DENIED;
}
- if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) {
+ bool canCaptureHotword = captureHotwordAllowed(pid, uid);
+ if ((attr->source == AUDIO_SOURCE_HOTWORD) && !canCaptureHotword) {
return BAD_VALUE;
}
@@ -415,7 +417,7 @@
case AudioPolicyInterface::API_INPUT_TELEPHONY_RX:
// FIXME: use the same permission as for remote submix for now.
case AudioPolicyInterface::API_INPUT_MIX_CAPTURE:
- if (!captureAudioOutputAllowed(pid, uid)) {
+ if (!canCaptureOutput) {
ALOGE("getInputForAttr() permission denied: capture not allowed");
status = PERMISSION_DENIED;
}
@@ -442,7 +444,8 @@
}
sp<AudioRecordClient> client = new AudioRecordClient(*attr, *input, uid, pid, session,
- *selectedDeviceId, opPackageName);
+ *selectedDeviceId, opPackageName,
+ canCaptureOutput, canCaptureHotword);
mAudioRecordClients.add(*portId, client);
}