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));
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,
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);
} 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';
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,
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);
free(info.status);
free(info.health);
- free(info.power_source);
return g_variant_new("(i)", ret);
}
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;
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 */