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 UID_ENTITY_H
17 #define UID_ENTITY_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "entities/battery_stats_entity.h"
23 #include "stats_helper.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class UidEntity : public BatteryStatsEntity {
28 public:
29     UidEntity();
30     ~UidEntity() = default;
31     void Calculate(int32_t uid = StatsUtils::INVALID_VALUE) override;
32     double GetEntityPowerMah(int32_t uidOrUserId = StatsUtils::INVALID_VALUE) override;
33     double GetStatsPowerMah(StatsUtils::StatsType statsType, int32_t uid = StatsUtils::INVALID_VALUE)
34         override;
35     void UpdateUidMap(int32_t uid) override;
36     std::vector<int32_t> GetUids() override;
37     void Reset() override;
38     void DumpInfo(std::string& result, int32_t uid = StatsUtils::INVALID_VALUE) override;
39 private:
40     std::mutex uidEntityMutex_;
41     std::map<int32_t, double> uidPowerMap_;
42     void AddtoStatsList(int32_t uid, double power);
43     double GetPowerForCommon(StatsUtils::StatsType statsType, int32_t uid);
44     double GetPowerForConnectivity(StatsUtils::StatsType statsType, int32_t uid);
45     void DumpForBluetooth(int32_t uid, std::string& result);
46     void DumpForCommon(int32_t uid, std::string& result);
47     double CalculateForConnectivity(int32_t uid);
48     double CalculateForCommon(int32_t uid);
49 };
50 } // namespace PowerMgr
51 } // namespace OHOS
52 #endif // UID_ENTITY_H