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_stub.h"
17
18 #include <sys/socket.h>
19 #include <sys/types.h>
20
21 #include "ipc_skeleton.h"
22 #include "string_ex.h"
23
24 #include "mmi_log.h"
25 #include "multimodalinput_ipc_interface_code.h"
26
27 namespace OHOS {
28 namespace MMI {
29 namespace {
30 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventFilterStub" };
31 } // namespace
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t EventFilterStub::OnRemoteRequest(
34 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
35 {
36 CALL_DEBUG_ENTER;
37 MMI_HILOGD("code:%{public}d", code);
38
39 std::u16string descriptor = data.ReadInterfaceToken();
40 if (descriptor != IEventFilter::GetDescriptor()) {
41 MMI_HILOGE("Get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
42 return ERR_INVALID_STATE;
43 }
44
45 switch (code) {
46 case static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_KEY_EVENT): {
47 return StubHandleKeyEvent(data, reply);
48 }
49 case static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_POINTER_EVENT): {
50 return StubHandlePointerEvent(data, reply);
51 }
52 default: {
53 MMI_HILOGE("Unknown code:%{public}u, go switch default", code);
54 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55 }
56 }
57 }
58
StubHandleKeyEvent(MessageParcel & data,MessageParcel & reply)59 int32_t EventFilterStub::StubHandleKeyEvent(MessageParcel& data, MessageParcel& reply)
60 {
61 CALL_DEBUG_ENTER;
62 std::shared_ptr<KeyEvent> event = KeyEvent::Create();
63 if (event == nullptr) {
64 MMI_HILOGE("The event is nullptr");
65 return RET_ERR;
66 }
67
68 if (!event->ReadFromParcel(data)) {
69 MMI_HILOGE("Read data error");
70 return RET_ERR;
71 }
72
73 bool ret = HandleKeyEvent(event);
74 WRITEBOOL(reply, ret, RET_ERR);
75 return RET_OK;
76 }
77
StubHandlePointerEvent(MessageParcel & data,MessageParcel & reply)78 int32_t EventFilterStub::StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply)
79 {
80 CALL_DEBUG_ENTER;
81 std::shared_ptr<PointerEvent> event = PointerEvent::Create();
82 if (event == nullptr) {
83 MMI_HILOGE("The event is nullptr");
84 return RET_ERR;
85 }
86
87 if (!event->ReadFromParcel(data)) {
88 MMI_HILOGE("Read data error");
89 return RET_ERR;
90 }
91
92 bool ret = HandlePointerEvent(event);
93 WRITEBOOL(reply, ret, RET_ERR);
94 return RET_OK;
95 }
96 } // namespace MMI
97 } // namespace OHOS