Add timer to ignore discharging signal from kernel 79/227279/3
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 11 Mar 2020 05:06:16 +0000 (14:06 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 11 Mar 2020 07:34:56 +0000 (07:34 +0000)
Change-Id: Ib6e495c4515fe193b2e38332d818621e8d03a26a
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/battery/lowbat-handler.c
src/battery/power-supply.c

index 670d2b2..121f325 100644 (file)
@@ -96,6 +96,8 @@ static int noti_crit = NOTI_NONE;
 static dd_list *lpe;
 static int scenario_count;
 
+static guint low_batt_sig_timer;
+
 static int lowbat_monitor_init(void *data);
 
 static int lowbat_initialized(void *data)
@@ -934,11 +936,40 @@ static void lowbat_exit(void *data)
        int status = BATTERY_DISABLED;
 
        lowbat_initialized(&status);
+       if (low_batt_sig_timer) {
+               g_source_remove(low_batt_sig_timer);
+               low_batt_sig_timer = 0;
+       }
+}
+
+static gboolean low_battery_charge_status(void *data)
+{
+       low_batt_sig_timer = 0;
+       battery.charging_level = lowbat_monitor(data);
+       if (battery.charging_level > 0 && old_battery.charging_level != battery.charging_level) {
+               if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery.charging_level) < 0)
+                       _E("Fail to set level.");
+               if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery.charging_level) < 0)
+                       _E("power_supply_broadcast failed");
+       }
+       return G_SOURCE_REMOVE;
 }
 
 static int lowbat_execute(void *data)
 {
-       return lowbat_monitor(data);
+       /* In battery kernel side, it has a requirement that battery charging event must get quickly.
+        * So deviced receives the discharging and charging event within 1.5 sec,
+        * added a timer to wait for the second signal, if there is no second signal then execute
+        * the lowbat_execute.
+        */
+       if (low_batt_sig_timer) {
+               g_source_remove(low_batt_sig_timer);
+               low_batt_sig_timer = 0;
+       } else {
+               low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data);
+       }
+
+       return 0;
 }
 
 static const struct device_ops lowbat_device_ops = {
index 1b60cf2..a39ce17 100644 (file)
@@ -846,14 +846,6 @@ static void process_power_supply(void *data)
                        broadcasted = false;
        }
        battery.charging_level = lowbat_execute(data);
-       if (battery.charging_level > 0 && old_battery.charging_level != battery.charging_level) {
-               ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery.charging_level);
-               if (ret < 0)
-                       _E("Failed to set vconf value for battery capacity: %d", vconf_get_ext_errno());
-
-               if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery.charging_level) < 0)
-                       broadcasted = false;
-               }
 
        if (update_online()) {
                ret = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, online_status);