Introduce "generation" to track mutations.
Add generation numbers to the metadata for each media item. This is
useful for apps that are attempting to quickly identify exactly
which media items have changed since a previous point in
time. Generation numbers are monotonically increasing over time, and
can be safely arithmetically compared.
Detecting media changes using generation numbers is more robust than
using DATE_MODIFIED, since those values may change in unexpected
ways when apps use File.setLastModified() or when the system clock
is set incorrectly.
This is implemented by ensuring that all mutations to go through
our local SQLiteQueryBuilder, which then forces those mutations to
always happen inside an active transaction. Then each time we
create a transaction, we increment the generation counter, and
force-copy the current generation into any mutation operations.
This design also means that all mutations that should affect the
generation counter must go through DatabaseHelper to ensure that
the logic above is applied; there's mechanical refactoring across
MediaProvider to accomplish this.
Fix bug in getWritableDatabase() that could return a readable
database. Fix bug in LegacyMediaProvider to create missing
directories. Adjust logging script to enable log cleaner SQL from
SQLQueryBuilder instead of noisy raw logs.
Bug: 140248585
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: If87f586e2340688ea1716682de20ee40c0d2b953
1 file changed