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_BATTERY_STATS_ENTITY_H 17 #define BATTERY_BATTERY_STATS_ENTITY_H 18 19 #include <cstdint> 20 #include <iosfwd> 21 #include <memory> 22 #include <vector> 23 #include "stats_utils.h" 24 #include "stats_helper.h" 25 #include "battery_stats_info.h" 26 27 namespace OHOS { 28 namespace PowerMgr { 29 class BatteryStatsEntity { 30 public: 31 BatteryStatsEntity() = default; 32 virtual ~BatteryStatsEntity() = default; 33 virtual double GetEntityPowerMah(int32_t uidOrUserId = StatsUtils::INVALID_VALUE) = 0; 34 virtual void Reset() = 0; 35 virtual void Calculate(int32_t uid = StatsUtils::INVALID_VALUE) = 0; 36 virtual int64_t GetActiveTimeMs(StatsUtils::StatsType statsType, int16_t level = StatsUtils::INVALID_VALUE); 37 virtual int64_t GetActiveTimeMs(int32_t uid, StatsUtils::StatsType statsType, 38 int16_t level = StatsUtils::INVALID_VALUE); 39 virtual int64_t GetTrafficByte(StatsUtils::StatsType statsType, int32_t uid = StatsUtils::INVALID_VALUE); 40 virtual int64_t GetConsumptionCount(StatsUtils::StatsType statsType, int32_t uid = StatsUtils::INVALID_VALUE); 41 virtual double GetStatsPowerMah(StatsUtils::StatsType statsType, int32_t uid = StatsUtils::INVALID_VALUE); 42 virtual std::shared_ptr<StatsHelper::ActiveTimer> GetOrCreateTimer(StatsUtils::StatsType statsType, 43 int16_t level = StatsUtils::INVALID_VALUE); 44 virtual std::shared_ptr<StatsHelper::ActiveTimer> GetOrCreateTimer(int32_t uid, StatsUtils::StatsType statsType, 45 int16_t level = StatsUtils::INVALID_VALUE); 46 virtual std::shared_ptr<StatsHelper::ActiveTimer> GetOrCreateTimer(const std::string& deviceId, int32_t uid, 47 StatsUtils::StatsType statsType, int16_t level = StatsUtils::INVALID_VALUE); 48 virtual std::shared_ptr<StatsHelper::Counter> GetOrCreateCounter(StatsUtils::StatsType statsType, 49 int32_t uid = StatsUtils::INVALID_VALUE); 50 virtual void AggregateUserPowerMah(int32_t userId, double power); 51 virtual void UpdateUidMap(int32_t uid); 52 virtual int64_t GetCpuTimeMs(int32_t uid); 53 virtual void UpdateCpuTime(); 54 virtual std::vector<int32_t> GetUids(); 55 virtual void DumpInfo(std::string& result, int32_t uid = StatsUtils::INVALID_VALUE); 56 BatteryStatsInfo::ConsumptionType GetConsumptionType(); 57 static double GetTotalPowerMah(); 58 static void ResetStatsEntity(); 59 static BatteryStatsInfoList GetStatsInfoList(); 60 static void UpdateStatsInfoList(std::shared_ptr<BatteryStatsInfo> info); 61 protected: 62 static double totalPowerMah_; 63 static BatteryStatsInfoList statsInfoList_; 64 BatteryStatsInfo::ConsumptionType consumptionType_ = BatteryStatsInfo::CONSUMPTION_TYPE_INVALID; 65 }; 66 } // namespace PowerMgr 67 } // namespace OHOS 68 #endif // BATTERY_BATTERY_STATS_ENTITY_H