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

Commit 589171c8 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: fix capture policy for accessibility

Do not consider Accessibility services when determining
lastest active capture client. As an Accessibility service
capturing does not silence other captures, it should not
prevent another client from being selected as the latest active.

Bug: 135806801
Test: Start capture with Recorder app, activate Voice Access
Change-Id: I864be785752f27201d45ce24f95013de6391dbd6
parent 1c74123a
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)) :