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_manager_stub.h"
17 #include <ipc_skeleton.h>
18 #include <key_event.h>
19 #include <rs_iwindow_animation_controller.h>
20 #include <rs_window_animation_target.h>
21
22 #include "marshalling_helper.h"
23 #include "memory_guard.h"
24 #include "window_manager_hilog.h"
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerStub"};
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
33 MessageOption &option)
34 {
35 MemoryGuard cacheGuard;
36 if (data.ReadInterfaceToken() != GetDescriptor()) {
37 WLOGFE("InterfaceToken check failed");
38 return -1;
39 }
40 auto msgId = static_cast<WindowManagerMessage>(code);
41 switch (msgId) {
42 case WindowManagerMessage::TRANS_ID_CREATE_WINDOW: {
43 sptr<IRemoteObject> windowObject = data.ReadRemoteObject();
44 sptr<IWindow> windowProxy = iface_cast<IWindow>(windowObject);
45 sptr<WindowProperty> windowProperty = data.ReadStrongParcelable<WindowProperty>();
46 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
47 uint32_t windowId;
48 sptr<IRemoteObject> token = nullptr;
49 if (windowProperty && windowProperty->GetTokenState()) {
50 token = data.ReadRemoteObject();
51 } else {
52 WLOGI("accept token is nullptr");
53 }
54 WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId, token);
55 reply.WriteUint32(windowId);
56 reply.WriteInt32(static_cast<int32_t>(errCode));
57 if (windowProperty) {
58 reply.WriteUint32(windowProperty->GetWindowFlags());
59 reply.WriteUint32(windowProperty->GetApiCompatibleVersion());
60 }
61 break;
62 }
63 case WindowManagerMessage::TRANS_ID_ADD_WINDOW: {
64 sptr<WindowProperty> windowProperty = data.ReadStrongParcelable<WindowProperty>();
65 WMError errCode = AddWindow(windowProperty);
66 reply.WriteInt32(static_cast<int32_t>(errCode));
67 break;
68 }
69 case WindowManagerMessage::TRANS_ID_REMOVE_WINDOW: {
70 uint32_t windowId = data.ReadUint32();
71 bool isFromInnerkits = data.ReadBool();
72 WMError errCode = RemoveWindow(windowId, isFromInnerkits);
73 reply.WriteInt32(static_cast<int32_t>(errCode));
74 break;
75 }
76 case WindowManagerMessage::TRANS_ID_DESTROY_WINDOW: {
77 uint32_t windowId = data.ReadUint32();
78 WMError errCode = DestroyWindow(windowId);
79 reply.WriteInt32(static_cast<int32_t>(errCode));
80 break;
81 }
82 case WindowManagerMessage::TRANS_ID_REQUEST_FOCUS: {
83 uint32_t windowId = data.ReadUint32();
84 WMError errCode = RequestFocus(windowId);
85 reply.WriteInt32(static_cast<int32_t>(errCode));
86 break;
87 }
88 case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: {
89 uint32_t windowId = data.ReadUint32();
90 auto avoidAreaType = static_cast<AvoidAreaType>(data.ReadUint32());
91 AvoidArea avoidArea = GetAvoidAreaByType(windowId, avoidAreaType);
92 reply.WriteParcelable(&avoidArea);
93
94 break;
95 }
96 case WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: {
97 auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
98 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
99 sptr<IWindowManagerAgent> windowManagerAgentProxy =
100 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
101 WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy);
102 reply.WriteInt32(static_cast<int32_t>(errCode));
103 break;
104 }
105 case WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: {
106 auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
107 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
108 sptr<IWindowManagerAgent> windowManagerAgentProxy =
109 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
110 WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
111 reply.WriteInt32(static_cast<int32_t>(errCode));
112 break;
113 }
114 case WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG: {
115 uint32_t windowId = data.ReadUint32();
116 sptr<WindowProperty> windowProperty = data.ReadStrongParcelable<WindowProperty>();
117 sptr<MoveDragProperty> moveDragProperty = data.ReadStrongParcelable<MoveDragProperty>();
118 NotifyServerReadyToMoveOrDrag(windowId, windowProperty, moveDragProperty);
119 break;
120 }
121 case WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN: {
122 uint32_t windowId = data.ReadUint32();
123 bool isPointDown = data.ReadBool();
124 ProcessPointDown(windowId, isPointDown);
125 break;
126 }
127 case WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP: {
128 uint32_t windowId = data.ReadUint32();
129 ProcessPointUp(windowId);
130 break;
131 }
132 case WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID: {
133 uint32_t mainWinId = data.ReadUint32();
134 uint32_t topWinId;
135 WMError errCode = GetTopWindowId(mainWinId, topWinId);
136 reply.WriteUint32(topWinId);
137 reply.WriteInt32(static_cast<int32_t>(errCode));
138 break;
139 }
140 case WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS: {
141 WMError errCode = MinimizeAllAppWindows(data.ReadUint64());
142 reply.WriteInt32(static_cast<int32_t>(errCode));
143 break;
144 }
145 case WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS: {
146 WMError errCode = ToggleShownStateForAllAppWindows();
147 reply.WriteInt32(static_cast<int32_t>(errCode));
148 break;
149 }
150 case WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE: {
151 auto mode = static_cast<WindowLayoutMode>(data.ReadUint32());
152 WMError errCode = SetWindowLayoutMode(mode);
153 reply.WriteInt32(static_cast<int32_t>(errCode));
154 break;
155 }
156 case WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY: {
157 auto action = static_cast<PropertyChangeAction>(data.ReadUint32());
158 sptr<WindowProperty> windowProperty = new WindowProperty();
159 windowProperty->Read(data, action);
160 WMError errCode = UpdateProperty(windowProperty, action);
161 reply.WriteInt32(static_cast<int32_t>(errCode));
162 break;
163 }
164 case WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID: {
165 std::vector<sptr<AccessibilityWindowInfo>> infos;
166 WMError errCode = GetAccessibilityWindowInfo(infos);
167 if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
168 WLOGFE("Write accessibility window infos failed");
169 return -1;
170 }
171 reply.WriteInt32(static_cast<int32_t>(errCode));
172 break;
173 }
174 case WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID: {
175 std::vector<sptr<WindowVisibilityInfo>> infos;
176 WMError errCode = GetVisibilityWindowInfo(infos);
177 if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
178 WLOGFE("Write visibility window infos failed");
179 return -1;
180 }
181 reply.WriteInt32(static_cast<int32_t>(errCode));
182 break;
183 }
184 case WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER: {
185 sptr<IRemoteObject> controllerObject = data.ReadRemoteObject();
186 sptr<RSIWindowAnimationController> controller = iface_cast<RSIWindowAnimationController>(controllerObject);
187 WMError errCode = SetWindowAnimationController(controller);
188 reply.WriteInt32(static_cast<int32_t>(errCode));
189 break;
190 }
191 case WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG: {
192 SystemConfig config;
193 WMError errCode = GetSystemConfig(config);
194 reply.WriteParcelable(&config);
195 reply.WriteInt32(static_cast<int32_t>(errCode));
196 break;
197 }
198 case WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION: {
199 sptr<WindowTransitionInfo> from = data.ReadParcelable<WindowTransitionInfo>();
200 sptr<WindowTransitionInfo> to = data.ReadParcelable<WindowTransitionInfo>();
201 bool isFromClient = data.ReadBool();
202 WMError errCode = NotifyWindowTransition(from, to, isFromClient);
203 reply.WriteInt32(static_cast<int32_t>(errCode));
204 break;
205 }
206 case WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE: {
207 DisplayId displayId = data.ReadUint64();
208 ModeChangeHotZones hotZones = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
209 WMError errCode = GetModeChangeHotZones(displayId, hotZones);
210 reply.WriteInt32(static_cast<int32_t>(errCode));
211
212 reply.WriteInt32(hotZones.fullscreen_.posX_);
213 reply.WriteInt32(hotZones.fullscreen_.posY_);
214 reply.WriteUint32(hotZones.fullscreen_.width_);
215 reply.WriteUint32(hotZones.fullscreen_.height_);
216
217 reply.WriteInt32(hotZones.primary_.posX_);
218 reply.WriteInt32(hotZones.primary_.posY_);
219 reply.WriteUint32(hotZones.primary_.width_);
220 reply.WriteUint32(hotZones.primary_.height_);
221
222 reply.WriteInt32(hotZones.secondary_.posX_);
223 reply.WriteInt32(hotZones.secondary_.posY_);
224 reply.WriteUint32(hotZones.secondary_.width_);
225 reply.WriteUint32(hotZones.secondary_.height_);
226 break;
227 }
228 case WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK: {
229 std::vector<uint32_t> windowIds;
230 data.ReadUInt32Vector(&windowIds);
231 bool isAnimated = data.ReadBool();
232 sptr<RSIWindowAnimationFinishedCallback> finishedCallback = nullptr;
233 MinimizeWindowsByLauncher(windowIds, isAnimated, finishedCallback);
234 if (finishedCallback == nullptr) {
235 if (!reply.WriteBool(false)) {
236 WLOGFE("finishedCallback is nullptr and failed to write!");
237 return 0;
238 }
239 } else {
240 if (!reply.WriteBool(true) || !reply.WriteRemoteObject(finishedCallback->AsObject())) {
241 WLOGFE("finishedCallback is not nullptr and failed to write!");
242 return 0;
243 }
244 }
245 break;
246 }
247 case WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER: {
248 uint32_t windowId = data.ReadUint32();
249 bool haveAvoidAreaListener = data.ReadBool();
250 WMError errCode = UpdateAvoidAreaListener(windowId, haveAvoidAreaListener);
251 reply.WriteInt32(static_cast<int32_t>(errCode));
252 break;
253 }
254 case WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE: {
255 uint32_t windowId = data.ReadUint32();
256 bool isAdd = data.ReadBool();
257 WMError errCode = UpdateRsTree(windowId, isAdd);
258 reply.WriteInt32(static_cast<int32_t>(errCode));
259 break;
260 }
261 case WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET: {
262 uint32_t windowId = data.ReadUint32();
263 sptr<IRemoteObject> targetToken = data.ReadRemoteObject();
264 WMError errCode = BindDialogTarget(windowId, targetToken);
265 reply.WriteInt32(static_cast<int32_t>(errCode));
266 break;
267 }
268 case WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE : {
269 int32_t x = data.ReadInt32();
270 int32_t y = data.ReadInt32();
271 float scale = data.ReadFloat();
272 SetAnchorAndScale(x, y, scale);
273 break;
274 }
275 case WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET: {
276 int32_t deltaX = data.ReadInt32();
277 int32_t deltaY = data.ReadInt32();
278 SetAnchorOffset(deltaX, deltaY);
279 break;
280 }
281 case WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM: {
282 OffWindowZoom();
283 break;
284 }
285 case WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER: {
286 uint32_t windowId = data.ReadUint32();
287 WmErrorCode errCode = RaiseToAppTop(windowId);
288 reply.WriteInt32(static_cast<int32_t>(errCode));
289 break;
290 }
291 case WindowManagerMessage::TRANS_ID_GET_SNAPSHOT: {
292 uint32_t windowId = data.ReadUint32();
293 std::shared_ptr<Media::PixelMap> pixelMap = GetSnapshot(windowId);
294 reply.WriteParcelable(pixelMap.get());
295 break;
296 }
297 case WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED: {
298 bool enable = data.ReadBool();
299 WMError errCode = SetGestureNavigaionEnabled(enable);
300 reply.WriteInt32(static_cast<int32_t>(errCode));
301 break;
302 }
303 case WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY: {
304 uint32_t windowId = data.ReadUint32();
305 WindowGravity gravity = static_cast<WindowGravity>(data.ReadUint32());
306 uint32_t percent = data.ReadUint32();
307 WMError errCode = SetWindowGravity(windowId, gravity, percent);
308 reply.WriteInt32(static_cast<int32_t>(errCode));
309 break;
310 }
311 case WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT: {
312 uint32_t windowId = data.ReadUint32();
313 std::shared_ptr<MMI::KeyEvent> event = MMI::KeyEvent::Create();
314 event->ReadFromParcel(data);
315 DispatchKeyEvent(windowId, event);
316 break;
317 }
318 case WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT: {
319 std::vector<std::string> info;
320 data.ReadStringVector(&info);
321 NotifyDumpInfoResult(info);
322 break;
323 }
324 case WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS: {
325 std::vector<uint32_t> missionIds;
326 data.ReadUInt32Vector(&missionIds);
327 std::vector<sptr<RSWindowAnimationTarget>> targets;
328 WMError errCode = GetWindowAnimationTargets(missionIds, targets);
329 if (!MarshallingHelper::MarshallingVectorParcelableObj<RSWindowAnimationTarget>(reply, targets)) {
330 WLOGFE("Write window animation targets failed");
331 return -1;
332 }
333 reply.WriteInt32(static_cast<int32_t>(errCode));
334 break;
335 }
336 case WindowManagerMessage::TRANS_ID_SET_MAXIMIZE_MODE: {
337 MaximizeMode maximizeMode = static_cast<MaximizeMode>(data.ReadUint32());
338 SetMaximizeMode(maximizeMode);
339 break;
340 }
341 case WindowManagerMessage::TRANS_ID_GET_MAXIMIZE_MODE: {
342 MaximizeMode maximizeMode = GetMaximizeMode();
343 reply.WriteInt32(static_cast<int32_t>(maximizeMode));
344 break;
345 }
346 case WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO: {
347 FocusChangeInfo focusInfo;
348 GetFocusWindowInfo(focusInfo);
349 reply.WriteParcelable(&focusInfo);
350 break;
351 }
352 default:
353 WLOGFW("unknown transaction code %{public}d", code);
354 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
355 }
356 return 0;
357 }
358 } // namespace Rosen
359 } // namespace OHOS
360