OSDN Git Service

NoMan: Add flag to turn off aggregated in-mem stats
authorChristoph Studer <chstuder@google.com>
Fri, 22 Aug 2014 18:45:28 +0000 (20:45 +0200)
committerChristoph Studer <chstuder@google.com>
Fri, 22 Aug 2014 19:03:37 +0000 (21:03 +0200)
Bug: 16777910
Change-Id: Ic5baa910988f027c82ba16d713a44cc5d55b8333

services/core/java/com/android/server/notification/NotificationUsageStats.java

index 4a7a971..1df662c 100644 (file)
@@ -46,8 +46,13 @@ import java.util.Map;
  * {@hide}
  */
 public class NotificationUsageStats {
+    // WARNING: Aggregated stats can grow unboundedly with pkg+id+tag.
+    // Don't enable on production builds.
+    private static final boolean ENABLE_AGGREGATED_IN_MEMORY_STATS = true;
     private static final boolean ENABLE_SQLITE_LOG = true;
 
+    private static final AggregatedStats[] EMPTY_AGGREGATED_STATS = new AggregatedStats[0];
+
     // Guarded by synchronized(this).
     private final Map<String, AggregatedStats> mStats = new HashMap<String, AggregatedStats>();
     private final SQLiteLog mSQLiteLog;
@@ -147,6 +152,10 @@ public class NotificationUsageStats {
 
     // Locked by this.
     private AggregatedStats[] getAggregatedStatsLocked(NotificationRecord record) {
+        if (!ENABLE_AGGREGATED_IN_MEMORY_STATS) {
+            return EMPTY_AGGREGATED_STATS;
+        }
+
         StatusBarNotification n = record.sbn;
 
         String user = String.valueOf(n.getUserId());
@@ -171,9 +180,12 @@ public class NotificationUsageStats {
     }
 
     public synchronized void dump(PrintWriter pw, String indent, DumpFilter filter) {
-        for (AggregatedStats as : mStats.values()) {
-            if (filter != null && !filter.matches(as.key)) continue;
-            as.dump(pw, indent);
+        if (ENABLE_AGGREGATED_IN_MEMORY_STATS) {
+            for (AggregatedStats as : mStats.values()) {
+                if (filter != null && !filter.matches(as.key))
+                    continue;
+                as.dump(pw, indent);
+            }
         }
         if (ENABLE_SQLITE_LOG) {
             mSQLiteLog.dump(pw, indent, filter);