1 /* 2 * Copyright (C) 2021-2023 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 WIFI_COUNTRY_CODE_POLICY_FACTORY_H 17 #define WIFI_COUNTRY_CODE_POLICY_FACTORY_H 18 19 #include <bitset> 20 #include <list> 21 #include <string> 22 #include "wifi_errcode.h" 23 #include "wifi_scan_msg.h" 24 #include "wifi_country_code_define.h" 25 #include "wifi_scan_msg.h" 26 27 namespace OHOS { 28 namespace Wifi { 29 class WifiCountryCodePolicy { 30 public: 31 /** 32 * @Description WifiCountryCodePolicy constructor 33 * 34 * @param wifiCountryCodePolicyConf wifi country code policy config 35 */ 36 explicit WifiCountryCodePolicy(std::bitset<WIFI_COUNTRY_CODE_POLICE_DEF_LEN> wifiCountryCodePolicyConf); 37 38 /** 39 * @Description WifiCountryCodePolicy destructor 40 */ 41 ~WifiCountryCodePolicy() = default; 42 43 /** 44 * @Description calculate wifi countryCode 45 * 46 * @return wifiCountryCode - country code 47 */ 48 ErrCode CalculateWifiCountryCode(std::string &wifiCountryCode); 49 50 /** 51 * @Description handle scan result action 52 */ 53 void HandleScanResultAction(); 54 private: 55 void CreatePolicy(std::bitset<WIFI_COUNTRY_CODE_POLICE_DEF_LEN> wifiCountryCodePolicyConf); 56 ErrCode GetWifiCountryCodeByFactory(std::string &wifiCountryCode); 57 ErrCode GetWifiCountryCodeByMcc(std::string &wifiCountryCode); 58 ErrCode StatisticCountryCodeFromScanResult(std::string &wifiCountryCode); 59 ErrCode FindLargestCountCountryCode(std::string &wifiCountryCode); 60 ErrCode ParseCountryCodeElement(const std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode); 61 ErrCode HandleWifiNetworkStateChangeAction(int connectionStatus); 62 ErrCode GetWifiCountryCodeByRegion(std::string &wifiCountryCode); 63 ErrCode GetWifiCountryCodeByAP(std::string &wifiCountryCode); 64 ErrCode GetWifiCountryCodeByScanResult(std::string &wifiCountryCode); 65 ErrCode GetWifiCountryCodeByDefaultZZ(std::string &wifiCountryCode); 66 ErrCode GetWifiCountryCodeByCache(std::string &wifiCountryCode); 67 ErrCode GetWifiCountryCodeByDefaultRegion(std::string &wifiCountryCode); 68 ErrCode GetWifiCountryCodeByDefault(std::string &wifiCountryCode); 69 bool IsContainBssid(const std::vector<std::string> &bssidList, const std::string &bssid); 70 71 std::vector<std::vector<std::string>> m_allBssidVector; 72 std::map<std::string, std::string> m_bssidAndCountryCodeMap; 73 std::string m_wifiCountryCodeFromScanResults; 74 std::list<std::function<ErrCode(std::string&)>> m_policyList; 75 }; 76 } 77 } 78 #endif