From 6bf6848951666ed1f5d4779f62ef98643aabb351 Mon Sep 17 00:00:00 2001 From: thiruram Date: Wed, 6 May 2020 22:19:43 -0700 Subject: [PATCH] Introduces CONTAINER_WIDGETS_TRAY to LauncherSettings.Favorites. This would log LAUNCHER_ITEM_DRAG_STARTED event when an item is dragged from widgets tray. This also fixes empty component with widget logs. Sample Log: https://docs.google.com/document/d/1CBP2yTcXdFhPdNG5ZmWFKSgd8mDbMevY-akVlUXPLDo/edit#bookmark=id.bk5w3n8uwhcl Bug: 152978018 Change-Id: I51d16edae13973d5e62adda0e4efa861fa10dc1b --- protos/launcher_atom.proto | 4 +++ .../android/launcher3/LauncherSettings.java | 4 +++ .../android/launcher3/PendingAddItemInfo.java | 27 ++++++++++++++++--- src/com/android/launcher3/Workspace.java | 13 ++++++--- .../launcher3/model/data/ItemInfo.java | 6 +++++ .../widget/PendingAddShortcutInfo.java | 3 +++ .../widget/PendingAddWidgetInfo.java | 3 +++ 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/protos/launcher_atom.proto b/protos/launcher_atom.proto index f1b71e8868..f1db144604 100644 --- a/protos/launcher_atom.proto +++ b/protos/launcher_atom.proto @@ -48,12 +48,16 @@ message ContainerInfo { HotseatContainer hotseat = 2; FolderContainer folder = 3; AllAppsContainer all_apps_container = 4; + WidgetsContainer widgets_container = 5; } } message AllAppsContainer { } +message WidgetsContainer { +} + enum Origin { UNKNOWN = 0; DEFAULT_LAYOUT = 1; // icon automatically placed in workspace, folder, hotseat diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java index 87ead9e7b5..535c9e6c70 100644 --- a/src/com/android/launcher3/LauncherSettings.java +++ b/src/com/android/launcher3/LauncherSettings.java @@ -153,12 +153,16 @@ public class LauncherSettings { public static final int CONTAINER_PREDICTION = -102; public static final int CONTAINER_HOTSEAT_PREDICTION = -103; public static final int CONTAINER_ALL_APPS = -104; + public static final int CONTAINER_WIDGETS_TRAY = -105; + public static final String containerToString(int container) { switch (container) { case CONTAINER_DESKTOP: return "desktop"; case CONTAINER_HOTSEAT: return "hotseat"; case CONTAINER_PREDICTION: return "prediction"; + case CONTAINER_ALL_APPS: return "all_apps"; + case CONTAINER_WIDGETS_TRAY: return "widgets_tray"; default: return String.valueOf(container); } } diff --git a/src/com/android/launcher3/PendingAddItemInfo.java b/src/com/android/launcher3/PendingAddItemInfo.java index 29c9d935ae..be994ee138 100644 --- a/src/com/android/launcher3/PendingAddItemInfo.java +++ b/src/com/android/launcher3/PendingAddItemInfo.java @@ -18,12 +18,15 @@ package com.android.launcher3; import android.content.ComponentName; +import androidx.annotation.Nullable; + import com.android.launcher3.model.data.ItemInfo; +import java.util.Optional; + /** - * Meta data that is used for deferred binding. - * e.g., this object is used to pass information on draggable targets when they are dropped onto - * the workspace from another container. + * Meta data that is used for deferred binding. e.g., this object is used to pass information on + * draggable targets when they are dropped onto the workspace from another container. */ public class PendingAddItemInfo extends ItemInfo { @@ -36,4 +39,22 @@ public class PendingAddItemInfo extends ItemInfo { protected String dumpProperties() { return super.dumpProperties() + " componentName=" + componentName; } + + /** + * Returns shallow copy of the object. + */ + @Override + public ItemInfo makeShallowCopy() { + PendingAddItemInfo itemInfo = new PendingAddItemInfo(); + itemInfo.copyFrom(this); + itemInfo.componentName = this.componentName; + return itemInfo; + } + + @Nullable + @Override + public ComponentName getTargetComponent() { + return Optional.ofNullable(super.getTargetComponent()).orElse(componentName); + } + } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 286b522636..6b660c1ab8 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2438,6 +2438,10 @@ public class Workspace extends PagedView // widgets/shortcuts/folders in a slightly different way mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, item.spanX, item.spanY); + mStatsLogManager.log( + LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED, + d.logInstanceId, + d.dragInfo.buildProto(null)); } }; boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET @@ -2526,11 +2530,12 @@ public class Workspace extends PagedView mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, this); resetTransitionTransform(); } + mStatsLogManager.log( + LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED, + d.logInstanceId, + d.dragInfo.buildProto(null)); } - mStatsLogManager.log( - LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED, - d.logInstanceId, - d.dragInfo.buildProto(null)); + } public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) { diff --git a/src/com/android/launcher3/model/data/ItemInfo.java b/src/com/android/launcher3/model/data/ItemInfo.java index f2b7e54a12..a97d52969b 100644 --- a/src/com/android/launcher3/model/data/ItemInfo.java +++ b/src/com/android/launcher3/model/data/ItemInfo.java @@ -20,6 +20,7 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APP import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; @@ -342,6 +343,11 @@ public class ItemInfo { .setAllAppsContainer( AllAppsContainer.getDefaultInstance()) .build(); + case CONTAINER_WIDGETS_TRAY: + return ContainerInfo.newBuilder() + .setWidgetsContainer( + LauncherAtom.WidgetsContainer.getDefaultInstance()) + .build(); } return ContainerInfo.getDefaultInstance(); } diff --git a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java index 6e21a41b27..96016526a7 100644 --- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java +++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY; + import com.android.launcher3.PendingAddItemInfo; import com.android.launcher3.pm.ShortcutConfigActivityInfo; @@ -32,5 +34,6 @@ public class PendingAddShortcutInfo extends PendingAddItemInfo { componentName = activityInfo.getComponent(); user = activityInfo.getUser(); itemType = activityInfo.getItemType(); + this.container = CONTAINER_WIDGETS_TRAY; } } diff --git a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java index bc404842eb..bef9a08f14 100644 --- a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java +++ b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY; + import android.appwidget.AppWidgetHostView; import android.os.Bundle; @@ -50,6 +52,7 @@ public class PendingAddWidgetInfo extends PendingAddItemInfo { spanY = i.spanY; minSpanX = i.minSpanX; minSpanY = i.minSpanY; + this.container = CONTAINER_WIDGETS_TRAY; } public WidgetAddFlowHandler getHandler() {