From d80918f7b5d940f79a22f9945f16e79a5ff5a4a4 Mon Sep 17 00:00:00 2001 From: Tim Zimmermann Date: Mon, 22 Aug 2022 06:16:48 +0200 Subject: [PATCH] universal7885: Switch to health AIDL HAL Change-Id: Icbb7194943388679abd25b2dbd105424c34496a1 --- .../hidl-packages/health/Android.bp | 29 ---- .../hidl-packages/health/HealthImpl.cpp | 155 ------------------ .../rootdir/etc/init.exynos7885.rc | 7 - .../sepolicy/vendor/charger_vendor.te | 3 + .../sepolicy/vendor/file_contexts | 2 +- universal7885-common/universal7885-common.mk | 7 +- 6 files changed, 7 insertions(+), 196 deletions(-) delete mode 100644 universal7885-common/hidl-packages/health/Android.bp delete mode 100644 universal7885-common/hidl-packages/health/HealthImpl.cpp create mode 100644 universal7885-common/sepolicy/vendor/charger_vendor.te diff --git a/universal7885-common/hidl-packages/health/Android.bp b/universal7885-common/hidl-packages/health/Android.bp deleted file mode 100644 index 1f2372d..0000000 --- a/universal7885-common/hidl-packages/health/Android.bp +++ /dev/null @@ -1,29 +0,0 @@ -cc_library_shared { - name: "android.hardware.health@2.1-impl-exynos7885", - stem: "android.hardware.health@2.0-impl-2.1-exynos7885", - - proprietary: true, - recovery_available: true, - relative_install_path: "hw", - defaults: ["eureka_defaults"], - shared_libs: [ - "libbase", - "libcutils", - "libhidlbase", - "liblog", - "libutils", - "android.hardware.health@2.1", - "android.hardware.health@2.0", - ], - - static_libs: [ - "android.hardware.health@1.0-convert", - "libbatterymonitor", - "libhealthloop", - "libhealth2impl", - ], - - srcs: [ - "HealthImpl.cpp", - ], -} diff --git a/universal7885-common/hidl-packages/health/HealthImpl.cpp b/universal7885-common/hidl-packages/health/HealthImpl.cpp deleted file mode 100644 index 6a86a38..0000000 --- a/universal7885-common/hidl-packages/health/HealthImpl.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -using ::android::hardware::Return; -using ::android::hardware::health::InitHealthdConfig; -using ::android::hardware::health::V2_1::IHealth; -using ::android::hardware::health::V2_0::Result; -using ::android::hardware::health::V1_0::BatteryStatus; -using namespace std::literals; - -enum battery_stats { - CHARGE_CNT, - CURRENT_NOW, - CURRENT_AVG, - CAPACITY, - CHARGE_ENABLED, - FULL -}; - -std::unordered_map battery_sysfs = { - { CHARGE_CNT, "/efs/FactoryApp/batt_cable_count" }, - { CURRENT_NOW, "/sys/devices/platform/battery/power_supply/battery/current_now" }, - { CURRENT_AVG, "/sys/devices/platform/battery/power_supply/battery/current_avg" }, - { CAPACITY, "/sys/devices/platform/battery/power_supply/battery/charge_full" }, - { CHARGE_ENABLED, "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode" }, - { FULL, "/sys/devices/platform/battery/power_supply/battery/capacity" }, -}; - -struct callBack { - Result result; - std::string value; -}; - -namespace android { -namespace hardware { -namespace health { -namespace V2_1 { -namespace implementation { - -// android::hardware::health::V2_1::implementation::Health implements most -// defaults. Uncomment functions that you need to override. -class HealthImpl : public Health { - public: - explicit HealthImpl(std::unique_ptr&& config) - : Health(std::move(config)) {} - - static struct callBack ReadFile(const std::string &sysfs, const std::string &def) { - std::string ret = def; - std::ifstream file; - file.open(sysfs); - Result result = Result::SUCCESS; - if (file.is_open()){ - getline(file, ret); - file.close(); - } else { - result = Result::NOT_FOUND; - } - ALOGI ("%s: sysfs : %s, returns : %s", __func__, sysfs.c_str(), ret.c_str()); - struct callBack cb = { result, ret }; - return cb; - } - - static struct callBack ReadBattFile(battery_stats type, const std::string &def) { - return ReadFile(battery_sysfs[type], def); - } - - Return getChargeCounter(getChargeCounter_cb _hidl_cb) { - struct callBack ret = ReadBattFile(CHARGE_CNT, "-1"); - _hidl_cb(ret.result, std::stoi(ret.value)); - return Void(); - } - - Return getCurrentNow(getCurrentNow_cb _hidl_cb){ - struct callBack ret = ReadBattFile(CURRENT_NOW, "-1"); - _hidl_cb(ret.result, std::stoi(ret.value)); - return Void(); - } - - Return getCurrentAverage(getCurrentAverage_cb _hidl_cb){ - struct callBack ret = ReadBattFile(CURRENT_NOW, "-1"); - _hidl_cb(ret.result, std::stoi(ret.value)); - return Void(); - } - - Return getCapacity(getCapacity_cb _hidl_cb){ - struct callBack ret = ReadBattFile(CURRENT_NOW, "-1"); - _hidl_cb(ret.result, std::stoi(ret.value)); - return Void(); - } - - Return getChargeStatus(getChargeStatus_cb _hidl_cb){ - struct callBack ret = ReadBattFile(CURRENT_NOW, "-1"); - Result result = ret.result; - BatteryStatus batt = BatteryStatus::UNKNOWN; - if (std::stoi(ret.value) > 0) { - struct callBack res = ReadBattFile(FULL, "0"); - if (std::stoi(res.value) == 100){ - batt = BatteryStatus::FULL; - } else if (std::stoi(res.value) > 0) { - batt = BatteryStatus::CHARGING; - } - result = res.result; - } else if (std::stoi(ret.value) < 0) { - struct callBack res = ReadBattFile(CHARGE_ENABLED, "0"); - if (std::stoi(res.value) == 0){ - batt = BatteryStatus::DISCHARGING; - } else if (std::stoi(res.value) == 1) { - batt = BatteryStatus::NOT_CHARGING; - } - result = res.result; - } - _hidl_cb(result, batt); - return Void(); - } - - // Return getDiskStats(getDiskStats_cb _hidl_cb) override; - // Return getHealthInfo(getHealthInfo_cb _hidl_cb) override; - - // Functions introduced in Health HAL 2.1. - // Return getHealthConfig(getHealthConfig_cb _hidl_cb) override; - // Return getHealthInfo_2_1(getHealthInfo_2_1_cb _hidl_cb) override; - // Return shouldKeepScreenOn(shouldKeepScreenOn_cb _hidl_cb) override; - - protected: - // A subclass can override this to modify any health info object before - // returning to clients. This is similar to healthd_board_battery_update(). - // By default, it does nothing. - // void UpdateHealthInfo(HealthInfo* health_info) override; -}; - -} // namespace implementation -} // namespace V2_1 -} // namespace health -} // namespace hardware -} // namespace android - -extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) { - using ::android::hardware::health::V2_1::implementation::HealthImpl; - if (instance != "default"sv) { - return nullptr; - } - auto config = std::make_unique(); - InitHealthdConfig(config.get()); - - // healthd_board_init(config.get()); - - return new HealthImpl(std::move(config)); -} diff --git a/universal7885-common/rootdir/etc/init.exynos7885.rc b/universal7885-common/rootdir/etc/init.exynos7885.rc index 808811c..9a6b6b9 100644 --- a/universal7885-common/rootdir/etc/init.exynos7885.rc +++ b/universal7885-common/rootdir/etc/init.exynos7885.rc @@ -601,13 +601,6 @@ service tzts_service /vendor/bin/tzts_daemon group system disabled -service charger /system/bin/charger - class charger - user system - group system graphics input - capabilities SYS_BOOT - seclabel u:r:charger:s0 - # Start NFC on supported variants service nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.2-service.samsung override diff --git a/universal7885-common/sepolicy/vendor/charger_vendor.te b/universal7885-common/sepolicy/vendor/charger_vendor.te new file mode 100644 index 0000000..e8bae85 --- /dev/null +++ b/universal7885-common/sepolicy/vendor/charger_vendor.te @@ -0,0 +1,3 @@ +allow charger_vendor device:dir r_file_perms; +allow charger_vendor sysfs_battery:file r_file_perms; +allow charger_vendor sysfs_battery_writable:file r_file_perms; diff --git a/universal7885-common/sepolicy/vendor/file_contexts b/universal7885-common/sepolicy/vendor/file_contexts index ad8dac3..2bb31a9 100644 --- a/universal7885-common/sepolicy/vendor/file_contexts +++ b/universal7885-common/sepolicy/vendor/file_contexts @@ -206,7 +206,7 @@ /(vendor|system/vendor)/bin/hw/macloader u:object_r:macloader_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.power(@[0-9]\.[0-9])?-service\.samsung-libperfmgr u:object_r:hal_power_default_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.vibrator(@[0-9].[0-9])?-service\.samsung u:object_r:hal_vibrator_default_exec:s0 -/(vendor|system/vendor)/bin/hw/android\.hardware\.drm@[0-9]\.[0-9]-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0 +/(vendor|system/vendor)/bin/hw/android\.hardware\.health-service\.samsung u:object_r:hal_health_default_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.drm@[0-9]\.[0-9]-service\.widevine u:object_r:hal_drm_widevine_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.memtrack-service\.samsung-mali u:object_r:hal_memtrack_default_exec:s0 /(vendor|system/vendor)/bin/hw/android\.hardware\.keymaster@[0-9]\.[0-9]-service\.samsung u:object_r:hal_keymaster_default_exec:s0 diff --git a/universal7885-common/universal7885-common.mk b/universal7885-common/universal7885-common.mk index 8b5571a..d1ebfa8 100644 --- a/universal7885-common/universal7885-common.mk +++ b/universal7885-common/universal7885-common.mk @@ -102,7 +102,7 @@ PRODUCT_PACKAGES += \ # Charger PRODUCT_PACKAGES += \ - libsuspend + charger_res_images_vendor # Debug PRODUCT_PACKAGES += eklogger dlopener @@ -142,9 +142,8 @@ PRODUCT_PACKAGES += \ # Health PRODUCT_PACKAGES += \ - android.hardware.health@2.1-impl-exynos7885 \ - android.hardware.health@2.1-impl-exynos7885.recovery \ - android.hardware.health@2.1-service + android.hardware.health-service.samsung \ + android.hardware.health-service.samsung-recovery # HIDL PRODUCT_PACKAGES += \