1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ohbattery_info.h"
17 
18 #include  <cinttypes>
19 
20 #include "battery_srv_client.h"
21 
22 using namespace OHOS::PowerMgr;
23 
OH_BatteryInfo_GetCapacity()24 int32_t OH_BatteryInfo_GetCapacity()
25 {
26     BatterySrvClient& batterySrvClient = BatterySrvClient::GetInstance();
27     int32_t ret = batterySrvClient.GetCapacity();
28     return ret;
29 }
30 
OH_BatteryInfo_GetPluggedType()31 BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType()
32 {
33     BatterySrvClient& batterySrvClient = BatterySrvClient::GetInstance();
34     uint32_t result = static_cast<uint32_t>(batterySrvClient.GetPluggedType());
35     BatteryInfo_BatteryPluggedType ret = PLUGGED_TYPE_NONE;
36     switch (result) {
37         case static_cast<uint32_t>(PLUGGED_TYPE_AC):
38             ret = PLUGGED_TYPE_AC;
39             break;
40         case static_cast<uint32_t>(PLUGGED_TYPE_USB):
41             ret = PLUGGED_TYPE_USB;
42             break;
43         case static_cast<uint32_t>(PLUGGED_TYPE_WIRELESS):
44             ret = PLUGGED_TYPE_WIRELESS;
45             break;
46         case static_cast<uint32_t>(PLUGGED_TYPE_NONE):
47             ret = PLUGGED_TYPE_NONE;
48             break;
49         default:
50             ret = PLUGGED_TYPE_BUTT;
51             break;
52     }
53     return ret;
54 }
55