Adding logging for various interaction in PinItemRequest UI

Bug: 34766840
Change-Id: Ib29d7d4b53ab99cdf3ff253976ef55345729487b
diff --git a/protos/launcher_log.proto b/protos/launcher_log.proto
index c42b142..68a6b28 100644
--- a/protos/launcher_log.proto
+++ b/protos/launcher_log.proto
@@ -79,6 +79,7 @@
   PREDICTION = 7;
   SEARCHRESULT = 8;
   DEEPSHORTCUTS = 9;
+  PINITEM = 10;    // confirmation screen
 }
 
 // Used to define what type of control a Target would represent.
@@ -124,6 +125,10 @@
   enum Command {
     HOME_INTENT = 0;
     BACK = 1;
+    ENTRY = 2;    // Indicates entry to one of Launcher container type target
+                  // not using the HOME_INTENT
+    CANCEL = 3;   // Indicates that a confirmation screen was cancelled
+    CONFIRM = 4;  // Indicates thata confirmation screen was accepted
   }
   optional Type type = 1;
   optional Touch touch = 2;
diff --git a/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java b/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java
index ebe95d6..4a55e8c 100644
--- a/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java
+++ b/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java
@@ -33,6 +33,7 @@
 import android.widget.Toast;
 
 import com.android.launcher3.IconCache;
+import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.R;
 import com.android.launcher3.ShortcutInfo;
 
@@ -61,6 +62,10 @@
         return mUser;
     }
 
+    public int getItemType() {
+        return LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
+    }
+
     public abstract CharSequence getLabel();
 
     public abstract Drawable getFullResIcon(IconCache cache);
diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java
index c2a4820..6b27a99 100644
--- a/src/com/android/launcher3/dragndrop/AddItemActivity.java
+++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java
@@ -16,6 +16,11 @@
 
 package com.android.launcher3.dragndrop;
 
+import static com.android.launcher3.logging.LoggerUtils.newCommandAction;
+import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
+import static com.android.launcher3.logging.LoggerUtils.newItemTarget;
+import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent;
+
 import android.annotation.TargetApi;
 import android.app.ActivityOptions;
 import android.appwidget.AppWidgetHost;
@@ -31,7 +36,9 @@
 import android.os.Bundle;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.View.*;
+import android.view.View.DragShadowBuilder;
+import android.view.View.OnLongClickListener;
+import android.view.View.OnTouchListener;
 
 import com.android.launcher3.BaseActivity;
 import com.android.launcher3.InstallShortcutReceiver;
@@ -44,6 +51,9 @@
 import com.android.launcher3.compat.PinItemRequestCompat;
 import com.android.launcher3.model.WidgetItem;
 import com.android.launcher3.shortcuts.ShortcutInfoCompat;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
+import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
+import com.android.launcher3.widget.PendingAddShortcutInfo;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.WidgetHostViewLoader;
 import com.android.launcher3.widget.WidgetImageView;
@@ -102,6 +112,12 @@
 
         mWidgetCell.setOnTouchListener(this);
         mWidgetCell.setOnLongClickListener(this);
+
+        // savedInstanceState is null when the activity is created the first time (i.e., avoids
+        // duplicate logging during rotation)
+        if (savedInstanceState == null) {
+            logCommand(Action.Command.ENTRY);
+        }
     }
 
     @Override
@@ -154,7 +170,10 @@
     }
 
     private void setupShortcut() {
-        WidgetItem item = new WidgetItem(new PinShortcutRequestActivityInfo(mRequest, this));
+        PinShortcutRequestActivityInfo shortcutInfo =
+                new PinShortcutRequestActivityInfo(mRequest, this);
+        WidgetItem item = new WidgetItem(shortcutInfo);
+        mWidgetCell.getWidgetView().setTag(new PendingAddShortcutInfo(shortcutInfo));
         mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
         mWidgetCell.ensurePreview();
     }
@@ -177,6 +196,7 @@
         mWidgetOptions = WidgetHostViewLoader.getDefaultOptionsForWidget(this, mPendingWidgetInfo);
 
         WidgetItem item = new WidgetItem(widgetInfo, getPackageManager(), mIdp);
+        mWidgetCell.getWidgetView().setTag(mPendingWidgetInfo);
         mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
         mWidgetCell.ensurePreview();
         return true;
@@ -186,6 +206,7 @@
      * Called when the cancel button is clicked.
      */
     public void onCancelClick(View v) {
+        logCommand(Action.Command.CANCEL);
         finish();
     }
 
@@ -196,6 +217,7 @@
         if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) {
             InstallShortcutReceiver.queueShortcut(
                     new ShortcutInfoCompat(mRequest.getShortcutInfo()), this);
+            logCommand(Action.Command.CONFIRM);
             mRequest.accept();
             finish();
             return;
@@ -223,10 +245,17 @@
         InstallShortcutReceiver.queueWidget(mRequest.getAppWidgetProviderInfo(this), widgetId, this);
         mWidgetOptions.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
         mRequest.accept(mWidgetOptions);
+        logCommand(Action.Command.CONFIRM);
         finish();
     }
 
     @Override
+    public void onBackPressed() {
+        logCommand(Action.Command.BACK);
+        super.onBackPressed();
+    }
+
+    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (requestCode == REQUEST_BIND_APPWIDGET) {
             int widgetId = data != null
@@ -256,4 +285,11 @@
         mPendingBindWidgetId = savedInstanceState
                 .getInt(STATE_EXTRA_WIDGET_ID, mPendingBindWidgetId);
     }
+
+    private void logCommand(int command) {
+        getUserEventDispatcher().dispatchUserEvent(newLauncherEvent(
+                newCommandAction(command),
+                newItemTarget(mWidgetCell.getWidgetView()),
+                newContainerTarget(ContainerType.PINITEM)), null);
+    }
 }
diff --git a/src/com/android/launcher3/dragndrop/PinItemDragListener.java b/src/com/android/launcher3/dragndrop/PinItemDragListener.java
index fd252a2..dfc6566 100644
--- a/src/com/android/launcher3/dragndrop/PinItemDragListener.java
+++ b/src/com/android/launcher3/dragndrop/PinItemDragListener.java
@@ -42,6 +42,7 @@
 import com.android.launcher3.compat.PinItemRequestCompat;
 import com.android.launcher3.folder.Folder;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
 import com.android.launcher3.widget.PendingAddShortcutInfo;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.PendingItemDragHelper;
@@ -240,7 +241,7 @@
     @Override
     public void fillInLogContainerData(View v, ItemInfo info, LauncherLogProto.Target target,
             LauncherLogProto.Target targetParent) {
-        // TODO: We should probably log something
+        targetParent.containerType = ContainerType.PINITEM;
     }
 
     private void postCleanup() {
diff --git a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
index 6a8c19f..26460d7 100644
--- a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
+++ b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
@@ -27,6 +27,7 @@
 
 import com.android.launcher3.IconCache;
 import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.compat.LauncherAppsCompat;
 import com.android.launcher3.compat.PinItemRequestCompat;
 import com.android.launcher3.compat.ShortcutConfigActivityInfo;
@@ -55,6 +56,11 @@
     }
 
     @Override
+    public int getItemType() {
+        return LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
+    }
+
+    @Override
     public CharSequence getLabel() {
         return mInfo.getShortLabel();
     }
diff --git a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
index 7eeb8bf..e8f13a1 100644
--- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
@@ -32,6 +32,6 @@
         this.activityInfo = activityInfo;
         componentName = activityInfo.getComponent();
         user = activityInfo.getUser();
-        itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
+        itemType = activityInfo.getItemType();
     }
 }