diff --git a/BasicServicesKit/BUILD.gn b/BasicServicesKit/BUILD.gn index 285ccff68c80c348ff26014c4837b4e37234dec3..9368190c4c50f46f64504924555999f4f492360c 100644 --- a/BasicServicesKit/BUILD.gn +++ b/BasicServicesKit/BUILD.gn @@ -91,3 +91,17 @@ ohos_ndk_library("libtime_service_ndk") { system_capability = "SystemCapability.MiscServices.Time" system_capability_headers = [ "BasicServicesKit/time_service.h" ] } + +ohos_ndk_headers("ohbattery_info_header") { + dest_dir = "$ndk_headers_out_dir/BasicServicesKit/" + sources = [ "./ohbattery_info.h" ] +} + +ohos_ndk_library("libohbattery_info_ndk") { + output_name = "ohbattery_info" + output_extension = "so" + ndk_description_file = "./ohbattery_info.ndk.json" + min_compact_version = "13" + system_capability = "SystemCapability.PowerManager.BatteryManager.Core" + system_capability_headers = [ "BasicServicesKit/ohbattery_info.h" ] +} diff --git a/BasicServicesKit/ohbattery_info.h b/BasicServicesKit/ohbattery_info.h new file mode 100644 index 0000000000000000000000000000000000000000..2d6949dcc95f2fdb166c3b95f58355814b910cd1 --- /dev/null +++ b/BasicServicesKit/ohbattery_info.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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. + */ + +/** + * @addtogroup OH_BatteryInfo + * @{ + * + * @brief Provides the definition of the C interface for the BatteryInfo module. + * + * @syscap SystemCapability.PowerManager.BatteryManager.Core + * @since 13 + * @version 1.0 + */ +/** + * @file ohbattery_info.h + * + * @brief Declares the APIs to get informations about the current battery capacity and the power source type, + * defines strings that identify corresponding common events. + * + * @library libohbattery_info.so + * @kit BasicServicesKit + * @syscap SystemCapability.PowerManager.BatteryManager.Core + * @since 13 + * @version 1.0 + */ +#ifndef OHBATTERY_INFO_HEADER +#define OHBATTERY_INFO_HEADER + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief A string that identifies the common event sent after battery capacity changes. + * @since 13 + * @version 1.0 + */ +static const char* COMMON_EVENT_KEY_CAPACITY = "soc"; +/** + * @brief A string that identifies the common event sent after charge state changes. + * @since 13 + * @version 1.0 + */ +static const char* COMMON_EVENT_KEY_CHARGE_STATE = "chargeState"; +/** + * @brief A string that identifies the common event sent after plugged type changes. + * @since 13 + * @version 1.0 + */ +static const char* COMMON_EVENT_KEY_PLUGGED_TYPE = "pluggedType"; + +/** + * @brief Defines plugged types. + * + * @since 13 + * @version 1.0 + */ +typedef enum { + /** + * Power source is unplugged. + */ + PLUGGED_TYPE_NONE, + + /** + * Power source is an AC charger. + */ + PLUGGED_TYPE_AC, + + /** + * Power source is a USB DC charger. + */ + PLUGGED_TYPE_USB, + + /** + * Power source is wireless charger. + */ + PLUGGED_TYPE_WIRELESS, + + /** + * The bottom of the enum. + */ + PLUGGED_TYPE_BUTT +} BatteryInfo_BatteryPluggedType; + +/** + * @brief This API returns the current battery capacity. + * + * @return Returns number between 0 and 100. + * @syscap SystemCapability.PowerManager.BatteryManager.Core + * @since 13 + */ +int32_t OH_BatteryInfo_GetCapacity(); + +/** + * @brief This API returns the current plugged type. + * + * @return {@link BatteryInfo_BatteryPluggedType#PLUGGED_TYPE_NONE} if the power source is unplugged. + * {@link PLUGGED_TYPE_AC} if the power source is an AC charger. + * {@link PLUGGED_TYPE_USB} if the power source is an USB DC charger. + * {@link PLUGGED_TYPE_WIRELESS} if the power source is wireless charger. + * {@link PLUGGED_TYPE_BUTT} if the type is unknown. + * @syscap SystemCapability.PowerManager.BatteryManager.Core + * @since 13 + */ +BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType(); +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* OHBATTERY_INFO_HEADER */ +/** @} */ diff --git a/BasicServicesKit/ohbattery_info.ndk.json b/BasicServicesKit/ohbattery_info.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..f92237153886067815e7a6651559df7b1acadca8 --- /dev/null +++ b/BasicServicesKit/ohbattery_info.ndk.json @@ -0,0 +1,8 @@ +[ + { "first_introduced": "13", + "name":"OH_BatteryInfo_GetCapacity" + }, + { "first_introduced": "13", + "name":"OH_BatteryInfo_GetPluggedType" + } +]