1 /*
2 * Copyright (c) 2021-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 "miscdevice_service_proxy.h"
17
18 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
19 #include "hisysevent.h"
20 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
21 #include "securec.h"
22
23 #include "sensors_errors.h"
24
25 #undef LOG_TAG
26 #define LOG_TAG "MiscdeviceServiceProxy"
27
28 namespace OHOS {
29 namespace Sensors {
30 using namespace OHOS::HiviewDFX;
31
32 namespace {
33 constexpr int32_t MAX_LIGHT_COUNT = 0XFF;
34 } // namespace
35
MiscdeviceServiceProxy(const sptr<IRemoteObject> &impl)36 MiscdeviceServiceProxy::MiscdeviceServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IMiscdeviceService>(impl)
37 {}
38
Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage)39 int32_t MiscdeviceServiceProxy::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage)
40 {
41 MessageParcel data;
42 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
43 MISC_HILOGE("Write descriptor failed");
44 return WRITE_MSG_ERR;
45 }
46 if (!data.WriteInt32(vibratorId)) {
47 MISC_HILOGE("WriteInt32 vibratorId failed");
48 return WRITE_MSG_ERR;
49 }
50 if (!data.WriteInt32(timeOut)) {
51 MISC_HILOGE("WriteUint32 timeOut failed");
52 return WRITE_MSG_ERR;
53 }
54 if (!data.WriteInt32(usage)) {
55 MISC_HILOGE("WriteUint32 usage failed");
56 return WRITE_MSG_ERR;
57 }
58 if (!data.WriteBool(systemUsage)) {
59 MISC_HILOGE("WritBool systemUsage failed");
60 return WRITE_MSG_ERR;
61 }
62 sptr<IRemoteObject> remote = Remote();
63 CHKPR(remote, ERROR);
64 MessageParcel reply;
65 MessageOption option;
66 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::VIBRATE),
67 data, reply, option);
68 if (ret != NO_ERROR) {
69 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
70 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
71 HiSysEvent::EventType::FAULT, "PKG_NAME", "Vibrate", "ERROR_CODE", ret);
72 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
73 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
74 }
75 return ret;
76 }
77
StopVibrator(int32_t vibratorId)78 int32_t MiscdeviceServiceProxy::StopVibrator(int32_t vibratorId)
79 {
80 MessageParcel data;
81 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
82 MISC_HILOGE("Write descriptor failed");
83 return WRITE_MSG_ERR;
84 }
85 if (!data.WriteInt32(vibratorId)) {
86 MISC_HILOGE("WriteInt32 vibratorId failed");
87 return WRITE_MSG_ERR;
88 }
89 sptr<IRemoteObject> remote = Remote();
90 CHKPR(remote, ERROR);
91 MessageParcel reply;
92 MessageOption option;
93 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::STOP_VIBRATOR_ALL),
94 data, reply, option);
95 if (ret != NO_ERROR) {
96 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
97 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
98 HiSysEvent::EventType::FAULT, "PKG_NAME", "StopVibrator", "ERROR_CODE", ret);
99 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
100 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
101 }
102 return ret;
103 }
104
PlayVibratorEffect(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage, bool systemUsage)105 int32_t MiscdeviceServiceProxy::PlayVibratorEffect(int32_t vibratorId, const std::string &effect,
106 int32_t loopCount, int32_t usage, bool systemUsage)
107 {
108 MessageParcel data;
109 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
110 MISC_HILOGE("Write descriptor failed");
111 return WRITE_MSG_ERR;
112 }
113 if (!data.WriteInt32(vibratorId)) {
114 MISC_HILOGE("WriteInt32 vibratorId failed");
115 return WRITE_MSG_ERR;
116 }
117 if (!data.WriteString(effect)) {
118 MISC_HILOGE("WriteString effect failed");
119 return WRITE_MSG_ERR;
120 }
121 if (!data.WriteInt32(loopCount)) {
122 MISC_HILOGE("WriteInt32 loopCount failed");
123 return WRITE_MSG_ERR;
124 }
125 if (!data.WriteInt32(usage)) {
126 MISC_HILOGE("Writeint32 usage failed");
127 return WRITE_MSG_ERR;
128 }
129 if (!data.WriteBool(systemUsage)) {
130 MISC_HILOGE("Writebool systemUsage failed");
131 return WRITE_MSG_ERR;
132 }
133 sptr<IRemoteObject> remote = Remote();
134 CHKPR(remote, ERROR);
135 MessageParcel reply;
136 MessageOption option;
137 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::PLAY_VIBRATOR_EFFECT),
138 data, reply, option);
139 if (ret != NO_ERROR) {
140 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
141 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
142 HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayVibratorEffect", "ERROR_CODE", ret);
143 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
144 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
145 }
146 return ret;
147 }
148
StopVibrator(int32_t vibratorId, const std::string &mode)149 int32_t MiscdeviceServiceProxy::StopVibrator(int32_t vibratorId, const std::string &mode)
150 {
151 MessageParcel data;
152 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
153 MISC_HILOGE("Write descriptor failed");
154 return WRITE_MSG_ERR;
155 }
156 if (!data.WriteInt32(vibratorId)) {
157 MISC_HILOGE("WriteInt32 vibratorId failed");
158 return WRITE_MSG_ERR;
159 }
160 if (!data.WriteString(mode)) {
161 MISC_HILOGE("WriteString mode failed");
162 return WRITE_MSG_ERR;
163 }
164 sptr<IRemoteObject> remote = Remote();
165 CHKPR(remote, ERROR);
166 MessageParcel reply;
167 MessageOption option;
168 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::STOP_VIBRATOR_BY_MODE),
169 data, reply, option);
170 if (ret != NO_ERROR) {
171 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
172 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
173 HiSysEvent::EventType::FAULT, "PKG_NAME", "StopVibrator", "ERROR_CODE", ret);
174 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
175 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
176 }
177 return ret;
178 }
179
IsSupportEffect(const std::string &effect, bool &state)180 int32_t MiscdeviceServiceProxy::IsSupportEffect(const std::string &effect, bool &state)
181 {
182 MessageParcel data;
183 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
184 MISC_HILOGE("Write descriptor failed");
185 return WRITE_MSG_ERR;
186 }
187 if (!data.WriteString(effect)) {
188 MISC_HILOGE("WriteString effect failed");
189 return WRITE_MSG_ERR;
190 }
191 sptr<IRemoteObject> remote = Remote();
192 CHKPR(remote, ERROR);
193 MessageParcel reply;
194 MessageOption option;
195 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::IS_SUPPORT_EFFECT),
196 data, reply, option);
197 if (ret != NO_ERROR) {
198 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
199 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
200 HiSysEvent::EventType::FAULT, "PKG_NAME", "IsSupportEffect", "ERROR_CODE", ret);
201 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
202 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
203 return ret;
204 }
205 if (!reply.ReadBool(state)) {
206 MISC_HILOGE("Parcel read state failed");
207 return READ_MSG_ERR;
208 }
209 return ret;
210 }
211
212 #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM
PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, bool systemUsage, const VibrateParameter ¶meter)213 int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage,
214 bool systemUsage, const VibrateParameter ¶meter)
215 {
216 MessageParcel data;
217 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
218 MISC_HILOGE("Write descriptor failed");
219 return WRITE_MSG_ERR;
220 }
221 if (!data.WriteInt32(vibratorId)) {
222 MISC_HILOGE("WriteInt32 vibratorId failed");
223 return WRITE_MSG_ERR;
224 }
225 if (!data.WriteInt32(usage)) {
226 MISC_HILOGE("Writeint32 usage failed");
227 return WRITE_MSG_ERR;
228 }
229 if (!data.WriteBool(systemUsage)) {
230 MISC_HILOGE("Writebool systemUsage failed");
231 return WRITE_MSG_ERR;
232 }
233 if (!parameter.Marshalling(data)) {
234 MISC_HILOGE("Write adjust parameter failed");
235 return WRITE_MSG_ERR;
236 }
237 if (!data.WriteInt64(rawFd.offset)) {
238 MISC_HILOGE("Writeint64 offset failed");
239 return WRITE_MSG_ERR;
240 }
241 if (!data.WriteInt64(rawFd.length)) {
242 MISC_HILOGE("Writeint64 length failed");
243 return WRITE_MSG_ERR;
244 }
245 if (!data.WriteFileDescriptor(rawFd.fd)) {
246 MISC_HILOGE("WriteFileDescriptor fd failed");
247 return WRITE_MSG_ERR;
248 }
249 sptr<IRemoteObject> remote = Remote();
250 CHKPR(remote, ERROR);
251 MessageParcel reply;
252 MessageOption option;
253 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::PLAY_VIBRATOR_CUSTOM),
254 data, reply, option);
255 if (ret != NO_ERROR) {
256 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
257 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
258 HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayVibratorCustom", "ERROR_CODE", ret);
259 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
260 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
261 }
262 return ret;
263 }
264 #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM
265
GetLightList()266 std::vector<LightInfoIPC> MiscdeviceServiceProxy::GetLightList()
267 {
268 MessageParcel data;
269 std::vector<LightInfoIPC> lightInfos;
270 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
271 MISC_HILOGE("WriteInterfaceToken failed");
272 return lightInfos;
273 }
274 sptr<IRemoteObject> remote = Remote();
275 if (remote == nullptr) {
276 MISC_HILOGE("remote is nullptr");
277 return lightInfos;
278 }
279 MessageParcel reply;
280 MessageOption option;
281 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::GET_LIGHT_LIST),
282 data, reply, option);
283 if (ret != NO_ERROR) {
284 MISC_HILOGE("SendRequest failed, ret:%{public}d", ret);
285 return lightInfos;
286 }
287 uint32_t lightCount = 0;
288 if (!reply.ReadUint32(lightCount)) {
289 MISC_HILOGE("Parcel read failed");
290 return lightInfos;
291 }
292 if (lightCount > MAX_LIGHT_COUNT) {
293 lightCount = MAX_LIGHT_COUNT;
294 }
295 LightInfoIPC lightInfo;
296 for (uint32_t i = 0; i < lightCount; ++i) {
297 auto tmpLightInfo = lightInfo.Unmarshalling(reply);
298 CHKPC(tmpLightInfo);
299 lightInfos.push_back(*tmpLightInfo);
300 }
301 return lightInfos;
302 }
303
TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation)304 int32_t MiscdeviceServiceProxy::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation)
305 {
306 MessageParcel data;
307 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
308 MISC_HILOGE("Write descriptor failed");
309 return WRITE_MSG_ERR;
310 }
311 if (!data.WriteInt32(lightId)) {
312 MISC_HILOGE("WriteUint32 lightId failed");
313 return WRITE_MSG_ERR;
314 }
315 if (!data.WriteInt32(color.singleColor)) {
316 MISC_HILOGE("Write color failed");
317 return WRITE_MSG_ERR;
318 }
319 if (!animation.Marshalling(data)) {
320 MISC_HILOGE("Write animation failed");
321 return WRITE_MSG_ERR;
322 }
323 sptr<IRemoteObject> remote = Remote();
324 CHKPR(remote, ERROR);
325 MessageParcel reply;
326 MessageOption option;
327 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::TURN_ON),
328 data, reply, option);
329 if (ret != NO_ERROR) {
330 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
331 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
332 HiSysEvent::EventType::FAULT, "PKG_NAME", "TurnOn", "ERROR_CODE", ret);
333 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
334 MISC_HILOGE("SendRequest failed, ret:%{public}d", ret);
335 }
336 return ret;
337 }
338
TurnOff(int32_t lightId)339 int32_t MiscdeviceServiceProxy::TurnOff(int32_t lightId)
340 {
341 MessageParcel data;
342 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
343 MISC_HILOGE("Write descriptor failed");
344 return WRITE_MSG_ERR;
345 }
346 if (!data.WriteInt32(lightId)) {
347 MISC_HILOGE("WriteInt32 lightId failed");
348 return WRITE_MSG_ERR;
349 }
350 sptr<IRemoteObject> remote = Remote();
351 CHKPR(remote, ERROR);
352 MessageParcel reply;
353 MessageOption option;
354 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::TURN_OFF),
355 data, reply, option);
356 if (ret != NO_ERROR) {
357 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
358 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
359 HiSysEvent::EventType::FAULT, "PKG_NAME", "TurnOff", "ERROR_CODE", ret);
360 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
361 MISC_HILOGE("SendRequest failed, ret:%{public}d", ret);
362 }
363 return ret;
364 }
365
GetDelayTime(int32_t &delayTime)366 int32_t MiscdeviceServiceProxy::GetDelayTime(int32_t &delayTime)
367 {
368 MessageParcel data;
369 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
370 MISC_HILOGE("Write descriptor failed");
371 return WRITE_MSG_ERR;
372 }
373 sptr<IRemoteObject> remote = Remote();
374 CHKPR(remote, ERROR);
375 MessageParcel reply;
376 MessageOption option;
377 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::GET_DELAY_TIME),
378 data, reply, option);
379 if (ret != NO_ERROR) {
380 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
381 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
382 HiSysEvent::EventType::FAULT, "PKG_NAME", "GetDelayTime", "ERROR_CODE", ret);
383 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
384 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
385 }
386 if (!reply.ReadInt32(delayTime)) {
387 MISC_HILOGE("Parcel read failed");
388 return ERROR;
389 }
390 return ret;
391 }
392
PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, const VibrateParameter ¶meter)393 int32_t MiscdeviceServiceProxy::PlayPattern(const VibratePattern &pattern, int32_t usage,
394 bool systemUsage, const VibrateParameter ¶meter)
395 {
396 MessageParcel data;
397 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
398 MISC_HILOGE("Write descriptor failed");
399 return WRITE_MSG_ERR;
400 }
401 if (!pattern.Marshalling(data)) {
402 MISC_HILOGE("Marshalling failed");
403 return WRITE_MSG_ERR;
404 }
405 if (!data.WriteInt32(usage)) {
406 MISC_HILOGE("WriteUint32 usage failed");
407 return WRITE_MSG_ERR;
408 }
409 if (!data.WriteBool(systemUsage)) {
410 MISC_HILOGE("WriteBool systemUsage failed");
411 return WRITE_MSG_ERR;
412 }
413 if (!parameter.Marshalling(data)) {
414 MISC_HILOGE("Write adjust parameter failed");
415 return WRITE_MSG_ERR;
416 }
417 sptr<IRemoteObject> remote = Remote();
418 CHKPR(remote, ERROR);
419 MessageParcel reply;
420 MessageOption option;
421 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::PlAY_PATTERN),
422 data, reply, option);
423 if (ret != NO_ERROR) {
424 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
425 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
426 HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayPattern", "ERROR_CODE", ret);
427 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
428 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
429 }
430 return ret;
431 }
432
TransferClientRemoteObject(const sptr<IRemoteObject> &vibratorClient)433 int32_t MiscdeviceServiceProxy::TransferClientRemoteObject(const sptr<IRemoteObject> &vibratorClient)
434 {
435 MessageParcel data;
436 MessageParcel reply;
437 MessageOption option;
438 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
439 MISC_HILOGE("Write descriptor failed");
440 return WRITE_MSG_ERR;
441 }
442 if (!data.WriteRemoteObject(vibratorClient)) {
443 MISC_HILOGE("Parcel writeRemoteObject failed");
444 return WRITE_MSG_ERR;
445 }
446 sptr<IRemoteObject> remote = Remote();
447 CHKPR(remote, ERROR);
448 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::TRANSFER_CLIENT_REMOTE_OBJECT),
449 data, reply, option);
450 if (ret != NO_ERROR) {
451 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
452 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
453 HiSysEvent::EventType::FAULT, "PKG_NAME", "TransferClientRemoteObject", "ERROR_CODE", ret);
454 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
455 MISC_HILOGE("SendRequest failed, ret:%{public}d", ret);
456 }
457 return ret;
458 }
459
PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, int32_t usage, bool systemUsage, int32_t count)460 int32_t MiscdeviceServiceProxy::PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity,
461 int32_t usage, bool systemUsage, int32_t count)
462 {
463 MessageParcel data;
464 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
465 MISC_HILOGE("Write descriptor failed");
466 return WRITE_MSG_ERR;
467 }
468 if (!data.WriteInt32(vibratorId)) {
469 MISC_HILOGE("WriteInt32 vibratorId failed");
470 return WRITE_MSG_ERR;
471 }
472 if (!data.WriteString(effect)) {
473 MISC_HILOGE("WriteString effect failed");
474 return WRITE_MSG_ERR;
475 }
476 if (!data.WriteInt32(intensity)) {
477 MISC_HILOGE("WriteInt32 intensity failed");
478 return WRITE_MSG_ERR;
479 }
480 if (!data.WriteInt32(usage)) {
481 MISC_HILOGE("Writeint32 usage failed");
482 return WRITE_MSG_ERR;
483 }
484 if (!data.WriteBool(systemUsage)) {
485 MISC_HILOGE("WriteBool systemUsage failed");
486 return WRITE_MSG_ERR;
487 }
488 if (!data.WriteInt32(count)) {
489 MISC_HILOGE("Writeint32 count failed");
490 return WRITE_MSG_ERR;
491 }
492 sptr<IRemoteObject> remote = Remote();
493 CHKPR(remote, ERROR);
494 MessageParcel reply;
495 MessageOption option;
496 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::PLAY_PRIMITIVE_EFFECT),
497 data, reply, option);
498 if (ret != NO_ERROR) {
499 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
500 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
501 HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayPrimitiveEffect", "ERROR_CODE", ret);
502 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
503 MISC_HILOGD("SendRequest failed, ret:%{public}d", ret);
504 }
505 return ret;
506 }
507
GetVibratorCapacity(VibratorCapacity &capacity)508 int32_t MiscdeviceServiceProxy::GetVibratorCapacity(VibratorCapacity &capacity)
509 {
510 MessageParcel data;
511 if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) {
512 MISC_HILOGE("Write descriptor failed");
513 return WRITE_MSG_ERR;
514 }
515 sptr<IRemoteObject> remote = Remote();
516 CHKPR(remote, ERROR);
517 MessageParcel reply;
518 MessageOption option;
519 int32_t ret = remote->SendRequest(static_cast<uint32_t>(MiscdeviceInterfaceCode::GET_VIBRATOR_CAPACITY),
520 data, reply, option);
521 if (ret != NO_ERROR) {
522 #ifdef HIVIEWDFX_HISYSEVENT_ENABLE
523 HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION",
524 HiSysEvent::EventType::FAULT, "PKG_NAME", "GetVibratorCapacity", "ERROR_CODE", ret);
525 #endif // HIVIEWDFX_HISYSEVENT_ENABLE
526 MISC_HILOGE("SendRequest failed, ret:%{public}d", ret);
527 return ret;
528 }
529 auto vibratorCapacity = capacity.Unmarshalling(reply);
530 if (!vibratorCapacity.has_value()) {
531 MISC_HILOGE("VibratorCapacity Unmarshalling failed");
532 return ERROR;
533 }
534 capacity = vibratorCapacity.value();
535 return ret;
536 }
537 } // namespace Sensors
538 } // namespace OHOS
539