KeyChain: Do not attempt re-creating existing table

Due to a bug, it is possible to have a "V1" KeyChain grants.db database
that is not actually V1, in the sense that it already contains the
userselectable table (this would happen on devices upgrading from P
to P).

That caused the code added for handling database upgrades to throw an
exception if it found a V1 database and tried to create the
userselectable table, when it already exists.

To resolve the issue, find out if the userselectable table exists during
a V1 database upgrade, and only proceed with creating and filling it if
it does not already exist.

This CL also adds a future-proofing test to make sure that the content
of V2 databases does not get modified during future upgrades.

Bug: 76143437
Test: m -j RunKeyChainRoboTests
Change-Id: Ia03cd132084ec740cc16de7cc5440fcf4e494765
2 files changed
tree: 116ab52a9b592e2c215cbaec82f3f0c99620b0d1
  1. res/
  2. robotests/
  3. src/
  4. support/
  5. tests/
  6. Android.mk
  7. AndroidManifest.xml