Start the memory dumper directly.

Launching it as an activity from within Launcher is
problematic, so we'll just treat it as a special shortcut
and run the dump when the user clicks that shortcut icon.

Change-Id: Ibe9f4adcaff674f5bafa9b0fc58b5a86cf5ceb00
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index bfe0be3..0294961 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2027,12 +2027,20 @@
             // Open shortcut
             final Intent intent = ((ShortcutInfo) tag).intent;
 
-            ComponentName widgetComp = new ComponentName(this, WidgetAdder.class);
-            if (intent.getComponent() != null &&
-                    intent.getComponent().getClassName().equals(widgetComp.getClassName())) {
-                showAllApps(true);
-                return;
+            // Check for special shortcuts
+            if (intent.getComponent() != null) {
+                final String shortcutClass = intent.getComponent().getClassName();
+
+                if (shortcutClass.equals(WidgetAdder.class.getName())) {
+                    showAllApps(true);
+                    return;
+                } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
+                    MemoryDumpActivity.startDump(this);
+                    return;
+                }
             }
+
+            // Start activities
             int[] pos = new int[2];
             v.getLocationOnScreen(pos);
             intent.setSourceBounds(new Rect(pos[0], pos[1],
diff --git a/src/com/android/launcher3/MemoryDumpActivity.java b/src/com/android/launcher3/MemoryDumpActivity.java
index b437c22..37e3928 100644
--- a/src/com/android/launcher3/MemoryDumpActivity.java
+++ b/src/com/android/launcher3/MemoryDumpActivity.java
@@ -133,20 +133,33 @@
     public void onStart() {
         super.onStart();
 
+        startDump(this, new Runnable() {
+            @Override
+            public void run() {
+                finish();
+            }
+        });
+    }
+
+    public static void startDump(final Context context) {
+        startDump(context, null);
+    }
+
+    public static void startDump(final Context context, final Runnable andThen) {
         final ServiceConnection connection = new ServiceConnection() {
             public void onServiceConnected(ComponentName className, IBinder service) {
                 Log.v(TAG, "service connected, dumping...");
-                dumpHprofAndShare(MemoryDumpActivity.this,
-                        ((MemoryTracker.MemoryTrackerInterface)service).getService());
-                unbindService(this);
-                finish();
+                dumpHprofAndShare(context,
+                        ((MemoryTracker.MemoryTrackerInterface) service).getService());
+                context.unbindService(this);
+                if (andThen != null) andThen.run();
             }
 
             public void onServiceDisconnected(ComponentName className) {
             }
         };
         Log.v(TAG, "attempting to bind to memory tracker");
-        bindService(new Intent(this, MemoryTracker.class),
+        context.bindService(new Intent(context, MemoryTracker.class),
                 connection, Context.BIND_AUTO_CREATE);
     }
 }