Reset MediaStore database Uuid on schema reset.

MediaStore version is a combination of database version and uuid(derived
from randomUUID() and stored as xattr in MediaStore database file).

MediaStore version is used by apps to identify any changes in the data
in MediaStore database. This is useful for apps that cache MediaStore
database data. When there is a change in MediaStore version, apps are
advised to update their cache with changed data in MediaStore database.

MediaStore database version can change whenever there is an update in
the schema or change in data in any of the rows and columns that happens
during db upgrade. This shouldn't be confused with data changes in
database due to ContentResolver operations or any implicit database
updates in MediaProvider. Bulk data change in this case happens during
database upgrade or downgrade routine where we don't notify apps about a
particular db row change.

MediaStore Uuid is a random number derived from randomUUID() and stored
as xattr in database file. This will only change if database file is
deleted and recreated.

Hence, if there is database data corruption or database downgrade and
upgrade which doesn't change the database version and doesn't delete the
database file, we don't change the MediaStore version even if this has
dropped database tables and recreated a new table. This is a major
change in MediaStore database data and should be clearly indicated in
MediaStore version so that apps can resync their cache.

To solve this issue, we now reset the Uuid whenever we delete tables and
create new schema, we change the Uuid so that MediaStore version is
changed even if database version hasn't changed.

Bug: 192102594
Test: atest
com.android.providers.media.DatabaseHelperTest#testDowngradeChangesUUID

Change-Id: Ic59d583b35ce18ce7bf3d6cc87a55ac607db3a7d
Merged-In: Ic59d583b35ce18ce7bf3d6cc87a55ac607db3a7d
2 files changed