Search in sources :

Example 1 with DeviceGridState

use of com.android.launcher3.model.DeviceGridState in project android_packages_apps_Launcher3 by AOSPA.

the class RestoreDbTask method setPending.

/**
 * Marks the DB state as pending restoration
 */
public static void setPending(Context context) {
    FileLog.d(TAG, "Restore data received through full backup ");
    Utilities.getPrefs(context).edit().putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()).commit();
}
Also used : DeviceGridState(com.android.launcher3.model.DeviceGridState)

Example 2 with DeviceGridState

use of com.android.launcher3.model.DeviceGridState in project android_packages_apps_Launcher3 by ArrowOS.

the class RestoreDbTask method setPending.

/**
 * Marks the DB state as pending restoration
 */
public static void setPending(Context context) {
    FileLog.d(TAG, "Restore data received through full backup ");
    Utilities.getPrefs(context).edit().putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()).commit();
}
Also used : DeviceGridState(com.android.launcher3.model.DeviceGridState)

Example 3 with DeviceGridState

use of com.android.launcher3.model.DeviceGridState in project android_packages_apps_Launcher3 by ArrowOS.

the class GridSizeMigrationTaskV2 method migrateGridIfNeeded.

/**
 * When migrating the grid for preview, we copy the table
 * {@link LauncherSettings.Favorites#TABLE_NAME} into
 * {@link LauncherSettings.Favorites#PREVIEW_TABLE_NAME}, run grid size migration from the
 * former to the later, then use the later table for preview.
 *
 * Similarly when doing the actual grid migration, the former grid option's table
 * {@link LauncherSettings.Favorites#TABLE_NAME} is copied into the new grid option's
 * {@link LauncherSettings.Favorites#TMP_TABLE}, we then run the grid size migration algorithm
 * to migrate the later to the former, and load the workspace from the default
 * {@link LauncherSettings.Favorites#TABLE_NAME}.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context, InvariantDeviceProfile idp) {
    boolean migrateForPreview = idp != null;
    if (!migrateForPreview) {
        idp = LauncherAppState.getIDP(context);
    }
    if (!needsToMigrate(context, idp)) {
        return true;
    }
    SharedPreferences prefs = Utilities.getPrefs(context);
    HashSet<String> validPackages = getValidPackages(context);
    if (migrateForPreview) {
        if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW, idp.dbFile).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
            return false;
        }
    } else if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
        return false;
    }
    long migrationStartTime = System.currentTimeMillis();
    try (SQLiteTransaction t = (SQLiteTransaction) LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_NEW_TRANSACTION).getBinder(LauncherSettings.Settings.EXTRA_VALUE)) {
        DbReader srcReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.TABLE_NAME : LauncherSettings.Favorites.TMP_TABLE, context, validPackages);
        DbReader destReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.PREVIEW_TABLE_NAME : LauncherSettings.Favorites.TABLE_NAME, context, validPackages);
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        GridSizeMigrationTaskV2 task = new GridSizeMigrationTaskV2(context, t.getDb(), srcReader, destReader, idp.numDatabaseHotseatIcons, targetSize);
        task.migrate(idp);
        if (!migrateForPreview) {
            dropTable(t.getDb(), LauncherSettings.Favorites.TMP_TABLE);
        }
        t.commit();
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Workspace migration completed in " + (System.currentTimeMillis() - migrationStartTime));
        if (!migrateForPreview) {
            // Save current configuration, so that the migration does not run again.
            new DeviceGridState(idp).writeToPrefs(context);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Point(android.graphics.Point)

Example 4 with DeviceGridState

use of com.android.launcher3.model.DeviceGridState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class RestoreDbTask method setPending.

/**
 * Marks the DB state as pending restoration
 */
public static void setPending(Context context) {
    FileLog.d(TAG, "Restore data received through full backup ");
    Utilities.getPrefs(context).edit().putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()).commit();
}
Also used : DeviceGridState(com.android.launcher3.model.DeviceGridState)

Example 5 with DeviceGridState

use of com.android.launcher3.model.DeviceGridState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class GridSizeMigrationTaskV2 method migrateGridIfNeeded.

/**
 * When migrating the grid for preview, we copy the table
 * {@link LauncherSettings.Favorites#TABLE_NAME} into
 * {@link LauncherSettings.Favorites#PREVIEW_TABLE_NAME}, run grid size migration from the
 * former to the later, then use the later table for preview.
 *
 * Similarly when doing the actual grid migration, the former grid option's table
 * {@link LauncherSettings.Favorites#TABLE_NAME} is copied into the new grid option's
 * {@link LauncherSettings.Favorites#TMP_TABLE}, we then run the grid size migration algorithm
 * to migrate the later to the former, and load the workspace from the default
 * {@link LauncherSettings.Favorites#TABLE_NAME}.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context, InvariantDeviceProfile idp) {
    boolean migrateForPreview = idp != null;
    if (!migrateForPreview) {
        idp = LauncherAppState.getIDP(context);
    }
    if (!needsToMigrate(context, idp)) {
        return true;
    }
    SharedPreferences prefs = Utilities.getPrefs(context);
    HashSet<String> validPackages = getValidPackages(context);
    if (migrateForPreview) {
        if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW, idp.dbFile).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
            return false;
        }
    } else if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
        return false;
    }
    long migrationStartTime = System.currentTimeMillis();
    try (SQLiteTransaction t = (SQLiteTransaction) LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_NEW_TRANSACTION).getBinder(LauncherSettings.Settings.EXTRA_VALUE)) {
        DbReader srcReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.TABLE_NAME : LauncherSettings.Favorites.TMP_TABLE, context, validPackages);
        DbReader destReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.PREVIEW_TABLE_NAME : LauncherSettings.Favorites.TABLE_NAME, context, validPackages);
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        GridSizeMigrationTaskV2 task = new GridSizeMigrationTaskV2(context, t.getDb(), srcReader, destReader, idp.numDatabaseHotseatIcons, targetSize);
        task.migrate(idp);
        if (!migrateForPreview) {
            dropTable(t.getDb(), LauncherSettings.Favorites.TMP_TABLE);
        }
        t.commit();
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Workspace migration completed in " + (System.currentTimeMillis() - migrationStartTime));
        if (!migrateForPreview) {
            // Save current configuration, so that the migration does not run again.
            new DeviceGridState(idp).writeToPrefs(context);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Point(android.graphics.Point)

Aggregations

SharedPreferences (android.content.SharedPreferences)8 DeviceGridState (com.android.launcher3.model.DeviceGridState)8 Context (android.content.Context)4 OnSharedPreferenceChangeListener (android.content.SharedPreferences.OnSharedPreferenceChangeListener)4 TypedArray (android.content.res.TypedArray)4 Point (android.graphics.Point)4 ArrayMap (android.util.ArrayMap)4 Log (android.util.Log)4 Xml (android.util.Xml)4 AutoInstallsLayout (com.android.launcher3.AutoInstallsLayout)4 R (com.android.launcher3.R)4 Utilities.getDevicePrefs (com.android.launcher3.Utilities.getDevicePrefs)4 Utilities.getPrefs (com.android.launcher3.Utilities.getPrefs)4 FeatureFlags (com.android.launcher3.config.FeatureFlags)4 InstanceId (com.android.launcher3.logging.InstanceId)4 StatsLogManager (com.android.launcher3.logging.StatsLogManager)4 LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED (com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED)4 LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED (com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED)4 LAUNCHER_NOTIFICATION_DOT_DISABLED (com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DOT_DISABLED)4 LAUNCHER_NOTIFICATION_DOT_ENABLED (com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DOT_ENABLED)4