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

Commit 44302851 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "audio policy: fix capture policy for accessibility" into qt-r1-dev

parents b94ff285 589171c8
Loading
Loading
Loading
Loading
+32 −13
Original line number Diff line number Diff line
@@ -416,6 +416,11 @@ void AudioPolicyService::updateUidStates_l()
//            AND there is no active privacy sensitive capture or call
//                OR client has CAPTURE_AUDIO_OUTPUT privileged permission
//    OR The client is an accessibility service
//        AND Is on TOP
//                AND the source is VOICE_RECOGNITION or HOTWORD
//            OR The assistant is not on TOP
//                AND there is no active privacy sensitive capture or call
//                    OR client has CAPTURE_AUDIO_OUTPUT privileged permission
//        AND is on TOP
//        AND the source is VOICE_RECOGNITION or HOTWORD
//    OR the client source is virtual (remote submix, call audio TX or RX...)
@@ -460,7 +465,8 @@ void AudioPolicyService::updateUidStates_l()
        }

        bool isAssistant = mUidPolicy->isAssistantUid(current->uid);
        if (appState == APP_STATE_TOP) {
        bool isAccessibility = mUidPolicy->isA11yUid(current->uid);
        if (appState == APP_STATE_TOP && !isAccessibility) {
            if (current->startTimeNs > topStartNs) {
                topActive = current;
                topStartNs = current->startTimeNs;
@@ -469,10 +475,13 @@ void AudioPolicyService::updateUidStates_l()
                isAssistantOnTop = true;
            }
        }
        // Assistant capturing for HOTWORD not considered for latest active to avoid
        // masking regular clients started before
        if (current->startTimeNs > latestStartNs &&
            !(current->attributes.source == AUDIO_SOURCE_HOTWORD && isAssistant)) {
        // Assistant capturing for HOTWORD or Accessibility services not considered
        // for latest active to avoid masking regular clients started before
        if (current->startTimeNs > latestStartNs
                && !((current->attributes.source == AUDIO_SOURCE_HOTWORD
                        || isA11yOnTop || rttCallActive)
                    && isAssistant)
                && !isAccessibility) {
            latestActive = current;
            latestStartNs = current->startTimeNs;
        }
@@ -546,10 +555,20 @@ void AudioPolicyService::updateUidStates_l()
            // For accessibility service allow capture if:
            //     Is on TOP
            //          AND the source is VOICE_RECOGNITION or HOTWORD
            if (isA11yOnTop &&
                    (source == AUDIO_SOURCE_VOICE_RECOGNITION || source == AUDIO_SOURCE_HOTWORD)) {
            //     Or
            //          The assistant is not on TOP
            //          AND there is no active privacy sensitive capture or call
            //             OR client has CAPTURE_AUDIO_OUTPUT privileged permission
            if (isA11yOnTop) {
                if (source == AUDIO_SOURCE_VOICE_RECOGNITION || source == AUDIO_SOURCE_HOTWORD) {
                    allowCapture = true;
                }
            } else {
                if (!isAssistantOnTop
                        && (!(isSensitiveActive || isInCall) || current->canCaptureOutput)) {
                    allowCapture = true;
                }
            }
        }
        setAppState_l(current->uid,
                      allowCapture ? apmStatFromAmState(mUidPolicy->getUidState(current->uid)) :