From a40d8729898ad0fee12954fb1ba8fedef337d601 Mon Sep 17 00:00:00 2001 From: Xiaohui Niu Date: Tue, 31 Aug 2021 16:22:25 +0800 Subject: [PATCH] charger: fix charger display stuck 1.Retry charger when gr init fail caused by display not ready. 2.Remove meaningless logs which occupy log lines, the logs that really need to be printed cannot be output due to printk suppresses kernel logs. Bug: 197604278 Change-Id: Id9465a0a9c994986192fd39c124d05aed8caa862 Test: Manual. Power off charging. --- healthd/healthd_draw.cpp | 16 ++++++++-------- healthd/healthd_draw.h | 8 ++++++-- healthd/healthd_mode_charger.cpp | 7 ++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp index 50eee198f..9a47f6b2b 100644 --- a/healthd/healthd_draw.cpp +++ b/healthd/healthd_draw.cpp @@ -46,14 +46,6 @@ static int get_split_offset() { HealthdDraw::HealthdDraw(animation* anim) : kSplitScreen(get_split_screen()), kSplitOffset(get_split_offset()) { - int ret = gr_init(); - - if (ret < 0) { - LOGE("gr_init failed\n"); - graphics_available = false; - return; - } - graphics_available = true; sys_font = gr_sys_font(); if (sys_font == nullptr) { @@ -235,3 +227,11 @@ void HealthdDraw::draw_unknown(GRSurface* surf_unknown) { LOGW("Charging, level unknown\n"); } } + +std::unique_ptr HealthdDraw::Create(animation *anim) { + if (gr_init() < 0) { + LOGE("gr_init failed\n"); + return nullptr; + } + return std::unique_ptr(new HealthdDraw(anim)); +} diff --git a/healthd/healthd_draw.h b/healthd/healthd_draw.h index 7c847bdbf..0b48ce842 100644 --- a/healthd/healthd_draw.h +++ b/healthd/healthd_draw.h @@ -26,8 +26,6 @@ using namespace android; class HealthdDraw { public: - // Configures font using given animation. - HealthdDraw(animation* anim); virtual ~HealthdDraw(); // Redraws screen. @@ -36,6 +34,8 @@ class HealthdDraw { // Blanks screen if true, unblanks if false. virtual void blank_screen(bool blank); + static std::unique_ptr Create(animation *anim); + protected: virtual void clear_screen(); @@ -76,6 +76,10 @@ class HealthdDraw { // true if minui init'ed OK, false if minui init failed bool graphics_available; + + private: + // Configures font using given animation. + HealthdDraw(animation* anim); }; #endif // HEALTHD_DRAW_H diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index e95efc04c..3ea90b04e 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -218,9 +218,7 @@ static void dump_last_kmsg(void) { char* ptr; size_t len; - LOGW("\n"); LOGW("*************** LAST KMSG ***************\n"); - LOGW("\n"); const char* kmsg[] = { // clang-format off "/sys/fs/pstore/console-ramoops-0", @@ -263,9 +261,7 @@ static void dump_last_kmsg(void) { } out: - LOGW("\n"); LOGW("************* END LAST KMSG *************\n"); - LOGW("\n"); } static int request_suspend(bool enable) { @@ -325,7 +321,8 @@ void Charger::UpdateScreenState(int64_t now) { } } - healthd_draw_.reset(new HealthdDraw(&batt_anim_)); + healthd_draw_ = HealthdDraw::Create(&batt_anim_); + if (healthd_draw_ == nullptr) return; if (android::sysprop::ChargerProperties::disable_init_blank().value_or(false)) { healthd_draw_->blank_screen(true);