Avoid SQLite deadlock by closing completely.

We've capture traces that demonstrate a lock inversion while
processing setFilterVolumeNames(), since it attempts to call
closeAvailableNonPrimaryConnectionsAndLogExceptions() while holding
a transaction.  Other threads may call acquireConnection() during
this time, causing a deadlock.

To workaround this, we adjust setFilterVolumeNames() to perform a
full database close().  Any future calls will simply reopen the
database connections from scratch, which will ensure that the
updated views are recreated.

Also improve stability further by having tests waitForIdle()
before they start working with the legacy provider.

Bug: 152005629
Test: atest MediaProviderClientTests:com.android.providers.media.client.LegacyProviderMigrationTest --rerun-until-failure 100
Change-Id: I8f54bcaf8521f1149a089d44139ca74e604b4468
3 files changed