Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d76c458c authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Removing binder claas from main thread related to widget sizes" into main

parents 32f2cae2 1d8ed798
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1512,7 +1512,6 @@ public class Launcher extends StatefulActivity<LauncherState>

    private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
        hostView.setTag(item);
        item.onBindAppWidget(this, hostView);
        hostView.setFocusable(true);
        hostView.setOnFocusChangeListener(mFocusHandler);
    }
+44 −31
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.launcher3.util.PackageManagerHelper
import com.android.launcher3.util.PackageUserKey
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo
import com.android.launcher3.widget.WidgetInflater
import com.android.launcher3.widget.util.WidgetSizes

/**
 * This items is used by LoaderTask to process items that have been loaded from the Launcher's DB.
@@ -423,13 +424,14 @@ class WorkspaceItemProcessor(
        }
        val inflationResult = widgetInflater.inflateAppWidget(appWidgetInfo)
        var shouldUpdate = inflationResult.isUpdate
        if (inflationResult.type == WidgetInflater.TYPE_DELETE) {
        val lapi = inflationResult.widgetInfo

        when (inflationResult.type) {
            WidgetInflater.TYPE_DELETE -> {
                c.markDeleted(inflationResult.reason, inflationResult.restoreErrorType)
                return
            }

        val lapi = inflationResult.widgetInfo
        if (inflationResult.type == WidgetInflater.TYPE_PENDING) {
            WidgetInflater.TYPE_PENDING -> {
                tempPackageKey.update(component.packageName, c.user)
                val si = installingPkgs[tempPackageKey]

@@ -452,7 +454,8 @@ class WorkspaceItemProcessor(
                    appWidgetInfo.restoreStatus =
                        appWidgetInfo.restoreStatus or LauncherAppWidgetInfo.FLAG_RESTORE_STARTED
                }
            appWidgetInfo.installProgress = if (si == null) 0 else (si.getProgress() * 100).toInt()
                appWidgetInfo.installProgress =
                    if (si == null) 0 else (si.getProgress() * 100).toInt()
                appWidgetInfo.pendingItemInfo =
                    WidgetsModel.newPendingItemInfo(
                        app.context,
@@ -461,6 +464,16 @@ class WorkspaceItemProcessor(
                    )
                iconCache.getTitleAndIconForApp(appWidgetInfo.pendingItemInfo, false)
            }
            WidgetInflater.TYPE_REAL ->
                WidgetSizes.updateWidgetSizeRangesAsync(
                    appWidgetInfo.appWidgetId,
                    lapi,
                    app.context,
                    appWidgetInfo.spanX,
                    appWidgetInfo.spanY
                )
        }

        if (shouldUpdate) {
            c.updater()
                .put(Favorites.APPWIDGET_PROVIDER, component.flattenToString())
+0 −15
Original line number Diff line number Diff line
@@ -32,13 +32,11 @@ import android.os.Process;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.util.WidgetSizes;

/**
 * Represents a widget (either instantiated or about to be) in the Launcher.
@@ -143,8 +141,6 @@ public class LauncherAppWidgetInfo extends ItemInfo {
     */
    private int widgetFeatures;

    private boolean mHasNotifiedInitialWidgetSizeChanged;

    /**
     * The container from which this widget was added (e.g. widgets tray, pin widget, search)
     */
@@ -202,17 +198,6 @@ public class LauncherAppWidgetInfo extends ItemInfo {
                .put(LauncherSettings.Favorites.APPWIDGET_SOURCE, sourceContainer);
    }

    /**
     * When we bind the widget, we should notify the widget that the size has changed if we have not
     * done so already (only really for default workspace widgets).
     */
    public void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) {
        if (!mHasNotifiedInitialWidgetSizeChanged) {
            WidgetSizes.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
            mHasNotifiedInitialWidgetSizeChanged = true;
        }
    }

    @Override
    protected String dumpProperties() {
        return super.dumpProperties()
+28 −12
Original line number Diff line number Diff line
@@ -15,8 +15,11 @@
 */
package com.android.launcher3.widget.util;

import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;

import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
import android.graphics.Point;
@@ -91,13 +94,25 @@ public final class WidgetSizes {
     */
    public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Context context,
            int spanX, int spanY) {
        AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
        int widgetId = widgetView.getAppWidgetId();
        if (widgetId <= 0) {
        updateWidgetSizeRangesAsync(
                widgetView.getAppWidgetId(), widgetView.getAppWidgetInfo(), context, spanX, spanY);
    }

    /**
     * Updates a given {@code widgetId} with size, {@code spanX}, {@code spanY} asynchronously.
     *
     * <p>On Android S+, it also updates the given {@code widgetView} with a list of sizes derived
     * from {@code spanX}, {@code spanY} in all supported device profiles.
     */
    public static void updateWidgetSizeRangesAsync(int widgetId,
            AppWidgetProviderInfo info, Context context, int spanX, int spanY) {
        if (widgetId <= 0 || info == null) {
            return;
        }
        Bundle sizeOptions = getWidgetSizeOptions(context, widgetView.getAppWidgetInfo().provider,
                spanX, spanY);

        UI_HELPER_EXECUTOR.execute(() -> {
            AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
            Bundle sizeOptions = getWidgetSizeOptions(context, info.provider, spanX, spanY);
            if (sizeOptions.<SizeF>getParcelableArrayList(
                    AppWidgetManager.OPTION_APPWIDGET_SIZES).equals(
                    widgetManager.getAppWidgetOptions(widgetId).<SizeF>getParcelableArrayList(
@@ -105,6 +120,7 @@ public final class WidgetSizes {
                return;
            }
            widgetManager.updateAppWidgetOptions(widgetId, sizeOptions);
        });
    }

    /**