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