• 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 "multimodal_input_connect_stub.h"
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include "error_multimodal.h"
20 #include "mmi_log.h"
21 #include "multimodal_input_connect_define.h"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectStub" };
28 } // namespace
29 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t MultimodalInputConnectStub::OnRemoteRequest(
31     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
32 {
33     MMI_LOGD("enter, code:%{public}d", code);
34 
35     std::u16string descriptor = data.ReadInterfaceToken();
36     if (descriptor != IMultimodalInputConnect::GetDescriptor()) {
37         MMI_LOGE("get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
38         return ERR_INVALID_STATE;
39     }
40 
41     switch (code) {
42         case IMultimodalInputConnect::ALLOC_SOCKET_FD:
43             return StubHandleAllocSocketFd(data, reply);
44         case IMultimodalInputConnect::SET_EVENT_POINTER_FILTER:
45             return StubAddInputEventFilter(data, reply);
46         default:
47             MMI_LOGE("unknown code:%{public}u, go switch defaut", code);
48             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49     }
50 }
51 
StubAddInputEventFilter(MessageParcel & data,MessageParcel & reply)52 int32_t MultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply)
53 {
54     MMI_LOGD("enter");
55     int32_t ret = RET_OK;
56 
57     do {
58         const int32_t uid = IPCSkeleton::GetCallingUid();
59         if (uid != SYSTEM_UID && uid != ROOT_UID) {
60             MMI_LOGE("uid is not root or system");
61             ret = SASERVICE_PERMISSION_FAIL;
62             break;
63         }
64 
65         sptr<IRemoteObject> client = data.ReadRemoteObject();
66         if (client == nullptr) {
67             MMI_LOGE("the mouse client value is nullptr");
68             ret = ERR_INVALID_VALUE;
69             break;
70         }
71 
72         sptr<IEventFilter> filter = iface_cast<IEventFilter>(client);
73         if (filter == nullptr) {
74             MMI_LOGE("filter is nullptr");
75             ret = ERROR_NULL_POINTER;
76             break;
77         }
78 
79         MMI_LOGD("filter iface_cast succeeded");
80 
81         ret = AddInputEventFilter(filter);
82     } while (0);
83 
84     if (!reply.WriteInt32(ret)) {
85         MMI_LOGE("WriteInt32:%{public}d fail", ret);
86         return IPC_STUB_WRITE_PARCEL_ERR;
87     }
88 
89     MMI_LOGD("leave, ret:%{public}d", ret);
90     return RET_OK;
91 }
92 } // namespace MMI
93 } // namespace OHOS