aboutsummaryrefslogtreecommitdiff
path: root/cpp/telemetry
diff options
context:
space:
mode:
authorZhomart Mukhamejanov <zhomart@google.com>2021-03-18 11:41:25 -0700
committerZhomart Mukhamejanov <zhomart@google.com>2021-04-23 23:01:46 +0000
commit6add2eedb04d504e987f4be32663c0f2ce1697fa (patch)
tree2aa353958bf76129d2ee917105fcf709ded99098 /cpp/telemetry
parent3ba6a0b38b7940a20904241f2d299212da0f604a (diff)
downloadCar-6add2eedb04d504e987f4be32663c0f2ce1697fa.tar.gz
Initialize ICarTelemetryInternal class.
- Create TelemetryServer class that manages all the other services. - Move the dumpstate dumping to internal class from ICarTelemetry, make it closer to internal stuff. - Implementations are coming in other CLs to minimize CL sizes. Bug: 182608968 Test: mmm -j packages/services/Car/cpp/telemetry Test: atest cartelemetryd_impl_test Change-Id: I3c1698e822b5a3dcf376cbd04aacb94fcd374507 Merged-In: I3c1698e822b5a3dcf376cbd04aacb94fcd374507 (cherry picked from commit fe60c141541b2cf4f5a00580f0b0198b3121ac1a)
Diffstat (limited to 'cpp/telemetry')
-rw-r--r--cpp/telemetry/ARCHITECTURE.md16
-rw-r--r--cpp/telemetry/Android.bp3
-rw-r--r--cpp/telemetry/aidl/Android.bp31
-rw-r--r--cpp/telemetry/aidl/android/automotive/telemetry/internal/CarDataInternal.aidl32
-rw-r--r--cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarDataListener.aidl35
-rw-r--r--cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarTelemetryInternal.aidl38
-rw-r--r--cpp/telemetry/src/CarTelemetryImpl.cpp2
-rw-r--r--cpp/telemetry/src/CarTelemetryInternalImpl.cpp53
-rw-r--r--cpp/telemetry/src/CarTelemetryInternalImpl.h57
-rw-r--r--cpp/telemetry/src/RingBuffer.cpp12
-rw-r--r--cpp/telemetry/src/RingBuffer.h9
-rw-r--r--cpp/telemetry/src/TelemetryServer.cpp87
-rw-r--r--cpp/telemetry/src/TelemetryServer.h48
-rw-r--r--cpp/telemetry/src/main.cpp41
14 files changed, 414 insertions, 50 deletions
diff --git a/cpp/telemetry/ARCHITECTURE.md b/cpp/telemetry/ARCHITECTURE.md
index ae60c6b3a5..75dd194cd5 100644
--- a/cpp/telemetry/ARCHITECTURE.md
+++ b/cpp/telemetry/ARCHITECTURE.md
@@ -10,9 +10,13 @@
## 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?)
+```
+aidl/ - Internal AIDL declerations, for public AIDLs, please see
+ //frameworks/hardware/interfaces/automotive/telemetry
+products/ - AAOS Telemetry product, it's included in car_base.mk
+sepolicy - SELinux policies
+src/ - Source code
+ TelemetryServer.h - The main class.
+*.rc - rc file to start services
+*.xml - VINTF manifest (TODO: needed?)
+```
diff --git a/cpp/telemetry/Android.bp b/cpp/telemetry/Android.bp
index 45e1358a57..4640be9df2 100644
--- a/cpp/telemetry/Android.bp
+++ b/cpp/telemetry/Android.bp
@@ -25,6 +25,7 @@ cc_defaults {
],
shared_libs: [
"android.frameworks.automotive.telemetry-V1-cpp",
+ "android.automotive.telemetry.internal-cpp",
"libbase",
"liblog",
"libbinder",
@@ -47,6 +48,8 @@ cc_library {
srcs: [
"src/CarTelemetryImpl.cpp",
"src/RingBuffer.cpp",
+ "src/TelemetryServer.cpp",
+ "src/CarTelemetryInternalImpl.cpp",
],
// Allow dependencies to use header files.
export_include_dirs: [
diff --git a/cpp/telemetry/aidl/Android.bp b/cpp/telemetry/aidl/Android.bp
new file mode 100644
index 0000000000..bf6fac8297
--- /dev/null
+++ b/cpp/telemetry/aidl/Android.bp
@@ -0,0 +1,31 @@
+// 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.
+
+aidl_interface {
+ name: "android.automotive.telemetry.internal",
+ unstable: true,
+ vendor_available: false,
+ srcs: [
+ "android/automotive/telemetry/internal/*.aidl",
+ ],
+ backend: {
+ cpp: {
+ enabled: true,
+ },
+ java: {
+ platform_apis: true,
+ enabled: true,
+ },
+ }
+}
diff --git a/cpp/telemetry/aidl/android/automotive/telemetry/internal/CarDataInternal.aidl b/cpp/telemetry/aidl/android/automotive/telemetry/internal/CarDataInternal.aidl
new file mode 100644
index 0000000000..bf31169f19
--- /dev/null
+++ b/cpp/telemetry/aidl/android/automotive/telemetry/internal/CarDataInternal.aidl
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package android.automotive.telemetry.internal;
+
+/**
+ * Wrapper for {@code android.frameworks.automotive.telemetry.CarData}.
+ */
+parcelable CarDataInternal {
+ /**
+ * Must be a valid id. Scripts subscribe to data using this id.
+ */
+ int id;
+
+ /**
+ * Content corresponding to the schema defined by the id.
+ */
+ byte[] content;
+}
diff --git a/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarDataListener.aidl b/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarDataListener.aidl
new file mode 100644
index 0000000000..48ab6f9d03
--- /dev/null
+++ b/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarDataListener.aidl
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package android.automotive.telemetry.internal;
+
+import android.automotive.telemetry.internal.CarDataInternal;
+
+/**
+ * Listener for {@code ICarTelemetryInternal#registerListener}.
+ */
+oneway interface ICarDataListener {
+ /**
+ * Called by ICarTelemetry when the data are available to be consumed. ICarTelemetry removes
+ * the delivered data when the callback succeeds.
+ *
+ * <p>If the collected data is too large, it will send only chunk of the data, and the callback
+ * will be fired again.
+ *
+ * @param dataList the pushed data.
+ */
+ void onCarDataReceived(in CarDataInternal[] dataList);
+}
diff --git a/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarTelemetryInternal.aidl b/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarTelemetryInternal.aidl
new file mode 100644
index 0000000000..9f7c834f97
--- /dev/null
+++ b/cpp/telemetry/aidl/android/automotive/telemetry/internal/ICarTelemetryInternal.aidl
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package android.automotive.telemetry.internal;
+
+import android.automotive.telemetry.internal.ICarDataListener;
+
+/**
+ * An internal API provided by cartelemetryd for receiving the collected data.
+ */
+interface ICarTelemetryInternal {
+ /**
+ * Sets a listener for CarData. If there are existing CarData in the buffer, the daemon will
+ * start pushing them to the listener. There can be only a single registered listener at a time.
+ *
+ * @param listener the only listener.
+ * @throws IllegalStateException if someone is already registered.
+ */
+ void setListener(in ICarDataListener listener);
+
+ /**
+ * Clears the listener if exists. Silently ignores if there is no listener.
+ */
+ void clearListener();
+}
diff --git a/cpp/telemetry/src/CarTelemetryImpl.cpp b/cpp/telemetry/src/CarTelemetryImpl.cpp
index bbf7ac521d..ab6918000d 100644
--- a/cpp/telemetry/src/CarTelemetryImpl.cpp
+++ b/cpp/telemetry/src/CarTelemetryImpl.cpp
@@ -47,8 +47,6 @@ Status CarTelemetryImpl::write(const std::vector<CarData>& dataList) {
}
status_t CarTelemetryImpl::dump(int fd, const android::Vector<android::String16>& args) {
- dprintf(fd, "CarTelemetryImpl:\n");
- mRingBuffer->dump(fd, /* indent= */ 2);
return android::OK;
}
} // namespace telemetry
diff --git a/cpp/telemetry/src/CarTelemetryInternalImpl.cpp b/cpp/telemetry/src/CarTelemetryInternalImpl.cpp
new file mode 100644
index 0000000000..ab9def44ec
--- /dev/null
+++ b/cpp/telemetry/src/CarTelemetryInternalImpl.cpp
@@ -0,0 +1,53 @@
+/*
+ * 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 "CarTelemetryInternalImpl.h"
+
+#include "BufferedCarData.h"
+
+#include <android-base/logging.h>
+#include <android/automotive/telemetry/internal/CarDataInternal.h>
+#include <android/automotive/telemetry/internal/ICarDataListener.h>
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+using ::android::sp;
+using ::android::automotive::telemetry::internal::CarDataInternal;
+using ::android::automotive::telemetry::internal::ICarDataListener;
+using ::android::binder::Status;
+
+CarTelemetryInternalImpl::CarTelemetryInternalImpl(RingBuffer* buffer) : mRingBuffer(buffer) {}
+
+Status CarTelemetryInternalImpl::setListener(const sp<ICarDataListener>& listener) {
+ // TODO(b/182608968): implement
+ return Status::ok();
+}
+
+Status CarTelemetryInternalImpl::clearListener() {
+ // TODO(b/182608968): implement
+ return Status::ok();
+}
+
+status_t CarTelemetryInternalImpl::dump(int fd, const android::Vector<android::String16>& args) {
+ dprintf(fd, "ICarTelemetryInternal:\n");
+ mRingBuffer->dump(fd);
+ return android::OK;
+}
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
diff --git a/cpp/telemetry/src/CarTelemetryInternalImpl.h b/cpp/telemetry/src/CarTelemetryInternalImpl.h
new file mode 100644
index 0000000000..7b9fe73931
--- /dev/null
+++ b/cpp/telemetry/src/CarTelemetryInternalImpl.h
@@ -0,0 +1,57 @@
+/*
+ * 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_CARTELEMETRYINTERNALIMPL_H_
+#define CPP_TELEMETRY_SRC_CARTELEMETRYINTERNALIMPL_H_
+
+#include <android/automotive/telemetry/internal/BnCarTelemetryInternal.h>
+#include <android/automotive/telemetry/internal/CarDataInternal.h>
+#include <utils/String16.h>
+#include <utils/Vector.h>
+
+#include <RingBuffer.h>
+
+#include <memory>
+#include <vector>
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+// Implementation of android.automotive.telemetry.ICarTelemetryInternal.
+class CarTelemetryInternalImpl :
+ public android::automotive::telemetry::internal::BnCarTelemetryInternal {
+public:
+ // Doesn't own `buffer`.
+ explicit CarTelemetryInternalImpl(RingBuffer* buffer);
+
+ android::binder::Status setListener(
+ const android::sp<android::automotive::telemetry::internal::ICarDataListener>& listener)
+ override;
+
+ android::binder::Status clearListener() override;
+
+ status_t dump(int fd, const android::Vector<android::String16>& args) override;
+
+private:
+ RingBuffer* mRingBuffer; // not owned
+};
+
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
+
+#endif // CPP_TELEMETRY_SRC_CARTELEMETRYINTERNALIMPL_H_
diff --git a/cpp/telemetry/src/RingBuffer.cpp b/cpp/telemetry/src/RingBuffer.cpp
index 658d9d39b3..e46f0d3bba 100644
--- a/cpp/telemetry/src/RingBuffer.cpp
+++ b/cpp/telemetry/src/RingBuffer.cpp
@@ -64,12 +64,12 @@ std::vector<BufferedCarData> RingBuffer::popAllDataForId(int32_t id) {
return result;
}
-void RingBuffer::dump(int fd, int indent) const {
- dprintf(fd, "%*sRingBuffer:\n", indent, "");
- dprintf(fd, "%*s mSizeLimitBytes=%d\n", indent, "", mSizeLimitBytes);
- dprintf(fd, "%*s mCurrentSizeBytes=%d\n", indent, "", mCurrentSizeBytes);
- dprintf(fd, "%*s mList.size=%zu\n", indent, "", mList.size());
- dprintf(fd, "%*s mTotalDroppedDataCount=%" PRIu64 "\n", indent, "", mTotalDroppedDataCount);
+void RingBuffer::dump(int fd) const {
+ dprintf(fd, "RingBuffer:\n");
+ dprintf(fd, " mSizeLimitBytes=%d\n", mSizeLimitBytes);
+ dprintf(fd, " mCurrentSizeBytes=%d\n", mCurrentSizeBytes);
+ dprintf(fd, " mList.size=%zu\n", mList.size());
+ dprintf(fd, " mTotalDroppedDataCount=%" PRIu64 "\n", mTotalDroppedDataCount);
}
int32_t RingBuffer::currentSizeBytes() const {
diff --git a/cpp/telemetry/src/RingBuffer.h b/cpp/telemetry/src/RingBuffer.h
index 8978f323bf..db10a382a0 100644
--- a/cpp/telemetry/src/RingBuffer.h
+++ b/cpp/telemetry/src/RingBuffer.h
@@ -25,9 +25,16 @@ namespace android {
namespace automotive {
namespace telemetry {
+// A ring buffer that holds BufferedCarData. It drops old data if it's full.
+// Not thread-safe.
+// TODO(b/182608968): make it thread-safe
class RingBuffer {
public:
// RingBuffer limits `currentSizeBytes()` to the given param `sizeLimitBytes`.
+ // There is also a hard limit on number of items, it's expected that reader clients will
+ // fetch all the data before the buffer gets full.
+ // TODO(b/182608968): Only limit the size using count, and restructure the methods to match
+ // the new internal API.
explicit RingBuffer(int32_t sizeLimitBytes);
// Pushes the data to the buffer. If the buffer is full, it removes the oldest data.
@@ -39,7 +46,7 @@ public:
std::vector<BufferedCarData> popAllDataForId(int32_t id);
// Dumps the current state for dumpsys.
- void dump(int fd, int indent) const;
+ void dump(int fd) const;
// Returns the total size of CarData content in the buffer.
int32_t currentSizeBytes() const;
diff --git a/cpp/telemetry/src/TelemetryServer.cpp b/cpp/telemetry/src/TelemetryServer.cpp
new file mode 100644
index 0000000000..c99e38b065
--- /dev/null
+++ b/cpp/telemetry/src/TelemetryServer.cpp
@@ -0,0 +1,87 @@
+/*
+ * 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 "TelemetryServer.h"
+
+#include "CarTelemetryImpl.h"
+#include "RingBuffer.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 <inttypes.h> // for PRIu64 and friends
+
+#include <memory>
+#include <thread> // NOLINT(build/c++11)
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+using ::android::String16;
+using ::android::automotive::telemetry::CarTelemetryImpl;
+using ::android::automotive::telemetry::RingBuffer;
+
+constexpr const char kCarTelemetryServiceName[] =
+ "android.frameworks.automotive.telemetry.ICarTelemetry/default";
+constexpr const char kCarTelemetryInternalServiceName[] =
+ "android.automotive.telemetry.internal.ICarTelemetryInternal/default";
+
+// Total CarData content size limit in the RingBuffer. 2MB max memory for buffer is good for now.
+const int kMaxBufferSizeKilobytes = 2048;
+
+TelemetryServer::TelemetryServer() : mRingBuffer(kMaxBufferSizeKilobytes * 1024) {}
+
+void TelemetryServer::registerServices() {
+ android::sp<CarTelemetryImpl> telemetry = new CarTelemetryImpl(&mRingBuffer);
+ android::sp<CarTelemetryInternalImpl> telemetryInternal =
+ new CarTelemetryInternalImpl(&mRingBuffer);
+
+ // 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(FATAL) << "Unable to register " << kCarTelemetryServiceName << ", status=" << status;
+ }
+
+ LOG(VERBOSE) << "Registering " << kCarTelemetryInternalServiceName;
+ status =
+ android::defaultServiceManager()->addService(String16(kCarTelemetryInternalServiceName),
+ telemetryInternal);
+ if (status != android::OK) {
+ LOG(FATAL) << "Unable to register " << kCarTelemetryInternalServiceName
+ << ", status=" << status;
+ }
+}
+
+void TelemetryServer::startAndJoinThreadPool() {
+ android::ProcessState::self()->startThreadPool(); // Starts default 15 binder threads.
+ android::IPCThreadState::self()->joinThreadPool();
+}
+
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
diff --git a/cpp/telemetry/src/TelemetryServer.h b/cpp/telemetry/src/TelemetryServer.h
new file mode 100644
index 0000000000..0b400a11df
--- /dev/null
+++ b/cpp/telemetry/src/TelemetryServer.h
@@ -0,0 +1,48 @@
+/*
+ * 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_TELEMETRYSERVER_H_
+#define CPP_TELEMETRY_SRC_TELEMETRYSERVER_H_
+
+#include "CarTelemetryImpl.h"
+#include "CarTelemetryInternalImpl.h"
+
+#include <utils/Errors.h>
+
+namespace android {
+namespace automotive {
+namespace telemetry {
+
+class TelemetryServer {
+public:
+ TelemetryServer();
+
+ // Registers all the implemented AIDL services. Waits until `servicemanager` is available.
+ // Aborts the process if fails.
+ void registerServices();
+
+ // Blocks the thread.
+ void startAndJoinThreadPool();
+
+private:
+ RingBuffer mRingBuffer;
+};
+
+} // namespace telemetry
+} // namespace automotive
+} // namespace android
+
+#endif // CPP_TELEMETRY_SRC_TELEMETRYSERVER_H_
diff --git a/cpp/telemetry/src/main.cpp b/cpp/telemetry/src/main.cpp
index fcec0eeab9..1bd0dde710 100644
--- a/cpp/telemetry/src/main.cpp
+++ b/cpp/telemetry/src/main.cpp
@@ -14,52 +14,23 @@
* limitations under the License.
*/
-#include "CarTelemetryImpl.h"
-#include "RingBuffer.h"
+#include "TelemetryServer.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;
-using ::android::automotive::telemetry::RingBuffer;
-
-constexpr const char kCarTelemetryServiceName[] =
- "android.frameworks.automotive.telemetry.ICarTelemetry/default";
-// Total CarData content size limit in the RingBuffer. 2MB max memory for buffer is good for now.
-const int kMaxBufferSizeKilobytes = 2048;
+using ::android::automotive::telemetry::TelemetryServer;
// TODO(b/174608802): handle SIGQUIT/SIGTERM
int main(void) {
LOG(INFO) << "Starting cartelemetryd";
- RingBuffer buffer(kMaxBufferSizeKilobytes * 1024);
-
- android::sp<CarTelemetryImpl> telemetry = new CarTelemetryImpl(&buffer);
-
- // 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);
- }
+ TelemetryServer server;
- 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;
- }
+ // Register AIDL services. Aborts the server if fails.
+ server.registerServices();
LOG(VERBOSE) << "Service is created, joining the threadpool";
- android::ProcessState::self()->startThreadPool(); // Starts default 15 binder threads.
- android::IPCThreadState::self()->joinThreadPool();
+ server.startAndJoinThreadPool();
return 1; // never reaches
}