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