From b608849c7034e1788a6fbeee30e29cf8f4761ebc Mon Sep 17 00:00:00 2001 From: sail Date: Tue, 15 Aug 2017 04:01:52 -0700 Subject: Log impression if Dialer logs posts many notifications With this CL we now post HIGH_GLOBAL_NOTIFICATION_COUNT_REACHED once per process lifetime if we post more than 45 notifications. With this logging we'll have a better understanding of how many users get into this state. Note, the exact limit for notifications is 50. We could log an impression when we reach this limit exactly. This CL doesn't do that to avoid calling getActiveNotifications() on every notification. We also limit logging to once per process lifetime for performance reasons too. Bug: 62937258 Test: NotificationThrottlerTest.highGlobalNotificationCountReached PiperOrigin-RevId: 165291217 Change-Id: Iad3a8e84b10b9133870fc45579d98b1a0f922ed7 --- .../dialer/notification/NotificationThrottler.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'java/com/android/dialer/notification') diff --git a/java/com/android/dialer/notification/NotificationThrottler.java b/java/com/android/dialer/notification/NotificationThrottler.java index 7c2428737..661dec759 100644 --- a/java/com/android/dialer/notification/NotificationThrottler.java +++ b/java/com/android/dialer/notification/NotificationThrottler.java @@ -24,6 +24,8 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -35,6 +37,9 @@ import java.util.List; */ /* package */ class NotificationThrottler { private static final int MAX_NOTIFICATIONS_PER_TAG = 10; + private static final int HIGH_GLOBAL_NOTIFICATION_COUNT = 45; + + private static boolean didLogHighGlobalNotificationCountReached; /* package */ static void throttle(@NonNull Context context, @NonNull Notification notification) { Assert.isNotNull(context); @@ -46,9 +51,22 @@ import java.util.List; return; } - int count = 0; NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - for (StatusBarNotification currentNotification : notificationManager.getActiveNotifications()) { + StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications(); + if (activeNotifications.length > HIGH_GLOBAL_NOTIFICATION_COUNT + && !didLogHighGlobalNotificationCountReached) { + LogUtil.i( + "NotificationThrottler.throttle", + "app has %d notifications, system may suppress future notifications", + activeNotifications.length); + didLogHighGlobalNotificationCountReached = true; + Logger.get(context) + .logImpression(DialerImpression.Type.HIGH_GLOBAL_NOTIFICATION_COUNT_REACHED); + } + + // Count the number of notificatons for this group (excluding the summary). + int count = 0; + for (StatusBarNotification currentNotification : activeNotifications) { if (isNotificationInGroup(currentNotification, groupKey)) { count++; } -- cgit v1.2.3