Benchmarks for network metrics reporting

Bug: 29748723
Test: this is an APCT test.

(cherry picked from commit 484dac1d071c7476895c4a3184e8dbdd7b63e524)

Change-Id: I482a7d5c15210906069e0fe7ef55ab3f21bfc127
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index f8f300a..e962362 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -20,6 +20,7 @@
 
 #include <android-base/stringprintf.h>
 #include <cutils/log.h>
+#include <cutils/properties.h>
 #include <utils/Errors.h>
 #include <utils/String16.h>
 
@@ -58,6 +59,17 @@
     }
 }
 
+#define ENFORCE_DEBUGGABLE() {                              \
+    char value[PROPERTY_VALUE_MAX + 1];                     \
+    if (property_get("ro.debuggable", value, NULL) != 1     \
+            || value[0] != '1') {                           \
+        return binder::Status::fromExceptionCode(           \
+            binder::Status::EX_SECURITY,                    \
+            String8("Not available in production builds.")  \
+        );                                                  \
+    }                                                       \
+}
+
 #define ENFORCE_PERMISSION(permission) {                    \
     binder::Status status = checkPermission((permission));  \
     if (!status.isOk()) {                                   \
@@ -275,5 +287,27 @@
     return binder::Status::ok();
 }
 
+binder::Status NetdNativeService::getMetricsReportingLevel(int *reportingLevel) {
+    // This function intentionally does not lock, since the only thing it does is one read from an
+    // atomic_int.
+    ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+    ENFORCE_DEBUGGABLE();
+
+    *reportingLevel = gCtls->netCtrl.getMetricsReportingLevel();
+    return binder::Status::ok();
+}
+
+binder::Status NetdNativeService::setMetricsReportingLevel(const int reportingLevel) {
+    // This function intentionally does not lock, since the only thing it does is one write to an
+    // atomic_int.
+    ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
+    ENFORCE_DEBUGGABLE();
+
+    if (int err = gCtls->netCtrl.setMetricsReportingLevel(reportingLevel)) {
+        return binder::Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT);
+    }
+    return binder::Status::ok();
+}
+
 }  // namespace net
 }  // namespace android