Type: INTEGER
+ */ + public static final String APPWIDGET_SOURCE = "appWidgetSource"; + public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) { addTableToDb(db, myProfileId, optional, TABLE_NAME); } @@ -333,7 +343,8 @@ public class LauncherSettings { "restored INTEGER NOT NULL DEFAULT 0," + "profileId INTEGER DEFAULT " + myProfileId + "," + "rank INTEGER NOT NULL DEFAULT 0," + - "options INTEGER NOT NULL DEFAULT 0" + + "options INTEGER NOT NULL DEFAULT 0," + + APPWIDGET_SOURCE + " INTEGER NOT NULL DEFAULT " + CONTAINER_UNKNOWN + ");"); } } diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index ab3ea0abe7..d1e643fd9f 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -184,16 +184,19 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo } catch (Exception e) { Log.e("AllAppsContainerView", "restoreInstanceState viewId = 0", e); } + Bundle state = (Bundle) sparseArray.get(R.id.work_tab_state_id, null); if (state != null) { int currentPage = state.getInt(BUNDLE_KEY_CURRENT_PAGE, 0); if (currentPage != 0) { - rebindAdapters(true); mViewPager.setCurrentPage(currentPage); + rebindAdapters(true); + } else { + mSearchUiManager.resetSearch(); } } - } + } @Override protected void dispatchSaveInstanceState(SparseArrayIf {@link #mInfo}'s category is {@code PackageItemInfo#NO_CATEGORY} or unknown, returns + * {@code null}. + */ + @Nullable + private Drawable getWidgetCategoryIcon() { + switch (mInfo.pendingItemInfo.category) { + case CONVERSATIONS: + return getContext().getDrawable(R.drawable.ic_conversations_widget_category); + } + return null; + } } diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index a52adf673d..8798332c85 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -16,6 +16,7 @@ package com.android.launcher3.widget; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY; import static com.android.launcher3.Utilities.ATLEAST_S; import android.content.Context; @@ -99,6 +100,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private RemoteViews mRemoteViewsPreview; private NavigableAppWidgetHostView mAppWidgetHostViewPreview; + private int mSourceContainer = CONTAINER_WIDGETS_TRAY; public WidgetCell(Context context) { this(context, null); @@ -177,6 +179,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { mAppWidgetHostViewPreview = null; } + public void setSourceContainer(int sourceContainer) { + this.mSourceContainer = sourceContainer; + } + public void applyFromCellItem(WidgetItem item, WidgetPreviewLoader loader) { applyPreviewOnAppWidgetHostView(item); @@ -205,7 +211,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { mPreviewWidth += mShortcutPreviewPadding; mPreviewHeight += mShortcutPreviewPadding; } else { - setTag(new PendingAddWidgetInfo(item.widgetInfo)); + setTag(new PendingAddWidgetInfo(item.widgetInfo, mSourceContainer)); } } diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java index d7928c77b9..c045cf1b43 100644 --- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java +++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java @@ -16,6 +16,7 @@ package com.android.launcher3.widget; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_BOTTOM_WIDGETS_TRAY; import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN; import android.animation.PropertyValuesHolder; @@ -229,6 +230,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { previewContainer.setOnClickListener(this); previewContainer.setOnLongClickListener(this); widget.setAnimatePreview(false); + widget.setSourceContainer(CONTAINER_BOTTOM_WIDGETS_TRAY); parent.addView(widget); return widget; diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java index fe42ddfb15..6fc684862d 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java +++ b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget.picker; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION; + import android.content.Context; import android.util.AttributeSet; import android.util.Log; @@ -132,6 +134,7 @@ public final class WidgetsRecommendationTableLayout extends TableLayout { previewContainer.setOnClickListener(mWidgetCellOnClickListener); previewContainer.setOnLongClickListener(mWidgetCellOnLongClickListener); widget.setAnimatePreview(false); + widget.setSourceContainer(CONTAINER_WIDGETS_PREDICTION); parent.addView(widget); return widget; diff --git a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java index a66b031719..631067b929 100644 --- a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java +++ b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java @@ -225,6 +225,14 @@ public class WidgetsModel { return null; } + /** Returns {@link PackageItemInfo} of a pending widget. */ + public static PackageItemInfo newPendingItemInfo(ComponentName provider) { + if (CONVERSATION_WIDGET.equals(provider)) { + return new PackageItemInfo(provider.getPackageName(), PackageItemInfo.CONVERSATIONS); + } + return new PackageItemInfo(provider.getPackageName()); + } + private WidgetPackageOrCategoryKey getWidgetPackageOrCategoryKey(WidgetItem item) { if (CONVERSATION_WIDGET.equals(item.componentName)) { return new WidgetPackageOrCategoryKey(PackageItemInfo.CONVERSATIONS, item.user); diff --git a/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java b/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java index 0ec0f026d9..2b2fef4ae6 100644 --- a/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java +++ b/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java @@ -15,21 +15,27 @@ */ package com.android.launcher3.util.rule; -import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess; - import static androidx.test.InstrumentationRegistry.getInstrumentation; +import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess; + import android.content.ComponentName; import android.content.pm.ActivityInfo; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import android.util.Log; import androidx.annotation.Nullable; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; +import com.android.systemui.shared.system.PackageManagerWrapper; + +import org.junit.Assert; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.util.ArrayList; + /** * Test rule which executes a shell command at the start of the test. */ @@ -37,10 +43,19 @@ public class ShellCommandRule implements TestRule { private final String mCmd; private final String mRevertCommand; + private final boolean mCheckSuccess; + private final Runnable mAdditionalChecks; - public ShellCommandRule(String cmd, @Nullable String revertCommand) { + public ShellCommandRule(String cmd, @Nullable String revertCommand, boolean checkSuccess, + Runnable additionalChecks) { mCmd = cmd; mRevertCommand = revertCommand; + mCheckSuccess = checkSuccess; + mAdditionalChecks = additionalChecks; + } + + public ShellCommandRule(String cmd, @Nullable String revertCommand) { + this(cmd, revertCommand, false, null); } @Override @@ -48,12 +63,27 @@ public class ShellCommandRule implements TestRule { return new Statement() { @Override public void evaluate() throws Throwable { - UiDevice.getInstance(getInstrumentation()).executeShellCommand(mCmd); + final String result = + UiDevice.getInstance(getInstrumentation()).executeShellCommand(mCmd); + if (mCheckSuccess) { + Assert.assertTrue( + "Failed command: " + mCmd + ", result: " + result, + "Success".equals(result.replaceAll("\\s", ""))); + } + if (mAdditionalChecks != null) mAdditionalChecks.run(); try { base.evaluate(); } finally { if (mRevertCommand != null) { - UiDevice.getInstance(getInstrumentation()).executeShellCommand(mRevertCommand); + final String revertResult = UiDevice.getInstance( + getInstrumentation()).executeShellCommand( + mRevertCommand); + if (mCheckSuccess) { + Assert.assertTrue( + "Failed command: " + mRevertCommand + + ", result: " + revertResult, + "Success".equals(result.replaceAll("\\s", ""))); + } } } } @@ -72,7 +102,15 @@ public class ShellCommandRule implements TestRule { * Sets the target launcher as default launcher. */ public static ShellCommandRule setDefaultLauncher() { - return new ShellCommandRule(getLauncherCommand(getLauncherInMyProcess()), null); + final ActivityInfo launcher = getLauncherInMyProcess(); + Log.d("b/187080582", "Launcher: " + new ComponentName(launcher.packageName, launcher.name) + .flattenToString()); + return new ShellCommandRule(getLauncherCommand(launcher), null, true, () -> + Assert.assertEquals("Setting default launcher failed", + new ComponentName(launcher.packageName, launcher.name) + .flattenToString(), + PackageManagerWrapper.getInstance().getHomeActivities(new ArrayList<>()) + .flattenToString())); } public static String getLauncherCommand(ActivityInfo launcher) { diff --git a/tests/src_common/com/android/launcher3/common/WidgetUtils.java b/tests/src_common/com/android/launcher3/common/WidgetUtils.java index 5e17e0a5a7..97500e3131 100644 --- a/tests/src_common/com/android/launcher3/common/WidgetUtils.java +++ b/tests/src_common/com/android/launcher3/common/WidgetUtils.java @@ -56,7 +56,9 @@ public class WidgetUtils { item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP; if (bindWidget) { - PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(info); + PendingAddWidgetInfo pendingInfo = + new PendingAddWidgetInfo( + info, LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY); pendingInfo.spanX = item.spanX; pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX;