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 #include "zidl/window_stub.h"
17 #include <vector>
18 #include "ipc_skeleton.h"
19 #include <key_event.h>
20 #include "pointer_event.h"
21 #include "window_manager_hilog.h"
22 #include <transaction/rs_transaction.h>
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowStub"};
28 }
29
OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)30 int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
31 {
32 if (staticDestroyMonitor_.IsDestroyed()) {
33 WLOGFE("Main thread finished, static data has been destroyed");
34 return ERR_INVALID_STATE;
35 }
36 if (data.ReadInterfaceToken() != GetDescriptor()) {
37 WLOGFE("InterfaceToken check failed");
38 return ERR_TRANSACTION_FAILED;
39 }
40 WindowMessage msgId = static_cast<WindowMessage>(code);
41 switch (msgId) {
42 case WindowMessage::TRANS_ID_UPDATE_WINDOW_RECT: {
43 int32_t posX = 0;
44 int32_t posY = 0;
45 uint32_t width = 0;
46 uint32_t height = 0;
47 if (!data.ReadInt32(posX) || !data.ReadInt32(posY) || !data.ReadUint32(width) || !data.ReadUint32(height)) {
48 TLOGE(WmsLogTag::WMS_LAYOUT, "read rect failed");
49 return ERR_INVALID_DATA;
50 }
51 Rect rect { posX, posY, width, height };
52 bool decoStatus = false;
53 if (!data.ReadBool(decoStatus)) {
54 TLOGE(WmsLogTag::WMS_LAYOUT, "read decoStatus failed");
55 return ERR_INVALID_DATA;
56 }
57 uint32_t changeReason = 0;
58 if (!data.ReadUint32(changeReason)) {
59 TLOGE(WmsLogTag::WMS_LAYOUT, "read changeReason failed");
60 return ERR_INVALID_DATA;
61 }
62 if (changeReason < static_cast<uint32_t>(WindowSizeChangeReason::UNDEFINED) ||
63 changeReason > static_cast<uint32_t>(WindowSizeChangeReason::END)) {
64 TLOGE(WmsLogTag::WMS_LAYOUT, "Unknown reason");
65 return ERR_INVALID_DATA;
66 }
67 WindowSizeChangeReason reason = static_cast<WindowSizeChangeReason>(changeReason);
68 bool hasRSTransaction = false;
69 if (!data.ReadBool(hasRSTransaction)) {
70 TLOGE(WmsLogTag::WMS_LAYOUT, "read hasRSTransaction failed");
71 return ERR_INVALID_DATA;
72 }
73 if (hasRSTransaction) {
74 auto rsTransaction = data.ReadParcelable<RSTransaction>();
75 if (!rsTransaction) {
76 WLOGFE("RSTransaction unMarsh failed");
77 return -1;
78 }
79 std::shared_ptr<RSTransaction> transaction(rsTransaction);
80 UpdateWindowRect(rect, decoStatus, reason, transaction);
81 } else {
82 UpdateWindowRect(rect, decoStatus, reason);
83 }
84 break;
85 }
86 case WindowMessage::TRANS_ID_UPDATE_WINDOW_MODE: {
87 uint32_t windowMode = 0;
88 if (!data.ReadUint32(windowMode)) {
89 TLOGE(WmsLogTag::WMS_LAYOUT, "read windowMode failed");
90 return ERR_INVALID_DATA;
91 }
92 WindowMode mode = static_cast<WindowMode>(windowMode);
93 UpdateWindowMode(mode);
94 break;
95 }
96 case WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO: {
97 uint32_t modeSupportInfo = 0;
98 if (!data.ReadUint32(modeSupportInfo)) {
99 TLOGE(WmsLogTag::WMS_LAYOUT, "read modeSupportInfo failed");
100 return ERR_INVALID_DATA;
101 }
102 UpdateWindowModeSupportInfo(modeSupportInfo);
103 break;
104 }
105 case WindowMessage::TRANS_ID_UPDATE_FOCUS_STATUS: {
106 bool focused = data.ReadBool();
107 UpdateFocusStatus(focused);
108 break;
109 }
110 case WindowMessage::TRANS_ID_UPDATE_AVOID_AREA: {
111 sptr<AvoidArea> avoidArea = data.ReadStrongParcelable<AvoidArea>();
112 if (avoidArea == nullptr) {
113 return ERR_INVALID_DATA;
114 }
115 uint32_t type = 0;
116 if (!data.ReadUint32(type) ||
117 type < static_cast<uint32_t>(AvoidAreaType::TYPE_SYSTEM) ||
118 type > static_cast<uint32_t>(AvoidAreaType::TYPE_NAVIGATION_INDICATOR)) {
119 return ERR_INVALID_DATA;
120 }
121 UpdateAvoidArea(avoidArea, static_cast<AvoidAreaType>(type));
122 break;
123 }
124 case WindowMessage::TRANS_ID_UPDATE_WINDOW_STATE: {
125 uint32_t state = 0;
126 if (!data.ReadUint32(state)) {
127 TLOGE(WmsLogTag::DEFAULT, "read state error");
128 return ERR_INVALID_DATA;
129 }
130 UpdateWindowState(static_cast<WindowState>(state));
131 break;
132 }
133 case WindowMessage::TRANS_ID_UPDATE_DRAG_EVENT: {
134 PointInfo point = {0, 0};
135 if (!data.ReadInt32(point.x) || !data.ReadInt32(point.y)) {
136 return ERR_INVALID_DATA;
137 }
138 uint32_t eventType = 0;
139 if (!data.ReadUint32(eventType) || eventType > static_cast<uint32_t>(DragEvent::DRAG_EVENT_END)) {
140 return ERR_INVALID_DATA;
141 }
142 DragEvent event = static_cast<DragEvent>(eventType);
143 UpdateWindowDragInfo(point, event);
144 break;
145 }
146 case WindowMessage::TRANS_ID_UPDATE_DISPLAY_ID: {
147 uint64_t from = 0;
148 uint64_t to = 0;
149 if (!data.ReadUint64(from) || !data.ReadUint64(to)) {
150 TLOGE(WmsLogTag::DEFAULT, "read display id error");
151 return ERR_INVALID_DATA;
152 }
153 UpdateDisplayId(from, to);
154 break;
155 }
156 case WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA: {
157 sptr<OccupiedAreaChangeInfo> info = data.ReadParcelable<OccupiedAreaChangeInfo>();
158 if (info == nullptr) {
159 WLOGFE("OccupiedAreaChangeInfo is null");
160 return ERR_INVALID_DATA;
161 }
162 bool hasRSTransaction = data.ReadBool();
163 if (hasRSTransaction) {
164 auto rsTransaction = data.ReadParcelable<RSTransaction>();
165 if (!rsTransaction) {
166 WLOGFE("RSTransaction unMarsh failed");
167 return ERR_INVALID_DATA;
168 }
169 std::shared_ptr<RSTransaction> transaction(rsTransaction);
170 UpdateOccupiedAreaChangeInfo(info, transaction);
171 } else {
172 UpdateOccupiedAreaChangeInfo(info);
173 }
174 break;
175 }
176 case WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA_AND_RECT: {
177 sptr<OccupiedAreaChangeInfo> info = data.ReadParcelable<OccupiedAreaChangeInfo>();
178 if (info == nullptr) {
179 TLOGE(WmsLogTag::WMS_KEYBOARD, "OccupiedAreaChangeInfo is null");
180 return ERR_INVALID_DATA;
181 }
182 int32_t posX = 0;
183 int32_t posY = 0;
184 uint32_t width = 0;
185 uint32_t height = 0;
186 if (!data.ReadInt32(posX) || !data.ReadInt32(posY) ||
187 !data.ReadUint32(width) || !data.ReadUint32(height)) {
188 TLOGE(WmsLogTag::WMS_KEYBOARD, "Rect value read failed.");
189 return ERR_INVALID_DATA;
190 }
191 struct Rect rect { posX, posY, width, height };
192 bool hasRSTransaction = false;
193 if (!data.ReadBool(hasRSTransaction)) {
194 TLOGE(WmsLogTag::WMS_KEYBOARD, "hasRSTransaction value read failed.");
195 return ERR_INVALID_DATA;
196 }
197 if (hasRSTransaction) {
198 auto rsTransaction = data.ReadParcelable<RSTransaction>();
199 if (!rsTransaction) {
200 TLOGE(WmsLogTag::WMS_KEYBOARD, "RSTransaction unMarsh failed");
201 return ERR_INVALID_DATA;
202 }
203 std::shared_ptr<RSTransaction> transaction(rsTransaction);
204 UpdateOccupiedAreaAndRect(info, rect, transaction);
205 } else {
206 UpdateOccupiedAreaAndRect(info, rect);
207 }
208 break;
209 }
210 case WindowMessage::TRANS_ID_UPDATE_ACTIVE_STATUS: {
211 bool isActive = data.ReadBool();
212 UpdateActiveStatus(isActive);
213 break;
214 }
215 case WindowMessage::TRANS_ID_GET_WINDOW_PROPERTY: {
216 auto property = GetWindowProperty();
217 reply.WriteParcelable(property.GetRefPtr());
218 break;
219 }
220 case WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED: {
221 NotifyTouchOutside();
222 break;
223 }
224 case WindowMessage::TRANS_ID_NOTIFY_SCREEN_SHOT: {
225 NotifyScreenshot();
226 break;
227 }
228 case WindowMessage::TRANS_ID_NOTIFY_DESTROY: {
229 NotifyDestroy();
230 break;
231 }
232 case WindowMessage::TRANS_ID_NOTIFY_FOREGROUND: {
233 NotifyForeground();
234 break;
235 }
236 case WindowMessage::TRANS_ID_NOTIFY_BACKGROUND: {
237 NotifyBackground();
238 break;
239 }
240 case WindowMessage::TRANS_ID_DUMP_INFO: {
241 std::vector<std::string> params;
242 if (!data.ReadStringVector(¶ms)) {
243 WLOGFE("Fail to read params");
244 return ERR_INVALID_DATA;
245 }
246 DumpInfo(params);
247 break;
248 }
249 case WindowMessage::TRANS_ID_NOTIFY_CLIENT_POINT_UP: {
250 auto pointerEvent = MMI::PointerEvent::Create();
251 if (!pointerEvent || !pointerEvent->ReadFromParcel(data)) {
252 WLOGFE("Read Pointer Event failed");
253 return ERR_INVALID_DATA;
254 }
255 NotifyWindowClientPointUp(pointerEvent);
256 break;
257 }
258 case WindowMessage::TRANS_ID_UPDATE_ZOOM_TRANSFORM: {
259 Transform trans;
260 trans.Unmarshalling(data);
261 bool isDisplayZoomOn = data.ReadBool();
262 UpdateZoomTransform(trans, isDisplayZoomOn);
263 break;
264 }
265 case WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE: {
266 uint32_t splitWindowMode = 0;
267 if (!data.ReadUint32(splitWindowMode)) {
268 TLOGE(WmsLogTag::WMS_LAYOUT, "read splitWindowMode failed");
269 return ERR_INVALID_DATA;
270 }
271 RestoreSplitWindowMode(splitWindowMode);
272 break;
273 }
274 case WindowMessage::TRANS_ID_CONSUME_KEY_EVENT: {
275 auto event = MMI::KeyEvent::Create();
276 if (!event || !event->ReadFromParcel(data)) {
277 WLOGFE("Read Pointer Event failed");
278 return ERR_INVALID_DATA;
279 }
280 ConsumeKeyEvent(event);
281 break;
282 }
283 case WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS: {
284 bool interactive = data.ReadBool();
285 NotifyForegroundInteractiveStatus(interactive);
286 break;
287 }
288 default:
289 WLOGFW("unknown transaction code %{public}d", code);
290 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
291 }
292 return ERR_NONE;
293 }
294 } // namespace Rosen
295 } // namespace OHOS
296