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 "event_filter_proxy.h"
17
18 #include "message_option.h"
19 #include "string_ex.h"
20
21 #include "mmi_log.h"
22 #include "multimodalinput_ipc_interface_code.h"
23
24 #undef MMI_LOG_DOMAIN
25 #define MMI_LOG_DOMAIN MMI_LOG_HANDLER
26 #undef MMI_LOG_TAG
27 #define MMI_LOG_TAG "EventFilterProxy"
28
29 namespace OHOS {
30 namespace MMI {
EventFilterProxy(const sptr<IRemoteObject> & impl)31 EventFilterProxy::EventFilterProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IEventFilter>(impl)
32 {
33 MMI_HILOGI("EventFilterProxy()");
34 }
35
HandleKeyEvent(const std::shared_ptr<KeyEvent> event)36 bool EventFilterProxy::HandleKeyEvent(const std::shared_ptr<KeyEvent> event)
37 {
38 CALL_DEBUG_ENTER;
39 CHKPF(event);
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option;
43 if (!data.WriteInterfaceToken(EventFilterProxy::GetDescriptor())) {
44 MMI_HILOGE("Failed to write descriptor");
45 return false;
46 }
47
48 if (!event->WriteToParcel(data)) {
49 MMI_HILOGE("Failed to write event to req");
50 return false;
51 }
52
53 sptr<IRemoteObject> remote = Remote();
54 CHKPF(remote);
55 const uint32_t code = static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_KEY_EVENT);
56 int32_t ret = remote->SendRequest(code, data, reply, option);
57 if (ret != NO_ERROR) {
58 MMI_HILOGE("Send request failed, ret:%{public}d", ret);
59 return false;
60 }
61
62 bool result = false;
63 READBOOL(reply, result);
64 return result;
65 }
66
HandlePointerEvent(const std::shared_ptr<PointerEvent> event)67 bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr<PointerEvent> event)
68 {
69 CALL_DEBUG_ENTER;
70 CHKPF(event);
71 MessageParcel data;
72 MessageParcel reply;
73 MessageOption option;
74 if (!data.WriteInterfaceToken(EventFilterProxy::GetDescriptor())) {
75 MMI_HILOGE("Failed to write descriptor");
76 return false;
77 }
78
79 if (!event->WriteToParcel(data)) {
80 MMI_HILOGE("Failed to write event to req");
81 return false;
82 }
83
84 sptr<IRemoteObject> remote = Remote();
85 CHKPF(remote);
86 const uint32_t code = static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_POINTER_EVENT);
87 int32_t ret = remote->SendRequest(code, data, reply, option);
88 if (ret != NO_ERROR) {
89 MMI_HILOGE("Send request failed, ret:%{public}d", ret);
90 return false;
91 }
92
93 bool result = false;
94 READBOOL(reply, result);
95 return result;
96 }
97 } // namespace MMI
98 } // namespace OHOS
99