1 /*
2 * Copyright (c) 2023 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 "service_ex_manager.h"
17
18 #include <dlfcn.h>
19
20 #include "iam_check.h"
21 #include "iam_logger.h"
22
23 #define LOG_LABEL UserIam::Common::LABEL_FINGERPRINT_AUTH_SA
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace FingerprintAuth {
28 namespace {
29 const char *SO_NAME = "libfingerprintauthservice_ex.z.so";
30 const char *GET_SENSOR_ILLUMINATION_TASK_SYMBOL_NAME =
31 "_ZN4OHOS7UserIam15FingerprintAuth25GetSensorIlluminationTaskEv";
32 using GetSensorIlluminationTaskFunc = std::shared_ptr<ISensorIlluminationTask> (*)();
33 } // namespace
34
GetInstance()35 ServiceExManager &ServiceExManager::GetInstance()
36 {
37 static ServiceExManager manager;
38 return manager;
39 }
40
Acquire()41 UserAuth::ResultCode ServiceExManager::Acquire()
42 {
43 std::lock_guard<std::recursive_mutex> lock(recursiveMutex_);
44 IAM_LOGI("start");
45 if (!isOpened_) {
46 handle_ = dlopen(SO_NAME, RTLD_LAZY);
47 if (handle_ == nullptr) {
48 IAM_LOGE("failed to open so, error: %{public}s", dlerror());
49 return UserAuth::GENERAL_ERROR;
50 }
51 isOpened_ = true;
52 IAM_LOGI("dlopen success");
53 }
54
55 IAM_LOGI("success");
56 return UserAuth::SUCCESS;
57 }
58
Release()59 void ServiceExManager::Release()
60 {
61 std::lock_guard<std::recursive_mutex> lock(recursiveMutex_);
62 IAM_LOGI("in this version, so is not released");
63 }
64
GetSensorIlluminationTask()65 std::shared_ptr<ISensorIlluminationTask> ServiceExManager::GetSensorIlluminationTask()
66 {
67 std::lock_guard<std::recursive_mutex> lock(recursiveMutex_);
68 IF_FALSE_LOGE_AND_RETURN_VAL(handle_ != nullptr, nullptr);
69
70 GetSensorIlluminationTaskFunc getFunc =
71 reinterpret_cast<GetSensorIlluminationTaskFunc>(dlsym(handle_, GET_SENSOR_ILLUMINATION_TASK_SYMBOL_NAME));
72 if (getFunc == nullptr) {
73 IAM_LOGE("failed to find symbol, error: %{public}s", dlerror());
74 return nullptr;
75 }
76
77 return getFunc();
78 }
79 } // namespace FingerprintAuth
80 } // namespace UserIam
81 } // namespace OHOS