summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux4 <tim@linux4.de>2020-04-20 17:41:47 +0200
committerJan Altensen <info@stricted.net>2020-05-01 18:10:01 +0200
commit9426065ceb6df54d81e764d76599bf4a4efc7c35 (patch)
treefa25f1fcbd73aa420fb19951cfc6fe26d348388c
parentf6a8f6e6ecfe1939871082adcfcbdac64248bc03 (diff)
downloadandroid_hardware_samsung-9426065ceb6df54d81e764d76599bf4a4efc7c35.tar.gz
android_hardware_samsung-9426065ceb6df54d81e764d76599bf4a4efc7c35.tar.bz2
android_hardware_samsung-9426065ceb6df54d81e764d76599bf4a4efc7c35.zip
samsung: hidl: add powershare
Change-Id: I7ebfc84674c3a29c7cca53861d71d3e9b94947fd
-rw-r--r--hidl/powershare/Android.mk43
-rw-r--r--hidl/powershare/PowerShare.cpp98
-rw-r--r--hidl/powershare/PowerShare.h54
-rw-r--r--hidl/powershare/include/samsung_powershare.h23
-rw-r--r--hidl/powershare/service.cpp50
-rw-r--r--hidl/powershare/vendor.lineage.powershare@1.0-service.samsung.rc4
6 files changed, 272 insertions, 0 deletions
diff --git a/hidl/powershare/Android.mk b/hidl/powershare/Android.mk
new file mode 100644
index 0000000..1bebb3c
--- /dev/null
+++ b/hidl/powershare/Android.mk
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2020 The LineageOS 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ PowerShare.cpp \
+ service.cpp
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/include \
+
+LOCAL_SHARED_LIBRARIES := \
+ libbase \
+ libbinder \
+ libhidlbase \
+ libhidltransport \
+ libutils \
+ vendor.lineage.powershare@1.0
+
+LOCAL_MODULE := vendor.lineage.powershare@1.0-service.samsung
+LOCAL_INIT_RC := vendor.lineage.powershare@1.0-service.samsung.rc
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_OWNER := samsung
+LOCAL_VENDOR_MODULE := true
+
+include $(BUILD_EXECUTABLE)
diff --git a/hidl/powershare/PowerShare.cpp b/hidl/powershare/PowerShare.cpp
new file mode 100644
index 0000000..6332e5f
--- /dev/null
+++ b/hidl/powershare/PowerShare.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2020 The LineageOS 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 "powershare@1.0-service.samsung"
+
+#include "PowerShare.h"
+#include <android-base/logging.h>
+#include <fstream>
+#include <iostream>
+#include "samsung_powershare.h"
+
+namespace vendor {
+namespace lineage {
+namespace powershare {
+namespace V1_0 {
+namespace implementation {
+
+/*
+ * Write value to path and close file.
+ */
+template <typename T>
+static void set(const std::string& path, const T& value) {
+ std::ofstream file(path);
+
+ if (!file) {
+ PLOG(ERROR) << "Failed to open: " << path;
+ return;
+ }
+
+ LOG(DEBUG) << "write: " << path << " value: " << value;
+
+ file << value << std::endl;
+
+ if (!file) {
+ PLOG(ERROR) << "Failed to write: " << path << " value: " << value;
+ }
+}
+
+template <typename T>
+static T get(const std::string& path, const T& def) {
+ std::ifstream file(path);
+
+ if (!file) {
+ PLOG(ERROR) << "Failed to open: " << path;
+ return def;
+ }
+
+ T result;
+
+ file >> result;
+
+ if (file.fail()) {
+ PLOG(ERROR) << "Failed to read: " << path;
+ return def;
+ } else {
+ LOG(DEBUG) << "read: " << path << " value: " << result;
+ return result;
+ }
+}
+
+Return<bool> PowerShare::isEnabled() {
+ return get(POWERSHARE_PATH, 0) == 1;
+}
+
+Return<bool> PowerShare::setEnabled(bool enable) {
+ set(POWERSHARE_PATH, enable ? 1 : 0);
+
+ return isEnabled();
+}
+
+Return<uint32_t> PowerShare::getMinBattery() {
+ return get(POWERSHARE_STOP_CAPACITY_PATH, 0);
+}
+
+Return<uint32_t> PowerShare::setMinBattery(uint32_t minBattery) {
+ set(POWERSHARE_STOP_CAPACITY_PATH, minBattery);
+
+ return getMinBattery();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace powershare
+} // namespace lineage
+} // namespace vendor
diff --git a/hidl/powershare/PowerShare.h b/hidl/powershare/PowerShare.h
new file mode 100644
index 0000000..ebb2e95
--- /dev/null
+++ b/hidl/powershare/PowerShare.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 The LineageOS 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 VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
+#define VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
+
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <vendor/lineage/powershare/1.0/IPowerShare.h>
+
+namespace vendor {
+namespace lineage {
+namespace powershare {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::sp;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+
+using ::vendor::lineage::powershare::V1_0::IPowerShare;
+
+
+struct PowerShare : public IPowerShare {
+ Return<bool> isEnabled() override;
+ Return<bool> setEnabled(bool enable) override;
+ Return<uint32_t> getMinBattery() override;
+ Return<uint32_t> setMinBattery(uint32_t minBattery) override;
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace powershare
+} // namespace lineage
+} // namespace vendor
+
+#endif // VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
diff --git a/hidl/powershare/include/samsung_powershare.h b/hidl/powershare/include/samsung_powershare.h
new file mode 100644
index 0000000..8e7c88b
--- /dev/null
+++ b/hidl/powershare/include/samsung_powershare.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2020 The LineageOS 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 SAMSUNG_POWERSHARE_H
+#define SAMSUNG_POWERSHARE_H
+
+#define POWERSHARE_PATH "/sys/class/power_supply/battery/wc_tx_en"
+#define POWERSHARE_STOP_CAPACITY_PATH "/sys/class/power_supply/battery/wc_tx_stop_capacity"
+
+#endif // SAMSUNG_POWERSHARE_H
diff --git a/hidl/powershare/service.cpp b/hidl/powershare/service.cpp
new file mode 100644
index 0000000..b3d5d3d
--- /dev/null
+++ b/hidl/powershare/service.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 The LineageOS 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 "powershare@1.0-service.samsung"
+
+#include <android-base/logging.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "PowerShare.h"
+
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+
+using vendor::lineage::powershare::V1_0::IPowerShare;
+using vendor::lineage::powershare::V1_0::implementation::PowerShare;
+
+using android::OK;
+using android::status_t;
+
+int main() {
+ android::sp<PowerShare> service = new PowerShare();
+
+ configureRpcThreadpool(1, true);
+
+ status_t status = service->registerAsService();
+ if (status != OK) {
+ LOG(ERROR) << "Cannot register PowerShare HAL service.";
+ return 1;
+ }
+
+ LOG(INFO) << "PowerShare HAL service ready.";
+
+ joinRpcThreadpool();
+
+ LOG(ERROR) << "PowerShare HAL service failed to join thread pool.";
+ return 1;
+}
diff --git a/hidl/powershare/vendor.lineage.powershare@1.0-service.samsung.rc b/hidl/powershare/vendor.lineage.powershare@1.0-service.samsung.rc
new file mode 100644
index 0000000..de95798
--- /dev/null
+++ b/hidl/powershare/vendor.lineage.powershare@1.0-service.samsung.rc
@@ -0,0 +1,4 @@
+service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.samsung
+ class hal
+ user system
+ group system