1 /*
2 * Copyright (c) 2025 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 "load_mode_handler_dynamic.h"
17
18 #include "driver_load_manager.h"
19 #include "iam_logger.h"
20 #include "system_param_manager.h"
21
22 #define LOG_TAG "PIN_AUTH_SA"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace PinAuth {
LoadModeHandlerDynamic()27 LoadModeHandlerDynamic::LoadModeHandlerDynamic()
28 {
29 IAM_LOGI("sa load mode is dynamic");
30 }
31
StartSubscribe()32 void LoadModeHandlerDynamic::StartSubscribe()
33 {
34 std::lock_guard<std::recursive_mutex> lock(mutex_);
35 if (isSubscribed_) {
36 return;
37 }
38
39 DriverLoadManager::GetInstance().StartSubscribe();
40
41 isSubscribed_ = true;
42 }
43
OnFrameworkDown()44 void LoadModeHandlerDynamic::OnFrameworkDown()
45 {
46 IAM_LOGI("fwk down");
47 SystemParamManager::GetInstance().SetParam(FWK_READY_KEY, FALSE_STR);
48 SystemParamManager::GetInstance().SetParam(IS_PIN_FUNCTION_READY_KEY, FALSE_STR);
49 bool isPinEnrolled = SystemParamManager::GetInstance().GetParam(IS_PIN_ENROLLED_KEY, FALSE_STR) == TRUE_STR;
50 if (isPinEnrolled) {
51 IAM_LOGI("pin auth service down, pin enrolled, wait fwk ready");
52 } else {
53 bool isStopSa = SystemParamManager::GetInstance().GetParam(STOP_SA_KEY, FALSE_STR) == TRUE_STR;
54 if (isStopSa) {
55 IAM_LOGI("Sa is stopping, not need stop sa");
56 } else {
57 IAM_LOGI("pin auth service down, pin not enrolled, stop sa");
58 SystemParamManager::GetInstance().SetParamTwice(STOP_SA_KEY, FALSE_STR, TRUE_STR);
59 }
60 }
61 }
62 } // namespace PinAuth
63 } // namespace UserIam
64 } // namespace OHOS