Search in sources :

Example 1 with LoaderTask

use of com.android.launcher3.model.LoaderTask in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherModel method startLoader.

/**
 * Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible.
 * @return true if the page could be bound synchronously.
 */
public boolean startLoader() {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    ItemInstallQueue.INSTANCE.get(mApp.getContext()).pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
    synchronized (mLock) {
        // Don't bother to start the thread if we know it's not going to do anything
        final Callbacks[] callbacksList = getCallbacks();
        if (callbacksList.length > 0) {
            // Clear any pending bind-runnables from the synchronized load process.
            for (Callbacks cb : callbacksList) {
                MAIN_EXECUTOR.execute(cb::clearPendingBinds);
            }
            // If there is already one running, tell it to stop.
            stopLoader();
            LoaderResults loaderResults = new LoaderResults(mApp, mBgDataModel, mBgAllAppsList, callbacksList);
            if (mModelLoaded && !mIsLoaderTaskRunning) {
                // Divide the set of loaded items into those that we are binding synchronously,
                // and everything else that is to be bound normally (asynchronously).
                loaderResults.bindWorkspace();
                // For now, continue posting the binding of AllApps as there are other
                // issues that arise from that.
                loaderResults.bindAllApps();
                loaderResults.bindDeepShortcuts();
                loaderResults.bindWidgets();
                return true;
            } else {
                stopLoader();
                mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);
                // Always post the loader task, instead of running directly
                // (even on same thread) so that we exit any nested synchronized blocks
                MODEL_EXECUTOR.post(mLoaderTask);
            }
        }
    }
    return false;
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LoaderTask(com.android.launcher3.model.LoaderTask) LoaderResults(com.android.launcher3.model.LoaderResults)

Example 2 with LoaderTask

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

the class LauncherModel method stopLoader.

/**
 * If there is already a loader task running, tell it to stop.
 * @return true if an existing loader was stopped.
 */
private boolean stopLoader() {
    synchronized (mLock) {
        LoaderTask oldTask = mLoaderTask;
        mLoaderTask = null;
        if (oldTask != null) {
            oldTask.stopLocked();
            return true;
        }
        return false;
    }
}
Also used : LoaderTask(com.android.launcher3.model.LoaderTask)

Example 3 with LoaderTask

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

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with LoaderTask

use of com.android.launcher3.model.LoaderTask in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherModel method startLoaderForResults.

public void startLoaderForResults(LoaderResults results) {
    synchronized (mLock) {
        stopLoader();
        mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, results);
        // Always post the loader task, instead of running directly (even on same thread) so
        // that we exit any nested synchronized blocks
        MODEL_EXECUTOR.post(mLoaderTask);
    }
}
Also used : LoaderTask(com.android.launcher3.model.LoaderTask)

Example 5 with LoaderTask

use of com.android.launcher3.model.LoaderTask in project android_packages_apps_Trebuchet by LineageOS.

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]);
        int result = new ContentWriter(context, new ContentWriter.CommitParams("appWidgetId=? and (restored & 1) = 1 and profileId=?", new String[] { oldWidgetId, Long.toString(mainProfileId) })).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();
            }
        }
    }
    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.getModel().forceReload();
    }
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter) AppWidgetHost(android.appwidget.AppWidgetHost) AppWidgetManager(android.appwidget.AppWidgetManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

LoaderTask (com.android.launcher3.model.LoaderTask)19 WorkerThread (androidx.annotation.WorkerThread)12 AppWidgetHost (android.appwidget.AppWidgetHost)7 AppWidgetManager (android.appwidget.AppWidgetManager)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)7 ContentResolver (android.content.ContentResolver)7 Cursor (android.database.Cursor)7 ContentWriter (com.android.launcher3.util.ContentWriter)7 Callbacks (com.android.launcher3.model.BgDataModel.Callbacks)6 ArrayList (java.util.ArrayList)6 Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 PreviewContext (com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext)5 BgDataModel (com.android.launcher3.model.BgDataModel)5 LoaderResults (com.android.launcher3.model.LoaderResults)5 ModelDelegate (com.android.launcher3.model.ModelDelegate)5 LauncherAppWidgetHost (com.android.launcher3.widget.LauncherAppWidgetHost)5 DeviceProfile (com.android.launcher3.DeviceProfile)4 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)4 ItemInfo (com.android.launcher3.ItemInfo)1