Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20d2e03e authored by lpeter's avatar lpeter
Browse files

Use PermissionChecker (av) in captureAudioOutputAllowed method

PermissionChecker now includes some higher level logic for allowing the
HotwordDetectionService to grant CAPTURE_AUDIO_OUTPUT permission.

We have a similar change to grant RECORD_AUDIO and CAPTURE_AUDIO_HOTWORD
permissions to HotwordDetectionService before.
(ag/14427323 and ag/14883678)

Bug: 228328385
Test: atest CtsVoiceInteractionTestCases
Change-Id: I1b23f6af75bd680ff8c3a58b357668678238f591
parent f6523efd
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -181,10 +181,14 @@ void finishRecording(const AttributionSourceState& attributionSource, audio_sour

bool captureAudioOutputAllowed(const AttributionSourceState& attributionSource) {
    uid_t uid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t(attributionSource.uid));
    pid_t pid = VALUE_OR_FATAL(aidl2legacy_int32_t_pid_t(attributionSource.pid));
    if (isAudioServerOrRootUid(uid)) return true;
    static const String16 sCaptureAudioOutput("android.permission.CAPTURE_AUDIO_OUTPUT");
    bool ok = PermissionCache::checkPermission(sCaptureAudioOutput, pid, uid);
    // Use PermissionChecker, which includes some logic for allowing the isolated
    // HotwordDetectionService to hold certain permissions.
    permission::PermissionChecker permissionChecker;
    bool ok = (permissionChecker.checkPermissionForPreflight(
            sCaptureAudioOutput, attributionSource, String16(),
            AppOpsManager::OP_NONE) != permission::PermissionChecker::PERMISSION_HARD_DENIED);
    if (!ok) ALOGV("Request requires android.permission.CAPTURE_AUDIO_OUTPUT");
    return ok;
}