--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_SYSTEM_BATTERY_INTERNAL_H__
+#define __TIZEN_SYSTEM_BATTERY_INTERNAL_H__
+
+
+#include <stdbool.h>
+#include "device-error.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE
+ * @{
+ */
+#define INFO_MAX 32
+
+struct battery_info {
+ char status[INFO_MAX];
+ char health[INFO_MAX];
+ char power_source[INFO_MAX];
+ int online;
+ int present;
+ int capacity;
+ int current_now;
+ int current_average;
+ int voltage_now;
+ int voltage_average;
+ int temperature;
+};
+
+/**
+ * @brief Gets the battery status..
+ * @since_tizen 6.0
+ * @param[out] battery status
+ * @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(struct battery_info *info);
+
+/**
+ * @}
+ */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // __TIZEN_SYSTEM_BATTERY_H__
#include <vconf.h>
#include "battery.h"
+#include "battery-internal.h"
#include "common.h"
#include "dbus.h"
#include <system_info.h>
#define METHOD_GET_PERCENT "GetPercent"
#define METHOD_GET_INFO "GetBatteryInfo"
-#define INFO_MAX 32
#define BATTERY_FEATURE "http://tizen.org/feature/battery"
-struct battery_info {
- char status[INFO_MAX];
- char health[INFO_MAX];
- char power_source[INFO_MAX];
- int online;
- int present;
- int capacity;
- int current_now;
- int current_average;
- int voltage_now;
- int voltage_average;
- int temperature;
-};
-
static int is_battery_supported(void)
{
int ret;
return DEVICE_ERROR_NONE;
}
-static int device_battery_get_info(struct battery_info *info)
+int device_battery_get_info(struct battery_info *info)
{
int ret;
GVariant *output = NULL;
if (!info)
return DEVICE_ERROR_INVALID_PARAMETER;
+ ret = is_battery_supported();
+ if (!ret)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
ret = dbus_method_sync_with_reply_var(DEVICED_BUS_NAME,
DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
METHOD_GET_INFO, NULL, &output);