• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef POWERMGR_BATTERY_SRV_CLIENT_H
17 #define POWERMGR_BATTERY_SRV_CLIENT_H
18 
19 #include <singleton.h>
20 #include <memory>
21 #include <mutex>
22 #include "iremote_object.h"
23 #include "ibattery_srv.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class BatterySrvClient final : public DelayedRefSingleton<BatterySrvClient> {
28     DECLARE_DELAYED_REF_SINGLETON(BatterySrvClient);
29 
30 public:
31     DISALLOW_COPY_AND_MOVE(BatterySrvClient);
32 
33     /**
34      * Return the capacity of the battery, in percent.
35      */
36     int32_t GetCapacity();
37     /**
38      * Return the charging status, such as CHARGE_STATE_NONE, CHARGE_STATE_ENABLE,
39      * CHARGE_STATE_DISABLE, CHARGE_STATE_FULL,...
40      */
41     BatteryChargeState GetChargingStatus();
42     /**
43      * Return the Health state of the battery, such as HEALTH_STATE_UNKNOWN,
44      * HEALTH_STATE_GOOD, HEALTH_STATE_OVERHEAT,....
45      */
46     BatteryHealthState GetHealthStatus();
47     /**
48      * Return the charger type plugged, such as PLUGGED_TYPE_NONE,
49      * PLUGGED_TYPE_AC, PLUGGED_TYPE_USB,....
50      */
51     BatteryPluggedType GetPluggedType();
52     /**
53      * Return the voltage of the battery, in mv.
54      */
55     int32_t GetVoltage();
56     /**
57      * Return the present state of the battery, true or false.
58      */
59     bool GetPresent();
60     /**
61      * Return the technology of the battery, such as Li-ion.
62      */
63     std::string GetTechnology();
64     /**
65      * Return the temperature of the battery, in 0.1℃.
66      */
67     int32_t GetBatteryTemperature();
68      /**
69      * Return the Current of the battery, in mA.
70      */
71     int32_t GetNowCurrent();
72     /**
73      * Return the RemainEnergy of the battery, in mAh.
74      */
75     int32_t GetRemainEnergy();
76     /**
77      * Return the GetTotalEnergy of the battery, in mAh.
78      */
79     int32_t GetTotalEnergy();
80     /**
81      * Return the level of the battery
82      */
83     BatteryCapacityLevel GetCapacityLevel();
84     /**
85      * Return the remaining charge time
86      */
87     int64_t GetRemainingChargeTime();
88 
89 #ifndef BATTERYMGR_DEATHRECIPIENT_UNITTEST
90 private:
91 #endif
92     class BatterySrvDeathRecipient : public IRemoteObject::DeathRecipient {
93     public:
94         BatterySrvDeathRecipient() = default;
95         virtual ~BatterySrvDeathRecipient() = default;
96         void OnRemoteDied(const wptr<IRemoteObject>& remote);
97     private:
98         DISALLOW_COPY_AND_MOVE(BatterySrvDeathRecipient);
99     };
100 
101     ErrCode Connect();
102     sptr<IBatterySrv> proxy_ {nullptr};
103     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
104     void ResetProxy(const wptr<IRemoteObject>& remote);
105     std::mutex mutex_;
106 };
107 } // namespace PowerMgr
108 } // namespace OHOS
109 
110 #endif // BATTERY_SRV_CLIENT_H
111