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