1 /* 2 * Copyright (C) 2025 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_SELECT_NETWORK_DATA_REPORT_H 17 #define OHOS_SELECT_NETWORK_DATA_REPORT_H 18 #include <vector> 19 #include <mutex> 20 #include <map> 21 #include "wifi_log.h" 22 #include "wifi_crowdsourced_data.h" 23 #include "ienhance_service.h" 24 #include "sta_sm_ext.h" 25 26 namespace OHOS { 27 namespace Wifi { 28 29 class StaStateMachine; 30 31 /* wifi 数据上报类 */ 32 class WifiDataReportService : public StaSMExt { 33 private: 34 ConnectEventTimeInfo connEventTimepInfo_; 35 bool disConnFlag_ = false; 36 std::map<std::string, time_t> lastPushTime_; // 存储每个bssid的最后推送时间 37 std::vector<WifiCrowdsourcedQoeInfo> historyData_; // 存储历史数据 38 std::mutex historyMutex_; // 用于保护历史记录 39 public: 40 41 explicit WifiDataReportService(StaStateMachine* staStateMachinePtr, int instId); 42 ~ WifiDataReportService() override; 43 44 /** 45 * @Description : 初始化成员变量 46 * 47 */ 48 void InitReportApAllInfo(); 49 50 /** 51 * @Description : 事件上报 52 * 53 * @param reportReason - 上报原因 54 */ 55 void ReportApConnEventInfo(ConnReportReason reportReason, int targetNetworkId); 56 57 /** 58 * @Description : 周期上报 59 * 60 * @param qoeInfo - WifiSignalPollInfo 信息 61 * @param reportReason - 上报原因 62 */ 63 void ReportQoeInfo(const WifiSignalPollInfo& qoeInfo, ConnReportReason reportReason, int targetNetworkId); 64 65 private: 66 67 /** 68 * @Description : 4 × 8位 -> 32位 69 * 70 * @param ext - signalpoll.ext 71 * @param index - signalpoll.ext 特定元素的索引 72 */ 73 uint32_t GetUint32FromExt(const std::vector<uint8_t>& ext, size_t index); 74 75 /** 76 * @Description : 2 × 8位 -> 16位 77 * 78 * @param uint8Vec - uint8 vector 79 */ 80 std::vector<uint16_t> ConvertUint8ToUint16(const std::vector<uint8_t>& uint8Vec); 81 82 /** 83 * @Description : BE, BK, VI, VO 四个队列合并 84 * 85 * @param uint8Vec - uint8 vector 86 */ 87 std::vector<uint16_t> SequenceMerge(const std::vector<uint16_t>& sequence); 88 89 /** 90 * @Description : 更新 AP 连接事件时间戳 91 * 92 * @param timeType - 上报时间类型(连接开始,连接成功,断开连接) 93 */ 94 void UpdateApConnEventTimepInfo(ConnTimeType timeType); 95 96 /** 97 * @Description : 获取 AP Device 信息 98 * 99 * @param networkId - linkedinfo->networkId 100 * @param instId - linkedinfo->instId 101 * @param apDeviceInfo - AP Device info 102 */ 103 void GetApDeviceInfo(const int& networkId, int instId, WifiDeviceConfig& apDeviceInfo); // 获取并更新 AP Device 信息 104 105 /** 106 * @Description : 判断是否为邻频 ap 107 * 108 * @param apFrequency - 扫描 ap 的频率 109 * @param targetApFrequency - 目标 ap 的频率 110 * @param wifiBand - 目标 ap 的频段 111 * @return true - 是邻频 ap, false - 不是邻频 ap 112 */ 113 bool IsAdjacentChannel(int apFrequency, int targetApFrequency, char wifiBand); 114 115 /** 116 * @Description : 更新目标 ap 邻频和同频 ap 数 117 * 118 * @param apDetailInfo - ap 详细信息 119 * @param targetBssid - 目标 ap 的 bssid 120 * @param freq - 目标 ap 的频率 121 * @param band - 目标 ap 的频段 122 */ 123 void UpdateSameAdjaFreqCount(WifiCrowdsourcedDetailInfo& apDetailInfo, const std::string targetBssid, 124 const int freq, const int band); 125 126 /** 127 * @Description : 更新前台应用包名 128 * 129 * @param apDetailInfo - ap 详细信息 130 */ 131 void UpdateForegroundBundleName(WifiCrowdsourcedDetailInfo& apDetailInfo); 132 133 /** 134 * @Description : 更新众包数据的 ap 详细信息 135 * 136 * @param apDetailInfo - ap详细信息 137 * @param linkedInfo - ap linked 信息 138 * @param apDeviceInfo - ap device 信息 139 */ 140 void UpdateCrowdsourcedDetailInfo(WifiCrowdsourcedDetailInfo& apDetailInfo, 141 const WifiLinkedInfo& linkedInfo, const WifiDeviceConfig& apDeviceInfo); 142 143 /** 144 * @Description : 更新众包数据的 ap Qoe 信息 145 * 146 * @param apDetailInfo - ap详细信息 147 * @param historyData - ap 历史若干条 qoe 信息 148 */ 149 void UpdateCrowdsourcedQoeInfo(WifiCrowdsourcedQoeInfo& apQoeInfo, 150 const std::vector<WifiCrowdsourcedQoeInfo>& historyData); 151 152 /** 153 * @Description : 解析 WifiSignalPollInfo 信息 154 * 155 * @param parseInfo - 解析后存放的 Info 156 * @param signalPollInfo - signalPoll Info 157 */ 158 void ParseSignalPollInfo(WifiCrowdsourcedQoeInfo& parseInfo, const WifiSignalPollInfo& signalPollInfo); 159 160 /** 161 * @Description : 解析 WifiSignalPollInfo 信息 EX 162 * 163 * @param parseInfo - 解析后存放的 Info 164 * @param signalPollInfo - signalPoll Info 165 */ 166 void ParseSignalPollInfoEx(WifiCrowdsourcedQoeInfo& parseInfo, const WifiSignalPollInfo& signalPollInfo); 167 }; 168 } // namespace Wifi 169 } // namespace OHOS 170 #endif