Fix ANR when migrating large databases.

Partners have helped identify a case where DocumentsUI can end up
wedged while trying to query for MediaDocumentsProvider roots, since
the checks for isEmpty() need a working post-migration database.

To work around this, we return an empty set of SAF roots while the
upgrade is ongoing, and we invalidate our roots once the database
is finally ready, which triggers a DocumentsUI refresh.

Also two additional performance optimizations: first, we ignore
recalculation of fields in legacy databases when we know that we'll
simply recalculate them again moments later after the migration, and
second we drop indexes during the migration and recreate them once
the migration is finished.

Bug: 153842860
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I4d7874d99e31420517f55f9cfeead6c5da726b2b
4 files changed