• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IS_SO_CROP_H
16 #include <cinttypes>
17 #include "strongauthmanager.h"
18 #include "screenlock_common.h"
19 #include "sclock_log.h"
20 #include "screenlock_system_ability.h"
21 #include "user_auth_client_callback.h"
22 #include "user_idm_client.h"
23 #include "os_account_manager.h"
24 #include "innerlistenermanager.h"
25 #include "syspara/parameters.h"
26 
27 namespace OHOS {
28 namespace ScreenLock {
29 std::mutex StrongAuthManger::instanceLock_;
30 sptr<StrongAuthManger> StrongAuthManger::instance_;
31 using namespace OHOS::UserIam::UserAuth;
32 using namespace OHOS::AccountSA;
33 
StrongAuthManger()34 StrongAuthManger::StrongAuthManger() {}
35 
~StrongAuthManger()36 StrongAuthManger::~StrongAuthManger() {}
37 
authTimer()38 StrongAuthManger::authTimer::authTimer()
39 {
40     userId_ = 0;
41 }
42 
authTimer(bool repeat,uint64_t interval,bool isExact,bool isIdle)43 StrongAuthManger::authTimer::authTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle)
44 {
45     this->repeat = repeat;
46     this->interval = interval;
47     this->type = TIMER_TYPE_WAKEUP;
48     if (isExact) {
49         this->type = TIMER_TYPE_WAKEUP + TIMER_TYPE_REALTIME;
50     }
51     if (isIdle) {
52         this->type = TIMER_TYPE_IDLE;
53     }
54     userId_ = 0;
55 }
56 
~authTimer()57 StrongAuthManger::authTimer::~authTimer() {}
58 
OnTrigger()59 void StrongAuthManger::authTimer::OnTrigger()
60 {
61     SCLOCK_HILOGI("%{public}d, OnTrigger enter", userId_);
62     if (callBack_) {
63         callBack_(userId_);
64     }
65 }
66 
SetType(const int & type)67 void StrongAuthManger::authTimer::SetType(const int &type)
68 {
69     this->type = type;
70 }
71 
SetRepeat(bool repeat)72 void StrongAuthManger::authTimer::SetRepeat(bool repeat)
73 {
74     this->repeat = repeat;
75 }
76 
SetInterval(const uint64_t & interval)77 void StrongAuthManger::authTimer::SetInterval(const uint64_t &interval)
78 {
79     this->interval = interval;
80 }
81 
SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent)82 void StrongAuthManger::authTimer::SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent)
83 {
84     this->wantAgent = wantAgent;
85 }
86 
SetCallbackInfo(const std::function<void (int32_t)> & callBack)87 void StrongAuthManger::authTimer::SetCallbackInfo(const std::function<void(int32_t)> &callBack)
88 {
89     this->callBack_ = callBack;
90 }
91 
GetUserId()92 int32_t StrongAuthManger::authTimer::GetUserId()
93 {
94     return userId_;
95 }
96 
SetUserId(int32_t userId)97 void StrongAuthManger::authTimer::SetUserId(int32_t userId)
98 {
99     userId_ = userId;
100 }
101 
StrongAuthTimerCallback(int32_t userId)102 static void StrongAuthTimerCallback(int32_t userId)
103 {
104     SCLOCK_HILOGI("%{public}s, enter", __FUNCTION__);
105     int32_t reasonFlag = static_cast<int32_t>(StrongAuthReasonFlags::AFTER_TIMEOUT);
106     StrongAuthManger::GetInstance()->SetStrongAuthStat(userId, reasonFlag);
107     return;
108 }
109 
IsOsAccountUnlocked(int32_t osAccountId)110 static bool IsOsAccountUnlocked(int32_t osAccountId)
111 {
112     bool isUnlocked = false;
113     OHOS::ErrCode res = OHOS::AccountSA::OsAccountManager::IsOsAccountVerified(osAccountId, isUnlocked);
114     if (res != OHOS::ERR_OK) {
115         SCLOCK_HILOGE(" Check account verify status failed, res: %{public}d, accountId: %{public}d", res, osAccountId);
116         return false;
117     }
118     SCLOCK_HILOGI(" account verified status: %{public}d, accountId: %{public}d", isUnlocked, osAccountId);
119     return isUnlocked;
120 }
121 
GetInstance()122 sptr<StrongAuthManger> StrongAuthManger::GetInstance()
123 {
124     if (instance_ == nullptr) {
125         std::lock_guard<std::mutex> autoLock(instanceLock_);
126         if (instance_ == nullptr) {
127             instance_ = new StrongAuthManger;
128         }
129     }
130     return instance_;
131 }
132 
GetTimerId(int32_t userId)133 uint64_t StrongAuthManger::GetTimerId(int32_t userId)
134 {
135     uint64_t timerId = 0;
136     auto iter = strongAuthTimerInfo.find(userId);
137     if (iter != strongAuthTimerInfo.end()) {
138         timerId = iter->second.timerId;
139     }
140     SCLOCK_HILOGI("GetTimerId, timerId: %{public}d", static_cast<int32_t>(timerId));
141     return timerId;
142 }
143 
RegistIamEventListener()144 void StrongAuthManger::RegistIamEventListener()
145 {
146     SCLOCK_HILOGD("RegistIamEventListener start");
147     if (OHOS::system::GetDeviceType() == "2in1") {
148         SCLOCK_HILOGD("2in1 device no need to registCredChangeListener");
149         return;
150     }
151 
152     std::vector<UserIam::UserAuth::AuthType> authTypeList;
153     authTypeList.emplace_back(AuthType::PIN);
154     authTypeList.emplace_back(AuthType::FACE);
155     authTypeList.emplace_back(AuthType::FINGERPRINT);
156 
157     if (credChangeListener_ == nullptr) {
158         credChangeListener_ = std::make_shared<CredChangeListenerService>();
159     }
160     int32_t ret = UserIam::UserAuth::UserIdmClient::GetInstance().RegistCredChangeEventListener(
161         authTypeList, credChangeListener_);
162     SCLOCK_HILOGI("RegistCredChangeEventListener ret: %{public}d", ret);
163 }
164 
RegistAuthEventListener()165 void StrongAuthManger::RegistAuthEventListener()
166 {
167     SCLOCK_HILOGD("RegistAuthEventListener start");
168     std::vector<UserIam::UserAuth::AuthType> authTypeList;
169     authTypeList.emplace_back(AuthType::PIN);
170     authTypeList.emplace_back(AuthType::FACE);
171     authTypeList.emplace_back(AuthType::FINGERPRINT);
172 
173     if (authSuccessListener_ == nullptr) {
174         authSuccessListener_ = std::make_shared<AuthEventListenerService>();
175     }
176     int32_t ret = UserIam::UserAuth::UserAuthClient::GetInstance().RegistUserAuthSuccessEventListener(
177         authTypeList, authSuccessListener_);
178     SCLOCK_HILOGI("RegistUserAuthSuccessEventListener ret: %{public}d", ret);
179 }
180 
OnNotifyAuthSuccessEvent(int32_t userId,UserIam::UserAuth::AuthType authType,int32_t callerType,const std::string & bundleName)181 void StrongAuthManger::AuthEventListenerService::OnNotifyAuthSuccessEvent(int32_t userId,
182     UserIam::UserAuth::AuthType authType, int32_t callerType, const std::string &bundleName)
183 {
184     SCLOCK_HILOGI("OnNotifyAuthSuccessEvent: %{public}d, %{public}d, %{public}s, callerType: %{public}d", userId,
185         static_cast<int32_t>(authType), bundleName.c_str(), callerType);
186     if (authType == AuthType::PIN) {
187         StrongAuthManger::GetInstance()->SetStrongAuthStat(userId, static_cast<int32_t>(StrongAuthReasonFlags::NONE));
188         int64_t triggerPeriod = StrongAuthManger::GetInstance()->GetStrongAuthTriggerPeriod(userId);
189         StrongAuthManger::GetInstance()->ResetStrongAuthTimer(userId, triggerPeriod);
190     }
191     return;
192 }
193 
OnNotifyCredChangeEvent(int32_t userId,UserIam::UserAuth::AuthType authType,UserIam::UserAuth::CredChangeEventType eventType,const UserIam::UserAuth::CredChangeEventInfo & changeInfo)194 void StrongAuthManger::CredChangeListenerService::OnNotifyCredChangeEvent(int32_t userId,
195     UserIam::UserAuth::AuthType authType, UserIam::UserAuth::CredChangeEventType eventType,
196     const UserIam::UserAuth::CredChangeEventInfo &changeInfo)
197 {
198     SCLOCK_HILOGI("OnNotifyCredChangeEvent: %{public}d, %{public}d, %{public}d, %{public}u", userId,
199         static_cast<int32_t>(authType), eventType, static_cast<uint16_t>(changeInfo.isSilentCredChange));
200 
201     if (OHOS::system::GetDeviceType() == "2in1") {
202         // PC只有无密码到有密码需要创建定时器
203         if (authType == AuthType::PIN && eventType == ADD_CRED &&
204             StrongAuthManger::GetInstance()->IsUserExitInStrongAuthInfo(userId) &&
205             !StrongAuthManger::GetInstance()->IsUserHasStrongAuthTimer(userId)) {
206             SCLOCK_HILOGD("2in1 device only deal add cred");
207             StrongAuthManger::GetInstance()->StartStrongAuthTimer(userId);
208         }
209         return;
210     }
211 
212     //新用户应该走切换重启创建定时器
213     if (authType == AuthType::PIN && StrongAuthManger::GetInstance()->IsUserExitInStrongAuthInfo(userId)) {
214         if (eventType == ADD_CRED || (eventType == UPDATE_CRED && !changeInfo.isSilentCredChange)) {
215             StrongAuthManger::GetInstance()->ResetStrongAuthTimer(userId, CRED_CHANGE_FIRST_STRONG_AUTH_TIMEOUT_MS);
216         } else if (eventType == DEL_USER) {
217             StrongAuthManger::GetInstance()->SetStrongAuthStat(
218                 userId, static_cast<int32_t>(StrongAuthReasonFlags::NONE));
219             StrongAuthManger::GetInstance()->DestroyStrongAuthTimer(userId);
220         } else if (eventType == ENFORCE_DEL_USER) {
221             StrongAuthManger::GetInstance()->DestroyStrongAuthStateInfo(userId);
222             StrongAuthManger::GetInstance()->DestroyStrongAuthTimer(userId);
223         }
224     }
225     return;
226 }
227 
UnRegistIamEventListener()228 void StrongAuthManger::UnRegistIamEventListener()
229 {
230     if (credChangeListener_ != nullptr) {
231         int32_t ret = UserIam::UserAuth::
232             UserIdmClient::GetInstance().UnRegistCredChangeEventListener(credChangeListener_);
233         credChangeListener_ = nullptr;
234         SCLOCK_HILOGI("UnRegistCredChangeEventListener ret: %{public}d", ret);
235     }
236 }
237 
UnRegistAuthEventListener()238 void StrongAuthManger::UnRegistAuthEventListener()
239 {
240     if (authSuccessListener_ != nullptr) {
241         int32_t ret = UserIam::UserAuth::
242             UserAuthClient::GetInstance().UnRegistUserAuthSuccessEventListener(authSuccessListener_);
243         authSuccessListener_ = nullptr;
244         SCLOCK_HILOGI("UnRegistUserAuthSuccessEventListener ret: %{public}d", ret);
245     }
246 }
247 
StartStrongAuthTimer(int32_t userId)248 void StrongAuthManger::StartStrongAuthTimer(int32_t userId)
249 {
250     StartStrongAuthTimer(userId, DEFAULT_STRONG_AUTH_TIMEOUT_MS);
251 }
252 
StartStrongAuthTimer(int32_t userId,int64_t triggerPeriod)253 void StrongAuthManger::StartStrongAuthTimer(int32_t userId, int64_t triggerPeriod)
254 {
255     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
256     uint64_t timerId = GetTimerId(userId);
257     if (timerId != 0) {
258         SCLOCK_HILOGI("StrongAuthTimer exist. userId:%{public}d", userId);
259         return;
260     }
261 
262     SCLOCK_HILOGI("StartStrongAuthTimer triggerPeriod:%{public}" PRId64, triggerPeriod);
263     std::shared_ptr<authTimer> timer = std::make_shared<authTimer>(true, DEFAULT_STRONG_AUTH_TIMEOUT_MS, true, false);
264     timer->SetCallbackInfo(StrongAuthTimerCallback);
265     timer->SetUserId(userId);
266     timerId = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(timer);
267     int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
268     MiscServices::TimeServiceClient::GetInstance()->StartTimer(timerId, currentTime + triggerPeriod);
269     TimerInfo timerInfo = {
270         .timerId = timerId,
271         .triggerPeriod = triggerPeriod,
272         .credChangeTimerStamp = currentTime,
273     };
274     strongAuthTimerInfo.insert(std::make_pair(userId, timerInfo));
275     return;
276 }
277 
ResetStrongAuthTimer(int32_t userId,int64_t triggerPeriod)278 void StrongAuthManger::ResetStrongAuthTimer(int32_t userId, int64_t triggerPeriod)
279 {
280     SCLOCK_HILOGI("ResetStrongAuthTimer triggerPeriod:%{public}" PRId64, triggerPeriod);
281     uint64_t timerId = GetTimerId(userId);
282     if (timerId == 0) {
283         StartStrongAuthTimer(userId, triggerPeriod);
284         return;
285     }
286     int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
287     MiscServices::TimeServiceClient::GetInstance()->StopTimer(timerId);
288     MiscServices::TimeServiceClient::GetInstance()->StartTimer(timerId, currentTime + triggerPeriod);
289     SetCredChangeTriggerPeriod(userId, triggerPeriod);
290     return;
291 }
292 
SetCredChangeTriggerPeriod(int32_t userId,int64_t triggerPeriod)293 void StrongAuthManger::SetCredChangeTriggerPeriod(int32_t userId, int64_t triggerPeriod)
294 {
295     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
296     auto iter = strongAuthTimerInfo.find(userId);
297     if (iter == strongAuthTimerInfo.end()) {
298         SCLOCK_HILOGI("SetCredChangeTriggerPeriod userId:%{public}d not exit", userId);
299         return;
300     }
301     iter->second.triggerPeriod = triggerPeriod;
302     iter->second.credChangeTimerStamp = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
303     return;
304 }
305 
GetStrongAuthTriggerPeriod(int32_t userId)306 int64_t StrongAuthManger::GetStrongAuthTriggerPeriod(int32_t userId)
307 {
308     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
309     auto iter = strongAuthTimerInfo.find(userId);
310     if (iter == strongAuthTimerInfo.end()) {
311         SCLOCK_HILOGI("GetStrongAuthTriggerPeriod userId:%{public}d not exit", userId);
312         return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
313     }
314     int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
315     if (iter->second.triggerPeriod == CRED_CHANGE_FIRST_STRONG_AUTH_TIMEOUT_MS) {
316         if (currentTime - iter->second.credChangeTimerStamp > CRED_CHANGE_FIRST_STRONG_AUTH_TIMEOUT_MS) {
317             iter->second.triggerPeriod = CRED_CHANGE_SECOND_STRONG_AUTH_TIMEOUT_MS;
318             iter->second.credChangeTimerStamp = currentTime;
319             return iter->second.triggerPeriod;
320         }
321         return iter->second.triggerPeriod;
322     }
323 
324     if (iter->second.triggerPeriod == CRED_CHANGE_SECOND_STRONG_AUTH_TIMEOUT_MS) {
325         if (currentTime - iter->second.credChangeTimerStamp >
326             CRED_CHANGE_SECOND_STRONG_AUTH_TIMEOUT_MS) {
327             iter->second.triggerPeriod = DEFAULT_STRONG_AUTH_TIMEOUT_MS;
328             return iter->second.triggerPeriod;
329         }
330         return iter->second.triggerPeriod;
331     }
332     return iter->second.triggerPeriod;
333 }
334 
DestroyAllStrongAuthTimer()335 void StrongAuthManger::DestroyAllStrongAuthTimer()
336 {
337     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
338     for (auto iter = strongAuthTimerInfo.begin(); iter != strongAuthTimerInfo.end();) {
339         uint64_t timerId = GetTimerId(iter->first);
340         if (timerId != 0) {
341             MiscServices::TimeServiceClient::GetInstance()->StopTimer(timerId);
342             MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(timerId);
343             iter = strongAuthTimerInfo.erase(iter);
344         } else {
345             ++iter;
346         }
347     }
348     return;
349 }
350 
DestroyStrongAuthTimer(int32_t userId)351 void StrongAuthManger::DestroyStrongAuthTimer(int32_t userId)
352 {
353     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
354     uint64_t timerId = GetTimerId(userId);
355     if (timerId == 0) {
356         return;
357     }
358     MiscServices::TimeServiceClient::GetInstance()->StopTimer(timerId);
359     MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(timerId);
360     strongAuthTimerInfo.erase(userId);
361     SCLOCK_HILOGW("DestroyStrongAuthTimer lenth: %{public}d", static_cast<int32_t>(strongAuthTimerInfo.size()));
362     return;
363 }
364 
SetStrongAuthStat(int32_t userId,int32_t reasonFlag)365 void StrongAuthManger::SetStrongAuthStat(int32_t userId, int32_t reasonFlag)
366 {
367     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
368     auto iter = strongAuthStateInfo.find(userId);
369     if (iter == strongAuthStateInfo.end()) {
370         SCLOCK_HILOGI("SetStrongAuthStat fail, user not exit in strongAuthStateInfo");
371         strongAuthStateInfo.insert(std::make_pair(userId, reasonFlag));
372         NotifyStrongAuthChange(userId, reasonFlag);
373         return;
374     }
375 
376     auto oldFlag = iter->second;
377     if (oldFlag == static_cast<int32_t>(StrongAuthReasonFlags::AFTER_BOOT) &&
378         reasonFlag != static_cast<int32_t>(StrongAuthReasonFlags::NONE)) {
379         // 重启强认证状态优先级最高
380         SCLOCK_HILOGE("still after_boot, oldFlag:%{public}u, reasonFlag:%{public}u", oldFlag, reasonFlag);
381         return;
382     }
383 
384     iter->second = reasonFlag;
385     lock.unlock();
386     NotifyStrongAuthChange(userId, reasonFlag);
387     SCLOCK_HILOGI("SetStrongAuthStat, oldFlag:%{public}u, reasonFlag:%{public}u", oldFlag, reasonFlag);
388     return;
389 }
390 
GetStrongAuthStat(int32_t userId)391 int32_t StrongAuthManger::GetStrongAuthStat(int32_t userId)
392 {
393     std::lock_guard<std::mutex> lock(strongAuthTimerMutex);
394     int32_t reasonFlag = static_cast<int32_t>(StrongAuthReasonFlags::AFTER_BOOT);
395     auto iter = strongAuthStateInfo.find(userId);
396     if (IsOsAccountUnlocked(userId) && iter != strongAuthStateInfo.end()) {
397         reasonFlag = iter->second;
398         SCLOCK_HILOGI("GetStrongAuthStat, reasonFlag:%{public}u", reasonFlag);
399     }
400     return reasonFlag;
401 }
402 
GetStrongAuthTimeTrigger(int32_t userId)403 int32_t StrongAuthManger::GetStrongAuthTimeTrigger(int32_t userId)
404 {
405     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
406     auto iter = strongAuthTimerInfo.find(userId);
407     if (iter != strongAuthTimerInfo.end()) {
408         return iter->second.triggerPeriod;
409     }
410     return 0;
411 }
412 
AccountUnlocked(int32_t userId)413 void StrongAuthManger::AccountUnlocked(int32_t userId)
414 {
415     NotifyStrongAuthChange(userId, static_cast<int32_t>(StrongAuthReasonFlags::NONE));
416 }
417 
DestroyStrongAuthStateInfo(int32_t userId)418 void StrongAuthManger::DestroyStrongAuthStateInfo(int32_t userId)
419 {
420     std::lock_guard<std::mutex> lock(strongAuthTimerMutex);
421     auto iter = strongAuthStateInfo.find(userId);
422     if (iter != strongAuthStateInfo.end()) {
423         strongAuthStateInfo.erase(userId);
424     }
425     return;
426 }
427 
InitStrongAuthStat(int32_t userId,int32_t reasonFlag)428 void StrongAuthManger::InitStrongAuthStat(int32_t userId, int32_t reasonFlag)
429 {
430     std::lock_guard<std::mutex> lock(strongAuthTimerMutex);
431     auto iter = strongAuthStateInfo.find(userId);
432     if (iter == strongAuthStateInfo.end()) {
433         strongAuthStateInfo.insert(std::make_pair(userId, reasonFlag));
434         SCLOCK_HILOGW("InitStrongAuthStat, userId:%{public}u, reasonFlag:%{public}u", userId, reasonFlag);
435         NotifyStrongAuthChange(userId, reasonFlag);
436     }
437     return;
438 }
439 
GetCredInfo(int32_t userId)440 bool StrongAuthManger::GetCredInfo(int32_t userId)
441 {
442     std::unique_lock<std::mutex> lock(strongAuthTimerMutex);
443     if (strongAuthStateInfo.find(userId) != strongAuthStateInfo.end()) {
444         return true;
445     }
446     lock.unlock();
447 
448     auto getInfoCallback = std::make_shared<StrongAuthManger::StrongAuthGetSecurity>(userId);
449     int32_t result = UserIdmClient::GetInstance().GetCredentialInfo(userId, AuthType::PIN, getInfoCallback);
450     if (result != static_cast<int32_t>(ResultCode::SUCCESS)) {
451         SCLOCK_HILOGE("GetCredentialInfo AuthType::PIN result = %{public}d", result);
452     }
453     return result;
454 }
455 
OnCredentialInfo(int32_t result,const std::vector<UserIam::UserAuth::CredentialInfo> & infoList)456 void StrongAuthManger::StrongAuthGetSecurity::OnCredentialInfo(
457     int32_t result, const std::vector<UserIam::UserAuth::CredentialInfo> &infoList)
458 {
459     if (infoList.size() > 0 ||
460         (result != UserIam::UserAuth::SUCCESS && result != UserIam::UserAuth::NOT_ENROLLED)) {
461         SCLOCK_HILOGD("infoList.size() = %{public}zu", infoList.size());
462         int32_t reasonFlag = static_cast<int32_t>(StrongAuthReasonFlags::AFTER_BOOT);
463         StrongAuthManger::GetInstance()->InitStrongAuthStat(userId_, reasonFlag);
464         // 重启后为72小时
465         StrongAuthManger::GetInstance()->StartStrongAuthTimer(userId_);
466     } else {
467         int32_t reasonFlag = static_cast<int32_t>(StrongAuthReasonFlags::NONE);
468         StrongAuthManger::GetInstance()->InitStrongAuthStat(userId_, reasonFlag);
469     }
470     return;
471 }
472 
IsUserExitInStrongAuthInfo(int32_t userId)473 bool StrongAuthManger::IsUserExitInStrongAuthInfo(int32_t userId)
474 {
475     std::lock_guard<std::mutex> lock(strongAuthTimerMutex);
476     auto iter = strongAuthStateInfo.find(userId);
477     if (iter != strongAuthStateInfo.end()) {
478         return true;
479     }
480     return false;
481 }
482 
IsUserHasStrongAuthTimer(int32_t userId)483 bool StrongAuthManger::IsUserHasStrongAuthTimer(int32_t userId)
484 {
485     std::lock_guard<std::mutex> lock(strongAuthTimerMutex);
486     auto iter = strongAuthTimerInfo.find(userId);
487     if (iter != strongAuthTimerInfo.end()) {
488         return true;
489     }
490     return false;
491 }
492 
NotifyStrongAuthChange(int32_t userId,int32_t reasonFlag)493 void StrongAuthManger::NotifyStrongAuthChange(int32_t userId, int32_t reasonFlag)
494 {
495     if (reasonFlag == static_cast<int32_t>(StrongAuthReasonFlags::NONE)) {
496         if (IsOsAccountUnlocked(userId)) {
497             ScreenLockSystemAbility::GetInstance()->StrongAuthChanged(userId, reasonFlag);
498             InnerListenerManager::GetInstance()->OnStrongAuthChanged(userId, reasonFlag);
499         }
500     } else {
501         ScreenLockSystemAbility::GetInstance()->StrongAuthChanged(userId, reasonFlag);
502         InnerListenerManager::GetInstance()->OnStrongAuthChanged(userId, reasonFlag);
503     }
504 }
505 } // namespace ScreenLock
506 } // namespace OHOS
507 #endif // IS_SO_CROP_H