From: taeyoung Date: Thu, 26 Nov 2015 13:05:36 +0000 (+0900) Subject: battery: add charge_status property X-Git-Tag: accepted/tizen/mobile/20151211.055150~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F52839%2F1;p=platform%2Fcore%2Fsystem%2Fdeviced.git battery: add charge_status property - charge_status is used for send system event. If charge_status is same as previous status, system event is not delivered. - In addition, application related codes are fixed to launch popup. Change-Id: I0ba02703c25eed91db4198f1ef7da2c8df7ec4cd Signed-off-by: taeyoung --- diff --git a/src/battery/battery.h b/src/battery/battery.h index e352e3c..f1496bb 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -37,8 +37,6 @@ struct battery_config_info { int critical; int poweroff; int realoff; - char warning_method[METHOD_NAME_MAX]; - char critical_method[METHOD_NAME_MAX]; }; int battery_charge_err_low_act(void *data); diff --git a/src/battery/config.c b/src/battery/config.c index 00d39ad..4dd42c1 100644 --- a/src/battery/config.c +++ b/src/battery/config.c @@ -59,12 +59,6 @@ static int load_config(struct parse_result *result, void *user_data) info->poweroff = atoi(value); else if (MATCH(name, "RealOff")) info->realoff = atoi(value); - else if (MATCH(name, "WarningMethod")) - snprintf(info->warning_method, - sizeof(info->warning_method), "%s", value); - else if (MATCH(name, "CriticalMethod")) - snprintf(info->critical_method, - sizeof(info->critical_method), "%s", value); return 0; } diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 4dbc660..cad1bf7 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "battery.h" #include "config.h" @@ -37,6 +39,7 @@ #include "display/poll.h" #include "core/edbus-handler.h" #include "power/power-handler.h" +#include "apps/apps.h" #include "power-supply.h" #define CHARGE_POWERSAVE_FREQ_ACT "charge_powersave_freq_act" @@ -79,8 +82,6 @@ static struct battery_config_info battery_info = { .critical = BATTERY_CRITICAL, .poweroff = BATTERY_POWEROFF, .realoff = BATTERY_REALOFF, - .warning_method = "warning", - .critical_method = "critical", }; static dd_list *lpe; @@ -251,25 +252,25 @@ static int lowbat_popup(char *option) launched_poweroff = 0; if (!strcmp(option, CRITICAL_LOW_BAT_ACT)) { - value = battery_info.critical_method; + value = "lowbattery_critical"; lowbat_popup_option = LOWBAT_OPT_CHECK; } else if (!strcmp(option, WARNING_LOW_BAT_ACT)) { - value = battery_info.warning_method; + value = "lowbattery_warning"; lowbat_popup_option = LOWBAT_OPT_WARNING; } else if (!strcmp(option, POWER_OFF_BAT_ACT)) { value = "poweroff"; lowbat_popup_option = LOWBAT_OPT_POWEROFF; } else if (!strcmp(option, CHARGE_ERROR_ACT)) { - value = "Charger error"; + value = "chargeerr"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_LOW_ACT)) { - value = "Charger low temperature error"; + value = "chargeerrlow"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_HIGH_ACT)) { - value = "Charger high temperature error"; + value = "chargeerrhigh"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_OVP_ACT)) { - value = "Charger ovp error"; + value = "chargeerrovp"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_CHECK_ACT)) { launched_poweroff = 0; @@ -290,6 +291,11 @@ direct_launch: if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) launched_poweroff = 1; + ret = launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, "remove_battery_popups"); + if (ret < 0) + _E("Failed to close all of battery popups"); + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); if ((r_disturb != 0 && r_block != 0) || @@ -299,9 +305,8 @@ direct_launch: else _I("block LCD"); - ret = manage_notification("Low battery", value); - if (ret == -1) - return -1; + return launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, value); } else { _D("boot-animation running yet"); } @@ -387,6 +392,36 @@ static void lowbat_scenario_init(void) lowbat_add_scenario(battery_info.realoff, battery_info.realoff, battery_power_off_act); } +static void battery_level_send_system_event(int bat_percent) +{ + bundle *b; + const char *str; + static const char *prev; + + if (bat_percent > BATTERY_LEVEL_CHECK_FULL) + str = EVT_VAL_BATTERY_LEVEL_FULL; + else if (bat_percent > BATTERY_LEVEL_CHECK_HIGH) + str = EVT_VAL_BATTERY_LEVEL_HIGH; + else if (bat_percent > BATTERY_LEVEL_CHECK_LOW) + str = EVT_VAL_BATTERY_LEVEL_LOW; + else if (bat_percent > BATTERY_LEVEL_CHECK_CRITICAL) + str = EVT_VAL_BATTERY_LEVEL_CRITICAL; + else + str = EVT_VAL_BATTERY_LEVEL_EMPTY; + + if (prev == str) + return; + + prev = str; + + _D("system_event(%s)", str); + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BATTERY_LEVEL_STATUS, str); + eventsystem_send_system_event(SYS_EVENT_BATTERY_LEVEL_STATUS, b); + bundle_free(b); +} + static void change_lowbat_level(int bat_percent) { int prev, now; @@ -430,6 +465,7 @@ static int lowbat_process(int bat_percent, void *ad) if (new_bat_capacity < 0) return -EINVAL; change_lowbat_level(new_bat_capacity); + battery_level_send_system_event(new_bat_capacity); if (new_bat_capacity != cur_bat_capacity) { _D("[BAT_MON] cur = %d new = %d", cur_bat_capacity, new_bat_capacity); @@ -532,6 +568,7 @@ static int check_lowbat_percent(int *pct) if (bat_percent > 100) bat_percent = 100; change_lowbat_level(bat_percent); + battery_level_send_system_event(bat_percent); *pct = bat_percent; return 0; } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 5b4e3b8..3a8d70a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -22,6 +22,9 @@ #include #include #include +#include +#include + #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" @@ -29,6 +32,7 @@ #include "core/config-parser.h" #include "display/poll.h" #include "display/setting.h" +#include "apps/apps.h" #include "power-supply.h" #include "battery.h" @@ -52,16 +56,9 @@ #define METHOD_FULL_NOTI_OFF "BatteryFullNotiOff" #define METHOD_CHARGE_NOTI_ON "BatteryChargeNotiOn" -#define CHARGE_SIOP_DISABLE_SIGNAL "SiopDisable" - #define RETRY_MAX 5 #define BATTERY_CHECK_TIMER_INTERVAL (0.5) -enum siop_disable_status_type { - SIOP_ENABLE = 0, - SIOP_DISABLE = 1, -}; - enum power_supply_init_type { POWER_SUPPLY_NOT_READY = 0, POWER_SUPPLY_INITIALIZED = 1, @@ -73,7 +70,6 @@ static const struct uevent_handler uh = { .uevent_func = uevent_power_handler, }; -static int siop_disable = SIOP_ENABLE; struct battery_status battery; static int noti_id; static Ecore_Timer *power_timer; @@ -101,16 +97,15 @@ static void pm_check_and_change(int bInserted) static int changed_battery_cf(enum present_type status) { - int ret; + char *value; - if (status != PRESENT_ABNORMAL) - return 0; - - ret = manage_notification("Battery disconnect", "Battery disconnect"); - if (ret < 0) - return -1; + if (status == PRESENT_ABNORMAL) + value = "battdisconnect"; + else + value = "remove_battery_popups"; - return 0; + return launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, value); } static void abnormal_popup_timer_init(void) @@ -142,7 +137,6 @@ static Eina_Bool health_timer_cb(void *data) return EINA_FALSE; _I("popup - Battery health status is not good"); - siop_disable = SIOP_DISABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); pm_change_internal(getpid(), LCD_NORMAL); pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); @@ -351,6 +345,38 @@ static void check_power_supply(int state) update_pm_setting(SETTING_CHARGING, state); } +static void charger_state_send_system_event(int state) +{ + bundle *b; + const char *str; + + switch (state) { + case CHARGE_STATUS_CHARGING: + str = EVT_VAL_BATTERY_CHARGER_CHARGING; + break; + case CHARGE_STATUS_FULL: + case CHARGE_STATUS_DISCHARGING: + str = EVT_VAL_BATTERY_CHARGER_DISCHARGING; + break; + case CHARGE_STATUS_CONNECTED: + str = EVT_VAL_BATTERY_CHARGER_CONNECTED; + break; + case CHARGE_STATUS_DISCONNECTED: + str = EVT_VAL_BATTERY_CHARGER_DISCONNECTED; + break; + default: + _E("invalid parameter(%d)", state); + return; + } + + _D("system_event(%s)", str); + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BATTERY_CHARGER_STATUS, str); + eventsystem_send_system_event(SYS_EVENT_BATTERY_CHARGER_STATUS, b); + bundle_free(b); +} + static void update_present(enum battery_noti_status status) { static int old = DEVICE_NOTI_OFF; @@ -385,7 +411,6 @@ static void update_health(enum battery_noti_status status) pm_change_internal(getpid(), LCD_NORMAL); if (status == DEVICE_NOTI_ON) { _I("popup - Battery health status is not good"); - siop_disable = SIOP_DISABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); if (battery.temp == TEMP_LOW) @@ -393,7 +418,6 @@ static void update_health(enum battery_noti_status status) else if (battery.temp == TEMP_HIGH) battery_charge_err_high_act(NULL); } else { - siop_disable = SIOP_ENABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_GOOD); pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); health_status_broadcast(); @@ -457,6 +481,13 @@ static void check_battery_status(void) static void check_online(void) { static int old_online; + static int old_charge_status; + int charge_status; + + if (battery.charge_status == CHARGE_STATUS_FULL) + charge_status = CHARGE_STATUS_DISCHARGING; + else + charge_status = battery.charge_status; if (battery.online > POWER_SUPPLY_TYPE_BATTERY && old_online == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) { @@ -464,33 +495,60 @@ static void check_online(void) vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); check_power_supply(old_online); + charger_state_send_system_event(CHARGE_STATUS_CONNECTED); + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); + } else if (battery.online <= POWER_SUPPLY_TYPE_BATTERY && old_online == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { old_online = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED; vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); check_power_supply(old_online); + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); + charger_state_send_system_event(CHARGE_STATUS_DISCONNECTED); + + } else { + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); } + + old_charge_status = charge_status; } static void check_charge_status(const char *env_value) { if (env_value == NULL) return; + + _D("Charge Status(%s)", env_value); + if (strncmp(env_value, CHARGEFULL_NAME, - sizeof(CHARGEFULL_NAME)) == 0) { + sizeof(CHARGEFULL_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_FULL; + else if (strncmp(env_value, CHARGENOW_NAME, + sizeof(CHARGENOW_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_CHARGING; + else if (strncmp(env_value, DISCHARGE_NAME, + sizeof(DISCHARGE_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_DISCHARGING; + else if (strncmp(env_value, NOTCHARGE_NAME, + sizeof(NOTCHARGE_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_NOT_CHARGING; + else + battery.charge_status = CHARGE_STATUS_UNKNOWN; + + if (battery.charge_status == CHARGE_STATUS_FULL) { battery.charge_full = CHARGING_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (strncmp(env_value, CHARGENOW_NAME, - sizeof(CHARGENOW_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_CHARGING; - } else if (strncmp(env_value, DISCHARGE_NAME, - sizeof(DISCHARGE_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_DISCHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (strncmp(env_value, NOTCHARGE_NAME, - sizeof(NOTCHARGE_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_NOT_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_ABNORMAL; } else { @@ -568,6 +626,7 @@ static void process_power_supply(void *data) old.capacity = battery.capacity; old.online = battery.online; + old.charge_status = battery.charge_status; old.charge_now = battery.charge_now; old.charge_full = battery.charge_full; @@ -666,10 +725,7 @@ static void power_supply_status_init(void) capacity == battery.capacity) return; - if (charge_now != battery.charge_now || - charge_full != battery.charge_full || - capacity != battery.capacity) - _I("charging %d full %d capacity %d", battery.charge_now, battery.charge_full, battery.capacity); + _I("charging %d full %d capacity %d", battery.charge_now, battery.charge_full, battery.capacity); if (charge_now != battery.charge_now) { vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); @@ -812,20 +868,6 @@ static DBusMessage *dbus_get_health(E_DBus_Object *obj, DBusMessage *msg) return reply; } -static DBusMessage *dbus_get_siop_disable_status(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = siop_disable; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - static DBusMessage *dbus_power_supply_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; @@ -901,7 +943,6 @@ static const struct edbus_method edbus_methods[] = { { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw }, { CHARGE_FULL_SIGNAL, NULL, "i", dbus_is_full }, { CHARGE_HEALTH_SIGNAL, NULL, "i", dbus_get_health }, - { CHARGE_SIOP_DISABLE_SIGNAL, NULL, "i", dbus_get_siop_disable_status }, { POWER_SUBSYSTEM, "sisssss", "i", dbus_power_supply_handler }, }; diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h index 387af81..47df1e2 100644 --- a/src/battery/power-supply.h +++ b/src/battery/power-supply.h @@ -25,6 +25,15 @@ enum device_change_type { DEVICE_CHANGE_NORMAL = 1, }; +enum charge_status_type { + CHARGE_STATUS_UNKNOWN, + CHARGE_STATUS_DISCONNECTED, + CHARGE_STATUS_CONNECTED, + CHARGE_STATUS_CHARGING, + CHARGE_STATUS_DISCHARGING, + CHARGE_STATUS_NOT_CHARGING, + CHARGE_STATUS_FULL, +}; enum charge_full_type { CHARGING_NOT_FULL = 0, CHARGING_FULL = 1, @@ -68,6 +77,7 @@ enum battery_noti_status { struct battery_status { int capacity; + int charge_status; int charge_full; int charge_now; int health; diff --git a/src/core/udev.h b/src/core/udev.h index f6aa3f8..e3f4ac6 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -34,8 +34,6 @@ #define POWER_PATH "/sys/class/power_supply/battery" #define POWER_SUPPLY_UEVENT POWER_PATH"/uevent" #define CAPACITY "POWER_SUPPLY_CAPACITY" -#define CHARGE_FULL "POWER_SUPPLY_CHARGE_FULL" -#define CHARGE_NOW "POWER_SUPPLY_CHARGE_NOW" #define CHARGE_HEALTH "POWER_SUPPLY_HEALTH" #define CHARGE_PRESENT "POWER_SUPPLY_PRESENT" #define CHARGE_NAME "POWER_SUPPLY_NAME"