Search in sources :

Example 41 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by AOSPA.

the class ModelWriter method moveItemInDatabase.

/**
 * Move an item in the DB to a new <container, screen, cellX, cellY>
 */
public void moveItemInDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    notifyItemModified(item);
    enqueueDeleteRunnable(new UpdateItemRunnable(item, () -> new ContentWriter(mContext).put(Favorites.CONTAINER, item.container).put(Favorites.CELLX, item.cellX).put(Favorites.CELLY, item.cellY).put(Favorites.RANK, item.rank).put(Favorites.SCREEN, item.screenId)));
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter)

Example 42 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_Launcher3 by AOSPA.

the class AppWidgetsRestoredReceiver method restoreAppWidgetIds.

/**
 * Updates the app widgets whose id has changed during the restore process.
 */
@WorkerThread
public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) {
    AppWidgetHost appWidgetHost = new LauncherAppWidgetHost(context);
    if (WidgetsModel.GO_DISABLE_WIDGETS) {
        Log.e(TAG, "Skipping widget ID remap as widgets not supported");
        appWidgetHost.deleteHost();
        return;
    }
    if (!RestoreDbTask.isPending(context)) {
        // Someone has already gone through our DB once, probably LoaderTask. Skip any further
        // modifications of the DB.
        Log.e(TAG, "Skipping widget ID remap as DB already in use");
        for (int widgetId : newWidgetIds) {
            Log.d(TAG, "Deleting widgetId: " + widgetId);
            appWidgetHost.deleteAppWidgetId(widgetId);
        }
        return;
    }
    final ContentResolver cr = context.getContentResolver();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
    for (int i = 0; i < oldWidgetIds.length; i++) {
        Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);
        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LoaderTask.isValidProvider(provider)) {
            // This will ensure that we show 'Click to setup' UI if required.
            state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }
        // b/135926478: Work profile widget restore is broken in platform. This forces us to
        // recreate the widget during loading with the correct host provider.
        long mainProfileId = UserCache.INSTANCE.get(context).getSerialNumberForUser(myUserHandle());
        String oldWidgetId = Integer.toString(oldWidgetIds[i]);
        final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
        final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
        int result = new ContentWriter(context, new ContentWriter.CommitParams(where, args)).put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]).put(LauncherSettings.Favorites.RESTORED, state).commit();
        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI, new String[] { Favorites.APPWIDGET_ID }, "appWidgetId=?", new String[] { oldWidgetId }, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
        // attempt to update widget id in backup table as well
        new ContentWriter(context, ContentWriter.CommitParams.backupCommitParams("appWidgetId=? and profileId=?", args)).put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]).put(LauncherSettings.Favorites.RESTORED, state).commit();
    }
    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.getModel().forceReload();
    }
}
Also used : AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetManager(android.appwidget.AppWidgetManager) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) ContentWriter(com.android.launcher3.util.ContentWriter) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 43 with ContentWriter

use of com.android.launcher3.util.ContentWriter in project android_packages_apps_404Launcher by P-404.

the class ModelWriter method addItemToDatabase.

/**
 * Add an item to the database in a specified container. Sets the container, screen, cellX and
 * cellY fields of the item. Also assigns an ID to the item.
 */
public void addItemToDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    final ContentResolver cr = mContext.getContentResolver();
    item.id = Settings.call(cr, Settings.METHOD_NEW_ITEM_ID).getInt(Settings.EXTRA_VALUE);
    notifyOtherCallbacks(c -> c.bindItems(Collections.singletonList(item), false));
    ModelVerifier verifier = new ModelVerifier();
    final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    MODEL_EXECUTOR.execute(() -> {
        // Write the item on background thread, as some properties might have been updated in
        // the background.
        final ContentWriter writer = new ContentWriter(mContext);
        item.onAddToDatabase(writer);
        writer.put(Favorites._ID, item.id);
        cr.insert(Favorites.CONTENT_URI, writer.getValues(mContext));
        synchronized (mBgDataModel) {
            checkItemInfoLocked(item.id, item, stackTrace);
            mBgDataModel.addItem(mContext, item, true);
            verifier.verifyModel();
        }
    });
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter) ContentResolver(android.content.ContentResolver)

Aggregations

ContentWriter (com.android.launcher3.util.ContentWriter)43 ContentResolver (android.content.ContentResolver)16 AppWidgetHost (android.appwidget.AppWidgetHost)7 AppWidgetManager (android.appwidget.AppWidgetManager)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)7 Intent (android.content.Intent)7 Cursor (android.database.Cursor)7 Rect (android.graphics.Rect)7 WorkerThread (androidx.annotation.WorkerThread)7 GridOccupancy (com.android.launcher3.util.GridOccupancy)7 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)6 Executor (java.util.concurrent.Executor)6 LauncherAppWidgetHost (com.android.launcher3.widget.LauncherAppWidgetHost)5 WorkspaceItemInfo (com.android.launcher3.WorkspaceItemInfo)1 ExecutorService (java.util.concurrent.ExecutorService)1