From b200c60221ed20b79c257741f6c17489de77628a Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 20 Oct 2021 22:42:35 -0700 Subject: [PATCH 1/3] libsuspend: vendor_available. This is needed by charger in vendor. Test: builds Bug: 203246116 Change-Id: I55c5cace9dcd7b2fd475d61234bd469428b4caac --- libsuspend/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsuspend/Android.bp b/libsuspend/Android.bp index 671de4d98..144b4b6ca 100644 --- a/libsuspend/Android.bp +++ b/libsuspend/Android.bp @@ -6,6 +6,7 @@ package { cc_library { name: "libsuspend", + vendor_available: true, srcs: [ "autosuspend.c", "autosuspend_wakeup_count.cpp", From e3ffd1bfc240605396f297e048dc3fa0beff6bf1 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 20 Oct 2021 22:18:16 -0700 Subject: [PATCH 2/3] charger: make libhealthd_charger_ui vendor_available. This is a prerequisite to move charger to vendor partition. Because vendor domains can't read ro.charger.*, they are all assumed to be the default value. They aren't set in the ecosystem anyway, so it is time to deprecate them. Test: builds Bug: 203246116 Change-Id: I0b17e62ab3ac5a89df091333fd9f24e33bdfd49a --- healthd/Android.bp | 18 ++++++++++++++++++ healthd/healthd_draw.cpp | 13 ++++++++++++- healthd/healthd_mode_charger.cpp | 7 ++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/healthd/Android.bp b/healthd/Android.bp index 15f009e93..be3f92087 100644 --- a/healthd/Android.bp +++ b/healthd/Android.bp @@ -106,6 +106,7 @@ sysprop_library { cc_library_static { name: "libhealthd_draw", + vendor_available: true, export_include_dirs: ["."], static_libs: [ "libcharger_sysprop", @@ -117,10 +118,19 @@ cc_library_static { header_libs: ["libbatteryservice_headers"], srcs: ["healthd_draw.cpp"], + + target: { + vendor: { + exclude_static_libs: [ + "libcharger_sysprop", + ], + }, + }, } cc_library_static { name: "libhealthd_charger_ui", + vendor_available: true, export_include_dirs: [ "include", "include_charger", @@ -156,6 +166,14 @@ cc_library_static { "healthd_mode_charger.cpp", "AnimationParser.cpp", ], + + target: { + vendor: { + exclude_static_libs: [ + "libcharger_sysprop", + ], + }, + }, } cc_library_static { diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp index 9a47f6b2b..4484fa61e 100644 --- a/healthd/healthd_draw.cpp +++ b/healthd/healthd_draw.cpp @@ -18,19 +18,30 @@ #include #include -#include "charger.sysprop.h" #include "healthd_draw.h" +#if !defined(__ANDROID_VNDK__) +#include "charger.sysprop.h" +#endif + #define LOGE(x...) KLOG_ERROR("charger", x); #define LOGW(x...) KLOG_WARNING("charger", x); #define LOGV(x...) KLOG_DEBUG("charger", x); static bool get_split_screen() { +#if !defined(__ANDROID_VNDK__) return android::sysprop::ChargerProperties::draw_split_screen().value_or(false); +#else + return false; +#endif } static int get_split_offset() { +#if !defined(__ANDROID_VNDK__) int64_t value = android::sysprop::ChargerProperties::draw_split_offset().value_or(0); +#else + int64_t value = 0; +#endif if (value < static_cast(std::numeric_limits::min())) { LOGW("draw_split_offset = %" PRId64 " overflow for an int; resetting to %d.\n", value, std::numeric_limits::min()); diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index aac719bab..d40a41a8e 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -50,13 +50,16 @@ #include #include "AnimationParser.h" -#include "charger.sysprop.h" #include "healthd_draw.h" #include #include #include +#if !defined(__ANDROID_VNDK__) +#include "charger.sysprop.h" +#endif + using std::string_literals::operator""s; using namespace android; using aidl::android::hardware::health::BatteryStatus; @@ -314,10 +317,12 @@ void Charger::UpdateScreenState(int64_t now) { healthd_draw_ = HealthdDraw::Create(&batt_anim_); if (healthd_draw_ == nullptr) return; +#if !defined(__ANDROID_VNDK__) if (android::sysprop::ChargerProperties::disable_init_blank().value_or(false)) { healthd_draw_->blank_screen(true); screen_blanked_ = true; } +#endif } /* animation is over, blank screen and leave */ From ac748369bb6c83a5f6497c71a45ad98fd2f46d1d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 26 Oct 2021 17:20:25 -0700 Subject: [PATCH 3/3] charger: vendor charger use resources from /vendor For the vendor variant of libhealthd_mode_charger, read resources from /vendor. The core variant continues to read resources from /product, /system, and /res. Test: run charger from /vendor manually Bug: 203246116 Change-Id: Ia9df1d081a51783409b5dbd3e3d4719efc3cb6a7 --- healthd/Android.bp | 26 ++++++++++++++++++++++++ healthd/healthd_mode_charger.cpp | 35 +++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/healthd/Android.bp b/healthd/Android.bp index be3f92087..eaa8e5bb3 100644 --- a/healthd/Android.bp +++ b/healthd/Android.bp @@ -325,3 +325,29 @@ phony { "system_core_charger_res_images_battery_scale.png", ], } + +// /vendor/etc/res/images/charger/battery_fail.png +prebuilt_etc { + name: "system_core_charger_res_images_battery_fail.png_default_vendor", + src: "images/battery_fail.png", + relative_install_path: "res/images/charger/default", + vendor: true, + filename: "battery_fail.png", +} + +// /vendor/etc/res/images/charger/battery_scale.png +prebuilt_etc { + name: "system_core_charger_res_images_battery_scale.png_default_vendor", + src: "images/battery_scale.png", + relative_install_path: "res/images/charger/default", + vendor: true, + filename: "battery_scale.png", +} + +phony { + name: "charger_res_images_vendor", + required: [ + "system_core_charger_res_images_battery_fail.png_default_vendor", + "system_core_charger_res_images_battery_scale.png_default_vendor", + ], +} diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index d40a41a8e..0f9779c4f 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -99,6 +99,13 @@ char* locale; namespace android { +#if defined(__ANDROID_VNDK__) +static constexpr const char* vendor_animation_desc_path = + "/vendor/etc/res/values/charger/animation.txt"; +static constexpr const char* vendor_animation_root = "/vendor/etc/res/images/"; +static constexpr const char* vendor_default_animation_root = "/vendor/etc/res/images/default/"; +#else + // Legacy animation resources are loaded from this directory. static constexpr const char* legacy_animation_root = "/res/images/"; @@ -112,6 +119,7 @@ static constexpr const char* product_animation_desc_path = "/product/etc/res/values/charger/animation.txt"; static constexpr const char* product_animation_root = "/product/etc/res/images/"; static constexpr const char* animation_desc_path = "/res/values/charger/animation.txt"; +#endif static const animation BASE_ANIMATION = { .text_clock = @@ -619,6 +627,16 @@ void Charger::InitAnimation() { bool parse_success; std::string content; + +#if defined(__ANDROID_VNDK__) + if (base::ReadFileToString(vendor_animation_desc_path, &content)) { + parse_success = parse_animation_desc(content, &batt_anim_); + batt_anim_.set_resource_root(vendor_animation_root); + } else { + LOGW("Could not open animation description at %s\n", vendor_animation_desc_path); + parse_success = false; + } +#else if (base::ReadFileToString(product_animation_desc_path, &content)) { parse_success = parse_animation_desc(content, &batt_anim_); batt_anim_.set_resource_root(product_animation_root); @@ -634,17 +652,26 @@ void Charger::InitAnimation() { LOGW("Could not open animation description at %s\n", animation_desc_path); parse_success = false; } +#endif + +#if defined(__ANDROID_VNDK__) + auto default_animation_root = vendor_default_animation_root; +#else + auto default_animation_root = system_animation_root; +#endif if (!parse_success) { - LOGW("Could not parse animation description. Using default animation.\n"); + LOGW("Could not parse animation description. " + "Using default animation with resources at %s\n", + default_animation_root); batt_anim_ = BASE_ANIMATION; - batt_anim_.animation_file.assign(system_animation_root + "charger/battery_scale.png"s); + batt_anim_.animation_file.assign(default_animation_root + "charger/battery_scale.png"s); InitDefaultAnimationFrames(); batt_anim_.frames = owned_frames_.data(); batt_anim_.num_frames = owned_frames_.size(); } if (batt_anim_.fail_file.empty()) { - batt_anim_.fail_file.assign(system_animation_root + "charger/battery_fail.png"s); + batt_anim_.fail_file.assign(default_animation_root + "charger/battery_fail.png"s); } LOGV("Animation Description:\n"); @@ -685,9 +712,11 @@ void Charger::OnInit(struct healthd_config* config) { ret = CreateDisplaySurface(batt_anim_.fail_file, &surf_unknown_); if (ret < 0) { +#if !defined(__ANDROID_VNDK__) LOGE("Cannot load custom battery_fail image. Reverting to built in: %d\n", ret); ret = CreateDisplaySurface((system_animation_root + "charger/battery_fail.png"s).c_str(), &surf_unknown_); +#endif if (ret < 0) { LOGE("Cannot load built in battery_fail image\n"); surf_unknown_ = NULL;