• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef OHOS_WIFI_NETWORK_SELECTION_MANAGER_H
18 #define OHOS_WIFI_NETWORK_SELECTION_MANAGER_H
19 
20 #include <mutex>
21 #include "network_selection.h"
22 #include "network_selector_factory.h"
23 
24 namespace OHOS::Wifi {
25 struct NetworkSelectionResult {
26     InterScanInfo interScanInfo;
27     WifiDeviceConfig wifiDeviceConfig;
28 };
29 
30 class NetworkSelectionManager {
31 public:
32     NetworkSelectionManager();
33 
34     /**
35      * the function to select network with ssid
36      *
37      * @param deviceConfig Ap device config information
38      * @param autoSelectBssid Candidate network bssid
39      */
40     void SelectNetworkWithSsid(WifiDeviceConfig& deviceConfig, std::string& autoSelectBssid);
41 
42     /**
43      * Convert WifiScanInfo to InterScanInfo
44      *
45      * @param wifiScanInfo wifiScanInfo
46      * @param interScanInfo interScanInfo
47      */
48     void ConvertScanInfo(WifiScanInfo &wifiScanInfo, InterScanInfo &interScanInfo);
49 
50     /**
51      * the function to select network.
52      *
53      * @param networkSelectionResult Network selection result
54      * @param type the type of networkSelection
55      * @param scanInfos scanInfos
56      * @return whether network selection is successful.
57      */
58     bool SelectNetwork(NetworkSelectionResult &networkSelectionResult,
59                        NetworkSelectType type,
60                        const std::vector<InterScanInfo> &scanInfos);
61 private:
62     std::unique_ptr<NetworkSelectorFactory> pNetworkSelectorFactory = nullptr;
63 
64     /**
65      * get the saved deviceConfig associated with scanInfo
66      *
67      * @param networkCandidates  Candidate network
68      * @param scanInfos scanInfos
69      */
70     static void GetAllDeviceConfigs(std::vector<NetworkSelection::NetworkCandidate> &networkCandidates,
71                                     const std::vector<InterScanInfo> &scanInfos);
72 
73     /**
74      * Try nominator the candidate network.
75      *
76      * @param networkCandidates candidate networks
77      * @param networkSelector networkSelector
78      */
79     static void TryNominate(std::vector<NetworkSelection::NetworkCandidate> &networkCandidates,
80                             const std::unique_ptr<NetworkSelection::INetworkSelector> &networkSelector);
81 
82     /**
83      * get saved configs for chr
84      *
85      * @param networkCandidates candidate networks
86      */
87     std::string GetSavedNetInfoForChr(
88         std::vector<NetworkSelection::NetworkCandidate> &networkCandidates, bool &isSavedNetEmpty);
89     /**
90      * get filtered reason for chr
91      *
92      * @param networkCandidates candidate networks
93      */
94     std::string GetFilteredReasonForChr(
95         std::vector<NetworkSelection::NetworkCandidate> &networkCandidates);
96 
97     /**
98      * get selected network info for chr
99      *
100      * @param networkCandidate best network candidate
101      */
102     std::string GetSelectedInfoForChr(NetworkSelection::NetworkCandidate *networkCandidate);
103 
104     /**
105      * is outdoor filter
106      *
107      * @param networkCandidate best network candidate
108      */
109     bool IsOutdoorFilter(NetworkSelection::NetworkCandidate *networkCandidate);
110 
111 private:
112     std::mutex rssiCntMutex_;
113     std::map<std::string, int> rssiCntMap_;
114 };
115 }
116 #endif
117