• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "fingerprint_auth_service.h"
17 
18 #include <cstdint>
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 
26 #include "iam_executor_idriver_manager.h"
27 #include "ipc_skeleton.h"
28 #include "iremote_object.h"
29 #include "iservice_registry.h"
30 #include "refbase.h"
31 #include "system_ability.h"
32 #include "system_ability_definition.h"
33 
34 #include "iam_check.h"
35 #include "iam_logger.h"
36 #include "iam_ptr.h"
37 
38 #include "fingerprint_auth_defines.h"
39 #include "fingerprint_auth_driver_hdi.h"
40 #include "fingerprint_auth_interface_adapter.h"
41 #include "sensor_illumination_manager.h"
42 
43 #define LOG_TAG "FINGERPRINT_AUTH_SA"
44 
45 namespace OHOS {
46 namespace UserIam {
47 namespace FingerprintAuth {
48 namespace UserAuth = OHOS::UserIam::UserAuth;
49 using namespace OHOS::UserIam;
50 namespace {
51 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(FingerprintAuthService::GetInstance().get());
52 const uint16_t FINGERPRINT_AUTH_DEFAULT_HDI_ID = 1;
53 const auto FINGERPRINT_AUTH_DEFAULT_HDI_ADAPTER = Common::MakeShared<FingerprintAuthInterfaceAdapter>();
54 auto FINGERPRINT_AUTH_DEFAULT_HDI = Common::MakeShared<FingerprintAuthDriverHdi>(FINGERPRINT_AUTH_DEFAULT_HDI_ADAPTER);
55 // serviceName and HdiConfig.id must be globally unique
56 const std::map<std::string, UserAuth::HdiConfig> HDI_NAME_2_CONFIG = {
57     { "fingerprint_auth_interface_service", { FINGERPRINT_AUTH_DEFAULT_HDI_ID, FINGERPRINT_AUTH_DEFAULT_HDI } },
58 };
59 const std::vector<std::shared_ptr<FingerprintAuthDriverHdi>> FINGERPRINT_AUTH_DRIVER_HDIS = {
60     FINGERPRINT_AUTH_DEFAULT_HDI
61 };
62 // setup brightness manager
63 const auto FINGER_SENSOR_ILLUMINATION_MANAGER = SensorIlluminationManager::GetInstance();
64 } // namespace
65 std::mutex FingerprintAuthService::mutex_;
66 std::shared_ptr<FingerprintAuthService> FingerprintAuthService::instance_ = nullptr;
67 
FingerprintAuthService()68 FingerprintAuthService::FingerprintAuthService() : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_FINGERPRINTAUTH, true)
69 {
70 }
71 
GetInstance()72 std::shared_ptr<FingerprintAuthService> FingerprintAuthService::GetInstance()
73 {
74     if (instance_ == nullptr) {
75         std::lock_guard<std::mutex> guard(mutex_);
76         if (instance_ == nullptr) {
77             instance_ = Common::MakeShared<FingerprintAuthService>();
78             if (instance_ == nullptr) {
79                 IAM_LOGE("make share failed");
80             }
81         }
82     }
83     return instance_;
84 }
85 
OnStart()86 void FingerprintAuthService::OnStart()
87 {
88     IAM_LOGI("start");
89     StartDriverManager();
90     IAM_LOGI("success");
91 }
92 
OnStop()93 void FingerprintAuthService::OnStop()
94 {
95     IAM_LOGE("service is persistent, OnStop is not implemented");
96     return;
97 }
98 
StartDriverManager()99 void FingerprintAuthService::StartDriverManager()
100 {
101     IAM_LOGI("start");
102     int32_t ret = UserAuth::IDriverManager::Start(HDI_NAME_2_CONFIG);
103     if (ret != UserAuth::ResultCode::SUCCESS) {
104         IAM_LOGE("start driver manager failed");
105     }
106 }
107 } // namespace FingerprintAuth
108 } // namespace UserIam
109 } // namespace OHOS
110