1 /*
2  * Copyright (c) 2022-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 
16 #include "i_inputer_data_impl.h"
17 
18 #include "iam_logger.h"
19 #include "pin_auth_all_in_one_hdi.h"
20 #include "pin_auth_collector_hdi.h"
21 
22 #define LOG_TAG "PIN_AUTH_SA"
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace PinAuth {
27 using namespace OHOS::UserIam::UserAuth;
IInputerDataImpl(uint64_t scheduleId,std::shared_ptr<PinAuthAllInOneHdi> hdi)28 IInputerDataImpl::IInputerDataImpl(uint64_t scheduleId, std::shared_ptr<PinAuthAllInOneHdi> hdi)
29     : scheduleId_(scheduleId), allInOneHdi_(hdi), collectorHdi_(nullptr) {}
30 
IInputerDataImpl(uint64_t scheduleId,std::shared_ptr<PinAuthCollectorHdi> hdi)31 IInputerDataImpl::IInputerDataImpl(uint64_t scheduleId, std::shared_ptr<PinAuthCollectorHdi> hdi)
32     : scheduleId_(scheduleId), allInOneHdi_(nullptr), collectorHdi_(hdi) {}
33 
~IInputerDataImpl()34 IInputerDataImpl::~IInputerDataImpl() {}
35 
OnSetData(int32_t authSubType,std::vector<uint8_t> data,int32_t errorCode)36 void IInputerDataImpl::OnSetData(int32_t authSubType, std::vector<uint8_t> data, int32_t errorCode)
37 {
38     IAM_LOGI("start");
39     std::lock_guard<std::mutex> guard(mutex_);
40     if (allInOneHdi_ != nullptr) {
41         IAM_LOGI("all in one set data");
42         if (allInOneHdi_->OnSetData(scheduleId_, authSubType, data, errorCode) != SUCCESS) {
43             IAM_LOGE("event has canceled");
44             return;
45         }
46     } else if (collectorHdi_ != nullptr) {
47         IAM_LOGI("collector set data");
48         if (collectorHdi_->OnSetData(scheduleId_, authSubType, data, errorCode) != SUCCESS) {
49             IAM_LOGE("event has canceled");
50             return;
51         }
52     } else {
53         IAM_LOGE("no hdi exist");
54     }
55     IAM_LOGI("end");
56 }
57 } // namespace PinAuth
58 } // namespace UserIam
59 } // namespace OHOS
60