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
16 #include "session/container/include/zidl/window_event_channel_stub.h"
17 #include "session/container/include/zidl/window_event_ipc_interface_code.h"
18
19 #include <axis_event.h>
20 #include <ipc_types.h>
21 #include <key_event.h>
22 #include <pointer_event.h>
23
24 #include "accessibility_element_info.h"
25 #include "parcel/accessibility_element_info_parcel.h"
26 #include "window_manager_hilog.h"
27
28 namespace OHOS::Rosen {
29 namespace {
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStub"};
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int WindowEventChannelStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
34 MessageParcel& reply, MessageOption& option)
35 {
36 WLOGFD("Window event channel on remote request!, code: %{public}u", code);
37 if (data.ReadInterfaceToken() != GetDescriptor()) {
38 WLOGFE("Failed to check interface token!");
39 return ERR_TRANSACTION_FAILED;
40 }
41
42 switch (code) {
43 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_KEY_EVENT):
44 return HandleTransferKeyEvent(data, reply);
45 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_KEY_EVENT_ASYNC):
46 return HandleTransferKeyEventAsync(data, reply);
47 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_POINTER_EVENT):
48 return HandleTransferPointerEvent(data, reply);
49 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_FOCUS_ACTIVE_EVENT):
50 return HandleTransferFocusActiveEvent(data, reply);
51 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_FOCUS_STATE_EVENT):
52 return HandleTransferFocusStateEvent(data, reply);
53 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_BACKPRESSED_EVENT):
54 return HandleTransferBackpressedEvent(data, reply);
55 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_ACCESSIBILITY_HOVER_EVENT):
56 return HandleTransferAccessibilityHoverEvent(data, reply);
57 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_ACCESSIBILITY_CHILD_TREE_REGISTER):
58 return HandleTransferAccessibilityChildTreeRegister(data, reply);
59 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_ACCESSIBILITY_CHILD_TREE_UNREGISTER):
60 return HandleTransferAccessibilityChildTreeUnregister(data, reply);
61 case static_cast<uint32_t>(WindowEventInterfaceCode::TRANS_ID_TRANSFER_ACCESSIBILITY_DUMP_CHILD_INFO):
62 return HandleTransferAccessibilityDumpChildInfo(data, reply);
63 default:
64 WLOGFE("Failed to find function handler!");
65 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67 }
68
HandleTransferBackpressedEvent(MessageParcel & data,MessageParcel & reply)69 int WindowEventChannelStub::HandleTransferBackpressedEvent(MessageParcel& data, MessageParcel& reply)
70 {
71 WLOGFD("TransferBackpressedEvent!");
72 bool isConsumed = false;
73 WSError errCode = TransferBackpressedEventForConsumed(isConsumed);
74
75 reply.WriteBool(isConsumed);
76 reply.WriteInt32(static_cast<int32_t>(errCode));
77 return ERR_NONE;
78 }
79
HandleTransferKeyEvent(MessageParcel & data,MessageParcel & reply)80 int WindowEventChannelStub::HandleTransferKeyEvent(MessageParcel& data, MessageParcel& reply)
81 {
82 WLOGFD("TransferKeyEvent!");
83 auto keyEvent = MMI::KeyEvent::Create();
84 if (keyEvent == nullptr) {
85 WLOGFE("Failed to create key event!");
86 return ERR_INVALID_DATA;
87 }
88 if (!keyEvent->ReadFromParcel(data)) {
89 WLOGFE("Read Key Event failed");
90 return ERR_INVALID_DATA;
91 }
92 bool isPreImeEvent = data.ReadBool();
93 bool isConsumed = false;
94 WSError errCode = TransferKeyEventForConsumed(keyEvent, isConsumed, isPreImeEvent);
95
96 reply.WriteBool(isConsumed);
97 reply.WriteInt32(static_cast<int32_t>(errCode));
98 return ERR_NONE;
99 }
100
HandleTransferKeyEventAsync(MessageParcel & data,MessageParcel & reply)101 int WindowEventChannelStub::HandleTransferKeyEventAsync(MessageParcel& data, MessageParcel& reply)
102 {
103 auto keyEvent = MMI::KeyEvent::Create();
104 if (keyEvent == nullptr) {
105 TLOGE(WmsLogTag::WMS_EVENT, "Failed to create key event!");
106 return ERR_INVALID_DATA;
107 }
108 if (!keyEvent->ReadFromParcel(data)) {
109 TLOGE(WmsLogTag::WMS_EVENT, "Read Key Event failed");
110 return ERR_INVALID_DATA;
111 }
112 bool isPreImeEvent = false;
113 if (!data.ReadBool(isPreImeEvent)) {
114 TLOGE(WmsLogTag::WMS_EVENT, "Read Key Event failed");
115 return ERR_INVALID_DATA;
116 }
117 sptr<IRemoteObject> listener = data.ReadRemoteObject();
118 if (listener == nullptr) {
119 TLOGE(WmsLogTag::WMS_EVENT, "ReadRemoteObject failed");
120 return ERR_INVALID_DATA;
121 }
122
123 WSError errCode = TransferKeyEventForConsumedAsync(keyEvent, isPreImeEvent, listener);
124 reply.WriteUint32(static_cast<uint32_t>(errCode));
125 return ERR_NONE;
126 }
127
HandleTransferPointerEvent(MessageParcel & data,MessageParcel & reply)128 int WindowEventChannelStub::HandleTransferPointerEvent(MessageParcel& data, MessageParcel& reply)
129 {
130 WLOGFD("TransferPointerEvent!");
131 auto pointerEvent = MMI::PointerEvent::Create();
132 if (pointerEvent == nullptr) {
133 WLOGFE("Failed to create pointer event!");
134 return ERR_INVALID_DATA;
135 }
136 if (!pointerEvent->ReadFromParcel(data)) {
137 WLOGFE("Read Pointer Event failed");
138 return ERR_INVALID_DATA;
139 }
140 WSError errCode = TransferPointerEvent(pointerEvent);
141 reply.WriteInt32(static_cast<int32_t>(errCode));
142 return ERR_NONE;
143 }
144
HandleTransferFocusActiveEvent(MessageParcel & data,MessageParcel & reply)145 int WindowEventChannelStub::HandleTransferFocusActiveEvent(MessageParcel& data, MessageParcel& reply)
146 {
147 bool isFocusActive = data.ReadBool();
148 WSError errCode = TransferFocusActiveEvent(isFocusActive);
149 reply.WriteInt32(static_cast<int32_t>(errCode));
150 return ERR_NONE;
151 }
152
HandleTransferFocusStateEvent(MessageParcel & data,MessageParcel & reply)153 int WindowEventChannelStub::HandleTransferFocusStateEvent(MessageParcel& data, MessageParcel& reply)
154 {
155 bool focusState = data.ReadBool();
156 WSError errCode = TransferFocusState(focusState);
157 reply.WriteInt32(static_cast<int32_t>(errCode));
158 return ERR_NONE;
159 }
160
HandleTransferAccessibilityHoverEvent(MessageParcel & data,MessageParcel & reply)161 int WindowEventChannelStub::HandleTransferAccessibilityHoverEvent(MessageParcel& data, MessageParcel& reply)
162 {
163 float pointX = 0;
164 float pointY = 0;
165 int32_t sourceType = 0;
166 int32_t eventType = 0;
167 int64_t timeMs = 0;
168 if (!data.ReadFloat(pointX) ||
169 !data.ReadFloat(pointY) ||
170 !data.ReadInt32(sourceType) ||
171 !data.ReadInt32(eventType) ||
172 !data.ReadInt64(timeMs)) {
173 WLOGFE("Read HandleTransferAccessibilityHoverEvent data failed!");
174 return ERR_INVALID_DATA;
175 };
176 WSError errCode = TransferAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs);
177 reply.WriteInt32(static_cast<int32_t>(errCode));
178 return ERR_NONE;
179 }
180
HandleTransferAccessibilityChildTreeRegister(MessageParcel & data,MessageParcel & reply)181 int32_t WindowEventChannelStub::HandleTransferAccessibilityChildTreeRegister(MessageParcel& data, MessageParcel& reply)
182 {
183 uint32_t windowId = 0;
184 int32_t treeId = -1;
185 int64_t accessibilityId = -1;
186 if (!data.ReadUint32(windowId) ||
187 !data.ReadInt32(treeId) ||
188 !data.ReadInt64(accessibilityId)) {
189 TLOGE(WmsLogTag::WMS_UIEXT, "Read HandleTransferAccessibilityChildTreeRegister data failed!");
190 return ERR_INVALID_DATA;
191 }
192 WSError errCode = TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
193 reply.WriteInt32(static_cast<int32_t>(errCode));
194 return ERR_NONE;
195 }
196
HandleTransferAccessibilityChildTreeUnregister(MessageParcel & data,MessageParcel & reply)197 int32_t WindowEventChannelStub::HandleTransferAccessibilityChildTreeUnregister(
198 MessageParcel& data, MessageParcel& reply)
199 {
200 WSError errCode = TransferAccessibilityChildTreeUnregister();
201 reply.WriteInt32(static_cast<int32_t>(errCode));
202 return ERR_NONE;
203 }
204
HandleTransferAccessibilityDumpChildInfo(MessageParcel & data,MessageParcel & reply)205 int32_t WindowEventChannelStub::HandleTransferAccessibilityDumpChildInfo(MessageParcel& data, MessageParcel& reply)
206 {
207 std::vector<std::string> params;
208 if (!data.ReadStringVector(¶ms)) {
209 TLOGE(WmsLogTag::WMS_UIEXT, "Read HandleTransferAccessibilityDumpChildInfo data failed!");
210 return ERR_INVALID_VALUE;
211 }
212 std::vector<std::string> info;
213 TransferAccessibilityDumpChildInfo(params, info);
214 reply.WriteStringVector(info);
215 return ERR_NONE;
216 }
217 }
218