summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--metricsd/Android.mk15
-rw-r--r--metricsd/etc/weaved/commands/metrics.json10
-rw-r--r--metricsd/etc/weaved/states/metrics.schema.json8
-rw-r--r--metricsd/etc/weaved/traits/metrics.json18
-rw-r--r--metricsd/metrics_collector.cc16
5 files changed, 32 insertions, 35 deletions
diff --git a/metricsd/Android.mk b/metricsd/Android.mk
index 839ab659e..35537537f 100644
--- a/metricsd/Android.mk
+++ b/metricsd/Android.mk
@@ -146,9 +146,7 @@ LOCAL_CLANG := true
LOCAL_CPP_EXTENSION := $(metrics_cpp_extension)
LOCAL_CPPFLAGS := $(metrics_CPPFLAGS)
LOCAL_INIT_RC := metrics_collector.rc
-LOCAL_REQUIRED_MODULES := \
- metrics.json \
- metrics.schema.json
+LOCAL_REQUIRED_MODULES := metrics.json
LOCAL_RTTI_FLAG := -frtti
LOCAL_SHARED_LIBRARIES := $(metrics_collector_shared_libraries)
LOCAL_SRC_FILES := $(metrics_collector_common) \
@@ -207,13 +205,6 @@ include $(BUILD_NATIVE_TEST)
include $(CLEAR_VARS)
LOCAL_MODULE := metrics.json
LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/weaved/commands
-LOCAL_SRC_FILES := etc/weaved/commands/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := metrics.schema.json
-LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/weaved/states
-LOCAL_SRC_FILES := etc/weaved/states/$(LOCAL_MODULE)
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/weaved/traits
+LOCAL_SRC_FILES := etc/weaved/traits/$(LOCAL_MODULE)
include $(BUILD_PREBUILT)
diff --git a/metricsd/etc/weaved/commands/metrics.json b/metricsd/etc/weaved/commands/metrics.json
deleted file mode 100644
index b7f32d5f5..000000000
--- a/metricsd/etc/weaved/commands/metrics.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "_metrics": {
- "_enableAnalyticsReporting": {
- "minimalRole": "manager"
- },
- "_disableAnalyticsReporting": {
- "minimalRole": "manager"
- }
- }
-}
diff --git a/metricsd/etc/weaved/states/metrics.schema.json b/metricsd/etc/weaved/states/metrics.schema.json
deleted file mode 100644
index 130ac46a0..000000000
--- a/metricsd/etc/weaved/states/metrics.schema.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "_metrics": {
- "_AnalyticsReportingState": {
- "enum": ["enabled", "disabled"],
- "default": "disabled"
- }
- }
-}
diff --git a/metricsd/etc/weaved/traits/metrics.json b/metricsd/etc/weaved/traits/metrics.json
new file mode 100644
index 000000000..7d17c7774
--- /dev/null
+++ b/metricsd/etc/weaved/traits/metrics.json
@@ -0,0 +1,18 @@
+{
+ "_metrics": {
+ "commands": {
+ "_enableAnalyticsReporting": {
+ "minimalRole": "manager"
+ },
+ "_disableAnalyticsReporting": {
+ "minimalRole": "manager"
+ }
+ },
+ "state": {
+ "_AnalyticsReportingState": {
+ "type": "string",
+ "enum": [ "enabled", "disabled" ]
+ }
+ }
+ }
+}
diff --git a/metricsd/metrics_collector.cc b/metricsd/metrics_collector.cc
index f3871e42a..5468b9f25 100644
--- a/metricsd/metrics_collector.cc
+++ b/metricsd/metrics_collector.cc
@@ -71,6 +71,8 @@ const int kMetricMeminfoInterval = 30; // seconds
const char kMeminfoFileName[] = "/proc/meminfo";
const char kVmStatFileName[] = "/proc/vmstat";
+const char kWeaveComponent[] = "metrics";
+
} // namespace
// Zram sysfs entries.
@@ -246,10 +248,13 @@ int MetricsCollector::OnInit() {
device_ = weaved::Device::CreateInstance(
bus_,
base::Bind(&MetricsCollector::UpdateWeaveState, base::Unretained(this)));
+ device_->AddComponent(kWeaveComponent, {"_metrics"});
device_->AddCommandHandler(
+ kWeaveComponent,
"_metrics._enableAnalyticsReporting",
base::Bind(&MetricsCollector::OnEnableMetrics, base::Unretained(this)));
device_->AddCommandHandler(
+ kWeaveComponent,
"_metrics._disableAnalyticsReporting",
base::Bind(&MetricsCollector::OnDisableMetrics, base::Unretained(this)));
@@ -324,12 +329,13 @@ void MetricsCollector::UpdateWeaveState() {
if (!device_)
return;
- brillo::VariantDictionary state_change{
- { "_metrics._AnalyticsReportingState",
- metrics_lib_->AreMetricsEnabled() ? "enabled" : "disabled" }
- };
+ std::string enabled =
+ metrics_lib_->AreMetricsEnabled() ? "enabled" : "disabled";
- if (!device_->SetStateProperties(state_change, nullptr)) {
+ if (!device_->SetStateProperty(kWeaveComponent,
+ "_metrics._AnalyticsReportingState",
+ enabled,
+ nullptr)) {
LOG(ERROR) << "failed to update weave's state";
}
}