diff options
author | MarcKe <herderkewitz@googlemail.com> | 2015-01-26 04:39:08 +0100 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-01 04:29:12 -0800 |
commit | 705dd14c10b53e662f6df958297bf677d2a91397 (patch) | |
tree | 88048fe4d1e3b6338d3300d06bd3243cbb217f89 /healthd | |
parent | 3533500566093619d97e46574184a746f1d4e805 (diff) | |
download | system_core-705dd14c10b53e662f6df958297bf677d2a91397.zip system_core-705dd14c10b53e662f6df958297bf677d2a91397.tar.gz system_core-705dd14c10b53e662f6df958297bf677d2a91397.tar.bz2 |
healthd: fix LED color on 100%
if soc reaches 100, the loop variable would reach 3.
acessing the the fourth element of soc_leds is undefined behaviour
Change-Id: Iebc521c66844c811afa0244bc7977d1f88144227
Diffstat (limited to 'healthd')
-rw-r--r-- | healthd/healthd_mode_charger.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 7ebbdfb..709ec12 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -244,7 +244,7 @@ static int set_battery_soc_leds(int soc) static int old_color = 0; for (i = 0; i < (int)ARRAY_SIZE(soc_leds); i++) { - if (soc < soc_leds[i].soc) + if (soc <= soc_leds[i].soc) break; } color = soc_leds[i].color; @@ -666,14 +666,17 @@ static void handle_input_state(struct charger *charger, int64_t now) static void handle_power_supply_state(struct charger *charger, int64_t now) { static int old_soc = 0; - int soc; + int soc = 0; if (!charger->have_battery_state) return; healthd_board_mode_charger_battery_update(batt_prop); - soc = get_battery_capacity(); + if (batt_prop && batt_prop->batteryLevel >= 0) { + soc = batt_prop->batteryLevel; + } + if (old_soc != soc) { old_soc = soc; set_battery_soc_leds(soc); |