--- /dev/null
+/*
+ * Copyright (c) 2021 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.
+ */
+#include <stdlib.h>
+
+#include <hal/hal-common.h>
+
+#include "hal-device-battery-interface.h"
+#include "common.h"
+
+static hal_backend_device_battery_funcs *hal_device_battery_funcs = NULL;
+
+int hal_device_battery_passthrough_get_backend(void)
+{
+ int ret;
+
+ if (hal_device_battery_funcs)
+ return 0;
+
+ hal_device_battery_funcs = calloc(1, sizeof(hal_backend_device_battery_funcs));
+ if (!hal_device_battery_funcs)
+ return -ENOMEM;
+
+ ret = hal_common_get_backend(HAL_MODULE_DEVICE_BATTERY, (void **)&hal_device_battery_funcs);
+ if (ret < 0) {
+ _E("Failed to get device-battery backend");
+ free(hal_device_battery_funcs);
+ hal_device_battery_funcs = NULL;
+ return -ENOTSUP;
+ }
+
+ return 0;
+}
+
+int hal_device_battery_passthrough_put_backend(void)
+{
+ int ret = 0;
+
+ if (!hal_device_battery_funcs)
+ return 0;
+
+ ret = hal_common_put_backend(HAL_MODULE_DEVICE_BATTERY, (void *)hal_device_battery_funcs);
+ if (ret < 0) {
+ _E("Failed to put device-battery backend");
+ return ret;
+ }
+
+ free(hal_device_battery_funcs);
+ hal_device_battery_funcs = NULL;
+
+ return 0;
+}
+
+int hal_device_battery_passthrough_register_changed_event(hal_device_battery_updated_cb updated_cb, void *user_data)
+{
+ int ret;
+
+ if (!updated_cb)
+ return -EINVAL;
+
+ if (!hal_device_battery_funcs) {
+ if ((ret = hal_device_battery_passthrough_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_battery_funcs ||
+ !hal_device_battery_funcs->register_changed_event)
+ return -ENOTSUP;
+
+ return hal_device_battery_funcs->register_changed_event(updated_cb, user_data);
+}
+
+int hal_device_battery_passthrough_unregister_changed_event(hal_device_battery_updated_cb updated_cb)
+{
+ int ret;
+
+ if (!updated_cb)
+ return -EINVAL;
+
+ if (!hal_device_battery_funcs) {
+ if ((ret = hal_device_battery_passthrough_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_battery_funcs ||
+ !hal_device_battery_funcs->unregister_changed_event)
+ return -ENOTSUP;
+
+ hal_device_battery_funcs->unregister_changed_event(updated_cb);
+ return 0;
+}
+
+int hal_device_battery_passthrough_get_current_state(hal_device_battery_updated_cb updated_cb, void *user_data)
+{
+ int ret;
+
+ if (!updated_cb)
+ return -EINVAL;
+
+ if (!hal_device_battery_funcs) {
+ if ((ret = hal_device_battery_passthrough_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_battery_funcs ||
+ !hal_device_battery_funcs->get_current_state)
+ return -ENOTSUP;
+
+ return hal_device_battery_funcs->get_current_state(updated_cb, user_data);
+}
+
+int hal_device_battery_passthrough_get_power_source_name(hal_device_battery_power_source_type_e power_source_type, const char **power_source)
+{
+ if (!power_source)
+ return -EINVAL;
+
+ switch (power_source_type) {
+ case HAL_DEVICE_BATTERY_POWER_SOURCE_AC:
+ *power_source = "ac";
+ break;
+ case HAL_DEVICE_BATTERY_POWER_SOURCE_USB:
+ *power_source = "usb";
+ break;
+ case HAL_DEVICE_BATTERY_POWER_SOURCE_WIRELESS:
+ *power_source = "wireless";
+ break;
+ case HAL_DEVICE_BATTERY_POWER_SOURCE_NONE:
+ default:
+ *power_source = "none";
+ break;
+ }
+
+ return 0;
+}
+
+int hal_device_battery_passthrough_get_power_source_type(char *power_source, hal_device_battery_power_source_type_e *power_source_type)
+{
+ if (!power_source || !power_source_type)
+ return -EINVAL;
+
+ if (strcmp(power_source, "ac") == 0)
+ *power_source_type = HAL_DEVICE_BATTERY_POWER_SOURCE_AC;
+ else if (strcmp(power_source, "usb") == 0)
+ *power_source_type = HAL_DEVICE_BATTERY_POWER_SOURCE_USB;
+ else if (strcmp(power_source, "wireless") == 0)
+ *power_source_type = HAL_DEVICE_BATTERY_POWER_SOURCE_WIRELESS;
+ else
+ *power_source_type = HAL_DEVICE_BATTERY_POWER_SOURCE_NONE;
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2021 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 __HAL_DEVICE_BATTERY_PASSTHROUGH_H__
+#define __HAL_DEVICE_BATTERY_PASSTHROUGH_H__
+
+#include "hal-device-battery-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_battery_passthrough_get_backend(void);
+int hal_device_battery_passthrough_put_backend(void);
+int hal_device_battery_passthrough_register_changed_event(hal_device_battery_updated_cb updated_cb, void *user_data);
+int hal_device_battery_passthrough_unregister_changed_event(hal_device_battery_updated_cb updated_cb);
+int hal_device_battery_passthrough_get_current_state(hal_device_battery_updated_cb updated_cb, void *user_data);
+int hal_device_battery_passthrough_get_power_source_name(hal_device_battery_power_source_type_e power_source_type, const char **power_source);
+int hal_device_battery_passthrough_get_power_source_type(char *power_source, hal_device_battery_power_source_type_e *power_source_type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __HAL_DEVICE_BATTERY_PASSTHROUGH_H__