1 /* 2 * Copyright (c) 2022 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 PIN_AUTH_MANAGER_H 17 #define PIN_AUTH_MANAGER_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "iremote_object.h" 25 #include "refbase.h" 26 #include "singleton.h" 27 28 #include "inputer_get_data.h" 29 #include "i_inputer_data_impl.h" 30 31 namespace OHOS { 32 namespace UserIam { 33 namespace PinAuth { 34 class PinAuthManager : public DelayedRefSingleton<PinAuthManager> { 35 DECLARE_DELAYED_REF_SINGLETON(PinAuthManager); 36 public: 37 bool RegisterInputer(uint32_t tokenId, const sptr<InputerGetData> &inputer); 38 void UnRegisterInputer(uint32_t tokenId); 39 sptr<InputerGetData> GetInputerLock(uint32_t tokenId); 40 41 private: 42 std::unordered_map<uint32_t, sptr<InputerGetData>> pinAuthInputerMap_; 43 std::unordered_map<uint32_t, sptr<IRemoteObject::DeathRecipient>> pinAuthDeathMap_; 44 std::mutex mutex_; 45 class ResPinauthInputerDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { 46 public: 47 explicit ResPinauthInputerDeathRecipient(uint32_t tokenId); 48 ~ResPinauthInputerDeathRecipient() override = default; 49 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 50 51 private: 52 uint32_t tokenId_; 53 }; 54 }; 55 } // namespace PinAuth 56 } // namespace UserIam 57 } // namespace OHOS 58 59 #endif // PIN_AUTH_MANAGER_H 60