1 /*
2 * Copyright (C) 2021 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 "keyevent_consumer_stub.h"
17
18 #include "global.h"
19 #include "ipc_object_stub.h"
20 #include "ipc_skeleton.h"
21 #include "ipc_types.h"
22 #include "itypes_util.h"
23 #include "message.h"
24
25 namespace OHOS {
26 namespace MiscServices {
KeyEventConsumerStub(KeyEventCallback callback,std::shared_ptr<MMI::KeyEvent> keyEvent)27 KeyEventConsumerStub::KeyEventConsumerStub(KeyEventCallback callback, std::shared_ptr<MMI::KeyEvent> keyEvent)
28 : callback_(callback), keyEvent_(keyEvent)
29 {
30 }
31
~KeyEventConsumerStub()32 KeyEventConsumerStub::~KeyEventConsumerStub()
33 {
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t KeyEventConsumerStub::OnRemoteRequest(
37 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 IMSA_HILOGD("KeyEventConsumerStub, code: %{public}u, callingPid: %{public}d, callingUid: %{public}d", code,
40 IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
41 auto descriptorToken = data.ReadInterfaceToken();
42 if (descriptorToken != IKeyEventConsumer::GetDescriptor()) {
43 IMSA_HILOGE("KeyEventConsumerStub descriptor error");
44 return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
45 }
46 if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(KEY_EVENT_CONSUMER_CMD_LAST)) {
47 return (this->*HANDLERS.at(code))(data, reply);
48 } else {
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 }
52
OnKeyEventResultOnRemote(MessageParcel & data,MessageParcel & reply)53 int32_t KeyEventConsumerStub::OnKeyEventResultOnRemote(MessageParcel &data, MessageParcel &reply)
54 {
55 IMSA_HILOGI("callingPid/Uid: %{public}d/%{public}d", IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
56 bool isConsumed = false;
57 if (!ITypesUtil::Unmarshal(data, isConsumed)) {
58 IMSA_HILOGE("failed to read message parcel");
59 return ErrorCode::ERROR_EX_PARCELABLE;
60 }
61 if (callback_ != nullptr) {
62 IMSA_HILOGE("callback is not nullptr, isConsumed:%{public}d ", isConsumed);
63 callback_(keyEvent_, isConsumed);
64 }
65 return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
66 }
67
OnKeyEventResult(bool isConsumed)68 int32_t KeyEventConsumerStub::OnKeyEventResult(bool isConsumed)
69 {
70 return ErrorCode::NO_ERROR;
71 }
72 } // namespace MiscServices
73 } // namespace OHOS
74