battery: Replace macro power source definitions to hal_device_battery_power_source_type_e 04/310104/7
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 22 Apr 2024 11:55:57 +0000 (20:55 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 23 Apr 2024 11:44:48 +0000 (20:44 +0900)
As Power source type macros are replaced by hal_device_battery_power_source_type_e,
definition usage logic also changed.
To get hal_device_battery_power_source_type_e string,
hal_device_battery_power_get_name_of_power_source_type_e is used.

Change-Id: I281d61756019ffb2c11e4e6cca87d8591fd19215
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/battery/power-supply.c

index e650e4336add68211c79c65cef2bb730d6c8a88e..b62234cfda56db39611ff9621b8c494cf583752c 100644 (file)
@@ -791,6 +791,8 @@ static void process_power_supply(void *data)
 static int battery_state(hal_device_battery_info_s *info)
 {
        static struct battery_status prev_status;
+       const char* power_source_name = NULL;
+       int ret = 0;
 
        if (!info) {
                memcpy(&prev_status, &battery, sizeof(battery));
@@ -817,11 +819,14 @@ static int battery_state(hal_device_battery_info_s *info)
        prev_status.present = battery.present;
        prev_status.charger_connected = battery.charger_connected;
 
+       ret = hal_device_battery_get_power_source_name(info->power_source, &power_source_name);
+       if (ret < 0)
+               _W("Failed to get battery power source name");
        _I("%s(%s) %s(%d) Capa(%d) Hth(%s,%d) Pres(%d) Curr(%d,%d)",
                        info->status,
                        battery.charge_now == CHARGER_CHARGING ? "Charging"
                                : (battery.charge_now == CHARGER_DISCHARGING ? "Discharging" : "Abnormal"),
-                       info->power_source,
+                       power_source_name,
                        info->online,
                        info->capacity,
                        info->health,
@@ -865,6 +870,7 @@ static void battery_disable_module(int value)
 static void battery_changed(hal_device_battery_info_s *info, void *data)
 {
        int ret_val;
+       const char* power_source_name = NULL;
 
        if (!info) {
                (void)battery_state(NULL);
@@ -885,8 +891,12 @@ static void battery_changed(hal_device_battery_info_s *info, void *data)
        } else
                battery.health_s[0] = '\0';
 
-       if (info->power_source)
-               check_power_source(info->power_source);
+       ret_val = hal_device_battery_get_power_source_name(info->power_source, &power_source_name);
+       if (ret_val < 0)
+               _W("Failed to get battery power source name");
+
+       if (power_source_name)
+               check_power_source(power_source_name);
        else
                battery.power_source_s[0] = '\0';
 
@@ -1093,6 +1103,7 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
        char *type_str;
        char *argv[13];
        hal_device_battery_info_s info = {0, };
+       hal_device_battery_power_source_type_e power_source_type;
 
        g_variant_get(param, "(sisssisssssssss)", &type_str,
                                &argc,
@@ -1135,14 +1146,17 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn,
        info.online = charger_connected;
        info.present = atoi(argv[4]);
        check_misc_status(argv[5]);
-       info.power_source = strdup(argv[7]);
+       ret = hal_device_battery_get_power_source_type(argv[7], &power_source_type);
+       if (ret < 0)
+               _W("Failed to get battery power source type");
+       info.power_source = power_source_type;
        info.voltage_now = atoi(argv[8]);
        info.voltage_average = atoi(argv[9]);
        info.current_now = atoi(argv[10]);
        info.current_average = atoi(argv[11]);
        info.temperature = atoi(argv[12]);
        _D("C(%d) S(%s) H(%s) O(%d) P(%d) SRC(%s) Vol(%d %d) Cur(%d %d) T(%d)",
-               info.capacity, info.status, info.health, info.online, info.present, info.power_source, info.voltage_now, info.voltage_average, info.current_now, info.current_average, info.temperature);
+               info.capacity, info.status, info.health, info.online, info.present, argv[7], info.voltage_now, info.voltage_average, info.current_now, info.current_average, info.temperature);
 
        battery_changed(&info, NULL);
 
@@ -1163,7 +1177,6 @@ out:
 
        free(info.status);
        free(info.health);
-       free(info.power_source);
 
        return g_variant_new("(i)", ret);
 }
@@ -1177,7 +1190,7 @@ static void battery_get_info(hal_device_battery_info_s *info, void *data)
 
        bat->status = strdup(info->status);
        bat->health = strdup(info->health);
-       bat->power_source = strdup(info->power_source);
+       bat->power_source = info->power_source;
        bat->online = info->online;
        bat->present = info->present;
        bat->capacity = info->capacity;
@@ -1210,16 +1223,18 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn,
                battery_changed(&info, NULL);
                free(info.status);
                free(info.health);
-               free(info.power_source);
        } else {
                if (vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val) == 0 &&
                        val != VCONFKEY_SYSMAN_USB_DISCONNECTED)
-                       str = HAL_DEVICE_BATTERY_POWER_SOURCE_USB;
+                       ret = hal_device_battery_get_power_source_name(HAL_DEVICE_BATTERY_POWER_SOURCE_USB, &str);
                else if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &val) == 0 &&
                        val == VCONFKEY_SYSMAN_CHARGER_CONNECTED)
-                       str = HAL_DEVICE_BATTERY_POWER_SOURCE_AC;
+                       ret = hal_device_battery_get_power_source_name(HAL_DEVICE_BATTERY_POWER_SOURCE_AC, &str);
                else
-                       str = HAL_DEVICE_BATTERY_POWER_SOURCE_NONE;
+                       ret = hal_device_battery_get_power_source_name(HAL_DEVICE_BATTERY_POWER_SOURCE_NONE, &str);
+
+               if (ret < 0)
+                       _W("Failed to get battery power source name");
                snprintf(battery.power_source_s, sizeof(battery.power_source_s), "%s", str);
 
                battery.current_now = -1; /* Not supported */