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