diff options
Diffstat (limited to 'src/com/android/launcher3/logging')
5 files changed, 119 insertions, 60 deletions
diff --git a/src/com/android/launcher3/logging/DumpTargetWrapper.java b/src/com/android/launcher3/logging/DumpTargetWrapper.java index 365e8f21e..067bdfdec 100644 --- a/src/com/android/launcher3/logging/DumpTargetWrapper.java +++ b/src/com/android/launcher3/logging/DumpTargetWrapper.java @@ -15,17 +15,22 @@ */ package com.android.launcher3.logging; +import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; + +import android.content.ComponentName; import android.os.Process; import android.text.TextUtils; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.model.nano.LauncherDumpProto; import com.android.launcher3.model.nano.LauncherDumpProto.ContainerType; import com.android.launcher3.model.nano.LauncherDumpProto.DumpTarget; import com.android.launcher3.model.nano.LauncherDumpProto.ItemType; import com.android.launcher3.model.nano.LauncherDumpProto.UserType; +import com.android.launcher3.util.ShortcutUtil; import java.util.ArrayList; import java.util.List; @@ -73,20 +78,23 @@ public class DumpTargetWrapper { public DumpTarget newItemTarget(ItemInfo info) { DumpTarget dt = new DumpTarget(); dt.type = DumpTarget.Type.ITEM; - + if (info == null) { + return dt; + } switch (info.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: dt.itemType = ItemType.APP_ICON; break; - case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: - dt.itemType = ItemType.UNKNOWN_ITEMTYPE; - break; case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: dt.itemType = ItemType.WIDGET; break; - case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: + case ITEM_TYPE_DEEP_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: dt.itemType = ItemType.SHORTCUT; break; + default: + dt.itemType = ItemType.UNKNOWN_ITEMTYPE; + break; } return dt; } @@ -120,6 +128,9 @@ public class DumpTargetWrapper { } private static String getItemStr(DumpTarget t) { + if (t == null) { + return ""; + } String typeStr = LoggerUtils.getFieldName(t.itemType, ItemType.class); if (!TextUtils.isEmpty(t.packageName)) { typeStr += ", package=" + t.packageName; @@ -132,8 +143,15 @@ public class DumpTargetWrapper { } public DumpTarget writeToDumpTarget(ItemInfo info) { - node.component = info.getTargetComponent() == null? "": - info.getTargetComponent().flattenToString(); + if (info == null) { + return node; + } + if (ShortcutUtil.isDeepShortcut(info)) { + node.component = ((WorkspaceItemInfo) info).getDeepShortcutId(); + } else { + ComponentName cmp = info.getTargetComponent(); + node.component = cmp == null ? "" : cmp.flattenToString(); + } node.packageName = info.getTargetComponent() == null? "": info.getTargetComponent().getPackageName(); if (info instanceof LauncherAppWidgetInfo) { diff --git a/src/com/android/launcher3/logging/EventLogArray.java b/src/com/android/launcher3/logging/EventLogArray.java index f20f3659e..3ecfb23c2 100644 --- a/src/com/android/launcher3/logging/EventLogArray.java +++ b/src/com/android/launcher3/logging/EventLogArray.java @@ -16,11 +16,13 @@ package com.android.launcher3.logging; +import android.util.Log; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.Locale; +import java.util.Random; /** * A utility class to record and log events. Events are stored in a fixed size array and old logs @@ -37,6 +39,7 @@ public class EventLogArray { private final String name; private final EventEntry[] logs; private int nextIndex; + private int mLogId; public EventLogArray(String name, int size) { this.name = name; @@ -52,10 +55,6 @@ public class EventLogArray { addLog(TYPE_INTEGER, event, extras); } - public void addLog(String event, float extras) { - addLog(TYPE_FLOAT, event, extras); - } - public void addLog(String event, boolean extras) { addLog(extras ? TYPE_BOOL_TRUE : TYPE_BOOL_FALSE, event, 0); } @@ -65,7 +64,7 @@ public class EventLogArray { int last = (nextIndex + logs.length - 1) % logs.length; int secondLast = (nextIndex + logs.length - 2) % logs.length; if (isEntrySame(logs[last], type, event) && isEntrySame(logs[secondLast], type, event)) { - logs[last].update(type, event, extras); + logs[last].update(type, event, extras, mLogId); logs[secondLast].duplicateCount++; return; } @@ -73,7 +72,7 @@ public class EventLogArray { if (logs[nextIndex] == null) { logs[nextIndex] = new EventEntry(); } - logs[nextIndex].update(type, event, extras); + logs[nextIndex].update(type, event, extras, mLogId); nextIndex = (nextIndex + 1) % logs.length; } @@ -113,10 +112,18 @@ public class EventLogArray { if (log.duplicateCount > 0) { msg.append(" & ").append(log.duplicateCount).append(" similar events"); } + msg.append(" traceId: ").append(log.traceId); writer.println(msg); } } + /** Returns a 3 digit random number between 100-999 */ + public int generateAndSetLogId() { + Random r = new Random(); + mLogId = r.nextInt(900) + 100; + return mLogId; + } + private boolean isEntrySame(EventEntry entry, int type, String event) { return entry != null && entry.type == type && entry.event.equals(event); } @@ -129,11 +136,13 @@ public class EventLogArray { private float extras; private long time; private int duplicateCount; + private int traceId; - public void update(int type, String event, float extras) { + public void update(int type, String event, float extras, int traceId) { this.type = type; this.event = event; this.extras = extras; + this.traceId = traceId; time = System.currentTimeMillis(); duplicateCount = 0; } diff --git a/src/com/android/launcher3/logging/FileLog.java b/src/com/android/launcher3/logging/FileLog.java index f7f8ef18f..923a89b1c 100644 --- a/src/com/android/launcher3/logging/FileLog.java +++ b/src/com/android/launcher3/logging/FileLog.java @@ -1,13 +1,14 @@ package com.android.launcher3.logging; +import static com.android.launcher3.util.Executors.createAndStartNewLooper; + import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.util.Log; import android.util.Pair; -import com.android.launcher3.Utilities; -import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.util.IOUtils; import java.io.BufferedReader; import java.io.File; @@ -29,8 +30,7 @@ import java.util.concurrent.TimeUnit; */ public final class FileLog { - protected static final boolean ENABLED = - FeatureFlags.IS_DOGFOOD_BUILD || Utilities.IS_DEBUG_DEVICE; + protected static final boolean ENABLED = true; private static final String FILE_NAME_PREFIX = "log-"; private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); @@ -91,9 +91,8 @@ public final class FileLog { private static Handler getHandler() { synchronized (DATE_FORMAT) { if (sHandler == null) { - HandlerThread thread = new HandlerThread("file-logger"); - thread.start(); - sHandler = new Handler(thread.getLooper(), new LogWriterCallback()); + sHandler = new Handler(createAndStartNewLooper("file-logger"), + new LogWriterCallback()); } } return sHandler; @@ -131,7 +130,7 @@ public final class FileLog { private PrintWriter mCurrentWriter = null; private void closeWriter() { - Utilities.closeSilently(mCurrentWriter); + IOUtils.closeSilently(mCurrentWriter); mCurrentWriter = null; } @@ -219,7 +218,7 @@ public final class FileLog { } catch (Exception e) { // ignore } finally { - Utilities.closeSilently(in); + IOUtils.closeSilently(in); } } } diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java index 9b75b43b4..598792abc 100644 --- a/src/com/android/launcher3/logging/LoggerUtils.java +++ b/src/com/android/launcher3/logging/LoggerUtils.java @@ -44,6 +44,7 @@ import java.lang.reflect.Modifier; public class LoggerUtils { private static final ArrayMap<Class, SparseArray<String>> sNameCache = new ArrayMap<>(); private static final String UNKNOWN = "UNKNOWN"; + private static final int DEFAULT_PREDICTED_RANK = -100; public static String getFieldName(int value, Class c) { SparseArray<String> cache; @@ -90,7 +91,7 @@ public class LoggerUtils { } public static String getTargetStr(Target t) { - if (t == null){ + if (t == null) { return ""; } String str = ""; @@ -137,17 +138,16 @@ public class LoggerUtils { if (t.intentHash != 0) { typeStr += ", intentHash=" + t.intentHash; } - if ((t.packageNameHash != 0 || t.componentHash != 0 || t.intentHash != 0) && - t.itemType != ItemType.TASK) { + if (t.itemType == ItemType.FOLDER_ICON) { + typeStr += ", grid(" + t.gridX + "," + t.gridY + ")"; + } else if ((t.packageNameHash != 0 || t.componentHash != 0 || t.intentHash != 0) + && t.itemType != ItemType.TASK) { typeStr += ", predictiveRank=" + t.predictedRank + ", grid(" + t.gridX + "," + t.gridY - + "), span(" + t.spanX + "," + t.spanY - + "), pageIdx=" + t.pageIndex; - + + "), span(" + t.spanX + "," + t.spanY + "), pageIdx=" + t.pageIndex; } if (t.searchQueryLength != 0) { typeStr += ", searchQueryLength=" + t.searchQueryLength; } - if (t.itemType == ItemType.TASK) { typeStr += ", pageIdx=" + t.pageIndex; } @@ -168,17 +168,17 @@ public class LoggerUtils { public static Target newItemTarget(ItemInfo info, InstantAppResolver instantAppResolver) { Target t = newTarget(Target.Type.ITEM); - switch (info.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: t.itemType = (instantAppResolver != null && info instanceof AppInfo - && instantAppResolver.isInstantApp(((AppInfo) info)) ) + && instantAppResolver.isInstantApp(((AppInfo) info))) ? ItemType.WEB_APP : ItemType.APP_ICON; - t.predictedRank = -100; // Never assigned + t.predictedRank = DEFAULT_PREDICTED_RANK; break; case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: t.itemType = ItemType.SHORTCUT; + t.predictedRank = DEFAULT_PREDICTED_RANK; break; case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: t.itemType = ItemType.FOLDER_ICON; @@ -188,6 +188,7 @@ public class LoggerUtils { break; case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: t.itemType = ItemType.DEEPSHORTCUT; + t.predictedRank = DEFAULT_PREDICTED_RANK; break; } return t; diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java index c72b07a7f..99906fe1a 100644 --- a/src/com/android/launcher3/logging/UserEventDispatcher.java +++ b/src/com/android/launcher3/logging/UserEventDispatcher.java @@ -26,6 +26,8 @@ import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent; import static com.android.launcher3.logging.LoggerUtils.newTarget; import static com.android.launcher3.logging.LoggerUtils.newTouchAction; +import static java.util.Optional.ofNullable; + import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; @@ -35,6 +37,7 @@ import android.os.SystemClock; import android.util.Log; import android.view.View; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.DropTarget; @@ -58,7 +61,7 @@ import java.util.UUID; /** * Manages the creation of {@link LauncherEvent}. * To debug this class, execute following command before side loading a new apk. - * + * <p> * $ adb shell setprop log.tag.UserEvent VERBOSE */ public class UserEventDispatcher implements ResourceBasedOverride { @@ -94,19 +97,26 @@ public class UserEventDispatcher implements ResourceBasedOverride { /** * Fills in the container data on the given event if the given view is not null. + * * @return whether container data was added. */ - public static boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) { + public boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) { // Fill in grid(x,y), pageIndex of the child and container type of the parent LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(v); if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) { return false; } - ItemInfo itemInfo = (ItemInfo) v.getTag(); - provider.fillInLogContainerData(v, itemInfo, event.srcTarget[0], event.srcTarget[1]); + final ItemInfo itemInfo = (ItemInfo) v.getTag(); + final Target target = event.srcTarget[0]; + final Target targetParent = event.srcTarget[1]; + onFillInLogContainerData(itemInfo, target, targetParent); + provider.fillInLogContainerData(v, itemInfo, target, targetParent); return true; } + protected void onFillInLogContainerData( + @NonNull ItemInfo itemInfo, @NonNull Target target, @NonNull Target targetParent) { } + private boolean mSessionStarted; private long mElapsedContainerMillis; private long mElapsedSessionMillis; @@ -139,7 +149,11 @@ public class UserEventDispatcher implements ResourceBasedOverride { mAppOrTaskLaunch = true; } - public void logActionTip(int actionType, int viewType) { } + /** + * Dummy method. + */ + public void logActionTip(int actionType, int viewType) { + } @Deprecated public void logTaskLaunchOrDismiss(int action, int direction, int taskIndex, @@ -184,15 +198,15 @@ public class UserEventDispatcher implements ResourceBasedOverride { public void logActionCommand(int command, int srcContainerType, int dstContainerType) { logActionCommand(command, newContainerTarget(srcContainerType), - dstContainerType >=0 ? newContainerTarget(dstContainerType) : null); + dstContainerType >= 0 ? newContainerTarget(dstContainerType) : null); } public void logActionCommand(int command, int srcContainerType, int dstContainerType, - int pageIndex) { + int pageIndex) { Target srcTarget = newContainerTarget(srcContainerType); srcTarget.pageIndex = pageIndex; logActionCommand(command, srcTarget, - dstContainerType >=0 ? newContainerTarget(dstContainerType) : null); + dstContainerType >= 0 ? newContainerTarget(dstContainerType) : null); } public void logActionCommand(int command, Target srcTarget, Target dstTarget) { @@ -241,7 +255,7 @@ public class UserEventDispatcher implements ResourceBasedOverride { } public void logActionOnControl(int action, int controlType, int parentContainer, - int grandParentContainer){ + int grandParentContainer) { LauncherEvent event = newLauncherEvent(newTouchAction(action), newControlTarget(controlType), newContainerTarget(parentContainer), @@ -250,11 +264,11 @@ public class UserEventDispatcher implements ResourceBasedOverride { } public void logActionOnControl(int action, int controlType, @Nullable View controlInContainer, - int parentContainerType) { + int parentContainerType) { final LauncherEvent event = (controlInContainer == null && parentContainerType < 0) ? newLauncherEvent(newTouchAction(action), newTarget(Target.Type.CONTROL)) : newLauncherEvent(newTouchAction(action), newTarget(Target.Type.CONTROL), - newTarget(Target.Type.CONTAINER)); + newTarget(Target.Type.CONTAINER)); event.srcTarget[0].controlType = controlType; if (controlInContainer != null) { fillInLogContainerData(event, controlInContainer); @@ -301,9 +315,9 @@ public class UserEventDispatcher implements ResourceBasedOverride { * (1) WORKSPACE: if the launcher is the foreground activity * (2) APP: if another app was the foreground activity */ - public void logStateChangeAction(int action, int dir, int downX, int downY, int srcChildTargetType, - int srcParentContainerType, int dstContainerType, - int pageIndex) { + public void logStateChangeAction(int action, int dir, int downX, int downY, + int srcChildTargetType, int srcParentContainerType, int dstContainerType, + int pageIndex) { LauncherEvent event; if (srcChildTargetType == LauncherLogProto.ItemType.TASK) { event = newLauncherEvent(newTouchAction(action), @@ -326,9 +340,25 @@ public class UserEventDispatcher implements ResourceBasedOverride { } public void logActionOnItem(int action, int dir, int itemType) { + logActionOnItem(action, dir, itemType, null, null); + } + + /** + * Creates new {@link LauncherEvent} of ITEM target type with input arguments and dispatches it. + * + * @param touchAction ENUM value of {@link LauncherLogProto.Action.Touch} Action + * @param dir ENUM value of {@link LauncherLogProto.Action.Direction} Action + * @param itemType ENUM value of {@link LauncherLogProto.ItemType} + * @param gridX Nullable X coordinate of item's position on the workspace grid + * @param gridY Nullable Y coordinate of item's position on the workspace grid + */ + public void logActionOnItem(int touchAction, int dir, int itemType, + @Nullable Integer gridX, @Nullable Integer gridY) { Target itemTarget = newTarget(Target.Type.ITEM); itemTarget.itemType = itemType; - LauncherEvent event = newLauncherEvent(newTouchAction(action), itemTarget); + ofNullable(gridX).ifPresent(value -> itemTarget.gridX = value); + ofNullable(gridY).ifPresent(value -> itemTarget.gridY = value); + LauncherEvent event = newLauncherEvent(newTouchAction(touchAction), itemTarget); event.action.dir = dir; dispatchUserEvent(event, null); } @@ -351,7 +381,7 @@ public class UserEventDispatcher implements ResourceBasedOverride { LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.DRAGDROP), newItemTarget(dragObj.originalDragInfo, mInstantAppResolver), newTarget(Target.Type.CONTAINER)); - event.destTarget = new Target[] { + event.destTarget = new Target[]{ newItemTarget(dragObj.originalDragInfo, mInstantAppResolver), newDropTarget(dropTargetAsView) }; @@ -373,14 +403,10 @@ public class UserEventDispatcher implements ResourceBasedOverride { int actionTouch = isButton ? Action.Touch.TAP : Action.Touch.SWIPE; Action action = newCommandAction(actionTouch); action.command = Action.Command.BACK; - action.dir = isButton - ? Action.Direction.NONE - : gestureSwipeLeft - ? Action.Direction.LEFT - : Action.Direction.RIGHT; - Target target = newControlTarget(isButton - ? LauncherLogProto.ControlType.BACK_BUTTON - : LauncherLogProto.ControlType.BACK_GESTURE); + action.dir = isButton ? Action.Direction.NONE : + gestureSwipeLeft ? Action.Direction.LEFT : Action.Direction.RIGHT; + Target target = newControlTarget(isButton ? LauncherLogProto.ControlType.BACK_BUTTON : + LauncherLogProto.ControlType.BACK_GESTURE); target.spanX = downX; target.spanY = downY; target.cardinality = completed ? 1 : 0; @@ -391,6 +417,7 @@ public class UserEventDispatcher implements ResourceBasedOverride { /** * Currently logs following containers: workspace, allapps, widget tray. + * * @param reason */ public final void resetElapsedContainerMillis(String reason) { @@ -427,10 +454,16 @@ public class UserEventDispatcher implements ResourceBasedOverride { mAppOrTaskLaunch = false; ev.elapsedContainerMillis = SystemClock.uptimeMillis() - mElapsedContainerMillis; ev.elapsedSessionMillis = SystemClock.uptimeMillis() - mElapsedSessionMillis; - if (!IS_VERBOSE) { return; } + Log.d(TAG, generateLog(ev)); + } + + /** + * Returns a human-readable log for given user event. + */ + public static String generateLog(LauncherEvent ev) { String log = "\n-----------------------------------------------------" + "\naction:" + LoggerUtils.getActionStr(ev.action); if (ev.srcTarget != null && ev.srcTarget.length > 0) { @@ -445,8 +478,7 @@ public class UserEventDispatcher implements ResourceBasedOverride { ev.elapsedSessionMillis, ev.actionDurationMillis); log += "\n\n"; - Log.d(TAG, log); - return; + return log; } private static String getTargetsStr(Target[] targets) { |