From 57dd992bf72a3cf800286bd8f5c42f2c5222a61b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 8 Dec 2016 17:39:45 +0900 Subject: [PATCH] modify thermal for over temperature Change-Id: Ic6eb138d7b882d0583cd421602f0357d1f11d332 Signed-off-by: lokilee73 --- src/thermal/thermal.c | 153 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 131 insertions(+), 22 deletions(-) mode change 100644 => 100755 src/thermal/thermal.c diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c old mode 100644 new mode 100755 index 603eda4..a9122ce --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -31,6 +31,90 @@ static struct thermal_device *thermal_dev; static int noti; +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) + +enum thermal_action_type { + NO_CHANGE, + LOW_TO_HIGH, + HIGH_TO_LOW, + HIGH_TO_CRITICAL, + NEED_TO_CHECK +}; + +enum thermal_level_update_type { + UPDATE, + KEEP +}; + +struct thermal_state { + thermal_state_e old_state; + thermal_state_e new_state; + enum thermal_action_type status; +}; + +struct thermal_level { + thermal_level_e old_level; + thermal_level_e new_level; + enum thermal_action_type status; + enum thermal_level_update_type level; +}; + +static struct thermal_state temp_state[] = { + { THERMAL_STATE_LOW, THERMAL_STATE_LOW, NO_CHANGE}, + { THERMAL_STATE_LOW, THERMAL_STATE_NORMAL, NO_CHANGE}, + { THERMAL_STATE_LOW, THERMAL_STATE_HIGH, LOW_TO_HIGH}, + { THERMAL_STATE_NORMAL, THERMAL_STATE_LOW, NO_CHANGE}, + { THERMAL_STATE_NORMAL, THERMAL_STATE_NORMAL, NO_CHANGE}, + { THERMAL_STATE_NORMAL, THERMAL_STATE_HIGH, LOW_TO_HIGH}, + { THERMAL_STATE_HIGH, THERMAL_STATE_LOW, NEED_TO_CHECK}, + { THERMAL_STATE_HIGH, THERMAL_STATE_NORMAL, NEED_TO_CHECK}, + { THERMAL_STATE_HIGH, THERMAL_STATE_HIGH, NEED_TO_CHECK} +}; + +static struct thermal_level temp_level[] = { + { THERMAL_LEVEL_WARNING, THERMAL_LEVEL_NORMAL, HIGH_TO_LOW, UPDATE}, + { THERMAL_LEVEL_WARNING, THERMAL_LEVEL_WARNING, NO_CHANGE, UPDATE}, + { THERMAL_LEVEL_WARNING, THERMAL_LEVEL_CRITICAL, HIGH_TO_CRITICAL, UPDATE}, + { THERMAL_LEVEL_WARNING, THERMAL_LEVEL_POWEROFF, HIGH_TO_CRITICAL, UPDATE}, + { THERMAL_LEVEL_CRITICAL, THERMAL_LEVEL_NORMAL, NO_CHANGE, KEEP}, + { THERMAL_LEVEL_CRITICAL, THERMAL_LEVEL_WARNING, NO_CHANGE, KEEP}, + { THERMAL_LEVEL_CRITICAL, THERMAL_LEVEL_CRITICAL, NO_CHANGE, UPDATE}, + { THERMAL_LEVEL_CRITICAL, THERMAL_LEVEL_POWEROFF, NO_CHANGE, UPDATE}, + { THERMAL_LEVEL_POWEROFF, THERMAL_LEVEL_NORMAL, NO_CHANGE, KEEP}, + { THERMAL_LEVEL_POWEROFF, THERMAL_LEVEL_WARNING, NO_CHANGE, KEEP}, + { THERMAL_LEVEL_POWEROFF, THERMAL_LEVEL_CRITICAL, NO_CHANGE, KEEP}, + { THERMAL_LEVEL_POWEROFF, THERMAL_LEVEL_POWEROFF, NO_CHANGE, UPDATE} +}; + +static int thermal_state_check(int old_state, int new_state) +{ + int i, ret = -1; + + for (i = 0; i < ARRAY_SIZE(temp_state); i++) { + if (old_state == temp_state[i].old_state && + new_state == temp_state[i].new_state) { + ret = temp_state[i].status; + break; + } + } + + return ret; +} + +static void thermal_level_check(int old_level, int new_level, int *out_status, int *out_level) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(temp_level); i++) { + if (old_level == temp_level[i].old_level && + new_level == temp_level[i].new_level) { + *out_status = temp_level[i].status; + *out_level = temp_level[i].level; + break; + } + } +} + static void thermal_remove_noti(void) { if (noti) { @@ -39,6 +123,12 @@ static void thermal_remove_noti(void) } } +static void thermal_remove_popup(void) +{ + launch_system_app(APP_DEFAULT, 2, + APP_KEY_TYPE, "remove_cooldown_popups"); +} + static void thermal_add_noti(void) { if (!noti) @@ -51,38 +141,57 @@ static void thermal_add_popup(void) APP_KEY_TYPE, "overheat"); } +static void thermal_add_recovery_popup(void) +{ + launch_system_app(APP_DEFAULT, 2, + APP_KEY_TYPE, "cooled_down"); +} + static void thermal_action(struct thermal_info *info, void *data) { + static int old_state = -1, old_level = -1; + static int status, high_status, update; + if (!info) return; - switch (info->state) { - case THERMAL_STATE_LOW: - _E("THERMAL: temparature LOW"); - thermal_remove_noti(); - break; - case THERMAL_STATE_NORMAL: - _I("THERMAL: temparature normal"); + if (old_state < 0) { + old_state = info->state; + old_level = info->level; + } + + status = thermal_state_check(old_state, info->state); + + if (status == NO_CHANGE) + update = UPDATE; + else if (status == LOW_TO_HIGH) { thermal_remove_noti(); - break; - case THERMAL_STATE_HIGH: - if (info->level == THERMAL_LEVEL_WARNING) { - _E("THERMAL: temparature HIGH (warning)"); - thermal_add_noti(); - } else if (info->level == THERMAL_LEVEL_CRITICAL) { - _E("THERMAL: temparature HIGH (critical)"); + thermal_remove_popup(); + thermal_add_noti(); + update = UPDATE; + } else if (status == NEED_TO_CHECK) { + thermal_level_check(old_level, info->level, &high_status, &update); + _I("high_status = %d update = %d", high_status, update); + if (high_status == HIGH_TO_LOW) { + thermal_remove_popup(); thermal_remove_noti(); - thermal_add_popup(); - } else if (info->level == THERMAL_LEVEL_POWEROFF) { - _E("THERMAL: temparature HIGH (poweroff)"); + thermal_add_recovery_popup(); + } else if (high_status == HIGH_TO_CRITICAL) { thermal_remove_noti(); + thermal_remove_popup(); thermal_add_popup(); - } else - _E("THERMAL: temparature HIGH"); - break; - default: - break; + } + } + + if (update == UPDATE) { + old_state = info->state; + old_level = info->level; + } else { + old_state = old_state; + old_level = old_level; } + + _I("Last old_state = %d old_level=%d", old_state, old_level); } static int thermal_service_start(void) -- 2.7.4