mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00

Some commands may be asynchronous and subsequent commands need to wait for them to complete before running. This change updates the queue to use (and listen to) Futures instead of calling Runnables directly. The commands are currently still added as Runanbles though, so this change is a no-op. Also moves the permission check in MediaSessionImpl to before queueing the command because the permission should be check at the time of calling the method. When executing the comamnds in the queue, we need to be careful to avoid recursion in the same thread (which happens when both the Future is immediate and running on the correct thread already). To avoid recursion, we detect this case and loop the commands instead. Issue: androidx/media#85 PiperOrigin-RevId: 461827264 (cherry picked from commit dee80788e4fc5e82739ae014a5d2759b77f03daa)