OSDN Git Service

Clean up around 1) Log.VERBOSE and 2) dump
authorHyunyoung Song <hyunyoungs@google.com>
Mon, 30 Jan 2017 23:11:27 +0000 (15:11 -0800)
committerHyunyoung Song <hyunyoungs@google.com>
Wed, 1 Feb 2017 23:11:08 +0000 (15:11 -0800)
b/31772480

Note: in the follow up CL, I will add the dump result of the bgDataModel
to a proto

Change-Id: I5261cff0fb29cedd1dd772b8b15f67095ad5b967

src/com/android/launcher3/AppInfo.java
src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherModel.java
src/com/android/launcher3/logging/UserEventDispatcher.java
src/com/android/launcher3/model/BgDataModel.java
src/com/android/launcher3/provider/RestoreDbTask.java
src/com/android/launcher3/util/LogConfig.java [new file with mode: 0644]
src/com/android/launcher3/util/SQLiteCacheHelper.java

index 6bec997..8bf49c2 100644 (file)
@@ -91,17 +91,6 @@ public class AppInfo extends ItemInfoWithIcon {
         return super.dumpProperties() + " componentName=" + componentName;
     }
 
-    /**
-     * Helper method used for debugging.
-     */
-    public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
-        Log.d(tag, label + " size=" + list.size());
-        for (AppInfo info: list) {
-            Log.d(tag, "   title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
-                    + " componentName=" + info.componentName.getPackageName());
-        }
-    }
-
     public ShortcutInfo makeShortcut() {
         return new ShortcutInfo(this);
     }
index 11db9a0..d963f43 100644 (file)
@@ -117,6 +117,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
 import com.android.launcher3.util.ActivityResultInfo;
 import com.android.launcher3.util.ComponentKey;
 import com.android.launcher3.util.ItemInfoMatcher;
+import com.android.launcher3.util.LogConfig;
 import com.android.launcher3.util.MultiHashMap;
 import com.android.launcher3.util.PackageManagerHelper;
 import com.android.launcher3.util.PackageUserKey;
@@ -172,10 +173,6 @@ public class Launcher extends BaseActivity
      */
     protected static final int REQUEST_LAST = 100;
 
-    // To turn on these properties, type
-    // adb shell setprop logTap.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
-    static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
-
     // The Intent extra that defines whether to ignore the launch animation
     static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
             "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
@@ -2201,25 +2198,7 @@ public class Launcher extends BaseActivity
 
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
-        if (event.getAction() == KeyEvent.ACTION_DOWN) {
-            switch (event.getKeyCode()) {
-                case KeyEvent.KEYCODE_HOME:
-                    return true;
-                case KeyEvent.KEYCODE_VOLUME_DOWN:
-                    if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
-                        dumpState();
-                        return true;
-                    }
-                    break;
-            }
-        } else if (event.getAction() == KeyEvent.ACTION_UP) {
-            switch (event.getKeyCode()) {
-                case KeyEvent.KEYCODE_HOME:
-                    return true;
-            }
-        }
-
-        return super.dispatchKeyEvent(event);
+        return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
     }
 
     @Override
@@ -3968,50 +3947,48 @@ public class Launcher extends BaseActivity
     }
 
     /**
-     * Prints out out state for debugging.
+     * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
      */
-    public void dumpState() {
-        Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
-        Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
-        Log.d(TAG, "mPendingRequestArgs=" + mPendingRequestArgs);
-        Log.d(TAG, "mPendingActivityResult=" + mPendingActivityResult);
-        mModel.dumpState();
-        // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
-
-        Log.d(TAG, "END launcher3 dump state");
-    }
-
     @Override
     public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
         super.dump(prefix, fd, writer, args);
-        // Dump workspace
-        writer.println(prefix + "Workspace Items");
-        for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
-            writer.println(prefix + "  Homescreen " + i);
 
-            ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
+        if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
+            writer.println(prefix + "Workspace Items");
+            for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
+                writer.println(prefix + "  Homescreen " + i);
+
+                ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
+                for (int j = 0; j < layout.getChildCount(); j++) {
+                    Object tag = layout.getChildAt(j).getTag();
+                    if (tag != null) {
+                        writer.println(prefix + "    " + tag.toString());
+                    }
+                }
+            }
+
+            writer.println(prefix + "  Hotseat");
+            ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
             for (int j = 0; j < layout.getChildCount(); j++) {
                 Object tag = layout.getChildAt(j).getTag();
                 if (tag != null) {
                     writer.println(prefix + "    " + tag.toString());
                 }
             }
-        }
 
-        writer.println(prefix + "  Hotseat");
-        ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
-        for (int j = 0; j < layout.getChildCount(); j++) {
-            Object tag = layout.getChildAt(j).getTag();
-            if (tag != null) {
-                writer.println(prefix + "    " + tag.toString());
+            try {
+                FileLog.flushAll(writer);
+            } catch (Exception e) {
+                // Ignore
             }
         }
 
-        try {
-            FileLog.flushAll(writer);
-        } catch (Exception e) {
-            // Ignore
-        }
+        writer.println(prefix + "Misc:");
+        writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
+        writer.print(" mPendingRequestArgs=" + mPendingRequestArgs);
+        writer.println(" mPendingActivityResult=" + mPendingActivityResult);
+
+        mModel.dumpState(prefix, fd, writer, args);
 
         if (mLauncherCallbacks != null) {
             mLauncherCallbacks.dump(prefix, fd, writer, args);
index 79f9792..2389d84 100644 (file)
@@ -81,6 +81,8 @@ import com.android.launcher3.util.Provider;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.util.ViewOnDrawExecutor;
 
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
 import java.lang.ref.WeakReference;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -2098,15 +2100,6 @@ public class LauncherModel extends BroadcastReceiver
             }
             bindDeepShortcuts();
         }
-
-        public void dumpState() {
-            synchronized (sBgDataModel) {
-                Log.d(TAG, "mLoaderTask.mContext=" + mContext);
-                Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);
-                Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished);
-                Log.d(TAG, "mItems size=" + sBgDataModel.workspaceItems.size());
-            }
-        }
     }
 
     public void bindDeepShortcuts() {
@@ -2267,17 +2260,15 @@ public class LauncherModel extends BroadcastReceiver
                 && (provider.provider.getPackageName() != null);
     }
 
-    public void dumpState() {
-        Log.d(TAG, "mCallbacks=" + mCallbacks);
-        AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mBgAllAppsList.data);
-        AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mBgAllAppsList.added);
-        AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mBgAllAppsList.removed);
-        AppInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mBgAllAppsList.modified);
-        if (mLoaderTask != null) {
-            mLoaderTask.dumpState();
-        } else {
-            Log.d(TAG, "mLoaderTask=null");
+    public void dumpState(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
+        if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
+            writer.println(prefix + "All apps list: size=" + mBgAllAppsList.data.size());
+            for (AppInfo info : mBgAllAppsList.data) {
+                writer.println(prefix + "   title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
+                        + " componentName=" + info.componentName.getPackageName());
+            }
         }
+        sBgDataModel.dump(prefix, fd, writer, args);
     }
 
     public Callbacks getCallback() {
index 8ded6b8..8ab33dc 100644 (file)
@@ -32,6 +32,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
 import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
 import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.LogConfig;
 
 import java.util.List;
 import java.util.Locale;
@@ -56,7 +57,7 @@ public class UserEventDispatcher {
 
     private static final String TAG = "UserEvent";
     private static final boolean IS_VERBOSE =
-            ProviderConfig.IS_DOGFOOD_BUILD && Utilities.isPropertyEnabled(TAG);
+            ProviderConfig.IS_DOGFOOD_BUILD && Utilities.isPropertyEnabled(LogConfig.USEREVENT);
 
     /**
      * Implemented by containers to provide a container source for a given child.
index 2ac33ea..6b64087 100644 (file)
@@ -17,6 +17,7 @@ package com.android.launcher3.model;
 
 import android.content.Context;
 import android.os.UserHandle;
+import android.text.TextUtils;
 import android.util.Log;
 import android.util.MutableInt;
 
@@ -35,6 +36,8 @@ import com.android.launcher3.util.ComponentKey;
 import com.android.launcher3.util.LongArrayMap;
 import com.android.launcher3.util.MultiHashMap;
 
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -99,6 +102,37 @@ public class BgDataModel {
         deepShortcutMap.clear();
     }
 
+    // TODO: current dump is very cryptic and hard to understand. Make it more legible.
+    public synchronized void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
+        writer.println(prefix + "Data Model:");
+        for (int i = 0; i < workspaceScreens.size(); i++) {
+            writer.println(prefix + "\tIndex of workspaceScreens:" + workspaceScreens.get(i).toString());
+        }
+        for (int i = 0; i < workspaceItems.size(); i++) {
+            writer.println(prefix + '\t' + workspaceItems.get(i).toString());
+        }
+        for (int i = 0; i < appWidgets.size(); i++) {
+            writer.println(prefix + '\t' + appWidgets.get(i).toString());
+        }
+        for (int i = 0; i< folders.size(); i++) {
+            writer.println(prefix + '\t' + folders.valueAt(i).toString());
+        }
+        for (int i = 0; i< itemsIdMap.size(); i++) {
+            writer.println(prefix + '\t' + itemsIdMap.valueAt(i).toString());
+        }
+
+        if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
+            writer.println(prefix + "shortcuts");
+            for (ArrayList<String> map : deepShortcutMap.values()) {
+                writer.print(prefix + "  ");
+                for (String str : map) {
+                    writer.print(str.toString() + ", ");
+                }
+                writer.println();
+            }
+        }
+    }
+
     public synchronized void removeItem(Context context, ItemInfo... items) {
         removeItem(context, Arrays.asList(items));
     }
index a200a85..dc85aba 100644 (file)
@@ -27,6 +27,7 @@ import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.ShortcutInfo;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.logging.FileLog;
+import com.android.launcher3.util.LogConfig;
 
 import java.io.InvalidObjectException;
 
@@ -44,13 +45,6 @@ public class RestoreDbTask {
     private static final String INFO_COLUMN_NAME = "name";
     private static final String INFO_COLUMN_DEFAULT_VALUE = "dflt_value";
 
-    /**
-     * When enabled all icons are kept on the home screen, even if they don't have an active
-     * session. To enable use:
-     *      adb shell setprop log.tag.launcher_keep_all_icons VERBOSE
-     */
-    private static final String KEEP_ALL_ICONS = "launcher_keep_all_icons";
-
     public static boolean performRestore(DatabaseHelper helper) {
         SQLiteDatabase db = helper.getWritableDatabase();
         db.beginTransaction();
@@ -85,7 +79,7 @@ public class RestoreDbTask {
         }
 
         // Mark all items as restored.
-        boolean keepAllIcons = Utilities.isPropertyEnabled(KEEP_ALL_ICONS);
+        boolean keepAllIcons = Utilities.isPropertyEnabled(LogConfig.KEEP_ALL_ICONS);
         ContentValues values = new ContentValues();
         values.put(Favorites.RESTORED, ShortcutInfo.FLAG_RESTORED_ICON
                 | (keepAllIcons ? ShortcutInfo.FLAG_RESTORE_STARTED : 0));
diff --git a/src/com/android/launcher3/util/LogConfig.java b/src/com/android/launcher3/util/LogConfig.java
new file mode 100644 (file)
index 0000000..4acdb5c
--- /dev/null
@@ -0,0 +1,31 @@
+package com.android.launcher3.util;
+
+/**
+ * This is a utility class that keeps track of all the tag that can be enabled to debug
+ * a behavior in runtime.
+ *
+ * To use any of the strings defined in this class, execute the following command.
+ *
+ * $ adb shell setprop log.tag.TAGNAME VERBOSE
+ */
+
+public class LogConfig {
+    // These are list of strings that can be used to replace TAGNAME.
+
+    /**
+     * After this tag is turned on, whenever there is n user event, debug information is
+     * printed out to logcat.
+     */
+    public static final String USEREVENT = "UserEvent";
+
+    /**
+     * When turned on, all icons are kept on the home screen, even if they don't have an active
+     * session.
+     */
+    public static final String KEEP_ALL_ICONS = "KeepAllIcons";
+
+    /**
+     * When turned on, icon cache is only fetched from memory and not disk.
+     */
+    public static final String MEMORY_ONLY_ICON_CACHE = "MemoryOnlyIconCache";
+}
index 9aabfeb..1ff6293 100644 (file)
@@ -20,7 +20,7 @@ public abstract class SQLiteCacheHelper {
     private static final String TAG = "SQLiteCacheHelper";
 
     private static final boolean NO_ICON_CACHE = ProviderConfig.IS_DOGFOOD_BUILD &&
-            Utilities.isPropertyEnabled("MEMORY_ONLY_ICON_CACHE");
+            Utilities.isPropertyEnabled(LogConfig.MEMORY_ONLY_ICON_CACHE);
 
     private final String mTableName;
     private final MySQLiteOpenHelper mOpenHelper;