Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7df93d28 authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Setup infrastructure (multi-db support) for the new grid migration algorithm

We'll have a db for each grid option and a db for back up / restore.

TODO(pinyaoting): support back up / restore using the new infrastructure, particularly calls to GridBackupTable should use different DBs when the feature flag (NEW_GRID_MIGRATION_ALGORITHM) is on.

Bug: 144052802
Test: N/A

Change-Id: I644a3e70148bd78204a747a337446a3c038f616f
parent 328c9e5a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@
        <attr name="numFolderColumns" format="integer" />
        <!-- numHotseatIcons defaults to numColumns, if not specified -->
        <attr name="numHotseatIcons" format="integer" />
        <attr name="dbFile" format="string" />
        <attr name="defaultLayoutId" format="reference" />
        <attr name="demoModeLayoutId" format="reference" />
    </declare-styleable>
+3 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
        launcher:numFolderRows="2"
        launcher:numFolderColumns="3"
        launcher:numHotseatIcons="3"
        launcher:dbFile="launcher_3_by_3.db"
        launcher:defaultLayoutId="@xml/default_workspace_3x3" >

        <display-option
@@ -51,6 +52,7 @@
        launcher:numFolderRows="3"
        launcher:numFolderColumns="4"
        launcher:numHotseatIcons="4"
        launcher:dbFile="launcher_4_by_4.db"
        launcher:defaultLayoutId="@xml/default_workspace_4x4" >

        <display-option
@@ -102,6 +104,7 @@
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:numHotseatIcons="5"
        launcher:dbFile="launcher.db"
        launcher:defaultLayoutId="@xml/default_workspace_5x5" >

        <display-option
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ public class BackupRestoreTest {
                { APP_ICON, SHORTCUT, SHORTCUT, NO__ICON},
            }}, 2, OLD_WORK_PROFILE_ID);
        // simulates the creation of backup upon restore
        new GridBackupTable(RuntimeEnvironment.application, mDb, mIdp.numHotseatIcons,
        new GridBackupTable(RuntimeEnvironment.application, mDb, mDb, mIdp.numHotseatIcons,
                mIdp.numColumns, mIdp.numRows).doBackup(
                        MY_OLD_PROFILE_ID, GridBackupTable.OPTION_REQUIRES_SANITIZATION);
        // reset favorites table
+6 −6
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class GridBackupTableTest {

    @Test
    public void backupTableCreated() {
        GridBackupTable backupTable = new GridBackupTable(mContext, mDb, 4, 4, 4);
        GridBackupTable backupTable = new GridBackupTable(mContext, mDb, mDb, 4, 4, 4);
        assertFalse(backupTable.backupOrRestoreAsNeeded());
        Settings.call(mContext.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);

@@ -75,14 +75,14 @@ public class GridBackupTableTest {

    @Test
    public void backupTableRestored() {
        assertFalse(new GridBackupTable(mContext, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        assertFalse(new GridBackupTable(mContext, mDb, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        Settings.call(mContext.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);

        // Delete entries
        mDb.delete(TABLE_NAME, null, null);
        assertEquals(0, queryNumEntries(mDb, TABLE_NAME));

        GridBackupTable backupTable = new GridBackupTable(mContext, mDb, 3, 3, 3);
        GridBackupTable backupTable = new GridBackupTable(mContext, mDb, mDb, 3, 3, 3);
        assertTrue(backupTable.backupOrRestoreAsNeeded());

        // Items have been restored
@@ -96,7 +96,7 @@ public class GridBackupTableTest {

    @Test
    public void backupTableRemovedOnAdd() {
        assertFalse(new GridBackupTable(mContext, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        assertFalse(new GridBackupTable(mContext, mDb, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        Settings.call(mContext.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);

        assertTrue(tableExists(mDb, BACKUP_TABLE_NAME));
@@ -107,7 +107,7 @@ public class GridBackupTableTest {

    @Test
    public void backupTableRemovedOnDelete() {
        assertFalse(new GridBackupTable(mContext, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        assertFalse(new GridBackupTable(mContext, mDb, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        Settings.call(mContext.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);

        assertTrue(tableExists(mDb, BACKUP_TABLE_NAME));
@@ -118,7 +118,7 @@ public class GridBackupTableTest {

    @Test
    public void backupTableRetainedOnUpdate() {
        assertFalse(new GridBackupTable(mContext, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        assertFalse(new GridBackupTable(mContext, mDb, mDb, 4, 4, 4).backupOrRestoreAsNeeded());
        Settings.call(mContext.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);

        assertTrue(tableExists(mDb, BACKUP_TABLE_NAME));
+5 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class InvariantDeviceProfile {
     */
    public int numAllAppsColumns;

    public String dbFile;
    public int defaultLayoutId;
    int demoModeLayoutId;

@@ -146,6 +147,7 @@ public class InvariantDeviceProfile {
        iconTextSize = p.iconTextSize;
        numHotseatIcons = p.numHotseatIcons;
        numAllAppsColumns = p.numAllAppsColumns;
        dbFile = p.dbFile;
        defaultLayoutId = p.defaultLayoutId;
        demoModeLayoutId = p.demoModeLayoutId;
        mExtraAttrs = p.mExtraAttrs;
@@ -292,6 +294,7 @@ public class InvariantDeviceProfile {
        numRows = closestProfile.numRows;
        numColumns = closestProfile.numColumns;
        numHotseatIcons = closestProfile.numHotseatIcons;
        dbFile = closestProfile.dbFile;
        defaultLayoutId = closestProfile.defaultLayoutId;
        demoModeLayoutId = closestProfile.demoModeLayoutId;
        numFolderRows = closestProfile.numFolderRows;
@@ -559,6 +562,7 @@ public class InvariantDeviceProfile {

        private final int numHotseatIcons;

        private final String dbFile;
        private final int defaultLayoutId;
        private final int demoModeLayoutId;

@@ -571,6 +575,7 @@ public class InvariantDeviceProfile {
            numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
            numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);

            dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
            defaultLayoutId = a.getResourceId(
                    R.styleable.GridDisplayOption_defaultLayoutId, 0);
            demoModeLayoutId = a.getResourceId(
Loading