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 "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace Accessibility {
AccessibleAbilityManagerConfigObserverProxy(const sptr<IRemoteObject> & impl)21 AccessibleAbilityManagerConfigObserverProxy::AccessibleAbilityManagerConfigObserverProxy(
22 const sptr<IRemoteObject> &impl) : IRemoteProxy<IAccessibleAbilityManagerConfigObserver>(impl)
23 {}
24
~AccessibleAbilityManagerConfigObserverProxy()25 AccessibleAbilityManagerConfigObserverProxy::~AccessibleAbilityManagerConfigObserverProxy()
26 {}
27
WriteInterfaceToken(MessageParcel & data)28 bool AccessibleAbilityManagerConfigObserverProxy::WriteInterfaceToken(MessageParcel &data)
29 {
30 HILOG_DEBUG();
31 if (!data.WriteInterfaceToken(AccessibleAbilityManagerConfigObserverProxy::GetDescriptor())) {
32 HILOG_ERROR("write interface token failed");
33 return false;
34 }
35 return true;
36 }
37
OnConfigStateChanged(const uint32_t stateType)38 void AccessibleAbilityManagerConfigObserverProxy::OnConfigStateChanged(const uint32_t stateType)
39 {
40 HILOG_DEBUG();
41
42 int32_t error = NO_ERROR;
43 MessageParcel data;
44 MessageParcel reply;
45 MessageOption option(MessageOption::TF_ASYNC);
46
47 if (!WriteInterfaceToken(data)) {
48 HILOG_ERROR("fail, connection write Token");
49 return;
50 }
51
52 if (!data.WriteUint32(stateType)) {
53 HILOG_ERROR("fail, connection write stateType error");
54 return;
55 }
56
57 sptr<IRemoteObject> remote = Remote();
58 if (!remote) {
59 HILOG_ERROR("fail to send transact cmd due to remote object");
60 return;
61 }
62
63 error = remote->SendRequest(
64 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_CONFIG_STATE_CHANGED),
65 data, reply, option);
66 if (error != NO_ERROR) {
67 HILOG_ERROR("OnConfigStateChanged fail, error: %{public}d", error);
68 return;
69 }
70 }
71
OnAudioBalanceChanged(const float audioBalance)72 void AccessibleAbilityManagerConfigObserverProxy::OnAudioBalanceChanged(const float audioBalance)
73 {
74 HILOG_DEBUG();
75
76 int32_t error = NO_ERROR;
77 MessageParcel data;
78 MessageParcel reply;
79 MessageOption option(MessageOption::TF_ASYNC);
80
81 if (!WriteInterfaceToken(data)) {
82 HILOG_ERROR("fail, connection write Token");
83 return;
84 }
85
86 if (!data.WriteFloat(audioBalance)) {
87 HILOG_ERROR("fail, connection write stateType error");
88 return;
89 }
90
91 sptr<IRemoteObject> remote = Remote();
92 if (!remote) {
93 HILOG_ERROR("fail to send transact cmd due to remote object");
94 return;
95 }
96
97 error = remote->SendRequest(
98 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_AUDIO_BALANCE_CHANGED),
99 data, reply, option);
100 if (error != NO_ERROR) {
101 HILOG_ERROR("OnAudioBalanceChanged fail, error: %{public}d", error);
102 return;
103 }
104 }
105
OnBrightnessDiscountChanged(const float brightnessDiscount)106 void AccessibleAbilityManagerConfigObserverProxy::OnBrightnessDiscountChanged(const float brightnessDiscount)
107 {
108 HILOG_DEBUG();
109
110 int32_t error = NO_ERROR;
111 MessageParcel data;
112 MessageParcel reply;
113 MessageOption option(MessageOption::TF_ASYNC);
114
115 if (!WriteInterfaceToken(data)) {
116 HILOG_ERROR("fail, connection write Token");
117 return;
118 }
119
120 if (!data.WriteFloat(brightnessDiscount)) {
121 HILOG_ERROR("fail, connection write stateType error");
122 return;
123 }
124
125 sptr<IRemoteObject> remote = Remote();
126 if (!remote) {
127 HILOG_ERROR("fail to send transact cmd due to remote object");
128 return;
129 }
130
131 error = remote->SendRequest(
132 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_BRIGHTNESS_DISCOUNT_CHANGED),
133 data, reply, option);
134 if (error != NO_ERROR) {
135 HILOG_ERROR("OnBrightnessDiscountChanged fail, error: %{public}d", error);
136 return;
137 }
138 }
139
OnContentTimeoutChanged(const uint32_t contentTimeout)140 void AccessibleAbilityManagerConfigObserverProxy::OnContentTimeoutChanged(const uint32_t contentTimeout)
141 {
142 HILOG_DEBUG();
143
144 int32_t error = NO_ERROR;
145 MessageParcel data;
146 MessageParcel reply;
147 MessageOption option(MessageOption::TF_ASYNC);
148
149 if (!WriteInterfaceToken(data)) {
150 HILOG_ERROR("fail, connection write Token");
151 return;
152 }
153
154 if (!data.WriteUint32(contentTimeout)) {
155 HILOG_ERROR("fail, connection write stateType error");
156 return;
157 }
158
159 sptr<IRemoteObject> remote = Remote();
160 if (!remote) {
161 HILOG_ERROR("fail to send transact cmd due to remote object");
162 return;
163 }
164
165 error = remote->SendRequest(
166 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_CONTENT_TIMEOUT_CHANGED),
167 data, reply, option);
168 if (error != NO_ERROR) {
169 HILOG_ERROR("OnContentTimeoutChanged fail, error: %{public}d", error);
170 return;
171 }
172 }
173
OnDaltonizationColorFilterChanged(const uint32_t filterType)174 void AccessibleAbilityManagerConfigObserverProxy::OnDaltonizationColorFilterChanged(const uint32_t filterType)
175 {
176 HILOG_DEBUG();
177
178 int32_t error = NO_ERROR;
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option(MessageOption::TF_ASYNC);
182
183 if (!WriteInterfaceToken(data)) {
184 HILOG_ERROR("fail, connection write Token");
185 return;
186 }
187
188 if (!data.WriteUint32(filterType)) {
189 HILOG_ERROR("fail, connection write stateType error");
190 return;
191 }
192
193 sptr<IRemoteObject> remote = Remote();
194 if (!remote) {
195 HILOG_ERROR("fail to send transact cmd due to remote object");
196 return;
197 }
198
199 error = remote->SendRequest(
200 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_DALTONIZATION_COLOR_FILTER_CHANGED),
201 data, reply, option);
202 if (error != NO_ERROR) {
203 HILOG_ERROR("OnDaltonizationColorFilterChanged fail, error: %{public}d", error);
204 return;
205 }
206 }
207
OnMouseAutoClickChanged(const int32_t mouseAutoClick)208 void AccessibleAbilityManagerConfigObserverProxy::OnMouseAutoClickChanged(const int32_t mouseAutoClick)
209 {
210 HILOG_DEBUG();
211
212 int32_t error = NO_ERROR;
213 MessageParcel data;
214 MessageParcel reply;
215 MessageOption option(MessageOption::TF_ASYNC);
216
217 if (!WriteInterfaceToken(data)) {
218 HILOG_ERROR("fail, connection write Token");
219 return;
220 }
221
222 if (!data.WriteInt32(mouseAutoClick)) {
223 HILOG_ERROR("fail, connection write stateType error");
224 return;
225 }
226
227 sptr<IRemoteObject> remote = Remote();
228 if (!remote) {
229 HILOG_ERROR("fail to send transact cmd due to remote object");
230 return;
231 }
232
233 error = remote->SendRequest(
234 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_MOUSE_AUTOCLICK_CHANGED),
235 data, reply, option);
236 if (error != NO_ERROR) {
237 HILOG_ERROR("OnMouseAutoClickChanged fail, error: %{public}d", error);
238 return;
239 }
240 }
241
OnShortkeyTargetChanged(const std::string & shortkeyTarget)242 void AccessibleAbilityManagerConfigObserverProxy::OnShortkeyTargetChanged(const std::string &shortkeyTarget)
243 {
244 HILOG_DEBUG();
245
246 int32_t error = NO_ERROR;
247 MessageParcel data;
248 MessageParcel reply;
249 MessageOption option(MessageOption::TF_ASYNC);
250
251 if (!WriteInterfaceToken(data)) {
252 HILOG_ERROR("fail, connection write Token");
253 return;
254 }
255
256 if (!data.WriteString(shortkeyTarget)) {
257 HILOG_ERROR("fail, connection write stateType error");
258 return;
259 }
260
261 sptr<IRemoteObject> remote = Remote();
262 if (!remote) {
263 HILOG_ERROR("fail to send transact cmd due to remote object");
264 return;
265 }
266
267 error = remote->SendRequest(
268 static_cast<uint32_t>(IAccessibleAbilityManagerConfigObserver::Message::ON_SHORTKEY_TARGET_CHANGED),
269 data, reply, option);
270 if (error != NO_ERROR) {
271 HILOG_ERROR("OnShortkeyTargetChanged fail, error: %{public}d", error);
272 return;
273 }
274 }
275 } // namespace Accessibility
276 } // namespace OHOS