1 /*
2  * Copyright (c) 2023 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 OHOS_WINDOW_ADAPTER_LITE_H
17 #define OHOS_WINDOW_ADAPTER_LITE_H
18 
19 #include <shared_mutex>
20 #include <refbase.h>
21 #include <zidl/window_manager_agent_interface.h>
22 
23 #include "singleton_delegator.h"
24 #include "window_property.h"
25 #include "wm_single_instance.h"
26 #include "zidl/window_manager_lite_interface.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 class WMSDeathRecipient : public IRemoteObject::DeathRecipient {
31 public:
32     virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
33 };
34 
35 class WindowAdapterLite {
36 WM_DECLARE_SINGLE_INSTANCE(WindowAdapterLite);
37 public:
38     using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>;
39     virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo);
40     virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
41         const sptr<IWindowManagerAgent>& windowManagerAgent);
42     virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
43         const sptr<IWindowManagerAgent>& windowManagerAgent);
44     virtual WMError CheckWindowId(int32_t windowId, int32_t& pid);
45     virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos);
46     virtual void ClearWindowAdapter();
47     virtual WMError GetWindowModeType(WindowModeType& windowModeType);
48     virtual WMError RaiseWindowToTop(int32_t persistentId);
49     virtual WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo);
50     WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc);
51     virtual WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos);
52     virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds);
53     virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
54     virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType);
55     virtual WMError TerminateSessionByPersistentId(int32_t persistentId);
56     virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos);
57     virtual WMError CloseTargetFloatWindow(const std::string& bundleName);
58     virtual WMError CloseTargetPiPWindow(const std::string& bundleName);
59     virtual WMError GetCurrentPiPWindowInfo(std::string& bundleName);
60 
61 private:
62     static inline SingletonDelegator<WindowAdapterLite> delegator;
63     bool InitSSMProxy();
64     void OnUserSwitch();
65     void ReregisterWindowManagerLiteAgent();
66 
67     sptr<IWindowManagerLite> GetWindowManagerServiceProxy() const;
68 
69     mutable std::mutex mutex_;
70     sptr<IWindowManagerLite> windowManagerServiceProxy_ = nullptr;
71     sptr<WMSDeathRecipient> wmsDeath_ = nullptr;
72     bool isProxyValid_ = false;
73     bool isRegisteredUserSwitchListener_ = false;
74     // above guarded by mutex_
75 
76     std::mutex windowManagerLiteAgentMapMutex_;
77     std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerLiteAgentMap_;
78 };
79 } // namespace Rosen
80 } // namespace OHOS
81 #endif // OHOS_WINDOW_ADAPTER_H
82