2016-03-08 16:55:47 -08:00
|
|
|
package com.android.launcher3.logging;
|
|
|
|
|
|
2016-11-23 02:24:32 +05:30
|
|
|
import android.util.ArrayMap;
|
|
|
|
|
import android.util.SparseArray;
|
2016-08-15 16:22:20 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
|
2016-09-01 12:47:12 -07:00
|
|
|
import com.android.launcher3.ButtonDropTarget;
|
|
|
|
|
import com.android.launcher3.DeleteDropTarget;
|
|
|
|
|
import com.android.launcher3.InfoDropTarget;
|
2016-08-15 16:22:20 -07:00
|
|
|
import com.android.launcher3.ItemInfo;
|
|
|
|
|
import com.android.launcher3.LauncherSettings;
|
2016-09-01 12:47:12 -07:00
|
|
|
import com.android.launcher3.UninstallDropTarget;
|
2016-03-08 16:55:47 -08:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
2016-11-23 02:24:32 +05:30
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
|
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
|
|
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ItemType;
|
2016-11-22 23:49:52 +05:30
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
|
2016-03-08 16:55:47 -08:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
|
|
|
|
|
2016-11-23 02:24:32 +05:30
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
|
|
2016-03-08 16:55:47 -08:00
|
|
|
/**
|
2016-11-23 02:24:32 +05:30
|
|
|
* Helper methods for logging.
|
2016-03-08 16:55:47 -08:00
|
|
|
*/
|
|
|
|
|
public class LoggerUtils {
|
2016-11-23 02:24:32 +05:30
|
|
|
private static final ArrayMap<Class, SparseArray<String>> sNameCache = new ArrayMap<>();
|
|
|
|
|
private static final String UNKNOWN = "UNKNOWN";
|
|
|
|
|
|
|
|
|
|
private static String getFieldName(int value, Class c) {
|
|
|
|
|
SparseArray<String> cache;
|
|
|
|
|
synchronized (sNameCache) {
|
|
|
|
|
cache = sNameCache.get(c);
|
|
|
|
|
if (cache == null) {
|
|
|
|
|
cache = new SparseArray<>();
|
|
|
|
|
for (Field f : c.getDeclaredFields()) {
|
|
|
|
|
if (f.getType() == int.class && Modifier.isStatic(f.getModifiers())) {
|
|
|
|
|
try {
|
|
|
|
|
f.setAccessible(true);
|
|
|
|
|
cache.put(f.getInt(null), f.getName());
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
// Ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sNameCache.put(c, cache);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String result = cache.get(value);
|
|
|
|
|
return result != null ? result : UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getActionStr(Action action) {
|
2016-10-06 10:53:29 -07:00
|
|
|
switch (action.type) {
|
2016-11-23 02:24:32 +05:30
|
|
|
case Action.Type.TOUCH: return getFieldName(action.touch, Action.Touch.class);
|
|
|
|
|
case Action.Type.COMMAND: return getFieldName(action.command, Action.Command.class);
|
|
|
|
|
default: return UNKNOWN;
|
2016-10-06 10:53:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 16:55:47 -08:00
|
|
|
public static String getTargetStr(Target t) {
|
2016-07-21 11:48:37 -07:00
|
|
|
if (t == null){
|
2016-11-23 02:24:32 +05:30
|
|
|
return "";
|
2016-07-21 11:48:37 -07:00
|
|
|
}
|
2016-03-08 16:55:47 -08:00
|
|
|
switch (t.type) {
|
2016-11-23 02:24:32 +05:30
|
|
|
case Target.Type.ITEM:
|
2016-03-08 16:55:47 -08:00
|
|
|
return getItemStr(t);
|
2016-11-23 02:24:32 +05:30
|
|
|
case Target.Type.CONTROL:
|
|
|
|
|
return getFieldName(t.controlType, ControlType.class);
|
|
|
|
|
case Target.Type.CONTAINER:
|
|
|
|
|
return getFieldName(t.containerType, ContainerType.class)
|
|
|
|
|
+ " id=" + t.pageIndex;
|
2016-03-08 16:55:47 -08:00
|
|
|
default:
|
|
|
|
|
return "UNKNOWN TARGET TYPE";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getItemStr(Target t) {
|
2016-11-23 02:24:32 +05:30
|
|
|
String typeStr = getFieldName(t.itemType, ItemType.class);
|
2016-08-15 16:22:20 -07:00
|
|
|
if (t.packageNameHash != 0) {
|
|
|
|
|
typeStr += ", packageHash=" + t.packageNameHash;
|
|
|
|
|
}
|
|
|
|
|
if (t.componentHash != 0) {
|
|
|
|
|
typeStr += ", componentHash=" + t.componentHash;
|
|
|
|
|
}
|
|
|
|
|
if (t.intentHash != 0) {
|
|
|
|
|
typeStr += ", intentHash=" + t.intentHash;
|
|
|
|
|
}
|
2016-10-03 14:01:25 -07:00
|
|
|
if (t.spanX != 0) {
|
|
|
|
|
typeStr += ", spanX=" + t.spanX;
|
|
|
|
|
}
|
2016-11-23 02:24:32 +05:30
|
|
|
return typeStr + ", grid=(" + t.gridX + "," + t.gridY + "), id=" + t.pageIndex;
|
2016-03-08 16:55:47 -08:00
|
|
|
}
|
2016-04-12 18:32:04 -07:00
|
|
|
|
2016-11-22 23:49:52 +05:30
|
|
|
public static Target newItemTarget(View v) {
|
|
|
|
|
return (v.getTag() instanceof ItemInfo)
|
|
|
|
|
? newItemTarget((ItemInfo) v.getTag())
|
2016-11-23 02:24:32 +05:30
|
|
|
: newTarget(Target.Type.ITEM);
|
2016-09-01 12:47:12 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 23:49:52 +05:30
|
|
|
public static Target newItemTarget(ItemInfo info) {
|
2016-11-23 02:24:32 +05:30
|
|
|
Target t = newTarget(Target.Type.ITEM);
|
2016-09-01 12:47:12 -07:00
|
|
|
switch (info.itemType) {
|
2016-08-15 16:22:20 -07:00
|
|
|
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
|
2016-11-23 02:24:32 +05:30
|
|
|
t.itemType = ItemType.APP_ICON;
|
2016-08-15 16:22:20 -07:00
|
|
|
break;
|
|
|
|
|
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
|
2016-11-23 02:24:32 +05:30
|
|
|
t.itemType = ItemType.SHORTCUT;
|
2016-08-15 16:22:20 -07:00
|
|
|
break;
|
|
|
|
|
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
|
2016-11-23 02:24:32 +05:30
|
|
|
t.itemType = ItemType.FOLDER_ICON;
|
2016-08-15 16:22:20 -07:00
|
|
|
break;
|
|
|
|
|
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
|
2016-11-23 02:24:32 +05:30
|
|
|
t.itemType = ItemType.WIDGET;
|
2016-08-15 16:22:20 -07:00
|
|
|
break;
|
|
|
|
|
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
|
2016-11-23 02:24:32 +05:30
|
|
|
t.itemType = ItemType.DEEPSHORTCUT;
|
2016-08-15 16:22:20 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
2016-09-01 12:47:12 -07:00
|
|
|
|
2016-11-22 23:49:52 +05:30
|
|
|
public static Target newDropTarget(View v) {
|
|
|
|
|
if (!(v instanceof ButtonDropTarget)) {
|
2016-11-23 02:24:32 +05:30
|
|
|
return newTarget(Target.Type.CONTAINER);
|
2016-09-01 12:47:12 -07:00
|
|
|
}
|
2016-11-23 02:24:32 +05:30
|
|
|
Target t = newTarget(Target.Type.CONTROL);
|
2016-09-01 12:47:12 -07:00
|
|
|
if (v instanceof InfoDropTarget) {
|
2016-11-23 02:24:32 +05:30
|
|
|
t.controlType = ControlType.APPINFO_TARGET;
|
2016-09-01 12:47:12 -07:00
|
|
|
} else if (v instanceof UninstallDropTarget) {
|
2016-11-23 02:24:32 +05:30
|
|
|
t.controlType = ControlType.UNINSTALL_TARGET;
|
2016-09-01 12:47:12 -07:00
|
|
|
} else if (v instanceof DeleteDropTarget) {
|
2016-11-23 02:24:32 +05:30
|
|
|
t.controlType = ControlType.REMOVE_TARGET;
|
2016-09-01 12:47:12 -07:00
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 23:49:52 +05:30
|
|
|
public static Target newTarget(int targetType) {
|
2016-11-23 02:24:32 +05:30
|
|
|
Target t = new Target();
|
2016-11-22 23:49:52 +05:30
|
|
|
t.type = targetType;
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
public static Target newContainerTarget(int containerType) {
|
2016-11-23 02:24:32 +05:30
|
|
|
Target t = newTarget(Target.Type.CONTAINER);
|
2016-11-22 23:49:52 +05:30
|
|
|
t.containerType = containerType;
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Action newAction(int type) {
|
|
|
|
|
Action a = new Action();
|
|
|
|
|
a.type = type;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
public static Action newCommandAction(int command) {
|
2016-11-23 02:24:32 +05:30
|
|
|
Action a = newAction(Action.Type.COMMAND);
|
2016-11-22 23:49:52 +05:30
|
|
|
a.command = command;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
public static Action newTouchAction(int touch) {
|
2016-11-23 02:24:32 +05:30
|
|
|
Action a = newAction(Action.Type.TOUCH);
|
2016-11-22 23:49:52 +05:30
|
|
|
a.touch = touch;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static LauncherEvent newLauncherEvent(Action action, Target... srcTargets) {
|
2016-11-23 02:24:32 +05:30
|
|
|
LauncherEvent event = new LauncherEvent();
|
2016-11-22 23:49:52 +05:30
|
|
|
event.srcTarget = srcTargets;
|
|
|
|
|
event.action = action;
|
|
|
|
|
return event;
|
2016-09-01 12:47:12 -07:00
|
|
|
}
|
2016-03-08 16:55:47 -08:00
|
|
|
}
|