• 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 BLUETOOTH_ENTITY_H
17 #define BLUETOOTH_ENTITY_H
18 
19 #include <map>
20 
21 #include "entities/battery_stats_entity.h"
22 
23 namespace OHOS {
24 namespace PowerMgr {
25 class BluetoothEntity : public BatteryStatsEntity {
26 public:
27     enum PowerType {
28         POWER_TYPE_BR = 0,
29         POWER_TYPE_BLE,
30         POWER_TYPE_ALL,
31     };
32     BluetoothEntity();
33     ~BluetoothEntity() = default;
34     void Calculate(int32_t uid = StatsUtils::INVALID_VALUE) override;
35     int64_t GetActiveTimeMs(StatsUtils::StatsType statsType, int16_t level = StatsUtils::INVALID_VALUE) override;
36     int64_t GetActiveTimeMs(int32_t uid, StatsUtils::StatsType statsType,
37         int16_t level = StatsUtils::INVALID_VALUE) override;
38     double GetEntityPowerMah(int32_t uidOrUserId = StatsUtils::INVALID_VALUE) override;
39     double GetStatsPowerMah(StatsUtils::StatsType statsType, int32_t uid = StatsUtils::INVALID_VALUE) override;
40     void Reset() override;
41     void DumpInfo(std::string& result, int32_t uid = StatsUtils::INVALID_VALUE) override;
42     std::shared_ptr<StatsHelper::ActiveTimer> GetOrCreateTimer(StatsUtils::StatsType statsType,
43         int16_t level = StatsUtils::INVALID_VALUE) override;
44     std::shared_ptr<StatsHelper::ActiveTimer> GetOrCreateTimer(int32_t uid, StatsUtils::StatsType statsType,
45         int16_t level = StatsUtils::INVALID_VALUE) override;
46 
47 private:
48     double GetBluetoothUidPower();
49     void CalculateBtPower();
50     void CalculateBtPowerForApp(int32_t uid);
51     void UpdateAppBluetoothBlePower(PowerType type, int32_t uid, double powerMah);
52     double bluetoothBrPowerMah_ = StatsUtils::DEFAULT_VALUE;
53     double bluetoothBlePowerMah_ = StatsUtils::DEFAULT_VALUE;
54     double bluetoothPowerMah_ = StatsUtils::DEFAULT_VALUE;
55     std::map<int32_t, double> appBluetoothBrPowerMap_;
56     std::map<int32_t, double> appBluetoothBlePowerMap_;
57     std::map<int32_t, double> appBluetoothPowerMap_;
58     std::shared_ptr<StatsHelper::ActiveTimer> bluetoothBrOnTimer_;
59     std::shared_ptr<StatsHelper::ActiveTimer> bluetoothBleOnTimer_;
60     std::map<int32_t, std::shared_ptr<StatsHelper::ActiveTimer>> appBluetoothBrScanTimerMap_;
61     std::map<int32_t, std::shared_ptr<StatsHelper::ActiveTimer>> appBluetoothBleScanTimerMap_;
62 };
63 } // namespace PowerMgr
64 } // namespace OHOS
65 #endif // BLUETOOTH_ENTITY_H