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
diff --git a/java/com/android/dialer/logging/dialer_impression.proto b/java/com/android/dialer/logging/dialer_impression.proto
index 4422b9c..de38ff3 100644
--- a/java/com/android/dialer/logging/dialer_impression.proto
+++ b/java/com/android/dialer/logging/dialer_impression.proto
@@ -499,5 +499,10 @@
// Found Lightbringer reachable contact when launching Dialer
HAS_LIGHTBRINGER_REACHABLE_CONTACTS = 1248;
+
+ // This impression is logged once per process when the number of
+ // notifications is very high and the system may suppress future
+ // notifications.
+ HIGH_GLOBAL_NOTIFICATION_COUNT_REACHED = 1249;
}
}
diff --git a/java/com/android/dialer/notification/NotificationThrottler.java b/java/com/android/dialer/notification/NotificationThrottler.java
index 7c24287..661dec7 100644
--- a/java/com/android/dialer/notification/NotificationThrottler.java
+++ b/java/com/android/dialer/notification/NotificationThrottler.java
@@ -24,6 +24,8 @@
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 @@
*/
/* 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 @@
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++;
}