Simplifying some test utility methods

Bug: 283821111
Test: Presubmit
Flag: N/A
Change-Id: I7b9690bc0cc53d097d26cd4f0ab2dd36ba88e1cb
This commit is contained in:
Sunny Goyal
2023-05-25 19:20:10 -07:00
parent 0edac04688
commit ee9740462e
18 changed files with 171 additions and 193 deletions

View File

@@ -280,13 +280,29 @@ public class ModelDbController {
mOpenHelper.getReadableDatabase(), Favorites.HYBRID_HOTSEAT_BACKUP_TABLE);
}
/**
* Migrates the DB if needed. If the migration failed, it clears the DB.
*/
public void tryMigrateDB() {
if (!migrateGridIfNeeded()) {
Log.d(TAG, "Migration failed: resetting launcher database");
createEmptyDB();
LauncherPrefs.get(mContext).putSync(
getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()).to(true));
// Write the grid state to avoid another migration
new DeviceGridState(LauncherAppState.getIDP(mContext)).writeToPrefs(mContext);
}
}
/**
* Migrates the DB if needed, and returns false if the migration failed
* and DB needs to be cleared.
* @return true if migration was success or ignored, false if migration failed
* and the DB should be reset.
*/
public boolean migrateGridIfNeeded() {
private boolean migrateGridIfNeeded() {
createDbIfNotExists();
InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
if (!GridSizeMigrationUtil.needsToMigrate(mContext, idp)) {