Search in sources :

Example 21 with SQLiteTransaction

use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherProvider method bulkInsert.

@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    createDbIfNotExists();
    SqlArguments args = new SqlArguments(uri);
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    try (SQLiteTransaction t = new SQLiteTransaction(db)) {
        int numValues = values.length;
        for (int i = 0; i < numValues; i++) {
            addModifiedTime(values[i]);
            if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) {
                return 0;
            }
        }
        onAddOrDeleteOp(db);
        t.commit();
    }
    reloadLauncherIfExternal();
    return values.length;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)

Example 22 with SQLiteTransaction

use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction 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;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) InvalidObjectException(java.io.InvalidObjectException)

Example 23 with SQLiteTransaction

use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project Neo-Launcher by NeoApplications.

the class HomeWidgetMigrationTask method migrateIfNeeded.

@SuppressLint("ApplySharedPref")
public static void migrateIfNeeded(Context context) {
    SharedPreferences prefs = Utilities.getPrefs(context);
    boolean needsMigration = !prefs.getBoolean(PREF_MIGRATION_STATUS, false) && prefs.getBoolean(SMARTSPACE_PREF, false);
    if (!needsMigration)
        return;
    // Save the pref so we only run migration once
    prefs.edit().putBoolean(PREF_MIGRATION_STATUS, true).commit();
    HashSet<String> validPackages = getValidPackages(context);
    InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
    Point size = new Point(idp.numColumns, idp.numRows);
    long migrationStartTime = System.currentTimeMillis();
    try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
        if (!new HomeWidgetMigrationTask(context, transaction.getDb(), validPackages, size).migrateWorkspace()) {
            throw new RuntimeException("Failed to migrate Smartspace");
        }
    } catch (Exception e) {
        Log.e(TAG, "Error during grid migration", e);
    } finally {
        Log.v(TAG, "Home widget migration completed in " + (System.currentTimeMillis() - migrationStartTime));
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint)

Example 24 with SQLiteTransaction

use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction 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 25 with SQLiteTransaction

use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project Neo-Launcher by NeoApplications.

the class GridSizeMigrationTask method removeBrokenHotseatItems.

/**
 * Removes any broken item from the hotseat.
 *
 * @return a map with occupied hotseat position set to non-null value.
 */
public static IntSparseArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
    try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
        GridSizeMigrationTask task = new GridSizeMigrationTask(context, transaction.getDb(), getValidPackages(context), Integer.MAX_VALUE, Integer.MAX_VALUE);
        // Load all the valid entries
        ArrayList<DbEntry> items = task.loadHotseatEntries();
        // Delete any entry marked for deletion by above load.
        task.applyOperations();
        IntSparseArrayMap<Object> positions = new IntSparseArrayMap<>();
        for (DbEntry item : items) {
            positions.put(item.screenId, item);
        }
        transaction.commit();
        return positions;
    }
}
Also used : IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)

Aggregations

SQLiteTransaction (com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)26 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)11 SharedPreferences (android.content.SharedPreferences)6 Point (android.graphics.Point)6 Utilities.getPointString (com.android.launcher3.Utilities.getPointString)5 InvalidObjectException (java.io.InvalidObjectException)5 TargetApi (android.annotation.TargetApi)3 ContentProviderOperation (android.content.ContentProviderOperation)3 ContentProviderResult (android.content.ContentProviderResult)3 Cursor (android.database.Cursor)3 SQLException (android.database.SQLException)3 SQLiteException (android.database.sqlite.SQLiteException)3 Utilities.parsePoint (com.android.launcher3.Utilities.parsePoint)3 IntArray (com.android.launcher3.util.IntArray)3 IntSparseArrayMap (com.android.launcher3.util.IntSparseArrayMap)3 ArrayList (java.util.ArrayList)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 SuppressLint (android.annotation.SuppressLint)1