• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "accessibility_element_operator_callback_proxy.h"
17 #include "accessibility_element_info_parcel.h"
18 #include "hilog_wrapper.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityElementOperatorCallbackProxy(const sptr<IRemoteObject> & impl)22 AccessibilityElementOperatorCallbackProxy::AccessibilityElementOperatorCallbackProxy(
23     const sptr<IRemoteObject> &impl) : IRemoteProxy<IAccessibilityElementOperatorCallback>(impl)
24 {}
25 
~AccessibilityElementOperatorCallbackProxy()26 AccessibilityElementOperatorCallbackProxy::~AccessibilityElementOperatorCallbackProxy()
27 {}
28 
WriteInterfaceToken(MessageParcel & data)29 bool AccessibilityElementOperatorCallbackProxy::WriteInterfaceToken(MessageParcel &data)
30 {
31     HILOG_DEBUG();
32     if (!data.WriteInterfaceToken(AccessibilityElementOperatorCallbackProxy::GetDescriptor())) {
33         HILOG_ERROR("write interface token failed");
34         return false;
35     }
36     return true;
37 }
38 
SendTransactCmd(IAccessibilityElementOperatorCallback::Message code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 bool AccessibilityElementOperatorCallbackProxy::SendTransactCmd(IAccessibilityElementOperatorCallback::Message code,
40     MessageParcel &data, MessageParcel &reply,  MessageOption &option)
41 {
42     HILOG_DEBUG();
43 
44     sptr<IRemoteObject> remote = Remote();
45     if (!remote) {
46         HILOG_ERROR("fail to send transact cmd %{public}d due to remote object", code);
47         return false;
48     }
49     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
50     if (result != NO_ERROR) {
51         HILOG_ERROR("receive error transact code %{public}d in transact cmd %{public}d", result, code);
52         return false;
53     }
54     return true;
55 }
56 
SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> & infos,const int32_t requestId)57 void AccessibilityElementOperatorCallbackProxy::SetSearchElementInfoByAccessibilityIdResult(
58     const std::vector<AccessibilityElementInfo> &infos, const int32_t requestId)
59 {
60     HILOG_DEBUG();
61     MessageParcel data;
62     MessageParcel reply;
63     MessageOption option(MessageOption::TF_ASYNC);
64 
65     if (!WriteInterfaceToken(data)) {
66         HILOG_ERROR("fail, connection write Token");
67         return;
68     }
69 
70     if (!data.WriteInt32(infos.size())) {
71         HILOG_ERROR("write infos's size failed");
72         return;
73     }
74 
75     for (auto &info : infos) {
76         AccessibilityElementInfoParcel infoParcel(info);
77         if (!data.WriteParcelable(&infoParcel)) {
78             HILOG_ERROR("write Parcelable failed");
79             return;
80         }
81     }
82 
83     if (!data.WriteInt32(requestId)) {
84         HILOG_ERROR("fail, connection write requestId");
85         return;
86     }
87 
88     if (!SendTransactCmd(IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_ACCESSIBILITY_ID,
89         data, reply, option)) {
90         HILOG_ERROR("SetSearchElementInfoByAccessibilityIdResult failed");
91         return;
92     }
93 }
94 
SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> & infos,const int32_t requestId)95 void AccessibilityElementOperatorCallbackProxy::SetSearchElementInfoByTextResult(
96     const std::vector<AccessibilityElementInfo> &infos, const int32_t requestId)
97 {
98     HILOG_DEBUG();
99     MessageParcel data;
100     MessageParcel reply;
101     MessageOption option(MessageOption::TF_ASYNC);
102 
103     if (!WriteInterfaceToken(data)) {
104         HILOG_ERROR("fail, connection write Token");
105         return;
106     }
107 
108     if (!data.WriteInt32(infos.size())) {
109         HILOG_ERROR("write infos's size failed");
110         return;
111     }
112 
113     for (auto &info : infos) {
114         AccessibilityElementInfoParcel infoParcel(info);
115         if (!data.WriteParcelable(&infoParcel)) {
116             HILOG_ERROR("write Parcelable failed");
117             return;
118         }
119     }
120 
121     if (!data.WriteInt32(requestId)) {
122         HILOG_ERROR("fail, connection write requestId");
123         return;
124     }
125 
126     if (!SendTransactCmd(IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_TEXT,
127         data, reply, option)) {
128         HILOG_ERROR("SetSearchElementInfoByTextResult failed");
129         return;
130     }
131 }
132 
SetFindFocusedElementInfoResult(const AccessibilityElementInfo & info,const int32_t requestId)133 void AccessibilityElementOperatorCallbackProxy::SetFindFocusedElementInfoResult(
134     const AccessibilityElementInfo &info, const int32_t requestId)
135 {
136     HILOG_DEBUG();
137     MessageParcel data;
138     MessageParcel reply;
139     MessageOption option(MessageOption::TF_ASYNC);
140     AccessibilityElementInfoParcel infoParcel(info);
141 
142     if (!WriteInterfaceToken(data)) {
143         HILOG_ERROR("fail, connection write Token");
144         return;
145     }
146 
147     if (!data.WriteParcelable(&infoParcel)) {
148         HILOG_ERROR("fail, connection write info");
149         return;
150     }
151     if (!data.WriteInt32(requestId)) {
152         HILOG_ERROR("fail, connection write requestId");
153         return;
154     }
155 
156     if (!SendTransactCmd(IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUSED_INFO,
157         data, reply, option)) {
158         HILOG_ERROR("SetFindFocusedElementInfoResult failed");
159         return;
160     }
161 }
162 
SetFocusMoveSearchResult(const AccessibilityElementInfo & info,const int32_t requestId)163 void AccessibilityElementOperatorCallbackProxy::SetFocusMoveSearchResult(const AccessibilityElementInfo &info,
164     const int32_t requestId)
165 {
166     HILOG_DEBUG();
167     MessageParcel data;
168     MessageParcel reply;
169     MessageOption option(MessageOption::TF_ASYNC);
170     AccessibilityElementInfoParcel infoParcel(info);
171 
172     if (!WriteInterfaceToken(data)) {
173         HILOG_ERROR("fail, connection write Token");
174         return;
175     }
176 
177     if (!data.WriteParcelable(&infoParcel)) {
178         HILOG_ERROR("fail, connection write info");
179         return;
180     }
181 
182     if (!data.WriteInt32(requestId)) {
183         HILOG_ERROR("fail, connection write requestId");
184         return;
185     }
186 
187     if (!SendTransactCmd(IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUS_MOVE,
188         data, reply, option)) {
189         HILOG_ERROR("SetFocusMoveSearchResult failed");
190         return;
191     }
192 }
193 
SetExecuteActionResult(const bool succeeded,const int32_t requestId)194 void AccessibilityElementOperatorCallbackProxy::SetExecuteActionResult(const bool succeeded, const int32_t requestId)
195 {
196     HILOG_DEBUG();
197     MessageParcel data;
198     MessageParcel reply;
199     MessageOption option(MessageOption::TF_ASYNC);
200 
201     if (!WriteInterfaceToken(data)) {
202         HILOG_ERROR("fail, connection write Token");
203         return;
204     }
205 
206     if (!data.WriteBool(succeeded)) {
207         HILOG_ERROR("fail, connection write succeeded");
208         return;
209     }
210 
211     if (!data.WriteInt32(requestId)) {
212         HILOG_ERROR("fail, connection write requestId");
213         return;
214     }
215 
216     if (!SendTransactCmd(IAccessibilityElementOperatorCallback::Message::SET_RESULT_PERFORM_ACTION,
217         data, reply, option)) {
218         HILOG_ERROR("SetExecuteActionResult failed");
219         return;
220     }
221 }
222 } // namespace Accessibility
223 } // namespace OHOS