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