Create Power Stats AIDL interface
Bug: 162472196
Test: m
Change-Id: I225135c24cc713da085ff7238c1b0695e8ab93ed
diff --git a/powerstats/aidl/default/Android.bp b/powerstats/aidl/default/Android.bp
new file mode 100644
index 0000000..caecd88
--- /dev/null
+++ b/powerstats/aidl/default/Android.bp
@@ -0,0 +1,30 @@
+// 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.
+
+cc_binary {
+ name: "android.hardware.powerstats-service.example",
+ relative_install_path: "hw",
+ init_rc: ["powerstats-default.rc"],
+ vintf_fragments: ["powerstats-default.xml"],
+ vendor: true,
+ shared_libs: [
+ "libbase",
+ "libbinder_ndk",
+ "android.hardware.powerstats-ndk_platform",
+ ],
+ srcs: [
+ "main.cpp",
+ "PowerStats.cpp",
+ ],
+}
diff --git a/powerstats/aidl/default/PowerStats.cpp b/powerstats/aidl/default/PowerStats.cpp
new file mode 100644
index 0000000..50a829e
--- /dev/null
+++ b/powerstats/aidl/default/PowerStats.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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 "PowerStats.h"
+
+#include <android-base/logging.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace powerstats {
+
+ndk::ScopedAStatus PowerStats::getEnergyData(const std::vector<int32_t>& in_railIndices,
+ std::vector<EnergyData>* _aidl_return) {
+ (void)in_railIndices;
+ (void)_aidl_return;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus PowerStats::getPowerEntityInfo(std::vector<PowerEntityInfo>* _aidl_return) {
+ (void)_aidl_return;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus PowerStats::getPowerEntityStateInfo(
+ const std::vector<int32_t>& in_powerEntityIds,
+ std::vector<PowerEntityStateSpace>* _aidl_return) {
+ (void)in_powerEntityIds;
+ (void)_aidl_return;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus PowerStats::getPowerEntityStateResidencyData(
+ const std::vector<int32_t>& in_powerEntityIds,
+ std::vector<PowerEntityStateResidencyResult>* _aidl_return) {
+ (void)in_powerEntityIds;
+ (void)_aidl_return;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus PowerStats::getRailInfo(std::vector<RailInfo>* _aidl_return) {
+ (void)_aidl_return;
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace powerstats
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/powerstats/aidl/default/PowerStats.h b/powerstats/aidl/default/PowerStats.h
new file mode 100644
index 0000000..392d1e6
--- /dev/null
+++ b/powerstats/aidl/default/PowerStats.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/powerstats/BnPowerStats.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace powerstats {
+
+class PowerStats : public BnPowerStats {
+ public:
+ PowerStats() = default;
+ ndk::ScopedAStatus getEnergyData(const std::vector<int32_t>& in_railIndices,
+ std::vector<EnergyData>* _aidl_return) override;
+ ndk::ScopedAStatus getPowerEntityInfo(std::vector<PowerEntityInfo>* _aidl_return) override;
+ ndk::ScopedAStatus getPowerEntityStateInfo(
+ const std::vector<int32_t>& in_powerEntityIds,
+ std::vector<PowerEntityStateSpace>* _aidl_return) override;
+ ndk::ScopedAStatus getPowerEntityStateResidencyData(
+ const std::vector<int32_t>& in_powerEntityIds,
+ std::vector<PowerEntityStateResidencyResult>* _aidl_return) override;
+ ndk::ScopedAStatus getRailInfo(std::vector<RailInfo>* _aidl_return) override;
+};
+
+} // namespace powerstats
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/powerstats/aidl/default/main.cpp b/powerstats/aidl/default/main.cpp
new file mode 100644
index 0000000..1496805
--- /dev/null
+++ b/powerstats/aidl/default/main.cpp
@@ -0,0 +1,35 @@
+/*
+ * 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 "PowerStats.h"
+
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::powerstats::PowerStats;
+
+int main() {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+ std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
+
+ const std::string instance = std::string() + PowerStats::descriptor + "/default";
+ binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
+ CHECK(status == STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ return EXIT_FAILURE; // should not reach
+}
diff --git a/powerstats/aidl/default/powerstats-default.rc b/powerstats/aidl/default/powerstats-default.rc
new file mode 100644
index 0000000..9b04be3
--- /dev/null
+++ b/powerstats/aidl/default/powerstats-default.rc
@@ -0,0 +1,4 @@
+service vendor.powerstats-default /vendor/bin/hw/android.hardware.powerstats-service.example
+ class hal
+ user system
+ group system
diff --git a/powerstats/aidl/default/powerstats-default.xml b/powerstats/aidl/default/powerstats-default.xml
new file mode 100644
index 0000000..e07513d
--- /dev/null
+++ b/powerstats/aidl/default/powerstats-default.xml
@@ -0,0 +1,6 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.powerstats</name>
+ <fqname>IPowerStats/default</fqname>
+ </hal>
+</manifest>