Prevent concurrent database upgrades.

MediaProvider contains a seperate MediaUpdateReceiver component, which
only runs as part of the PRE_BOOT_COMPLETED broadcast that is sent when
an OTA has been installed. The goal of MediaUpdateReceiver is to start
migrating the MediaProvider database as early as possible in boot,
because otherwise apps that access the MediaProvider database might
start ANR'ing while waiting for any database migration to happen.

Unfortuntely MediaUpdateReceiver has its own instances of the
DatabaseHelper class, on top of the regular instances in
MediaProvider.java. This means that two threads can try to access the
DatabaseHelper in parallel, and in turn, two threads could also have
their onUpgrade() methods invoked in parallel. While locking might
prevent them from running in parralel, even running them sequentially
would result in fatal errors, because we'd recreate columns that already
exist.

To prevent us from doing the upgrade twice, keep track of upgraded
databases in a static.

Bug: 210593666
Test: TEST_MAPPING
Change-Id: Ib9df31ccc479346b29aad6e30de47499c9103516
1 file changed