{
setting_retm_if(str == NULL, "str parameter is NULL");
- int val = -1;
- char file[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
- snprintf(file, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO,
- "%s/%s/%s", SETTING_ABOUT_POWER_SUPPLY_PATH, "battery", "capacity");
-
- char buf[MAX_DISPLAY_STR_LEN_ON_PHONE_INFO] = { 0, };
- int fd = 0;
- int r = 0;
-
- fd = open(file, O_RDONLY);
- if (fd != -1) {
- r = read(fd, buf, MAX_DISPLAY_STR_LEN_ON_PHONE_INFO);
- if ((r >= 0) && (r < MAX_DISPLAY_STR_LEN_ON_PHONE_INFO)) {
- buf[r] = '\0';
- val = atoi(buf);
- snprintf(str, size, "%d%s", val, "\%");
- } else {
- SETTING_TRACE_ERROR("read file fail");
- snprintf(str, size, "%s", _("IDS_ST_HEADER_UNAVAILABLE"));
- }
+ int bat_level = -1;
- close(fd);
- } else {
- SETTING_TRACE_ERROR("open file fail");
+ /* Read battery level from vconf, as system-server sets that key using a
+ device-specific plugin. Reading directly from /sys fails on different
+ devices */
+ if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &bat_level) == 0) {
+ snprintf(str, size, "%d%s", bat_level, "\%");
+ }
+ else {
+ SETTING_TRACE_ERROR("Reading VCONFKEY_SYSMAN_BATTERY_CAPACITY failed.");
snprintf(str, size, "%s", _("IDS_ST_HEADER_UNAVAILABLE"));
}
}