Broadcast app launches from all apps too.

Bug 10943415

Change-Id: I0e496a53fc253bd313d269a05674d7c5cdadee68
diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java
index dd870e4..4e9d68b 100644
--- a/src/com/android/launcher3/AppsCustomizePagedView.java
+++ b/src/com/android/launcher3/AppsCustomizePagedView.java
@@ -500,6 +500,7 @@
                 mPressedIcon.lockDrawableState();
             }
             mLauncher.startActivitySafely(v, appInfo.intent, appInfo);
+            mLauncher.getStats().recordLaunch(appInfo.intent);
         } else if (v instanceof PagedViewWidget) {
             // Let the user know that they have to long press to add a widget
             if (mWidgetInstructionToast != null) {
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 102f4c2..8f0fdde 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -634,6 +634,10 @@
         }
     }
 
+    public Stats getStats() {
+        return mStats;
+    }
+
     public LayoutInflater getInflater() {
         return mInflater;
     }
diff --git a/src/com/android/launcher3/Stats.java b/src/com/android/launcher3/Stats.java
index ca088f7..882fb04 100644
--- a/src/com/android/launcher3/Stats.java
+++ b/src/com/android/launcher3/Stats.java
@@ -103,20 +103,24 @@
         }
     }
 
+    public void recordLaunch(Intent intent) {
+        recordLaunch(intent, null);
+    }
+
     public void recordLaunch(Intent intent, ShortcutInfo shortcut) {
         intent = new Intent(intent);
         intent.setSourceBounds(null);
 
         final String flat = intent.toUri(0);
 
-        mLauncher.sendBroadcast(
-                new Intent(ACTION_LAUNCH)
-                        .putExtra(EXTRA_INTENT, flat)
-                        .putExtra(EXTRA_CONTAINER, shortcut.container)
-                        .putExtra(EXTRA_SCREEN, shortcut.screenId)
-                        .putExtra(EXTRA_CELLX, shortcut.cellX)
-                        .putExtra(EXTRA_CELLY, shortcut.cellY),
-                PERM_LAUNCH);
+        Intent broadcastIntent = new Intent(ACTION_LAUNCH).putExtra(EXTRA_INTENT, flat);
+        if (shortcut != null) {
+            broadcastIntent.putExtra(EXTRA_CONTAINER, shortcut.container)
+                    .putExtra(EXTRA_SCREEN, shortcut.screenId)
+                    .putExtra(EXTRA_CELLX, shortcut.cellX)
+                    .putExtra(EXTRA_CELLY, shortcut.cellY);
+        }
+        mLauncher.sendBroadcast(broadcastIntent, PERM_LAUNCH);
 
         incrementLaunch(flat);
 
@@ -128,10 +132,17 @@
             try {
                 mLog.writeInt(LOG_TAG_LAUNCH);
                 mLog.writeLong(System.currentTimeMillis());
-                mLog.writeShort((short) shortcut.container);
-                mLog.writeShort((short) shortcut.screenId);
-                mLog.writeShort((short) shortcut.cellX);
-                mLog.writeShort((short) shortcut.cellY);
+                if (shortcut == null) {
+                    mLog.writeShort(0);
+                    mLog.writeShort(0);
+                    mLog.writeShort(0);
+                    mLog.writeShort(0);
+                } else {
+                    mLog.writeShort((short) shortcut.container);
+                    mLog.writeShort((short) shortcut.screenId);
+                    mLog.writeShort((short) shortcut.cellX);
+                    mLog.writeShort((short) shortcut.cellY);
+                }
                 mLog.writeUTF(flat);
                 if (FLUSH_IMMEDIATELY) {
                     mLog.flush(); // TODO: delayed writes