Catch any database access on main thread.

Obtaining a database from the main thread can trigger an ANR if we
end up executing long-running upgrade steps.

Fix one case uncovered by this case by moving ensureDefaultFolders()
to a background thread.  Also fix obscure bug where wrong database
was being used.

Bug: 135201004, 140789081
Test: atest --test-mapping packages/apps/MediaProvider
Change-Id: I5713a19532f0bdac6ae2a86ba333ee8a4d92a8e6
3 files changed