commit | 8ecd6b301234b46ba4ac0848df48337300a195ed | [log] [tgz] |
---|---|---|
author | Lakshman Annadorai <lakshmana@google.com> | Thu Jan 06 20:00:05 2022 -0800 |
committer | Lakshman Annadorai <lakshmana@google.com> | Sat Jan 08 00:25:16 2022 +0000 |
tree | 72e8190bb4f65135f14a32447e4dd5fa323cc62b | |
parent | 67372a6ea7ca9f177cb27fc071dd9b12eae5431b [diff] |
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)
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.