• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SECURITY_COMPONENT_MOCK_WINDOW_MANAGER_H
16 #define SECURITY_COMPONENT_MOCK_WINDOW_MANAGER_H
17 #include <cstdint>
18 #include <iremote_object.h>
19 #include <refbase.h>
20 #include <vector>
21 
22 namespace OHOS {
23 namespace Rosen {
24 using DisplayId = uint64_t;
25 using WindowMode = uint32_t;
26 using WindowType = uint32_t;
27 enum class WMError : int32_t {
28     WM_OK = 0,
29 };
30 
31 struct Rect {
32     int32_t posX_;
33     int32_t posY_;
34     uint32_t width_;
35     uint32_t height_;
36 };
37 
38 class AccessibilityWindowInfo : public Parcelable {
39 public:
40     AccessibilityWindowInfo() = default;
41     ~AccessibilityWindowInfo() = default;
Marshalling(Parcel & parcel)42     virtual bool Marshalling(Parcel& parcel) const override
43     {
44         return true;
45     };
46 
47     int32_t wid_;
48     int32_t innerWid_;
49     int32_t uiNodeId_;
50     Rect windowRect_;
51     bool focused_ { false };
52     bool isDecorEnable_ { false };
53     DisplayId displayId_;
54     uint32_t layer_;
55     WindowMode mode_;
56     WindowType type_;
57     float scaleVal_;
58     bool isCompatScaleMode_ { false };
59 };
60 
61 class UnreliableWindowInfo : public Parcelable {
62 public:
63     UnreliableWindowInfo() = default;
64     ~UnreliableWindowInfo() = default;
Marshalling(Parcel & parcel)65     virtual bool Marshalling(Parcel& parcel) const override
66     {
67         return true;
68     };
69     int32_t windowId_ { 0 };
70     Rect windowRect_;
71     uint32_t zOrder_ { 0 };
72     float floatingScale_ { 1.0f };
73     float scaleX_ { 1.0f };
74     float scaleY_ { 1.0f };
75 };
76 
77 #ifndef FUZZ_ENABLE
78 class WindowManager {
79 public:
GetInstance()80     static WindowManager& GetInstance()
81     {
82         static WindowManager instance;
83         return instance;
84     };
85 
GetAccessibilityWindowInfo(std::vector<sptr<Rosen::AccessibilityWindowInfo>> & list)86     WMError GetAccessibilityWindowInfo(std::vector<sptr<Rosen::AccessibilityWindowInfo>>& list)
87     {
88         list = list_;
89         return result_;
90     };
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)91     WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) const
92     {
93         infos = info_;
94         return result_;
95     }
96 
WindowManager()97     WindowManager() {};
98 
SetDefaultSecCompScene()99     void SetDefaultSecCompScene()
100     {
101         result_ = OHOS::Rosen::WMError::WM_OK;
102         std::vector<sptr<AccessibilityWindowInfo>> list;
103         sptr<AccessibilityWindowInfo> compWin = new AccessibilityWindowInfo();
104         compWin->wid_ = 0;
105         compWin->layer_ = 0;
106         compWin->scaleVal_ = 0.0;
107         list.emplace_back(compWin);
108         list_ = list;
109 
110         std::vector<sptr<UnreliableWindowInfo>> info;
111         sptr<UnreliableWindowInfo> unreliableWinInfo = new UnreliableWindowInfo();
112         unreliableWinInfo->windowId_ = 0;
113         unreliableWinInfo->zOrder_ = 0;
114         unreliableWinInfo->floatingScale_ = 0.0;
115         info.emplace_back(unreliableWinInfo);
116         info_ = info;
117     };
118 
119     std::vector<sptr<Rosen::AccessibilityWindowInfo>> list_;
120     std::vector<sptr<Rosen::UnreliableWindowInfo>> info_;
121     WMError result_ = OHOS::Rosen::WMError::WM_OK;
122 private:
~WindowManager()123     ~WindowManager() {};
124 };
125 #else
126 class WindowManager {
127 public:
GetInstance()128     static WindowManager& GetInstance()
129     {
130         static WindowManager instance;
131         return instance;
132     };
133 
GetAccessibilityWindowInfo(std::vector<sptr<Rosen::AccessibilityWindowInfo>> & list)134     WMError GetAccessibilityWindowInfo(std::vector<sptr<Rosen::AccessibilityWindowInfo>>& list)
135     {
136         sptr<AccessibilityWindowInfo> compWin = sptr<AccessibilityWindowInfo>::MakeSptr();
137         compWin->wid_ = 0;
138         compWin->layer_ = 0;
139         compWin->scaleVal_ = 1.0;
140         list.emplace_back(compWin);
141         return OHOS::Rosen::WMError::WM_OK;
142     };
143 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)144     WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) const
145     {
146         sptr<UnreliableWindowInfo> compoLayer = sptr<UnreliableWindowInfo>::MakeSptr();
147         compoLayer->windowId_ = 0;
148         compoLayer->zOrder_ = 0;
149         compoLayer->floatingScale_ = 1.0;
150         infos.emplace_back(compoLayer);
151         sptr<UnreliableWindowInfo> coverLayer = sptr<UnreliableWindowInfo>::MakeSptr();
152         // window is 128*128, cover window is 96*96
153         coverLayer->windowRect_ = Rect{0, 0, 96, 96};
154         coverLayer->windowId_ = 1;
155         coverLayer->zOrder_ = 1;
156         coverLayer->floatingScale_ = 1.0;
157         infos.emplace_back(coverLayer);
158         return OHOS::Rosen::WMError::WM_OK;
159     }
160 
WindowManager()161     WindowManager() {};
162 private:
~WindowManager()163     ~WindowManager() {};
164 };
165 #endif // FUZZ_ENABLE
166 } // namespace Rosen
167 } // namespace OHOS
168 #endif // SECURITY_COMPONENT_MOCK_WINDOW_MANAGER_H
169