Reduce time consuming when a lot of audio port event happen continually.
Since the AudioPortEventHandler runs in application's main thread, it
may cause ANR if there are a lot of setForceUse calling by the
application continually in a short time. The root cause is that there
may be a lot of audio port event from the native side when there are a
lot of device switching request. In this case, updating audio port cache
may take a long time due to inconsistency between audio port generation
and patches generation.
To solve this problem, we only check the generation once when ports and
patches are both requested to return earlier. In the meantime, we only
repeat the last audio port event since we will refresh the ports cache
every time when we receive the event.
Bug: 64952619
Test: keep switching output device in hangout video/voice chat
Change-Id: I3164c4e331950a481b76ce890d8c1403fd9b98ee
2 files changed