1 /*
2 * Copyright (C) 2024 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 #include <random>
17 #include "wifi_config_center.h"
18 #include "wifi_logger.h"
19 #include "wifi_common_util.h"
20 #include "wifi_global_func.h"
21 #include "wifi_randommac_helper.h"
22 #ifndef OHOS_ARCH_LITE
23 #include "display_info.h"
24 #endif
25 DEFINE_WIFILOG_LABEL("WifiConfigCenter");
26
27 namespace OHOS {
28 namespace Wifi {
29 #ifdef DTFUZZ_TEST
30 static WifiConfigCenter* gWifiConfigCenter = nullptr;
31 #endif
GetInstance()32 WifiConfigCenter &WifiConfigCenter::GetInstance()
33 {
34 #ifdef DTFUZZ_TEST
35 if (gWifiConfigCenter == nullptr) {
36 gWifiConfigCenter = new (std::nothrow) WifiConfigCenter();
37 }
38 if (gWifiConfigCenter == nullptr) {
39 static WifiConfigCenter gWifiConfigCenter;
40 return gWifiConfigCenter;
41 }
42 return *gWifiConfigCenter;
43 #else
44 static WifiConfigCenter gWifiConfigCenter;
45 return gWifiConfigCenter;
46 #endif
47 }
48
WifiConfigCenter()49 WifiConfigCenter::WifiConfigCenter()
50 {
51 mWifiState.emplace(0, static_cast<int>(WifiState::DISABLED));
52 mWifiDetailState.emplace(0, WifiDetailState::STATE_INACTIVE);
53 mStaMidState.emplace(0, WifiOprMidState::CLOSED);
54 mWifiCloseTime.emplace(0, std::chrono::steady_clock::now());
55 mIsAncoConnected.emplace(0, false);
56 mWifiIpInfo.emplace(0, IpInfo());
57 mWifiIpV6Info.emplace(0, IpV6Info());
58 mWifiLinkedInfo.emplace(0, WifiLinkedInfo());
59 mWifiMloLinkedInfo.emplace(0, std::vector<WifiLinkedInfo>());
60 mLastSelectedNetworkId.emplace(0, INVALID_NETWORK_ID);
61 mLastSelectedTimeVal.emplace(0, time(NULL));
62 mBssidToTimeoutTime.emplace(0, std::make_pair("", 0));
63 mLastDiscReason.emplace(0, DisconnectedReason::DISC_REASON_DEFAULT);
64 mScanMidState.emplace(0, WifiOprMidState::CLOSED);
65 mScanOnlyMidState.emplace(0, WifiOprMidState::CLOSED);
66 mApMidState.emplace(0, WifiOprMidState::CLOSED);
67 mHotspotState.emplace(0, static_cast<int>(ApState::AP_STATE_CLOSED));
68 powerModel.emplace(0, PowerModel::GENERAL);
69 }
70
~WifiConfigCenter()71 WifiConfigCenter::~WifiConfigCenter()
72 {}
73
Init()74 int WifiConfigCenter::Init()
75 {
76 if (WifiSettings::GetInstance().Init() < 0) {
77 WIFI_LOGE("Init wifi settings failed!");
78 return -1;
79 }
80 wifiScanConfig = std::make_unique<WifiScanConfig>();
81 ClearLocalHid2dInfo();
82 if (systemMode_ == SystemMode::M_FACTORY_MODE) {
83 mPersistWifiState[INSTID_WLAN0] = WIFI_STATE_DISABLED;
84 } else {
85 mPersistWifiState[INSTID_WLAN0] = WifiSettings::GetInstance().GetOperatorWifiType(INSTID_WLAN0);
86 }
87 mAirplaneModeState = WifiSettings::GetInstance().GetLastAirplaneMode();
88 return 0;
89 }
90
GetWifiScanConfig()91 std::unique_ptr<WifiScanConfig>& WifiConfigCenter::GetWifiScanConfig()
92 {
93 return wifiScanConfig;
94 }
95
SetWifiSelfcureReset(const bool isReset)96 void WifiConfigCenter::SetWifiSelfcureReset(const bool isReset)
97 {
98 mWifiSelfcureReset = isReset;
99 }
100
GetWifiSelfcureReset() const101 bool WifiConfigCenter::GetWifiSelfcureReset() const
102 {
103 return mWifiSelfcureReset.load();
104 }
105
SetWifiSelfcureResetEntered(const bool isReset)106 void WifiConfigCenter::SetWifiSelfcureResetEntered(const bool isReset)
107 {
108 mWifiSelfcureResetEntered = isReset;
109 }
110
GetWifiSelfcureResetEntered() const111 bool WifiConfigCenter::GetWifiSelfcureResetEntered() const
112 {
113 return mWifiSelfcureResetEntered.load();
114 }
115
SetLastNetworkId(const int networkId)116 void WifiConfigCenter::SetLastNetworkId(const int networkId)
117 {
118 mLastNetworkId = networkId;
119 }
120
GetLastNetworkId() const121 int WifiConfigCenter::GetLastNetworkId() const
122 {
123 return mLastNetworkId.load();
124 }
125
SetSelectedCandidateNetworkId(const int networkId)126 void WifiConfigCenter::SetSelectedCandidateNetworkId(const int networkId)
127 {
128 mSelectedCandidateNetworkId = networkId;
129 }
130
GetSelectedCandidateNetworkId() const131 int WifiConfigCenter::GetSelectedCandidateNetworkId() const
132 {
133 return mSelectedCandidateNetworkId.load();
134 }
135
SetWifiAllowSemiActive(bool isAllowed)136 void WifiConfigCenter::SetWifiAllowSemiActive(bool isAllowed)
137 {
138 mWifiAllowSemiActive = isAllowed;
139 }
140
GetWifiAllowSemiActive() const141 bool WifiConfigCenter::GetWifiAllowSemiActive() const
142 {
143 if (WifiConfigCenter::GetInstance().GetSystemMode() == SystemMode::M_FACTORY_MODE) {
144 WIFI_LOGI("factory mode, not allow semi active.");
145 return false;
146 }
147 return mWifiAllowSemiActive.load();
148 }
149
SetWifiStopState(bool state)150 void WifiConfigCenter::SetWifiStopState(bool state)
151 {
152 mWifiStoping = state;
153 }
154
GetWifiStopState() const155 bool WifiConfigCenter::GetWifiStopState() const
156 {
157 return mWifiStoping.load();
158 }
159
SetStaIfaceName(const std::string & ifaceName,int instId)160 void WifiConfigCenter::SetStaIfaceName(const std::string &ifaceName, int instId)
161 {
162 std::unique_lock<std::mutex> lock(mStaMutex);
163 mStaIfaceName[instId] = ifaceName;
164 }
165
GetStaIfaceName(int instId)166 std::string WifiConfigCenter::GetStaIfaceName(int instId)
167 {
168 std::unique_lock<std::mutex> lock(mStaMutex);
169 WIFI_LOGD("GetStaIfaceName instId:%{public}d mStaIfaceName[instId]:%{public}s ",
170 instId, mStaIfaceName[instId].c_str());
171 return mStaIfaceName[instId];
172 }
173
GetWifiState(int instId)174 int WifiConfigCenter::GetWifiState(int instId)
175 {
176 std::unique_lock<std::mutex> lock(mStaMutex);
177 auto iter = mWifiState.find(instId);
178 if (iter != mWifiState.end()) {
179 return iter->second.load();
180 }
181 mWifiState[instId] = static_cast<int>(WifiState::DISABLED);
182 return mWifiState[instId].load();
183 }
184
SetWifiState(int state,int instId)185 int WifiConfigCenter::SetWifiState(int state, int instId)
186 {
187 std::unique_lock<std::mutex> lock(mStaMutex);
188 mWifiState[instId] = state;
189 return 0;
190 }
191
GetWifiDetailState(int instId)192 WifiDetailState WifiConfigCenter::GetWifiDetailState(int instId)
193 {
194 std::unique_lock<std::mutex> lock(mStaMutex);
195 auto iter = mWifiDetailState.find(instId);
196 if (iter != mWifiDetailState.end()) {
197 return iter->second;
198 }
199 mWifiDetailState[instId] = WifiDetailState::STATE_UNKNOWN;
200 return mWifiDetailState[instId];
201 }
202
SetWifiDetailState(WifiDetailState state,int instId)203 int WifiConfigCenter::SetWifiDetailState(WifiDetailState state, int instId)
204 {
205 std::unique_lock<std::mutex> lock(mStaMutex);
206 mWifiDetailState[instId] = state;
207 return 0;
208 }
209
GetWifiMidState(int instId)210 WifiOprMidState WifiConfigCenter::GetWifiMidState(int instId)
211 {
212 std::unique_lock<std::mutex> lock(mStaMutex);
213 auto iter = mStaMidState.find(instId);
214 if (iter != mStaMidState.end()) {
215 return iter->second.load();
216 } else {
217 mStaMidState.emplace(instId, WifiOprMidState::CLOSED);
218 return mStaMidState[instId].load();
219 }
220 }
221
SetWifiMidState(WifiOprMidState expState,WifiOprMidState state,int instId)222 bool WifiConfigCenter::SetWifiMidState(WifiOprMidState expState, WifiOprMidState state, int instId)
223 {
224 WIFI_LOGI("SetWifiMidState expState:%{public}d,state:%{public}d,instId:%{public}d",
225 (int)expState, (int)state, instId);
226 std::unique_lock<std::mutex> lock(mStaMutex);
227 auto iter = mStaMidState.find(instId);
228 if (iter != mStaMidState.end()) {
229 return iter->second.compare_exchange_strong(expState, state);
230 } else {
231 mStaMidState.emplace(instId, state);
232 return true;
233 }
234 return false;
235 }
236
SetWifiMidState(WifiOprMidState state,int instId)237 void WifiConfigCenter::SetWifiMidState(WifiOprMidState state, int instId)
238 {
239 WIFI_LOGI("SetWifiMidState ,state:%{public}d,instId:%{public}d", (int)state, instId);
240 std::unique_lock<std::mutex> lock(mStaMutex);
241 auto ret = mStaMidState.emplace(instId, state);
242 if (!ret.second) {
243 mStaMidState[instId] = state;
244 }
245 }
246
SetWifiStaCloseTime(int instId)247 void WifiConfigCenter::SetWifiStaCloseTime(int instId)
248 {
249 std::unique_lock<std::mutex> lock(mStaMutex);
250 mWifiCloseTime[instId] = std::chrono::steady_clock::now();
251 }
252
GetWifiStaInterval(int instId)253 double WifiConfigCenter::GetWifiStaInterval(int instId)
254 {
255 std::unique_lock<std::mutex> lock(mStaMutex);
256 auto iter = mWifiCloseTime.find(instId);
257 if (iter != mWifiCloseTime.end()) {
258 std::chrono::steady_clock::time_point curr = std::chrono::steady_clock::now();
259 double drMs = std::chrono::duration<double, std::milli>(curr - iter->second).count();
260 return drMs;
261 }
262
263 return 0;
264 }
265
GetWifiConnectedMode(int instId)266 bool WifiConfigCenter::GetWifiConnectedMode(int instId)
267 {
268 std::unique_lock<std::mutex> lock(mStaMutex);
269 return mIsAncoConnected[instId].load();
270 }
271
SetWifiConnectedMode(bool isAncoConnected,int instId)272 void WifiConfigCenter::SetWifiConnectedMode(bool isAncoConnected, int instId)
273 {
274 std::unique_lock<std::mutex> lock(mStaMutex);
275 mIsAncoConnected[instId] = isAncoConnected;
276 }
277
278
SetChangeDeviceConfig(ConfigChange value,const WifiDeviceConfig & config)279 int WifiConfigCenter::SetChangeDeviceConfig(ConfigChange value, const WifiDeviceConfig &config)
280 {
281 std::unique_lock<std::mutex> lock(mStaMutex);
282 mLastRemoveDeviceConfig = std::make_pair((int)value, config);
283 return WIFI_OPT_SUCCESS;
284 }
285
GetChangeDeviceConfig(ConfigChange & value,WifiDeviceConfig & config)286 bool WifiConfigCenter::GetChangeDeviceConfig(ConfigChange& value, WifiDeviceConfig &config)
287 {
288 std::unique_lock<std::mutex> lock(mStaMutex);
289 value = (ConfigChange)mLastRemoveDeviceConfig.first;
290 config = mLastRemoveDeviceConfig.second;
291 return true;
292 }
293
GetIpInfo(IpInfo & info,int instId)294 int WifiConfigCenter::GetIpInfo(IpInfo &info, int instId)
295 {
296 std::unique_lock<std::mutex> lock(mStaMutex);
297 auto iter = mWifiIpInfo.find(instId);
298 if (iter != mWifiIpInfo.end()) {
299 info = iter->second;
300 }
301 return 0;
302 }
303
SaveIpInfo(const IpInfo & info,int instId)304 int WifiConfigCenter::SaveIpInfo(const IpInfo &info, int instId)
305 {
306 std::unique_lock<std::mutex> lock(mStaMutex);
307 mWifiIpInfo[instId] = info;
308 return 0;
309 }
310
GetIpv6Info(IpV6Info & info,int instId)311 int WifiConfigCenter::GetIpv6Info(IpV6Info &info, int instId)
312 {
313 std::unique_lock<std::mutex> lock(mStaMutex);
314 auto iter = mWifiIpV6Info.find(instId);
315 if (iter != mWifiIpV6Info.end()) {
316 info = iter->second;
317 }
318 return 0;
319 }
320
SaveIpV6Info(const IpV6Info & info,int instId)321 int WifiConfigCenter::SaveIpV6Info(const IpV6Info &info, int instId)
322 {
323 std::unique_lock<std::mutex> lock(mStaMutex);
324 mWifiIpV6Info[instId] = info;
325 return 0;
326 }
327
GetAllWifiLinkedInfo()328 std::map<int, WifiLinkedInfo> WifiConfigCenter::GetAllWifiLinkedInfo()
329 {
330 std::unique_lock<std::mutex> lock(mStaMutex);
331 return mWifiLinkedInfo;
332 }
333
GetLinkedInfo(WifiLinkedInfo & info,int instId)334 int WifiConfigCenter::GetLinkedInfo(WifiLinkedInfo &info, int instId)
335 {
336 std::unique_lock<std::mutex> lock(mStaMutex);
337 auto iter = mWifiLinkedInfo.find(instId);
338 if (iter != mWifiLinkedInfo.end()) {
339 info = iter->second;
340 }
341 return 0;
342 }
343
SaveLinkedInfo(const WifiLinkedInfo & info,int instId)344 int WifiConfigCenter::SaveLinkedInfo(const WifiLinkedInfo &info, int instId)
345 {
346 std::unique_lock<std::mutex> lock(mStaMutex);
347 auto iter = mWifiLinkedInfo.find(instId);
348 if (iter != mWifiLinkedInfo.end()) {
349 WifiChannelWidth channelWidth = iter->second.channelWidth;
350 std::string bssid = iter->second.bssid;
351 iter->second = info;
352 if (bssid == info.bssid) {
353 iter->second.channelWidth = channelWidth;
354 }
355 } else {
356 mWifiLinkedInfo.emplace(instId, info);
357 }
358
359 return 0;
360 }
361
GetMloLinkedInfo(std::vector<WifiLinkedInfo> & mloInfo,int instId)362 int WifiConfigCenter::GetMloLinkedInfo(std::vector<WifiLinkedInfo> &mloInfo, int instId)
363 {
364 std::unique_lock<std::mutex> lock(mStaMutex);
365 auto iter = mWifiMloLinkedInfo.find(instId);
366 if (iter != mWifiMloLinkedInfo.end()) {
367 if (iter->second.size() != WIFI_MAX_MLO_LINK_NUM) {
368 return -1;
369 }
370 mloInfo = iter->second;
371 }
372 return 0;
373 }
374
SaveMloLinkedInfo(const std::vector<WifiLinkedInfo> & mloInfo,int instId)375 int WifiConfigCenter::SaveMloLinkedInfo(const std::vector<WifiLinkedInfo> &mloInfo, int instId)
376 {
377 std::unique_lock<std::mutex> lock(mStaMutex);
378 mWifiMloLinkedInfo[instId] = mloInfo;
379 return 0;
380 }
SetMacAddress(const std::string & macAddress,int instId)381 int WifiConfigCenter::SetMacAddress(const std::string &macAddress, int instId)
382 {
383 std::unique_lock<std::mutex> lock(mStaMutex);
384 mMacAddress[instId] = macAddress;
385 return 0;
386 }
387
GetMacAddress(std::string & macAddress,int instId)388 int WifiConfigCenter::GetMacAddress(std::string &macAddress, int instId)
389 {
390 std::unique_lock<std::mutex> lock(mStaMutex);
391 auto iter = mMacAddress.find(instId);
392 if (iter != mMacAddress.end()) {
393 macAddress = iter->second;
394 }
395 return 0;
396 }
397
SetUserLastSelectedNetworkId(int networkId,int instId)398 void WifiConfigCenter::SetUserLastSelectedNetworkId(int networkId, int instId)
399 {
400 std::unique_lock<std::mutex> lock(mStaMutex);
401 mLastSelectedNetworkId[instId] = networkId;
402 mLastSelectedTimeVal[instId] = time(NULL);
403 }
404
GetUserLastSelectedNetworkId(int instId)405 int WifiConfigCenter::GetUserLastSelectedNetworkId(int instId)
406 {
407 std::unique_lock<std::mutex> lock(mStaMutex);
408 auto iter = mLastSelectedNetworkId.find(instId);
409 if (iter != mLastSelectedNetworkId.end()) {
410 return iter->second;
411 }
412 return -1;
413 }
414
GetUserLastSelectedNetworkTimeVal(int instId)415 time_t WifiConfigCenter::GetUserLastSelectedNetworkTimeVal(int instId)
416 {
417 std::unique_lock<std::mutex> lock(mStaMutex);
418 auto iter = mLastSelectedTimeVal.find(instId);
419 if (iter != mLastSelectedTimeVal.end()) {
420 return iter->second;
421 }
422 return 0;
423 }
424
GetConnectTimeoutBssid(int instId)425 std::string WifiConfigCenter::GetConnectTimeoutBssid(int instId)
426 {
427 std::unique_lock<std::mutex> lock(mStaMutex);
428 auto iter = mBssidToTimeoutTime.find(instId);
429 if (iter != mBssidToTimeoutTime.end()) {
430 const int timeout = 30; // 30s
431 if (iter->second.second - static_cast<int>(time(NULL)) > timeout) {
432 return "";
433 }
434 return iter->second.first;
435 }
436 return "";
437 }
438
SetConnectTimeoutBssid(std::string & bssid,int instId)439 int WifiConfigCenter::SetConnectTimeoutBssid(std::string &bssid, int instId)
440 {
441 std::unique_lock<std::mutex> lock(mStaMutex);
442 time_t now = time(nullptr);
443 if (now == static_cast<time_t>(-1)) {
444 LOGE("SetConnectTimeoutBssid: call time failed!");
445 return -1;
446 }
447 mBssidToTimeoutTime[instId] = std::make_pair(bssid, static_cast<int>(now));
448 return 0;
449 }
450
SaveDisconnectedReason(DisconnectedReason discReason,int instId)451 void WifiConfigCenter::SaveDisconnectedReason(DisconnectedReason discReason, int instId)
452 {
453 std::unique_lock<std::mutex> lock(mStaMutex);
454 mLastDiscReason[instId] = discReason;
455 }
456
GetDisconnectedReason(DisconnectedReason & discReason,int instId)457 int WifiConfigCenter::GetDisconnectedReason(DisconnectedReason &discReason, int instId)
458 {
459 std::unique_lock<std::mutex> lock(mStaMutex);
460 auto iter = mLastDiscReason.find(instId);
461 if (iter != mLastDiscReason.end()) {
462 discReason = iter->second;
463 }
464 return 0;
465 }
466
InsertWifiCategoryBlackListCache(int blacklistType,const std::string currentBssid,const WifiCategoryBlackListInfo wifiBlackListInfo)467 void WifiConfigCenter::InsertWifiCategoryBlackListCache(int blacklistType, const std::string currentBssid,
468 const WifiCategoryBlackListInfo wifiBlackListInfo)
469 {
470 std::unique_lock<std::mutex> lock(mStaMutex);
471 std::map<std::string, WifiCategoryBlackListInfo> wifiBlackListCache;
472 if (mWifiCategoryBlackListCache.find(blacklistType) != mWifiCategoryBlackListCache.end()) {
473 wifiBlackListCache = mWifiCategoryBlackListCache[blacklistType];
474 }
475 auto iter = wifiBlackListCache.find(currentBssid);
476 if (iter != wifiBlackListCache.end()) {
477 iter->second = wifiBlackListInfo;
478 } else {
479 wifiBlackListCache.emplace(std::make_pair(currentBssid, wifiBlackListInfo));
480 }
481 mWifiCategoryBlackListCache[blacklistType] = wifiBlackListCache;
482 }
483
RemoveWifiCategoryBlackListCache(int blacklistType,const std::string bssid)484 void WifiConfigCenter::RemoveWifiCategoryBlackListCache(int blacklistType, const std::string bssid)
485 {
486 std::unique_lock<std::mutex> lock(mStaMutex);
487 if (mWifiCategoryBlackListCache.find(blacklistType) == mWifiCategoryBlackListCache.end()) {
488 LOGE("%{public}s: dont exist wifi bla type", __func__);
489 return;
490 }
491 std::map<std::string, WifiCategoryBlackListInfo> wifiBlackListCache = mWifiCategoryBlackListCache[blacklistType];
492 if (wifiBlackListCache.find(bssid) != wifiBlackListCache.end()) {
493 wifiBlackListCache.erase(bssid);
494 mWifiCategoryBlackListCache[blacklistType] = wifiBlackListCache;
495 } else {
496 LOGE("%{public}s: don't exist wifi bla list, bssid: %{public}s", __func__, MacAnonymize(bssid).c_str());
497 return;
498 }
499 }
500
GetWifiCategoryBlackListCache(int blacklistType,std::map<std::string,WifiCategoryBlackListInfo> & blackListCache)501 int WifiConfigCenter::GetWifiCategoryBlackListCache(int blacklistType,
502 std::map<std::string, WifiCategoryBlackListInfo> &blackListCache)
503 {
504 std::unique_lock<std::mutex> lock(mStaMutex);
505 if (mWifiCategoryBlackListCache.find(blacklistType) == mWifiCategoryBlackListCache.end()) {
506 LOGE("%{public}s: dont exist wifi bla type", __func__);
507 return -1;
508 }
509 blackListCache = mWifiCategoryBlackListCache[blacklistType];
510 return 0;
511 }
512
UpdateWifiConnectFailListCache(int blacklistType,const std::string bssid,const WifiCategoryConnectFailInfo wifiConnectFailInfo)513 void WifiConfigCenter::UpdateWifiConnectFailListCache(int blacklistType, const std::string bssid,
514 const WifiCategoryConnectFailInfo wifiConnectFailInfo)
515 {
516 std::unique_lock<std::mutex> lock(mStaMutex);
517 auto iter = mWifiConnectFailCache.find(bssid);
518 if (iter != mWifiConnectFailCache.end()
519 && iter->second.actionType >= wifiConnectFailInfo.actionType) {
520 iter->second.connectFailTimes++;
521 } else {
522 mWifiConnectFailCache[bssid] = wifiConnectFailInfo;
523 }
524 }
525
RemoveWifiConnectFailListCache(const std::string bssid)526 void WifiConfigCenter::RemoveWifiConnectFailListCache(const std::string bssid)
527 {
528 std::unique_lock<std::mutex> lock(mStaMutex);
529 if (mWifiConnectFailCache.find(bssid) != mWifiConnectFailCache.end()) {
530 mWifiConnectFailCache.erase(bssid);
531 } else {
532 LOGE("%{public}s: don't exist wifi connect fail list, bssid: %{public}s",
533 __func__, MacAnonymize(bssid).c_str());
534 return;
535 }
536 }
537
GetWifiConnectFailListCache(std::map<std::string,WifiCategoryConnectFailInfo> & connectFailCache)538 int WifiConfigCenter::GetWifiConnectFailListCache(std::map<std::string,
539 WifiCategoryConnectFailInfo> &connectFailCache)
540 {
541 std::unique_lock<std::mutex> lock(mStaMutex);
542 connectFailCache = mWifiConnectFailCache;
543 return 0;
544 }
545
EnableNetwork(int networkId,bool disableOthers,int instId)546 bool WifiConfigCenter::EnableNetwork(int networkId, bool disableOthers, int instId)
547 {
548 if (disableOthers) {
549 SetUserLastSelectedNetworkId(networkId, instId);
550 }
551 return true;
552 }
553
GetScanMidState(int instId)554 WifiOprMidState WifiConfigCenter::GetScanMidState(int instId)
555 {
556 std::unique_lock<std::mutex> lock(mScanMutex);
557 auto iter = mScanMidState.find(instId);
558 if (iter != mScanMidState.end()) {
559 return iter->second.load();
560 } else {
561 mScanMidState.emplace(instId, WifiOprMidState::CLOSED);
562 return mScanMidState[instId].load();
563 }
564 }
565
SetScanMidState(WifiOprMidState expState,WifiOprMidState state,int instId)566 bool WifiConfigCenter::SetScanMidState(WifiOprMidState expState, WifiOprMidState state, int instId)
567 {
568 std::unique_lock<std::mutex> lock(mScanMutex);
569 auto iter = mScanMidState.find(instId);
570 if (iter != mScanMidState.end()) {
571 return iter->second.compare_exchange_strong(expState, state);
572 } else {
573 mScanMidState.emplace(instId, state);
574 return true;
575 }
576 return false;
577 }
578
SetScanMidState(WifiOprMidState state,int instId)579 void WifiConfigCenter::SetScanMidState(WifiOprMidState state, int instId)
580 {
581 std::unique_lock<std::mutex> lock(mScanMutex);
582 auto ret = mScanMidState.emplace(instId, state);
583 if (!ret.second) {
584 mScanMidState[instId] = state;
585 }
586 }
587
GetWifiScanOnlyMidState(int instId)588 WifiOprMidState WifiConfigCenter::GetWifiScanOnlyMidState(int instId)
589 {
590 std::unique_lock<std::mutex> lock(mScanMutex);
591 auto iter = mScanOnlyMidState.find(instId);
592 if (iter != mScanOnlyMidState.end()) {
593 return iter->second.load();
594 } else {
595 mScanOnlyMidState.emplace(instId, WifiOprMidState::CLOSED);
596 return mScanOnlyMidState[instId].load();
597 }
598 }
599
SetWifiScanOnlyMidState(WifiOprMidState expState,WifiOprMidState state,int instId)600 bool WifiConfigCenter::SetWifiScanOnlyMidState(WifiOprMidState expState, WifiOprMidState state, int instId)
601 {
602 std::unique_lock<std::mutex> lock(mScanMutex);
603 auto iter = mScanOnlyMidState.find(instId);
604 if (iter != mScanOnlyMidState.end()) {
605 return iter->second.compare_exchange_strong(expState, state);
606 } else {
607 mScanOnlyMidState.emplace(instId, state);
608 return true;
609 }
610 return false;
611 }
612
SetWifiScanOnlyMidState(WifiOprMidState state,int instId)613 void WifiConfigCenter::SetWifiScanOnlyMidState(WifiOprMidState state, int instId)
614 {
615 std::unique_lock<std::mutex> lock(mScanMutex);
616 auto ret = mScanOnlyMidState.emplace(instId, state);
617 if (!ret.second) {
618 mScanOnlyMidState[instId] = state;
619 }
620 }
621
SetWifiLinkedStandardAndMaxSpeed(WifiLinkedInfo & linkInfo)622 int WifiConfigCenter::SetWifiLinkedStandardAndMaxSpeed(WifiLinkedInfo &linkInfo)
623 {
624 std::vector<WifiScanInfo> wifiScanInfoList;
625 wifiScanConfig->GetScanInfoListInner(wifiScanInfoList);
626 for (auto iter = wifiScanInfoList.begin(); iter != wifiScanInfoList.end(); ++iter) {
627 if (iter->bssid == linkInfo.bssid) {
628 linkInfo.wifiStandard = iter->wifiStandard;
629 linkInfo.maxSupportedRxLinkSpeed = iter->maxSupportedRxLinkSpeed;
630 linkInfo.maxSupportedTxLinkSpeed = iter->maxSupportedTxLinkSpeed;
631 break;
632 }
633 }
634 return 0;
635 }
636
SetMloWifiLinkedMaxSpeed(int instId)637 void WifiConfigCenter::SetMloWifiLinkedMaxSpeed(int instId)
638 {
639 std::unique_lock<std::mutex> lock(mStaMutex);
640 auto mloIter = mWifiMloLinkedInfo.find(instId);
641 if (mloIter == mWifiMloLinkedInfo.end()) {
642 return;
643 }
644 if (mloIter->second.size() != WIFI_MAX_MLO_LINK_NUM) {
645 return;
646 }
647 std::vector<WifiScanInfo> wifiScanInfoList;
648 wifiScanConfig->GetScanInfoListInner(wifiScanInfoList);
649 for (auto iter = wifiScanInfoList.begin(); iter != wifiScanInfoList.end(); ++iter) {
650 for (auto& mloInfoItem : mWifiMloLinkedInfo[instId]) {
651 if (iter->bssid == mloInfoItem.bssid) {
652 mloInfoItem.maxSupportedRxLinkSpeed = iter->maxSupportedRxLinkSpeed;
653 mloInfoItem.maxSupportedTxLinkSpeed = iter->maxSupportedTxLinkSpeed;
654 }
655 }
656 }
657 }
658
CheckScanOnlyAvailable(int instId)659 bool WifiConfigCenter::CheckScanOnlyAvailable(int instId)
660 {
661 return (WifiSettings::GetInstance().GetScanOnlySwitchState(instId)) && (GetAirplaneModeState() == MODE_STATE_CLOSE);
662 }
663
GetConnectedBssid(int instId)664 std::string WifiConfigCenter::GetConnectedBssid(int instId)
665 {
666 WifiLinkedInfo linkedInfo;
667 GetLinkedInfo(linkedInfo, instId);
668 if (linkedInfo.connState == ConnState::CONNECTED) {
669 return linkedInfo.bssid;
670 }
671 return "";
672 }
673
SetSoftapToggledState(bool state)674 void WifiConfigCenter::SetSoftapToggledState(bool state)
675 {
676 mSoftapToggled = state;
677 }
678
GetSoftapToggledState() const679 bool WifiConfigCenter::GetSoftapToggledState() const
680 {
681 return mSoftapToggled.load();
682 }
683
684
SetHotspotIdleTimeout(int time)685 int WifiConfigCenter::SetHotspotIdleTimeout(int time)
686 {
687 mHotspotIdleTimeout = time;
688 return 0;
689 }
690
GetHotspotIdleTimeout() const691 int WifiConfigCenter::GetHotspotIdleTimeout() const
692 {
693 return mHotspotIdleTimeout.load();
694 }
695
SetApIfaceName(const std::string & ifaceName)696 void WifiConfigCenter::SetApIfaceName(const std::string &ifaceName)
697 {
698 std::unique_lock<std::mutex> lock(mApMutex);
699 mApIfaceName = ifaceName;
700 }
701
GetApIfaceName()702 std::string WifiConfigCenter::GetApIfaceName()
703 {
704 std::unique_lock<std::mutex> lock(mApMutex);
705 return mApIfaceName;
706 }
707
GetApMidState(int id)708 WifiOprMidState WifiConfigCenter::GetApMidState(int id)
709 {
710 std::unique_lock<std::mutex> lock(mApMutex);
711 auto iter = mApMidState.find(id);
712 if (iter != mApMidState.end()) {
713 return iter->second.load();
714 } else {
715 mApMidState.emplace(id, WifiOprMidState::CLOSED);
716 return mApMidState[id].load();
717 }
718 }
719
SetApMidState(WifiOprMidState expState,WifiOprMidState state,int id)720 bool WifiConfigCenter::SetApMidState(WifiOprMidState expState, WifiOprMidState state, int id)
721 {
722 std::unique_lock<std::mutex> lock(mApMutex);
723 auto iter = mApMidState.find(id);
724 if (iter != mApMidState.end()) {
725 return iter->second.compare_exchange_strong(expState, state);
726 } else {
727 mApMidState.emplace(id, state);
728 return true;
729 }
730 return false;
731 }
732
SetApMidState(WifiOprMidState state,int id)733 void WifiConfigCenter::SetApMidState(WifiOprMidState state, int id)
734 {
735 std::unique_lock<std::mutex> lock(mApMutex);
736 auto ret = mApMidState.emplace(id, state);
737 if (!ret.second) {
738 mApMidState[id] = state;
739 }
740 }
741
GetHotspotState(int id)742 int WifiConfigCenter::GetHotspotState(int id)
743 {
744 std::unique_lock<std::mutex> lock(mApMutex);
745 auto iter = mHotspotState.find(id);
746 if (iter != mHotspotState.end()) {
747 return iter->second.load();
748 }
749 mHotspotState[id] = static_cast<int>(ApState::AP_STATE_CLOSED);
750 return mHotspotState[id].load();
751 }
752
SetHotspotState(int state,int id)753 int WifiConfigCenter::SetHotspotState(int state, int id)
754 {
755 std::unique_lock<std::mutex> lock(mApMutex);
756 mHotspotState[id] = state;
757 return 0;
758 }
759
SetPowerModel(const PowerModel & model,int id)760 int WifiConfigCenter::SetPowerModel(const PowerModel& model, int id)
761 {
762 std::unique_lock<std::mutex> lock(mApMutex);
763 auto ret = powerModel.emplace(id, model);
764 if (!ret.second) {
765 powerModel[id] = model;
766 }
767 return 0;
768 }
769
GetPowerModel(PowerModel & model,int id)770 int WifiConfigCenter::GetPowerModel(PowerModel& model, int id)
771 {
772 std::unique_lock<std::mutex> lock(mApMutex);
773 auto iter = powerModel.find(id);
774 if (iter != powerModel.end()) {
775 model = iter->second;
776 } else {
777 powerModel[id] = PowerModel::GENERAL;
778 model = powerModel[id];
779 }
780 return 0;
781 }
782
GetStationList(std::vector<StationInfo> & results,int id)783 int WifiConfigCenter::GetStationList(std::vector<StationInfo> &results, int id)
784 {
785 std::unique_lock<std::mutex> lock(mApMutex);
786 for (auto iter = mConnectStationInfo.begin(); iter != mConnectStationInfo.end(); iter++) {
787 results.push_back(iter->second);
788 }
789 return 0;
790 }
791
ManageStation(const StationInfo & info,int mode,int id)792 int WifiConfigCenter::ManageStation(const StationInfo &info, int mode, int id)
793 {
794 std::unique_lock<std::mutex> lock(mApMutex);
795 auto iter = mConnectStationInfo.find(info.bssid);
796 if (mode == MODE_ADD || mode == MODE_UPDATE) {
797 if (iter != mConnectStationInfo.end()) {
798 iter->second = info;
799 } else {
800 mConnectStationInfo.emplace(std::make_pair(info.bssid, info));
801 }
802 #ifdef SUPPORT_RANDOM_MAC_ADDR
803 StoreWifiMacAddrPairInfo(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, info.bssid, "");
804 #endif
805 } else if (mode == MODE_DEL) {
806 if (iter != mConnectStationInfo.end()) {
807 mConnectStationInfo.erase(iter);
808 }
809 #ifdef SUPPORT_RANDOM_MAC_ADDR
810 RemoveMacAddrPairInfo(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, info.bssid, info.bssidType);
811 #endif
812 } else {
813 return -1;
814 }
815 return 0;
816 }
817
ClearStationList(int id)818 int WifiConfigCenter::ClearStationList(int id)
819 {
820 #ifdef SUPPORT_RANDOM_MAC_ADDR
821 ClearMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO);
822 #endif
823 std::unique_lock<std::mutex> lock(mApMutex);
824 mConnectStationInfo.clear();
825 return 0;
826 }
827
SetP2pIfaceName(const std::string & ifaceName)828 void WifiConfigCenter::SetP2pIfaceName(const std::string &ifaceName)
829 {
830 std::unique_lock<std::mutex> lock(mP2pMutex);
831 mP2pIfaceName = ifaceName;
832 }
833
GetP2pIfaceName()834 std::string WifiConfigCenter::GetP2pIfaceName()
835 {
836 std::unique_lock<std::mutex> lock(mP2pMutex);
837 return mP2pIfaceName;
838 }
839
SetHid2dUpperScene(int uid,const Hid2dUpperScene & scene)840 int WifiConfigCenter::SetHid2dUpperScene(int uid, const Hid2dUpperScene &scene)
841 {
842 LOGD("SetHid2dUpperScene uid: %{public}d", uid);
843 std::unique_lock<std::mutex> lock(mP2pMutex);
844 mHid2dUpperScenePair.insert_or_assign(uid, scene);
845 if (scene.setTime != 0) {
846 mHid2dSceneLastSetTime = scene.setTime;
847 }
848 return 0;
849 }
850
GetHid2dUpperScene(int uid,Hid2dUpperScene & scene)851 int WifiConfigCenter::GetHid2dUpperScene(int uid, Hid2dUpperScene &scene)
852 {
853 std::unique_lock<std::mutex> lock(mP2pMutex);
854 auto iter = mHid2dUpperScenePair.find(uid);
855 if (iter != mHid2dUpperScenePair.end()) {
856 scene = iter->second;
857 }
858 return 0;
859 }
860
SetHid2dSceneLastSetTime(int64_t setTime)861 int WifiConfigCenter::SetHid2dSceneLastSetTime(int64_t setTime)
862 {
863 mHid2dSceneLastSetTime = setTime;
864 return 0;
865 }
866
GetHid2dSceneLastSetTime()867 int64_t WifiConfigCenter::GetHid2dSceneLastSetTime()
868 {
869 return mHid2dSceneLastSetTime.load();
870 }
871
ClearLocalHid2dInfo(int uid)872 void WifiConfigCenter::ClearLocalHid2dInfo(int uid)
873 {
874 std::unique_lock<std::mutex> lock(mP2pMutex);
875 Hid2dUpperScene scene;
876 scene.mac = "";
877 scene.scene = 0;
878 scene.fps = 0;
879 scene.bw = 0;
880 if (uid != 0) {
881 mHid2dUpperScenePair.insert_or_assign(uid, scene);
882 } else {
883 mHid2dUpperScenePair.insert_or_assign(SOFT_BUS_SERVICE_UID, scene);
884 mHid2dUpperScenePair.insert_or_assign(CAST_ENGINE_SERVICE_UID, scene);
885 mHid2dUpperScenePair.insert_or_assign(MIRACAST_SERVICE_UID, scene);
886 mHid2dUpperScenePair.insert_or_assign(SHARE_SERVICE_UID, scene);
887 mHid2dUpperScenePair.insert_or_assign(MOUSE_CROSS_SERVICE_UID, scene);
888 SetHid2dSceneLastSetTime(0);
889 }
890 }
891
SetLastConnStaFreq(int freq)892 int WifiConfigCenter::SetLastConnStaFreq(int freq)
893 {
894 lastConnStaFreq_.store(freq);
895 return 0;
896 }
897
GetLastConnStaFreq()898 int WifiConfigCenter::GetLastConnStaFreq()
899 {
900 return lastConnStaFreq_.load();
901 }
902
SetP2pEnhanceState(int state)903 int WifiConfigCenter::SetP2pEnhanceState(int state)
904 {
905 p2pEnhanceState_.store(state);
906 return 0;
907 }
908
GetP2pEnhanceState()909 int WifiConfigCenter::GetP2pEnhanceState()
910 {
911 return p2pEnhanceState_.load();
912 }
913
SetP2pEnhanceActionListenChannel(int channel)914 int WifiConfigCenter::SetP2pEnhanceActionListenChannel(int channel)
915 {
916 p2pEnhanceActionListenChannel_.store(channel);
917 return 0;
918 }
919
GetP2pEnhanceActionListenChannel()920 int WifiConfigCenter::GetP2pEnhanceActionListenChannel()
921 {
922 return p2pEnhanceActionListenChannel_.load();
923 }
924
SetP2pEnhanceFreq(int freq)925 int WifiConfigCenter::SetP2pEnhanceFreq(int freq)
926 {
927 p2pEnhanceFreq_.store(freq);
928 return 0;
929 }
930
GetP2pEnhanceFreq()931 int WifiConfigCenter::GetP2pEnhanceFreq()
932 {
933 return p2pEnhanceFreq_.load();
934 }
935
GetP2pMidState()936 WifiOprMidState WifiConfigCenter::GetP2pMidState()
937 {
938 return mP2pMidState.load();
939 }
940
SetP2pMidState(WifiOprMidState expState,WifiOprMidState state)941 bool WifiConfigCenter::SetP2pMidState(WifiOprMidState expState, WifiOprMidState state)
942 {
943 return mP2pMidState.compare_exchange_strong(expState, state);
944 }
945
SetP2pMidState(WifiOprMidState state)946 void WifiConfigCenter::SetP2pMidState(WifiOprMidState state)
947 {
948 mP2pMidState = state;
949 }
950
SetP2pState(int state)951 int WifiConfigCenter::SetP2pState(int state)
952 {
953 mP2pState = state;
954 return 0;
955 }
956
GetP2pState()957 int WifiConfigCenter::GetP2pState()
958 {
959 return mP2pState.load();
960 }
961
SetP2pDiscoverState(int state)962 int WifiConfigCenter::SetP2pDiscoverState(int state)
963 {
964 mP2pDiscoverState = state;
965 return 0;
966 }
967
GetP2pDiscoverState()968 int WifiConfigCenter::GetP2pDiscoverState()
969 {
970 return mP2pDiscoverState.load();
971 }
972
SetP2pBusinessType(const P2pBusinessType & type)973 int WifiConfigCenter::SetP2pBusinessType(const P2pBusinessType &type)
974 {
975 mP2pBusinessType = type;
976 return 0;
977 }
978
GetP2pBusinessType(P2pBusinessType & type)979 int WifiConfigCenter::GetP2pBusinessType(P2pBusinessType &type)
980 {
981 type = mP2pBusinessType.load();
982 return 0;
983 }
984
SaveP2pCreatorUid(int uid)985 int WifiConfigCenter::SaveP2pCreatorUid(int uid)
986 {
987 mP2pCreatorUid = uid;
988 return 0;
989 }
990
GetP2pCreatorUid()991 int WifiConfigCenter::GetP2pCreatorUid()
992 {
993 return mP2pCreatorUid.load();
994 }
995
SetExplicitGroup(bool isExplicit)996 void WifiConfigCenter::SetExplicitGroup(bool isExplicit)
997 {
998 mExplicitGroup = isExplicit;
999 }
1000
IsExplicitGroup(void)1001 bool WifiConfigCenter::IsExplicitGroup(void)
1002 {
1003 return mExplicitGroup.load();
1004 }
1005
GetP2pInfo(WifiP2pLinkedInfo & linkedInfo)1006 int WifiConfigCenter::GetP2pInfo(WifiP2pLinkedInfo &linkedInfo)
1007 {
1008 std::unique_lock<std::mutex> lock(mP2pMutex);
1009 linkedInfo = mWifiP2pInfo;
1010 return 0;
1011 }
1012
SaveP2pInfo(WifiP2pLinkedInfo & linkedInfo)1013 int WifiConfigCenter::SaveP2pInfo(WifiP2pLinkedInfo &linkedInfo)
1014 {
1015 std::unique_lock<std::mutex> lock(mP2pMutex);
1016 mWifiP2pInfo = linkedInfo;
1017 return 0;
1018 }
1019
SetCurrentP2pGroupInfo(const WifiP2pGroupInfo & group)1020 void WifiConfigCenter::SetCurrentP2pGroupInfo(const WifiP2pGroupInfo &group)
1021 {
1022 std::unique_lock<std::mutex> lock(mP2pMutex);
1023 m_P2pGroupInfo = group;
1024 }
1025
GetCurrentP2pGroupInfo()1026 WifiP2pGroupInfo WifiConfigCenter::GetCurrentP2pGroupInfo()
1027 {
1028 std::unique_lock<std::mutex> lock(mP2pMutex);
1029 return m_P2pGroupInfo;
1030 }
1031
SetCoexSupport(bool isSupport)1032 void WifiConfigCenter::SetCoexSupport(bool isSupport)
1033 {
1034 mIsSupportCoex = isSupport;
1035 }
1036
GetCoexSupport() const1037 bool WifiConfigCenter::GetCoexSupport() const
1038 {
1039 return mIsSupportCoex.load();
1040 }
1041
SetScreenState(const int & state)1042 void WifiConfigCenter::SetScreenState(const int &state)
1043 {
1044 mScreenState = state;
1045 }
1046
GetScreenState() const1047 int WifiConfigCenter::GetScreenState() const
1048 {
1049 return mScreenState.load();
1050 }
1051
SetThermalLevel(const int & level)1052 void WifiConfigCenter::SetThermalLevel(const int &level)
1053 {
1054 mThermalLevel = level;
1055 }
1056
GetThermalLevel() const1057 int WifiConfigCenter::GetThermalLevel() const
1058 {
1059 return mThermalLevel.load();
1060 }
1061
SetPowerIdelState(const int & state)1062 void WifiConfigCenter::SetPowerIdelState(const int &state)
1063 {
1064 mPowerIdelState = state;
1065 }
1066
GetPowerIdelState() const1067 int WifiConfigCenter::GetPowerIdelState() const
1068 {
1069 return mPowerIdelState.load();
1070 }
1071
SetGnssFixState(const int & state)1072 void WifiConfigCenter::SetGnssFixState(const int &state)
1073 {
1074 mGnssFixState = state;
1075 }
1076
GetGnssFixState() const1077 int WifiConfigCenter::GetGnssFixState() const
1078 {
1079 return mGnssFixState.load();
1080 }
1081
SetScanGenieState(const int & state)1082 void WifiConfigCenter::SetScanGenieState(const int &state)
1083 {
1084 mScanGenieState = state;
1085 }
1086
GetScanGenieState() const1087 int WifiConfigCenter::GetScanGenieState() const
1088 {
1089 return mScanGenieState.load();
1090 }
1091
SetWifiStateOnAirplaneChanged(const int & state)1092 bool WifiConfigCenter::SetWifiStateOnAirplaneChanged(const int &state)
1093 {
1094 mAirplaneModeState = state;
1095 WifiSettings::GetInstance().SetLastAirplaneMode(state);
1096 if (WifiSettings::GetInstance().GetWifiFlagOnAirplaneMode()) {
1097 if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_DISABLED) {
1098 return true;
1099 }
1100 if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_SEMI_ENABLED && state == MODE_STATE_OPEN) {
1101 SetPersistWifiState(WIFI_STATE_DISABLED, INSTID_WLAN0);
1102 return true;
1103 }
1104 return false;
1105 }
1106 if (state == MODE_STATE_OPEN) {
1107 if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_ENABLED) {
1108 WifiSettings::GetInstance().SetWifiDisabledByAirplane(true);
1109 }
1110 SetPersistWifiState(WIFI_STATE_DISABLED, INSTID_WLAN0);
1111 } else {
1112 if (WifiSettings::GetInstance().GetWifiDisabledByAirplane()) {
1113 SetPersistWifiState(WIFI_STATE_ENABLED, INSTID_WLAN0);
1114 WifiSettings::GetInstance().SetWifiDisabledByAirplane(false);
1115 }
1116 }
1117 return true;
1118 }
1119
GetAirplaneModeState() const1120 int WifiConfigCenter::GetAirplaneModeState() const
1121 {
1122 return mAirplaneModeState.load();
1123 }
1124
GetWifiToggledEnable(int id)1125 int WifiConfigCenter::GetWifiToggledEnable(int id)
1126 {
1127 if (GetAirplaneModeState() == MODE_STATE_OPEN) {
1128 if (GetPersistWifiState(id) == WIFI_STATE_ENABLED) {
1129 return WIFI_STATE_ENABLED;
1130 }
1131 return WIFI_STATE_DISABLED;
1132 }
1133 if (GetPersistWifiState(id) != WIFI_STATE_ENABLED && GetWifiAllowSemiActive()) {
1134 return WIFI_STATE_SEMI_ENABLED;
1135 }
1136 return GetPersistWifiState(id);
1137 }
1138
SetWifiToggledState(int state,int id)1139 void WifiConfigCenter::SetWifiToggledState(int state, int id)
1140 {
1141 if (GetAirplaneModeState() == MODE_STATE_OPEN) {
1142 WifiSettings::GetInstance().SetWifiDisabledByAirplane(false);
1143 if (state == WIFI_STATE_ENABLED) {
1144 WifiSettings::GetInstance().SetWifiFlagOnAirplaneMode(true);
1145 } else {
1146 WifiSettings::GetInstance().SetWifiFlagOnAirplaneMode(false);
1147 state = WIFI_STATE_DISABLED;
1148 }
1149 }
1150 SetPersistWifiState(state, id);
1151 }
1152
SetPowerSavingModeState(const int & state)1153 void WifiConfigCenter::SetPowerSavingModeState(const int &state)
1154 {
1155 mPowerSavingModeState = state;
1156 }
1157
GetPowerSavingModeState() const1158 int WifiConfigCenter::GetPowerSavingModeState() const
1159 {
1160 return mPowerSavingModeState.load();
1161 }
1162
SetFreezeModeState(int state)1163 void WifiConfigCenter::SetFreezeModeState(int state)
1164 {
1165 mFreezeModeState = state;
1166 }
1167
GetFreezeModeState() const1168 int WifiConfigCenter::GetFreezeModeState() const
1169 {
1170 return mFreezeModeState.load();
1171 }
1172
SetNoChargerPlugModeState(int state)1173 void WifiConfigCenter::SetNoChargerPlugModeState(int state)
1174 {
1175 mNoChargerPlugModeState = state;
1176 }
1177
GetNoChargerPlugModeState() const1178 int WifiConfigCenter::GetNoChargerPlugModeState() const
1179 {
1180 return mNoChargerPlugModeState.load();
1181 }
1182
SetThreadStatusFlag(bool state)1183 void WifiConfigCenter::SetThreadStatusFlag(bool state)
1184 {
1185 if (state) {
1186 mThreadStartTime = std::chrono::duration_cast<std::chrono::milliseconds>(
1187 std::chrono::steady_clock::now().time_since_epoch()).count();
1188 }
1189 mThreadStatusFlag_ = state;
1190 }
1191
GetThreadStatusFlag(void) const1192 bool WifiConfigCenter::GetThreadStatusFlag(void) const
1193 {
1194 return mThreadStatusFlag_.load();
1195 }
1196
GetThreadStartTime(void) const1197 uint64_t WifiConfigCenter::GetThreadStartTime(void) const
1198 {
1199 return mThreadStartTime.load();
1200 }
1201
StoreWifiMacAddrPairInfo(WifiMacAddrInfoType type,const std::string & realMacAddr,const std::string & randomAddr)1202 bool WifiConfigCenter::StoreWifiMacAddrPairInfo(WifiMacAddrInfoType type, const std::string &realMacAddr,
1203 const std::string &randomAddr)
1204 {
1205 if (realMacAddr.empty()) {
1206 return false;
1207 }
1208
1209 if (type >= WifiMacAddrInfoType::INVALID_MACADDR_INFO) {
1210 return false;
1211 }
1212
1213 std::string randomMacAddr;
1214 if (randomAddr.empty()) {
1215 WifiRandomMacHelper::GenerateRandomMacAddressByBssid(realMacAddr, randomMacAddr);
1216 } else {
1217 randomMacAddr = randomAddr;
1218 }
1219 LOGD("%{public}s: type:%{public}d, address:%{private}s, randomAddr:%{private}s, randomMacAddr:%{private}s",
1220 __func__, type, realMacAddr.c_str(), randomAddr.c_str(), randomMacAddr.c_str());
1221 WifiMacAddrInfo realMacAddrInfo;
1222 realMacAddrInfo.bssid = realMacAddr;
1223 realMacAddrInfo.bssidType = REAL_DEVICE_ADDRESS;
1224 WifiMacAddrErrCode ret = AddMacAddrPairs(type, realMacAddrInfo, randomMacAddr);
1225 if (ret == WIFI_MACADDR_OPER_SUCCESS) {
1226 WifiMacAddrInfo randomMacAddrInfo;
1227 randomMacAddrInfo.bssid = randomMacAddr;
1228 randomMacAddrInfo.bssidType = RANDOM_DEVICE_ADDRESS;
1229 AddMacAddrPairs(type, randomMacAddrInfo, realMacAddr);
1230 }
1231 return true;
1232 }
1233
GetRandomMacAddr(WifiMacAddrInfoType type,std::string bssid)1234 std::string WifiConfigCenter::GetRandomMacAddr(WifiMacAddrInfoType type, std::string bssid)
1235 {
1236 LOGD("%{public}s: query a random mac address, type:%{public}d, bssid:%{private}s",
1237 __func__, type, bssid.c_str());
1238 WifiMacAddrInfo realMacAddrInfo;
1239 realMacAddrInfo.bssid = bssid;
1240 realMacAddrInfo.bssidType = REAL_DEVICE_ADDRESS;
1241 std::string randomMacAddr = GetMacAddrPairs(type, realMacAddrInfo);
1242 if (!randomMacAddr.empty()) {
1243 LOGD("%{public}s: find the record, bssid:%{private}s, bssidType:%{public}d, randomMacAddr:%{private}s",
1244 __func__, realMacAddrInfo.bssid.c_str(), realMacAddrInfo.bssidType, randomMacAddr.c_str());
1245 return randomMacAddr;
1246 } else {
1247 WifiMacAddrInfo randomMacAddrInfo;
1248 randomMacAddrInfo.bssid = bssid;
1249 randomMacAddrInfo.bssidType = RANDOM_DEVICE_ADDRESS;
1250 randomMacAddr = GetMacAddrPairs(type, realMacAddrInfo);
1251 if (!randomMacAddr.empty()) {
1252 LOGD("%{public}s: find the record, bssid:%{private}s, bssidType:%{public}d, randomMacAddr:%{private}s",
1253 __func__, randomMacAddrInfo.bssid.c_str(), randomMacAddrInfo.bssidType, randomMacAddr.c_str());
1254 return randomMacAddr;
1255 }
1256 }
1257 return "";
1258 }
1259
RemoveMacAddrPairs(WifiMacAddrInfoType type,const WifiMacAddrInfo & macAddrInfo)1260 int WifiConfigCenter::RemoveMacAddrPairs(WifiMacAddrInfoType type, const WifiMacAddrInfo &macAddrInfo)
1261 {
1262 LOGD("remove a mac address pair, type:%{public}d, bssid:%{private}s, bssidType:%{public}d",
1263 type, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType);
1264 std::unique_lock<std::mutex> lock(mMacAddrPairMutex);
1265 switch (type) {
1266 case WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO:
1267 DelMacAddrPairs(mWifiScanMacAddrPair, macAddrInfo);
1268 break;
1269 case WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO:
1270 DelMacAddrPairs(mHotspotMacAddrPair, macAddrInfo);
1271 break;
1272 case WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO:
1273 DelMacAddrPairs(mP2pDeviceMacAddrPair, macAddrInfo);
1274 break;
1275 case WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO:
1276 DelMacAddrPairs(mP2pGroupsInfoMacAddrPair, macAddrInfo);
1277 break;
1278 case WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO:
1279 DelMacAddrPairs(mP2pCurrentgroupMacAddrPair, macAddrInfo);
1280 break;
1281 default:
1282 LOGE("%{public}s: invalid mac address type, type:%{public}d", __func__, type);
1283 return -1;
1284 }
1285 return 0;
1286 }
1287
GetMacAddrPairs(WifiMacAddrInfoType type,const WifiMacAddrInfo & macAddrInfo)1288 std::string WifiConfigCenter::GetMacAddrPairs(WifiMacAddrInfoType type, const WifiMacAddrInfo &macAddrInfo)
1289 {
1290 LOGD("get a mac address pair, type:%{public}d, bssid:%{private}s, bssidType:%{public}d",
1291 type, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType);
1292 std::unique_lock<std::mutex> lock(mMacAddrPairMutex);
1293 switch (type) {
1294 case WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO:
1295 return GetPairMacAddress(mWifiScanMacAddrPair, macAddrInfo);
1296 case WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO:
1297 return GetPairMacAddress(mHotspotMacAddrPair, macAddrInfo);
1298 case WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO:
1299 return GetPairMacAddress(mP2pDeviceMacAddrPair, macAddrInfo);
1300 case WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO:
1301 return GetPairMacAddress(mP2pGroupsInfoMacAddrPair, macAddrInfo);
1302 case WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO:
1303 return GetPairMacAddress(mP2pCurrentgroupMacAddrPair, macAddrInfo);
1304 default:
1305 LOGE("%{public}s: invalid mac address type, type:%{public}d", __func__, type);
1306 return "";
1307 }
1308 return "";
1309 }
1310
ClearMacAddrPairs(WifiMacAddrInfoType type)1311 void WifiConfigCenter::ClearMacAddrPairs(WifiMacAddrInfoType type)
1312 {
1313 LOGI("%{public}s type:%{public}d", __func__, type);
1314 std::unique_lock<std::mutex> lock(mMacAddrPairMutex);
1315 switch (type) {
1316 case WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO:
1317 mWifiScanMacAddrPair.clear();
1318 break;
1319 case WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO:
1320 mHotspotMacAddrPair.clear();
1321 break;
1322 case WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO:
1323 mP2pDeviceMacAddrPair.clear();
1324 break;
1325 case WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO:
1326 mP2pGroupsInfoMacAddrPair.clear();
1327 break;
1328 case WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO:
1329 mP2pCurrentgroupMacAddrPair.clear();
1330 break;
1331 default:
1332 LOGE("%{public}s: invalid mac address type, type:%{public}d", __func__, type);
1333 }
1334 return;
1335 }
1336
HasWifiActive()1337 bool WifiConfigCenter::HasWifiActive()
1338 {
1339 std::unique_lock<std::mutex> lock(mStaMutex);
1340 for (auto &item : mWifiState) {
1341 int state = item.second.load();
1342 if (state == static_cast<int>(WifiState::ENABLING) || state == static_cast<int>(WifiState::ENABLED)) {
1343 LOGD("HasWifiActive: one wifi is active! instId:%{public}d", item.first);
1344 return true;
1345 }
1346 }
1347 LOGD("HasWifiActive: No wifi is active!");
1348 return false;
1349 }
1350
UpdateLinkedInfo(int instId)1351 void WifiConfigCenter::UpdateLinkedInfo(int instId)
1352 {
1353 std::vector<WifiScanInfo> wifiScanInfoList;
1354 wifiScanConfig->GetScanInfoListInner(wifiScanInfoList);
1355 for (auto iter = wifiScanInfoList.begin(); iter != wifiScanInfoList.end(); ++iter) {
1356 if (iter->bssid == mWifiLinkedInfo[instId].bssid) {
1357 if (mWifiLinkedInfo[instId].channelWidth == WifiChannelWidth::WIDTH_INVALID) {
1358 mWifiLinkedInfo[instId].channelWidth = iter->channelWidth;
1359 }
1360 mWifiLinkedInfo[instId].isHiLinkNetwork = iter->isHiLinkNetwork;
1361 if (iter->isHiLinkNetwork == HILINK_PRO_NETWORK) {
1362 mWifiLinkedInfo[instId].isHiLinkProNetwork = true;
1363 }
1364 break;
1365 }
1366 }
1367 WifiCategory category = wifiScanConfig->GetWifiCategoryRecord(mWifiLinkedInfo[instId].bssid);
1368 mWifiLinkedInfo[instId].supportedWifiCategory = category;
1369 LOGD("WifiSettings UpdateLinkedInfo.");
1370 }
1371
SetPersistWifiState(int state,int instId)1372 void WifiConfigCenter::SetPersistWifiState(int state, int instId)
1373 {
1374 if (instId < 0 || instId >= STA_INSTANCE_MAX_NUM) {
1375 LOGE("SetPersistWifiState invalid instId %{public}d", instId);
1376 return;
1377 }
1378 mPersistWifiState.at(instId) = state;
1379 WifiSettings::GetInstance().SetOperatorWifiType(state, instId);
1380 LOGI("persist wifi state is %{public}d", state);
1381 }
1382
GetPersistWifiState(int instId)1383 int WifiConfigCenter::GetPersistWifiState(int instId)
1384 {
1385 if (instId < 0 || instId >= STA_INSTANCE_MAX_NUM) {
1386 LOGE("GetPersistWifiState invalid instId %{public}d", instId);
1387 return -1;
1388 }
1389 return mPersistWifiState.at(instId);
1390 }
1391
GetPairMacAddress(std::map<WifiMacAddrInfo,std::string> & macAddrInfoMap,const WifiMacAddrInfo & macAddrInfo)1392 std::string WifiConfigCenter::GetPairMacAddress(std::map<WifiMacAddrInfo, std::string>& macAddrInfoMap,
1393 const WifiMacAddrInfo &macAddrInfo)
1394 {
1395 auto iter = macAddrInfoMap.find(macAddrInfo);
1396 if (iter != macAddrInfoMap.end()) {
1397 LOGD("%{public}s: find the record, realMacAddr:%{private}s, bssidType:%{public}d, randomMacAddr:%{private}s",
1398 __func__, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType, iter->second.c_str());
1399 return iter->second;
1400 } else {
1401 LOGE("%{public}s: record not found, macaddr: %{public}s", __func__, MacAnonymize(macAddrInfo.bssid).c_str());
1402 }
1403 return "";
1404 }
1405
InsertMacAddrPairs(std::map<WifiMacAddrInfo,std::string> & macAddrInfoMap,const WifiMacAddrInfo & macAddrInfo,std::string & randomMacAddr)1406 WifiMacAddrErrCode WifiConfigCenter::InsertMacAddrPairs(std::map<WifiMacAddrInfo, std::string>& macAddrInfoMap,
1407 const WifiMacAddrInfo &macAddrInfo, std::string& randomMacAddr)
1408 {
1409 auto iter = macAddrInfoMap.find(macAddrInfo);
1410 if (iter != macAddrInfoMap.end()) {
1411 LOGD("%{public}s: the record is existed, macAddr:%{private}s, bssidType:%{public}d, value:%{private}s",
1412 __func__, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType, iter->second.c_str());
1413 return WIFI_MACADDR_HAS_EXISTED;
1414 } else {
1415 macAddrInfoMap.insert(std::make_pair(macAddrInfo, randomMacAddr));
1416 LOGD("%{public}s: add a mac address pair, bssid:%{private}s, bssidType:%{public}d, randomMacAddr:%{private}s",
1417 __func__, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType, randomMacAddr.c_str());
1418 return WIFI_MACADDR_OPER_SUCCESS;
1419 }
1420 }
1421
DelMacAddrPairs(std::map<WifiMacAddrInfo,std::string> & macAddrInfoMap,const WifiMacAddrInfo & macAddrInfo)1422 void WifiConfigCenter::DelMacAddrPairs(std::map<WifiMacAddrInfo, std::string>& macAddrInfoMap,
1423 const WifiMacAddrInfo &macAddrInfo)
1424 {
1425 auto iter = macAddrInfoMap.find(macAddrInfo);
1426 if (iter != macAddrInfoMap.end()) {
1427 if (iter->second.empty()) {
1428 LOGI("%{public}s: invalid record, bssid:%{private}s, bssidType:%{public}d",
1429 __func__, iter->first.bssid.c_str(), iter->first.bssidType);
1430 } else {
1431 LOGD("%{public}s:find the record, realMacAddr:%{private}s, bssidType:%{public}d, randomMacAddr:%{private}s",
1432 __func__, macAddrInfo.bssid.c_str(), macAddrInfo.bssidType, iter->second.c_str());
1433 }
1434 macAddrInfoMap.erase(iter);
1435 }
1436 }
1437
RemoveMacAddrPairInfo(WifiMacAddrInfoType type,std::string bssid,int bssidType)1438 void WifiConfigCenter::RemoveMacAddrPairInfo(WifiMacAddrInfoType type, std::string bssid, int bssidType)
1439 {
1440 LOGD("%{public}s: remove a mac address pair, type:%{public}d, bssid:%{private}s",
1441 __func__, type, bssid.c_str());
1442 WifiMacAddrInfo randomMacAddrInfo;
1443 randomMacAddrInfo.bssid = GetRandomMacAddr(type, bssid);
1444 randomMacAddrInfo.bssidType = REAL_DEVICE_ADDRESS == bssidType ? RANDOM_DEVICE_ADDRESS : REAL_DEVICE_ADDRESS;
1445 RemoveMacAddrPairs(type, randomMacAddrInfo);
1446
1447 WifiMacAddrInfo realMacAddrInfo;
1448 realMacAddrInfo.bssid = bssid;
1449 realMacAddrInfo.bssidType = REAL_DEVICE_ADDRESS == bssidType ? REAL_DEVICE_ADDRESS : RANDOM_DEVICE_ADDRESS;
1450 RemoveMacAddrPairs(type, realMacAddrInfo);
1451 }
1452
AddMacAddrPairs(WifiMacAddrInfoType type,const WifiMacAddrInfo & macAddrInfo,std::string randomMacAddr)1453 WifiMacAddrErrCode WifiConfigCenter::AddMacAddrPairs(WifiMacAddrInfoType type,
1454 const WifiMacAddrInfo &macAddrInfo, std::string randomMacAddr)
1455 {
1456 if ((type >= WifiMacAddrInfoType::INVALID_MACADDR_INFO) || macAddrInfo.bssid.empty()) {
1457 LOGE("%{public}s: invalid parameter, type:%{public}d, bssid:%{private}s",
1458 __func__, type, macAddrInfo.bssid.c_str());
1459 return WIFI_MACADDR_INVALID_PARAM;
1460 }
1461 std::unique_lock<std::mutex> lock(mMacAddrPairMutex);
1462 switch (type) {
1463 case WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO:
1464 return InsertMacAddrPairs(mWifiScanMacAddrPair, macAddrInfo, randomMacAddr);
1465 case WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO:
1466 return InsertMacAddrPairs(mHotspotMacAddrPair, macAddrInfo, randomMacAddr);
1467 case WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO:
1468 return InsertMacAddrPairs(mP2pDeviceMacAddrPair, macAddrInfo, randomMacAddr);
1469 case WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO:
1470 return InsertMacAddrPairs(mP2pGroupsInfoMacAddrPair, macAddrInfo, randomMacAddr);
1471 case WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO:
1472 return InsertMacAddrPairs(mP2pCurrentgroupMacAddrPair, macAddrInfo, randomMacAddr);
1473 default:
1474 LOGE("%{public}s: invalid mac address type, type:%{public}d", __func__, type);
1475 break;
1476 }
1477 return WIFI_MACADDR_INVALID_PARAM;
1478 }
1479
GetAllWifiLinkedNetworkId()1480 std::set<int> WifiConfigCenter::GetAllWifiLinkedNetworkId()
1481 {
1482 std::unique_lock<std::mutex> lock(mStaMutex);
1483 std::set<int> wifiLinkedNetworkId;
1484 for (auto iter = mWifiLinkedInfo.begin(); iter != mWifiLinkedInfo.end(); iter++) {
1485 wifiLinkedNetworkId.insert(iter->second.networkId);
1486 }
1487 return wifiLinkedNetworkId;
1488 }
1489
SetSystemMode(int systemMode)1490 void WifiConfigCenter::SetSystemMode(int systemMode)
1491 {
1492 systemMode_ = systemMode;
1493 LOGI("SetSystemMode %{public}d", systemMode_);
1494 }
1495
GetSystemMode()1496 int WifiConfigCenter::GetSystemMode()
1497 {
1498 WIFI_LOGD("GetSystemMode %{public}d", systemMode_);
1499 return systemMode_;
1500 }
1501
SetDeviceType(int deviceType)1502 void WifiConfigCenter::SetDeviceType(int deviceType)
1503 {
1504 mDeviceType = deviceType;
1505 }
1506
GetDeviceType()1507 int WifiConfigCenter::GetDeviceType()
1508 {
1509 return mDeviceType;
1510 }
1511
IsAllowPopUp()1512 bool WifiConfigCenter::IsAllowPopUp()
1513 {
1514 switch (mDeviceType) {
1515 case ProductDeviceType::WEARABLE:
1516 LOGI("Not allow pop up dialog, device type:%{public}d", mDeviceType);
1517 return false;
1518 default:
1519 LOGI("Allow pop up dialog, device type:%{public}d", mDeviceType);
1520 return true;
1521 }
1522 }
1523
IsAllowPcPopUp()1524 bool WifiConfigCenter::IsAllowPcPopUp()
1525 {
1526 switch (mDeviceType) {
1527 case ProductDeviceType::PC:
1528 LOGI("Not allow pop up dialog, device type:%{public}d", mDeviceType);
1529 return false;
1530 default:
1531 LOGI("Allow pop up dialog, device type:%{public}d", mDeviceType);
1532 return true;
1533 }
1534 }
1535
IsNeedFastScan(void)1536 bool WifiConfigCenter::IsNeedFastScan(void)
1537 {
1538 std::unique_lock<std::mutex> lock(mScanMutex);
1539 return isNeedFastScan;
1540 }
1541
SetFastScan(bool fastScan)1542 void WifiConfigCenter::SetFastScan(bool fastScan)
1543 {
1544 std::unique_lock<std::mutex> lock(mScanMutex);
1545 isNeedFastScan = fastScan;
1546 }
1547
SetAutoConnect(bool autoConnectEnable)1548 void WifiConfigCenter::SetAutoConnect(bool autoConnectEnable)
1549 {
1550 if (GetDeviceType() != ProductDeviceType::WEARABLE) {
1551 LOGD("SetAutoConnect not wearable device");
1552 return;
1553 }
1554
1555 LOGI("SetAutoConnect autoConnectEnable:%{public}d", autoConnectEnable);
1556 autoConnectEnable_.store(autoConnectEnable);
1557 }
1558
GetAutoConnect()1559 bool WifiConfigCenter::GetAutoConnect()
1560 {
1561 return autoConnectEnable_.load();
1562 }
1563
GetLocalOnlyHotspotConfig(HotspotConfig & hotspotConfig)1564 int WifiConfigCenter::GetLocalOnlyHotspotConfig(HotspotConfig &hotspotConfig)
1565 {
1566 std::unique_lock<std::mutex> lock(mApMutex);
1567 hotspotConfig = localOnlyHotspotConfig_;
1568 return 0;
1569 }
1570
SetLocalOnlyHotspotConfig(const HotspotConfig & hotspotConfig)1571 void WifiConfigCenter::SetLocalOnlyHotspotConfig(const HotspotConfig &hotspotConfig)
1572 {
1573 std::unique_lock<std::mutex> lock(mApMutex);
1574 localOnlyHotspotConfig_ = hotspotConfig;
1575 }
1576
SetNetworkControlInfo(const WifiNetworkControlInfo & networkControlInfo)1577 void WifiConfigCenter::SetNetworkControlInfo(const WifiNetworkControlInfo& networkControlInfo)
1578 {
1579 std::unique_lock<std::mutex> lock(mScanMutex);
1580 networkControlInfoRecord = networkControlInfo;
1581 }
1582
GetNetworkControlInfo()1583 WifiNetworkControlInfo WifiConfigCenter::GetNetworkControlInfo()
1584 {
1585 std::unique_lock<std::mutex> lock(mScanMutex);
1586 return networkControlInfoRecord;
1587 }
1588
1589 #ifndef OHOS_ARCH_LITE
SetScreenDispalyState(int32_t orientation)1590 void WifiConfigCenter::SetScreenDispalyState(int32_t orientation)
1591 {
1592 screenDisplayOrientation.store(orientation);
1593 }
1594
IsScreenLandscape()1595 bool WifiConfigCenter::IsScreenLandscape()
1596 {
1597 return screenDisplayOrientation.load() == static_cast<int32_t>(Rosen::DisplayOrientation::LANDSCAPE) ||
1598 screenDisplayOrientation.load() == static_cast<int32_t>(Rosen::DisplayOrientation::LANDSCAPE_INVERTED);
1599 }
1600 #endif
1601 } // namespace Wifi
1602 } // namespace OHOS
1603