Rewrite MediaStore thumbnail internals.

Keeps existing public APIs intact, but rewrite the internal to pave
the way for storage changes coming in Q.  All thumbnail generation
and reading now happens in MediaProvider, since apps won't have
direct access to MiniThumbFile files in Q.

Instead, InternalThumbnails now uses openTypedAssetFileDescriptor()
to open the original Uri, but with an EXTRA_SIZE indicating that
it'd like a thumbnail of a specific size.  This uses best-practices
which allow apps obtaining a Uri permission grant to a specific
media Uri to request a thumbnail of that media without additional
permissions.  This also lets us use CancellationSignal to cancel
thumbnail requests that are no longer needed, and we start checking
this signal at each query() point internally.

Move internals to use ExecutorService pattern, which will let us
expand the thread pool in a future CL based on device capabilities.

Previous logic that asynchronously generated thumbnails after certain
actions is now replaced with simpler invalidation.  This paves the
way for us to move proactive thumbnail generation to be driven by an
idle maintenance service, to be better stewards of battery life.  We
continue to generate thumbnails on-demand when not yet cached.

ThumbnailUtils already handles extracting EXIF thumbnails, so we don't
need to duplicate that work locally.

Flag that enables dumping of all raw SQL for debugging purposes on
a per-process basis.

Bug: 111268862, 111890672
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: Ibcdbc564c8fee09ddd33ebccc470fa5cbdff97b4
2 files changed