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_proxy.h"
17
18 #include "message_option.h"
19
20 #include "mmi_log.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 "AncoChannelProxy"
26
27 namespace OHOS {
28 namespace MMI {
29
AncoChannelProxy(const sptr<IRemoteObject> & remoteObj)30 AncoChannelProxy::AncoChannelProxy(const sptr<IRemoteObject> &remoteObj)
31 : IRemoteProxy<IAncoChannel>(remoteObj)
32 {}
33
SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)34 int32_t AncoChannelProxy::SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
35 {
36 CALL_INFO_TRACE;
37 CHKPR(pointerEvent, RET_ERR);
38 MessageParcel data;
39 if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
40 MMI_HILOGE("Failed to write descriptor");
41 return RET_ERR;
42 }
43 if (!pointerEvent->WriteToParcel(data)) {
44 MMI_HILOGE("Failed to marshal PointerEvent");
45 return RET_ERR;
46 }
47 MessageParcel reply;
48 MessageOption option;
49 sptr<IRemoteObject> remote = Remote();
50 CHKPR(remote, RET_ERR);
51 int32_t ret = remote->SendRequest(
52 static_cast<uint32_t>(AncoRequestId::SYNC_POINTER_EVENT), data, reply, option);
53 if (ret != RET_OK) {
54 MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
55 return ret;
56 }
57 READINT32(reply, ret, RET_ERR);
58 return ret;
59 }
60
SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)61 int32_t AncoChannelProxy::SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)
62 {
63 CALL_INFO_TRACE;
64 CHKPR(keyEvent, RET_ERR);
65 MessageParcel data;
66 if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
67 MMI_HILOGE("Failed to write descriptor");
68 return RET_ERR;
69 }
70 if (!keyEvent->WriteToParcel(data)) {
71 MMI_HILOGE("Failed to marshal KeyEvent");
72 return RET_ERR;
73 }
74 MessageParcel reply;
75 MessageOption option;
76 sptr<IRemoteObject> remote = Remote();
77 CHKPR(remote, RET_ERR);
78 int32_t ret = remote->SendRequest(
79 static_cast<uint32_t>(AncoRequestId::SYNC_KEY_EVENT), data, reply, option);
80 if (ret != RET_OK) {
81 MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
82 return ret;
83 }
84 READINT32(reply, ret, RET_ERR);
85 return ret;
86 }
87
UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)88 int32_t AncoChannelProxy::UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)
89 {
90 CALL_INFO_TRACE;
91 CHKPR(windows, RET_ERR);
92 MessageParcel data;
93 if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
94 MMI_HILOGE("Failed to write descriptor");
95 return RET_ERR;
96 }
97 if (!AncoWindows::Marshalling(*windows, data)) {
98 MMI_HILOGE("Failed to marshal windows");
99 return RET_ERR;
100 }
101 MessageParcel reply;
102 MessageOption option;
103 sptr<IRemoteObject> remote = Remote();
104 CHKPR(remote, RET_ERR);
105 int32_t ret = remote->SendRequest(
106 static_cast<uint32_t>(AncoRequestId::UPDATE_WINDOW_INFO), data, reply, option);
107 if (ret != RET_OK) {
108 MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
109 return ret;
110 }
111 READINT32(reply, ret, RET_ERR);
112 return ret;
113 }
114
SyncKnuckleStatus(bool isKnuckleEnable)115 int32_t AncoChannelProxy::SyncKnuckleStatus(bool isKnuckleEnable)
116 {
117 CALL_INFO_TRACE;
118 MessageParcel data;
119 if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
120 MMI_HILOGE("Failed to write descriptor");
121 return RET_ERR;
122 }
123 if (!data.WriteBool(isKnuckleEnable)) {
124 MMI_HILOGE("Failed to write knuckle status");
125 return RET_ERR;
126 }
127 MessageParcel reply;
128 MessageOption option;
129 sptr<IRemoteObject> remote = Remote();
130 CHKPR(remote, RET_ERR);
131 int32_t ret = remote->SendRequest(
132 static_cast<uint32_t>(AncoRequestId::SYNC_KNUCKLE_STATUS), data, reply, option);
133 if (ret != RET_OK) {
134 MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
135 return ret;
136 }
137 return ret;
138 }
139 } // namespace MMI
140 } // namespace OHOS
141