• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_ROSEN_WINDOW_MANAGER_H
17 #define OHOS_ROSEN_WINDOW_MANAGER_H
18 
19 #include <memory>
20 #include <refbase.h>
21 #include <vector>
22 #include <iremote_object.h>
23 #include "wm_single_instance.h"
24 #include "wm_common.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 struct SystemBarRegionTint {
29     WindowType type_;
30     SystemBarProperty prop_;
31     Rect region_;
SystemBarRegionTintSystemBarRegionTint32     SystemBarRegionTint() : prop_(SystemBarProperty()) {}
SystemBarRegionTintSystemBarRegionTint33     SystemBarRegionTint(WindowType type, SystemBarProperty prop, Rect region)
34         : type_(type), prop_(prop), region_(region) {}
35 };
36 using SystemBarRegionTints = std::vector<SystemBarRegionTint>;
37 
38 class FocusChangeInfo : public Parcelable {
39 public:
40     FocusChangeInfo() = default;
FocusChangeInfo(uint32_t winId,DisplayId displayId,int32_t pid,int32_t uid,WindowType type,const sptr<IRemoteObject> & abilityToken)41     FocusChangeInfo(uint32_t winId, DisplayId displayId, int32_t pid, int32_t uid, WindowType type,
42         const sptr<IRemoteObject>& abilityToken): windowId_(winId), displayId_(displayId), pid_(pid), uid_(uid),
43         windowType_(type),  abilityToken_(abilityToken) {};
44     ~FocusChangeInfo() = default;
45 
46     virtual bool Marshalling(Parcel& parcel) const override;
47     static FocusChangeInfo* Unmarshalling(Parcel& parcel);
48 
49     uint32_t windowId_ = INVALID_WINDOW_ID;
50     DisplayId displayId_ = 0;
51     int32_t pid_ = 0;
52     int32_t uid_ = 0;
53     WindowType windowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
54     sptr<IRemoteObject> abilityToken_;
55 };
56 
57 class IFocusChangedListener : virtual public RefBase {
58 public:
59     virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0;
60 
61     virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0;
62 };
63 
64 class ISystemBarChangedListener : virtual public RefBase {
65 public:
66     virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) = 0;
67 };
68 
69 class WindowVisibilityInfo : public Parcelable {
70 public:
71     WindowVisibilityInfo() = default;
WindowVisibilityInfo(uint32_t winId,int32_t pid,int32_t uid,bool visibility,WindowType winType)72     WindowVisibilityInfo(uint32_t winId, int32_t pid, int32_t uid, bool visibility, WindowType winType)
73         : windowId_(winId), pid_(pid), uid_(uid), isVisible_(visibility), windowType_(winType) {};
74     ~WindowVisibilityInfo() = default;
75 
76     virtual bool Marshalling(Parcel& parcel) const override;
77     static WindowVisibilityInfo* Unmarshalling(Parcel& parcel);
78 
79     uint32_t windowId_ { INVALID_WINDOW_ID };
80     int32_t pid_ { 0 };
81     int32_t uid_ { 0 };
82     bool isVisible_ { false };
83     WindowType windowType_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
84 };
85 
86 class IVisibilityChangedListener : virtual public RefBase {
87 public:
88     virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) = 0;
89 };
90 
91 class AccessibilityWindowInfo : public Parcelable {
92 public:
93     AccessibilityWindowInfo() = default;
94     ~AccessibilityWindowInfo() = default;
95 
96     virtual bool Marshalling(Parcel& parcel) const override;
97     static AccessibilityWindowInfo* Unmarshalling(Parcel& parcel);
98 
99     int32_t wid_;
100     Rect windowRect_;
101     bool focused_ { false };
102     bool isDecorEnable_ { false };
103     DisplayId displayId_;
104     uint32_t layer_;
105     WindowMode mode_;
106     WindowType type_;
107 };
108 
109 class IWindowUpdateListener : virtual public RefBase {
110 public:
111     virtual void OnWindowUpdate(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type) = 0;
112 };
113 
114 class ICameraFloatWindowChangedListener : virtual public RefBase {
115 public:
116     virtual void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) = 0;
117 };
118 
119 class WindowManager {
120 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
121 friend class WindowManagerAgent;
122 friend class WMSDeathRecipient;
123 public:
124     bool RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
125     bool UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
126     bool RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
127     bool UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
128     bool RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
129     bool UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
130     bool RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
131     bool UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
132     bool RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
133     bool UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
134     void MinimizeAllAppWindows(DisplayId displayId);
135     WMError ToggleShownStateForAllAppWindows();
136     WMError SetWindowLayoutMode(WindowLayoutMode mode);
137     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const;
138     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const;
139 
140 private:
141     WindowManager();
142     ~WindowManager() = default;
143     class Impl;
144     std::unique_ptr<Impl> pImpl_;
145 
146     void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
147         DisplayId displayId, bool focused) const;
148     void UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const;
149     void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) const;
150     void NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
151         WindowUpdateType type) const;
152     void UpdateWindowVisibilityInfo(
153         const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
154     void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const;
155     void OnRemoteDied() const;
156 };
157 } // namespace Rosen
158 } // namespace OHOS
159 
160 #endif // OHOS_ROSEN_WINDOW_MANAGER_H
161