Merge changes from topic "charger-vendor"

* changes:
  charger: vendor charger use resources from /vendor
  charger: make libhealthd_charger_ui vendor_available.
  libsuspend: vendor_available.
This commit is contained in:
Yifan Hong 2021-11-03 18:53:33 +00:00 committed by Gerrit Code Review
commit 95e2f7ffc8
4 changed files with 95 additions and 5 deletions

View file

@ -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 {
@ -307,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",
],
}

View file

@ -18,19 +18,30 @@
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
#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<int64_t>(std::numeric_limits<int>::min())) {
LOGW("draw_split_offset = %" PRId64 " overflow for an int; resetting to %d.\n", value,
std::numeric_limits<int>::min());

View file

@ -50,13 +50,16 @@
#include <suspend/autosuspend.h>
#include "AnimationParser.h"
#include "charger.sysprop.h"
#include "healthd_draw.h"
#include <aidl/android/hardware/health/BatteryStatus.h>
#include <health/HealthLoop.h>
#include <healthd/healthd.h>
#if !defined(__ANDROID_VNDK__)
#include "charger.sysprop.h"
#endif
using std::string_literals::operator""s;
using namespace android;
using aidl::android::hardware::health::BatteryStatus;
@ -96,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/";
@ -109,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 =
@ -314,10 +325,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 */
@ -614,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);
@ -629,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");
@ -680,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;

View file

@ -6,6 +6,7 @@ package {
cc_library {
name: "libsuspend",
vendor_available: true,
srcs: [
"autosuspend.c",
"autosuspend_wakeup_count.cpp",