Add getUserEventLogger to LauncherCallbacks

b/26494415

Change-Id: I8abaaf1269c12435a523e31bf769991018ea5c02
This commit is contained in:
Hyunyoung Song
2016-03-08 16:55:47 -08:00
parent 726eb822d3
commit 8fd5e938d3
9 changed files with 267 additions and 219 deletions
+36 -7
View File
@@ -82,7 +82,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
@@ -109,8 +108,10 @@ import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.logging.UserEventLogger;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.Logger;
import com.android.launcher3.logging.LoggerUtils;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.TestingUtils;
@@ -131,6 +132,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
/**
* Default launcher application.
@@ -366,7 +368,7 @@ public class Launcher extends Activity
}
private Stats mStats;
private Logger mUserEventLogger;
private UserEventLogger mUserEventLogger;
public FocusIndicatorView mFocusHandler;
private boolean mRotationEnabled = false;
@@ -425,8 +427,8 @@ public class Launcher extends Activity
mDragController = new DragController(this);
mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
mUserEventLogger = new Logger(this);
mStats = new Stats(this);
initLogger();
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
@@ -536,7 +538,7 @@ public class Launcher extends Activity
private boolean mWorkspaceImportanceStored = false;
private boolean mHotseatImportanceStored = false;
private int mWorkspaceImportanceForAccessibility =
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
@Override
@@ -632,7 +634,35 @@ public class Launcher extends Activity
public Stats getStats() {
return mStats;
}
public Logger getLogger() {return mUserEventLogger; }
/**
* Logger object is a singleton and does not have to be coupled with the foreground activity.
* Since most user event logging is done on the UI, the object is retrieved from the
* callback for convenience.
*/
private void initLogger() {
if (mLauncherCallbacks != null) {
mUserEventLogger = mLauncherCallbacks.getLogger();
}
if (mUserEventLogger == null) {
mUserEventLogger = new UserEventLogger() {
@Override
public void processEvent(LauncherLogProto.LauncherEvent ev) {
if (ev.action.touch == LauncherLogProto.Action.TAP && ev.srcTarget.itemType == LauncherLogProto.APP_ICON) {
Log.d(TAG, String.format(Locale.US, "action:%s target:%s\n\telapsed container %d ms session %d ms",
LoggerUtils.getActionStr(ev.action),
LoggerUtils.getTargetStr(ev.srcTarget),
ev.elapsedContainerMillis,
ev.elapsedSessionMillis));
}
}
};
}
}
public UserEventLogger getLogger() {
return mUserEventLogger;
}
public boolean isDraggingEnabled() {
// We prevent dragging when we are loading the workspace as it is possible to pick up a view
@@ -3302,7 +3332,6 @@ public class Launcher extends Activity
getWindow().getDecorView()
.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
mUserEventLogger.resetElapsedContainerMillis();
return changed;
}
@@ -8,6 +8,7 @@ import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import com.android.launcher3.allapps.AllAppsSearchBarController;
import com.android.launcher3.logging.UserEventLogger;
import com.android.launcher3.util.ComponentKey;
import java.io.FileDescriptor;
@@ -97,6 +98,7 @@ public interface LauncherCallbacks {
/*
* Extensions points for adding / replacing some other aspects of the Launcher experience.
*/
public UserEventLogger getLogger();
public Intent getFirstRunActivity();
public boolean hasFirstRunActivity();
public boolean hasDismissableIntroScreen();
@@ -148,6 +148,7 @@ public class LauncherStateTransitionAnimation {
}
@Override
void onTransitionComplete() {
mLauncher.getLogger().resetElapsedContainerMillis();
if (startSearchAfterTransition) {
toView.startAppsSearch();
}
@@ -167,7 +168,12 @@ public class LauncherStateTransitionAnimation {
final View buttonView = mLauncher.getWidgetsButton();
mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState,
Workspace.State.OVERVIEW_HIDDEN, buttonView, toView, animated,
new PrivateTransitionCallbacks(FINAL_REVEAL_ALPHA_FOR_WIDGETS));
new PrivateTransitionCallbacks(FINAL_REVEAL_ALPHA_FOR_WIDGETS){
@Override
void onTransitionComplete() {
mLauncher.getLogger().resetElapsedContainerMillis();
}
});
}
/**
@@ -462,6 +468,10 @@ public class LauncherStateTransitionAnimation {
}
};
}
@Override
void onTransitionComplete() {
mLauncher.getLogger().resetElapsedContainerMillis();
}
};
// Only animate the search bar if animating to spring loaded mode from all apps
mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState, toWorkspaceState,
@@ -488,6 +498,10 @@ public class LauncherStateTransitionAnimation {
}
};
}
@Override
void onTransitionComplete() {
mLauncher.getLogger().resetElapsedContainerMillis();
}
};
mCurrentAnimation = startAnimationToWorkspaceFromOverlay(
fromWorkspaceState, toWorkspaceState,
-1
View File
@@ -26,7 +26,6 @@ import android.view.View;
import android.view.ViewParent;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.userevent.Logger;
public class Stats {
@@ -47,7 +47,6 @@ import com.android.launcher3.LauncherTransitionable;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.Logger;
import com.android.launcher3.util.ComponentKey;
import java.nio.charset.Charset;
@@ -313,7 +312,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
icon.getMeasuredHeight());
updateBackgroundAndPaddings();
mLauncher.getLogger().resetElapsedContainerMillis();
}
@Override
@@ -0,0 +1,117 @@
package com.android.launcher3.logging;
import android.os.Bundle;
import android.util.Log;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Stats;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
/**
* Debugging helper methods.
* toString() cannot be overriden inside auto generated {@link LauncherLogProto}.
* Note: switch statement cannot be replaced with reflection as proguard strips the constants
*/
public class LoggerUtils {
private static final String TAG = "LoggerUtils";
private static final boolean DEBUG = false;
static int getContainerType(ShortcutInfo shortcut) {
switch ((int) shortcut.container) {
case LauncherSettings.Favorites.CONTAINER_DESKTOP: return LauncherLogProto.WORKSPACE;
case LauncherSettings.Favorites.CONTAINER_HOTSEAT: return LauncherLogProto.HOTSEAT;
default:
return (int) shortcut.container;
}
}
public static String getActionStr(LauncherLogProto.Action action) {
switch(action.touch) {
case Action.TAP: return "TAP";
case Action.LONGPRESS: return "LONGPRESS";
case Action.DRAGDROP: return "DRAGDROP";
case Action.PINCH: return "PINCH";
default: return "UNKNOWN";
}
}
public static String getTargetStr(Target t) {
String typeStr;
switch (t.type) {
case Target.ITEM:
return getItemStr(t);
case Target.CONTROL:
return getControlStr(t);
case Target.CONTAINER:
return getContainerStr(t);
default:
return "UNKNOWN TARGET TYPE";
}
}
private static String getItemStr(Target t) {
String typeStr = "";
switch(t.itemType){
case LauncherLogProto.APP_ICON: typeStr = "ICON"; break;
case LauncherLogProto.SHORTCUT: typeStr = "SHORTCUT"; break;
case LauncherLogProto.WIDGET: typeStr = "WIDGET"; break;
default: typeStr = "UNKNOWN";
}
return typeStr + " " + t.packageNameHash + " grid=(" + t.gridX + "," + t.gridY + ") "
+ getContainerStr(t.parent);
}
private static String getControlStr(Target t) {
switch(t.controlType) {
case LauncherLogProto.ALL_APPS_BUTTON: return "ALL_APPS_BUTTON";
case LauncherLogProto.WIDGETS_BUTTON: return "WIDGETS_BUTTON";
case LauncherLogProto.WALLPAPER_BUTTON: return "WALLPAPER_BUTTON";
case LauncherLogProto.SETTINGS_BUTTON: return "SETTINGS_BUTTON";
case LauncherLogProto.REMOVE_TARGET: return "REMOVE_TARGET";
case LauncherLogProto.UNINSTALL_TARGET: return "UNINSTALL_TARGET";
case LauncherLogProto.APPINFO_TARGET: return "APPINFO_TARGET";
case LauncherLogProto.RESIZE_HANDLE: return "RESIZE_HANDLE";
case LauncherLogProto.FAST_SCROLL_HANDLE: return "FAST_SCROLL_HANDLE";
default: return "UNKNOWN";
}
}
private static String getContainerStr(LauncherLogProto.Target t) {
String str;
Log.d(TAG, "t.containerType" + t.containerType);
switch (t.containerType) {
case LauncherLogProto.WORKSPACE:
str = "WORKSPACE";
break;
case LauncherLogProto.HOTSEAT:
str = "HOTSEAT";
break;
case LauncherLogProto.FOLDER:
str = "FOLDER";
break;
case LauncherLogProto.ALLAPPS:
str = "ALLAPPS";
break;
case LauncherLogProto.WIDGETS:
str = "WIDGETS";
break;
case LauncherLogProto.OVERVIEW:
str = "OVERVIEW";
break;
case LauncherLogProto.PREDICTION:
str = "PREDICTION";
break;
case LauncherLogProto.SEARCHRESULT:
str = "SEARCHRESULT";
break;
default:
str = "UNKNOWN";
}
return str + " id=" + t.pageIndex;
}
}
@@ -1,4 +1,97 @@
package com.android.launcher3.logging;
import android.os.Bundle;
import android.util.Log;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Stats;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import java.util.Locale;
public abstract class UserEventLogger {
private String TAG = "UserEventLogger";
private boolean DEBUG = false;
private long mElapsedContainerMillis;
private long mElapsedSessionMillis;
private long mActionDurationMillis;
public final void logAppLaunch(String provider, ShortcutInfo shortcut, Bundle bundle) {
if (FeatureFlags.LAUNCHER3_LEGACY_LOGGING) return;
LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
event.action = new LauncherLogProto.Action();
event.action.type = LauncherLogProto.Action.TOUCH;
event.action.touch = LauncherLogProto.Action.TAP;
event.srcTarget = new LauncherLogProto.Target();
event.srcTarget.type = LauncherLogProto.Target.ITEM;
event.srcTarget.itemType = LauncherLogProto.APP_ICON;
// TODO: package hash name should be different per device.
event.srcTarget.packageNameHash = provider.hashCode();
event.srcTarget.parent = new LauncherLogProto.Target();
String subContainer = bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER);
if (shortcut != null) {
event.srcTarget.parent.containerType = LoggerUtils.getContainerType(shortcut);
event.srcTarget.pageIndex = (int) shortcut.screenId;
event.srcTarget.gridX = shortcut.cellX;
event.srcTarget.gridX = shortcut.cellY;
}
if (subContainer != null) {
event.srcTarget.parent.type = LauncherLogProto.Target.CONTAINER;
if (subContainer.equals(Stats.SUB_CONTAINER_FOLDER)) {
event.srcTarget.parent.containerType = LauncherLogProto.FOLDER;
} else if (subContainer.equals(Stats.SUB_CONTAINER_ALL_APPS_A_Z)) {
event.srcTarget.parent.containerType = LauncherLogProto.ALLAPPS;
} else if (subContainer.equals(Stats.CONTAINER_HOTSEAT)) {
event.srcTarget.parent.containerType = LauncherLogProto.HOTSEAT;
} else if (subContainer.equals(Stats.SUB_CONTAINER_ALL_APPS_PREDICTION)) {
event.srcTarget.parent.containerType = LauncherLogProto.PREDICTION;
}
if (DEBUG) {
Log.d(TAG, String.format("parent bundle: %s %s %s %s",
bundle.getString(Stats.SOURCE_EXTRA_CONTAINER),
bundle.getString(Stats.SOURCE_EXTRA_CONTAINER_PAGE),
bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER),
bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER_PAGE)));
}
}
event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
processEvent(event);
}
/**
* Currently logs following containers: workspace, allapps, widget tray.
*/
public final void resetElapsedContainerMillis() {
mElapsedContainerMillis = System.currentTimeMillis();
if(DEBUG) {
Log.d(TAG, "resetElapsedContainerMillis " + mElapsedContainerMillis);
}
}
public final void resetElapsedSessionMillis() {
mElapsedSessionMillis = System.currentTimeMillis();
mElapsedContainerMillis = System.currentTimeMillis();
if(DEBUG) {
Log.d(TAG, "resetElapsedSessionMillis " + mElapsedSessionMillis);
}
}
public final void resetActionDurationMillis() {
mActionDurationMillis = System.currentTimeMillis();
if(DEBUG) {
Log.d(TAG, "resetElapsedContainerMillis " + mElapsedContainerMillis);
}
}
public abstract void processEvent(LauncherLogProto.LauncherEvent ev);
}
@@ -11,6 +11,7 @@ import android.widget.FrameLayout;
import com.android.launcher3.AppInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherCallbacks;
import com.android.launcher3.logging.UserEventLogger;
import com.android.launcher3.allapps.AllAppsSearchBarController;
import com.android.launcher3.util.ComponentKey;
@@ -224,6 +225,9 @@ public class LauncherExtension extends Launcher {
addToCustomContentPage(customContent, mCustomContentCallbacks, "");
}
@Override
public UserEventLogger getLogger() { return null; }
@Override
public View getQsbBar() {
return null;
@@ -1,208 +0,0 @@
package com.android.launcher3.userevent;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.Stats;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import java.util.Locale;
/**
* Creates {@LauncherLogProto} nano protobuf object that can be used for user event
* metrics analysis.
*/
public class Logger {
private static final String TAG = "UserEventLogger";
private static final boolean DEBUG = false;
private long mActionDurationMillis;
private long mElapsedContainerMillis;
private long mElapsedSessionMillis;
private Context mContext;
public Logger(Context context) {
mContext = context;
}
public void logAppLaunch(String provider, ShortcutInfo shortcut, Bundle bundle) {
LauncherEvent event = new LauncherEvent();
event.action = new Action();
event.action.type = Action.TOUCH;
event.action.touch = Action.TAP;
event.srcTarget = new Target();
event.srcTarget.type = Target.ITEM;
event.srcTarget.itemType = LauncherLogProto.APP_ICON;
// TODO: package hash name should be different per device.
event.srcTarget.packageNameHash = provider.hashCode();
event.srcTarget.parent = new Target();
String subContainer = bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER);
if (shortcut != null) {
event.srcTarget.parent.containerType = getContainerType(shortcut);
event.srcTarget.pageIndex = (int) shortcut.screenId;
event.srcTarget.gridX = shortcut.cellX;
event.srcTarget.gridX = shortcut.cellY;
}
if (subContainer != null) {
event.srcTarget.parent.type = Target.CONTAINER;
if (subContainer.equals(Stats.SUB_CONTAINER_FOLDER)) {
event.srcTarget.parent.containerType = LauncherLogProto.FOLDER;
} else if (subContainer.equals(Stats.SUB_CONTAINER_ALL_APPS_A_Z)) {
event.srcTarget.parent.containerType = LauncherLogProto.ALLAPPS;
} else if (subContainer.equals(Stats.CONTAINER_HOTSEAT)) {
event.srcTarget.parent.containerType = LauncherLogProto.HOTSEAT;
} else if (subContainer.equals(Stats.SUB_CONTAINER_ALL_APPS_PREDICTION)) {
event.srcTarget.parent.containerType = LauncherLogProto.PREDICTION;
}
if (DEBUG) {
Log.d(TAG, String.format("parent bundle: %s %s %s %s",
bundle.getString(Stats.SOURCE_EXTRA_CONTAINER),
bundle.getString(Stats.SOURCE_EXTRA_CONTAINER_PAGE),
bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER),
bundle.getString(Stats.SOURCE_EXTRA_SUB_CONTAINER_PAGE)));
}
}
// Assign timeToAction
event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
// Debug
processLauncherEvent(event);
}
public void resetElapsedContainerMillis() {
mElapsedContainerMillis = System.currentTimeMillis();
}
public void resetElapsedSessionMillis() {
mElapsedSessionMillis = System.currentTimeMillis();
}
//
// Debugging helper methods.
// toString() cannot be overriden inside auto generated {@link LauncherLogProto}.
// Note: switch statement cannot be replaced with reflection as proguard strips the constants
private static void processLauncherEvent(LauncherEvent ev) {
if (DEBUG) {
if (ev.action.touch == Action.TAP && ev.srcTarget.itemType == LauncherLogProto.APP_ICON) {
Log.d(TAG, String.format(Locale.US, "action:%s target:%s\n\telapsed container %d ms session %d ms",
getActionStr(ev.action),
getTargetStr(ev.srcTarget),
ev.elapsedContainerMillis,
ev.elapsedSessionMillis));
}
}
}
private static int getContainerType(ShortcutInfo shortcut) {
switch ((int) shortcut.container) {
case LauncherSettings.Favorites.CONTAINER_DESKTOP: return LauncherLogProto.WORKSPACE;
case LauncherSettings.Favorites.CONTAINER_HOTSEAT: return LauncherLogProto.HOTSEAT;
default:
return (int) shortcut.container;
}
}
private static String getActionStr(Action action) {
switch(action.touch) {
case Action.TAP: return "TAP";
case Action.LONGPRESS: return "LONGPRESS";
case Action.DRAGDROP: return "DRAGDROP";
case Action.PINCH: return "PINCH";
default: return "UNKNOWN";
}
}
private static String getTargetStr(Target t) {
String typeStr;
switch (t.type) {
case LauncherLogProto.Target.ITEM:
return getItemStr(t);
case LauncherLogProto.Target.CONTROL:
return getControlStr(t);
case LauncherLogProto.Target.CONTAINER:
return getContainerStr(t);
default:
return "UNKNOWN TARGET TYPE";
}
}
private static String getItemStr(Target t) {
String typeStr = "";
switch(t.itemType){
case LauncherLogProto.APP_ICON: typeStr = "ICON"; break;
case LauncherLogProto.SHORTCUT: typeStr = "SHORTCUT"; break;
case LauncherLogProto.WIDGET: typeStr = "WIDGET"; break;
default: typeStr = "UNKNOWN";
}
return typeStr + " " + t.packageNameHash + " grid=(" + t.gridX + "," + t.gridY + ") "
+ getContainerStr(t.parent);
}
private static String getControlStr(Target t) {
switch(t.controlType) {
case LauncherLogProto.ALL_APPS_BUTTON: return "ALL_APPS_BUTTON";
case LauncherLogProto.WIDGETS_BUTTON: return "WIDGETS_BUTTON";
case LauncherLogProto.WALLPAPER_BUTTON: return "WALLPAPER_BUTTON";
case LauncherLogProto.SETTINGS_BUTTON: return "SETTINGS_BUTTON";
case LauncherLogProto.REMOVE_TARGET: return "REMOVE_TARGET";
case LauncherLogProto.UNINSTALL_TARGET: return "UNINSTALL_TARGET";
case LauncherLogProto.APPINFO_TARGET: return "APPINFO_TARGET";
case LauncherLogProto.RESIZE_HANDLE: return "RESIZE_HANDLE";
case LauncherLogProto.FAST_SCROLL_HANDLE: return "FAST_SCROLL_HANDLE";
default: return "UNKNOWN";
}
}
private static String getContainerStr(Target t) {
String str;
Log.d(TAG, "t.containerType" + t.containerType);
switch (t.containerType) {
case LauncherLogProto.WORKSPACE:
str = "WORKSPACE";
break;
case LauncherLogProto.HOTSEAT:
str = "HOTSEAT";
break;
case LauncherLogProto.FOLDER:
str = "FOLDER";
break;
case LauncherLogProto.ALLAPPS:
str = "ALLAPPS";
break;
case LauncherLogProto.WIDGETS:
str = "WIDGETS";
break;
case LauncherLogProto.OVERVIEW:
str = "OVERVIEW";
break;
case LauncherLogProto.PREDICTION:
str = "PREDICTION";
break;
case LauncherLogProto.SEARCHRESULT:
str = "SEARCHRESULT";
break;
default:
str = "UNKNOWN";
}
return str + " id=" + t.pageIndex;
}
}