Search in sources :

Example 1 with DatabaseHelper

use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Launcher3 by crdroidandroid.

the class RestoreDbTask method restoreWorkspace.

private void restoreWorkspace(@NonNull Context context, @NonNull SQLiteDatabase db, @NonNull DatabaseHelper helper, @NonNull BackupManager backupManager) throws Exception {
    final InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
    GridBackupTable backupTable = new GridBackupTable(context, db, idp.numDatabaseHotseatIcons, idp.numColumns, idp.numRows);
    if (backupTable.restoreFromRawBackupIfAvailable(getDefaultProfileId(db))) {
        int itemsDeleted = sanitizeDB(helper, db, backupManager);
        LauncherAppState.getInstance(context).getModel().forceReload();
        restoreAppWidgetIdsIfExists(context);
        if (itemsDeleted == 0) {
            // all the items are restored, we no longer need the backup table
            dropTable(db, Favorites.BACKUP_TABLE_NAME);
        }
    }
}
Also used : GridBackupTable(com.android.launcher3.model.GridBackupTable) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile)

Example 2 with DatabaseHelper

use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Launcher3 by crdroidandroid.

the class DbDowngradeHelperTest method testDowngrade_success_v22.

@Test
public void testDowngrade_success_v22() throws Exception {
    setupTestDb();
    SQLiteOpenHelper helper = new TestOpenHelper(22);
    assertEquals(22, helper.getWritableDatabase().getVersion());
    // Check column does not exist
    try (Cursor c = helper.getWritableDatabase().query(Favorites.TABLE_NAME, null, null, null, null, null, null)) {
        assertEquals(-1, c.getColumnIndex(Favorites.OPTIONS));
        // Check data is present
        assertEquals(10, c.getCount());
    }
    helper.close();
    helper = new DatabaseHelper(mContext, DB_FILE, false) {

        @Override
        public void onOpen(SQLiteDatabase db) {
        }
    };
    assertEquals(LauncherProvider.SCHEMA_VERSION, helper.getWritableDatabase().getVersion());
    try (Cursor c = helper.getWritableDatabase().query(Favorites.TABLE_NAME, null, null, null, null, null, null)) {
        // Check column exists
        assertNotSame(-1, c.getColumnIndex(Favorites.OPTIONS));
        // Check data is present
        assertEquals(10, c.getCount());
    }
    helper.close();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) DatabaseHelper(com.android.launcher3.LauncherProvider.DatabaseHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 3 with DatabaseHelper

use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Trebuchet by LineageOS.

the class RestoreDbTask method restoreIfPossible.

/**
 * Restore the workspace if backup is available.
 */
public static boolean restoreIfPossible(@NonNull Context context, @NonNull DatabaseHelper helper, @NonNull BackupManager backupManager) {
    final SQLiteDatabase db = helper.getWritableDatabase();
    try (SQLiteTransaction t = new SQLiteTransaction(db)) {
        RestoreDbTask task = new RestoreDbTask();
        task.restoreWorkspace(context, db, helper, backupManager);
        t.commit();
        return true;
    } catch (Exception e) {
        FileLog.e(TAG, "Failed to restore db", e);
        return false;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) InvalidObjectException(java.io.InvalidObjectException)

Example 4 with DatabaseHelper

use of com.android.launcher3.LauncherProvider.DatabaseHelper in project Neo-Launcher by NeoApplications.

the class DbDowngradeHelperTest method testDowngrade_success_v22.

@Test
public void testDowngrade_success_v22() throws Exception {
    setupTestDb();
    SQLiteOpenHelper helper = new TestOpenHelper(22);
    assertEquals(22, helper.getWritableDatabase().getVersion());
    // Check column does not exist
    try (Cursor c = helper.getWritableDatabase().query(Favorites.TABLE_NAME, null, null, null, null, null, null)) {
        assertEquals(-1, c.getColumnIndex(Favorites.OPTIONS));
        // Check data is present
        assertEquals(10, c.getCount());
    }
    helper.close();
    helper = new DatabaseHelper(mContext, null, DB_FILE) {

        @Override
        public void onOpen(SQLiteDatabase db) {
        }
    };
    assertEquals(LauncherProvider.SCHEMA_VERSION, helper.getWritableDatabase().getVersion());
    try (Cursor c = helper.getWritableDatabase().query(Favorites.TABLE_NAME, null, null, null, null, null, null)) {
        // Check column exists
        assertNotSame(-1, c.getColumnIndex(Favorites.OPTIONS));
        // Check data is present
        assertEquals(10, c.getCount());
    }
    helper.close();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) DatabaseHelper(com.android.launcher3.LauncherProvider.DatabaseHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 5 with DatabaseHelper

use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Launcher3 by crdroidandroid.

the class RestoreDbTask method restoreIfPossible.

/**
 * Restore the workspace if backup is available.
 */
public static boolean restoreIfPossible(@NonNull Context context, @NonNull DatabaseHelper helper, @NonNull BackupManager backupManager) {
    final SQLiteDatabase db = helper.getWritableDatabase();
    try (SQLiteTransaction t = new SQLiteTransaction(db)) {
        RestoreDbTask task = new RestoreDbTask();
        task.restoreWorkspace(context, db, helper, backupManager);
        t.commit();
        return true;
    } catch (Exception e) {
        FileLog.e(TAG, "Failed to restore db", e);
        return false;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) InvalidObjectException(java.io.InvalidObjectException)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)11 DatabaseHelper (com.android.launcher3.LauncherProvider.DatabaseHelper)6 SQLiteTransaction (com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)5 InvalidObjectException (java.io.InvalidObjectException)5 ContentValues (android.content.ContentValues)3 Cursor (android.database.Cursor)3 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)3 Test (org.junit.Test)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 GridBackupTable (com.android.launcher3.model.GridBackupTable)2