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 SERVICES_INCLUDE_SCLOCK_MANAGER_H 17 #define SERVICES_INCLUDE_SCLOCK_MANAGER_H 18 19 #include <mutex> 20 #include <string> 21 #include <map> 22 23 #include "iremote_object.h" 24 #include "refbase.h" 25 #include "screenlock_callback_interface.h" 26 #include "screenlock_common.h" 27 #include "screenlock_manager_interface.h" 28 #include "screenlock_system_ability_interface.h" 29 #include "screenlock_inner_listener.h" 30 #include "screenlock_inner_listener_wapper.h" 31 #include "visibility.h" 32 33 namespace OHOS { 34 namespace ScreenLock { 35 class ScreenLockManager : public RefBase { 36 public: 37 SCREENLOCK_API static sptr<ScreenLockManager> GetInstance(); 38 /** 39 * Lock the screen. 40 * 41 * @param userId Indicates the user ID. 42 * @return Returns E_SCREENLOCK_OK if success; otherwise failed. 43 */ 44 SCREENLOCK_API int32_t Lock(int32_t userId); 45 46 /** 47 * Check whether the screen is currently locked. 48 * 49 * @param isLocked Indicates the screen lock state. 50 * @return Returns E_SCREENLOCK_OK if success; otherwise failed. 51 */ 52 SCREENLOCK_API int32_t IsLocked(bool &isLocked); 53 54 SCREENLOCK_API bool IsScreenLocked(); 55 SCREENLOCK_API bool GetSecure(); 56 SCREENLOCK_API int32_t Unlock(Action action, const sptr<ScreenLockCallbackInterface> &listener); 57 int32_t Lock(const sptr<ScreenLockCallbackInterface> &listener); 58 SCREENLOCK_API int32_t OnSystemEvent(const sptr<ScreenLockSystemAbilityInterface> &listener); 59 SCREENLOCK_API int32_t SendScreenLockEvent(const std::string &event, int param); 60 SCREENLOCK_API int32_t IsScreenLockDisabled(int userId, bool &isDisabled); 61 SCREENLOCK_API int32_t SetScreenLockDisabled(bool disable, int userId); 62 SCREENLOCK_API int32_t SetScreenLockAuthState(int authState, int32_t userId, std::string &authToken); 63 SCREENLOCK_API int32_t GetScreenLockAuthState(int userId, int32_t &authState); 64 SCREENLOCK_API int32_t RequestStrongAuth(int reasonFlag, int32_t userId); 65 SCREENLOCK_API int32_t GetStrongAuth(int userId, int32_t &reasonFlag); 66 SCREENLOCK_API int32_t IsDeviceLocked(int userId, bool &isDeviceLocked); 67 SCREENLOCK_API int32_t RegisterStrongAuthListener(const sptr<StrongAuthListener> &listener); 68 SCREENLOCK_API int32_t UnRegisterStrongAuthListener(const sptr<StrongAuthListener> &listener); 69 SCREENLOCK_API int32_t IsLockedWithUserId(int userId, bool &isLocked); 70 SCREENLOCK_API int32_t RegisterDeviceLockedListener(const sptr<DeviceLockedListener> &listener); 71 SCREENLOCK_API int32_t UnRegisterDeviceLockedListener(const sptr<DeviceLockedListener> &listener); 72 private: 73 class ScreenLockSaDeathRecipient : public IRemoteObject::DeathRecipient { 74 public: ScreenLockSaDeathRecipient()75 explicit ScreenLockSaDeathRecipient(){}; 76 ~ScreenLockSaDeathRecipient() = default; OnRemoteDied(const wptr<IRemoteObject> & object)77 void OnRemoteDied(const wptr<IRemoteObject> &object) override 78 { 79 ScreenLockManager::GetInstance()->OnRemoteSaDied(object); 80 } 81 }; 82 83 ScreenLockManager(); 84 ~ScreenLockManager() override; 85 void RemoveDeathRecipient(); 86 void OnRemoteSaDied(const wptr<IRemoteObject> &object); 87 sptr<ScreenLockManagerInterface> GetProxy(); 88 sptr<ScreenLockManagerInterface> GetScreenLockManagerProxy(); 89 static std::mutex instanceLock_; 90 static sptr<ScreenLockManager> instance_; 91 static std::mutex listenerLock_; 92 static sptr<ScreenLockSystemAbilityInterface> systemEventListener_; 93 sptr<ScreenLockSaDeathRecipient> deathRecipient_; 94 std::mutex managerProxyLock_; 95 sptr<ScreenLockManagerInterface> screenlockManagerProxy_; 96 std::mutex ListenerWrapperMapMutex; 97 std::map<sptr<InnerListener>, sptr<InnerListenerWrapper>> InnerListenerWrapperMap; 98 int32_t RegisterListenerInner(const ListenType listenType, const sptr<InnerListener>& listener); 99 int32_t UnRegisterListenerInner(const ListenType listenType, const sptr<InnerListener>& listener); 100 }; 101 } // namespace ScreenLock 102 } // namespace OHOS 103 #endif // SERVICES_INCLUDE_SCLOCK_SERVICES_MANAGER_H