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

Commit 2017ddac authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Clamp AIDL stream latency to [1, 3000] ms

Bug: 295055755
Test: atest CtsMediaAudioTestCases
Change-Id: I9fc8c5f9897f0588238b3a405eb645e3471f6c21
parent a017705a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -267,7 +267,11 @@ status_t StreamHalAidl::getLatency(uint32_t *latency) {
    if (status_t status = updateCountersIfNeeded(&reply); status != OK) {
        return status;
    }
    *latency = std::max<int32_t>(0, reply.latencyMs);

    *latency = std::clamp(std::max<int32_t>(0, reply.latencyMs), 1, 3000);
    ALOGW_IF(reply.latencyMs != static_cast<int32_t>(*latency),
             "Suspicious latency value reported by HAL: %d, clamped to %u", reply.latencyMs,
             *latency);
    return OK;
}