statsd informs incidentd of anomalies

When an anomaly is detected by statsd, it passes to incidentd the
information specified in the config.

Test: manual (using the fake config) saw in logcat that incidentd was
called (reportIncident)
Change-Id: I0a257b49db706d7b14a2976fb7e62c3c3535725f
diff --git a/cmds/statsd/src/anomaly/AnomalyTracker.cpp b/cmds/statsd/src/anomaly/AnomalyTracker.cpp
index c2bf233..7bacb44 100644
--- a/cmds/statsd/src/anomaly/AnomalyTracker.cpp
+++ b/cmds/statsd/src/anomaly/AnomalyTracker.cpp
@@ -19,6 +19,9 @@
 
 #include "AnomalyTracker.h"
 
+#include <android/os/IIncidentManager.h>
+#include <android/os/IncidentReportArgs.h>
+#include <binder/IServiceManager.h>
 #include <time.h>
 
 namespace android {
@@ -213,7 +216,7 @@
             // TODO: Can construct a name based on the criteria (and/or relay the criteria).
             ALOGW("An anomaly (nameless) has occurred! Informing incidentd.");
         }
-        // TODO: informIncidentd();
+        informIncidentd();
     } else {
         ALOGW("An anomaly has occurred! (But informing incidentd not requested.)");
     }
@@ -314,6 +317,29 @@
     }
 }
 
+void AnomalyTracker::informIncidentd() {
+    VLOG("informIncidentd called.");
+    if (!mAlert.has_incidentd_details()) {
+        ALOGE("Attempted to call incidentd without any incidentd_details.");
+        return;
+    }
+    sp<IIncidentManager> service = interface_cast<IIncidentManager>(
+            defaultServiceManager()->getService(android::String16("incident")));
+    if (service == NULL) {
+        ALOGW("Couldn't get the incident service.");
+        return;
+    }
+
+    IncidentReportArgs incidentReport;
+    const Alert::IncidentdDetails& details = mAlert.incidentd_details();
+    for (int i = 0; i < details.section_size(); i++) {
+        incidentReport.addSection(details.section(i));
+    }
+    // TODO: Pass in mAlert.name() into the addHeader?
+
+    service->reportIncident(incidentReport);
+}
+
 }  // namespace statsd
 }  // namespace os
 }  // namespace android