SysUiLeaks: Add GarbageMonitor

Adds a service for monitoring the amount of tracked garbage.
If it exceeds reasonable levels, a notification with a leak
report is posted.

Test: runtest systemui
Change-Id: Ib55281f2aac557743b97c46bc616688261c72e9c
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index 8d46b43..273b5e3 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -67,7 +67,9 @@
 import com.android.systemui.statusbar.policy.ZenModeController;
 import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
 import com.android.systemui.tuner.TunerService;
+import com.android.systemui.util.leak.GarbageMonitor;
 import com.android.systemui.util.leak.LeakDetector;
+import com.android.systemui.util.leak.LeakReporter;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -104,6 +106,12 @@
      */
     public static final DependencyKey<Handler> MAIN_HANDLER = new DependencyKey<>("main_handler");
 
+    /**
+     * An email address to send memory leak reports to by default.
+     */
+    public static final DependencyKey<String> LEAK_REPORT_EMAIL
+            = new DependencyKey<>("leak_report_email");
+
     private final ArrayMap<Object, Object> mDependencies = new ArrayMap<>();
     private final ArrayMap<Object, DependencyProvider> mProviders = new ArrayMap<>();
 
@@ -192,6 +200,18 @@
 
         mProviders.put(LeakDetector.class, LeakDetector::create);
 
+        mProviders.put(LEAK_REPORT_EMAIL, () -> null);
+
+        mProviders.put(LeakReporter.class, () -> new LeakReporter(
+                mContext,
+                getDependency(LeakDetector.class),
+                getDependency(LEAK_REPORT_EMAIL)));
+
+        mProviders.put(GarbageMonitor.class, () -> new GarbageMonitor(
+                getDependency(BG_LOOPER),
+                getDependency(LeakDetector.class),
+                getDependency(LeakReporter.class)));
+
         mProviders.put(TunerService.class, () ->
                 new TunerService(mContext));