1 /*
2 * Copyright (c) 2024 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 "anco_channel_stub.h"
17
18 #include "string_ex.h"
19
20 #include "define_multimodal.h"
21
22 #undef MMI_LOG_DOMAIN
23 #define MMI_LOG_DOMAIN MMI_LOG_HANDLER
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "AncoChannelStub"
26
27 namespace OHOS {
28 namespace MMI {
29
AncoChannelStub()30 AncoChannelStub::AncoChannelStub()
31 {
32 handlers_ = {
33 { AncoRequestId::SYNC_POINTER_EVENT, &AncoChannelStub::StubSyncPointerEvent },
34 { AncoRequestId::SYNC_KEY_EVENT, &AncoChannelStub::StubSyncKeyEvent },
35 { AncoRequestId::UPDATE_WINDOW_INFO, &AncoChannelStub::StubUpdateWindowInfo },
36 { AncoRequestId::SYNC_KNUCKLE_STATUS, &AncoChannelStub::StubSyncKnuckleStatus },
37 };
38 }
39
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int32_t AncoChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
41 MessageParcel &reply, MessageOption &option)
42 {
43 CALL_INFO_TRACE;
44 std::u16string descriptor = data.ReadInterfaceToken();
45 if (descriptor != IAncoChannel::GetDescriptor()) {
46 MMI_HILOGE("Got unexpected descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
47 return ERR_INVALID_STATE;
48 }
49 int32_t ret = RET_ERR;
50 auto cbIter = handlers_.find(static_cast<AncoRequestId>(code));
51
52 if (cbIter == handlers_.end()) {
53 MMI_HILOGE("Unexpected request:%{public}u", code);
54 } else {
55 ret = (this->*(cbIter->second))(data, reply);
56 }
57 WRITEINT32(reply, ret);
58 return ret;
59 }
60
StubSyncPointerEvent(MessageParcel & data,MessageParcel & reply)61 int32_t AncoChannelStub::StubSyncPointerEvent(MessageParcel &data, MessageParcel &reply)
62 {
63 CALL_INFO_TRACE;
64 auto pointerEvent = PointerEvent::Create();
65 CHKPR(pointerEvent, RET_ERR);
66 if (!pointerEvent->ReadFromParcel(data)) {
67 MMI_HILOGE("Failed to unmarshal PointerEvent");
68 return RET_ERR;
69 }
70 return SyncInputEvent(pointerEvent);
71 }
72
StubSyncKeyEvent(MessageParcel & data,MessageParcel & reply)73 int32_t AncoChannelStub::StubSyncKeyEvent(MessageParcel &data, MessageParcel &reply)
74 {
75 auto keyEvent = KeyEvent::Create();
76 CHKPR(keyEvent, RET_ERR);
77 if (!keyEvent->ReadFromParcel(data)) {
78 MMI_HILOGE("Failed to unmarshal KeyEvent");
79 return RET_ERR;
80 }
81 return SyncInputEvent(keyEvent);
82 }
83
StubUpdateWindowInfo(MessageParcel & data,MessageParcel & reply)84 int32_t AncoChannelStub::StubUpdateWindowInfo(MessageParcel &data, MessageParcel &reply)
85 {
86 auto windows = std::make_shared<AncoWindows>();
87 if (!AncoWindows::Unmarshalling(data, *windows)) {
88 MMI_HILOGE("Failed to unmarshal anco windows");
89 return RET_ERR;
90 }
91 return UpdateWindowInfo(windows);
92 }
93
StubSyncKnuckleStatus(MessageParcel & data,MessageParcel & reply)94 int32_t AncoChannelStub::StubSyncKnuckleStatus(MessageParcel &data, MessageParcel &reply)
95 {
96 bool touchType = false;
97 if (!data.ReadBool(touchType)) {
98 MMI_HILOGE("Failed to read status.");
99 return RET_ERR;
100 }
101 return SyncKnuckleStatus(touchType);
102 }
103 } // namespace MMI
104 } // namespace OHOS
105