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

Commit aa2b872d authored by Sihua Ma's avatar Sihua Ma
Browse files

Move most of the functions in LauncherAppWidgetHost to LauncherWidgetHolder

Test: N/A
Bug: 235358918
Change-Id: I343419376491203a195154f2766b12e5def38879
parent b63cc3f1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ import android.content.pm.ShortcutInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.LauncherWidgetHolder;
import com.android.launcher3.Utilities;
import com.android.launcher3.widget.LauncherAppWidgetHost;

/**
 * A wrapper for the hidden API calls
@@ -44,7 +44,7 @@ public class ApiWrapper {
     * @param handler InteractionHandler for the views in the host
     */
    public static void setHostInteractionHandler(@NonNull AppWidgetHost host,
            @Nullable LauncherAppWidgetHost.LauncherWidgetInteractionHandler handler) {
            @Nullable LauncherWidgetHolder.LauncherWidgetInteractionHandler handler) {
        host.setInteractionHandler(handler::onInteraction);
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -29,16 +29,16 @@ import android.view.View;
import android.widget.RemoteViews;
import android.window.SplashScreen;

import com.android.launcher3.LauncherWidgetHolder;
import com.android.launcher3.Utilities;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.widget.LauncherAppWidgetHost;
import com.android.launcher3.widget.LauncherAppWidgetHostView;

/** Provides a Quickstep specific animation when launching an activity from an app widget. */
class QuickstepInteractionHandler implements
        LauncherAppWidgetHost.LauncherWidgetInteractionHandler {
class QuickstepInteractionHandler
        implements LauncherWidgetHolder.LauncherWidgetInteractionHandler {

    private static final String TAG = "QuickstepInteractionHandler";

+7 −8
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package com.android.launcher3;

import static android.os.Process.myUserHandle;

import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
@@ -12,6 +11,7 @@ import android.content.Intent;
import android.database.Cursor;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;

import com.android.launcher3.LauncherSettings.Favorites;
@@ -21,7 +21,6 @@ import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.widget.LauncherAppWidgetHost;

public class AppWidgetsRestoredReceiver extends BroadcastReceiver {

@@ -32,7 +31,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
        if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
            int hostId = intent.getIntExtra(AppWidgetManager.EXTRA_HOST_ID, 0);
            Log.d(TAG, "Widget ID map received for host:" + hostId);
            if (hostId != LauncherAppWidgetHost.APPWIDGET_HOST_ID) {
            if (hostId != LauncherWidgetHolder.APPWIDGET_HOST_ID) {
                return;
            }

@@ -50,11 +49,11 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
     * 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);
    public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds,
            @NonNull LauncherWidgetHolder holder) {
        if (WidgetsModel.GO_DISABLE_WIDGETS) {
            Log.e(TAG, "Skipping widget ID remap as widgets not supported");
            appWidgetHost.deleteHost();
            holder.deleteHost();
            return;
        }
        if (!RestoreDbTask.isPending(context)) {
@@ -63,7 +62,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
            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);
                holder.deleteAppWidgetId(widgetId);
            }
            return;
        }
@@ -100,7 +99,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
                try {
                    if (!cursor.moveToFirst()) {
                        // The widget no long exists.
                        appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
                        holder.deleteAppWidgetId(newWidgetIds[i]);
                    }
                } finally {
                    cursor.close();
+7 −8
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.launcher3;

import android.appwidget.AppWidgetHost;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
@@ -74,7 +73,7 @@ public class AutoInstallsLayout {
    private static final String FORMATTED_LAYOUT_RES = "default_layout_%dx%d";
    private static final String LAYOUT_RES = "default_layout";

    static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost,
    static AutoInstallsLayout get(Context context, LauncherWidgetHolder appWidgetHolder,
            LayoutParserCallback callback) {
        Pair<String, Resources> customizationApkInfo = PackageManagerHelper.findSystemApk(
                ACTION_LAUNCHER_CUSTOMIZATION, context.getPackageManager());
@@ -109,7 +108,7 @@ public class AutoInstallsLayout {
            Log.e(TAG, "Layout definition not found in package: " + pkg);
            return null;
        }
        return new AutoInstallsLayout(context, appWidgetHost, callback, targetRes, layoutId,
        return new AutoInstallsLayout(context, appWidgetHolder, callback, targetRes, layoutId,
                TAG_WORKSPACE);
    }

@@ -156,7 +155,7 @@ public class AutoInstallsLayout {
    @Thunk
    final Context mContext;
    @Thunk
    final AppWidgetHost mAppWidgetHost;
    final LauncherWidgetHolder mAppWidgetHolder;
    protected final LayoutParserCallback mCallback;

    protected final PackageManager mPackageManager;
@@ -174,17 +173,17 @@ public class AutoInstallsLayout {

    protected SQLiteDatabase mDb;

    public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
    public AutoInstallsLayout(Context context, LauncherWidgetHolder appWidgetHolder,
            LayoutParserCallback callback, Resources res,
            int layoutId, String rootTag) {
        this(context, appWidgetHost, callback, res, () -> res.getXml(layoutId), rootTag);
        this(context, appWidgetHolder, callback, res, () -> res.getXml(layoutId), rootTag);
    }

    public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
    public AutoInstallsLayout(Context context, LauncherWidgetHolder appWidgetHolder,
            LayoutParserCallback callback, Resources res,
            Supplier<XmlPullParser> initialLayoutSupplier, String rootTag) {
        mContext = context;
        mAppWidgetHost = appWidgetHost;
        mAppWidgetHolder = appWidgetHolder;
        mCallback = callback;

        mPackageManager = context.getPackageManager();
+5 −6
Original line number Diff line number Diff line
package com.android.launcher3;

import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
@@ -55,9 +54,9 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
    private static final String ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE =
            "com.android.launcher.action.APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE";

    public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
    public DefaultLayoutParser(Context context, LauncherWidgetHolder appWidgetHolder,
            LayoutParserCallback callback, Resources sourceRes, int layoutId) {
        super(context, appWidgetHost, callback, sourceRes, layoutId, TAG_FAVORITES);
        super(context, appWidgetHolder, callback, sourceRes, layoutId, TAG_FAVORITES);
    }

    @Override
@@ -336,11 +335,11 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
            final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
            int insertedId = -1;
            try {
                int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
                int appWidgetId = mAppWidgetHolder.allocateAppWidgetId();

                if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn)) {
                    Log.e(TAG, "Unable to bind app widget id " + cn);
                    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
                    mAppWidgetHolder.deleteAppWidgetId(appWidgetId);
                    return -1;
                }

@@ -349,7 +348,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
                mValues.put(Favorites._ID, mCallback.generateNewItemId());
                insertedId = mCallback.insertAndCheck(mDb, mValues);
                if (insertedId < 0) {
                    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
                    mAppWidgetHolder.deleteAppWidgetId(appWidgetId);
                    return insertedId;
                }

Loading