battery: invalidate battery vconf when battery disconnected 25/266425/3
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 12 Nov 2021 05:53:00 +0000 (14:53 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Fri, 12 Nov 2021 08:27:38 +0000 (17:27 +0900)
Change-Id: I4afad3783088c1cb1a7a8ef63b9535907b0a20ad
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/battery/power-supply.c

index d00b2b4..12f263a 100644 (file)
@@ -968,6 +968,27 @@ static int battery_state(struct battery_info *info)
        return 1;
 }
 
+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,
+       };
+
+       _D("Invalidate battery vconfs 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);
+       }
+}
+
 static void battery_changed(struct battery_info *info, void *data)
 {
        int ret_val;
@@ -1029,8 +1050,12 @@ static void battery_changed(struct battery_info *info, void *data)
                battery.present = PRESENT_NORMAL;
        }
 
-       process_power_supply(&battery.capacity);
-
+       if (battery.present) {
+               process_power_supply(&battery.capacity);
+       } else {
+               _D("Battery disconnected");
+               battery_invalidate_vconf(-ENODEV);
+       }
 }
 
 static void power_supply_status_init(void)
@@ -1074,11 +1099,20 @@ static void power_supply_timer_start(void)
 
 static void power_supply_timer_stop(void)
 {
+       int retval;
+
        if (power_timer == 0)
                return;
        _I("Stop battery init timer during booting.");
        g_source_remove(power_timer);
        power_timer = 0;
+
+       /* check battery has been initialized until booting done */
+       retval = hal_device_battery_get_current_state(battery_changed, NULL);
+       if (retval < 0) {
+               _E("Failed to initialize battery state");
+               battery_invalidate_vconf(retval);
+       }
 }
 
 static GVariant *dbus_get_charger_status(GDBusConnection *conn,