Search in sources :

Example 11 with DatabaseHelper

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

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.numHotseatIcons, 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 12 with DatabaseHelper

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

the class RestoreDbTask method performRestore.

public static boolean performRestore(Context context, DatabaseHelper helper, BackupManager backupManager) {
    SQLiteDatabase db = helper.getWritableDatabase();
    try (SQLiteTransaction t = new SQLiteTransaction(db)) {
        RestoreDbTask task = new RestoreDbTask();
        task.sanitizeDB(helper, db, backupManager);
        task.restoreAppWidgetIdsIfExists(context);
        t.commit();
        return true;
    } catch (Exception e) {
        FileLog.e(TAG, "Failed to verify db", e);
        return false;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) InvalidObjectException(java.io.InvalidObjectException)

Example 13 with DatabaseHelper

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

the class DbDowngradeHelperTest method setupTestDb.

private void setupTestDb() throws Exception {
    mSchemaFile.delete();
    mDbFile.delete();
    DbDowngradeHelper.updateSchemaFile(mSchemaFile, LauncherProvider.SCHEMA_VERSION, mContext);
    DatabaseHelper dbHelper = new DatabaseHelper(mContext, null, DB_FILE) {

        @Override
        public void onOpen(SQLiteDatabase db) {
        }
    };
    // Insert dummy data
    for (int i = 0; i < 10; i++) {
        ContentValues values = new ContentValues();
        values.put(Favorites._ID, i);
        values.put(Favorites.TITLE, "title " + i);
        dbHelper.getWritableDatabase().insert(Favorites.TABLE_NAME, null, values);
    }
    dbHelper.close();
}
Also used : ContentValues(android.content.ContentValues) DatabaseHelper(com.android.launcher3.LauncherProvider.DatabaseHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

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