system/core
修订版 | 926792883660eb986ad214f40554cfba5e3f4c1d (tree) |
---|---|
时间 | 2019-04-01 11:43:26 |
作者 | Ken Tsou <kentsou@goog...> |
Commiter | android-build-merger |
Merge "charger: fix show 0% symptom when start to draw UI" am: a93a89f4bd
am: 5052f7db39
Change-Id: Icf6c36e86d5b7ab10d86f7c38cbd1173f4f6d964
@@ -64,7 +64,8 @@ void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unkn | ||
64 | 64 | clear_screen(); |
65 | 65 | |
66 | 66 | /* try to display *something* */ |
67 | - if (batt_anim->cur_level < 0 || batt_anim->num_frames == 0) | |
67 | + if (batt_anim->cur_status == BATTERY_STATUS_UNKNOWN || batt_anim->cur_level < 0 || | |
68 | + batt_anim->num_frames == 0) | |
68 | 69 | draw_unknown(surf_unknown); |
69 | 70 | else |
70 | 71 | draw_battery(batt_anim); |
@@ -77,6 +77,7 @@ char* locale; | ||
77 | 77 | #define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC) |
78 | 78 | #define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC) |
79 | 79 | #define UNPLUGGED_DISPLAY_TIME (3 * MSEC_PER_SEC) |
80 | +#define MAX_BATT_LEVEL_WAIT_TIME (3 * MSEC_PER_SEC) | |
80 | 81 | |
81 | 82 | #define LAST_KMSG_MAX_SZ (32 * 1024) |
82 | 83 |
@@ -105,6 +106,7 @@ struct charger { | ||
105 | 106 | int64_t next_screen_transition; |
106 | 107 | int64_t next_key_check; |
107 | 108 | int64_t next_pwr_check; |
109 | + int64_t wait_batt_level_timestamp; | |
108 | 110 | |
109 | 111 | key_state keys[KEY_MAX + 1]; |
110 | 112 |
@@ -290,6 +292,21 @@ static void update_screen_state(charger* charger, int64_t now) { | ||
290 | 292 | |
291 | 293 | if (!batt_anim->run || now < charger->next_screen_transition) return; |
292 | 294 | |
295 | + // If battery level is not ready, keep checking in the defined time | |
296 | + if (batt_prop == nullptr || | |
297 | + (batt_prop->batteryLevel == 0 && batt_prop->batteryStatus == BATTERY_STATUS_UNKNOWN)) { | |
298 | + if (charger->wait_batt_level_timestamp == 0) { | |
299 | + // Set max delay time and skip drawing screen | |
300 | + charger->wait_batt_level_timestamp = now + MAX_BATT_LEVEL_WAIT_TIME; | |
301 | + LOGV("[%" PRId64 "] wait for battery capacity ready\n", now); | |
302 | + return; | |
303 | + } else if (now <= charger->wait_batt_level_timestamp) { | |
304 | + // Do nothing, keep waiting | |
305 | + return; | |
306 | + } | |
307 | + // If timeout and battery level is still not ready, draw unknown battery | |
308 | + } | |
309 | + | |
293 | 310 | if (healthd_draw == nullptr) { |
294 | 311 | if (healthd_config && healthd_config->screen_on) { |
295 | 312 | if (!healthd_config->screen_on(batt_prop)) { |
@@ -709,6 +726,7 @@ void healthd_mode_charger_init(struct healthd_config* config) { | ||
709 | 726 | charger->next_screen_transition = -1; |
710 | 727 | charger->next_key_check = -1; |
711 | 728 | charger->next_pwr_check = -1; |
729 | + charger->wait_batt_level_timestamp = 0; | |
712 | 730 | |
713 | 731 | // Initialize Health implementation (which initializes the internal BatteryMonitor). |
714 | 732 | Health::initInstance(config); |