1 /* 2 * Copyright (C) 2024-2024 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 OHOS_WIFI_NET_STATS_MANAGER_H 17 #define OHOS_WIFI_NET_STATS_MANAGER_H 18 19 #include "wifi_errcode.h" 20 #include <map> 21 #include <string> 22 #include <vector> 23 #include "singleton.h" 24 #include "net_stats_info.h" 25 #include <mutex> 26 27 namespace OHOS { 28 namespace Wifi { 29 30 using NetStats = std::vector<NetManagerStandard::NetStatsInfo>; 31 using NetStatsInfo = NetManagerStandard::NetStatsInfo; 32 33 class WifiNetStatsManager : public Singleton<WifiNetStatsManager> { 34 public: 35 void StartNetStats(); 36 void StopNetStats(); 37 private: 38 void PerformPollAndLog(); 39 ErrCode GetWifiNetStatsDetail(NetStats &netStats); 40 NetStats GetIncrementalNetStats(NetStats curNetStats); 41 NetStatsInfo GetTotalNetStatsInfo(NetStats netStats); 42 void LogNetStatsTraffic(NetStats netStats); 43 std::map<int32_t, NetStatsInfo> ConvertNetStatsToMap(NetStats netStats); 44 std::string GetTrafficLog(std::string bundleName, NetStatsInfo info, bool needEndStr = true); 45 std::string GetBundleName(int32_t uid); 46 private: 47 std::map<int32_t, NetStatsInfo> m_lastStatsMap; 48 std::mutex lastStatsMapMutex_ {}; 49 bool m_hasLastStats {false}; 50 uint64_t m_netStatsTimerId {0}; 51 }; 52 } // namespace Wifi 53 } // namespace OHOS 54 55 #endif