metrics: Add init script for metrics_daemon.
This init script creates the metrics data directory (/data/misc/metrics)
and starts the daemon.
BUG: 22953527
Change-Id: I21cd36f38a7a3550bc755cef5699e9a6ac3dfb94
diff --git a/metricsd/Android.mk b/metricsd/Android.mk
index 9edba6e..0442147 100644
--- a/metricsd/Android.mk
+++ b/metricsd/Android.mk
@@ -16,6 +16,8 @@
ifeq ($(HOST_OS),linux)
+LOCAL_INIT_SERVICE := metrics_daemon
+
metrics_cpp_extension := .cc
libmetrics_sources := \
c_metrics_library.cc \
@@ -96,12 +98,13 @@
# metrics daemon.
# ========================================================
include $(CLEAR_VARS)
-LOCAL_MODULE := metrics_daemon
+LOCAL_MODULE := $(LOCAL_INIT_SERVICE)
LOCAL_C_INCLUDES := $(metrics_includes) \
external/libchromeos
LOCAL_CFLAGS := $(metrics_CFLAGS)
LOCAL_CPP_EXTENSION := $(metrics_cpp_extension)
LOCAL_CPPFLAGS := $(metrics_CPPFLAGS)
+LOCAL_REQUIRED_MODULES := init.$(LOCAL_INIT_SERVICE).rc
LOCAL_RTTI_FLAG := -frtti
LOCAL_SHARED_LIBRARIES := $(metrics_shared_libraries) \
libmetrics \
@@ -113,4 +116,13 @@
LOCAL_STATIC_LIBRARIES := metrics_daemon_protos
include $(BUILD_EXECUTABLE)
+ifdef INITRC_TEMPLATE
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.$(LOCAL_INIT_SERVICE).rc
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_INITRCD)
+LOCAL_SRC_FILES := init.$(LOCAL_INIT_SERVICE).rc
+include $(BUILD_PREBUILT)
+endif # INITRC_TEMPLATE
+
endif # HOST_OS == linux
diff --git a/metricsd/init.metrics_daemon.rc b/metricsd/init.metrics_daemon.rc
new file mode 100644
index 0000000..ad78ea5
--- /dev/null
+++ b/metricsd/init.metrics_daemon.rc
@@ -0,0 +1,8 @@
+on boot
+ mkdir /data/misc/metrics 0700 system system
+
+service metrics_daemon /system/bin/metrics_daemon --uploader -nodaemon
+ class late_start
+ user system
+ group system dbus inet
+ seclabel u:r:brillo:s0