1365d9939Sopenharmony_ci/* 2365d9939Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 3365d9939Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4365d9939Sopenharmony_ci * you may not use this file except in compliance with the License. 5365d9939Sopenharmony_ci * You may obtain a copy of the License at 6365d9939Sopenharmony_ci * 7365d9939Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8365d9939Sopenharmony_ci * 9365d9939Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10365d9939Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11365d9939Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12365d9939Sopenharmony_ci * See the License for the specific language governing permissions and 13365d9939Sopenharmony_ci * limitations under the License. 14365d9939Sopenharmony_ci */ 15365d9939Sopenharmony_ci#ifndef SCREENLOCK_STRONG_AUTH_MANAGER_H 16365d9939Sopenharmony_ci#define SCREENLOCK_STRONG_AUTH_MANAGER_H 17365d9939Sopenharmony_ci 18365d9939Sopenharmony_ci#include <mutex> 19365d9939Sopenharmony_ci#include <string> 20365d9939Sopenharmony_ci#include <singleton.h> 21365d9939Sopenharmony_ci#include <sys/time.h> 22365d9939Sopenharmony_ci#include "iremote_object.h" 23365d9939Sopenharmony_ci#include "refbase.h" 24365d9939Sopenharmony_ci#include "screenlock_common.h" 25365d9939Sopenharmony_ci#include "visibility.h" 26365d9939Sopenharmony_ci#include "time_service_client.h" 27365d9939Sopenharmony_ci#include "itimer_info.h" 28365d9939Sopenharmony_ci#include "user_auth_event_listener_stub.h" 29365d9939Sopenharmony_ci 30365d9939Sopenharmony_cinamespace OHOS { 31365d9939Sopenharmony_cinamespace ScreenLock { 32365d9939Sopenharmony_ciclass StrongAuthManger : public RefBase { 33365d9939Sopenharmony_cipublic: 34365d9939Sopenharmony_ci SCREENLOCK_API static sptr<StrongAuthManger> GetInstance(); 35365d9939Sopenharmony_ci 36365d9939Sopenharmony_ci StrongAuthManger(); 37365d9939Sopenharmony_ci ~StrongAuthManger() override; 38365d9939Sopenharmony_ci 39365d9939Sopenharmony_ci uint64_t GetTimerId(int32_t userId); 40365d9939Sopenharmony_ci void StartStrongAuthTimer(int32_t userId); 41365d9939Sopenharmony_ci void DestroyStrongAuthTimer(int32_t userId); 42365d9939Sopenharmony_ci void DestroyAllStrongAuthTimer(); 43365d9939Sopenharmony_ci void ResetStrongAuthTimer(int32_t userId); 44365d9939Sopenharmony_ci void SetStrongAuthStat(int32_t userId, int32_t reasonFlag); 45365d9939Sopenharmony_ci int32_t GetStrongAuthStat(int32_t userId); 46365d9939Sopenharmony_ci void RegistUserAuthSuccessEventListener(); 47365d9939Sopenharmony_ci void UnRegistUserAuthSuccessEventListener(); 48365d9939Sopenharmony_ci 49365d9939Sopenharmony_cipublic: 50365d9939Sopenharmony_ci 51365d9939Sopenharmony_ci class AuthEventListenerService : public UserIam::UserAuth::AuthEventListenerStub { 52365d9939Sopenharmony_ci public: 53365d9939Sopenharmony_ci AuthEventListenerService() = default; 54365d9939Sopenharmony_ci ~AuthEventListenerService() = default; 55365d9939Sopenharmony_ci void OnNotifyAuthSuccessEvent(int32_t userId, UserIam::UserAuth::AuthType authType, int32_t callerType, 56365d9939Sopenharmony_ci std::string &bundleName) override; 57365d9939Sopenharmony_ci }; 58365d9939Sopenharmony_ci 59365d9939Sopenharmony_ci class authTimer : public MiscServices::ITimerInfo { 60365d9939Sopenharmony_ci public: 61365d9939Sopenharmony_ci authTimer(); 62365d9939Sopenharmony_ci authTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle = false); 63365d9939Sopenharmony_ci virtual ~authTimer(); 64365d9939Sopenharmony_ci virtual void OnTrigger() override; 65365d9939Sopenharmony_ci virtual void SetType(const int &type) override; 66365d9939Sopenharmony_ci virtual void SetRepeat(bool repeat) override; 67365d9939Sopenharmony_ci virtual void SetInterval(const uint64_t &interval) override; 68365d9939Sopenharmony_ci virtual void SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent) override; 69365d9939Sopenharmony_ci void SetCallbackInfo(const std::function<void(int32_t)> &callBack); 70365d9939Sopenharmony_ci int32_t GetUserId(); 71365d9939Sopenharmony_ci void SetUserId(int32_t userId); 72365d9939Sopenharmony_ci 73365d9939Sopenharmony_ci private: 74365d9939Sopenharmony_ci int32_t userId_ = 0; 75365d9939Sopenharmony_ci std::function<void(int32_t)> callBack_ = nullptr; 76365d9939Sopenharmony_ci }; 77365d9939Sopenharmony_ci 78365d9939Sopenharmony_ciprivate: 79365d9939Sopenharmony_ci std::mutex strongAuthTimerMutex; 80365d9939Sopenharmony_ci static std::mutex instanceLock_; 81365d9939Sopenharmony_ci static sptr<StrongAuthManger> instance_; 82365d9939Sopenharmony_ci std::map<int32_t, int32_t> strongAuthStateInfo; 83365d9939Sopenharmony_ci std::map<int32_t, uint64_t> strongAuthTimerInfo; 84365d9939Sopenharmony_ci sptr<UserIam::UserAuth::AuthEventListenerInterface> listener_; 85365d9939Sopenharmony_ci}; 86365d9939Sopenharmony_ci} // namespace OHOS 87365d9939Sopenharmony_ci} // namespace ScreenLock 88365d9939Sopenharmony_ci#endif // SCREENLOCK_STRONG_AUTH_MANAGER_H