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 struct Rect rect { data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() };
44 bool decoStatus = data.ReadBool();
45 WindowSizeChangeReason reason = static_cast<WindowSizeChangeReason>(data.ReadUint32());
46 bool hasRSTransaction = data.ReadBool();
47 if (hasRSTransaction) {
48 auto rsTransaction = data.ReadParcelable<RSTransaction>();
49 if (!rsTransaction) {
50 WLOGFE("RSTransaction unMarsh failed");
51 return -1;
52 }
53 std::shared_ptr<RSTransaction> transaction(rsTransaction);
54 UpdateWindowRect(rect, decoStatus, reason, transaction);
55 } else {
56 UpdateWindowRect(rect, decoStatus, reason);
57 }
58 break;
59 }
60 case WindowMessage::TRANS_ID_UPDATE_WINDOW_MODE: {
61 WindowMode mode = static_cast<WindowMode>(data.ReadUint32());
62 UpdateWindowMode(mode);
63 break;
64 }
65 case WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO: {
66 uint32_t windowModeSupportType = 0;
67 if (!data.ReadUint32(windowModeSupportType)) {
68 TLOGE(WmsLogTag::WMS_LAYOUT, "read windowModeSupportType failed");
69 return ERR_INVALID_DATA;
70 }
71 UpdateWindowModeSupportType(windowModeSupportType);
72 break;
73 }
74 case WindowMessage::TRANS_ID_UPDATE_FOCUS_STATUS: {
75 bool focused = data.ReadBool();
76 UpdateFocusStatus(focused);
77 break;
78 }
79 case WindowMessage::TRANS_ID_UPDATE_AVOID_AREA: {
80 sptr<AvoidArea> avoidArea = data.ReadStrongParcelable<AvoidArea>();
81 if (avoidArea == nullptr) {
82 return ERR_INVALID_DATA;
83 }
84 uint32_t type;
85 if (!data.ReadUint32(type)) {
86 return ERR_INVALID_DATA;
87 }
88 UpdateAvoidArea(avoidArea, static_cast<AvoidAreaType>(type));
89 break;
90 }
91 case WindowMessage::TRANS_ID_UPDATE_WINDOW_STATE: {
92 UpdateWindowState(static_cast<WindowState>(data.ReadUint32()));
93 break;
94 }
95 case WindowMessage::TRANS_ID_UPDATE_DRAG_EVENT: {
96 PointInfo point;
97 point.x = data.ReadInt32();
98 point.y = data.ReadInt32();
99 DragEvent event = static_cast<DragEvent>(data.ReadUint32());
100 UpdateWindowDragInfo(point, event);
101 break;
102 }
103 case WindowMessage::TRANS_ID_UPDATE_DISPLAY_ID: {
104 UpdateDisplayId(data.ReadUint64(), data.ReadUint64());
105 break;
106 }
107 case WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA: {
108 sptr<OccupiedAreaChangeInfo> info = data.ReadParcelable<OccupiedAreaChangeInfo>();
109 if (info == nullptr) {
110 WLOGFE("OccupiedAreaChangeInfo is null");
111 return ERR_INVALID_DATA;
112 }
113 bool hasRSTransaction = data.ReadBool();
114 if (hasRSTransaction) {
115 auto rsTransaction = data.ReadParcelable<RSTransaction>();
116 if (!rsTransaction) {
117 WLOGFE("RSTransaction unMarsh failed");
118 return ERR_INVALID_DATA;
119 }
120 std::shared_ptr<RSTransaction> transaction(rsTransaction);
121 UpdateOccupiedAreaChangeInfo(info, transaction);
122 } else {
123 UpdateOccupiedAreaChangeInfo(info);
124 }
125
126 break;
127 }
128 case WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA_AND_RECT: {
129 sptr<OccupiedAreaChangeInfo> info = data.ReadParcelable<OccupiedAreaChangeInfo>();
130 if (info == nullptr) {
131 WLOGFE("OccupiedAreaChangeInfo is null");
132 return ERR_INVALID_DATA;
133 }
134 struct Rect rect { data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() };
135 bool hasRSTransaction = data.ReadBool();
136 if (hasRSTransaction) {
137 auto rsTransaction = data.ReadParcelable<RSTransaction>();
138 if (!rsTransaction) {
139 WLOGFE("RSTransaction unMarsh failed");
140 return ERR_INVALID_DATA;
141 }
142 std::shared_ptr<RSTransaction> transaction(rsTransaction);
143 UpdateOccupiedAreaAndRect(info, rect, transaction);
144 } else {
145 UpdateOccupiedAreaAndRect(info, rect);
146 }
147
148 break;
149 }
150 case WindowMessage::TRANS_ID_UPDATE_ACTIVE_STATUS: {
151 bool isActive = data.ReadBool();
152 UpdateActiveStatus(isActive);
153 break;
154 }
155 case WindowMessage::TRANS_ID_GET_WINDOW_PROPERTY: {
156 auto property = GetWindowProperty();
157 reply.WriteParcelable(property.GetRefPtr());
158 break;
159 }
160 case WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED: {
161 NotifyTouchOutside();
162 break;
163 }
164 case WindowMessage::TRANS_ID_NOTIFY_SCREEN_SHOT: {
165 NotifyScreenshot();
166 break;
167 }
168 case WindowMessage::TRANS_ID_NOTIFY_DESTROY: {
169 NotifyDestroy();
170 break;
171 }
172 case WindowMessage::TRANS_ID_NOTIFY_FOREGROUND: {
173 NotifyForeground();
174 break;
175 }
176 case WindowMessage::TRANS_ID_NOTIFY_BACKGROUND: {
177 NotifyBackground();
178 break;
179 }
180 case WindowMessage::TRANS_ID_DUMP_INFO: {
181 std::vector<std::string> params;
182 if (!data.ReadStringVector(¶ms)) {
183 WLOGFE("Fail to read params");
184 return ERR_INVALID_DATA;
185 }
186 DumpInfo(params);
187 break;
188 }
189 case WindowMessage::TRANS_ID_NOTIFY_CLIENT_POINT_UP: {
190 auto pointerEvent = MMI::PointerEvent::Create();
191 if (!pointerEvent || !pointerEvent->ReadFromParcel(data)) {
192 WLOGFE("Read Pointer Event failed");
193 return ERR_INVALID_DATA;
194 }
195 NotifyWindowClientPointUp(pointerEvent);
196 break;
197 }
198 case WindowMessage::TRANS_ID_UPDATE_ZOOM_TRANSFORM: {
199 Transform trans;
200 trans.Unmarshalling(data);
201 bool isDisplayZoomOn = data.ReadBool();
202 UpdateZoomTransform(trans, isDisplayZoomOn);
203 break;
204 }
205 case WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE: {
206 RestoreSplitWindowMode(data.ReadUint32());
207 break;
208 }
209 case WindowMessage::TRANS_ID_CONSUME_KEY_EVENT: {
210 auto event = MMI::KeyEvent::Create();
211 if (!event || !event->ReadFromParcel(data)) {
212 WLOGFE("Read Pointer Event failed");
213 return ERR_INVALID_DATA;
214 }
215 ConsumeKeyEvent(event);
216 break;
217 }
218 case WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS: {
219 bool interactive = data.ReadBool();
220 NotifyForegroundInteractiveStatus(interactive);
221 break;
222 }
223 default:
224 WLOGFW("unknown transaction code %{public}d", code);
225 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
226 }
227 return ERR_NONE;
228 }
229 } // namespace Rosen
230 } // namespace OHOS
231