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