• 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 <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 
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventFilterStub" };
30 }  // namespace
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t EventFilterStub::OnRemoteRequest(
33     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
34 {
35     CALL_DEBUG_ENTER;
36     MMI_HILOGD("code:%{public}d", code);
37 
38     std::u16string descriptor = data.ReadInterfaceToken();
39     if (descriptor != IEventFilter::GetDescriptor()) {
40         MMI_HILOGE("Get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
41         return ERR_INVALID_STATE;
42     }
43 
44     switch (code) {
45         case static_cast<uint32_t>(IEventFilter::OPERATOR_TYPE::HANDLE_POINTER_EVENT): {
46             return StubHandlePointerEvent(data, reply);
47         }
48         default: {
49             MMI_HILOGE("Unknown code:%{public}u, go switch defaut", code);
50             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51         }
52     }
53 }
54 
StubHandlePointerEvent(MessageParcel & data,MessageParcel & reply)55 int32_t EventFilterStub::StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply)
56 {
57     CALL_DEBUG_ENTER;
58     std::shared_ptr<PointerEvent> event = PointerEvent::Create();
59     if (event == nullptr) {
60         MMI_HILOGE("The event is nullptr");
61         return RET_ERR;
62     }
63 
64     if (!event->ReadFromParcel(data)) {
65         MMI_HILOGE("Read data error");
66         return RET_ERR;
67     }
68 
69     bool ret = HandlePointerEvent(event);
70     WRITEBOOL(reply, ret, RET_ERR);
71     return RET_OK;
72 }
73 } // namespace MMI
74 } // namespace OHOS