battery: rename battery.online as charger_connected 36/270236/7
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 27 Jan 2022 01:46:10 +0000 (17:46 -0800)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 3 Feb 2022 05:19:09 +0000 (14:19 +0900)
 The charger_connected has changed to have only a value of 0 or 1,
which corresponds to charger disconnected/connected. At before, the
variable can have any integer other than 0 or 1, which implied which
type of charger had been connected. Instead of those integers, the
power_source_s or vconf can be utilized for charger type.
 The vconf, VCONFKEY_SYSMAN_CHARGER_TYPE, which was exclusive for MCD
product profile, has changed to have a one of the value belows, and it
will be changed according to battery.power_source_s.
    0 (none, charger disconnected or unknown type)
    1 (ac)
    2 (usb)
    3 (wireless)

Change-Id: I8ff4751e521585f94cd421a0edeba04651094bce
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/battery/lowbat-handler.c
src/battery/lowbat-handler.h
src/battery/power-supply.c
src/battery/power-supply.h
src/core/udev.h
src/touchscreen/touchscreen.c
tests/auto-test/battery.c

index fd8cfed..56a4959 100644 (file)
@@ -89,6 +89,7 @@ static int scenario_count;
 
 static guint low_batt_sig_timer;
 
+static int uevent_buffering = 0;
 static int lowbat_monitor_init(void *data);
 
 static int lowbat_initialized(void *data)
@@ -435,13 +436,13 @@ static void lowbat_custom_popup(int online, int capacity)
                custom_warning_launch = false;
                return;
        }
-       if (online == battery->online && custom_warning_launch)
+       if (online == battery->charger_connected && custom_warning_launch)
                return;
-       if (battery->online > POWER_SUPPLY_TYPE_BATTERY && custom_warning_launch)
+       if (battery->charger_connected == 1 && custom_warning_launch)
                return;
 
        custom_warning_launch = true;
-       _I("Launch custom lowbattery warning popup. online(%d, %d), capacity(%d, %d)", online, battery->online, capacity, custom_warning_level);
+       _I("Launch custom lowbattery warning popup. online(%d, %d), capacity(%d, %d)", online, battery->charger_connected, capacity, custom_warning_level);
        (void)battery_warning_low_act(NULL);
 }
 
@@ -499,7 +500,7 @@ static int lowbat_process(int bat_percent, void *ad)
        if (new_bat_capacity <= battery_info.realoff) {
                if (battery->charge_now == CHARGER_CHARGING || battery->charger_charging == CHARGER_DISABLED) {
                        _I("Skip lowbat poweroff during test (c:%d charge:%d online:%d charger_charging:%d)",
-                               battery->capacity, battery->charge_now, battery->online, battery->charger_charging);
+                               battery->capacity, battery->charge_now, battery->charger_connected, battery->charger_charging);
                        new_bat_state = battery_info.poweroff;
                        if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF)
                                status = VCONFKEY_SYSMAN_BAT_POWER_OFF;
@@ -543,7 +544,7 @@ static int lowbat_process(int bat_percent, void *ad)
                        new_bat_state = battery_info.realoff;
                        status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF;
                        _I("Go to real poweroff inspite of charging (c:%d charge:%d online:%d charger_charging %d current now %d)",
-                               battery->capacity, battery->charge_now, battery->online, battery->charger_charging, battery->current_now);
+                               battery->capacity, battery->charge_now, battery->charger_connected, battery->charger_charging, battery->current_now);
                        low_bat_skip_cnt = 0;
                } else if (battery->current_now <= MIN_INOW_VALUE) {
                        low_bat_skip_cnt++;
@@ -571,12 +572,12 @@ static int lowbat_process(int bat_percent, void *ad)
                low_bat_old = low_bat;
        }
 
-       if (battery->online == POWER_SUPPLY_TYPE_UNKNOWN)
+       if (battery->charger_connected == -1)
                return result;
-       if (cur_bat_state == new_bat_state && online == battery->online)
+       if (cur_bat_state == new_bat_state && online == battery->charger_connected)
                return result;
 
-       online = battery->online;
+       online = battery->charger_connected;
        if (cur_bat_state == BATTERY_UNKNOWN)
                cur_bat_state = battery_info.normal;
        if (lowbat_scenario(cur_bat_state, new_bat_state, NULL))
@@ -766,7 +767,7 @@ static int lowbat_execute(void *data)
        /* Do lowbat_process immediately rather deferring it when poweroff is needed.
         * This prevents poweroff from being delayed infinitely when the uevent continues
         * to occur shorter than 1.5 seconds on realoff capacity */
-       if (capacity <= battery_info.realoff)
+       if (capacity <= battery_info.realoff || !uevent_buffering)
                low_battery_charge_status(data);
        else
                low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data);
@@ -774,6 +775,16 @@ static int lowbat_execute(void *data)
        return 0;
 }
 
+void lowbat_enable_uevent_buffering(void)
+{
+       uevent_buffering = 1;
+}
+
+void lowbat_disable_uevent_buffering(void)
+{
+       uevent_buffering = 0;
+}
+
 static const struct device_ops lowbat_device_ops = {
        DECLARE_NAME_LEN("lowbat"),
        .probe    = lowbat_probe,
index 4c54fbd..26ead12 100644 (file)
@@ -23,6 +23,8 @@
 #define RETRY_MAX                5
 
 int lowbat_popup(int option);
+void lowbat_enable_uevent_buffering(void);
+void lowbat_disable_uevent_buffering(void);
 extern struct battery_config_info battery_info;
 
 #endif /* __LOWBAT_HANDLER_H__ */
index cddbe9a..08f00cd 100644 (file)
@@ -41,6 +41,7 @@
 #include "battery.h"
 #include "battery-ops.h"
 #include "extcon/extcon.h"
+#include "lowbat-handler.h"
 
 #ifndef VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL
 #define VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL "db/setting/blockmode_wearable"
@@ -94,7 +95,6 @@ static const struct uevent_handler uh = {
 static struct battery_status battery;
 struct battery_status old_battery;
 static int noti_id;
-static int online_status = -1;
 static int abnormal_health_popup_timer;
 static bool launching_health_popup;
 
@@ -411,14 +411,6 @@ static void charger_state_send_system_event(int state)
                str = EVT_VAL_BATTERY_CHARGER_DISCHARGING;
                CRITICAL_LOG("Battery charger: %s", str);
                break;
-       case CHARGE_STATUS_CONNECTED:
-               str = EVT_VAL_BATTERY_CHARGER_CONNECTED;
-               CRITICAL_LOG("Battery charger: %s", str);
-               break;
-       case CHARGE_STATUS_DISCONNECTED:
-               str = EVT_VAL_BATTERY_CHARGER_DISCONNECTED;
-               CRITICAL_LOG("Battery charger: %s", str);
-               break;
        default:
                _E("Invalid parameter: %d", state);
                return;
@@ -554,61 +546,6 @@ static void check_abnormal_status(void)
        }
 }
 
-static bool update_online(void)
-{
-       int chg_on;
-       int ret_val;
-       bool broadcast = false;
-
-       if (battery.online <= POWER_SUPPLY_TYPE_BATTERY &&
-           battery.charger_charging == CHARGER_DISABLED) {
-               battery.charger_charging = CHARGER_ENABLED;
-               ret_val = sys_get_int(CHARGER_CHARGE_ON_NODE, &chg_on);
-               if (ret_val == 0 && battery.charger_charging != chg_on) {
-                       ret_val = sys_set_int(CHARGER_CHARGE_ON_NODE, battery.charger_charging);
-                       _I("%s to change status with %d", ((ret_val == 0) ? "success" : "fail"), battery.charger_charging);
-               }
-       }
-
-       if (battery.online > POWER_SUPPLY_TYPE_BATTERY &&
-           online_status != VCONFKEY_SYSMAN_CHARGER_CONNECTED) {
-               online_status = VCONFKEY_SYSMAN_CHARGER_CONNECTED;
-               extcon_update_count(EXTCON_TA, 1);
-               check_power_supply(online_status);
-               charger_state_send_system_event(CHARGE_STATUS_CONNECTED);
-               device_notify(DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED, NULL);
-               if (old_battery.charge_status != battery.charge_status)
-                       charger_state_send_system_event(battery.charge_status);
-               broadcast = true;
-       } else if (battery.online <= POWER_SUPPLY_TYPE_BATTERY &&
-           online_status != VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) {
-               online_status = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED;
-               check_power_supply(online_status);
-               if (old_battery.charge_status != battery.charge_status)
-                       charger_state_send_system_event(battery.charge_status);
-               charger_state_send_system_event(CHARGE_STATUS_DISCONNECTED);
-               device_notify(DEVICE_NOTIFIER_BATTERY_CHARGER_DISCONNECTED, NULL);
-               broadcast = true;
-       } else {
-               if (old_battery.charge_status != battery.charge_status)
-                       charger_state_send_system_event(battery.charge_status);
-       }
-
-       if (battery.online <= POWER_SUPPLY_TYPE_BATTERY)
-               battery.online_type = CHARGER_TYPE_NONE;
-       else if (battery.online == CHARGER_WIRELESS_TYPE_BT ||
-           battery.online == CHARGER_WIRELESS_TYPE_3G)
-               battery.online_type = CHARGER_TYPE_WIRELESS;
-       else if (battery.online == CHARGER_INCOMPATIBLE_TYPE)
-               battery.online_type = CHARGER_TYPE_INCOMPATIBLE;
-       else if (battery.online == CHARGER_D2D_TYPE)
-               battery.online_type = CHARGER_TYPE_D2D;
-       else
-               battery.online_type = CHARGER_TYPE_WIRE;
-
-       return broadcast;
-}
-
 static void check_charge_status(const char *env_value)
 {
        int len;
@@ -670,6 +607,27 @@ static void check_health_status(const char *env_value)
                battery.health = HEALTH_NO_OPT;
 }
 
+static void check_power_source(const char *env_value)
+{
+       int maxlen = sizeof(battery.power_source_s);
+
+       if (!env_value)
+               return;
+
+       snprintf(battery.power_source_s, maxlen, "%s", env_value);
+       battery.power_source_s[maxlen - 1] = '\0';
+
+       if (strncmp(battery.power_source_s, "ac", sizeof("ac")) == 0) {
+               battery.online_type = CHARGER_TYPE_AC;
+       } else if (strncmp(battery.power_source_s, "usb", sizeof("usb")) == 0) {
+               battery.online_type = CHARGER_TYPE_USB;
+       } else if (strncmp(battery.power_source_s, "wireless", sizeof("wireless")) == 0) {
+               battery.online_type = CHARGER_TYPE_WIRELESS;
+       } else {
+               battery.online_type = CHARGER_TYPE_NONE;
+       }
+}
+
 static void check_misc_status(const char *env_value)
 {
        if (env_value == NULL) {
@@ -679,11 +637,11 @@ static void check_misc_status(const char *env_value)
        battery.misc = atoi(env_value);
 }
 
-static void check_online_status(const char *env_value)
+static void check_online_type(const char *env_value)
 {
        if (env_value == NULL)
                return;
-       battery.online = atoi(env_value);
+       battery.charger_connected = atoi(env_value);
 }
 
 static void check_present_status(const char *env_value)
@@ -714,8 +672,8 @@ static void update_capacity_full(void)
        static int old;
        int delta;
 
-       if (battery.online <= POWER_SUPPLY_TYPE_BATTERY ||
-           old == 0 ||
+       if (battery.charger_connected == 0 ||
+               old == 0 ||
            old >= battery.capacity) {
                old = battery.capacity;
                return;
@@ -737,7 +695,7 @@ static void update_battery_cycle(void)
                return;
        }
 
-       if (battery.online > POWER_SUPPLY_TYPE_BATTERY ||
+       if (battery.charger_connected == 1 ||
            old == 0 ||
            old <= battery.capacity) {
                old = battery.capacity;
@@ -793,15 +751,27 @@ static void process_power_supply(void *data)
 
        (void)lowbat_execute(data);
 
-       if (update_online()) {
-               ret_val = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, online_status);
+       if (old_battery.charger_connected != battery.charger_connected) {
+               check_power_supply(battery.charger_connected);
+               ret_val = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, battery.charger_connected);
                if (ret_val < 0)
                        _E("Failed to set vconf value for charger status: %d", vconf_get_ext_errno());
-
-               if (power_supply_broadcast(CHARGER_STATUS_SIGNAL, online_status) < 0)
-                       broadcasted = false;
+               if (battery.charger_connected == 0) {
+                       CRITICAL_LOG("Battery charger disconnected");
+                       event_system_send(SYS_EVENT_BATTERY_CHARGER_STATUS, EVT_KEY_BATTERY_CHARGER_STATUS, EVT_VAL_BATTERY_CHARGER_CONNECTED);
+                       device_notify(DEVICE_NOTIFIER_BATTERY_CHARGER_DISCONNECTED, NULL);
+               } else if (battery.charger_connected == 1) {
+                       CRITICAL_LOG("Battery charger connected");
+                       event_system_send(SYS_EVENT_BATTERY_CHARGER_STATUS, EVT_KEY_BATTERY_CHARGER_STATUS, EVT_VAL_BATTERY_CHARGER_DISCONNECTED);
+                       device_notify(DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED, NULL);
+               } else {
+                       _E("Invalid charger connected");
+               }
        }
 
+       if (old_battery.charge_status != battery.charge_status)
+               charger_state_send_system_event(battery.charge_status);
+
        if (old_battery.online_type != battery.online_type) {
                ret_val = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_TYPE, battery.online_type);
                if (ret_val < 0)
@@ -831,7 +801,7 @@ static void process_power_supply(void *data)
                old_battery.online_type != battery.online_type)
                _I("Signal(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d : %s) %s(%d)",
                        broadcasted,
-                       CHARGER_STATUS_SIGNAL, online_status,
+                       CHARGER_STATUS_SIGNAL, battery.charger_connected,
                        CHARGER_TYPE_SIGNAL, battery.online_type,
                        CHARGE_NOW_SIGNAL, battery.charge_now,
                        CHARGE_FULL_SIGNAL, battery.charge_full,
@@ -843,7 +813,7 @@ static void process_power_supply(void *data)
 
        old_battery.capacity = battery.capacity;
        old_battery.charging_level = battery.charging_level;
-       old_battery.online = battery.online;
+       old_battery.charger_connected = battery.charger_connected;
        old_battery.online_type = battery.online_type;
        old_battery.charge_status = battery.charge_status;
        old_battery.charge_full = battery.charge_full;
@@ -901,7 +871,7 @@ static void uevent_power_handler(struct udev_device *dev)
        env_value = udev_device_get_property_value(dev, CHARGE_STATUS);
        check_charge_status(env_value);
        env_value = udev_device_get_property_value(dev, CHARGE_ONLINE);
-       check_online_status(env_value);
+       check_online_type(env_value);
        env_value = udev_device_get_property_value(dev, CHARGE_HEALTH);
        check_health_status(env_value);
        env_value = udev_device_get_property_value(dev, CHARGE_MISC_EVENT);
@@ -913,11 +883,18 @@ static void uevent_power_handler(struct udev_device *dev)
        env_value = udev_device_get_property_value(dev, TEMPERATURE);
        check_temperature_status(env_value);
 
+       /* The uevent property or HAL API for charger_type is not supported. Therefore,
+        * use pseudo value for the online_type according to charger connectivity. */
+       if (battery.charger_connected == 0)
+               battery.online_type = CHARGER_TYPE_NONE;
+       else if (battery.charger_connected == 1)
+               battery.online_type = CHARGER_TYPE_USB;
+
        battery_initialized = true;
 
        ret_val = delayed_init_done(NULL);
        if (ret_val) {
-               if (battery.online > POWER_SUPPLY_TYPE_BATTERY)
+               if (battery.charger_connected == 1)
                        power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON);
                else
                        power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_OFF);
@@ -937,11 +914,12 @@ static int battery_state(struct battery_info *info)
 
        if (battery.capacity != 0 && prev_status.capacity == battery.capacity &&
            prev_status.charge_status == battery.charge_status &&
+               prev_status.online_type == battery.online_type &&
            prev_status.charge_full == battery.charge_full &&
            prev_status.charge_now == battery.charge_now &&
            prev_status.health == battery.health &&
            prev_status.present == battery.present &&
-           prev_status.online == battery.online &&
+           prev_status.charger_connected == battery.charger_connected &&
                prev_status.freq_strength == battery.freq_strength)
                return 0;
 
@@ -951,7 +929,7 @@ static int battery_state(struct battery_info *info)
        prev_status.charge_now = battery.charge_now;
        prev_status.health = battery.health;
        prev_status.present = battery.present;
-       prev_status.online = battery.online;
+       prev_status.charger_connected = battery.charger_connected;
        prev_status.freq_strength = battery.freq_strength;
 
        _I("%s(%s) %s(%d) Capa(%d) Hth(%s,%d) Pres(%d) Curr(%d,%d)",
@@ -972,21 +950,28 @@ static int battery_state(struct battery_info *info)
 static void battery_invalidate_vconf(int value)
 {
        int retval;
-       const char *vconf[] = {
-               VCONFKEY_SYSMAN_BATTERY_CAPACITY,
-               VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
-               VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
-               VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+       static const struct invalidate_list {
+               const char *vconfkey;
+               int *member;
+       } list[] = {
+               { VCONFKEY_SYSMAN_BATTERY_CAPACITY, &old_battery.capacity },
+               { VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &old_battery.charging_level },
+               { VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &old_battery.charge_now },
+               { VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, NULL },
        };
 
-       _D("Invalidate battery vconfs to %d", value);
+       _D("Invalidate battery value to %d", value);
 
-       for (int i = 0; i < ARRAY_SIZE(vconf); ++i) {
-               retval = vconf_set_int(vconf[i], value);
-               if (retval == 0)
-                       _D("Set vconf %s to %d", vconf[i], value);
-               else
-                       _E("Failed to set %s to %d, %d", vconf[i], value, retval);
+       for (int i = 0; i < ARRAY_SIZE(list); ++i) {
+               if (list[i].vconfkey) {
+                       retval = vconf_set_int(list[i].vconfkey, value);
+                       if (retval == 0)
+                               _D("Set vconf %s to %d", list[i].vconfkey, value);
+                       else
+                               _E("Failed to set %s to %d, %d", list[i].vconfkey, value, retval);
+               }
+               if (list[i].member)
+                       *(list[i].member) = value;
        }
 }
 
@@ -1014,12 +999,11 @@ static void battery_changed(struct battery_info *info, void *data)
                battery.health_s[0] = '\0';
 
        if (info->power_source)
-               snprintf(battery.power_source_s, sizeof(battery.power_source_s),
-                               "%s", info->power_source);
+               check_power_source(info->power_source);
        else
                battery.power_source_s[0] = '\0';
 
-       battery.online = info->online;
+       battery.charger_connected = info->online;
        battery.present = info->present;
        battery.capacity = info->capacity;
        battery.current_now = info->current_now;
@@ -1154,8 +1138,8 @@ static GVariant *dbus_charger_charging(GDBusConnection *conn,
                ret = -EINVAL;
                goto out;
        }
-       if (battery.online <= POWER_SUPPLY_TYPE_BATTERY) {
-               _E("There is no charger(%d) input(%d).", battery.online, battery.charger_charging);
+       if (battery.charger_connected == 0) {
+               _E("There is no charger(%d) input(%d).", battery.charger_connected, battery.charger_charging);
                ret = -EACCES;
                goto out;
        }
@@ -1266,11 +1250,16 @@ static GVariant *dbus_get_power_supply_handler(GDBusConnection *conn,
        const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
        GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
+       /* This method is for getting battery state after battery modification
+        * by battery test driver. At this point, restore uevent buffering, which
+        * had been disabled by test driver. */
+       lowbat_enable_uevent_buffering();
+
        return g_variant_new("(iiiiiiiisiiiii)", 0,
                                battery.capacity,
                                battery.charge_status,
                                battery.health,
-                               battery.online,
+                               battery.charger_connected,
                                battery.present,
                                battery.misc,
                                battery.freq_strength,
@@ -1288,16 +1277,17 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
 {
        pid_t pid;
        int ret = 0, argc = 0;
+       int charger_connected;
        char *type_str;
        char *argv[13];
        struct battery_info info = {0, };
 
-       g_variant_get(param, "(sisssssssssssss)", &type_str,
+       g_variant_get(param, "(sisssisssssssss)", &type_str,
                                &argc,
                                &argv[0],
                                &argv[1],
                                &argv[2],
-                               &argv[3],
+                               &charger_connected,
                                &argv[4],
                                &argv[5],
                                &argv[6],
@@ -1321,10 +1311,16 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
                goto out;
        }
 
+       /* The battery change triggered by this dbus must be processed
+        * within a single subroutine as the objective of this method call is mostly
+        * for the testing. Therefore, do not buffering the mocked uevent so that make
+        * the test driver can get the changed battery result without waiting */
+       lowbat_disable_uevent_buffering();
+
        info.capacity = atoi(argv[0]);
        info.status = strdup(argv[1]);
        info.health = strdup(argv[2]);
-       info.online = atoi(argv[3]);
+       info.online = charger_connected;
        info.present = atoi(argv[4]);
        check_misc_status(argv[5]);
        info.freq_strength = atoi(argv[6]);
@@ -1340,6 +1336,7 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
        if (battery_dev_available)
                battery_changed(&info, NULL);
 
+       /*
        snprintf(battery.status_s, sizeof(battery.status_s), "%s",
                        (battery.charge_now == CHARGER_CHARGING) ? "Charging" :
                        (battery.charge_now == CHARGER_ABNORMAL) ? "Not Charging" :
@@ -1353,8 +1350,9 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
                battery.charge_now,
                argv[2],
                battery.health,
-               argv[3],
-               battery.online,
+               //argv[3],
+               "charger_connected",
+               battery.charger_connected,
                argv[4],
                battery.present,
                argv[5],
@@ -1375,18 +1373,19 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
                argv[12],
                battery.temperature);
 
-       if (battery.online > POWER_SUPPLY_TYPE_BATTERY)
+       if (battery.charger_connected == 1)
                power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON);
        else
                power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_OFF);
 
-       process_power_supply(&battery.capacity);
+       //process_power_supply(&battery.capacity);
+       */
 out:
        g_free(type_str);
        g_free(argv[0]);
        g_free(argv[1]);
        g_free(argv[2]);
-       g_free(argv[3]);
+       //g_free(argv[3]);
        g_free(argv[4]);
        g_free(argv[5]);
        g_free(argv[6]);
@@ -1469,7 +1468,7 @@ out:
                                battery.status_s,
                                battery.health_s,
                                battery.power_source_s,
-                               battery.online,
+                               battery.charger_connected,
                                battery.present,
                                battery.capacity,
                                battery.current_now,
@@ -1508,7 +1507,7 @@ static const dbus_method_s dbus_methods[] = {
        { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw },
        { CHARGE_FULL_SIGNAL,         NULL, "i", dbus_is_full },
        { CHARGE_HEALTH_SIGNAL,        NULL, "s", dbus_get_health },
-       { POWER_SUBSYSTEM,      "sisssssssssssss", "i", dbus_power_supply_handler },
+       { POWER_SUBSYSTEM,      "sisssisssssssss", "i", dbus_power_supply_handler },
        { GET_POWER_SUBSYSTEM,      NULL, "iiiiiiiisiiiii", dbus_get_power_supply_handler },
        { "GetBatteryInfo",           NULL, "isssiiiiiiii", dbus_get_battery_info },
        { CHARGER_TYPE_SIGNAL,         NULL, "i", dbus_get_charger_type },
@@ -1540,7 +1539,7 @@ static int delayed_init_done(void *data)
        event_handler_state_changed((void *)&state);
 
        _I("booting done %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d) %s(%d : %s)",
-                       CHARGER_STATUS_SIGNAL, online_status,
+                       CHARGER_STATUS_SIGNAL, battery.charger_connected,
                        CHARGE_NOW_SIGNAL, battery.charge_now,
                        CHARGE_FULL_SIGNAL, battery.charge_full,
                        CHARGE_CAPACITY_SIGNAL, battery.capacity,
@@ -1723,6 +1722,7 @@ static void power_supply_init(void *data)
        battery.charger_charging = CHARGER_ENABLED;
        battery.misc = MISC_NONE;
        battery.freq_strength = 0;
+       battery.charger_connected = -1;
 
        /* It will be true on initializing battery structure */
        battery_initialized = false;
index 84c459c..547a2d2 100644 (file)
@@ -32,8 +32,6 @@ enum device_change_type {
 
 enum charge_status_type {
        CHARGE_STATUS_UNKNOWN,
-       CHARGE_STATUS_DISCONNECTED,
-       CHARGE_STATUS_CONNECTED,
        CHARGE_STATUS_CHARGING,
        CHARGE_STATUS_DISCHARGING,
        CHARGE_STATUS_NOT_CHARGING,
@@ -89,10 +87,9 @@ enum charger_charging_status {
 
 enum charger_type {
        CHARGER_TYPE_NONE = 0,
-       CHARGER_TYPE_WIRE,
+       CHARGER_TYPE_AC,
+       CHARGER_TYPE_USB,
        CHARGER_TYPE_WIRELESS,
-       CHARGER_TYPE_INCOMPATIBLE,
-       CHARGER_TYPE_D2D,
 };
 
 struct battery_status {
@@ -104,7 +101,7 @@ struct battery_status {
        int present;
        int voltage_now;
        int voltage_average;
-       int online;
+       int charger_connected;
        int online_type;
        int temperature;
        int current_now;
index f45d03e..34361b2 100644 (file)
@@ -76,14 +76,6 @@ enum {
        POWER_SUPPLY_STATUS_FULL,
 };
 
-enum {
-        POWER_SUPPLY_TYPE_UNKNOWN = 0,
-        POWER_SUPPLY_TYPE_BATTERY,
-        POWER_SUPPLY_TYPE_UPS,
-        POWER_SUPPLY_TYPE_MAINS,
-        POWER_SUPPLY_TYPE_USB,
-};
-
 enum dock_type {
        DOCK_NONE   = 0,
        DOCK_SOUND  = 7,
index 83b78a7..c642203 100644 (file)
@@ -218,8 +218,8 @@ static int touchscreen_stop(enum device_flags flags)
                return touchscreen_set_state(TOUCHSCREEN_OFF);
        }
 
-       if (battery && battery->online_type >= CHARGER_TYPE_WIRE) {
-               _I("Battery charging one %d %d.", battery->online, battery->online_type);
+       if (battery && battery->charger_connected == 1) {
+               _I("Battery charging one %d %d.", battery->charger_connected, battery->online_type);
                return touchscreen_powersaving(POWERSAVING_ON);
        }
 
index 10c44e0..1e8a1f7 100644 (file)
 #define TEMPCOLD       "Cold"
 #define OVERVOLT       "Over voltage"
 
-//Power Source
-#define TYPE_UNKNOWN   "0"
-#define TYPE_BATTERY   "1"
-#define TYPE_UPS       "2"
-#define TYPE_MAINS     "3"
-#define TYPE_USB       "4"
-
 //External Power Source
 #define AC             "ac"
 #define USB            "usb"
 
 enum charge_status_type {
        CHARGE_STATUS_UNKNOWN,
-       CHARGE_STATUS_DISCONNECTED,
-       CHARGE_STATUS_CONNECTED,
        CHARGE_STATUS_CHARGING,
        CHARGE_STATUS_DISCHARGING,
        CHARGE_STATUS_NOT_CHARGING,
@@ -135,10 +126,9 @@ enum health_type {
 
 enum charger_type {
        CHARGER_TYPE_NONE = 0,
-       CHARGER_TYPE_WIRE,
+       CHARGER_TYPE_AC,
+       CHARGER_TYPE_USB,
        CHARGER_TYPE_WIRELESS,
-       CHARGER_TYPE_INCOMPATIBLE,
-       CHARGER_TYPE_D2D,
 };
 
 static struct power_supply_type {
@@ -147,7 +137,7 @@ static struct power_supply_type {
        const char *capacity;
        const char *charge_status;
        const char *health;
-       const char *online;
+       const int online;
        const char *present;
        const char *power_source;
        const char *voltage_now;
@@ -159,64 +149,64 @@ static struct power_supply_type {
        const char *freq_strength;
        const char *name;
 } power_supply_types[] = {
-       {"norm",  S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},
-       {"norm",  S_ENTER, "100", DISCHARGE, GOOD,         TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"norm",  S_LEAVE, "100", DISCHARGE, GOOD,         TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-       {"heat1", S_ENTER, "100", DISCHARGE, OVERHEAT, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL},
-       {"heat1", S_ENTER, "100", NOTCHARGE, OVERHEAT, TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "HEALTH(H) BEFORE CHARGE"},
-       {"heat1", S_LEAVE, "100", DISCHARGE, OVERHEAT, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"heat1", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"heat2", S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_800, MISC_NORMAL, LEVEL_0, NULL},
-       {"heat2", S_ENTER, "100", NOTCHARGE, OVERHEAT, TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "HEALTH(H) AFTER CHARGE"},
-       {"heat2", S_LEAVE, "100", DISCHARGE, OVERHEAT, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"heat2", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"cold1", S_ENTER, "100", DISCHARGE, TEMPCOLD, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL},
-       {"cold1", S_ENTER, "100", NOTCHARGE, TEMPCOLD, TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "HEALTH(L) BEFORE CHARGE"},
-       {"cold1", S_LEAVE, "100", DISCHARGE, TEMPCOLD, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"cold1", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"cold2", S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_0,   MISC_NORMAL, LEVEL_0, NULL},
-       {"cold2", S_ENTER, "100", NOTCHARGE, TEMPCOLD, TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "HEALTH(L) AFTER CHARGE"},
-       {"cold2", S_LEAVE, "100", DISCHARGE, TEMPCOLD, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"cold2", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"ovp",   S_ENTER, "100", DISCHARGE, OVERVOLT, TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "OVP"},
-       {"ovp",   S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"pres1", S_ENTER, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL},
-       {"pres1", S_ENTER, "100", NOTCHARGE, GOOD,     TYPE_UPS,      PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "PRESENT BEFORE CHARGE"},
-       {"pres1", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_ABNORMAL, NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"pres1", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"pres2", S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, NULL},
-       {"pres2", S_ENTER, "100", NOTCHARGE, GOOD,     TYPE_UPS,      PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "PRESENT AFTER CHARGE"},
-       {"pres2", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_ABNORMAL, NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
-       {"pres2", S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
-
-       {"bat15", S_ENTER, "15",  DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_3P6, VOLT_3P6, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 15%"}, /* lowbat 15% */
-       {"bat15", S_LEAVE, "15",  CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   NONE,     VOLT_3P6, VOLT_3P6, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 15%"},
-       {"bat5",  S_ENTER, "5",   DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_3P4, VOLT_3P4, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 5%"},  /* lowbat 5% */
-       {"bat5",  S_LEAVE, "5",   CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   NONE,     VOLT_3P4, VOLT_3P4, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 5%"},
-       {"bat3",  S_ENTER, "3",   DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_3P2, VOLT_3P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 3%"},  /* lowbat 3% */
-       {"bat3",  S_LEAVE, "3",   CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   NONE,     VOLT_3P2, VOLT_3P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 3%"},
-       {"bat1",  S_ENTER, "1",   DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   NONE,     VOLT_3P0, VOLT_3P0, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 1%"},  /* lowbat 1% */
-       {"bat1",  S_LEAVE, "1",   CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   NONE,     VOLT_3P0, VOLT_3P0, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 1%"},
-
-       {"ta",    S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},   /* charging */
-       {"ta",    S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},/* discharging */
-
-       {"full",  S_ENTER, "100", CHARGEFULL, GOOD,    TYPE_UPS,      PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},   /* full */
-       {"full",  S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},/* discharging */
-
-       {"capa",  S_ENTER, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "CAPACITY"},/* discharging */
-       {"capa",  S_LEAVE, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CAPACITY"},/* charging */
-
-       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},
-       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_1, "FREQ LEVEL 1 AFTER CHARGE"},
-       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     TYPE_UPS,      PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_2, "FREQ LEVEL 2 AFTER CHARGE"},
-       {"freq",  S_LEAVE, "100", DISCHARGE, GOOD,     TYPE_BATTERY,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"}, /* init */
+       {"norm",  S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},
+       {"norm",  S_ENTER, "100", DISCHARGE, GOOD,         0,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"norm",  S_LEAVE, "100", DISCHARGE, GOOD,         0,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+       {"heat1", S_ENTER, "100", DISCHARGE, OVERHEAT, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL},
+       {"heat1", S_ENTER, "100", NOTCHARGE, OVERHEAT, 1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "HEALTH(H) BEFORE CHARGE"},
+       {"heat1", S_LEAVE, "100", DISCHARGE, OVERHEAT, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"heat1", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"heat2", S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_800, MISC_NORMAL, LEVEL_0, NULL},
+       {"heat2", S_ENTER, "100", NOTCHARGE, OVERHEAT, 1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "HEALTH(H) AFTER CHARGE"},
+       {"heat2", S_LEAVE, "100", DISCHARGE, OVERHEAT, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"heat2", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_800, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"cold1", S_ENTER, "100", DISCHARGE, TEMPCOLD, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL},
+       {"cold1", S_ENTER, "100", NOTCHARGE, TEMPCOLD, 1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "HEALTH(L) BEFORE CHARGE"},
+       {"cold1", S_LEAVE, "100", DISCHARGE, TEMPCOLD, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"cold1", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"cold2", S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_0,   MISC_NORMAL, LEVEL_0, NULL},
+       {"cold2", S_ENTER, "100", NOTCHARGE, TEMPCOLD, 1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "HEALTH(L) AFTER CHARGE"},
+       {"cold2", S_LEAVE, "100", DISCHARGE, TEMPCOLD, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"cold2", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_0,   MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"ovp",   S_ENTER, "100", DISCHARGE, OVERVOLT, 0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "OVP"},
+       {"ovp",   S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"pres1", S_ENTER, "100", DISCHARGE, GOOD,     0,  PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL},
+       {"pres1", S_ENTER, "100", NOTCHARGE, GOOD,     1,  PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "PRESENT BEFORE CHARGE"},
+       {"pres1", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_ABNORMAL, NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"pres1", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"pres2", S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, NULL},
+       {"pres2", S_ENTER, "100", NOTCHARGE, GOOD,     1,  PRESENT_ABNORMAL, USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "PRESENT AFTER CHARGE"},
+       {"pres2", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_ABNORMAL, NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},
+       {"pres2", S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, NULL}, /* init */
+
+       {"bat15", S_ENTER, "15",  DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_3P6, VOLT_3P6, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 15%"}, /* lowbat 15% */
+       {"bat15", S_LEAVE, "15",  CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   NONE,     VOLT_3P6, VOLT_3P6, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 15%"},
+       {"bat5",  S_ENTER, "5",   DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_3P4, VOLT_3P4, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 5%"},  /* lowbat 5% */
+       {"bat5",  S_LEAVE, "5",   CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   NONE,     VOLT_3P4, VOLT_3P4, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 5%"},
+       {"bat3",  S_ENTER, "3",   DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_3P2, VOLT_3P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 3%"},  /* lowbat 3% */
+       {"bat3",  S_LEAVE, "3",   CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   NONE,     VOLT_3P2, VOLT_3P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 3%"},
+       {"bat1",  S_ENTER, "1",   DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   NONE,     VOLT_3P0, VOLT_3P0, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 1%"},  /* lowbat 1% */
+       {"bat1",  S_LEAVE, "1",   CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   NONE,     VOLT_3P0, VOLT_3P0, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "LOWBAT 1%"},
+
+       {"ta",    S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_300, CUR_300, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},   /* charging */
+       {"ta",    S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},/* discharging */
+
+       {"full",  S_ENTER, "100", CHARGEFULL, GOOD,    1,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},   /* full */
+       {"full",  S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"},/* discharging */
+
+       {"capa",  S_ENTER, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "CAPACITY"},/* discharging */
+       {"capa",  S_LEAVE, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   USB,      VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CAPACITY"},/* charging */
+
+       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_0, "CHARGE"},
+       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_1, "FREQ LEVEL 1 AFTER CHARGE"},
+       {"freq",  S_ENTER, "100", CHARGENOW, GOOD,     1,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_100, CUR_100, TEMP_250, MISC_NORMAL, LEVEL_2, "FREQ LEVEL 2 AFTER CHARGE"},
+       {"freq",  S_LEAVE, "100", DISCHARGE, GOOD,     0,  PRESENT_NORMAL,   WIRELESS, VOLT_4P2, VOLT_4P2, CUR_0,   CUR_0,   TEMP_250, MISC_NORMAL, LEVEL_0, "DISCHARGE"}, /* init */
 };
 
 static bool get_battery_method(const char *method, int *value)
@@ -340,7 +330,7 @@ static bool set_battery_low_level(int newlevel)
                        goto out;
                } else {
                        if (0 != reply_val) {
-                               _E("Failed to call dbus method(%s): Return fail.", METHOD_BATTERY_SETLOWBATLEVEL);
+                               _E("Failed to call dbus method(%s), newlevel=%d, retval=%d.", METHOD_BATTERY_SETLOWBATLEVEL, newlevel, reply_val);
                                goto out;
                        }
                }
@@ -503,13 +493,20 @@ static bool compare_vconf(struct power_supply_type list)
 {
        int value, ret, temp;
        int capacity, online, charge_status;
+       int invalid;
+
+       invalid = (strcmp(list.present, PRESENT_ABNORMAL) == 0);
 
        ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
        if (ret < 0) {
                _E("Failed to get vconf value for battery charge now: %d", vconf_get_ext_errno());
                return false;
        }
-       if (!strcmp(list.charge_status, CHARGEFULL)) {
+
+       if (invalid) {
+               charge_status = CHARGE_STATUS_NOT_CHARGING;
+               temp = -ENODEV;
+       } else if (!strcmp(list.charge_status, CHARGEFULL)) {
                charge_status = CHARGE_STATUS_FULL;
                temp = CHARGER_DISCHARGING;
        } else if (!strcmp(list.charge_status, CHARGENOW)) {
@@ -525,8 +522,11 @@ static bool compare_vconf(struct power_supply_type list)
                charge_status = CHARGE_STATUS_UNKNOWN;
                temp = CHARGER_DISCHARGING;
        }
-       if (temp != value)
+
+       if (temp != value) {
+               _E("Failed to get vconf VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, expect=%d, value=%d", temp, value);
                return false;
+       }
 
        capacity = atoi(list.capacity);
        ret= vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,  &value);
@@ -534,7 +534,10 @@ static bool compare_vconf(struct power_supply_type list)
                _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno());
                return false;
        }
-       if (capacity <= DEFAULT_REALOFF) {
+
+       if (invalid) {
+               temp = -ENODEV;
+       } else if (capacity <= DEFAULT_REALOFF) {
                if (charge_status == CHARGE_STATUS_CHARGING)
                        temp = VCONFKEY_SYSMAN_BAT_POWER_OFF;
                else
@@ -551,54 +554,76 @@ static bool compare_vconf(struct power_supply_type list)
        } else {
                temp = VCONFKEY_SYSMAN_BAT_NORMAL;
        }
-       if (temp != value)
+       if (temp != value) {
+               _E("Failed to get vconf VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, expect=%d, value=%d", temp, value);
                return false;
+       }
 
        ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &value);
        if (ret < 0) {
                _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno());
                return false;
        }
-       online = atoi(list.online);
-       if (online > atoi(TYPE_BATTERY))
+       online = list.online;
+       if (online == 1)
                temp = VCONFKEY_SYSMAN_CHARGER_CONNECTED;
        else
                temp = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED;
-       if (temp != value)
+       if (!invalid && temp != value) {
+               _D("Failed to get online, expected=%d, value=%d", temp, value);
                return false;
+       }
 
        ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value);
        if (ret < 0) {
                _E("Failed to get vconf value for battery capacity: %d", vconf_get_ext_errno());
                return false;
        }
-       if (value != capacity)
+
+       if (invalid)
+               capacity = -ENODEV;
+
+       if (value != capacity) {
+               _E("Failed to get capacity, expect=%d, value=%d", capacity, value);
                return false;
+       }
 
        ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_TYPE, &value);
        if (ret < 0) {
                _E("Failed to get vconf value for charger type: %d", vconf_get_ext_errno());
                return false;
        }
-       if (online <= POWER_SUPPLY_TYPE_BATTERY)
-               temp = CHARGER_TYPE_NONE;
-       else if (online == CHARGER_WIRELESS_TYPE_BT ||
-               online == CHARGER_WIRELESS_TYPE_3G)
+
+       if (strncmp(list.power_source, "ac", sizeof("ac")) == 0) {
+               temp = CHARGER_TYPE_AC;
+       } else if (strncmp(list.power_source, "usb", sizeof("usb")) == 0) {
+               temp = CHARGER_TYPE_USB;
+       } else if (strncmp(list.power_source, "wireless", sizeof("wireless")) == 0) {
                temp = CHARGER_TYPE_WIRELESS;
-       else if (online == CHARGER_INCOMPATIBLE_TYPE)
-               temp = CHARGER_TYPE_INCOMPATIBLE;
-       else if (online == CHARGER_D2D_TYPE)
-               temp = CHARGER_TYPE_D2D;
-       else
-               temp = CHARGER_TYPE_WIRE;
-       if (temp != value)
+       } else {
+               temp = CHARGER_TYPE_NONE;
+       }
+
+       if (!invalid && temp != value) {
+               _E("Failed to get power source, expect=%d, value=%d", temp, value);
                return false;
+       }
 
        return true;
 }
 
 static bool compare_power_supply(struct power_supply_type list, int value[], const char *power_source)
 {
+       int present = atoi(list.present);
+
+       if (present != value[4]) {
+               _E("Different present : %d %d", atoi(list.present), value[4]);
+               return false;
+       }
+
+       if (!present)
+               return true;
+
        if (atoi(list.capacity) != value[0]) {
                _E("Different capacity : %d %d", atoi(list.capacity), value[0]);
                return false;
@@ -614,13 +639,8 @@ static bool compare_power_supply(struct power_supply_type list, int value[], con
                return false;
        }
 
-       if (atoi(list.online) != value[3]) {
-               _E("Different online : %d %d", atoi(list.online), value[3]);
-               return false;
-       }
-
-       if (atoi(list.present) != value[4]) {
-               _E("Different present : %d %d", atoi(list.present), value[4]);
+       if (list.online != value[3]) {
+               _E("Different online : %d %d", list.online, value[3]);
                return false;
        }
 
@@ -673,7 +693,7 @@ static bool set_battery_power_supply(int index)
        int reply_val, ret_dbus;
        bool ret = FALSE;
 
-       var = g_variant_new("(sisssssssssssss)", POWER_SUBSYSTEM,
+       var = g_variant_new("(sisssisssssssss)", POWER_SUBSYSTEM,
                                13,
                                power_supply_types[index].capacity,
                                power_supply_types[index].charge_status,
@@ -688,7 +708,8 @@ static bool set_battery_power_supply(int index)
                                power_supply_types[index].current_now,
                                power_supply_types[index].current_avg,
                                power_supply_types[index].temperature);
-                               _I("C(%s) S(%s) H(%s) O(%s) P(%s) M(%s) F(%s) SRC(%s) Vol(%s %s) Cur(%s %s) T(%s)",
+
+                               _I("C(%s) S(%s) H(%s) O(%d) P(%s) M(%s) F(%s) SRC(%s) Vol(%s %s) Cur(%s %s) T(%s)",
                                power_supply_types[index].capacity,
                                power_supply_types[index].charge_status,
                                power_supply_types[index].health,
@@ -708,7 +729,7 @@ static bool set_battery_power_supply(int index)
                                                DEVICED_INTERFACE_BATTERY,
                                                POWER_SUBSYSTEM, var, &reply);
        if (ret_dbus < 0) {
-               _E("Failed to call dbus method(%s): No reply", POWER_SUBSYSTEM);
+               _E("Failed to call dbus method(%s), %d", POWER_SUBSYSTEM, ret_dbus);
                return ret;
        }
 
@@ -719,7 +740,6 @@ static bool set_battery_power_supply(int index)
                if (reply_val < 0) {
                        _E("Failed to call dbus method(%s): Return fail(%d)", POWER_SUBSYSTEM, reply_val);
                } else {
-                       _I("Success. val=%d", reply_val);
                        ret = TRUE;
                }
        }
@@ -764,7 +784,7 @@ static bool get_battery_power_supply(int out_rsp[], char **out_power_source)
                if (reply_val < 0) {
                        _E("Failed to call dbus method(%s): Return fail(%d)", METHOD_BATTERY_GET_POWERSUPPLY, reply_val);
                } else {
-                       _I("Success : C(%d) S(%d) H(%d) O(%d) P(%d) M(%d) F(%d) SRC(%s) Vol(%d %d) Cur(%d %d) Temp(%d)",
+                       _I("C(%d) S(%d) H(%d) O(%d) P(%d) M(%d) F(%d) SRC(%s) Vol(%d %d) Cur(%d %d) Temp(%d)",
                                out_rsp[0], out_rsp[1], out_rsp[2], out_rsp[3], out_rsp[4], out_rsp[5], out_rsp[6], *out_power_source, out_rsp[7], out_rsp[8], out_rsp[9], out_rsp[10], out_rsp[11]);
                        ret = true;
                }
@@ -877,11 +897,36 @@ void battery_test_all(int *success, int *fail)
        (get_battery_info())            ? s++ : f++;
        (get_battery_info_direct(&info))     ? s++ : f++;
 
+       int retval;
+
        for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++) {
-               (set_battery_power_supply(index) &&
-                       get_battery_power_supply(rsp, &power_source) &&
-                       compare_power_supply(power_supply_types[index], rsp, power_source) &&
-                       compare_vconf(power_supply_types[index])) ? s++ : f++;
+               _D("[tc: %2d] Start", index);
+
+               retval = set_battery_power_supply(index);
+               if (!retval) {
+                       _E("[tc: %2d] Failed to set_battery_power_supply, success=%d, fail=%d", index, s, ++f);
+                       continue;
+               }
+
+               retval = get_battery_power_supply(rsp, &power_source);
+               if (!retval) {
+                       _E("[tc: %2d] Failed to get_battery_power_supply, success=%d, fail=%d", index, s, ++f);
+                       continue;
+               }
+
+               retval = compare_power_supply(power_supply_types[index], rsp, power_source);
+               if (!retval) {
+                       _E("[tc: %2d] Failed to compare_power_supply, success=%d, fail=%d", index, s, ++f);
+                       continue;
+               }
+
+               retval = compare_vconf(power_supply_types[index]);
+               if (!retval) {
+                       _E("[tc: %2d] Failed to compare_vconf, success=%d, fail=%d", index, s, ++f);
+                       continue;
+               }
+
+               _D("[tc: %2d] Pass, success=%d, fail=%d", index, ++s, f);
        }
 
        if (NULL != success)    *success = s;