aboutsummaryrefslogtreecommitdiff
path: root/cpp/telemetry
diff options
context:
space:
mode:
authorZhomart Mukhamejanov <zhomart@google.com>2020-12-28 18:16:04 -0800
committerZhomart Mukhamejanov <zhomart@google.com>2021-04-23 18:00:49 +0000
commit1a3a5a2a0290eca99987254b6e0a02b853ace11b (patch)
treee7102d6e48900d9b4ccda0b34c25f4e80057617f /cpp/telemetry
parent203d4c410f424eb311d04afd73b421d0ca206bd5 (diff)
downloadCar-1a3a5a2a0290eca99987254b6e0a02b853ace11b.tar.gz
Initialize cartelemetrylogs service.
Naming: - android.automotive.telemetry - will be an umpbrella project for all the telemetry relaterd services. - cartelemetryd (alias for android.automotve.telemetryd) - is an implementation for android.automotive.telemetry.ICarTelemetry. It collects logs and sends to CarTelemetryService. - "aidl_api/" is generated using "m ..-update-api" command. Bug: 181373018 Test: mmm -j packages/services/Car/cpp/telemetry Test: m -j Test: flashed and verified that a HAL sampleclient can write to it. Change-Id: Id42a5e7aa4a7075394d8b0ba8f4c984735d9c7cd Merged-In: Id42a5e7aa4a7075394d8b0ba8f4c984735d9c7cd
Diffstat (limited to 'cpp/telemetry')
-rw-r--r--cpp/telemetry/ARCHITECTURE.md18
-rw-r--r--cpp/telemetry/Android.bp61
-rw-r--r--cpp/telemetry/OWNERS3
-rw-r--r--cpp/telemetry/README.md3
-rw-r--r--cpp/telemetry/android.automotive.telemetryd@1.0.rc9
-rw-r--r--cpp/telemetry/android.automotive.telemetryd@1.0.xml23
-rw-r--r--cpp/telemetry/products/telemetry.mk22
-rw-r--r--cpp/telemetry/sampleclient/Android.bp33
-rw-r--r--cpp/telemetry/sampleclient/README.md47
-rw-r--r--cpp/telemetry/sampleclient/main.cpp68
-rw-r--r--cpp/telemetry/sepolicy/private/cartelemetryd.te9
-rw-r--r--cpp/telemetry/sepolicy/private/file_contexts1
-rw-r--r--cpp/telemetry/sepolicy/private/service_contexts1
-rw-r--r--cpp/telemetry/sepolicy/public/cartelemetryd.te1
-rw-r--r--cpp/telemetry/sepolicy/public/service.te1
-rw-r--r--cpp/telemetry/src/CarTelemetryImpl.cpp39
-rw-r--r--cpp/telemetry/src/CarTelemetryImpl.h42
-rw-r--r--cpp/telemetry/src/main.cpp59
18 files changed, 440 insertions, 0 deletions
diff --git a/cpp/telemetry/ARCHITECTURE.md b/cpp/telemetry/ARCHITECTURE.md
new file mode 100644
index 0000000000..ae60c6b3a5
--- /dev/null
+++ b/cpp/telemetry/ARCHITECTURE.md
@@ -0,0 +1,18 @@
+# Architecture of Car Telemetry Service
+
+## Names
+
+- C++ namespace `android.automotive.telemetry` - for all the car telemetry related projects.
+- android.telemetry.ICarTelemetry - AIDL interface for collecting car data.
+- cartelemetryd (android.automotive.telemetryd) - a daemon that implements `ICarTelemetry`
+ interface.
+- CarTelemetryService - a part of CarService that executes scrits. Located in car services dir.
+
+## Structure
+
+- aidl/ - AIDL declerations
+- products/ - AAOS Telemetry product, it's included in car_base.mk
+- sepolicy - SELinux policies
+- src/ - Source code
+- *.rc - rc file to start services
+- *.xml - VINTF manifest (TODO: needed?)
diff --git a/cpp/telemetry/Android.bp b/cpp/telemetry/Android.bp
new file mode 100644
index 0000000000..11ed4dc37f
--- /dev/null
+++ b/cpp/telemetry/Android.bp
@@ -0,0 +1,61 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_defaults {
+ name: "cartelemetryd_defaults",
+ cflags: [
+ "-Werror",
+ "-Wall",
+ "-Wno-unused-parameter",
+ ],
+ shared_libs: [
+ "android.frameworks.automotive.telemetry-V1-cpp",
+ "libbase",
+ "liblog",
+ "libbinder",
+ "libutils",
+ ],
+ product_variables: {
+ debuggable: {
+ cflags: [
+ "-DCARTELEMETRYD_DEBUG=true",
+ ]
+ }
+ },
+}
+
+cc_library {
+ name: "android.automotive.telemetryd@1.0-impl",
+ defaults: [
+ "cartelemetryd_defaults",
+ ],
+ srcs: [
+ "src/CarTelemetryImpl.cpp",
+ ],
+}
+
+cc_binary {
+ name: "android.automotive.telemetryd@1.0",
+ defaults: [
+ "cartelemetryd_defaults",
+ ],
+ srcs: [
+ "src/main.cpp"
+ ],
+ init_rc: ["android.automotive.telemetryd@1.0.rc"],
+ vintf_fragments: ["android.automotive.telemetryd@1.0.xml"],
+ shared_libs: [
+ "android.automotive.telemetryd@1.0-impl"
+ ],
+}
diff --git a/cpp/telemetry/OWNERS b/cpp/telemetry/OWNERS
new file mode 100644
index 0000000000..80794e17c4
--- /dev/null
+++ b/cpp/telemetry/OWNERS
@@ -0,0 +1,3 @@
+sgurun@google.com
+zhomart@google.com
+mdashouk@google.com
diff --git a/cpp/telemetry/README.md b/cpp/telemetry/README.md
new file mode 100644
index 0000000000..e1f277b975
--- /dev/null
+++ b/cpp/telemetry/README.md
@@ -0,0 +1,3 @@
+# Automotive Telemetry Service
+
+A structured log collection service for CarTelemetryService. See ARCHITECTURE.md to learn internals.
diff --git a/cpp/telemetry/android.automotive.telemetryd@1.0.rc b/cpp/telemetry/android.automotive.telemetryd@1.0.rc
new file mode 100644
index 0000000000..1513fa8f49
--- /dev/null
+++ b/cpp/telemetry/android.automotive.telemetryd@1.0.rc
@@ -0,0 +1,9 @@
+service cartelemetryd_service /system/bin/android.automotive.telemetryd@1.0
+ class core
+ user system
+ group system
+ disabled # starts below on early-init
+
+on early-init
+ # Start the service only after initializing the properties.
+ start cartelemetryd_service
diff --git a/cpp/telemetry/android.automotive.telemetryd@1.0.xml b/cpp/telemetry/android.automotive.telemetryd@1.0.xml
new file mode 100644
index 0000000000..81564664d9
--- /dev/null
+++ b/cpp/telemetry/android.automotive.telemetryd@1.0.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- Required VINTF manifest for AIDL servers. -->
+<manifest version="1.0" type="framework">
+ <hal format="aidl">
+ <name>android.frameworks.automotive.telemetry</name>
+ <version>1</version>
+ <fqname>ICarTelemetry/default</fqname>
+ </hal>
+</manifest>
diff --git a/cpp/telemetry/products/telemetry.mk b/cpp/telemetry/products/telemetry.mk
new file mode 100644
index 0000000000..634c9a93be
--- /dev/null
+++ b/cpp/telemetry/products/telemetry.mk
@@ -0,0 +1,22 @@
+# Copyright (C) 2021 The Android Open Source Project
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# cartelemetryd service
+PRODUCT_PACKAGES += android.automotive.telemetryd@1.0
+
+# Selinux public policies for cartelemetry
+PRODUCT_PUBLIC_SEPOLICY_DIRS += packages/services/Car/cpp/telemetry/sepolicy/public
+
+# Selinux private policies for cartelemetry
+PRODUCT_PRIVATE_SEPOLICY_DIRS += packages/services/Car/cpp/telemetry/sepolicy/private
diff --git a/cpp/telemetry/sampleclient/Android.bp b/cpp/telemetry/sampleclient/Android.bp
new file mode 100644
index 0000000000..ec608c44ce
--- /dev/null
+++ b/cpp/telemetry/sampleclient/Android.bp
@@ -0,0 +1,33 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Sample client for ICarTelemetry service.
+cc_binary {
+ name: "android.automotive.telemetryd-sampleclient",
+ srcs: [
+ "main.cpp",
+ ],
+ vendor: true,
+ cflags: [
+ "-Werror",
+ "-Wall",
+ "-Wno-unused-parameter",
+ ],
+ shared_libs: [
+ "android.frameworks.automotive.telemetry-V1-ndk_platform",
+ "libbase",
+ "libbinder_ndk",
+ "libutils",
+ ],
+}
diff --git a/cpp/telemetry/sampleclient/README.md b/cpp/telemetry/sampleclient/README.md
new file mode 100644
index 0000000000..8e8f3cc936
--- /dev/null
+++ b/cpp/telemetry/sampleclient/README.md
@@ -0,0 +1,47 @@
+# ICarTelemetry Sample Client
+
+This is a sample vendor service that sends `CarData` to car telemetry service.
+
+To include it in the final image, add
+`PRODUCT_PACKAGES += android.automotive.telemetryd-sampleclient` to
+`//packages/services/Car/cpp/telemetry/products/telemetry.mk` (or other suitable mk file).
+
+Example:
+```
+# this goes to products/telemetry.mk
+
+PRODUCT_PACKAGES += android.automotive.telemetryd-sampleclient
+```
+
+The sampleclient doesn't automatically start during boot, to start manually, run:
+`adb shell /vendor/bin/android.automotive.telemetryd-sampleclient`.
+
+If you want to test it by running `init`, add these SELinux rules:
+
+```
+# this goes to sepolicy/private/cartelemetryd.te
+
+type cartelemetryd_sample, domain;
+type cartelemetryd_sample_exec, vendor_file_type, exec_type, file_type;
+init_daemon_domain(cartelemetryd_sample)
+```
+
+```
+# this goes to sepolicy/private/file_contexts
+
+/vendor/bin/android\.automotive\.telemetryd-sampleclient u:object_r:cartelemetryd_sample_exec:s0
+```
+
+And create an `.rc` file:
+
+```
+# File: cartelemetryd-sampleclient.rc
+# Don't forget to add `init_rc: ["cartelemetryd-sampleclient.rc"],` to the Android.bp
+
+service cartelemetryd_sample /vendor/bin/android.automotive.telemetryd-sampleclient
+ class hal
+ user system
+ group system
+ oneshot # run once, otherwise init keeps restarting it
+ disabled # do not start automatically
+```
diff --git a/cpp/telemetry/sampleclient/main.cpp b/cpp/telemetry/sampleclient/main.cpp
new file mode 100644
index 0000000000..e45dc65bcc
--- /dev/null
+++ b/cpp/telemetry/sampleclient/main.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "cartelemetryd_sample"
+
+#include <aidl/android/frameworks/automotive/telemetry/ICarTelemetry.h>
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <android/binder_manager.h>
+#include <utils/SystemClock.h>
+
+using ::aidl::android::frameworks::automotive::telemetry::CarData;
+using ::aidl::android::frameworks::automotive::telemetry::ICarTelemetry;
+using ::android::base::StringPrintf;
+
+int main(int argc, char* argv[]) {
+ const auto started_at_millis = android::elapsedRealtime();
+
+ // The name of the service is described in
+ // https://source.android.com/devices/architecture/aidl/aidl-hals#instance-names
+ const std::string instance = StringPrintf("%s/default", ICarTelemetry::descriptor);
+ LOG(INFO) << "Obtaining: " << instance;
+ std::shared_ptr<ICarTelemetry> service = ICarTelemetry::fromBinder(
+ ndk::SpAIBinder(AServiceManager_getService(instance.c_str())));
+ if (!service) {
+ LOG(ERROR) << "ICarTelemetry service not found, may be still initializing?";
+ return 1;
+ }
+
+ LOG(INFO) << "Building a CarData message, delta_since_start: "
+ << android::elapsedRealtime() - started_at_millis << " millis";
+
+ // Build a CarData message
+ // TODO(b/174608802): set a correct data ID and content
+ CarData msg;
+ msg.id = 101;
+ msg.content = {1, 0, 1, 0};
+
+ LOG(INFO) << "Sending the car data, delta_since_start: "
+ << android::elapsedRealtime() - started_at_millis << " millis";
+
+ // Send the data
+ ndk::ScopedAStatus writeStatus = service->write({msg});
+
+ if (!writeStatus.isOk()) {
+ LOG(WARNING) << "Failed to write to the service: " << writeStatus.getMessage();
+ }
+
+ // Note: On a device the delta_since_start was between 1ms to 4ms
+ // (service side was not fully implemented yet during the test).
+ LOG(INFO) << "Finished, delta_since_start: " << android::elapsedRealtime() - started_at_millis
+ << " millis";
+
+ return 0;
+}
diff --git a/cpp/telemetry/sepolicy/private/cartelemetryd.te b/cpp/telemetry/sepolicy/private/cartelemetryd.te
new file mode 100644
index 0000000000..3baefb1ded
--- /dev/null
+++ b/cpp/telemetry/sepolicy/private/cartelemetryd.te
@@ -0,0 +1,9 @@
+### See //system/sepolicy/public/te_macros to learn about some SELinux macros.
+
+type cartelemetryd_exec, system_file_type, exec_type, file_type;
+
+binder_use(cartelemetryd)
+
+add_service(cartelemetryd, cartelemetryd_service)
+
+init_daemon_domain(cartelemetryd)
diff --git a/cpp/telemetry/sepolicy/private/file_contexts b/cpp/telemetry/sepolicy/private/file_contexts
new file mode 100644
index 0000000000..0b0915dd14
--- /dev/null
+++ b/cpp/telemetry/sepolicy/private/file_contexts
@@ -0,0 +1 @@
+/system/bin/android\.automotive\.telemetryd@1\.0 u:object_r:cartelemetryd_exec:s0
diff --git a/cpp/telemetry/sepolicy/private/service_contexts b/cpp/telemetry/sepolicy/private/service_contexts
new file mode 100644
index 0000000000..24d7df3af9
--- /dev/null
+++ b/cpp/telemetry/sepolicy/private/service_contexts
@@ -0,0 +1 @@
+android.frameworks.automotive.telemetry.ICarTelemetry/default u:object_r:cartelemetryd_service:s0
diff --git a/cpp/telemetry/sepolicy/public/cartelemetryd.te b/cpp/telemetry/sepolicy/public/cartelemetryd.te
new file mode 100644
index 0000000000..fab4d58108
--- /dev/null
+++ b/cpp/telemetry/sepolicy/public/cartelemetryd.te
@@ -0,0 +1 @@
+type cartelemetryd, domain, coredomain;
diff --git a/cpp/telemetry/sepolicy/public/service.te b/cpp/telemetry/sepolicy/public/service.te
new file mode 100644
index 0000000000..f0beee8fe0
--- /dev/null
+++ b/cpp/telemetry/sepolicy/public/service.te
@@ -0,0 +1 @@
+type cartelemetryd_service, service_manager_type;
diff --git a/cpp/telemetry/src/CarTelemetryImpl.cpp b/cpp/telemetry/src/CarTelemetryImpl.cpp
new file mode 100644
index 0000000000..f3187ec414
--- /dev/null
+++ b/cpp/telemetry/src/CarTelemetryImpl.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2021, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CarTelemetryImpl.h"
+
+#include <android-base/logging.h>
+#include <android/frameworks/automotive/telemetry/CarData.h>
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+using ::android::binder::Status;
+using ::android::frameworks::automotive::telemetry::CarData;
+
+Status CarTelemetryImpl::write(const std::vector<CarData>& dataList) {
+ LOG(INFO) << "write called";
+ return Status::ok();
+}
+
+status_t CarTelemetryImpl::dump(int fd, const Vector<String16>& args) {
+ return android::OK;
+}
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
diff --git a/cpp/telemetry/src/CarTelemetryImpl.h b/cpp/telemetry/src/CarTelemetryImpl.h
new file mode 100644
index 0000000000..f3422489ba
--- /dev/null
+++ b/cpp/telemetry/src/CarTelemetryImpl.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CPP_TELEMETRY_SRC_CARTELEMETRYIMPL_H_
+#define CPP_TELEMETRY_SRC_CARTELEMETRYIMPL_H_
+
+#include <android/frameworks/automotive/telemetry/BnCarTelemetry.h>
+#include <android/frameworks/automotive/telemetry/CarData.h>
+#include <utils/String16.h>
+#include <utils/Vector.h>
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+// Implementation of android.frameworks.automotive.telemetry.ICarTelemetry.
+class CarTelemetryImpl : public android::frameworks::automotive::telemetry::BnCarTelemetry {
+public:
+ android::binder::Status write(
+ const std::vector<android::frameworks::automotive::telemetry::CarData>& dataList)
+ override;
+ status_t dump(int fd, const android::Vector<android::String16>& args) override;
+};
+
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
+
+#endif // CPP_TELEMETRY_SRC_CARTELEMETRYIMPL_H_
diff --git a/cpp/telemetry/src/main.cpp b/cpp/telemetry/src/main.cpp
new file mode 100644
index 0000000000..1864c56f07
--- /dev/null
+++ b/cpp/telemetry/src/main.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CarTelemetryImpl.h"
+
+#include <android-base/chrono_utils.h>
+#include <android-base/logging.h>
+#include <android-base/properties.h>
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+#include <binder/ProcessState.h>
+
+#include <thread> // NOLINT(build/c++11)
+
+using ::android::String16;
+using ::android::automotive::telemetry::CarTelemetryImpl;
+
+constexpr const char kCarTelemetryServiceName[] =
+ "android.frameworks.automotive.telemetry.ICarTelemetry/default";
+
+// TODO(b/174608802): handle SIGQUIT/SIGTERM
+
+int main(void) {
+ LOG(INFO) << "Starting cartelemetryd";
+
+ android::sp<CarTelemetryImpl> telemetry = new CarTelemetryImpl();
+
+ // Wait for the service manager before starting ICarTelemetry service.
+ while (android::base::GetProperty("init.svc.servicemanager", "") != "running") {
+ // Poll frequent enough so the writer clients can connect to the service during boot.
+ std::this_thread::sleep_for(250ms);
+ }
+
+ LOG(VERBOSE) << "Registering " << kCarTelemetryServiceName;
+ auto status = android::defaultServiceManager()->addService(String16(kCarTelemetryServiceName),
+ telemetry);
+ if (status != android::OK) {
+ LOG(ERROR) << "Unable to register " << kCarTelemetryServiceName << ", status=" << status;
+ return 1;
+ }
+
+ LOG(VERBOSE) << "Service is created, joining the threadpool";
+ android::ProcessState::self()->startThreadPool(); // Starts default 15 binder threads.
+ android::IPCThreadState::self()->joinThreadPool();
+ return 1; // never reaches
+}