summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Kiryanov <rkir@google.com>2020-03-23 11:26:52 -0700
committerRoman Kiryanov <rkir@google.com>2020-03-24 11:51:19 -0700
commit23e3c29369f6a7068688b318ebbad4363460ff12 (patch)
tree2b38a10fb0cba45ba7ed0bd1413173ecf9c72b1b
parent42debcc1226b68c48cc0d1982c4b7c1e9af16adb (diff)
downloadplatform_hardware_interfaces-23e3c29369f6a7068688b318ebbad4363460ff12.tar.gz
platform_hardware_interfaces-23e3c29369f6a7068688b318ebbad4363460ff12.tar.bz2
platform_hardware_interfaces-23e3c29369f6a7068688b318ebbad4363460ff12.zip
Add default/android.hardware.dumpstate@1.1-service.example
Bug: 152067221 Test: VtsHalDumpstateV1_1TargetTest Signed-off-by: Roman Kiryanov <rkir@google.com> Change-Id: I7f4e50846e2dc4393563c602145afb5617b2d48f
-rw-r--r--dumpstate/1.1/default/Android.bp26
-rw-r--r--dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.rc8
-rw-r--r--dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.xml11
-rw-r--r--dumpstate/1.1/default/main.cpp129
4 files changed, 174 insertions, 0 deletions
diff --git a/dumpstate/1.1/default/Android.bp b/dumpstate/1.1/default/Android.bp
new file mode 100644
index 0000000000..bd920752ba
--- /dev/null
+++ b/dumpstate/1.1/default/Android.bp
@@ -0,0 +1,26 @@
+cc_binary {
+ name: "android.hardware.dumpstate@1.1-service.example",
+ vendor: true,
+ relative_install_path: "hw",
+ defaults: ["hidl_defaults"],
+ init_rc: [
+ "android.hardware.dumpstate@1.1-service.example.rc",
+ ],
+ vintf_fragments: [
+ "android.hardware.dumpstate@1.1-service.example.xml",
+ ],
+ srcs: ["main.cpp"],
+ shared_libs: [
+ "android.hardware.dumpstate@1.0",
+ "android.hardware.dumpstate@1.1",
+ "libbase",
+ "libcutils",
+ "libdumpstateutil",
+ "libhidlbase",
+ "liblog",
+ "libutils",
+ ],
+ cflags: [
+ "-DLOG_TAG=\"android.hardware.dumpstate@1.1-service.example\"",
+ ],
+}
diff --git a/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.rc b/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.rc
new file mode 100644
index 0000000000..3a1e06a5dc
--- /dev/null
+++ b/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.rc
@@ -0,0 +1,8 @@
+service dumpstate-1-1 /vendor/bin/hw/android.hardware.dumpstate@1.1-service.example
+ class hal
+ user nobody
+ group nobody
+ interface android.hardware.dumpstate@1.0::IDumpstateDevice default
+ interface android.hardware.dumpstate@1.1::IDumpstateDevice default
+ oneshot
+ disabled
diff --git a/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.xml b/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.xml
new file mode 100644
index 0000000000..775e8c8416
--- /dev/null
+++ b/dumpstate/1.1/default/android.hardware.dumpstate@1.1-service.example.xml
@@ -0,0 +1,11 @@
+<manifest version="1.0" type="device">
+ <hal format="hidl">
+ <name>android.hardware.dumpstate</name>
+ <transport>hwbinder</transport>
+ <version>1.1</version>
+ <interface>
+ <name>IDumpstateDevice</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
+</manifest>
diff --git a/dumpstate/1.1/default/main.cpp b/dumpstate/1.1/default/main.cpp
new file mode 100644
index 0000000000..4510f63647
--- /dev/null
+++ b/dumpstate/1.1/default/main.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020 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 <android-base/properties.h>
+#include <android/hardware/dumpstate/1.1/IDumpstateDevice.h>
+#include <android/hardware/dumpstate/1.1/types.h>
+#include <hidl/HidlLazyUtils.h>
+#include <hidl/HidlSupport.h>
+#include <hidl/HidlTransportSupport.h>
+#include <log/log.h>
+
+#include "DumpstateUtil.h"
+
+namespace {
+using ::android::hardware::hidl_handle;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+
+using ::android::hardware::dumpstate::V1_1::DumpstateMode;
+using ::android::hardware::dumpstate::V1_1::DumpstateStatus;
+using ::android::hardware::dumpstate::V1_1::IDumpstateDevice;
+
+using ::android::os::dumpstate::DumpFileToFd;
+
+const char kVerboseLoggingProperty[] = "persist.dumpstate.verbose_logging.enabled";
+
+struct DumpstateDevice : public IDumpstateDevice {
+ // 1.1
+ Return<DumpstateStatus> dumpstateBoard_1_1(const hidl_handle& handle, const DumpstateMode mode,
+ uint64_t /*timeoutMillis*/) override {
+ if (handle == nullptr || handle->numFds < 1) {
+ ALOGE("no FDs\n");
+ return DumpstateStatus::ILLEGAL_ARGUMENT;
+ }
+
+ int fd = handle->data[0];
+ if (fd < 0) {
+ ALOGE("invalid FD: %d\n", fd);
+ return DumpstateStatus::ILLEGAL_ARGUMENT;
+ }
+
+ switch (mode) {
+ case DumpstateMode::FULL:
+ return dumpstateBoardImpl(fd, true);
+
+ case DumpstateMode::DEFAULT:
+ return dumpstateBoardImpl(fd, false);
+
+ case DumpstateMode::INTERACTIVE:
+ case DumpstateMode::REMOTE:
+ case DumpstateMode::WEAR:
+ case DumpstateMode::CONNECTIVITY:
+ case DumpstateMode::WIFI:
+ case DumpstateMode::PROTO:
+ ALOGE("The requested mode is not supported: %s\n", toString(mode).c_str());
+ return DumpstateStatus::UNSUPPORTED_MODE;
+
+ default:
+ ALOGE("The requested mode is invalid: %s\n", toString(mode).c_str());
+ return DumpstateStatus::ILLEGAL_ARGUMENT;
+ }
+ }
+
+ Return<void> setVerboseLoggingEnabled(bool enable) override {
+ ::android::base::SetProperty(kVerboseLoggingProperty, enable ? "true" : "false");
+ return Void();
+ }
+
+ Return<bool> getVerboseLoggingEnabled() override { return getVerboseLoggingEnabledImpl(); }
+
+ // 1.0
+ Return<void> dumpstateBoard(const hidl_handle& h) override {
+ dumpstateBoard_1_1(h, DumpstateMode::DEFAULT, 0);
+ return Void();
+ }
+
+ DumpstateStatus dumpstateBoardImpl(const int fd, const bool full) {
+ ALOGD("DumpstateDevice::dumpstateBoard() FD: %d\n", fd);
+ ALOGI("Dumpstate HIDL not provided by device\n");
+
+ dprintf(fd, "verbose logging: %s\n",
+ getVerboseLoggingEnabledImpl() ? "enabled" : "disabled");
+
+ dprintf(fd, "[%s] %s\n", (full ? "full" : "default"), "Hello, world!");
+
+ // Shows an example on how to use the libdumpstateutil API.
+ DumpFileToFd(fd, "cmdline", "/proc/self/cmdline");
+
+ return DumpstateStatus::OK;
+ }
+
+ static bool getVerboseLoggingEnabledImpl() {
+ return ::android::base::GetBoolProperty(kVerboseLoggingProperty, false);
+ }
+};
+} // namespace
+
+int main(int, char**) {
+ using ::android::sp;
+ using ::android::hardware::configureRpcThreadpool;
+ using ::android::hardware::joinRpcThreadpool;
+ using ::android::hardware::LazyServiceRegistrar;
+
+ configureRpcThreadpool(1, true);
+
+ auto dumpstate = sp<DumpstateDevice>::make();
+ auto serviceRegistrar = LazyServiceRegistrar::getInstance();
+
+ if (serviceRegistrar.registerService(dumpstate) != ::android::OK) {
+ ALOGE("Could not register service.");
+ return 1;
+ }
+
+ joinRpcThreadpool();
+ return 0;
+}