From 778634c81870ae2013907950a98bb7793802e6c7 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 21 Mar 2017 11:59:04 -0700 Subject: [PATCH] Adding logging for various interaction in PinItemRequest UI Bug: 34766840 Change-Id: Ib29d7d4b53ab99cdf3ff253976ef55345729487b --- protos/launcher_log.proto | 5 +++ .../compat/ShortcutConfigActivityInfo.java | 5 +++ .../launcher3/dragndrop/AddItemActivity.java | 40 ++++++++++++++++++- .../dragndrop/PinItemDragListener.java | 3 +- .../PinShortcutRequestActivityInfo.java | 6 +++ .../widget/PendingAddShortcutInfo.java | 2 +- 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/protos/launcher_log.proto b/protos/launcher_log.proto index c42b142f72..68a6b28cdb 100644 --- a/protos/launcher_log.proto +++ b/protos/launcher_log.proto @@ -79,6 +79,7 @@ enum ContainerType { 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 @@ message Action { 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 ebe95d6805..4a55e8ca04 100644 --- a/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java +++ b/src/com/android/launcher3/compat/ShortcutConfigActivityInfo.java @@ -33,6 +33,7 @@ import android.util.Log; 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 @@ public abstract class ShortcutConfigActivityInfo { 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 c2a4820c8d..6b27a9992d 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.Build; 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.AppWidgetManagerCompat; 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 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener 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 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener } 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 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener 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 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener * Called when the cancel button is clicked. */ public void onCancelClick(View v) { + logCommand(Action.Command.CANCEL); finish(); } @@ -196,6 +217,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) { InstallShortcutReceiver.queueShortcut( new ShortcutInfoCompat(mRequest.getShortcutInfo()), this); + logCommand(Action.Command.CONFIRM); mRequest.accept(); finish(); return; @@ -223,9 +245,16 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener 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) { @@ -256,4 +285,11 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener 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 fd252a26ae..dfc65660e5 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.R; 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 @@ public class PinItemDragListener @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 6a8c19f4bd..26460d7761 100644 --- a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java +++ b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java @@ -27,6 +27,7 @@ import android.os.Build; 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; @@ -54,6 +55,11 @@ class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo { mContext = context; } + @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 7eeb8bf57a..e8f13a13ce 100644 --- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java +++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java @@ -32,6 +32,6 @@ public class PendingAddShortcutInfo extends PendingAddItemInfo { this.activityInfo = activityInfo; componentName = activityInfo.getComponent(); user = activityInfo.getUser(); - itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; + itemType = activityInfo.getItemType(); } }