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 "accessible_ability_manager_config_observer_proxy.h"
17 #include "accessibility_ipc_interface_code.h"
18 #include "hilog_wrapper.h"
19
20 namespace OHOS {
21 namespace Accessibility {
AccessibleAbilityManagerConfigObserverProxy(const sptr<IRemoteObject> & impl)22 AccessibleAbilityManagerConfigObserverProxy::AccessibleAbilityManagerConfigObserverProxy(
23 const sptr<IRemoteObject> &impl) : IRemoteProxy<IAccessibleAbilityManagerConfigObserver>(impl)
24 {}
25
~AccessibleAbilityManagerConfigObserverProxy()26 AccessibleAbilityManagerConfigObserverProxy::~AccessibleAbilityManagerConfigObserverProxy()
27 {}
28
WriteInterfaceToken(MessageParcel & data)29 bool AccessibleAbilityManagerConfigObserverProxy::WriteInterfaceToken(MessageParcel &data)
30 {
31 HILOG_DEBUG();
32 if (!data.WriteInterfaceToken(AccessibleAbilityManagerConfigObserverProxy::GetDescriptor())) {
33 HILOG_ERROR("write interface token failed");
34 return false;
35 }
36 return true;
37 }
38
OnConfigStateChanged(const uint32_t stateType)39 void AccessibleAbilityManagerConfigObserverProxy::OnConfigStateChanged(const uint32_t stateType)
40 {
41 HILOG_DEBUG();
42
43 int32_t error = NO_ERROR;
44 MessageParcel data;
45 MessageParcel reply;
46 MessageOption option(MessageOption::TF_ASYNC);
47
48 if (!WriteInterfaceToken(data)) {
49 HILOG_ERROR("fail, connection write Token");
50 return;
51 }
52
53 if (!data.WriteUint32(stateType)) {
54 HILOG_ERROR("fail, connection write stateType error");
55 return;
56 }
57
58 sptr<IRemoteObject> remote = Remote();
59 if (remote == nullptr) {
60 HILOG_ERROR("fail to send transact cmd due to remote object");
61 return;
62 }
63
64 error = remote->SendRequest(
65 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_CONFIG_STATE_CHANGED),
66 data, reply, option);
67 if (error != NO_ERROR) {
68 HILOG_ERROR("OnConfigStateChanged fail, error: %{public}d", error);
69 return;
70 }
71 }
72
OnAudioBalanceChanged(const float audioBalance)73 void AccessibleAbilityManagerConfigObserverProxy::OnAudioBalanceChanged(const float audioBalance)
74 {
75 HILOG_DEBUG();
76
77 int32_t error = NO_ERROR;
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option(MessageOption::TF_ASYNC);
81
82 if (!WriteInterfaceToken(data)) {
83 HILOG_ERROR("fail, connection write Token");
84 return;
85 }
86
87 if (!data.WriteFloat(audioBalance)) {
88 HILOG_ERROR("fail, connection write stateType error");
89 return;
90 }
91
92 sptr<IRemoteObject> remote = Remote();
93 if (remote == nullptr) {
94 HILOG_ERROR("fail to send transact cmd due to remote object");
95 return;
96 }
97
98 error = remote->SendRequest(
99 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_AUDIO_BALANCE_CHANGED),
100 data, reply, option);
101 if (error != NO_ERROR) {
102 HILOG_ERROR("OnAudioBalanceChanged fail, error: %{public}d", error);
103 return;
104 }
105 }
106
OnBrightnessDiscountChanged(const float brightnessDiscount)107 void AccessibleAbilityManagerConfigObserverProxy::OnBrightnessDiscountChanged(const float brightnessDiscount)
108 {
109 HILOG_DEBUG();
110
111 int32_t error = NO_ERROR;
112 MessageParcel data;
113 MessageParcel reply;
114 MessageOption option(MessageOption::TF_ASYNC);
115
116 if (!WriteInterfaceToken(data)) {
117 HILOG_ERROR("fail, connection write Token");
118 return;
119 }
120
121 if (!data.WriteFloat(brightnessDiscount)) {
122 HILOG_ERROR("fail, connection write stateType error");
123 return;
124 }
125
126 sptr<IRemoteObject> remote = Remote();
127 if (remote == nullptr) {
128 HILOG_ERROR("fail to send transact cmd due to remote object");
129 return;
130 }
131
132 error = remote->SendRequest(
133 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_BRIGHTNESS_DISCOUNT_CHANGED),
134 data, reply, option);
135 if (error != NO_ERROR) {
136 HILOG_ERROR("OnBrightnessDiscountChanged fail, error: %{public}d", error);
137 return;
138 }
139 }
140
OnContentTimeoutChanged(const uint32_t contentTimeout)141 void AccessibleAbilityManagerConfigObserverProxy::OnContentTimeoutChanged(const uint32_t contentTimeout)
142 {
143 HILOG_DEBUG();
144
145 int32_t error = NO_ERROR;
146 MessageParcel data;
147 MessageParcel reply;
148 MessageOption option(MessageOption::TF_ASYNC);
149
150 if (!WriteInterfaceToken(data)) {
151 HILOG_ERROR("fail, connection write Token");
152 return;
153 }
154
155 if (!data.WriteUint32(contentTimeout)) {
156 HILOG_ERROR("fail, connection write stateType error");
157 return;
158 }
159
160 sptr<IRemoteObject> remote = Remote();
161 if (remote == nullptr) {
162 HILOG_ERROR("fail to send transact cmd due to remote object");
163 return;
164 }
165
166 error = remote->SendRequest(
167 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_CONTENT_TIMEOUT_CHANGED),
168 data, reply, option);
169 if (error != NO_ERROR) {
170 HILOG_ERROR("OnContentTimeoutChanged fail, error: %{public}d", error);
171 return;
172 }
173 }
174
OnDaltonizationColorFilterChanged(const uint32_t filterType)175 void AccessibleAbilityManagerConfigObserverProxy::OnDaltonizationColorFilterChanged(const uint32_t filterType)
176 {
177 HILOG_DEBUG();
178
179 int32_t error = NO_ERROR;
180 MessageParcel data;
181 MessageParcel reply;
182 MessageOption option(MessageOption::TF_ASYNC);
183
184 if (!WriteInterfaceToken(data)) {
185 HILOG_ERROR("fail, connection write Token");
186 return;
187 }
188
189 if (!data.WriteUint32(filterType)) {
190 HILOG_ERROR("fail, connection write stateType error");
191 return;
192 }
193
194 sptr<IRemoteObject> remote = Remote();
195 if (remote == nullptr) {
196 HILOG_ERROR("fail to send transact cmd due to remote object");
197 return;
198 }
199
200 error = remote->SendRequest(
201 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_DALTONIZATION_COLOR_FILTER_CHANGED),
202 data, reply, option);
203 if (error != NO_ERROR) {
204 HILOG_ERROR("OnDaltonizationColorFilterChanged fail, error: %{public}d", error);
205 return;
206 }
207 }
208
OnMouseAutoClickChanged(const int32_t mouseAutoClick)209 void AccessibleAbilityManagerConfigObserverProxy::OnMouseAutoClickChanged(const int32_t mouseAutoClick)
210 {
211 HILOG_DEBUG();
212
213 int32_t error = NO_ERROR;
214 MessageParcel data;
215 MessageParcel reply;
216 MessageOption option(MessageOption::TF_ASYNC);
217
218 if (!WriteInterfaceToken(data)) {
219 HILOG_ERROR("fail, connection write Token");
220 return;
221 }
222
223 if (!data.WriteInt32(mouseAutoClick)) {
224 HILOG_ERROR("fail, connection write stateType error");
225 return;
226 }
227
228 sptr<IRemoteObject> remote = Remote();
229 if (remote == nullptr) {
230 HILOG_ERROR("fail to send transact cmd due to remote object");
231 return;
232 }
233
234 error = remote->SendRequest(
235 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_MOUSE_AUTOCLICK_CHANGED),
236 data, reply, option);
237 if (error != NO_ERROR) {
238 HILOG_ERROR("OnMouseAutoClickChanged fail, error: %{public}d", error);
239 return;
240 }
241 }
242
OnShortkeyTargetChanged(const std::string & shortkeyTarget)243 void AccessibleAbilityManagerConfigObserverProxy::OnShortkeyTargetChanged(const std::string &shortkeyTarget)
244 {
245 HILOG_DEBUG();
246
247 int32_t error = NO_ERROR;
248 MessageParcel data;
249 MessageParcel reply;
250 MessageOption option(MessageOption::TF_ASYNC);
251
252 if (!WriteInterfaceToken(data)) {
253 HILOG_ERROR("fail, connection write Token");
254 return;
255 }
256
257 if (!data.WriteString(shortkeyTarget)) {
258 HILOG_ERROR("fail, connection write stateType error");
259 return;
260 }
261
262 sptr<IRemoteObject> remote = Remote();
263 if (remote == nullptr) {
264 HILOG_ERROR("fail to send transact cmd due to remote object");
265 return;
266 }
267
268 error = remote->SendRequest(
269 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_SHORTKEY_TARGET_CHANGED),
270 data, reply, option);
271 if (error != NO_ERROR) {
272 HILOG_ERROR("OnShortkeyTargetChanged fail, error: %{public}d", error);
273 return;
274 }
275 }
276
OnShortkeyMultiTargetChanged(const std::vector<std::string> & shortkeyMultiTarget)277 void AccessibleAbilityManagerConfigObserverProxy::OnShortkeyMultiTargetChanged(
278 const std::vector<std::string> &shortkeyMultiTarget)
279 {
280 HILOG_DEBUG();
281
282 int32_t error = NO_ERROR;
283 MessageParcel data;
284 MessageParcel reply;
285 MessageOption option(MessageOption::TF_ASYNC);
286
287 if (!WriteInterfaceToken(data)) {
288 HILOG_ERROR("fail, connection write Token");
289 return;
290 }
291
292 if (!data.WriteStringVector(shortkeyMultiTarget)) {
293 HILOG_ERROR("connection write argument shortkeyMultiTarget failed");
294 return;
295 }
296
297 sptr<IRemoteObject> remote = Remote();
298 if (remote == nullptr) {
299 HILOG_ERROR("fail to send transact cmd due to remote object");
300 return;
301 }
302
303 error = remote->SendRequest(
304 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_SHORTKEY_MULTI_TARGET_CHANGED),
305 data, reply, option);
306 if (error != NO_ERROR) {
307 HILOG_ERROR("OnShortkeyMultiTargetChanged fail, error: %{public}d", error);
308 return;
309 }
310 }
311
OnClickResponseTimeChanged(const uint32_t clickResponseTime)312 void AccessibleAbilityManagerConfigObserverProxy::OnClickResponseTimeChanged(const uint32_t clickResponseTime)
313 {
314 HILOG_DEBUG();
315
316 int32_t error = NO_ERROR;
317 MessageParcel data;
318 MessageParcel reply;
319 MessageOption option(MessageOption::TF_ASYNC);
320
321 if (!WriteInterfaceToken(data)) {
322 HILOG_ERROR("fail, connection write Token");
323 return;
324 }
325
326 if (!data.WriteUint32(clickResponseTime)) {
327 HILOG_ERROR("fail, connection write stateType error");
328 return;
329 }
330
331 sptr<IRemoteObject> remote = Remote();
332 if (remote == nullptr) {
333 HILOG_ERROR("fail to send transact cmd due to remote object");
334 return;
335 }
336
337 error = remote->SendRequest(
338 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_CLICK_RESPONSE_TIME),
339 data, reply, option);
340 if (error != NO_ERROR) {
341 HILOG_ERROR("OnClickResponseTimeChanged fail, error: %{public}d", error);
342 return;
343 }
344 }
345
OnIgnoreRepeatClickTimeChanged(const uint32_t ignoreRepeatClickTime)346 void AccessibleAbilityManagerConfigObserverProxy::OnIgnoreRepeatClickTimeChanged(const uint32_t ignoreRepeatClickTime)
347 {
348 HILOG_DEBUG();
349
350 int32_t error = NO_ERROR;
351 MessageParcel data;
352 MessageParcel reply;
353 MessageOption option(MessageOption::TF_ASYNC);
354
355 if (!WriteInterfaceToken(data)) {
356 HILOG_ERROR("fail, connection write Token");
357 return;
358 }
359
360 if (!data.WriteUint32(ignoreRepeatClickTime)) {
361 HILOG_ERROR("fail, connection write stateType error");
362 return;
363 }
364
365 sptr<IRemoteObject> remote = Remote();
366 if (remote == nullptr) {
367 HILOG_ERROR("fail to send transact cmd due to remote object");
368 return;
369 }
370
371 error = remote->SendRequest(
372 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_IGNORE_REPEAT_CLICK_TIME),
373 data, reply, option);
374 if (error != NO_ERROR) {
375 HILOG_ERROR("OnIgnoreRepeatClickTimeChanged fail, error: %{public}d", error);
376 return;
377 }
378 }
379
380 } // namespace Accessibility
381 } // namespace OHOS