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 BATTERY_STATS_PROXY_H
17 #define BATTERY_STATS_PROXY_H
18 
19 #include <cstdint>
20 #include <functional>
21 #include <iosfwd>
22 #include <vector>
23 #include <iremote_proxy.h>
24 #include <nocopyable.h>
25 #include "iremote_broker.h"
26 #include "iremote_object.h"
27 #include "refbase.h"
28 #include "ibattery_stats.h"
29 #include "battery_stats_info.h"
30 
31 namespace OHOS {
32 namespace PowerMgr {
33 class BatteryStatsProxy : public IRemoteProxy<IBatteryStats> {
34 public:
BatteryStatsProxy(const sptr<IRemoteObject> & impl)35     explicit BatteryStatsProxy(const sptr<IRemoteObject>& impl)
36         : IRemoteProxy<IBatteryStats>(impl) {}
37     ~BatteryStatsProxy() = default;
38     DISALLOW_COPY_AND_MOVE(BatteryStatsProxy);
39 
40     virtual BatteryStatsInfoList GetBatteryStats() override;
41     virtual void SetOnBattery(bool isOnBattery) override;
42     virtual double GetAppStatsMah(const int32_t& uid) override;
43     virtual double GetAppStatsPercent(const int32_t& uid) override;
44     virtual double GetPartStatsMah(const BatteryStatsInfo::ConsumptionType& type) override;
45     virtual double GetPartStatsPercent(const BatteryStatsInfo::ConsumptionType& type) override;
46     virtual uint64_t GetTotalTimeSecond(const StatsUtils::StatsType& statsType, const int32_t& uid) override;
47     virtual uint64_t GetTotalDataBytes(const StatsUtils::StatsType& statsType, const int32_t& uid) override;
48     virtual void Reset() override;
49     virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) override;
50     virtual StatsError GetLastError() override;
51 private:
52     static inline BrokerDelegator<BatteryStatsProxy> delegator_;
53     StatsError lastError_ {StatsError::ERR_OK};
54 };
55 } // namespace PowerMgr
56 } // namespace OHOS
57 #endif // BATTERY_STATS_PROXY_H