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_SYSTEMAPP_MANAGER_H
17 #define SERVICES_INCLUDE_SCLOCK_SYSTEMAPP_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "iremote_object.h"
23 #include "refbase.h"
24 #include "screenlock_manager_interface.h"
25 #include "screenlock_system_ability_interface.h"
26 #include "visibility.h"
27 
28 namespace OHOS {
29 namespace ScreenLock {
30 class ScreenLockAppDeathRecipient : public IRemoteObject::DeathRecipient {
31 public:
32     explicit ScreenLockAppDeathRecipient();
33     ~ScreenLockAppDeathRecipient() override;
34     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
35 };
36 
37 class ScreenLockAppManager : public RefBase {
38 public:
39     SCREENLOCK_API ScreenLockAppManager();
40     SCREENLOCK_API ~ScreenLockAppManager() override;
41     SCREENLOCK_API static sptr<ScreenLockAppManager> GetInstance();
42     SCREENLOCK_API int32_t OnSystemEvent(const sptr<ScreenLockSystemAbilityInterface> &listener);
43     SCREENLOCK_API int32_t SendScreenLockEvent(const std::string &event, int param);
44     SCREENLOCK_API int32_t IsScreenLockDisabled(int userId, bool &isDisabled);
45     SCREENLOCK_API int32_t SetScreenLockDisabled(bool disable, int userId);
46     SCREENLOCK_API int32_t SetScreenLockAuthState(int authState, int32_t userId, std::string &authToken);
47     SCREENLOCK_API int32_t GetScreenLockAuthState(int userId, int32_t &authState);
48     SCREENLOCK_API int32_t RequestStrongAuth(int reasonFlag, int32_t userId);
49     SCREENLOCK_API int32_t GetStrongAuth(int userId, int32_t &reasonFlag);
50     SCREENLOCK_API void OnRemoteSaDied(const wptr<IRemoteObject> &object);
51     SCREENLOCK_API sptr<ScreenLockManagerInterface> GetProxy();
52 
53 private:
54     static sptr<ScreenLockManagerInterface> GetScreenLockManagerProxy();
55     static std::mutex instanceLock_;
56     static sptr<ScreenLockAppManager> instance_;
57     static sptr<ScreenLockAppDeathRecipient> deathRecipient_;
58     static std::mutex listenerLock_;
59     static sptr<ScreenLockSystemAbilityInterface> systemEventListener_;
60     std::mutex managerProxyLock_;
61     sptr<ScreenLockManagerInterface> screenlockManagerProxy_;
62 };
63 } // namespace ScreenLock
64 } // namespace OHOS
65 #endif // SERVICES_INCLUDE_SCLOCK_SERVICES_MANAGER_H