• 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 BATTERY_STATS_INFO_H
17 #define BATTERY_STATS_INFO_H
18 
19 #include <list>
20 #include <memory>
21 #include <parcel.h>
22 #include <string>
23 
24 #include "battery_stats_info.h"
25 #include "stats_utils.h"
26 
27 namespace OHOS {
28 namespace PowerMgr {
29 class BatteryStatsInfo : Parcelable {
30 public:
31     enum ConsumptionType {
32         CONSUMPTION_TYPE_INVALID = -17,
33         CONSUMPTION_TYPE_APP,
34         CONSUMPTION_TYPE_BLUETOOTH,
35         CONSUMPTION_TYPE_IDLE,
36         CONSUMPTION_TYPE_PHONE,
37         CONSUMPTION_TYPE_RADIO,
38         CONSUMPTION_TYPE_SCREEN,
39         CONSUMPTION_TYPE_USER,
40         CONSUMPTION_TYPE_WIFI,
41         CONSUMPTION_TYPE_CAMERA,
42         CONSUMPTION_TYPE_FLASHLIGHT,
43         CONSUMPTION_TYPE_AUDIO,
44         CONSUMPTION_TYPE_SENSOR,
45         CONSUMPTION_TYPE_GNSS,
46         CONSUMPTION_TYPE_CPU,
47         CONSUMPTION_TYPE_WAKELOCK,
48         CONSUMPTION_TYPE_ALARM
49     };
50 
51     bool Marshalling(Parcel &parcel) const override;
52     static std::shared_ptr<BatteryStatsInfo> Unmarshalling(Parcel &parcel);
53     bool ReadFromParcel(Parcel &parcel);
54     void SetUid(int32_t uid);
55     void SetUserId(int32_t userId);
56     void SetConsumptioType(ConsumptionType type);
57     void SetPower(double power);
58     int32_t GetUid();
59     int32_t GetUserId();
60     ConsumptionType GetConsumptionType();
61     double GetPower();
62     static std::string ConvertConsumptionType(ConsumptionType type);
63 private:
64     int32_t uid_ = StatsUtils::INVALID_VALUE;
65     int32_t userId_ = StatsUtils::INVALID_VALUE;
66     ConsumptionType type_ = CONSUMPTION_TYPE_INVALID;
67     double totalPowerMah_ = StatsUtils::DEFAULT_VALUE;
68     static std::string ConvertTypeForPart(ConsumptionType type);
69     static std::string ConvertTypeForApp(ConsumptionType type);
70 };
71 using BatteryStatsInfoList = std::list<std::shared_ptr<BatteryStatsInfo>>;
72 } // namespace PowerMgr
73 } // namespace OHOS
74 #endif // BATTERY_STATS_INFO_H