Replace primary key in UserPackageSettings table.

- Add an autoincrementing integer as the new primary key for
UserPackageSettings table and make dependent table use this primary key
as their foreign key.
   - IoUsageStats table used the rowid of UserPackageSettings table as
   one of its primary keys and had a foreign key dependency on
   the rowid. But using rowid as a primary key is discouraged because
   the rowid of an entry is not guaranteed to be the same and can
   change when the table shrinks.
- Upgrade the database version and implement the onUpgrade method to
migrate the settings from the old UserPackageSettings table to the
new UserPackageSettings table.
  - IoUsageStats table has mappable entries only for the current date
  because the rowids of the historic stats are not mappable. So, drop
  this table on upgrade.
- Update the logic to save entries in UserPackageSettings table such
that any update to existing entries are done via DB update SQL and new
entries are added via DB replace SQL. This is to ensure the primary key
doesn't autoincrement for existing entries. Otherwise, dependent entries
in other tables will be deleted.
- Enable foreign key constrain in the database, so IoUsageStats entries
are in sync with the UserPackageSettings entries.

Test: atest WatchdogStorageUnitTest
Bug: 213190011

Change-Id: I34a3aba2ff337abcbdc9cde049c7829428391344
Merged-In: I34a3aba2ff337abcbdc9cde049c7829428391344
(cherry-picked from commit c1fd80853b6afa92ae555ae6c8bf92e230b9b31d)
2 files changed
tree: 72e8190bb4f65135f14a32447e4dd5fa323cc62b
  1. car-admin-ui-lib/
  2. car-internal-lib/
  3. car-lib/
  4. car-maps-placeholder/
  5. car-systemtest-lib/
  6. car-test-lib/
  7. car-usb-handler/
  8. car_product/
  9. cpp/
  10. data/
  11. experimental/
  12. FrameworkPackageStubs/
  13. obd2-lib/
  14. packages/
  15. procfs-inspector/
  16. service/
  17. tests/
  18. tools/
  19. user/
  20. vehicle-hal-support-lib/
  21. .clang-format
  22. .gitignore
  23. Android.mk
  24. CleanSpec.mk
  25. CPPLINT.cfg
  26. OWNERS
  27. PREUPLOAD.cfg
  28. README.md
  29. TEST_MAPPING
README.md

Native (C++) code format is required to be compatible with .clang-format file. Run

git clang-format --style=file --extension='h,cpp,cc' HEAD~

Note that clang-format is not desirable for Android java files. Therefore the command line above is limited to specific extensions.