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_proxy.h"
17
18 #include <axis_event.h>
19 #include <ipc_types.h>
20 #include <key_event.h>
21 #include <message_option.h>
22 #include <message_parcel.h>
23 #include <pointer_event.h>
24
25 #include "window_manager_hilog.h"
26
27 namespace OHOS::Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxy"};
30 }
31
TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)32 WSError WindowEventChannelProxy::TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option(MessageOption::TF_ASYNC);
37 if (!data.WriteInterfaceToken(GetDescriptor())) {
38 WLOGFE("WriteInterfaceToken failed");
39 return WSError::WS_ERROR_IPC_FAILED;
40 }
41
42 if (!keyEvent->WriteToParcel(data)) {
43 WLOGFE("Failed to write key event");
44 return WSError::WS_ERROR_IPC_FAILED;
45 }
46
47 if (Remote()->SendRequest(static_cast<uint32_t>(WindowEventChannelMessage::TRANS_ID_TRANSFER_KEY_EVENT),
48 data, reply, option) != ERR_NONE) {
49 WLOGFE("SendRequest failed");
50 return WSError::WS_ERROR_IPC_FAILED;
51 }
52 reply.ReadBool();
53 int32_t ret = reply.ReadInt32();
54 return static_cast<WSError>(ret);
55 }
56
TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)57 WSError WindowEventChannelProxy::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
58 {
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option(MessageOption::TF_ASYNC);
62 if (!data.WriteInterfaceToken(GetDescriptor())) {
63 WLOGFE("WriteInterfaceToken failed");
64 return WSError::WS_ERROR_IPC_FAILED;
65 }
66
67 if (!pointerEvent->WriteToParcel(data)) {
68 WLOGFE("Failed to write pointer event");
69 return WSError::WS_ERROR_IPC_FAILED;
70 }
71
72 if (Remote()->SendRequest(static_cast<uint32_t>(WindowEventChannelMessage::TRANS_ID_TRANSFER_POINTER_EVENT),
73 data, reply, option) != ERR_NONE) {
74 WLOGFE("SendRequest failed");
75 return WSError::WS_ERROR_IPC_FAILED;
76 }
77 int32_t ret = reply.ReadInt32();
78 return static_cast<WSError>(ret);
79 }
80
TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent> & keyEvent,bool & isConsumed)81 WSError WindowEventChannelProxy::TransferKeyEventForConsumed(
82 const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed)
83 {
84 MessageParcel data;
85 MessageParcel reply;
86 MessageOption option(MessageOption::TF_SYNC);
87 if (!data.WriteInterfaceToken(GetDescriptor())) {
88 WLOGFE("WriteInterfaceToken failed");
89 return WSError::WS_ERROR_IPC_FAILED;
90 }
91
92 if (!keyEvent->WriteToParcel(data)) {
93 WLOGFE("Failed to write key event");
94 return WSError::WS_ERROR_IPC_FAILED;
95 }
96
97 if (Remote()->SendRequest(static_cast<uint32_t>(WindowEventChannelMessage::TRANS_ID_TRANSFER_KEY_EVENT),
98 data, reply, option) != ERR_NONE) {
99 WLOGFE("SendRequest failed");
100 return WSError::WS_ERROR_IPC_FAILED;
101 }
102 isConsumed = reply.ReadBool();
103 int32_t ret = reply.ReadInt32();
104 return static_cast<WSError>(ret);
105 }
106
TransferFocusActiveEvent(bool isFocusActive)107 WSError WindowEventChannelProxy::TransferFocusActiveEvent(bool isFocusActive)
108 {
109 MessageParcel data;
110 MessageParcel reply;
111 MessageOption option(MessageOption::TF_ASYNC);
112 if (!data.WriteInterfaceToken(GetDescriptor())) {
113 WLOGFE("WriteInterfaceToken failed");
114 return WSError::WS_ERROR_IPC_FAILED;
115 }
116 if (!data.WriteBool(isFocusActive)) {
117 WLOGFE("Write bool failed");
118 return WSError::WS_ERROR_IPC_FAILED;
119 }
120 if (Remote()->SendRequest(static_cast<uint32_t>(WindowEventChannelMessage::TRANS_ID_TRANSFER_FOCUS_ACTIVE_EVENT),
121 data, reply, option) != ERR_NONE) {
122 WLOGFE("SendRequest failed");
123 return WSError::WS_ERROR_IPC_FAILED;
124 }
125 int32_t ret = reply.ReadInt32();
126 return static_cast<WSError>(ret);
127 }
128
TransferFocusState(bool focusState)129 WSError WindowEventChannelProxy::TransferFocusState(bool focusState)
130 {
131 MessageParcel data;
132 MessageParcel reply;
133 MessageOption option(MessageOption::TF_ASYNC);
134 if (!data.WriteInterfaceToken(GetDescriptor())) {
135 WLOGFE("WriteInterfaceToken failed");
136 return WSError::WS_ERROR_IPC_FAILED;
137 }
138 if (!data.WriteBool(focusState)) {
139 WLOGFE("Write focusState failed");
140 return WSError::WS_ERROR_IPC_FAILED;
141 }
142 if (Remote()->SendRequest(static_cast<uint32_t>(WindowEventChannelMessage::TRANS_ID_TRANSFER_FOCUS_STATE_EVENT),
143 data, reply, option) != ERR_NONE) {
144 WLOGFE("SendRequest failed");
145 return WSError::WS_ERROR_IPC_FAILED;
146 }
147 int32_t ret = reply.ReadInt32();
148 return static_cast<WSError>(ret);
149 }
150 } // namespace OHOS::Rosen
151