From 1d7ed30dba4b2c71fc7b0981532a872a13e5aedb Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 23 Sep 2020 12:15:43 -0700 Subject: [PATCH] Remove widgets that no longer fit the workspace in their current spans. This can happen when display size changes. We compare span sizes of widget in the db to the min sizes of the widget in the current display size. If the widget can no longer fit in its existing spans, we remove it. Also update test widgets to have minWidth/minHeight of 1dp. This ensures that the spanX, spanY, min* values remain consistent between different test devices. Bug: 168818961 Change-Id: I723372e4582658f78b2f23ced9073cb77977a6b8 --- src/com/android/launcher3/model/LoaderTask.java | 16 ++++++++++++++++ tests/res/xml/appwidget_hidden.xml | 4 ++-- tests/res/xml/appwidget_no_config.xml | 4 ++-- tests/res/xml/appwidget_with_config.xml | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 2b4520b613..c0d5882b46 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -49,6 +49,7 @@ import android.util.LongSparseArray; import android.util.TimingLogger; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherSettings; import com.android.launcher3.Utilities; @@ -306,6 +307,7 @@ public class LoaderTask implements Runnable { final PackageManagerHelper pmHelper = new PackageManagerHelper(context); final boolean isSafeMode = pmHelper.isSafeMode(); final boolean isSdCardReady = Utilities.isBootCompleted(); + final WidgetManagerHelper widgetHelper = new WidgetManagerHelper(context); boolean clearDb = false; try { @@ -391,6 +393,7 @@ public class LoaderTask implements Runnable { WorkspaceItemInfo info; LauncherAppWidgetInfo appWidgetInfo; + LauncherAppWidgetProviderInfo widgetProviderInfo; Intent intent; String targetPkg; @@ -720,6 +723,19 @@ public class LoaderTask implements Runnable { + appWidgetInfo.spanX + "x" + appWidgetInfo.spanY); continue; } + widgetProviderInfo = + widgetHelper.getLauncherAppWidgetInfo(appWidgetId); + if (widgetProviderInfo != null + && (appWidgetInfo.spanX < widgetProviderInfo.minSpanX + || appWidgetInfo.spanY < widgetProviderInfo.minSpanY)) { + // This can happen when display size changes. + c.markDeleted("Widget removed, min sizes not met: " + + "span=" + appWidgetInfo.spanX + "x" + + appWidgetInfo.spanY + " minSpan=" + + widgetProviderInfo.minSpanX + "x" + + widgetProviderInfo.minSpanY); + continue; + } if (!c.isOnWorkspaceOrHotseat()) { c.markDeleted("Widget found where container != " + "CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!"); diff --git a/tests/res/xml/appwidget_hidden.xml b/tests/res/xml/appwidget_hidden.xml index 6f0e0066fd..f6cffb52bf 100644 --- a/tests/res/xml/appwidget_hidden.xml +++ b/tests/res/xml/appwidget_hidden.xml @@ -1,8 +1,8 @@