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
diff --git a/healthd/Android.bp b/healthd/Android.bp
index be3f920..eaa8e5b 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -325,3 +325,29 @@
"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 d40a41a..0f9779c 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -99,6 +99,13 @@
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 @@
"/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 @@
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 @@
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 @@
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;