From 6c7ece743ce5bec997dddeff1121b65661dfc2f5 Mon Sep 17 00:00:00 2001 From: Ken Tsou Date: Fri, 15 Feb 2019 10:50:58 +0800 Subject: [PATCH] charger: fix show 0% symptom when start to draw UI Bug: 123060995 Test: m -j succeeded and confirm offmode charge UI behavior Change-Id: I7412157cfe829a86e72b3f43d9c43032f3567ed3 --- healthd/healthd_draw.cpp | 3 ++- healthd/healthd_mode_charger.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp index 706dc80ba..3da8bda3b 100644 --- a/healthd/healthd_draw.cpp +++ b/healthd/healthd_draw.cpp @@ -64,7 +64,8 @@ void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unkn clear_screen(); /* try to display *something* */ - if (batt_anim->cur_level < 0 || batt_anim->num_frames == 0) + if (batt_anim->cur_status == BATTERY_STATUS_UNKNOWN || batt_anim->cur_level < 0 || + batt_anim->num_frames == 0) draw_unknown(surf_unknown); else draw_battery(batt_anim); diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index bde5fbe4a..0e5aa4f5d 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -77,6 +77,7 @@ char* locale; #define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC) #define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC) #define UNPLUGGED_DISPLAY_TIME (3 * MSEC_PER_SEC) +#define MAX_BATT_LEVEL_WAIT_TIME (3 * MSEC_PER_SEC) #define LAST_KMSG_MAX_SZ (32 * 1024) @@ -105,6 +106,7 @@ struct charger { int64_t next_screen_transition; int64_t next_key_check; int64_t next_pwr_check; + int64_t wait_batt_level_timestamp; key_state keys[KEY_MAX + 1]; @@ -290,6 +292,21 @@ static void update_screen_state(charger* charger, int64_t now) { if (!batt_anim->run || now < charger->next_screen_transition) return; + // If battery level is not ready, keep checking in the defined time + if (batt_prop == nullptr || + (batt_prop->batteryLevel == 0 && batt_prop->batteryStatus == BATTERY_STATUS_UNKNOWN)) { + if (charger->wait_batt_level_timestamp == 0) { + // Set max delay time and skip drawing screen + charger->wait_batt_level_timestamp = now + MAX_BATT_LEVEL_WAIT_TIME; + LOGV("[%" PRId64 "] wait for battery capacity ready\n", now); + return; + } else if (now <= charger->wait_batt_level_timestamp) { + // Do nothing, keep waiting + return; + } + // If timeout and battery level is still not ready, draw unknown battery + } + if (healthd_draw == nullptr) { if (healthd_config && healthd_config->screen_on) { if (!healthd_config->screen_on(batt_prop)) { @@ -709,6 +726,7 @@ void healthd_mode_charger_init(struct healthd_config* config) { charger->next_screen_transition = -1; charger->next_key_check = -1; charger->next_pwr_check = -1; + charger->wait_batt_level_timestamp = 0; // Initialize Health implementation (which initializes the internal BatteryMonitor). Health::initInstance(config);