• 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 #ifndef OHOS_WIFI_SETTINGS_H
16 #define OHOS_WIFI_SETTINGS_H
17 
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include <atomic>
22 #include <memory>
23 #include <mutex>
24 #include <algorithm>
25 #include "wifi_config_file_impl.h"
26 
27 constexpr int RANDOM_STR_LEN = 6;
28 constexpr int MSEC = 1000;
29 constexpr int FOREGROUND_SCAN_CONTROL_TIMES = 4;
30 constexpr int FOREGROUND_SCAN_CONTROL_INTERVAL = 2 * 60;
31 constexpr int BACKGROUND_SCAN_CONTROL_TIMES = 1;
32 constexpr int BACKGROUND_SCAN_CONTROL_INTERVAL = 30 * 60;
33 constexpr int PNO_SCAN_CONTROL_TIMES = 1;
34 constexpr int PNO_SCAN_CONTROL_INTERVAL = 20;
35 constexpr int SYSTEM_TIMER_SCAN_CONTROL_TIMES = 4;
36 constexpr int SYSTEM_TIMER_SCAN_CONTROL_INTERVAL = 20;
37 constexpr int MODE_ADD = 0;
38 constexpr int MODE_DEL = 1;
39 constexpr int MODE_UPDATE = 2;
40 /* Obtain the scanning result that is valid within 180s. */
41 constexpr int WIFI_GET_SCAN_INFO_VALID_TIMESTAMP = 180;
42 
43 constexpr char DEVICE_CONFIG_FILE_PATH[] = "/data/misc/wifi/device_config.conf";
44 constexpr char HOTSPOT_CONFIG_FILE_PATH[] = "/data/misc/wifi/hotspot_config.conf";
45 constexpr char BLOCK_LIST_FILE_PATH[] = "/data/misc/wifi/block_list.conf";
46 constexpr char WIFI_CONFIG_FILE_PATH[] = "/data/misc/wifi/wifi_config.conf";
47 constexpr char WIFI_P2P_GROUP_INFO_FILE_PATH[] = "/data/misc/wifi/p2p_groups.conf";
48 constexpr char WIFI_P2P_VENDOR_CONFIG_FILE_PATH[] = "/data/misc/wifi/p2p_vendor_config.conf";
49 const std::string WIFI_TRUST_LIST_POLICY_FILE_PATH = "/data/misc/wifi/trust_list_polices.conf";
50 const std::string WIFI_MOVING_FREEZE_POLICY_FILE_PATH = "/data/misc/wifi/moving_freeze_policy.conf";
51 constexpr char WIFI_STA_RANDOM_MAC_FILE_PATH[] = "/data/misc/wifi/sta_randomMac.conf";
52 
53 namespace OHOS {
54 namespace Wifi {
55 using ChannelsTable = std::map<BandType, std::vector<int32_t>>;
56 
57 class WifiSettings {
58 public:
59     ~WifiSettings();
60     static WifiSettings &GetInstance();
61 
62     /**
63      * @Description Init the WifiSettings object
64      *
65      * @return int - init result, when 0 means success, other means some fails happened
66      */
67     int Init();
68 
69     /**
70      * @Description Get the Wifi Sta Capabilities
71      *
72      * @return int - mWifiStaCapabilities
73      */
74     int GetWifiStaCapabilities() const;
75 
76     /**
77      * @Description Save the Wifi Sta Capabilities
78      *
79      * @param capabilities - input capability
80      * @return int - 0 success
81      */
82     int SetWifiStaCapabilities(int capabilities);
83 
84     /**
85      * @Description Get current STA service state
86      *
87      * @return int - the wifi state, DISABLING/DISABLED/ENABLING/ENABLED/UNKNOWN
88      */
89     int GetWifiState() const;
90 
91     /**
92      * @Description Save STA service state
93      *
94      * @param state - the wifi state
95      * @return int - 0 success
96      */
97     int SetWifiState(int state);
98 
99     /**
100      * @Description Get the ScanAlways switch state
101      *
102      * @return true - ScanAlways on, false - ScanAlways off
103      */
104     bool GetScanAlwaysState() const;
105 
106     /**
107      * @Description Set the ScanAlways switch state
108      *
109      * @param isActive - ScanAlways on/off
110      * @return int - 0 success
111      */
112     int SetScanAlwaysState(bool isActive);
113 
114     /**
115      * @Description Save scan results
116      *
117      * @param results - vector scan results
118      * @return int - 0 success
119      */
120     int SaveScanInfoList(const std::vector<WifiScanInfo> &results);
121 
122     /**
123      * @Description Get scan results
124      *
125      * @param results - output vector of scan results
126      * @return int - 0 success
127      */
128     int GetScanInfoList(std::vector<WifiScanInfo> &results);
129 
130     /**
131      * @Description save the p2p connected info
132      *
133      * @param linkedInfo - WifiP2pLinkedInfo object
134      * @return int - 0 success
135      */
136     int SaveP2pInfo(WifiP2pLinkedInfo &linkedInfo);
137 
138     /**
139      * @Description Get the p2p connected info
140      *
141      * @param linkedInfo - output the p2p connected info
142      * @return int - 0 success
143      */
144     int GetP2pInfo(WifiP2pLinkedInfo &linkedInfo);
145 
146     /**
147      * @Description Get the scan control policy info
148      *
149      * @param info - output ScanControlInfo struct
150      * @return int - 0 success
151      */
152     int GetScanControlInfo(ScanControlInfo &info);
153 
154     /**
155      * @Description Save the scan control policy info
156      *
157      * @param info - input ScanControlInfo struct
158      * @return int - 0 success
159      */
160     int SetScanControlInfo(const ScanControlInfo &info);
161 
162     /**
163      * @Description Add Device Configuration
164      *
165      * @param config - WifiDeviceConfig object
166      * @return int - network id
167      */
168     int AddDeviceConfig(const WifiDeviceConfig &config);
169 
170     /**
171      * @Description Remove a wifi device config who's networkId equals input networkId
172      *
173      * @param networkId - a networkId that is to be removed
174      * @return int - 0 success ,other is failed
175      */
176     int RemoveDevice(int networkId);
177 
178     /**
179      * @Description Remove all saved wifi device config
180      *
181      */
182     void ClearDeviceConfig(void);
183 
184     /**
185      * @Description Get all saved wifi device config
186      *
187      * @param results - output wifi device config results
188      * @return int - 0 success
189      */
190     int GetDeviceConfig(std::vector<WifiDeviceConfig> &results);
191 
192     /**
193      * @Description Get the specify networkId's wifi device config
194      *
195      * @param networkId - network id
196      * @param config - output WifiDeviceConfig struct
197      * @return int - 0 success; -1 not find the device config
198      */
199     int GetDeviceConfig(const int &networkId, WifiDeviceConfig &config);
200 
201     /**
202      * @brief Get the specify wifi device config which bssid is equal to input bssid
203      *
204      * @param index - bssid string or ssid string
205      * @param indexType - index type 0:ssid 1:bssid
206      * @param config - output WifiDeviceConfig struct
207      * @return int - 0 success; -1 not find the device config
208      */
209     int GetDeviceConfig(const std::string &index, const int &indexType, WifiDeviceConfig &config);
210 
211     /**
212      * @Description Get the specify wifi device config which ssid is equal to input ssid and keymgmt is equal to input
213      * keymgmt
214      *
215      * @param ssid - ssid string
216      * @param keymgmt - keymgmt string
217      * @param config - output WifiDeviceConfig struct
218      * @return int - 0 success; -1 not find the device config
219      */
220     int GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config);
221     /**
222      * @Description Get the wifi device configs which hiddenSSID is true
223      *
224      * @param results - output WifiDeviceConfig structs
225      * @return int - 0 success
226      */
227     int GetHiddenDeviceConfig(std::vector<WifiDeviceConfig> &results);
228 
229     /**
230      * @Description Set a wifi device's state who's networkId equals input networkId;
231      * when the param bSetOther is true and the state is ENABLED, that means we need
232      * to set other wifi device DISABLED
233      * @param networkId - the wifi device's id
234      * @param state - WifiDeviceConfigStatus DISABLED/ENABLED/UNKNOWN
235      * @param bSetOther - whether set other device config disabled
236      * @return int - when 0 means success, other means some fails happened,
237      *               Input state invalid or not find the wifi device config
238      */
239     int SetDeviceState(int networkId, int state, bool bSetOther = false);
240 
241     /**
242      * @Description Synchronizing saved the wifi device config into config file
243      *
244      * @return int - 0 success; -1 save file failed
245      */
246     int SyncDeviceConfig();
247 
248     /**
249      * @Description Reload wifi device config from config file
250      *
251      * @return int - 0 success; -1 read config file failed
252      */
253     int ReloadDeviceConfig();
254 
255     /**
256      * @Description Synchronizing saved the wifi WifiP2pGroupInfo config into config file
257      *
258      * @return int - 0 success; -1 save file failed
259      */
260     int SyncWifiP2pGroupInfoConfig();
261 
262     /**
263      * @Description Reload wifi WifiP2pGroupInfo config from config file
264      *
265      * @return int - 0 success; -1 read config file failed
266      */
267     int ReloadWifiP2pGroupInfoConfig();
268 
269     /**
270      * @Description Save WifiP2pGroupInfo
271      *
272      * @param groups - input wifi p2p groups config results
273      * @return int - 0 success
274      */
275     int SetWifiP2pGroupInfo(const std::vector<WifiP2pGroupInfo> &groups);
276 
277     /**
278      * @Description Delete a WifiP2pGroupInfo node
279      *
280      * @return int
281      */
282     int RemoveWifiP2pGroupInfo();
283 
284     /**
285      * @Description Get all saved wifi p2p groups config
286      *
287      * @param results - output wifi p2p groups config results
288      * @return int - 0 success
289      */
290     int GetWifiP2pGroupInfo(std::vector<WifiP2pGroupInfo> &groups);
291 
292     /**
293      * @Description Get the dhcp info
294      *
295      * @param info - output IpInfo struct
296      * @return int - 0 success
297      */
298     int GetIpInfo(IpInfo &info);
299 
300     /**
301      * @Description Save dhcp info
302      *
303      * @param info - input IpInfo struct
304      * @return int - 0 success
305      */
306     int SaveIpInfo(const IpInfo &info);
307 
308     /**
309      * @Description Get current link info
310      *
311      * @param info - output WifiLinkedInfo struct
312      * @return int - 0 success
313      */
314     int GetLinkedInfo(WifiLinkedInfo &info);
315 
316     /**
317      * @Description Save link info
318      *
319      * @param info - input WifiLinkedInfo struct
320      * @return int - 0 success
321      */
322     int SaveLinkedInfo(const WifiLinkedInfo &info);
323 
324     /**
325      * @Description Save mac address
326      *
327      * @param macAddress - mac address info
328      * @return int - 0 success
329      */
330     int SetMacAddress(const std::string &macAddress);
331 
332     /**
333      * @Description Get the mac address
334      *
335      * @param macAddress - output mac address info
336      * @return int - 0 success
337      */
338     int GetMacAddress(std::string &macAddress);
339 
340     /**
341      * @Description reload mac address
342      *
343      * @return int - 0 success
344      */
345     int ReloadStaRandomMac();
346 
347     /**
348      * @Description add random mac address
349      *
350      * @param randomMacInfo - randmon mac address info
351      * @return int - 0 success
352      */
353     bool AddRandomMac(WifiStoreRandomMac &randomMacInfo);
354 
355     /**
356      * @Description Save the country code
357      *
358      * @param countryCode - input country code
359      * @return int - 0 success
360      */
361     int SetCountryCode(const std::string &countryCode);
362 
363     /**
364      * @Description Get the country code
365      *
366      * @param countryCode - output country code
367      * @return int - 0 success
368      */
369     int GetCountryCode(std::string &countryCode);
370 
371     /**
372      * @Description Get current hotspot state
373      *
374      * @return int - the hotspot state, IDLE/STARTING/STARTED/CLOSING/CLOSED
375      */
376     int GetHotspotState();
377 
378     /**
379      * @Description Save current hotspot state
380      *
381      * @param state - hotspot state
382      * @return int - 0 success
383      */
384     int SetHotspotState(int state);
385 
386     /**
387      * @Description Set the hotspot config
388      *
389      * @param config - input HotspotConfig struct
390      * @return int - 0 success
391      */
392     int SetHotspotConfig(const HotspotConfig &config);
393 
394     /**
395      * @Description Get the hotspot config
396      *
397      * @param config - output HotspotConfig struct
398      * @return int - 0 success
399      */
400     int GetHotspotConfig(HotspotConfig &config);
401 
402     /**
403      * @Description Synchronizing saved the Hotspot config into config file
404      *
405      * @return int - 0 success; -1 save file failed
406      */
407     int SyncHotspotConfig();
408 
409     /**
410      * @Description Set the p2p vendor config
411      *
412      * @param config - input P2pVendorConfig struct
413      * @return int - 0 success
414      */
415     int SetP2pVendorConfig(const P2pVendorConfig &config);
416 
417     /**
418      * @Description Get the p2p vendor config
419      *
420      * @param config - output P2pVendorConfig struct
421      * @return int - 0 success
422      */
423     int GetP2pVendorConfig(P2pVendorConfig &config);
424 
425     /**
426      * @Description Synchronizing saved the P2p Vendor config into config file
427      *
428      * @return int - 0 success; -1 save file failed
429      */
430     int SyncP2pVendorConfig();
431 
432     /**
433      * @Description Get current hotspot accept linked stations
434      *
435      * @param results - output StationInfo results
436      * @return int - 0 success
437      */
438     int GetStationList(std::vector<StationInfo> &results);
439 
440     /**
441      * @Description Management (add/update/delete) connected station list
442      *
443      * @param info - input StationInfo struct
444      * @param mode - mode of MODE_ADD MODE_UPDATE MODE_DEL
445      * @return int - 0 success; -1 mode not correct
446      */
447     int ManageStation(const StationInfo &info, int mode); /* add / update / remove */
448 
449     /**
450      * @Description Clear connected station list
451      *
452      * @return int - 0 success
453      */
454     int ClearStationList();
455 
456     /**
457      * @Description Get the block list
458      *
459      * @param results - output StationInfo results
460      * @return int - 0 success
461      */
462     int GetBlockList(std::vector<StationInfo> &results);
463 
464     /**
465      * @Description Manager (add/update/delete) station connect Blocklist
466      *
467      * @param info - input StationInfo struct
468      * @param mode - mode of MODE_ADD MODE_DEL MODE_UPDATE
469      * @return int - 0 success; -1 mode not correct
470      */
471     int ManageBlockList(const StationInfo &info, int mode); /* add / remove */
472 
473     /**
474      * @Description Judge whether the station is in current linked station list
475      *
476      * @param info - input StationInfo struct
477      * @return int - 0 find the station, exist; -1 not find, not exist
478      */
479     int FindConnStation(const StationInfo &info);
480 
481     /**
482      * @Description Synchronizing saved the block list config into config file
483      *
484      * @return int - 0 success; -1 save file failed
485      */
486     int SyncBlockList();
487 
488     /**
489      * @Description Get the Valid Bands object
490      *
491      * @param bands - output vector fo BandType
492      * @return int - 0 success
493      */
494     int GetValidBands(std::vector<BandType> &bands);
495 
496     /**
497      * @Description Set the Valid Channels object
498      *
499      * @param channelsInfo - input ChannelsTable struct
500      * @return int - 0 success
501      */
502     int SetValidChannels(const ChannelsTable &channelsInfo);
503 
504     /**
505      * @Description Get the Valid Channels object
506      *
507      * @param channelsInfo - output ChannelsTable struct
508      * @return int - 0 success
509      */
510     int GetValidChannels(ChannelsTable &channelsInfo);
511 
512     /**
513      * @Description Clear the number of valid channels
514      *
515      * @return int - 0 success
516      */
517     int ClearValidChannels();
518 
519     /**
520      * @Description set the p2p state
521      *
522      * @param state - the p2p state
523      * @return int - 0 success
524      */
525     int SetP2pState(int state);
526 
527     /**
528      * @Description Get current p2p state
529      *
530      * @return int - the p2p state, NONE/IDLE/STARTING/STARTED/CLOSING/CLOSED
531      */
532     int GetP2pState();
533 
534     /**
535      * @Description set the p2p discover state
536      *
537      * @param state - the p2p discover state
538      * @return int - 0 success
539      */
540     int SetP2pDiscoverState(int state);
541 
542     /**
543      * @Description Get current p2p discover state
544      *
545      * @return int -the p2p discover state, P2P_DISCOVER_NONE/P2P_DISCOVER_STARTING/P2P_DISCOVER_CLOSED
546      */
547     int GetP2pDiscoverState();
548 
549     /**
550      * @Description set the p2p connected state
551      *
552      * @param state - the p2p connected state
553      * @return int - 0 success
554      */
555     int SetP2pConnectedState(int state);
556 
557     /**
558      * @Description Get current p2p connected state
559      *
560      * @return int - the connected state, P2P_CONNECTED_NONE/P2P_CONNECTED_STARTING/P2P_CONNECTED_CLOSED
561      */
562     int GetP2pConnectedState();
563 
564     /**
565      * @Description Get signal level about given rssi and band
566      *
567      * @param rssi - rssi info
568      * @param band - band info
569      * @return int - level
570      */
571     int GetSignalLevel(const int &rssi, const int &band);
572 
573     /**
574      * @Description Get the Ap Max Conn Num
575      *
576      * @return int - number
577      */
578     int GetApMaxConnNum();
579 
580     /**
581      * @Description Enable Network
582      *
583      * @param networkId - enable network id
584      * @param disableOthers - when set, save this network id, and can use next time
585      * @return true
586      * @return false
587      */
588     bool EnableNetwork(int networkId, bool disableOthers);
589 
590     /**
591      * @Description Set the User Last Selected Network Id
592      *
593      * @param networkId - network id
594      */
595     void SetUserLastSelectedNetworkId(int networkId);
596 
597     /**
598      * @Description Get the User Last Selected Network Id
599      *
600      * @return int - network id
601      */
602     int GetUserLastSelectedNetworkId();
603 
604     /**
605      * @Description Get the User Last Selected Network time
606      *
607      * @return time_t - timestamp
608      */
609     time_t GetUserLastSelectedNetworkTimeVal();
610 
611     /**
612      * @Description Synchronizing saved the WifiConfig into config file
613      *
614      * @return int - 0 success; -1 save file failed
615      */
616     int SyncWifiConfig();
617 
618     /**
619      * @Description Get the config whether permit to use wifi when airplane mode opened
620      *
621      * @return true - can use
622      * @return false - cannot use
623      */
624     bool GetCanUseStaWhenAirplaneMode();
625 
626     /**
627      * @Description Set the config whether permit to use wifi when airplane mode opened
628      *
629      * @param bCan - true / false
630      * @return int - 0 success
631      */
632     int SetCanUseStaWhenAirplaneMode(bool bCan);
633 
634     /**
635      * @Description Get the config whether can open sta when airplane mode opened
636      *
637      * @return true - can open
638      * @return false - can't open
639      */
640     bool GetCanOpenStaWhenAirplaneMode();
641 
642     /**
643      * @Description Get the STA service last running state
644      *
645      * @return true - running
646      * @return false - not running
647      */
648     bool GetStaLastRunState();
649 
650     /**
651      * @Description Set the STA service running state
652      *
653      * @param bRun - running or not
654      * @return int - 0 success
655      */
656     int SetStaLastRunState(bool bRun);
657 
658     /**
659      * @Description Get the Dhcp Ip Type
660      *
661      * @return int - dhcp ip type, ipv4/ipv6/double
662      */
663     int GetDhcpIpType();
664 
665     /**
666      * @Description Set the Dhcp Ip Type
667      *
668      * @param dhcpIpType - ipv4/ipv6/double
669      * @return int - 0 success
670      */
671     int SetDhcpIpType(int dhcpIpType);
672 
673     /**
674      * @Description Get the Default Wifi Interface
675      *
676      * @return std::string - interface name
677      */
678     std::string GetDefaultWifiInterface();
679 
680     /**
681      * @Description Set the Screen State
682      *
683      * @param state - 1 on; 2 off
684      */
685     void SetScreenState(const int &state);
686 
687     /**
688      * @Description Get the Screen State
689      *
690      * @return int - 1 on; 2 off
691      */
692     int GetScreenState() const;
693 
694     /**
695      * @Description Set the Airplane Mode State
696      *
697      * @param state - 1 open; 2 close
698      */
699     void SetAirplaneModeState(const int &state);
700 
701     /**
702      * @Description Get the Airplane Mode State
703      *
704      * @return int - 1 open; 2 close
705      */
706     int GetAirplaneModeState() const;
707 
708     /**
709      * @Description Set the App Running State
710      *
711      * @param appRunMode - app run mode
712      */
713     void SetAppRunningState(ScanMode appRunMode);
714 
715     /**
716      * @Description Get the App Running State
717      *
718      * @return ScanMode
719      */
720     ScanMode GetAppRunningState() const;
721 
722     /**
723      * @Description Set the Power Saving Mode State
724      *
725      * @param state - 1 open; 2 close
726      */
727     void SetPowerSavingModeState(const int &state);
728 
729     /**
730      * @Description Get the Power Saving Mode State
731      *
732      * @return int - 1 open; 2 close
733      */
734     int GetPowerSavingModeState() const;
735 
736     /**
737      * @Description Set app package name.
738      *
739      * @param appPackageName - app package name
740      */
741     void SetAppPackageName(const std::string &appPackageName);
742 
743     /**
744      * @Description Get app package name.
745      *
746      * @return const std::string& - app package name.
747      */
748     const std::string& GetAppPackageName() const;
749 
750     /**
751      * @Description Set freeze mode state.
752      *
753      * @param state - 1 freeze mode; 2 moving mode
754      */
755     void SetFreezeModeState(int state);
756 
757     /**
758      * @Description Get freeze mode state.
759      *
760      * @return freeze mode.
761      */
762     int GetFreezeModeState() const;
763 
764     /**
765      * @Description Set no charger plugged in mode.
766      *
767      * @param state - 1 no charger plugged in mode; 2 charger plugged in mode
768      */
769     void SetNoChargerPlugModeState(int state);
770 
771     /**
772      * @Description Get no charger plugged in mode.
773      *
774      * @return no charger plugged in mode.
775      */
776     int GetNoChargerPlugModeState() const;
777 
778     /**
779      * @Description Set enable/disable Whether to allow network switchover
780      *
781      * @param bSwitch - enable/disable
782      * @return int - 0 success
783      */
784     int SetWhetherToAllowNetworkSwitchover(bool bSwitch);
785 
786     /**
787      * @Description Check whether enable network switchover
788      *
789      * @return true - enable
790      * @return false - disable
791      */
792     bool GetWhetherToAllowNetworkSwitchover();
793 
794     /**
795      * @Description Set the policy score slope
796      *
797      * @param score - score
798      * @return int - 0 success
799      */
800     int SetScoretacticsScoreSlope(const int &score);
801 
802     /**
803      * @Description Get the policy score slope
804      *
805      * @return int - score
806      */
807     int GetScoretacticsScoreSlope();
808 
809     /**
810      * @Description Initial score of the set strategy
811      *
812      * @param score - score
813      * @return int - 0 success
814      */
815     int SetScoretacticsInitScore(const int &score);
816 
817     /**
818      * @Description Obtain the initial score of the tactic
819      *
820      * @return int - score
821      */
822     int GetScoretacticsInitScore();
823 
824     /**
825      * @Description Set the scoring policy to the same BSSID score
826      *
827      * @param score - score
828      * @return int - 0 success
829      */
830     int SetScoretacticsSameBssidScore(const int &score);
831 
832     /**
833      * @Description Get the scoring policy to the same BSSID score
834      *
835      * @return int - score
836      */
837     int GetScoretacticsSameBssidScore();
838 
839     /**
840      * @Description Set the score policy for the same network
841      *
842      * @param score - score
843      * @return int - 0 success
844      */
845     int SetScoretacticsSameNetworkScore(const int &score);
846 
847     /**
848      * @Description Get the score policy for the same network
849      *
850      * @return int - score
851      */
852     int GetScoretacticsSameNetworkScore();
853 
854     /**
855      * @Description Set the 5 GHz score of the policy frequency
856      *
857      * @param score - score
858      * @return int - 0 success
859      */
860     int SetScoretacticsFrequency5GHzScore(const int &score);
861 
862     /**
863      * @Description Get the 5 GHz score of the policy frequency
864      *
865      * @return int - score
866      */
867     int GetScoretacticsFrequency5GHzScore();
868 
869     /**
870      * @Description Set the score policy. last select score
871      *
872      * @param score - score
873      * @return int - 0 success
874      */
875     int SetScoretacticsLastSelectionScore(const int &score);
876 
877     /**
878      * @Description Get the score policy, last select score
879      *
880      * @return int - score
881      */
882     int GetScoretacticsLastSelectionScore();
883 
884     /**
885      * @Description Setting the Score Policy Security Score
886      *
887      * @param score - score
888      * @return int - 0 success
889      */
890     int SetScoretacticsSecurityScore(const int &score);
891 
892     /**
893      * @Description Get the Score Policy Security Score
894      *
895      * @return int - priority
896      */
897     int GetScoretacticsSecurityScore();
898 
899     /**
900      * @Description Set the saved device appraisal priority
901      *
902      * @param priority - priority
903      * @return int - 0 success
904      */
905     int SetSavedDeviceAppraisalPriority(const int &priority);
906 
907     /**
908      * @Description Get the saved device appraisal priority
909      *
910      * @return int - priority
911      */
912     int GetSavedDeviceAppraisalPriority();
913 
914     /**
915      * @Description Judge the Module need preloaded or not
916      *
917      * @param name - module name
918      * @return true - need preload
919      * @return false - no need preload
920      */
921     bool IsModulePreLoad(const std::string &name);
922 
923     /**
924      * @Description Save wps connection device config
925      *
926      * @param config - input WifiDeviceConfig struct
927      * @return int - 0 success; -1 load the device config file failed
928      */
929     int AddWpsDeviceConfig(const WifiDeviceConfig &config);
930     /**
931      * @Description Get the Support HwPno Flag object
932      *
933      * @return true - support HwPno scan
934      * @return false - not support HwPno scan
935      */
936     bool GetSupportHwPnoFlag();
937     /**
938      * @Description Get the Min 2.4G strength object
939      *
940      * @return int Min 2.4G strength
941      */
942     int GetMinRssi2Dot4Ghz();
943     /**
944      * @Description Get the Min 5G strength object
945      *
946      * @return int Min 5G strength
947      */
948     int GetMinRssi5Ghz();
949 
950     /**
951      * @Description Get the Alternate dns.
952      *
953      * @return string - dns
954      */
955     std::string GetStrDnsBak() const;
956     /**
957      * @Description Obtaining Whether to Load the Configuration of the Standby STA.
958      *
959      * @return bool - Indicates whether to load the configuration of the standby STA.
960      */
961     bool IsLoadStabak() const;
962 
963     /**
964      * @Description set the device name
965      *
966      * @param deviceName - device name
967      * @return int - result
968      */
969     int SetP2pDeviceName(const std::string &deviceName);
970 
971     /**
972      * @Description get trustlist policies.
973      *
974      * @return const std::vector<TrustListPolicy>& - trustlist policies.
975      */
976     const std::vector<TrustListPolicy>& ReloadTrustListPolicies();
977 
978     /**
979      * @Description get moving freeze state trustlist.
980      *
981      * @return const MovingFreezePolicy& - moving freeze policy.
982      */
983     const MovingFreezePolicy& ReloadMovingFreezePolicy();
984 
985     /**
986      * @Description get bssid of connection timeout for last time.
987      *
988      * @return bssid.
989      */
990     std::string GetConnectTimeoutBssid();
991 
992     /**
993      * @Description set bssid of connection timeout for last time.
994      *
995      * @return int - result
996      */
997     int SetConnectTimeoutBssid(std::string &bssid);
998 
999 private:
1000     WifiSettings();
1001     void InitWifiConfig();
1002     void InitDefaultHotspotConfig();
1003     void InitHotspotConfig();
1004     void InitDefaultP2pVendorConfig();
1005     void InitP2pVendorConfig();
1006     void InitGetApMaxConnNum();
1007     void InitScanControlForbidList();
1008     void InitScanControlIntervalList();
1009     void InitScanControlInfo();
1010 
1011 private:
1012     int mWifiStaCapabilities;            /* Sta capability */
1013     std::atomic<int> mWifiState;         /* Sta service state */
1014     std::atomic<bool> mScanAlwaysActive; /* if scan always */
1015     std::vector<WifiScanInfo> mWifiScanInfoList;
1016     std::vector<WifiP2pGroupInfo> mGroupInfoList;
1017     std::vector<WifiStoreRandomMac> mWifiStoreRandomMac;
1018     ScanControlInfo mScanControlInfo;
1019     WifiP2pLinkedInfo mWifiP2pInfo;
1020     std::map<int, WifiDeviceConfig> mWifiDeviceConfig;
1021     IpInfo mWifiIpInfo;
1022     WifiLinkedInfo mWifiLinkedInfo;
1023     std::string mMacAddress;
1024     std::string mCountryCode;
1025     std::atomic<int> mHotspotState;
1026     HotspotConfig mHotspotConfig;
1027     P2pVendorConfig mP2pVendorConfig;
1028     std::map<std::string, StationInfo> mConnectStationInfo;
1029     std::map<std::string, StationInfo> mBlockListInfo;
1030     ChannelsTable mValidChannels;
1031     std::atomic<int> mP2pState;
1032     std::atomic<int> mP2pDiscoverState;
1033     std::atomic<int> mP2pConnectState;
1034     int mApMaxConnNum;           /* ap support max sta numbers */
1035     int mLastSelectedNetworkId;  /* last selected networkid */
1036     time_t mLastSelectedTimeVal; /* last selected time */
1037     int mScreenState;            /* 1 on 2 off */
1038     int mAirplaneModeState;      /* 1 on 2 off */
1039     ScanMode mAppRunningModeState; /* 0 app for 1 app back 2 sys for 3 sys back */
1040     int mPowerSavingModeState;   /* 1 on 2 off */
1041     std::string mAppPackageName;
1042     int mFreezeModeState;        /* 1 on 2 off */
1043     int mNoChargerPlugModeState;  /* 1 on 2 off */
1044     WifiConfig mWifiConfig;
1045     std::pair<std::string, int> mBssidToTimeoutTime;
1046 
1047     std::mutex mStaMutex;
1048     std::mutex mApMutex;
1049     std::mutex mConfigMutex;
1050     std::mutex mInfoMutex;
1051     std::mutex mP2pMutex;
1052 
1053     std::atomic_flag deviceConfigLoadFlag = ATOMIC_FLAG_INIT;
1054 
1055     WifiConfigFileImpl<WifiDeviceConfig> mSavedDeviceConfig; /* Persistence device config */
1056     WifiConfigFileImpl<HotspotConfig> mSavedHotspotConfig;
1057     WifiConfigFileImpl<StationInfo> mSavedBlockInfo;
1058     WifiConfigFileImpl<WifiConfig> mSavedWifiConfig;
1059     WifiConfigFileImpl<WifiP2pGroupInfo> mSavedWifiP2pGroupInfo;
1060     WifiConfigFileImpl<P2pVendorConfig> mSavedWifiP2pVendorConfig;
1061     WifiConfigFileImpl<TrustListPolicy> mTrustListPolicies;
1062     WifiConfigFileImpl<MovingFreezePolicy> mMovingFreezePolicy;
1063     MovingFreezePolicy mFPolicy;
1064     WifiConfigFileImpl<WifiStoreRandomMac> mSavedWifiStoreRandomMac;
1065 };
1066 }  // namespace Wifi
1067 }  // namespace OHOS
1068 #endif