From c05f531d98ee819d3efb4e6510209641e9e6a69b Mon Sep 17 00:00:00 2001 From: Luofan Chen Date: Wed, 23 Nov 2022 14:54:12 +0800 Subject: [PATCH] hardware: Implement our own charging HAL This commit is a charging control HAL for Sony devices that controls charging by making use of interfaces exposed by Sony's kernel. This HAL provides higher level interfaces for disabling/enabling charging by writing to specific kernel interface. Furthermore, it references pixel's powerstat implementation, uses uevent to monitor power_supply uevents, and provides an interface to allow users to set custom charging limit. Change-Id: Iea037e400326352443b9810a98401cfa15fa6ac5 --- interfaces/sony/Android.bp | 4 + interfaces/sony/Charger/.clang-format | 1 + interfaces/sony/Charger/Android.bp | 26 +++ interfaces/sony/Charger/Charger.cpp | 166 ++++++++++++++++++ interfaces/sony/Charger/Charger.h | 39 ++++ interfaces/sony/Charger/UeventListener.cpp | 112 ++++++++++++ interfaces/sony/Charger/UeventListener.h | 50 ++++++ interfaces/sony/Charger/aidl/Android.bp | 27 +++ .../aidl/aidl_api/vendor.sony.charger/1/.hash | 1 + .../1/vendor/sony/charger/ICharger.aidl | 16 ++ .../current/vendor/sony/charger/ICharger.aidl | 16 ++ .../aidl/vendor/sony/charger/ICharger.aidl | 16 ++ interfaces/sony/Charger/service.cpp | 37 ++++ .../Charger/vendor.sony.charger-service.rc | 4 + .../Charger/vendor.sony.charger-service.xml | 10 ++ sepolicy/qti/SEPolicy.mk | 6 + sepolicy/qti/vendor/attributes | 4 + sepolicy/qti/vendor/file_contexts | 2 + sepolicy/qti/vendor/hal_sony_charger.te | 6 + .../qti/vendor/hal_sony_charger_default.te | 16 ++ sepolicy/qti/vendor/service.te | 1 + sepolicy/qti/vendor/service_contexts | 1 + sepolicy/qti/vendor/system_app.te | 1 + 23 files changed, 562 insertions(+) create mode 100644 interfaces/sony/Android.bp create mode 120000 interfaces/sony/Charger/.clang-format create mode 100644 interfaces/sony/Charger/Android.bp create mode 100644 interfaces/sony/Charger/Charger.cpp create mode 100644 interfaces/sony/Charger/Charger.h create mode 100644 interfaces/sony/Charger/UeventListener.cpp create mode 100644 interfaces/sony/Charger/UeventListener.h create mode 100644 interfaces/sony/Charger/aidl/Android.bp create mode 100644 interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/.hash create mode 100644 interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/vendor/sony/charger/ICharger.aidl create mode 100644 interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/current/vendor/sony/charger/ICharger.aidl create mode 100644 interfaces/sony/Charger/aidl/vendor/sony/charger/ICharger.aidl create mode 100644 interfaces/sony/Charger/service.cpp create mode 100644 interfaces/sony/Charger/vendor.sony.charger-service.rc create mode 100644 interfaces/sony/Charger/vendor.sony.charger-service.xml create mode 100644 sepolicy/qti/SEPolicy.mk create mode 100644 sepolicy/qti/vendor/attributes create mode 100644 sepolicy/qti/vendor/file_contexts create mode 100644 sepolicy/qti/vendor/hal_sony_charger.te create mode 100644 sepolicy/qti/vendor/hal_sony_charger_default.te create mode 100644 sepolicy/qti/vendor/service.te create mode 100644 sepolicy/qti/vendor/service_contexts create mode 100644 sepolicy/qti/vendor/system_app.te diff --git a/interfaces/sony/Android.bp b/interfaces/sony/Android.bp new file mode 100644 index 0000000..30b978a --- /dev/null +++ b/interfaces/sony/Android.bp @@ -0,0 +1,4 @@ +hidl_package_root { + name: "vendor.sony", + path: "hardware/sony/interfaces/sony", +} diff --git a/interfaces/sony/Charger/.clang-format b/interfaces/sony/Charger/.clang-format new file mode 120000 index 0000000..f1b4f69 --- /dev/null +++ b/interfaces/sony/Charger/.clang-format @@ -0,0 +1 @@ +../../../../../build/soong/scripts/system-clang-format \ No newline at end of file diff --git a/interfaces/sony/Charger/Android.bp b/interfaces/sony/Charger/Android.bp new file mode 100644 index 0000000..bbb437e --- /dev/null +++ b/interfaces/sony/Charger/Android.bp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +cc_binary { + name: "vendor.sony.charger-service", + relative_install_path: "hw", + init_rc: ["vendor.sony.charger-service.rc"], + vintf_fragments: ["vendor.sony.charger-service.xml"], + vendor: true, + shared_libs: [ + "libbase", + "libcutils", + "liblog", + "libutils", + "libbinder_ndk", + "vendor.sony.charger-V1-ndk", + ], + srcs: [ + "service.cpp", + "Charger.cpp", + "UeventListener.cpp", + ] +} diff --git a/interfaces/sony/Charger/Charger.cpp b/interfaces/sony/Charger/Charger.cpp new file mode 100644 index 0000000..632e244 --- /dev/null +++ b/interfaces/sony/Charger/Charger.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "Charger.h" + +#include +#include +#include +#include +#include +#include + +namespace aidl { +namespace vendor { +namespace sony { +namespace charger { + +#define LOG_TAG "vendor.sony.charger" + +enum SUPPORTED_BOARD { + kona = 0, + lahaina = 1, +}; + +static constexpr const char* kChgActivationPath[] = { + "/sys/class/power_supply/battery_ext/smart_charging_activation", + "/sys/class/battchg_ext/smart_charging_activation", +}; + +static constexpr const char* kChgInterruptionPath[] = { + "/sys/class/power_supply/battery_ext/smart_charging_interruption", + "/sys/class/battchg_ext/smart_charging_interruption", +}; + +static constexpr const char* kBatCapacityPath[] = { + "/sys/class/power_supply/battery/capacity", + "/sys/class/power_supply/battery/capacity", +}; + +Charger::Charger() { + LOG(INFO) << "Charger HAL Starting..."; + char board_name[PROPERTY_VALUE_MAX]; + + property_get("ro.product.board", board_name, "null"); + + if (strncmp(board_name, "kona", strlen("kona")) == 0) { + chargerBoard = kona; + } else if (strncmp(board_name, "lahaina", strlen("lahaina")) == 0) { + chargerBoard = lahaina; + } else { + LOG(ERROR) << "Failed to get board number, default to kona"; + chargerBoard = kona; + } + chgLimit = 100; + chgStopReason = 0; +} + +bool Charger::updateChargingStatus() { + // If chgStopReason is not 0, we need to stop charging + bool enable = chgStopReason == 0; + + return setChargingEnableInternal(enable); +} + +bool Charger::setChargingEnableInternal(bool enabled) { + LOG(INFO) << (enabled ? "Enable" : "Disable") << " charging"; + std::fstream activationFile(kChgActivationPath[chargerBoard]); + std::fstream interruptionFile(kChgInterruptionPath[chargerBoard]); + int activationResult = -1; + int interruptionResult = -1; + + if (!activationFile.is_open() || !interruptionFile.is_open()) goto error; + + activationFile >> activationResult; + interruptionFile >> interruptionResult; + + if (activationFile.fail() || interruptionFile.fail()) goto error; + + if (activationResult == 0) { + activationFile << "1"; + if (activationFile.fail()) goto error; + } + + if (interruptionResult == enabled) { + interruptionFile << (enabled ? "0" : "1"); + if (interruptionFile.fail()) goto error; + } + + interruptionFile.close(); + activationFile.close(); + + return true; + +error: + LOG(ERROR) << "Failed to read or write charging status: " << strerror(errno); + return false; +} + +ndk::ScopedAStatus Charger::isChargingEnabled(bool* _aidl_return) { + *_aidl_return = chgStopReason & CHG_STOP_REASON_FORCE; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Charger::setChargingEnable(bool enabled) { + if (enabled) + chgStopReason &= ~CHG_STOP_REASON_FORCE; // clear bit, enable charging + else + chgStopReason |= CHG_STOP_REASON_FORCE; // Set bit, disable charging + + if (updateChargingStatus()) + return ndk::ScopedAStatus::ok(); + else + return ndk::ScopedAStatus::fromExceptionCode(EX_SERVICE_SPECIFIC); +} + +ndk::ScopedAStatus Charger::setChargingLimit(int32_t limit) { + LOG(INFO) << "Setting charging limit to " << limit; + if (limit > 100 || limit < 50) { + LOG(ERROR) << "The charging limit " << limit << " is not supported!"; + LOG(ERROR) << " Please select between 50 and 100"; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + + chgLimit = limit; + + return checkBatCapacityAndApplyLimit(); +} + +ndk::ScopedAStatus Charger::checkBatCapacityAndApplyLimit() { + std::ifstream batCapFile(kBatCapacityPath[chargerBoard]); + int batCapNow = -1; + + batCapFile >> batCapNow; + LOG(INFO) << "Capacity: " << batCapNow << ". Limit: " << chgLimit; + + if (chgLimit == 100) { + // We don't limit battery if the limit is 100 + chgStopReason &= ~CHG_STOP_REASON_LIMIT; + } else { + if (!batCapFile.is_open()) goto error; + + if (batCapNow >= chgLimit) { + // Set limit + chgStopReason |= CHG_STOP_REASON_LIMIT; + } else { + chgStopReason &= ~CHG_STOP_REASON_LIMIT; + } + } + + if (updateChargingStatus()) + return ndk::ScopedAStatus::ok(); + else + return ndk::ScopedAStatus::fromExceptionCode(EX_SERVICE_SPECIFIC); + +error: + LOG(ERROR) << "Failed to read charging status: " << strerror(errno); + return ndk::ScopedAStatus::fromExceptionCode(EX_SERVICE_SPECIFIC); +} + +} // namespace charger +} // namespace sony +} // namespace vendor +} // namespace aidl diff --git a/interfaces/sony/Charger/Charger.h b/interfaces/sony/Charger/Charger.h new file mode 100644 index 0000000..897c9ea --- /dev/null +++ b/interfaces/sony/Charger/Charger.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include "android/binder_status.h" + +namespace aidl { +namespace vendor { +namespace sony { +namespace charger { + +#define CHG_STOP_REASON_FORCE (1 << 0) +#define CHG_STOP_REASON_LIMIT (1 << 1) + +struct Charger : public BnCharger { + Charger(); + ndk::ScopedAStatus setChargingEnable(bool enabled) override; + ndk::ScopedAStatus isChargingEnabled(bool* _aidl_return) override; + ndk::ScopedAStatus setChargingLimit(int32_t limit) override; + ndk::ScopedAStatus checkBatCapacityAndApplyLimit() override; + + private: + bool updateChargingStatus(); + bool setChargingEnableInternal(bool enabled); + int chargerBoard; + int chgLimit; + int chgStopReason; +}; + +} // namespace charger +} // namespace sony +} // namespace vendor +} // namespace aidl diff --git a/interfaces/sony/Charger/UeventListener.cpp b/interfaces/sony/Charger/UeventListener.cpp new file mode 100644 index 0000000..5a7a255 --- /dev/null +++ b/interfaces/sony/Charger/UeventListener.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2022 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 "sonycharger-uevent" + +#include "UeventListener.h" +#include +#include +#include + +namespace aidl { +namespace vendor { +namespace sony { +namespace charger { + +UeventListener::UeventListener() : uevent_fd_(-1) {} + +std::shared_ptr getChargerService() { + const std::string instance = std::string() + ICharger::descriptor + "/default"; + static bool isChargerDeclared = false; + if (!isChargerDeclared) { + // It is good to cache the result - it would not be changed + isChargerDeclared = AServiceManager_isDeclared(instance.c_str()); + if (!isChargerDeclared) { + LOG(ERROR) << "Charger service is not registered"; + return nullptr; + } + } + + return ICharger::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService(instance.c_str()))); +} + +void UeventListener::handlePowerSupplyChange() { + LOG(INFO) << "handlePowerSupplyChange HERE"; + const std::shared_ptr charger_client = getChargerService(); + charger_client->checkBatCapacityAndApplyLimit(); +} + +#define UEVENT_MSG_LEN 2048 +bool UeventListener::ProcessUevent() { + char msg[UEVENT_MSG_LEN + 2]; + char* cp; + int n; + + if (uevent_fd_ < 0) { + uevent_fd_ = uevent_open_socket(64 * 1024, true); + if (uevent_fd_ < 0) { + LOG(ERROR) << "uevent_init: uevent_open_socket failed\n"; + return false; + } + } + + n = uevent_kernel_multicast_recv(uevent_fd_, msg, UEVENT_MSG_LEN); + if (n <= 0 || n >= UEVENT_MSG_LEN) return false; + + // Ensure double-null termination of msg + msg[n] = '\0'; + msg[n + 1] = '\0'; + + /** + * msg is a sequence of null-terminated strings. + * Iterate through and record positions of string/value pairs of interest. + * Double null indicates end of the message. (enforced above) + */ + cp = msg; + while (*cp) { + if (!strncmp(cp, "SUBSYSTEM=power_supply", strlen("SUBSYSTEM=power_supply"))) { + handlePowerSupplyChange(); + break; + } + + while (*cp++) + ; + } + + return true; +}; + +void UeventListener::ListenForever() { + constexpr int kMaxConsecutiveErrors = 10; + int consecutive_errors = 0; + + while (1) { + if (ProcessUevent()) { + consecutive_errors = 0; + } else { + if (++consecutive_errors == kMaxConsecutiveErrors) { + LOG(ERROR) << "Too many ProcessUevent errors; exiting UeventListener"; + return; + } + } + } +} + +} // namespace charger +} // namespace sony +} // namespace vendor +} // namespace aidl diff --git a/interfaces/sony/Charger/UeventListener.h b/interfaces/sony/Charger/UeventListener.h new file mode 100644 index 0000000..916a5ab --- /dev/null +++ b/interfaces/sony/Charger/UeventListener.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2022 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 HARDWARE_SONY_CHARGER_UEVENTLISTENER_H +#define HARDWARE_SONY_CHARGER_UEVENTLISTENER_H + +#include +#include "Charger.h" + +namespace aidl { +namespace vendor { +namespace sony { +namespace charger { + +/** + * A class to listen for uevents and report reliability events to + * the Sony Charger HAL. + * Runs in a background thread if created with ListenForeverInNewThread(). + * Alternatively, process one message at a time with ProcessUevent(). + */ +class UeventListener { + public: + UeventListener(); + bool ProcessUevent(); // Process a single Uevent + void ListenForever(); // Process Uevents forever + void handlePowerSupplyChange(); + + private: + int uevent_fd_; +}; +} // namespace charger +} // namespace sony +} // namespace vendor +} // namespace aidl + +#endif // HARDWARE_SONY_CHARGER_UEVENTLISTENER_H diff --git a/interfaces/sony/Charger/aidl/Android.bp b/interfaces/sony/Charger/aidl/Android.bp new file mode 100644 index 0000000..0dd6eb9 --- /dev/null +++ b/interfaces/sony/Charger/aidl/Android.bp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +aidl_interface { + name: "vendor.sony.charger", + vendor_available: true, + srcs: ["vendor/sony/charger/*.aidl"], + stability: "vintf", + + backend: { + cpp: { + enabled: false, + }, + java: { + platform_apis: true, + }, + }, + versions_with_info: [ + { + version: "1", + imports: [], + }, + ], +} diff --git a/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/.hash b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/.hash new file mode 100644 index 0000000..159bb05 --- /dev/null +++ b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/.hash @@ -0,0 +1 @@ +4cc0a23fecf1050a9fdda64e8dc71516775c753c diff --git a/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/vendor/sony/charger/ICharger.aidl b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/vendor/sony/charger/ICharger.aidl new file mode 100644 index 0000000..8f2d1b7 --- /dev/null +++ b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/1/vendor/sony/charger/ICharger.aidl @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package vendor.sony.charger; + +@VintfStability +interface ICharger +{ + void setChargingEnable(in boolean enabled); + boolean isChargingEnabled(); + void setChargingLimit(in int limit); + void checkBatCapacityAndApplyLimit(); +} diff --git a/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/current/vendor/sony/charger/ICharger.aidl b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/current/vendor/sony/charger/ICharger.aidl new file mode 100644 index 0000000..8f2d1b7 --- /dev/null +++ b/interfaces/sony/Charger/aidl/aidl_api/vendor.sony.charger/current/vendor/sony/charger/ICharger.aidl @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package vendor.sony.charger; + +@VintfStability +interface ICharger +{ + void setChargingEnable(in boolean enabled); + boolean isChargingEnabled(); + void setChargingLimit(in int limit); + void checkBatCapacityAndApplyLimit(); +} diff --git a/interfaces/sony/Charger/aidl/vendor/sony/charger/ICharger.aidl b/interfaces/sony/Charger/aidl/vendor/sony/charger/ICharger.aidl new file mode 100644 index 0000000..8f2d1b7 --- /dev/null +++ b/interfaces/sony/Charger/aidl/vendor/sony/charger/ICharger.aidl @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package vendor.sony.charger; + +@VintfStability +interface ICharger +{ + void setChargingEnable(in boolean enabled); + boolean isChargingEnabled(); + void setChargingLimit(in int limit); + void checkBatCapacityAndApplyLimit(); +} diff --git a/interfaces/sony/Charger/service.cpp b/interfaces/sony/Charger/service.cpp new file mode 100644 index 0000000..e4b4738 --- /dev/null +++ b/interfaces/sony/Charger/service.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "Charger.h" +#include "UeventListener.h" + +#include +#include +#include +#include + +using ::aidl::vendor::sony::charger::Charger; +using ::aidl::vendor::sony::charger::UeventListener; + +#define LOG_TAG "vendor.sony.charger.service" + +int main() { + LOG(INFO) << "Sony Charger HAL Starting ..."; + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr chg = ndk::SharedRefBase::make(); + + const std::string instance = std::string() + Charger::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(chg->asBinder().get(), instance.c_str()); + CHECK_EQ(status, STATUS_OK); + + LOG(INFO) << "Uevent listener starting ..."; + UeventListener ueventListener; + std::thread listenThread(&UeventListener::ListenForever, &ueventListener); + listenThread.detach(); + LOG(INFO) << "Uevent listener thread start done!"; + + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach +} diff --git a/interfaces/sony/Charger/vendor.sony.charger-service.rc b/interfaces/sony/Charger/vendor.sony.charger-service.rc new file mode 100644 index 0000000..40d8575 --- /dev/null +++ b/interfaces/sony/Charger/vendor.sony.charger-service.rc @@ -0,0 +1,4 @@ +service vendor.sony_charger /vendor/bin/hw/vendor.sony.charger-service + class hal + user root + group root diff --git a/interfaces/sony/Charger/vendor.sony.charger-service.xml b/interfaces/sony/Charger/vendor.sony.charger-service.xml new file mode 100644 index 0000000..52875d3 --- /dev/null +++ b/interfaces/sony/Charger/vendor.sony.charger-service.xml @@ -0,0 +1,10 @@ + + + vendor.sony.charger + 1 + + ICharger + default + + + diff --git a/sepolicy/qti/SEPolicy.mk b/sepolicy/qti/SEPolicy.mk new file mode 100644 index 0000000..1fec722 --- /dev/null +++ b/sepolicy/qti/SEPolicy.mk @@ -0,0 +1,6 @@ +# +# Copyright (C) 2022 The LineageOS Project +# +# SPDX-License-Identifier: Apache-2.0 +# +BOARD_VENDOR_SEPOLICY_DIRS += hardware/sony/sepolicy/qti/vendor diff --git a/sepolicy/qti/vendor/attributes b/sepolicy/qti/vendor/attributes new file mode 100644 index 0000000..9cc5d30 --- /dev/null +++ b/sepolicy/qti/vendor/attributes @@ -0,0 +1,4 @@ +# HALs +attribute hal_sony_charger; +attribute hal_sony_charger_client; +attribute hal_sony_charger_server; diff --git a/sepolicy/qti/vendor/file_contexts b/sepolicy/qti/vendor/file_contexts new file mode 100644 index 0000000..38fbfb4 --- /dev/null +++ b/sepolicy/qti/vendor/file_contexts @@ -0,0 +1,2 @@ +# HALd +/(vendor|system/vendor|odm|vendor/odm)/bin/hw/vendor\.sony\.charger-service u:object_r:hal_sony_charger_default_exec:s0 diff --git a/sepolicy/qti/vendor/hal_sony_charger.te b/sepolicy/qti/vendor/hal_sony_charger.te new file mode 100644 index 0000000..49bd8a5 --- /dev/null +++ b/sepolicy/qti/vendor/hal_sony_charger.te @@ -0,0 +1,6 @@ +# HwBinder IPC client/server +binder_call(hal_sony_charger_client, hal_sony_charger_server); +binder_call(hal_sony_charger_server, hal_sony_charger_client); + +add_service(hal_sony_charger_server, hal_sony_charger_service); +allow hal_sony_charger_client hal_sony_charger_service:service_manager { find }; diff --git a/sepolicy/qti/vendor/hal_sony_charger_default.te b/sepolicy/qti/vendor/hal_sony_charger_default.te new file mode 100644 index 0000000..020ce19 --- /dev/null +++ b/sepolicy/qti/vendor/hal_sony_charger_default.te @@ -0,0 +1,16 @@ +# Sony Charger Service +type hal_sony_charger_default, domain; +hal_server_domain(hal_sony_charger_default, hal_sony_charger); + +type hal_sony_charger_default_exec, exec_type, vendor_file_type, file_type; +init_daemon_domain(hal_sony_charger_default); + +binder_call(hal_sony_charger_default, servicemanager); + +allow hal_sony_charger_default vendor_sysfs_battery_supply:file { getattr rw_file_perms }; +allow hal_sony_charger_default vendor_sysfs_battery_supply:dir r_dir_perms; +allow hal_sony_charger_default hal_sony_charger_default:netlink_kobject_uevent_socket { create setopt getopt bind read }; +allow hal_sony_charger_default sysfs_battchg_ext:file { getattr rw_file_perms }; +allow hal_sony_charger_default sysfs_battchg_ext:dir r_dir_perms; + +permissive hal_sony_charger_default; diff --git a/sepolicy/qti/vendor/service.te b/sepolicy/qti/vendor/service.te new file mode 100644 index 0000000..6cb9943 --- /dev/null +++ b/sepolicy/qti/vendor/service.te @@ -0,0 +1 @@ +type hal_sony_charger_service, vendor_service, hal_service_type, service_manager_type; diff --git a/sepolicy/qti/vendor/service_contexts b/sepolicy/qti/vendor/service_contexts new file mode 100644 index 0000000..26c1685 --- /dev/null +++ b/sepolicy/qti/vendor/service_contexts @@ -0,0 +1 @@ +vendor.sony.charger.ICharger/default u:object_r:hal_sony_charger_service:s0 diff --git a/sepolicy/qti/vendor/system_app.te b/sepolicy/qti/vendor/system_app.te new file mode 100644 index 0000000..3def531 --- /dev/null +++ b/sepolicy/qti/vendor/system_app.te @@ -0,0 +1 @@ +binder_call(system_app, hal_sony_charger_default)