Fix ANR in MediaProvider during database migration

When MediaProvider foreground thread does the database migration, and
main thread is handling MediaUpgradeReceiver#onReceive on main thread,
main thread can run into ANR as MediaUpgradeReceiver will be blocked on
foreground thread for migration.
To avoid this, we run MediaUpgradeReceiver#onReceive on a separate
thread so that main thread is available for handling other MediaService
requests.

Also, added two different locks for internal and external database
migration locks so that these migrations can go in parallel if required.

Bug: 171683776
Test: atest /packages/providers/MediaProvider
Merged-In: I9ea073d4c82301d39ffabb1b3829cc943d495284
Change-Id: I9ea073d4c82301d39ffabb1b3829cc943d495284
2 files changed