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