use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Launcher3 by crdroidandroid.
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.backupWorkspace(context, db);
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;
}
}
use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Launcher3 by crdroidandroid.
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, DB_FILE, false) {
@Override
public void onOpen(SQLiteDatabase db) {
}
};
// Insert mock 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();
}
use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Trebuchet by LineageOS.
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();
}
use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Trebuchet by LineageOS.
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, DB_FILE, false) {
@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();
}
use of com.android.launcher3.LauncherProvider.DatabaseHelper in project android_packages_apps_Trebuchet by LineageOS.
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.backupWorkspace(context, db);
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;
}
}
Aggregations