1 /*
2 * Copyright (c) 2022-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 "powermgr_service_test_proxy.h"
17
18 #include <message_parcel.h>
19 #include <string_ex.h>
20
21 #include "errors.h"
22 #include "message_option.h"
23 #include "hilog/log.h"
24 #include "power_common.h"
25 #include "power_log.h"
26 #include "ipower_mgr.h"
27 #include "power_mgr_proxy.h"
28
29 using OHOS::HiviewDFX::HiLog;
30 namespace OHOS {
31 namespace PowerMgr {
32 constexpr int32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000;
PowerMgrServiceTestProxy(const sptr<PowerMgrService> & service)33 PowerMgrServiceTestProxy::PowerMgrServiceTestProxy(const sptr<PowerMgrService>& service)
34 {
35 if (service != nullptr) {
36 stub_ = static_cast<PowerMgrStub*>(service);
37 }
38 }
39
CreateRunningLockIpc(const sptr<IRemoteObject> & remoteObj,const RunningLockInfo & runningLockInfo,int32_t & powerError)40 int32_t PowerMgrServiceTestProxy::CreateRunningLockIpc(const sptr<IRemoteObject>& remoteObj,
41 const RunningLockInfo& runningLockInfo, int32_t& powerError)
42 {
43 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
44
45 MessageParcel data;
46 MessageParcel reply;
47 MessageOption option(MessageOption::TF_SYNC);
48
49 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
50 HiLog::Error(LABEL, "Write interface token failed!");
51 return ERR_INVALID_VALUE;
52 }
53
54 if (!data.WriteRemoteObject(remoteObj)) {
55 HiLog::Error(LABEL, "Write [remoteObj] failed!");
56 return ERR_INVALID_DATA;
57 }
58 if (!data.WriteParcelable(&runningLockInfo)) {
59 HiLog::Error(LABEL, "Write [runningLockInfo] failed!");
60 return ERR_INVALID_DATA;
61 }
62
63 int32_t result = stub_->OnRemoteRequest(
64 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_CREATE_RUNNING_LOCK_IPC), data, reply, option);
65 if (FAILED(result)) {
66 HiLog::Error(LABEL, "Send request failed!");
67 return result;
68 }
69
70 ErrCode errCode = reply.ReadInt32();
71 if (FAILED(errCode)) {
72 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
73 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_CREATE_RUNNING_LOCK_IPC));
74 return errCode;
75 }
76
77 powerError = reply.ReadInt32();
78 return ERR_OK;
79 }
80
ReleaseRunningLockIpc(const sptr<IRemoteObject> & remoteObj,const std::string & name)81 int32_t PowerMgrServiceTestProxy::ReleaseRunningLockIpc(const sptr<IRemoteObject>& remoteObj, const std::string& name)
82 {
83 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
84
85 MessageParcel data;
86 MessageParcel reply;
87 MessageOption option(MessageOption::TF_SYNC);
88
89 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
90 HiLog::Error(LABEL, "Write interface token failed!");
91 return ERR_INVALID_VALUE;
92 }
93
94 if (!data.WriteRemoteObject(remoteObj)) {
95 HiLog::Error(LABEL, "Write [remoteObj] failed!");
96 return ERR_INVALID_DATA;
97 }
98 if (!data.WriteString16(Str8ToStr16(name))) {
99 HiLog::Error(LABEL, "Write [name] failed!");
100 return ERR_INVALID_DATA;
101 }
102
103 int32_t result = stub_->OnRemoteRequest(
104 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RELEASE_RUNNING_LOCK_IPC), data, reply, option);
105 if (FAILED(result)) {
106 HiLog::Error(LABEL, "Send request failed!");
107 return result;
108 }
109
110 ErrCode errCode = reply.ReadInt32();
111 if (FAILED(errCode)) {
112 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
113 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RELEASE_RUNNING_LOCK_IPC));
114 return errCode;
115 }
116
117 return ERR_OK;
118 }
119
IsRunningLockTypeSupportedIpc(int32_t lockType,bool & lockTypesSupported)120 int32_t PowerMgrServiceTestProxy::IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockTypesSupported)
121 {
122 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
123
124 MessageParcel data;
125 MessageParcel reply;
126 MessageOption option(MessageOption::TF_SYNC);
127
128 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
129 HiLog::Error(LABEL, "Write interface token failed!");
130 return ERR_INVALID_VALUE;
131 }
132
133 if (!data.WriteInt32(lockType)) {
134 HiLog::Error(LABEL, "Write [lockType] failed!");
135 return ERR_INVALID_DATA;
136 }
137
138 int32_t result = stub_->OnRemoteRequest(
139 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_RUNNING_LOCK_TYPE_SUPPORTED_IPC), data, reply, option);
140 if (FAILED(result)) {
141 HiLog::Error(LABEL, "Send request failed!");
142 return result;
143 }
144
145 ErrCode errCode = reply.ReadInt32();
146 if (FAILED(errCode)) {
147 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
148 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_RUNNING_LOCK_TYPE_SUPPORTED_IPC));
149 return errCode;
150 }
151
152 lockTypesSupported = reply.ReadInt32() == 1 ? true : false;
153 return ERR_OK;
154 }
155
LockIpc(const sptr<IRemoteObject> & remoteObj,int32_t timeOutMs,int32_t & powerError)156 int32_t PowerMgrServiceTestProxy::LockIpc(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs, int32_t& powerError)
157 {
158 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
159
160 MessageParcel data;
161 MessageParcel reply;
162 MessageOption option(MessageOption::TF_SYNC);
163
164 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
165 HiLog::Error(LABEL, "Write interface token failed!");
166 return ERR_INVALID_VALUE;
167 }
168
169 if (!data.WriteRemoteObject(remoteObj)) {
170 HiLog::Error(LABEL, "Write [remoteObj] failed!");
171 return ERR_INVALID_DATA;
172 }
173 if (!data.WriteInt32(timeOutMs)) {
174 HiLog::Error(LABEL, "Write [timeOutMs] failed!");
175 return ERR_INVALID_DATA;
176 }
177
178 int32_t result = stub_->OnRemoteRequest(
179 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_LOCK_IPC), data, reply, option);
180 if (FAILED(result)) {
181 HiLog::Error(LABEL, "Send request failed!");
182 return result;
183 }
184
185 ErrCode errCode = reply.ReadInt32();
186 if (FAILED(errCode)) {
187 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
188 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_LOCK_IPC));
189 return errCode;
190 }
191
192 powerError = reply.ReadInt32();
193 return ERR_OK;
194 }
195
UnLockIpc(const sptr<IRemoteObject> & remoteObj,const std::string & name,int32_t & powerError)196 int32_t PowerMgrServiceTestProxy::UnLockIpc(const sptr<IRemoteObject>& remoteObj,
197 const std::string& name, int32_t& powerError)
198 {
199 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
200
201 MessageParcel data;
202 MessageParcel reply;
203 MessageOption option(MessageOption::TF_SYNC);
204
205 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
206 HiLog::Error(LABEL, "Write interface token failed!");
207 return ERR_INVALID_VALUE;
208 }
209
210 if (!data.WriteRemoteObject(remoteObj)) {
211 HiLog::Error(LABEL, "Write [remoteObj] failed!");
212 return ERR_INVALID_DATA;
213 }
214 if (!data.WriteString16(Str8ToStr16(name))) {
215 HiLog::Error(LABEL, "Write [name] failed!");
216 return ERR_INVALID_DATA;
217 }
218
219 int32_t result = stub_->OnRemoteRequest(
220 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_LOCK_IPC), data, reply, option);
221 if (FAILED(result)) {
222 HiLog::Error(LABEL, "Send request failed!");
223 return result;
224 }
225
226 ErrCode errCode = reply.ReadInt32();
227 if (FAILED(errCode)) {
228 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
229 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_LOCK_IPC));
230 return errCode;
231 }
232
233 powerError = reply.ReadInt32();
234 return ERR_OK;
235 }
236
IsUsedIpc(const sptr<IRemoteObject> & remoteObj,bool & isUsed)237 int32_t PowerMgrServiceTestProxy::IsUsedIpc(const sptr<IRemoteObject>& remoteObj, bool& isUsed)
238 {
239 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
240
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option(MessageOption::TF_SYNC);
244
245 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
246 HiLog::Error(LABEL, "Write interface token failed!");
247 return ERR_INVALID_VALUE;
248 }
249
250 if (!data.WriteRemoteObject(remoteObj)) {
251 HiLog::Error(LABEL, "Write [remoteObj] failed!");
252 return ERR_INVALID_DATA;
253 }
254
255 int32_t result = stub_->OnRemoteRequest(
256 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_USED_IPC), data, reply, option);
257 if (FAILED(result)) {
258 HiLog::Error(LABEL, "Send request failed!");
259 return result;
260 }
261
262 ErrCode errCode = reply.ReadInt32();
263 if (FAILED(errCode)) {
264 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
265 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_USED_IPC));
266 return errCode;
267 }
268
269 isUsed = reply.ReadInt32() == 1 ? true : false;
270 return ERR_OK;
271 }
272
ProxyRunningLockIpc(bool isProxied,int32_t pid,int32_t uid)273 int32_t PowerMgrServiceTestProxy::ProxyRunningLockIpc(bool isProxied, int32_t pid, int32_t uid)
274 {
275 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
276
277 MessageParcel data;
278 MessageParcel reply;
279 MessageOption option(MessageOption::TF_SYNC);
280
281 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
282 HiLog::Error(LABEL, "Write interface token failed!");
283 return ERR_INVALID_VALUE;
284 }
285
286 if (!data.WriteInt32(isProxied ? 1 : 0)) {
287 HiLog::Error(LABEL, "Write [isProxied] failed!");
288 return ERR_INVALID_DATA;
289 }
290 if (!data.WriteInt32(pid)) {
291 HiLog::Error(LABEL, "Write [pid] failed!");
292 return ERR_INVALID_DATA;
293 }
294 if (!data.WriteInt32(uid)) {
295 HiLog::Error(LABEL, "Write [uid] failed!");
296 return ERR_INVALID_DATA;
297 }
298
299 int32_t result = stub_->OnRemoteRequest(
300 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCK_IPC), data, reply, option);
301 if (FAILED(result)) {
302 HiLog::Error(LABEL, "Send request failed!");
303 return result;
304 }
305
306 ErrCode errCode = reply.ReadInt32();
307 if (FAILED(errCode)) {
308 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
309 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCK_IPC));
310 return errCode;
311 }
312
313 return ERR_OK;
314 }
315
ProxyRunningLocksIpc(bool isProxied,const VectorPair & vectorPairInfos)316 int32_t PowerMgrServiceTestProxy::ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos)
317 {
318 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
319
320 MessageParcel data;
321 MessageParcel reply;
322 MessageOption option(MessageOption::TF_SYNC);
323
324 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
325 HiLog::Error(LABEL, "Write interface token failed!");
326 return ERR_INVALID_VALUE;
327 }
328
329 if (!data.WriteInt32(isProxied ? 1 : 0)) {
330 HiLog::Error(LABEL, "Write [isProxied] failed!");
331 return ERR_INVALID_DATA;
332 }
333 if (!data.WriteParcelable(&vectorPairInfos)) {
334 HiLog::Error(LABEL, "Write [vectorPairInfos] failed!");
335 return ERR_INVALID_DATA;
336 }
337
338 int32_t result = stub_->OnRemoteRequest(
339 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC), data, reply, option);
340 if (FAILED(result)) {
341 HiLog::Error(LABEL, "Send request failed!");
342 return result;
343 }
344
345 ErrCode errCode = reply.ReadInt32();
346 if (FAILED(errCode)) {
347 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
348 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC));
349 return errCode;
350 }
351
352 return ERR_OK;
353 }
354
ResetRunningLocksIpc()355 int32_t PowerMgrServiceTestProxy::ResetRunningLocksIpc()
356 {
357 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
358
359 MessageParcel data;
360 MessageParcel reply;
361 MessageOption option(MessageOption::TF_SYNC);
362
363 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
364 HiLog::Error(LABEL, "Write interface token failed!");
365 return ERR_INVALID_VALUE;
366 }
367
368 int32_t result = stub_->OnRemoteRequest(
369 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RESET_RUNNING_LOCKS_IPC), data, reply, option);
370 if (FAILED(result)) {
371 HiLog::Error(LABEL, "Send request failed!");
372 return result;
373 }
374
375 ErrCode errCode = reply.ReadInt32();
376 if (FAILED(errCode)) {
377 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
378 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RESET_RUNNING_LOCKS_IPC));
379 return errCode;
380 }
381
382 return ERR_OK;
383 }
384
RebootDeviceIpc(const std::string & reason,int32_t & powerError)385 int32_t PowerMgrServiceTestProxy::RebootDeviceIpc(const std::string& reason, int32_t& powerError)
386 {
387 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
388
389 MessageParcel data;
390 MessageParcel reply;
391 MessageOption option(MessageOption::TF_SYNC);
392
393 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
394 HiLog::Error(LABEL, "Write interface token failed!");
395 return ERR_INVALID_VALUE;
396 }
397
398 if (!data.WriteString16(Str8ToStr16(reason))) {
399 HiLog::Error(LABEL, "Write [reason] failed!");
400 return ERR_INVALID_DATA;
401 }
402
403 int32_t result = stub_->OnRemoteRequest(
404 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_IPC), data, reply, option);
405 if (FAILED(result)) {
406 HiLog::Error(LABEL, "Send request failed!");
407 return result;
408 }
409
410 ErrCode errCode = reply.ReadInt32();
411 if (FAILED(errCode)) {
412 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
413 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_IPC));
414 return errCode;
415 }
416
417 powerError = reply.ReadInt32();
418 return ERR_OK;
419 }
420
ShutDownDeviceIpc(const std::string & reason,int32_t & powerError)421 int32_t PowerMgrServiceTestProxy::ShutDownDeviceIpc(const std::string& reason, int32_t& powerError)
422 {
423 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
424
425 MessageParcel data;
426 MessageParcel reply;
427 MessageOption option(MessageOption::TF_SYNC);
428
429 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
430 HiLog::Error(LABEL, "Write interface token failed!");
431 return ERR_INVALID_VALUE;
432 }
433
434 if (!data.WriteString16(Str8ToStr16(reason))) {
435 HiLog::Error(LABEL, "Write [reason] failed!");
436 return ERR_INVALID_DATA;
437 }
438
439 int32_t result = stub_->OnRemoteRequest(
440 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SHUT_DOWN_DEVICE_IPC), data, reply, option);
441 if (FAILED(result)) {
442 HiLog::Error(LABEL, "Send request failed!");
443 return result;
444 }
445
446 ErrCode errCode = reply.ReadInt32();
447 if (FAILED(errCode)) {
448 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
449 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SHUT_DOWN_DEVICE_IPC));
450 return errCode;
451 }
452
453 powerError = reply.ReadInt32();
454 return ERR_OK;
455 }
456
SuspendDeviceIpc(int64_t callTimeMs,int32_t reasonValue,bool suspendImmed,const std::string & apiVersion,int32_t & powerError)457 int32_t PowerMgrServiceTestProxy::SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue,
458 bool suspendImmed, const std::string& apiVersion, int32_t& powerError)
459 {
460 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
461
462 MessageParcel data;
463 MessageParcel reply;
464 MessageOption option(MessageOption::TF_SYNC);
465
466 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
467 HiLog::Error(LABEL, "Write interface token failed!");
468 return ERR_INVALID_VALUE;
469 }
470
471 if (!data.WriteInt64(callTimeMs)) {
472 HiLog::Error(LABEL, "Write [callTimeMs] failed!");
473 return ERR_INVALID_DATA;
474 }
475 if (!data.WriteInt32(reasonValue)) {
476 HiLog::Error(LABEL, "Write [reasonValue] failed!");
477 return ERR_INVALID_DATA;
478 }
479 if (!data.WriteInt32(suspendImmed ? 1 : 0)) {
480 HiLog::Error(LABEL, "Write [suspendImmed] failed!");
481 return ERR_INVALID_DATA;
482 }
483 if (!data.WriteString16(Str8ToStr16(apiVersion))) {
484 HiLog::Error(LABEL, "Write [apiVersion] failed!");
485 return ERR_INVALID_DATA;
486 }
487
488 int32_t result = stub_->OnRemoteRequest(
489 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SUSPEND_DEVICE_IPC), data, reply, option);
490 if (FAILED(result)) {
491 HiLog::Error(LABEL, "Send request failed!");
492 return result;
493 }
494
495 ErrCode errCode = reply.ReadInt32();
496 if (FAILED(errCode)) {
497 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
498 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SUSPEND_DEVICE_IPC));
499 return errCode;
500 }
501
502 powerError = reply.ReadInt32();
503 return ERR_OK;
504 }
505
WakeupDeviceIpc(int64_t callTimeMs,int32_t reasonValue,const std::string & details,const std::string & apiVersion,int32_t & powerError)506 int32_t PowerMgrServiceTestProxy::WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue,
507 const std::string& details, const std::string& apiVersion, int32_t& powerError)
508 {
509 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
510
511 MessageParcel data;
512 MessageParcel reply;
513 MessageOption option(MessageOption::TF_SYNC);
514
515 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
516 HiLog::Error(LABEL, "Write interface token failed!");
517 return ERR_INVALID_VALUE;
518 }
519
520 if (!data.WriteInt64(callTimeMs)) {
521 HiLog::Error(LABEL, "Write [callTimeMs] failed!");
522 return ERR_INVALID_DATA;
523 }
524 if (!data.WriteInt32(reasonValue)) {
525 HiLog::Error(LABEL, "Write [reasonValue] failed!");
526 return ERR_INVALID_DATA;
527 }
528 if (!data.WriteString16(Str8ToStr16(details))) {
529 HiLog::Error(LABEL, "Write [details] failed!");
530 return ERR_INVALID_DATA;
531 }
532 if (!data.WriteString16(Str8ToStr16(apiVersion))) {
533 HiLog::Error(LABEL, "Write [apiVersion] failed!");
534 return ERR_INVALID_DATA;
535 }
536
537 int32_t result = stub_->OnRemoteRequest(
538 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_WAKEUP_DEVICE_IPC), data, reply, option);
539 if (FAILED(result)) {
540 HiLog::Error(LABEL, "Send request failed!");
541 return result;
542 }
543
544 ErrCode errCode = reply.ReadInt32();
545 if (FAILED(errCode)) {
546 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
547 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_WAKEUP_DEVICE_IPC));
548 return errCode;
549 }
550
551 powerError = reply.ReadInt32();
552 return ERR_OK;
553 }
554
RefreshActivityIpc(int64_t callTimeMs,int32_t activityType,bool needChangeBacklight)555 int32_t PowerMgrServiceTestProxy::RefreshActivityIpc(int64_t callTimeMs, int32_t activityType, bool needChangeBacklight)
556 {
557 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
558
559 MessageParcel data;
560 MessageParcel reply;
561 MessageOption option(MessageOption::TF_SYNC);
562
563 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
564 HiLog::Error(LABEL, "Write interface token failed!");
565 return ERR_INVALID_VALUE;
566 }
567
568 if (!data.WriteInt64(callTimeMs)) {
569 HiLog::Error(LABEL, "Write [callTimeMs] failed!");
570 return ERR_INVALID_DATA;
571 }
572 if (!data.WriteInt32(activityType)) {
573 HiLog::Error(LABEL, "Write [activityType] failed!");
574 return ERR_INVALID_DATA;
575 }
576 if (!data.WriteInt32(needChangeBacklight ? 1 : 0)) {
577 HiLog::Error(LABEL, "Write [needChangeBacklight] failed!");
578 return ERR_INVALID_DATA;
579 }
580
581 uint32_t code = static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REFRESH_ACTIVITY_IPC);
582 int32_t result = stub_->OnRemoteRequest(code, data, reply, option);
583 if (FAILED(result)) {
584 HiLog::Error(LABEL, "Send request failed!");
585 return result;
586 }
587
588 ErrCode errCode = reply.ReadInt32();
589 if (FAILED(errCode)) {
590 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", code);
591 return errCode;
592 }
593
594 return ERR_OK;
595 }
596
OverrideScreenOffTimeIpc(int64_t timeout,int32_t & powerError)597 int32_t PowerMgrServiceTestProxy::OverrideScreenOffTimeIpc(int64_t timeout, int32_t& powerError)
598 {
599 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
600
601 MessageParcel data;
602 MessageParcel reply;
603 MessageOption option(MessageOption::TF_SYNC);
604
605 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
606 HiLog::Error(LABEL, "Write interface token failed!");
607 return ERR_INVALID_VALUE;
608 }
609
610 if (!data.WriteInt64(timeout)) {
611 HiLog::Error(LABEL, "Write [timeout] failed!");
612 return ERR_INVALID_DATA;
613 }
614
615 int32_t result = stub_->OnRemoteRequest(
616 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_OVERRIDE_SCREEN_OFF_TIME_IPC), data, reply, option);
617 if (FAILED(result)) {
618 HiLog::Error(LABEL, "Send request failed!");
619 return result;
620 }
621
622 ErrCode errCode = reply.ReadInt32();
623 if (FAILED(errCode)) {
624 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
625 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_OVERRIDE_SCREEN_OFF_TIME_IPC));
626 return errCode;
627 }
628
629 powerError = reply.ReadInt32();
630 return ERR_OK;
631 }
632
RestoreScreenOffTimeIpc(const std::string & apiVersion,int32_t & powerError)633 int32_t PowerMgrServiceTestProxy::RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError)
634 {
635 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
636
637 MessageParcel data;
638 MessageParcel reply;
639 MessageOption option(MessageOption::TF_SYNC);
640
641 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
642 HiLog::Error(LABEL, "Write interface token failed!");
643 return ERR_INVALID_VALUE;
644 }
645
646 if (!data.WriteString16(Str8ToStr16(apiVersion))) {
647 HiLog::Error(LABEL, "Write [apiVersion] failed!");
648 return ERR_INVALID_DATA;
649 }
650
651 int32_t result = stub_->OnRemoteRequest(
652 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RESTORE_SCREEN_OFF_TIME_IPC), data, reply, option);
653 if (FAILED(result)) {
654 HiLog::Error(LABEL, "Send request failed!");
655 return result;
656 }
657
658 ErrCode errCode = reply.ReadInt32();
659 if (FAILED(errCode)) {
660 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
661 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_RESTORE_SCREEN_OFF_TIME_IPC));
662 return errCode;
663 }
664
665 powerError = reply.ReadInt32();
666 return ERR_OK;
667 }
668
ForceSuspendDeviceIpc(int64_t callTimeMs)669 int32_t PowerMgrServiceTestProxy::ForceSuspendDeviceIpc(int64_t callTimeMs)
670 {
671 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
672
673 MessageParcel data;
674 MessageParcel reply;
675 MessageOption option;
676
677 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
678 HiLog::Error(LABEL, "Write interface token failed!");
679 return ERR_INVALID_VALUE;
680 }
681
682 if (!data.WriteInt64(callTimeMs)) {
683 HiLog::Error(LABEL, "Write [callTimeMs] failed!");
684 return ERR_INVALID_DATA;
685 }
686
687 int32_t result = stub_->OnRemoteRequest(
688 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_FORCE_SUSPEND_DEVICE_IPC), data, reply, option);
689 if (FAILED(result)) {
690 HiLog::Error(LABEL, "Send request failed!");
691 return result;
692 }
693 int32_t error = ERR_OK;
694 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, ERR_OK);
695 return error;
696 }
697
GetStateIpc(int32_t & powerState)698 int32_t PowerMgrServiceTestProxy::GetStateIpc(int32_t& powerState)
699 {
700 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
701
702 MessageParcel data;
703 MessageParcel reply;
704 MessageOption option(MessageOption::TF_SYNC);
705
706 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
707 HiLog::Error(LABEL, "Write interface token failed!");
708 return ERR_INVALID_VALUE;
709 }
710
711 int32_t result = stub_->OnRemoteRequest(
712 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_GET_STATE_IPC), data, reply, option);
713 if (FAILED(result)) {
714 HiLog::Error(LABEL, "Send request failed!");
715 return result;
716 }
717
718 ErrCode errCode = reply.ReadInt32();
719 if (FAILED(errCode)) {
720 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
721 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_GET_STATE_IPC));
722 return errCode;
723 }
724
725 powerState = reply.ReadInt32();
726 return ERR_OK;
727 }
728
IsScreenOnIpc(bool needPrintLog,bool & isScreenOn)729 int32_t PowerMgrServiceTestProxy::IsScreenOnIpc(bool needPrintLog, bool& isScreenOn)
730 {
731 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
732
733 MessageParcel data;
734 MessageParcel reply;
735 MessageOption option(MessageOption::TF_SYNC);
736
737 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
738 HiLog::Error(LABEL, "Write interface token failed!");
739 return ERR_INVALID_VALUE;
740 }
741
742 if (!data.WriteInt32(needPrintLog ? 1 : 0)) {
743 HiLog::Error(LABEL, "Write [needPrintLog] failed!");
744 return ERR_INVALID_DATA;
745 }
746
747 int32_t result = stub_->OnRemoteRequest(
748 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_SCREEN_ON_IPC), data, reply, option);
749 if (FAILED(result)) {
750 HiLog::Error(LABEL, "Send request failed!");
751 return result;
752 }
753
754 ErrCode errCode = reply.ReadInt32();
755 if (FAILED(errCode)) {
756 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
757 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_SCREEN_ON_IPC));
758 return errCode;
759 }
760
761 isScreenOn = reply.ReadInt32() == 1 ? true : false;
762 return ERR_OK;
763 }
764
IsForceSleepingIpc(bool & isForceSleeping)765 int32_t PowerMgrServiceTestProxy::IsForceSleepingIpc(bool& isForceSleeping)
766 {
767 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
768
769 MessageParcel data;
770 MessageParcel reply;
771 MessageOption option(MessageOption::TF_SYNC);
772
773 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
774 HiLog::Error(LABEL, "Write descriptor failed");
775 return ERR_INVALID_VALUE;
776 }
777
778 int32_t result = stub_->OnRemoteRequest(
779 static_cast<int>(IPowerMgrIpcCode::COMMAND_IS_FORCE_SLEEPING_IPC), data, reply, option);
780 if (FAILED(result)) {
781 HiLog::Error(LABEL, "Send request failed!");
782 return result;
783 }
784
785 ErrCode errCode = reply.ReadInt32();
786 if (FAILED(errCode)) {
787 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
788 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_FORCE_SLEEPING_IPC));
789 return errCode;
790 }
791
792 isForceSleeping = reply.ReadInt32() == 1 ? true : false;
793 return ERR_OK;
794 }
795
RegisterPowerStateCallbackIpc(const sptr<IPowerStateCallback> & powerCallback,bool isSync)796 int32_t PowerMgrServiceTestProxy::RegisterPowerStateCallbackIpc(
797 const sptr<IPowerStateCallback>& powerCallback, bool isSync)
798 {
799 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
800
801 MessageParcel data;
802 MessageParcel reply;
803 MessageOption option(MessageOption::TF_SYNC);
804
805 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
806 HiLog::Error(LABEL, "Write interface token failed!");
807 return ERR_INVALID_VALUE;
808 }
809
810 if (powerCallback == nullptr) {
811 HiLog::Error(LABEL, "powerCallback is nullptr!");
812 return ERR_INVALID_DATA;
813 }
814 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
815 HiLog::Error(LABEL, "Write [powerCallback] failed!");
816 return ERR_INVALID_DATA;
817 }
818 if (!data.WriteInt32(isSync ? 1 : 0)) {
819 HiLog::Error(LABEL, "Write [isSync] failed!");
820 return ERR_INVALID_DATA;
821 }
822
823 int32_t result = stub_->OnRemoteRequest(
824 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_STATE_CALLBACK_IPC), data, reply, option);
825 if (FAILED(result)) {
826 HiLog::Error(LABEL, "Send request failed!");
827 return result;
828 }
829
830 ErrCode errCode = reply.ReadInt32();
831 if (FAILED(errCode)) {
832 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
833 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_STATE_CALLBACK_IPC));
834 return errCode;
835 }
836
837 return ERR_OK;
838 }
839
UnRegisterPowerStateCallbackIpc(const sptr<IPowerStateCallback> & powerCallback)840 int32_t PowerMgrServiceTestProxy::UnRegisterPowerStateCallbackIpc(const sptr<IPowerStateCallback>& powerCallback)
841 {
842 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
843
844 MessageParcel data;
845 MessageParcel reply;
846 MessageOption option(MessageOption::TF_SYNC);
847
848 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
849 HiLog::Error(LABEL, "Write interface token failed!");
850 return ERR_INVALID_VALUE;
851 }
852
853 if (powerCallback == nullptr) {
854 HiLog::Error(LABEL, "powerCallback is nullptr!");
855 return ERR_INVALID_DATA;
856 }
857 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
858 HiLog::Error(LABEL, "Write [powerCallback] failed!");
859 return ERR_INVALID_DATA;
860 }
861
862 int32_t result = stub_->OnRemoteRequest(
863 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_STATE_CALLBACK_IPC), data, reply, option);
864 if (FAILED(result)) {
865 HiLog::Error(LABEL, "Send request failed!");
866 return result;
867 }
868
869 ErrCode errCode = reply.ReadInt32();
870 if (FAILED(errCode)) {
871 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
872 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_STATE_CALLBACK_IPC));
873 return errCode;
874 }
875
876 return ERR_OK;
877 }
878
RegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback> & powerCallback)879 int32_t PowerMgrServiceTestProxy::RegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback>& powerCallback)
880 {
881 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
882
883 MessageParcel data;
884 MessageParcel reply;
885 MessageOption option(MessageOption::TF_SYNC);
886
887 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
888 HiLog::Error(LABEL, "Write interface token failed!");
889 return ERR_INVALID_VALUE;
890 }
891
892 if (powerCallback == nullptr) {
893 HiLog::Error(LABEL, "powerCallback is nullptr!");
894 return ERR_INVALID_DATA;
895 }
896 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
897 HiLog::Error(LABEL, "Write [powerCallback] failed!");
898 return ERR_INVALID_DATA;
899 }
900
901 int32_t result = stub_->OnRemoteRequest(
902 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_MODE_CALLBACK_IPC), data, reply, option);
903 if (FAILED(result)) {
904 HiLog::Error(LABEL, "Send request failed!");
905 return result;
906 }
907
908 ErrCode errCode = reply.ReadInt32();
909 if (FAILED(errCode)) {
910 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
911 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_MODE_CALLBACK_IPC));
912 return errCode;
913 }
914
915 return ERR_OK;
916 }
917
UnRegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback> & powerCallback)918 int32_t PowerMgrServiceTestProxy::UnRegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback>& powerCallback)
919 {
920 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
921
922 MessageParcel data;
923 MessageParcel reply;
924 MessageOption option(MessageOption::TF_SYNC);
925
926 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
927 HiLog::Error(LABEL, "Write interface token failed!");
928 return ERR_INVALID_VALUE;
929 }
930
931 if (powerCallback == nullptr) {
932 HiLog::Error(LABEL, "powerCallback is nullptr!");
933 return ERR_INVALID_DATA;
934 }
935 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
936 HiLog::Error(LABEL, "Write [powerCallback] failed!");
937 return ERR_INVALID_DATA;
938 }
939
940 int32_t result = stub_->OnRemoteRequest(
941 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_MODE_CALLBACK_IPC), data, reply, option);
942 if (FAILED(result)) {
943 HiLog::Error(LABEL, "Send request failed!");
944 return result;
945 }
946
947 ErrCode errCode = reply.ReadInt32();
948 if (FAILED(errCode)) {
949 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
950 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_MODE_CALLBACK_IPC));
951 return errCode;
952 }
953
954 return ERR_OK;
955 }
956
RegisterScreenStateCallbackIpc(int32_t remainTime,const sptr<IScreenOffPreCallback> & powerCallback)957 int32_t PowerMgrServiceTestProxy::RegisterScreenStateCallbackIpc(
958 int32_t remainTime, const sptr<IScreenOffPreCallback>& powerCallback)
959 {
960 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
961
962 MessageParcel data;
963 MessageParcel reply;
964 MessageOption option(MessageOption::TF_SYNC);
965
966 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
967 HiLog::Error(LABEL, "Write interface token failed!");
968 return ERR_INVALID_VALUE;
969 }
970
971 if (!data.WriteInt32(remainTime)) {
972 HiLog::Error(LABEL, "Write [remainTime] failed!");
973 return ERR_INVALID_DATA;
974 }
975 if (powerCallback == nullptr) {
976 HiLog::Error(LABEL, "powerCallback is nullptr!");
977 return ERR_INVALID_DATA;
978 }
979 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
980 HiLog::Error(LABEL, "Write [powerCallback] failed!");
981 return ERR_INVALID_DATA;
982 }
983
984 int32_t result = stub_->OnRemoteRequest(
985 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, reply, option);
986 if (FAILED(result)) {
987 HiLog::Error(LABEL, "Send request failed!");
988 return result;
989 }
990
991 ErrCode errCode = reply.ReadInt32();
992 if (FAILED(errCode)) {
993 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
994 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_SCREEN_STATE_CALLBACK_IPC));
995 return errCode;
996 }
997
998 return ERR_OK;
999 }
1000
UnRegisterScreenStateCallbackIpc(const sptr<IScreenOffPreCallback> & powerCallback)1001 int32_t PowerMgrServiceTestProxy::UnRegisterScreenStateCallbackIpc(const sptr<IScreenOffPreCallback>& powerCallback)
1002 {
1003 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1004
1005 MessageParcel data;
1006 MessageParcel reply;
1007 MessageOption option(MessageOption::TF_SYNC);
1008
1009 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1010 HiLog::Error(LABEL, "Write interface token failed!");
1011 return ERR_INVALID_VALUE;
1012 }
1013
1014 if (powerCallback == nullptr) {
1015 HiLog::Error(LABEL, "powerCallback is nullptr!");
1016 return ERR_INVALID_DATA;
1017 }
1018 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
1019 HiLog::Error(LABEL, "Write [powerCallback] failed!");
1020 return ERR_INVALID_DATA;
1021 }
1022
1023 int32_t result = stub_->OnRemoteRequest(
1024 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, reply, option);
1025 if (FAILED(result)) {
1026 HiLog::Error(LABEL, "Send request failed!");
1027 return result;
1028 }
1029
1030 ErrCode errCode = reply.ReadInt32();
1031 if (FAILED(errCode)) {
1032 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1033 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SCREEN_STATE_CALLBACK_IPC));
1034 return errCode;
1035 }
1036
1037 return ERR_OK;
1038 }
1039
RegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback> & powerCallback)1040 int32_t PowerMgrServiceTestProxy::RegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback>& powerCallback)
1041 {
1042 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1043
1044 MessageParcel data;
1045 MessageParcel reply;
1046 MessageOption option(MessageOption::TF_SYNC);
1047
1048 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1049 HiLog::Error(LABEL, "Write interface token failed!");
1050 return ERR_INVALID_VALUE;
1051 }
1052
1053 if (powerCallback == nullptr) {
1054 HiLog::Error(LABEL, "powerCallback is nullptr!");
1055 return ERR_INVALID_DATA;
1056 }
1057 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
1058 HiLog::Error(LABEL, "Write [powerCallback] failed!");
1059 return ERR_INVALID_DATA;
1060 }
1061
1062 int32_t result = stub_->OnRemoteRequest(
1063 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, reply, option);
1064 if (FAILED(result)) {
1065 HiLog::Error(LABEL, "Send request failed!");
1066 return result;
1067 }
1068
1069 ErrCode errCode = reply.ReadInt32();
1070 if (FAILED(errCode)) {
1071 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1072 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_REGISTER_RUNNING_LOCK_CALLBACK_IPC));
1073 return errCode;
1074 }
1075
1076 return ERR_OK;
1077 }
1078
UnRegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback> & powerCallback)1079 int32_t PowerMgrServiceTestProxy::UnRegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback>& powerCallback)
1080 {
1081 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1082
1083 MessageParcel data;
1084 MessageParcel reply;
1085 MessageOption option(MessageOption::TF_SYNC);
1086
1087 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1088 HiLog::Error(LABEL, "Write interface token failed!");
1089 return ERR_INVALID_VALUE;
1090 }
1091
1092 if (powerCallback == nullptr) {
1093 HiLog::Error(LABEL, "powerCallback is nullptr!");
1094 return ERR_INVALID_DATA;
1095 }
1096 if (!data.WriteRemoteObject(powerCallback->AsObject())) {
1097 HiLog::Error(LABEL, "Write [powerCallback] failed!");
1098 return ERR_INVALID_DATA;
1099 }
1100
1101 int32_t result = stub_->OnRemoteRequest(
1102 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, reply, option);
1103 if (FAILED(result)) {
1104 HiLog::Error(LABEL, "Send request failed!");
1105 return result;
1106 }
1107
1108 ErrCode errCode = reply.ReadInt32();
1109 if (FAILED(errCode)) {
1110 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1111 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_RUNNING_LOCK_CALLBACK_IPC));
1112 return errCode;
1113 }
1114
1115 return ERR_OK;
1116 }
1117
1118 #ifdef POWER_MANAGER_TAKEOVER_SUSPEND
RegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback> & callback)1119 bool PowerMgrServiceTestProxy::RegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback>& callback)
1120 {
1121 RETURN_IF_WITH_RET((stub_ == nullptr || (callback == nullptr)), false);
1122
1123 MessageParcel data;
1124 MessageParcel reply;
1125 MessageOption option;
1126
1127 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1128 POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
1129 return false;
1130 }
1131
1132 data.WriteRemoteObject(callback->AsObject());
1133
1134 int ret = stub_->OnRemoteRequest(
1135 static_cast<int>(IPowerMgrIpcCode::COMMAND_REGISTER_SUSPEND_TAKEOVER_CALLBACK_IPC),
1136 data, reply, option);
1137 if (ret != ERR_OK) {
1138 POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
1139 return false;
1140 }
1141 return true;
1142 }
1143
UnRegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback> & callback)1144 bool PowerMgrServiceTestProxy::UnRegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback>& callback)
1145 {
1146 RETURN_IF_WITH_RET((stub_ == nullptr || (callback == nullptr)), false);
1147
1148 MessageParcel data;
1149 MessageParcel reply;
1150 MessageOption option;
1151
1152 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1153 POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
1154 return false;
1155 }
1156
1157 data.WriteRemoteObject(callback->AsObject());
1158
1159 int ret = stub_->OnRemoteRequest(
1160 static_cast<int>(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SUSPEND_TAKEOVER_CALLBACK_IPC),
1161 data, reply, option);
1162 if (ret != ERR_OK) {
1163 POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
1164 return false;
1165 }
1166 return true;
1167 }
1168 #endif
1169
SetDisplaySuspendIpc(bool enable)1170 int32_t PowerMgrServiceTestProxy::SetDisplaySuspendIpc(bool enable)
1171 {
1172 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1173
1174 MessageParcel data;
1175 MessageParcel reply;
1176 MessageOption option(MessageOption::TF_SYNC);
1177
1178 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1179 HiLog::Error(LABEL, "Write interface token failed!");
1180 return ERR_INVALID_VALUE;
1181 }
1182
1183 if (!data.WriteInt32(enable ? 1 : 0)) {
1184 HiLog::Error(LABEL, "Write [enable] failed!");
1185 return ERR_INVALID_DATA;
1186 }
1187
1188 int32_t result = stub_->OnRemoteRequest(
1189 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SET_DISPLAY_SUSPEND_IPC), data, reply, option);
1190 if (FAILED(result)) {
1191 HiLog::Error(LABEL, "Send request failed!");
1192 return result;
1193 }
1194
1195 ErrCode errCode = reply.ReadInt32();
1196 if (FAILED(errCode)) {
1197 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1198 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SET_DISPLAY_SUSPEND_IPC));
1199 return errCode;
1200 }
1201
1202 return ERR_OK;
1203 }
1204
SetDeviceModeIpc(int32_t modeValue,int32_t & powerError)1205 int32_t PowerMgrServiceTestProxy::SetDeviceModeIpc(int32_t modeValue, int32_t& powerError)
1206 {
1207 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1208
1209 MessageParcel data;
1210 MessageParcel reply;
1211 MessageOption option(MessageOption::TF_SYNC);
1212
1213 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1214 HiLog::Error(LABEL, "Write interface token failed!");
1215 return ERR_INVALID_VALUE;
1216 }
1217
1218 if (!data.WriteInt32(modeValue)) {
1219 HiLog::Error(LABEL, "Write [modeValue] failed!");
1220 return ERR_INVALID_DATA;
1221 }
1222
1223 int32_t result = stub_->OnRemoteRequest(
1224 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SET_DEVICE_MODE_IPC), data, reply, option);
1225 if (FAILED(result)) {
1226 HiLog::Error(LABEL, "Send request failed!");
1227 return result;
1228 }
1229
1230 ErrCode errCode = reply.ReadInt32();
1231 if (FAILED(errCode)) {
1232 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1233 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SET_DEVICE_MODE_IPC));
1234 return errCode;
1235 }
1236
1237 powerError = reply.ReadInt32();
1238 return ERR_OK;
1239 }
1240
GetDeviceModeIpc(int32_t & powerMode)1241 int32_t PowerMgrServiceTestProxy::GetDeviceModeIpc(int32_t& powerMode)
1242 {
1243 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1244
1245 MessageParcel data;
1246 MessageParcel reply;
1247 MessageOption option(MessageOption::TF_SYNC);
1248
1249 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1250 HiLog::Error(LABEL, "Write interface token failed!");
1251 return ERR_INVALID_VALUE;
1252 }
1253
1254 int32_t result = stub_->OnRemoteRequest(
1255 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_GET_DEVICE_MODE_IPC), data, reply, option);
1256 if (FAILED(result)) {
1257 HiLog::Error(LABEL, "Send request failed!");
1258 return result;
1259 }
1260
1261 ErrCode errCode = reply.ReadInt32();
1262 if (FAILED(errCode)) {
1263 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1264 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_GET_DEVICE_MODE_IPC));
1265 return errCode;
1266 }
1267
1268 powerMode = reply.ReadInt32();
1269 return ERR_OK;
1270 }
1271
ShellDumpIpc(const std::vector<std::string> & args,uint32_t argc,std::string & returnDump)1272 int32_t PowerMgrServiceTestProxy::ShellDumpIpc(const std::vector<std::string>& args,
1273 uint32_t argc, std::string& returnDump)
1274 {
1275 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1276
1277 MessageParcel data;
1278 MessageParcel reply;
1279 MessageOption option(MessageOption::TF_SYNC);
1280
1281 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1282 HiLog::Error(LABEL, "Write interface token failed!");
1283 return ERR_INVALID_VALUE;
1284 }
1285
1286 if (args.size() > static_cast<size_t>(VECTOR_MAX_SIZE)) {
1287 HiLog::Error(LABEL, "The vector/array size exceeds the security limit!");
1288 return ERR_INVALID_DATA;
1289 }
1290 data.WriteInt32(args.size());
1291 for (auto it3 = args.begin(); it3 != args.end(); ++it3) {
1292 if (!data.WriteString16(Str8ToStr16((*it3)))) {
1293 HiLog::Error(LABEL, "Write [(*it3)] failed!");
1294 return ERR_INVALID_DATA;
1295 }
1296 }
1297 if (!data.WriteUint32(argc)) {
1298 HiLog::Error(LABEL, "Write [argc] failed!");
1299 return ERR_INVALID_DATA;
1300 }
1301
1302 int32_t result = stub_->OnRemoteRequest(
1303 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SHELL_DUMP_IPC), data, reply, option);
1304 if (FAILED(result)) {
1305 HiLog::Error(LABEL, "Send request failed!");
1306 return result;
1307 }
1308
1309 ErrCode errCode = reply.ReadInt32();
1310 if (FAILED(errCode)) {
1311 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1312 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_SHELL_DUMP_IPC));
1313 return errCode;
1314 }
1315
1316 returnDump = Str16ToStr8(reply.ReadString16());
1317 return ERR_OK;
1318 }
1319
IsStandbyIpc(bool & isStandby,int32_t & powerError)1320 int32_t PowerMgrServiceTestProxy::IsStandbyIpc(bool& isStandby, int32_t& powerError)
1321 {
1322 RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA);
1323
1324 MessageParcel data;
1325 MessageParcel reply;
1326 MessageOption option(MessageOption::TF_SYNC);
1327
1328 if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1329 HiLog::Error(LABEL, "Write interface token failed!");
1330 return ERR_INVALID_VALUE;
1331 }
1332
1333 int32_t result = stub_->OnRemoteRequest(
1334 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_STANDBY_IPC), data, reply, option);
1335 if (FAILED(result)) {
1336 HiLog::Error(LABEL, "Send request failed!");
1337 return result;
1338 }
1339
1340 ErrCode errCode = reply.ReadInt32();
1341 if (FAILED(errCode)) {
1342 HiLog::Error(LABEL, "Read result failed, code is: %{public}d.",
1343 static_cast<uint32_t>(IPowerMgrIpcCode::COMMAND_IS_STANDBY_IPC));
1344 return errCode;
1345 }
1346
1347 isStandby = reply.ReadInt32() == 1 ? true : false;
1348 powerError = reply.ReadInt32();
1349 return ERR_OK;
1350 }
1351 } // namespace PowerMgr
1352 } // namespace OHOS
1353