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

Commit 8bc54bb6 authored by jiabin's avatar jiabin
Browse files

No need to try mmap path when the vendor property set as NEVER.

When the vendor set the MMAP policy as NEVER, the AAudioService will not
be created. In that case, there is no need to try MMAP path as it will
always fail.

Bug: 242103542
Test: repo steps in the bug
Test: atest AAudioTests
Change-Id: Ia34153bc1464e059f8b65865b4fcb6f83b3a160d
parent 265a0690
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -113,12 +113,28 @@ aaudio_result_t AudioStreamBuilder::build(AudioStream** streamPtr) {
    }

    std::vector<AudioMMapPolicyInfo> policyInfos;
    // The API setting is the highest priority.
    aaudio_policy_t mmapPolicy = AudioGlobal_getMMapPolicy();
    // If not specified then get from a system property.
    if (mmapPolicy == AAUDIO_UNSPECIFIED && android::AudioSystem::getMmapPolicyInfo(
    if (android::AudioSystem::getMmapPolicyInfo(
            AudioMMapPolicyType::DEFAULT, &policyInfos) == NO_ERROR) {
        mmapPolicy = AAudio_getAAudioPolicy(policyInfos);
        aaudio_policy_t systemMmapPolicy = AAudio_getAAudioPolicy(policyInfos);
        if (mmapPolicy == AAUDIO_POLICY_ALWAYS && systemMmapPolicy == AAUDIO_POLICY_NEVER) {
            // No need to try as AAudioService is not created and the client only wants MMAP path.
            return AAUDIO_ERROR_NO_SERVICE;
        }
        // Use system property for mmap policy if
        //    1. The API setting does not specify mmap policy or
        //    2. The system property specifies MMAP policy as never. In this case, AAudioService
        //       will not be started, no need to try mmap path.
        if (mmapPolicy == AAUDIO_UNSPECIFIED || systemMmapPolicy == AAUDIO_POLICY_NEVER) {
            mmapPolicy = systemMmapPolicy;
        }
    } else {
        // If it fails querying mmap policy info, it is highly possible that the AAudioService is
        // not created. In this case, we don't try mmap path.
        if (mmapPolicy == AAUDIO_POLICY_ALWAYS) {
            return AAUDIO_ERROR_NO_SERVICE;
        }
        mmapPolicy = AAUDIO_POLICY_NEVER;
    }
    // If still not specified then use the default.
    if (mmapPolicy == AAUDIO_UNSPECIFIED) {