* @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE
* @{
*/
-#define BATTER_INFO_MAX 32
+#define BATTERY_INFO_MAX 32
-struct battery_info {
- char status[BATTER_INFO_MAX];
- char health[BATTER_INFO_MAX];
- char power_source[BATTER_INFO_MAX];
+struct device_battery_info {
+ char status[BATTERY_INFO_MAX];
+ char health[BATTERY_INFO_MAX];
+ char power_source[BATTERY_INFO_MAX];
int online;
int present;
int capacity;
* @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
* @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device
*/
-int device_battery_get_info(struct battery_info *info);
+int device_battery_get_info(struct device_battery_info *info);
+
+/**
+ * @brief Gets the battery status..
+ * @since_tizen 6.0
+ * @param[out] info battery status information.\n
+ * The current_average is INT_MAX if battery hw does not provide current average.\n
+ * The voltage_average is INT_MAX if battery hw does not provide voltage average.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device
+ */
+int device_battery_get_info_direct(struct device_battery_info *info);
/**
* @}
#include <string.h>
#include <errno.h>
#include <vconf.h>
+#include <hw/common.h>
+#include <hw/battery.h>
#include "battery.h"
#include "battery-internal.h"
#define BATTERY_FEATURE "http://tizen.org/feature/battery"
+static struct hw_info *hw = NULL;
+static struct battery_device *battery_dev = NULL;
+
static int is_battery_supported(void)
{
int ret;
return DEVICE_ERROR_NONE;
}
-int device_battery_get_info(struct battery_info *info)
+int device_battery_get_info(struct device_battery_info *info)
{
int ret;
GVariant *output = NULL;
return ret;
}
+//LCOV_EXCL_START unused function
+static int load_battery_dev()
+{
+ int ret = 0;
+
+ if (!hw) {
+ ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID, (const struct hw_info **)&hw);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+ }
+
+ if (!hw->open) {
+ _E("Failed to open battery device: open(NULL)");
+ return -ENODEV;
+ }
+
+ ret = hw->open(hw, NULL, (struct hw_common**)&battery_dev);
+ if (ret < 0) {
+ _E("Failed to get battery device structure: %d", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static void battery_get_info(struct battery_info *info, void *data)
+{
+ struct device_battery_info *bat = data;
+
+ if (!info || !bat)
+ return;
+
+ snprintf(bat->status, sizeof(bat->status), "%s", info->status);
+ snprintf(bat->health, sizeof(bat->health), "%s", info->health);
+ snprintf(bat->power_source, sizeof(bat->power_source), "%s", info->power_source);
+ bat->online = info->online;
+ bat->present = info->present;
+ bat->capacity = info->capacity;
+ bat->current_now = info->current_now;
+ bat->current_average = info->current_average;
+ bat->temperature = info->temperature;
+ bat->voltage_now = info->voltage_now;
+ bat->voltage_average = info->voltage_average;
+}
+
+int device_battery_get_info_direct(struct device_battery_info *info)
+{
+ int ret;
+
+ if (!info)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ ret = is_battery_supported();
+ if (!ret)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
+ if (!battery_dev) {
+ ret = load_battery_dev();
+ if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ if (!battery_dev->get_current_state) {
+ _E("get_current_state() is not supported by the Battery HAL.");
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ ret = battery_dev->get_current_state(battery_get_info, info);
+ if (ret < 0) {
+ _E("Failed to get battery info: %d", ret);
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ return DEVICE_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
int device_battery_get_health(device_battery_health_e *health)
{
- struct battery_info info;
+ struct device_battery_info info;
int ret;
size_t len;
int device_battery_get_power_source(device_battery_power_source_e *source)
{
- struct battery_info info;
+ struct device_battery_info info;
int ret;
size_t len;
int device_battery_get_property(device_battery_property_e property, int *val)
{
- struct battery_info info = {0, };
+ struct device_battery_info info = {0, };
int ret;
if (!val)
int device_battery_get_status(device_battery_status_e *status)
{
- struct battery_info info;
+ struct device_battery_info info;
int ret;
size_t len;
return DEVICE_ERROR_NONE;
}
+
+void __attribute__ ((destructor)) battery_finalize(void)
+{
+ if (battery_dev) {
+ if (hw && hw->close)
+ hw->close((struct hw_common *)battery_dev);
+ }
+}