Handle thumbnail generation race conditions.

When multiple threads race for the same thumbnail, the second
thread could return a file with a thumbnail still in
progress. We could add heavy per-ID locking to mitigate this
rare race condition, but it's simpler to have both threads
generate the same thumbnail using temporary files and rename
them into place once finished.

Bug: 147852836
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I98ea9c5bc4262253ec6a1add05c2ede2de569cf9
1 file changed