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