14f7ff21fSopenharmony_ci/* 24f7ff21fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34f7ff21fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44f7ff21fSopenharmony_ci * you may not use this file except in compliance with the License. 54f7ff21fSopenharmony_ci * You may obtain a copy of the License at 64f7ff21fSopenharmony_ci * 74f7ff21fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84f7ff21fSopenharmony_ci * 94f7ff21fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104f7ff21fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114f7ff21fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124f7ff21fSopenharmony_ci * See the License for the specific language governing permissions and 134f7ff21fSopenharmony_ci * limitations under the License. 144f7ff21fSopenharmony_ci */ 154f7ff21fSopenharmony_ci 164f7ff21fSopenharmony_ci#include "service_ex_manager.h" 174f7ff21fSopenharmony_ci 184f7ff21fSopenharmony_ci#include <dlfcn.h> 194f7ff21fSopenharmony_ci 204f7ff21fSopenharmony_ci#include "iam_check.h" 214f7ff21fSopenharmony_ci#include "iam_logger.h" 224f7ff21fSopenharmony_ci 234f7ff21fSopenharmony_ci#define LOG_TAG "FINGERPRINT_AUTH_SA" 244f7ff21fSopenharmony_ci 254f7ff21fSopenharmony_cinamespace OHOS { 264f7ff21fSopenharmony_cinamespace UserIam { 274f7ff21fSopenharmony_cinamespace FingerprintAuth { 284f7ff21fSopenharmony_cinamespace { 294f7ff21fSopenharmony_ciconst char *SO_NAME = "libfingerprintauthservice_ex.z.so"; 304f7ff21fSopenharmony_ciconst char *GET_SENSOR_ILLUMINATION_TASK_SYMBOL_NAME = "_ZN4OHOS7UserIam15FingerprintAuth25GetSensorIlluminationTaskEv"; 314f7ff21fSopenharmony_ciusing GetSensorIlluminationTaskFunc = std::shared_ptr<ISensorIlluminationTask> (*)(); 324f7ff21fSopenharmony_ci} // namespace 334f7ff21fSopenharmony_ci 344f7ff21fSopenharmony_ciServiceExManager &ServiceExManager::GetInstance() 354f7ff21fSopenharmony_ci{ 364f7ff21fSopenharmony_ci static ServiceExManager manager; 374f7ff21fSopenharmony_ci return manager; 384f7ff21fSopenharmony_ci} 394f7ff21fSopenharmony_ci 404f7ff21fSopenharmony_ciUserAuth::ResultCode ServiceExManager::Acquire() 414f7ff21fSopenharmony_ci{ 424f7ff21fSopenharmony_ci std::lock_guard<std::recursive_mutex> lock(recursiveMutex_); 434f7ff21fSopenharmony_ci IAM_LOGI("start"); 444f7ff21fSopenharmony_ci if (!isOpened_) { 454f7ff21fSopenharmony_ci handle_ = dlopen(SO_NAME, RTLD_LAZY); 464f7ff21fSopenharmony_ci if (handle_ == nullptr) { 474f7ff21fSopenharmony_ci IAM_LOGE("failed to open so, error: %{public}s", dlerror()); 484f7ff21fSopenharmony_ci return UserAuth::GENERAL_ERROR; 494f7ff21fSopenharmony_ci } 504f7ff21fSopenharmony_ci isOpened_ = true; 514f7ff21fSopenharmony_ci IAM_LOGI("dlopen success"); 524f7ff21fSopenharmony_ci } 534f7ff21fSopenharmony_ci 544f7ff21fSopenharmony_ci IAM_LOGI("success"); 554f7ff21fSopenharmony_ci return UserAuth::SUCCESS; 564f7ff21fSopenharmony_ci} 574f7ff21fSopenharmony_ci 584f7ff21fSopenharmony_civoid ServiceExManager::Release() 594f7ff21fSopenharmony_ci{ 604f7ff21fSopenharmony_ci std::lock_guard<std::recursive_mutex> lock(recursiveMutex_); 614f7ff21fSopenharmony_ci IAM_LOGI("in this version, so is not released"); 624f7ff21fSopenharmony_ci} 634f7ff21fSopenharmony_ci 644f7ff21fSopenharmony_cistd::shared_ptr<ISensorIlluminationTask> ServiceExManager::GetSensorIlluminationTask() 654f7ff21fSopenharmony_ci{ 664f7ff21fSopenharmony_ci std::lock_guard<std::recursive_mutex> lock(recursiveMutex_); 674f7ff21fSopenharmony_ci IF_FALSE_LOGE_AND_RETURN_VAL(handle_ != nullptr, nullptr); 684f7ff21fSopenharmony_ci 694f7ff21fSopenharmony_ci GetSensorIlluminationTaskFunc getFunc = 704f7ff21fSopenharmony_ci reinterpret_cast<GetSensorIlluminationTaskFunc>(dlsym(handle_, GET_SENSOR_ILLUMINATION_TASK_SYMBOL_NAME)); 714f7ff21fSopenharmony_ci if (getFunc == nullptr) { 724f7ff21fSopenharmony_ci IAM_LOGE("failed to find symbol, error: %{public}s", dlerror()); 734f7ff21fSopenharmony_ci return nullptr; 744f7ff21fSopenharmony_ci } 754f7ff21fSopenharmony_ci 764f7ff21fSopenharmony_ci return getFunc(); 774f7ff21fSopenharmony_ci} 784f7ff21fSopenharmony_ci} // namespace FingerprintAuth 794f7ff21fSopenharmony_ci} // namespace UserIam 804f7ff21fSopenharmony_ci} // namespace OHOS