1 /* 2 * Copyright (c) 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 #ifndef OHOS_HDI_PIN_AUTH_COLLECTOR_IMPL_H 17 #define OHOS_HDI_PIN_AUTH_COLLECTOR_IMPL_H 18 19 #include <mutex> 20 #include <vector> 21 22 #include "nocopyable.h" 23 #include "thread_pool.h" 24 25 #include "defines.h" 26 #include "pin_auth_hdi.h" 27 #include "pin_auth.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace PinAuth { 32 class CollectorImpl : public HdiICollector, public NoCopyable { 33 public: 34 explicit CollectorImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi); 35 ~CollectorImpl() override; 36 37 int32_t GetExecutorInfo(HdiExecutorInfo &executorInfo) override; 38 int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 39 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 40 int32_t Cancel(uint64_t scheduleId) override; 41 int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg) override; 42 int32_t SetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data, 43 int32_t resultCode) override; 44 int32_t Collect(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, 45 const sptr<HdiIExecutorCallback> &callbackObj) override; 46 47 private: 48 void ClearPinData(const std::vector<uint8_t> &pinData); 49 bool IsCurrentSchedule(uint64_t scheduleId); 50 void CancelCurrentCollect(int32_t errorCode = CANCELED); 51 52 std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_; 53 OHOS::ThreadPool threadPool_; 54 std::optional<uint64_t> scheduleId_; 55 sptr<HdiIExecutorCallback> callback_; 56 }; 57 } // PinAuth 58 } // HDI 59 } // OHOS 60 61 #endif // OHOS_HDI_PIN_AUTH_COLLECTOR_IMPL_H 62