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 
16 #ifndef PRIVACY_WINDOW_MANAGER_CLIENT_H
17 #define PRIVACY_WINDOW_MANAGER_CLIENT_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "nocopyable.h"
23 #include "privacy_window_manager_death_recipient.h"
24 #include "privacy_window_manager_interface.h"
25 #include "privacy_window_manager_interface_lite.h"
26 #include "privacy_scene_session_manager_lite_proxy.h"
27 #include "privacy_scene_session_manager_proxy.h"
28 #include "privacy_session_manager_proxy.h"
29 #include "privacy_mock_session_manager_proxy.h"
30 
31 namespace OHOS {
32 namespace Security {
33 namespace AccessToken {
34 class PrivacyWindowManagerClient final {
35 public:
36     static PrivacyWindowManagerClient& GetInstance();
37 
38     virtual ~PrivacyWindowManagerClient();
39     int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
40         const sptr<IWindowManagerAgent>& windowManagerAgent);
41     int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
42         const sptr<IWindowManagerAgent>& windowManagerAgent);
43     void AddDeathCallback(void (*callback)());
44     void OnRemoteDiedHandle();
45 
46 private:
47     PrivacyWindowManagerClient();
48     DISALLOW_COPY_AND_MOVE(PrivacyWindowManagerClient);
49     sptr<IWindowManager> GetProxy();
50     sptr<IWindowManagerLite> GetLiteProxy();
51     int32_t RegisterWindowManagerAgentLite(WindowManagerAgentType type,
52         const sptr<IWindowManagerAgent>& windowManagerAgent);
53     int32_t UnregisterWindowManagerAgentLite(WindowManagerAgentType type,
54         const sptr<IWindowManagerAgent>& windowManagerAgent);
55 
56     void InitSceneSessionManagerProxy();
57     void InitSessionManagerServiceProxy();
58     void InitSceneSessionManagerLiteProxy();
59     sptr<ISceneSessionManager> GetSSMProxy();
60     sptr<ISceneSessionManagerLite> GetSSMLiteProxy();
61     void InitWMSProxy();
62     sptr<IWindowManager> GetWMSProxy();
63     void RemoveDeathRecipient();
64 
65     sptr<PrivacyWindowManagerDeathRecipient> serviceDeathObserver_ = nullptr;
66     std::mutex proxyMutex_;
67 
68     std::mutex deathMutex_;
69     void (*deathCallback_)();
70     sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr;
71     sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr;
72     sptr<ISceneSessionManager> sceneSessionManagerProxy_ = nullptr;
73     sptr<ISceneSessionManagerLite> sceneSessionManagerLiteProxy_ = nullptr;
74     sptr<IWindowManager> wmsProxy_ = nullptr;
75 };
76 } // namespace AccessToken
77 } // namespace Security
78 } // namespace OHOS
79 #endif // PRIVACY_WINDOW_MANAGER_CLIENT_H
80 
81