report notification load on panel reveal

Counts may differ from user perception. For example, if notifications arrive
after the shade is open (even if it is only peeking) there will not be another
panel_reveal before the user sees the shade.  User perception is more accurately
measured by visibility events.

Peek events will report the notificaiton load as 1.

Bug: 20088581
Change-Id: I10221d4b66a18c223aae21e616615f087c65b1e1
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index aea1585..63bfbe5 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -44,7 +44,7 @@
     // You need the STATUS_BAR_SERVICE permission
     void registerStatusBar(IStatusBar callbacks, out StatusBarIconList iconList,
             out int[] switches, out List<IBinder> binders);
-    void onPanelRevealed(boolean clearNotificationEffects);
+    void onPanelRevealed(boolean clearNotificationEffects, int numItems);
     void onPanelHidden();
     // Mark current notifications as "seen" and stop ringing, vibrating, blinking.
     void clearNotificationEffects();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 3e66907..6ad0ef9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -1623,7 +1623,13 @@
                 boolean clearNotificationEffects = !isPanelFullyCollapsed() &&
                     (mShowLockscreenNotifications ||
                         (mState == StatusBarState.SHADE || mState == StatusBarState.SHADE_LOCKED));
-                mBarService.onPanelRevealed(clearNotificationEffects);
+                int notificationLoad = mNotificationData.getActiveNotifications().size();
+                if (mHeadsUpManager.hasPinnedHeadsUp() && isPanelFullyCollapsed())  {
+                    notificationLoad = 1;
+                } else {
+                    MetricsLogger.histogram(mContext, "note_load", notificationLoad);
+                }
+                mBarService.onPanelRevealed(clearNotificationEffects, notificationLoad);
             } else {
                 mBarService.onPanelHidden();
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 3678cf1..a637e24 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -1180,6 +1180,7 @@
                         notification.getKey());
                 notification.getNotification().fullScreenIntent.send();
                 shadeEntry.notifyFullScreenIntentLaunched();
+                MetricsLogger.count(mContext, "note_fullscreen", 1);
             } catch (PendingIntent.CanceledException e) {
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
index 98bbe7c..63f5711 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
@@ -29,6 +29,7 @@
 import android.view.ViewTreeObserver;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.internal.logging.MetricsLogger;
 import com.android.systemui.R;
 import com.android.systemui.statusbar.ExpandableNotificationRow;
 import com.android.systemui.statusbar.NotificationData;
@@ -82,6 +83,7 @@
     private final View mStatusBarWindowView;
     private final int mStatusBarHeight;
     private final int mNotificationsTopPadding;
+    private final Context mContext;
     private PhoneStatusBar mBar;
     private int mSnoozeLengthMs;
     private ContentObserver mSettingsObserver;
@@ -101,7 +103,8 @@
     private boolean mIsObserving;
 
     public HeadsUpManager(final Context context, View statusBarWindowView) {
-        Resources resources = context.getResources();
+        mContext = context;
+        Resources resources = mContext.getResources();
         mTouchAcceptanceDelay = resources.getInteger(R.integer.touch_acceptance_delay);
         mSnoozedPackages = new ArrayMap<>();
         mDefaultSnoozeLengthMs = resources.getInteger(R.integer.heads_up_default_snooze_length_ms);
@@ -165,6 +168,7 @@
      */
     public void showNotification(NotificationData.Entry headsUp) {
         if (DEBUG) Log.v(TAG, "showNotification");
+        MetricsLogger.count(mContext, "note_peek", 1);
         addHeadsUpEntry(headsUp);
         updateNotification(headsUp, true);
         headsUp.setInterruption();
@@ -522,7 +526,6 @@
         });
     }
 
-
     /**
      * This represents a notification and how long it is in a heads up mode. It also manages its
      * lifecycle automatically when created.
diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags
index 43b640b..76afab3 100644
--- a/services/core/java/com/android/server/EventLogTags.logtags
+++ b/services/core/java/com/android/server/EventLogTags.logtags
@@ -60,7 +60,7 @@
 2752 notification_cancel_all (uid|1|5),(pid|1|5),(pkg|3),(userid|1|5),(required_flags|1),(forbidden_flags|1),(reason|1|5),(listener|3)
 # when the notification panel is shown
 # Note: New tag range starts here since 2753+ have been used below.
-27500 notification_panel_revealed
+27500 notification_panel_revealed (items|1)
 # when the notification panel is hidden
 27501 notification_panel_hidden
 # when notifications are newly displayed on screen, or disappear from screen
diff --git a/services/core/java/com/android/server/notification/NotificationDelegate.java b/services/core/java/com/android/server/notification/NotificationDelegate.java
index 87b4f8c..6a1401c 100644
--- a/services/core/java/com/android/server/notification/NotificationDelegate.java
+++ b/services/core/java/com/android/server/notification/NotificationDelegate.java
@@ -28,7 +28,7 @@
     void onNotificationError(int callingUid, int callingPid,
             String pkg, String tag, int id,
             int uid, int initialPid, String message, int userId);
-    void onPanelRevealed(boolean clearEffects);
+    void onPanelRevealed(boolean clearEffects, int numItems);
     void onPanelHidden();
     void clearEffects();
     void onNotificationVisibilityChanged(
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index d6a7bf93..87e9d42 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -567,8 +567,8 @@
         }
 
         @Override
-        public void onPanelRevealed(boolean clearEffects) {
-            EventLogTags.writeNotificationPanelRevealed();
+        public void onPanelRevealed(boolean clearEffects, int items) {
+            EventLogTags.writeNotificationPanelRevealed(items);
             if (clearEffects) {
                 clearEffects();
             }
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index 7640837..5ceb6ad 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -571,11 +571,11 @@
      *     LED, vibration, and ringing
      */
     @Override
-    public void onPanelRevealed(boolean clearNotificationEffects) {
+    public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
         enforceStatusBarService();
         long identity = Binder.clearCallingIdentity();
         try {
-            mNotificationDelegate.onPanelRevealed(clearNotificationEffects);
+            mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }