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 #ifndef SCREENLOCK_STRONG_AUTH_MANAGER_H 16 #define SCREENLOCK_STRONG_AUTH_MANAGER_H 17 18 #include <mutex> 19 #include <string> 20 #include <singleton.h> 21 #include <sys/time.h> 22 #include "iremote_object.h" 23 #include "refbase.h" 24 #include "screenlock_common.h" 25 #include "visibility.h" 26 #include "time_service_client.h" 27 #include "itimer_info.h" 28 #include "user_auth_event_listener_stub.h" 29 30 namespace OHOS { 31 namespace ScreenLock { 32 class StrongAuthManger : public RefBase { 33 public: 34 SCREENLOCK_API static sptr<StrongAuthManger> GetInstance(); 35 36 StrongAuthManger(); 37 ~StrongAuthManger() override; 38 39 uint64_t GetTimerId(int32_t userId); 40 void StartStrongAuthTimer(int32_t userId); 41 void DestroyStrongAuthTimer(int32_t userId); 42 void DestroyAllStrongAuthTimer(); 43 void ResetStrongAuthTimer(int32_t userId); 44 void SetStrongAuthStat(int32_t userId, int32_t reasonFlag); 45 int32_t GetStrongAuthStat(int32_t userId); 46 void RegistUserAuthSuccessEventListener(); 47 void UnRegistUserAuthSuccessEventListener(); 48 49 public: 50 51 class AuthEventListenerService : public UserIam::UserAuth::AuthEventListenerStub { 52 public: 53 AuthEventListenerService() = default; 54 ~AuthEventListenerService() = default; 55 void OnNotifyAuthSuccessEvent(int32_t userId, UserIam::UserAuth::AuthType authType, int32_t callerType, 56 std::string &bundleName) override; 57 }; 58 59 class authTimer : public MiscServices::ITimerInfo { 60 public: 61 authTimer(); 62 authTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle = false); 63 virtual ~authTimer(); 64 virtual void OnTrigger() override; 65 virtual void SetType(const int &type) override; 66 virtual void SetRepeat(bool repeat) override; 67 virtual void SetInterval(const uint64_t &interval) override; 68 virtual void SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent) override; 69 void SetCallbackInfo(const std::function<void(int32_t)> &callBack); 70 int32_t GetUserId(); 71 void SetUserId(int32_t userId); 72 73 private: 74 int32_t userId_ = 0; 75 std::function<void(int32_t)> callBack_ = nullptr; 76 }; 77 78 private: 79 std::mutex strongAuthTimerMutex; 80 static std::mutex instanceLock_; 81 static sptr<StrongAuthManger> instance_; 82 std::map<int32_t, int32_t> strongAuthStateInfo; 83 std::map<int32_t, uint64_t> strongAuthTimerInfo; 84 sptr<UserIam::UserAuth::AuthEventListenerInterface> listener_; 85 }; 86 } // namespace OHOS 87 } // namespace ScreenLock 88 #endif // SCREENLOCK_STRONG_AUTH_MANAGER_H