1 /*
2 * Copyright (c) 2023 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 "ability_manager_proxy.h"
17
18 #include "errors.h"
19 #include "string_ex.h"
20
21 #include "ability_connect_callback_proxy.h"
22 #include "ability_connect_callback_stub.h"
23 #include "ability_manager_errors.h"
24 #include "ability_scheduler_proxy.h"
25 #include "ability_scheduler_stub.h"
26 #include "ability_util.h"
27 #include "appexecfwk_errors.h"
28 #include "session_info.h"
29
30 namespace OHOS {
31 namespace AAFwk {
32 constexpr int32_t CYCLE_LIMIT = 1000;
WriteInterfaceToken(MessageParcel & data)33 bool AbilityManagerProxy::WriteInterfaceToken(MessageParcel &data)
34 {
35 if (!data.WriteInterfaceToken(AbilityManagerProxy::GetDescriptor())) {
36 HILOG_ERROR("write interface token failed.");
37 return false;
38 }
39 return true;
40 }
41
StartAbility(const Want & want,int32_t userId,int requestCode)42 int AbilityManagerProxy::StartAbility(const Want &want, int32_t userId, int requestCode)
43 {
44 int error;
45 MessageParcel data;
46 MessageParcel reply;
47 MessageOption option;
48
49 if (!WriteInterfaceToken(data)) {
50 return INNER_ERR;
51 }
52 if (!data.WriteParcelable(&want)) {
53 HILOG_ERROR("want write failed.");
54 return INNER_ERR;
55 }
56
57 if (!data.WriteInt32(userId)) {
58 HILOG_ERROR("userId write failed.");
59 return INNER_ERR;
60 }
61
62 if (!data.WriteInt32(requestCode)) {
63 HILOG_ERROR("requestCode write failed.");
64 return INNER_ERR;
65 }
66
67 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY, data, reply, option);
68 if (error != NO_ERROR) {
69 HILOG_ERROR("Send request error: %{public}d", error);
70 return error;
71 }
72 return reply.ReadInt32();
73 }
74
GetTopAbility()75 AppExecFwk::ElementName AbilityManagerProxy::GetTopAbility()
76 {
77 MessageParcel data;
78 MessageParcel reply;
79 MessageOption option;
80 if (!WriteInterfaceToken(data)) {
81 return {};
82 }
83
84 int error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY, data, reply, option);
85 if (error != NO_ERROR) {
86 HILOG_ERROR("Send request error: %{public}d", error);
87 return {};
88 }
89 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
90 if (!name) {
91 HILOG_ERROR("Read info failed.");
92 return {};
93 }
94 AppExecFwk::ElementName result = *name;
95 return result;
96 }
97
GetElementNameByToken(const sptr<IRemoteObject> & token)98 AppExecFwk::ElementName AbilityManagerProxy::GetElementNameByToken(const sptr<IRemoteObject> &token)
99 {
100 MessageParcel data;
101 MessageParcel reply;
102 MessageOption option;
103 if (!WriteInterfaceToken(data)) {
104 return {};
105 }
106 if (!data.WriteRemoteObject(token)) {
107 return {};
108 }
109 int error = SendRequest(AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN, data, reply, option);
110 if (error != NO_ERROR) {
111 HILOG_ERROR("Send request error: %{public}d", error);
112 return {};
113 }
114 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
115 if (!name) {
116 HILOG_ERROR("Read info failed.");
117 return {};
118 }
119 AppExecFwk::ElementName result = *name;
120 return result;
121 }
122
StartAbility(const Want & want,const AbilityStartSetting & abilityStartSetting,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)123 int AbilityManagerProxy::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
124 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
125 {
126 int error;
127 MessageParcel data;
128 MessageParcel reply;
129 MessageOption option;
130 if (!WriteInterfaceToken(data)) {
131 return INNER_ERR;
132 }
133 if (!data.WriteParcelable(&want)) {
134 HILOG_ERROR("want write failed.");
135 return INNER_ERR;
136 }
137 if (!data.WriteParcelable(&abilityStartSetting)) {
138 HILOG_ERROR("abilityStartSetting write failed.");
139 return INNER_ERR;
140 }
141 if (callerToken) {
142 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
143 HILOG_ERROR("flag and callerToken write failed.");
144 return INNER_ERR;
145 }
146 } else {
147 if (!data.WriteBool(false)) {
148 HILOG_ERROR("flag write failed.");
149 return INNER_ERR;
150 }
151 }
152 if (!data.WriteInt32(userId)) {
153 HILOG_ERROR("userId write failed.");
154 return INNER_ERR;
155 }
156 if (!data.WriteInt32(requestCode)) {
157 HILOG_ERROR("requestCode write failed.");
158 return INNER_ERR;
159 }
160 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS, data, reply, option);
161 if (error != NO_ERROR) {
162 HILOG_ERROR("Send request error: %{public}d", error);
163 return error;
164 }
165 return reply.ReadInt32();
166 }
167
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)168 int AbilityManagerProxy::StartAbility(
169 const Want &want, const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
170 {
171 int error;
172 MessageParcel data;
173 MessageParcel reply;
174 MessageOption option;
175
176 if (!WriteInterfaceToken(data)) {
177 return INNER_ERR;
178 }
179 if (!data.WriteParcelable(&want)) {
180 HILOG_ERROR("want write failed.");
181 return INNER_ERR;
182 }
183 if (callerToken) {
184 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
185 HILOG_ERROR("callerToken and flag write failed.");
186 return INNER_ERR;
187 }
188 } else {
189 if (!data.WriteBool(false)) {
190 HILOG_ERROR("flag write failed.");
191 return INNER_ERR;
192 }
193 }
194 if (!data.WriteInt32(userId)) {
195 HILOG_ERROR("userId write failed.");
196 return INNER_ERR;
197 }
198 if (!data.WriteInt32(requestCode)) {
199 HILOG_ERROR("requestCode write failed.");
200 return INNER_ERR;
201 }
202 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER, data, reply, option);
203 if (error != NO_ERROR) {
204 HILOG_ERROR("Send request error: %{public}d", error);
205 return error;
206 }
207 return reply.ReadInt32();
208 }
209
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)210 int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &startOptions,
211 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
212 {
213 int error;
214 MessageParcel data;
215 MessageParcel reply;
216 MessageOption option;
217 if (!WriteInterfaceToken(data)) {
218 return INNER_ERR;
219 }
220 if (!data.WriteParcelable(&want)) {
221 HILOG_ERROR("want write failed.");
222 return INNER_ERR;
223 }
224 if (!data.WriteParcelable(&startOptions)) {
225 HILOG_ERROR("startOptions write failed.");
226 return INNER_ERR;
227 }
228 if (callerToken) {
229 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
230 HILOG_ERROR("flag and callerToken write failed.");
231 return INNER_ERR;
232 }
233 } else {
234 if (!data.WriteBool(false)) {
235 HILOG_ERROR("flag write failed.");
236 return INNER_ERR;
237 }
238 }
239 if (!data.WriteInt32(userId)) {
240 HILOG_ERROR("userId write failed.");
241 return INNER_ERR;
242 }
243 if (!data.WriteInt32(requestCode)) {
244 HILOG_ERROR("requestCode write failed.");
245 return INNER_ERR;
246 }
247 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS, data, reply, option);
248 if (error != NO_ERROR) {
249 HILOG_ERROR("Send request error: %{public}d", error);
250 return error;
251 }
252 return reply.ReadInt32();
253 }
254
StartAbilityAsCaller(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)255 int AbilityManagerProxy::StartAbilityAsCaller(
256 const Want &want, const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
257 {
258 int error;
259 MessageParcel data;
260 MessageParcel reply;
261 MessageOption option;
262
263 if (!WriteInterfaceToken(data)) {
264 return INNER_ERR;
265 }
266 if (!data.WriteParcelable(&want)) {
267 HILOG_ERROR("want write failed.");
268 return INNER_ERR;
269 }
270 if (callerToken) {
271 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
272 HILOG_ERROR("callerToken and flag write failed.");
273 return INNER_ERR;
274 }
275 } else {
276 if (!data.WriteBool(false)) {
277 HILOG_ERROR("flag write failed.");
278 return INNER_ERR;
279 }
280 }
281 if (!data.WriteInt32(userId)) {
282 HILOG_ERROR("userId write failed.");
283 return INNER_ERR;
284 }
285 if (!data.WriteInt32(requestCode)) {
286 HILOG_ERROR("requestCode write failed.");
287 return INNER_ERR;
288 }
289 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN, data, reply, option);
290 if (error != NO_ERROR) {
291 HILOG_ERROR("Send request error: %{public}d", error);
292 return error;
293 }
294 return reply.ReadInt32();
295 }
296
StartAbilityAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)297 int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const StartOptions &startOptions,
298 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
299 {
300 int error;
301 MessageParcel data;
302 MessageParcel reply;
303 MessageOption option;
304 if (!WriteInterfaceToken(data)) {
305 return INNER_ERR;
306 }
307 if (!data.WriteParcelable(&want)) {
308 HILOG_ERROR("want write failed.");
309 return INNER_ERR;
310 }
311 if (!data.WriteParcelable(&startOptions)) {
312 HILOG_ERROR("startOptions write failed.");
313 return INNER_ERR;
314 }
315 if (callerToken) {
316 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
317 HILOG_ERROR("flag and callerToken write failed.");
318 return INNER_ERR;
319 }
320 } else {
321 if (!data.WriteBool(false)) {
322 HILOG_ERROR("flag write failed.");
323 return INNER_ERR;
324 }
325 }
326 if (!data.WriteInt32(userId)) {
327 HILOG_ERROR("userId write failed.");
328 return INNER_ERR;
329 }
330 if (!data.WriteInt32(requestCode)) {
331 HILOG_ERROR("requestCode write failed.");
332 return INNER_ERR;
333 }
334 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS, data, reply, option);
335 if (error != NO_ERROR) {
336 HILOG_ERROR("Send request error: %{public}d", error);
337 return error;
338 }
339 return reply.ReadInt32();
340 }
341
CheckUISessionParams(MessageParcel & data,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)342 int AbilityManagerProxy::CheckUISessionParams(MessageParcel &data, const sptr<IRemoteObject> &callerToken,
343 const sptr<SessionInfo> &sessionInfo, int32_t userId, int requestCode)
344 {
345 if (callerToken) {
346 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
347 HILOG_ERROR("callerToken and flag write failed.");
348 return INNER_ERR;
349 }
350 } else {
351 if (!data.WriteBool(false)) {
352 HILOG_ERROR("flag write failed.");
353 return INNER_ERR;
354 }
355 }
356 if (sessionInfo) {
357 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
358 HILOG_ERROR("flag and sessionInfo write failed.");
359 return INNER_ERR;
360 }
361 } else {
362 if (!data.WriteBool(false)) {
363 HILOG_ERROR("flag write failed.");
364 return INNER_ERR;
365 }
366 }
367 if (!data.WriteInt32(userId)) {
368 HILOG_ERROR("userId write failed.");
369 return INNER_ERR;
370 }
371 if (!data.WriteInt32(requestCode)) {
372 HILOG_ERROR("requestCode write failed.");
373 return INNER_ERR;
374 }
375 return ERR_OK;
376 }
377
StartAbilityByUIContentSession(const Want & want,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)378 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want,
379 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
380 int32_t userId, int requestCode)
381 {
382 int error;
383 MessageParcel data;
384 MessageParcel reply;
385 MessageOption option;
386 if (!WriteInterfaceToken(data)) {
387 return INNER_ERR;
388 }
389 if (!data.WriteParcelable(&want)) {
390 HILOG_ERROR("want write failed.");
391 return INNER_ERR;
392 }
393 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
394 return INNER_ERR;
395 }
396 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER, data, reply, option);
397 if (error != NO_ERROR) {
398 HILOG_ERROR("Send request error: %{public}d", error);
399 return error;
400 }
401 return reply.ReadInt32();
402 }
403
StartAbilityByUIContentSession(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)404 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want, const StartOptions &startOptions,
405 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
406 int32_t userId, int requestCode)
407 {
408 int error;
409 MessageParcel data;
410 MessageParcel reply;
411 MessageOption option;
412 if (!WriteInterfaceToken(data)) {
413 return INNER_ERR;
414 }
415 if (!data.WriteParcelable(&want)) {
416 HILOG_ERROR("want write failed.");
417 return INNER_ERR;
418 }
419 if (!data.WriteParcelable(&startOptions)) {
420 HILOG_ERROR("startOptions write failed.");
421 return INNER_ERR;
422 }
423 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
424 return INNER_ERR;
425 }
426 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS, data, reply, option);
427 if (error != NO_ERROR) {
428 HILOG_ERROR("Send request error: %{public}d", error);
429 return error;
430 }
431 return reply.ReadInt32();
432 }
433
StartExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)434 int AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
435 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
436 {
437 int error;
438 MessageParcel data;
439 MessageParcel reply;
440 MessageOption option;
441 if (!WriteInterfaceToken(data)) {
442 return INNER_ERR;
443 }
444 if (!data.WriteParcelable(&want)) {
445 HILOG_ERROR("want write failed.");
446 return INNER_ERR;
447 }
448 if (callerToken) {
449 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
450 HILOG_ERROR("flag and callerToken write failed.");
451 return INNER_ERR;
452 }
453 } else {
454 if (!data.WriteBool(false)) {
455 HILOG_ERROR("flag write failed.");
456 return INNER_ERR;
457 }
458 }
459 if (!data.WriteInt32(userId)) {
460 HILOG_ERROR("StartExtensionAbility, userId write failed.");
461 return INNER_ERR;
462 }
463 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
464 HILOG_ERROR("StartExtensionAbility, extensionType write failed.");
465 return INNER_ERR;
466 }
467 error = SendRequest(AbilityManagerInterfaceCode::START_EXTENSION_ABILITY, data, reply, option);
468 if (error != NO_ERROR) {
469 HILOG_ERROR("StartExtensionAbility, Send request error: %{public}d", error);
470 return error;
471 }
472 return reply.ReadInt32();
473 }
474
StartUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int32_t userId)475 int AbilityManagerProxy::StartUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int32_t userId)
476 {
477 int error;
478 MessageParcel data;
479 MessageParcel reply;
480 MessageOption option;
481 if (!WriteInterfaceToken(data)) {
482 return INNER_ERR;
483 }
484
485 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
486 "connect ability fail, extensionSessionInfo is nullptr");
487 if (extensionSessionInfo) {
488 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
489 HILOG_ERROR("flag and extensionSessionInfo write failed.");
490 return INNER_ERR;
491 }
492 } else {
493 if (!data.WriteBool(false)) {
494 HILOG_ERROR("flag write failed.");
495 return INNER_ERR;
496 }
497 }
498
499 if (!data.WriteInt32(userId)) {
500 HILOG_ERROR("StartExtensionAbility, userId write failed.");
501 return INNER_ERR;
502 }
503
504 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY, data, reply, option);
505 if (error != NO_ERROR) {
506 HILOG_ERROR("StartExtensionAbility, Send request error: %{public}d", error);
507 return error;
508 }
509 return reply.ReadInt32();
510 }
511
StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo)512 int AbilityManagerProxy::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo)
513 {
514 MessageParcel data;
515 MessageParcel reply;
516 MessageOption option;
517 if (!WriteInterfaceToken(data)) {
518 return INNER_ERR;
519 }
520 if (sessionInfo) {
521 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
522 HILOG_ERROR("flag and sessionInfo write failed.");
523 return INNER_ERR;
524 }
525 } else {
526 if (!data.WriteBool(false)) {
527 HILOG_ERROR("flag write failed.");
528 return INNER_ERR;
529 }
530 }
531 auto error = SendRequest(AbilityManagerInterfaceCode::START_UI_ABILITY_BY_SCB, data, reply, option);
532 if (error != NO_ERROR) {
533 HILOG_ERROR("Send request error: %{public}d", error);
534 return error;
535 }
536 return reply.ReadInt32();
537 }
538
StopExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)539 int AbilityManagerProxy::StopExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
540 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
541 {
542 int error;
543 MessageParcel data;
544 MessageParcel reply;
545 MessageOption option;
546 if (!WriteInterfaceToken(data)) {
547 return INNER_ERR;
548 }
549 if (!data.WriteParcelable(&want)) {
550 HILOG_ERROR("want write failed.");
551 return INNER_ERR;
552 }
553 if (callerToken) {
554 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
555 HILOG_ERROR("flag and callerToken write failed.");
556 return INNER_ERR;
557 }
558 } else {
559 if (!data.WriteBool(false)) {
560 HILOG_ERROR("flag write failed.");
561 return INNER_ERR;
562 }
563 }
564 if (!data.WriteInt32(userId)) {
565 HILOG_ERROR("userId write failed.");
566 return INNER_ERR;
567 }
568 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
569 HILOG_ERROR("extensionType write failed.");
570 return INNER_ERR;
571 }
572 error = SendRequest(AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY, data, reply, option);
573 if (error != NO_ERROR) {
574 HILOG_ERROR("Send request error: %{public}d", error);
575 return error;
576 }
577 return reply.ReadInt32();
578 }
579
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)580 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
581 {
582 return TerminateAbility(token, resultCode, resultWant, true);
583 }
584
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant,bool flag)585 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token,
586 int resultCode, const Want *resultWant, bool flag)
587 {
588 int error;
589 MessageParcel data;
590 MessageParcel reply;
591 MessageOption option;
592
593 if (!WriteInterfaceToken(data)) {
594 return INNER_ERR;
595 }
596 if (token) {
597 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
598 HILOG_ERROR("flag and token write failed.");
599 return INNER_ERR;
600 }
601 } else {
602 if (!data.WriteBool(false)) {
603 HILOG_ERROR("flag write failed.");
604 return INNER_ERR;
605 }
606 }
607 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
608 HILOG_ERROR("data write failed.");
609 return INNER_ERR;
610 }
611 if (!data.WriteBool(flag)) {
612 HILOG_ERROR("data write flag failed.");
613 return INNER_ERR;
614 }
615 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_ABILITY, data, reply, option);
616 if (error != NO_ERROR) {
617 HILOG_ERROR("Send request error: %{public}d", error);
618 return error;
619 }
620 return reply.ReadInt32();
621 }
622
TerminateUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int resultCode,const Want * resultWant)623 int AbilityManagerProxy::TerminateUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int resultCode,
624 const Want *resultWant)
625 {
626 int error;
627 MessageParcel data;
628 MessageParcel reply;
629 MessageOption option;
630
631 if (!WriteInterfaceToken(data)) {
632 return INNER_ERR;
633 }
634
635 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
636 "connect ability fail, extensionSessionInfo is nullptr");
637 if (extensionSessionInfo) {
638 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
639 HILOG_ERROR("flag and extensionSessionInfo write failed.");
640 return INNER_ERR;
641 }
642 } else {
643 if (!data.WriteBool(false)) {
644 HILOG_ERROR("flag write failed.");
645 return INNER_ERR;
646 }
647 }
648
649 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
650 HILOG_ERROR("data write failed.");
651 return INNER_ERR;
652 }
653
654 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY, data, reply, option);
655 if (error != NO_ERROR) {
656 HILOG_ERROR("Send request error: %{public}d", error);
657 return error;
658 }
659 return reply.ReadInt32();
660 }
661
CloseUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo)662 int AbilityManagerProxy::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo)
663 {
664 int error;
665 MessageParcel data;
666 MessageParcel reply;
667 MessageOption option;
668
669 if (!WriteInterfaceToken(data)) {
670 return INNER_ERR;
671 }
672
673 if (sessionInfo) {
674 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
675 HILOG_ERROR("flag and sessionInfo write failed.");
676 return INNER_ERR;
677 }
678 } else {
679 if (!data.WriteBool(false)) {
680 HILOG_ERROR("flag write failed.");
681 return INNER_ERR;
682 }
683 }
684
685 error = SendRequest(AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB, data, reply, option);
686 if (error != NO_ERROR) {
687 HILOG_ERROR("failed, Send request error: %{public}d", error);
688 return error;
689 }
690 return reply.ReadInt32();
691 }
692
SendResultToAbility(int32_t requestCode,int32_t resultCode,Want & resultWant)693 int AbilityManagerProxy::SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant)
694 {
695 int error;
696 MessageParcel data;
697 MessageParcel reply;
698 MessageOption option;
699
700 if (!WriteInterfaceToken(data)) {
701 return INNER_ERR;
702 }
703 if (!data.WriteInt32(requestCode)) {
704 HILOG_ERROR("requestCode write failed.");
705 return INNER_ERR;
706 }
707 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(&resultWant)) {
708 HILOG_ERROR("data write failed.");
709 return INNER_ERR;
710 }
711 error = SendRequest(AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY, data, reply, option);
712 if (error != NO_ERROR) {
713 HILOG_ERROR("Send request error: %{public}d", error);
714 return error;
715 }
716 return reply.ReadInt32();
717 }
718
MoveAbilityToBackground(const sptr<IRemoteObject> & token)719 int AbilityManagerProxy::MoveAbilityToBackground(const sptr<IRemoteObject> &token)
720 {
721 int error;
722 MessageParcel data;
723 MessageParcel reply;
724 MessageOption option;
725
726 if (!WriteInterfaceToken(data)) {
727 return INNER_ERR;
728 }
729 if (token) {
730 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
731 HILOG_ERROR("flag and token write failed.");
732 return INNER_ERR;
733 }
734 } else {
735 if (!data.WriteBool(false)) {
736 HILOG_ERROR("flag write failed.");
737 return INNER_ERR;
738 }
739 }
740 error = SendRequest(AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND, data, reply, option);
741 if (error != NO_ERROR) {
742 HILOG_ERROR("Send request error: %{public}d", error);
743 return error;
744 }
745 return reply.ReadInt32();
746 }
747
CloseAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)748 int AbilityManagerProxy::CloseAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
749 {
750 return TerminateAbility(token, resultCode, resultWant, false);
751 }
752
ConnectAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)753 int AbilityManagerProxy::ConnectAbility(
754 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken, int32_t userId)
755 {
756 return ConnectAbilityCommon(want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId);
757 }
758
ConnectAbilityCommon(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,AppExecFwk::ExtensionAbilityType extensionType,int32_t userId)759 int AbilityManagerProxy::ConnectAbilityCommon(
760 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken,
761 AppExecFwk::ExtensionAbilityType extensionType, int32_t userId)
762 {
763 MessageParcel data;
764 MessageParcel reply;
765 MessageOption option;
766
767 if (!WriteInterfaceToken(data)) {
768 return INNER_ERR;
769 }
770 if (!data.WriteParcelable(&want)) {
771 HILOG_ERROR("want write failed.");
772 return ERR_INVALID_VALUE;
773 }
774 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "connect ability fail, connect is nullptr");
775 if (connect->AsObject()) {
776 if (!data.WriteBool(true) || !data.WriteRemoteObject(connect->AsObject())) {
777 HILOG_ERROR("flag and connect write failed.");
778 return ERR_INVALID_VALUE;
779 }
780 } else {
781 if (!data.WriteBool(false)) {
782 HILOG_ERROR("flag write failed.");
783 return ERR_INVALID_VALUE;
784 }
785 }
786 if (callerToken) {
787 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
788 HILOG_ERROR("flag and callerToken write failed.");
789 return ERR_INVALID_VALUE;
790 }
791 } else {
792 if (!data.WriteBool(false)) {
793 HILOG_ERROR("flag write failed.");
794 return ERR_INVALID_VALUE;
795 }
796 }
797 if (!data.WriteInt32(userId)) {
798 HILOG_ERROR("%{public}s, userId write failed.", __func__);
799 return INNER_ERR;
800 }
801 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
802 HILOG_ERROR("%{public}s, extensionType write failed.", __func__);
803 return INNER_ERR;
804 }
805 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE, data, reply, option);
806 if (error != NO_ERROR) {
807 HILOG_ERROR("%{public}s, Send request error: %{public}d", __func__, error);
808 return error;
809 }
810 return reply.ReadInt32();
811 }
812
ConnectUIExtensionAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<SessionInfo> & sessionInfo,int32_t userId)813 int AbilityManagerProxy::ConnectUIExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect,
814 const sptr<SessionInfo> &sessionInfo, int32_t userId)
815 {
816 MessageParcel data;
817 MessageParcel reply;
818 MessageOption option;
819
820 if (!WriteInterfaceToken(data)) {
821 return INNER_ERR;
822 }
823 if (!data.WriteParcelable(&want)) {
824 HILOG_ERROR("want write failed.");
825 return ERR_INVALID_VALUE;
826 }
827 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "connect ability fail, connect is nullptr");
828 if (connect->AsObject()) {
829 if (!data.WriteBool(true) || !data.WriteRemoteObject(connect->AsObject())) {
830 HILOG_ERROR("flag and connect write failed.");
831 return ERR_INVALID_VALUE;
832 }
833 } else {
834 if (!data.WriteBool(false)) {
835 HILOG_ERROR("flag write failed.");
836 return ERR_INVALID_VALUE;
837 }
838 }
839 CHECK_POINTER_AND_RETURN_LOG(sessionInfo, ERR_INVALID_VALUE, "connect ability fail, sessionInfo is nullptr");
840 if (sessionInfo) {
841 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
842 HILOG_ERROR("flag and sessionInfo write failed.");
843 return ERR_INVALID_VALUE;
844 }
845 } else {
846 if (!data.WriteBool(false)) {
847 HILOG_ERROR("flag write failed.");
848 return ERR_INVALID_VALUE;
849 }
850 }
851 if (!data.WriteInt32(userId)) {
852 HILOG_ERROR("UserId write failed.");
853 return INNER_ERR;
854 }
855 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY, data, reply, option);
856 if (error != NO_ERROR) {
857 HILOG_ERROR("Send request error: %{public}d", error);
858 return error;
859 }
860 return reply.ReadInt32();
861 }
862
DisconnectAbility(const sptr<IAbilityConnection> & connect)863 int AbilityManagerProxy::DisconnectAbility(const sptr<IAbilityConnection> &connect)
864 {
865 int error;
866 MessageParcel data;
867 MessageParcel reply;
868 MessageOption option;
869 if (connect == nullptr) {
870 HILOG_ERROR("disconnect ability fail, connect is nullptr");
871 return ERR_INVALID_VALUE;
872 }
873 if (!WriteInterfaceToken(data)) {
874 return INNER_ERR;
875 }
876 if (!data.WriteRemoteObject(connect->AsObject())) {
877 HILOG_ERROR("connect write failed.");
878 return ERR_INVALID_VALUE;
879 }
880
881 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY, data, reply, option);
882 if (error != NO_ERROR) {
883 HILOG_ERROR("Send request error: %{public}d", error);
884 return error;
885 }
886 return reply.ReadInt32();
887 }
888
AcquireDataAbility(const Uri & uri,bool tryBind,const sptr<IRemoteObject> & callerToken)889 sptr<IAbilityScheduler> AbilityManagerProxy::AcquireDataAbility(
890 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken)
891 {
892 int error;
893 MessageParcel data;
894 MessageParcel reply;
895 MessageOption option;
896
897 if (!callerToken) {
898 HILOG_ERROR("invalid parameters for acquire data ability.");
899 return nullptr;
900 }
901 if (!WriteInterfaceToken(data)) {
902 return nullptr;
903 }
904 if (!data.WriteString(uri.ToString()) || !data.WriteBool(tryBind) || !data.WriteRemoteObject(callerToken)) {
905 HILOG_ERROR("data write failed.");
906 return nullptr;
907 }
908
909 error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY, data, reply, option);
910 if (error != NO_ERROR) {
911 HILOG_ERROR("Send request error: %{public}d", error);
912 return nullptr;
913 }
914
915 return iface_cast<IAbilityScheduler>(reply.ReadRemoteObject());
916 }
917
ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler,const sptr<IRemoteObject> & callerToken)918 int AbilityManagerProxy::ReleaseDataAbility(
919 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken)
920 {
921 int error;
922 MessageParcel data;
923 MessageParcel reply;
924 MessageOption option;
925
926 if (!dataAbilityScheduler || !callerToken) {
927 return ERR_INVALID_VALUE;
928 }
929 if (!WriteInterfaceToken(data)) {
930 return INNER_ERR;
931 }
932 if (!data.WriteRemoteObject(dataAbilityScheduler->AsObject()) || !data.WriteRemoteObject(callerToken)) {
933 HILOG_ERROR("data write failed.");
934 return INNER_ERR;
935 }
936
937 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY, data, reply, option);
938 if (error != NO_ERROR) {
939 HILOG_ERROR("Send request error: %{public}d", error);
940 return error;
941 }
942 return reply.ReadInt32();
943 }
944
AttachAbilityThread(const sptr<IAbilityScheduler> & scheduler,const sptr<IRemoteObject> & token)945 int AbilityManagerProxy::AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)
946 {
947 int error;
948 MessageParcel data;
949 MessageParcel reply;
950 MessageOption option;
951 if (scheduler == nullptr) {
952 return ERR_INVALID_VALUE;
953 }
954 if (!WriteInterfaceToken(data)) {
955 return INNER_ERR;
956 }
957 if (!data.WriteRemoteObject(scheduler->AsObject()) || !data.WriteRemoteObject(token)) {
958 HILOG_ERROR("data write failed.");
959 return ERR_INVALID_VALUE;
960 }
961
962 error = SendRequest(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD, data, reply, option);
963 if (error != NO_ERROR) {
964 HILOG_ERROR("Send request error: %{public}d", error);
965 return error;
966 }
967 return reply.ReadInt32();
968 }
969
AbilityTransitionDone(const sptr<IRemoteObject> & token,int state,const PacMap & saveData)970 int AbilityManagerProxy::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData)
971 {
972 int error;
973 MessageParcel data;
974 MessageParcel reply;
975 MessageOption option;
976
977 if (!WriteInterfaceToken(data)) {
978 return INNER_ERR;
979 }
980 if (!data.WriteRemoteObject(token) || !data.WriteInt32(state)) {
981 HILOG_ERROR("token or state write failed.");
982 return ERR_INVALID_VALUE;
983 }
984 if (!data.WriteParcelable(&saveData)) {
985 HILOG_ERROR("saveData write failed.");
986 return INNER_ERR;
987 }
988
989 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE, data, reply, option);
990 if (error != NO_ERROR) {
991 HILOG_ERROR("Send request error: %{public}d", error);
992 return error;
993 }
994 return reply.ReadInt32();
995 }
996
ScheduleConnectAbilityDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & remoteObject)997 int AbilityManagerProxy::ScheduleConnectAbilityDone(
998 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject)
999 {
1000 int error;
1001 MessageParcel data;
1002 MessageParcel reply;
1003 MessageOption option;
1004
1005 if (!WriteInterfaceToken(data)) {
1006 return INNER_ERR;
1007 }
1008
1009 if (token) {
1010 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1011 HILOG_ERROR("Failed to write flag and token.");
1012 return ERR_INVALID_VALUE;
1013 }
1014 } else {
1015 if (!data.WriteBool(false)) {
1016 HILOG_ERROR("Failed to write flag.");
1017 return ERR_INVALID_VALUE;
1018 }
1019 }
1020
1021 if (remoteObject) {
1022 if (!data.WriteBool(true) || !data.WriteRemoteObject(remoteObject)) {
1023 HILOG_ERROR("Failed to write flag and remoteObject.");
1024 return ERR_INVALID_VALUE;
1025 }
1026 } else {
1027 if (!data.WriteBool(false)) {
1028 HILOG_ERROR("Failed to write flag.");
1029 return ERR_INVALID_VALUE;
1030 }
1031 }
1032
1033 error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE, data, reply, option);
1034 if (error != NO_ERROR) {
1035 HILOG_ERROR("Send request error: %{public}d", error);
1036 return error;
1037 }
1038 return reply.ReadInt32();
1039 }
1040
ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> & token)1041 int AbilityManagerProxy::ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token)
1042 {
1043 int error;
1044 MessageParcel data;
1045 MessageParcel reply;
1046 MessageOption option;
1047
1048 if (!WriteInterfaceToken(data)) {
1049 return INNER_ERR;
1050 }
1051 if (!data.WriteRemoteObject(token)) {
1052 HILOG_ERROR("token write failed.");
1053 return ERR_INVALID_VALUE;
1054 }
1055
1056 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE, data, reply, option);
1057 if (error != NO_ERROR) {
1058 HILOG_ERROR("Send request error: %{public}d", error);
1059 return error;
1060 }
1061 return reply.ReadInt32();
1062 }
1063
ScheduleCommandAbilityDone(const sptr<IRemoteObject> & token)1064 int AbilityManagerProxy::ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token)
1065 {
1066 int error;
1067 MessageParcel data;
1068 MessageParcel reply;
1069 MessageOption option;
1070
1071 if (!WriteInterfaceToken(data)) {
1072 return INNER_ERR;
1073 }
1074 if (!data.WriteRemoteObject(token)) {
1075 HILOG_ERROR("token write failed.");
1076 return ERR_INVALID_VALUE;
1077 }
1078
1079 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE, data, reply, option);
1080 if (error != NO_ERROR) {
1081 HILOG_ERROR("Send request error: %{public}d", error);
1082 return error;
1083 }
1084 return reply.ReadInt32();
1085 }
1086
ScheduleCommandAbilityWindowDone(const sptr<IRemoteObject> & token,const sptr<SessionInfo> & sessionInfo,WindowCommand winCmd,AbilityCommand abilityCmd)1087 int AbilityManagerProxy::ScheduleCommandAbilityWindowDone(
1088 const sptr<IRemoteObject> &token,
1089 const sptr<SessionInfo> &sessionInfo,
1090 WindowCommand winCmd,
1091 AbilityCommand abilityCmd)
1092 {
1093 int error;
1094 MessageParcel data;
1095 MessageParcel reply;
1096 MessageOption option;
1097
1098 if (!WriteInterfaceToken(data)) {
1099 return INNER_ERR;
1100 }
1101 if (!data.WriteRemoteObject(token)) {
1102 HILOG_ERROR("token write failed.");
1103 return ERR_INVALID_VALUE;
1104 }
1105 if (!data.WriteParcelable(sessionInfo)) {
1106 HILOG_ERROR("sessionInfo write failed.");
1107 return ERR_INVALID_VALUE;
1108 }
1109 if (!data.WriteInt32(winCmd)) {
1110 HILOG_ERROR("winCmd write failed.");
1111 return ERR_INVALID_VALUE;
1112 }
1113 if (!data.WriteInt32(abilityCmd)) {
1114 HILOG_ERROR("abilityCmd write failed.");
1115 return ERR_INVALID_VALUE;
1116 }
1117
1118 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE, data, reply, option);
1119 if (error != NO_ERROR) {
1120 HILOG_ERROR("Send request error: %{public}d", error);
1121 return error;
1122 }
1123 return reply.ReadInt32();
1124 }
1125
DumpSysState(const std::string & args,std::vector<std::string> & state,bool isClient,bool isUserId,int UserId)1126 void AbilityManagerProxy::DumpSysState(
1127 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserId, int UserId)
1128 {
1129 int error;
1130 MessageParcel data;
1131 MessageParcel reply;
1132 MessageOption option;
1133
1134 if (!WriteInterfaceToken(data)) {
1135 return;
1136 }
1137 data.WriteString16(Str8ToStr16(args));
1138
1139 if (!data.WriteBool(isClient)) {
1140 HILOG_ERROR("data write failed.");
1141 return ;
1142 }
1143 if (!data.WriteBool(isUserId)) {
1144 HILOG_ERROR("data write failed.");
1145 return ;
1146 }
1147 if (!data.WriteInt32(UserId)) {
1148 HILOG_ERROR("data write failed.");
1149 return ;
1150 }
1151
1152 error = SendRequest(AbilityManagerInterfaceCode::DUMPSYS_STATE, data, reply, option);
1153 if (error != NO_ERROR) {
1154 HILOG_ERROR("AbilityManagerProxy: SendRequest err %{public}d", error);
1155 return;
1156 }
1157 int32_t stackNum = reply.ReadInt32();
1158 for (int i = 0; i < stackNum; i++) {
1159 std::string stac = Str16ToStr8(reply.ReadString16());
1160 state.emplace_back(stac);
1161 }
1162 }
1163
DumpState(const std::string & args,std::vector<std::string> & state)1164 void AbilityManagerProxy::DumpState(const std::string &args, std::vector<std::string> &state)
1165 {
1166 int error;
1167 MessageParcel data;
1168 MessageParcel reply;
1169 MessageOption option;
1170
1171 if (!WriteInterfaceToken(data)) {
1172 return;
1173 }
1174 data.WriteString16(Str8ToStr16(args));
1175
1176 error = SendRequest(AbilityManagerInterfaceCode::DUMP_STATE, data, reply, option);
1177 if (error != NO_ERROR) {
1178 HILOG_ERROR("AbilityManagerProxy: SendRequest err %{public}d", error);
1179 return;
1180 }
1181 int32_t stackNum = reply.ReadInt32();
1182 for (int i = 0; i < stackNum; i++) {
1183 std::string stac = Str16ToStr8(reply.ReadString16());
1184 state.emplace_back(stac);
1185 }
1186 }
1187
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser)1188 int AbilityManagerProxy::MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser)
1189 {
1190 int error;
1191 MessageParcel data;
1192 MessageParcel reply;
1193 MessageOption option;
1194
1195 if (!WriteInterfaceToken(data)) {
1196 return INNER_ERR;
1197 }
1198 if (!data.WriteRemoteObject(token)) {
1199 HILOG_ERROR("token write failed.");
1200 return ERR_INVALID_VALUE;
1201 }
1202 if (!data.WriteBool(fromUser)) {
1203 HILOG_ERROR("data write failed.");
1204 return ERR_INVALID_VALUE;
1205 }
1206
1207 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_ABILITY, data, reply, option);
1208 if (error != NO_ERROR) {
1209 HILOG_ERROR("Send request error: %{public}d", error);
1210 return error;
1211 }
1212 return reply.ReadInt32();
1213 }
1214
MinimizeUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,bool fromUser)1215 int AbilityManagerProxy::MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo,
1216 bool fromUser)
1217 {
1218 int error;
1219 MessageParcel data;
1220 MessageParcel reply;
1221 MessageOption option;
1222
1223 if (!WriteInterfaceToken(data)) {
1224 return INNER_ERR;
1225 }
1226 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
1227 "connect ability fail, extensionSessionInfo is nullptr");
1228 if (extensionSessionInfo) {
1229 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
1230 HILOG_ERROR("flag and extensionSessionInfo write failed.");
1231 return INNER_ERR;
1232 }
1233 } else {
1234 if (!data.WriteBool(false)) {
1235 HILOG_ERROR("flag write failed.");
1236 return INNER_ERR;
1237 }
1238 }
1239 if (!data.WriteBool(fromUser)) {
1240 HILOG_ERROR("data write failed.");
1241 return ERR_INVALID_VALUE;
1242 }
1243
1244 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY, data, reply, option);
1245 if (error != NO_ERROR) {
1246 HILOG_ERROR("Send request error: %{public}d", error);
1247 return error;
1248 }
1249 return reply.ReadInt32();
1250 }
1251
MinimizeUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool fromUser)1252 int AbilityManagerProxy::MinimizeUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool fromUser)
1253 {
1254 int error;
1255 MessageParcel data;
1256 MessageParcel reply;
1257 MessageOption option;
1258
1259 if (!WriteInterfaceToken(data)) {
1260 return INNER_ERR;
1261 }
1262 if (sessionInfo) {
1263 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
1264 HILOG_ERROR("flag and sessionInfo write failed.");
1265 return INNER_ERR;
1266 }
1267 } else {
1268 if (!data.WriteBool(false)) {
1269 HILOG_ERROR("flag write failed.");
1270 return INNER_ERR;
1271 }
1272 }
1273 if (!data.WriteBool(fromUser)) {
1274 HILOG_ERROR("fromUser write failed.");
1275 return INNER_ERR;
1276 }
1277
1278 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB, data, reply, option);
1279 if (error != NO_ERROR) {
1280 HILOG_ERROR("failed, Send request error: %{public}d", error);
1281 return error;
1282 }
1283 return reply.ReadInt32();
1284 }
1285
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token)1286 int AbilityManagerProxy::StopServiceAbility(const Want &want, int32_t userId, const sptr<IRemoteObject> &token)
1287 {
1288 int error;
1289 MessageParcel data;
1290 MessageParcel reply;
1291 MessageOption option;
1292
1293 if (!WriteInterfaceToken(data)) {
1294 return INNER_ERR;
1295 }
1296 if (!data.WriteParcelable(&want)) {
1297 HILOG_ERROR("want write failed.");
1298 return INNER_ERR;
1299 }
1300 if (!data.WriteInt32(userId)) {
1301 HILOG_ERROR("userId write failed.");
1302 return INNER_ERR;
1303 }
1304 if (token) {
1305 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1306 HILOG_ERROR("Failed to write flag and token.");
1307 return ERR_INVALID_VALUE;
1308 }
1309 } else {
1310 if (!data.WriteBool(false)) {
1311 HILOG_ERROR("Failed to write flag.");
1312 return ERR_INVALID_VALUE;
1313 }
1314 }
1315 error = SendRequest(AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY, data, reply, option);
1316 if (error != NO_ERROR) {
1317 HILOG_ERROR("Send request error: %{public}d", error);
1318 return error;
1319 }
1320 return reply.ReadInt32();
1321 }
1322
1323 template <typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)1324 int AbilityManagerProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
1325 {
1326 int32_t infoSize = reply.ReadInt32();
1327 if (infoSize > CYCLE_LIMIT) {
1328 HILOG_ERROR("infoSize is too large");
1329 return ERR_INVALID_VALUE;
1330 }
1331
1332 for (int32_t i = 0; i < infoSize; i++) {
1333 std::unique_ptr<T> info(reply.ReadParcelable<T>());
1334 if (!info) {
1335 HILOG_ERROR("Read Parcelable infos failed.");
1336 return ERR_INVALID_VALUE;
1337 }
1338 parcelableInfos.emplace_back(*info);
1339 }
1340 return NO_ERROR;
1341 }
1342
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)1343 int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
1344 MissionSnapshot& snapshot, bool isLowResolution)
1345 {
1346 int error;
1347 MessageParcel data;
1348 MessageParcel reply;
1349 MessageOption option;
1350
1351 if (!WriteInterfaceToken(data)) {
1352 return INNER_ERR;
1353 }
1354 if (!data.WriteString(deviceId)) {
1355 HILOG_ERROR("deviceId write failed.");
1356 return INNER_ERR;
1357 }
1358 if (!data.WriteInt32(missionId)) {
1359 HILOG_ERROR("missionId write failed.");
1360 return ERR_INVALID_VALUE;
1361 }
1362 if (!data.WriteBool(isLowResolution)) {
1363 HILOG_ERROR("isLowResolution write failed.");
1364 return ERR_INVALID_VALUE;
1365 }
1366 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO, data, reply, option);
1367 if (error != NO_ERROR) {
1368 HILOG_ERROR("Send request error: %{public}d", error);
1369 return error;
1370 }
1371 std::unique_ptr<MissionSnapshot> info(reply.ReadParcelable<MissionSnapshot>());
1372 if (!info) {
1373 HILOG_ERROR("readParcelableInfo failed.");
1374 auto errorCode = reply.ReadInt32();
1375 return errorCode ? errorCode : ERR_UNKNOWN_OBJECT;
1376 }
1377 snapshot = *info;
1378 return reply.ReadInt32();
1379 }
1380
UpdateMissionSnapShot(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & pixelMap)1381 void AbilityManagerProxy::UpdateMissionSnapShot(const sptr<IRemoteObject> &token,
1382 const std::shared_ptr<Media::PixelMap> &pixelMap)
1383 {
1384 MessageParcel data;
1385 MessageParcel reply;
1386 MessageOption option(MessageOption::TF_ASYNC);
1387
1388 if (!WriteInterfaceToken(data)) {
1389 return;
1390 }
1391 if (!data.WriteRemoteObject(token)) {
1392 HILOG_ERROR("write token failed.");
1393 return;
1394 }
1395 if (!data.WriteParcelable(pixelMap.get())) {
1396 HILOG_ERROR("write pixelMap failed.");
1397 return;
1398 }
1399 auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS,
1400 data, reply, option);
1401 if (error != NO_ERROR) {
1402 HILOG_ERROR("Send request error: %{public}d", error);
1403 }
1404 }
1405
EnableRecoverAbility(const sptr<IRemoteObject> & token)1406 void AbilityManagerProxy::EnableRecoverAbility(const sptr<IRemoteObject>& token)
1407 {
1408 int error;
1409 MessageParcel data;
1410 MessageParcel reply;
1411 MessageOption option(MessageOption::TF_ASYNC);
1412
1413 if (!WriteInterfaceToken(data)) {
1414 HILOG_ERROR("AppRecovery WriteInterfaceToken failed.");
1415 return;
1416 }
1417
1418 if (!data.WriteRemoteObject(token)) {
1419 HILOG_ERROR("AppRecovery WriteRemoteObject failed.");
1420 return;
1421 }
1422
1423 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE, data, reply, option);
1424 if (error != NO_ERROR) {
1425 HILOG_ERROR("AppRecovery Send request error: %{public}d", error);
1426 return;
1427 }
1428 return;
1429 }
1430
ScheduleRecoverAbility(const sptr<IRemoteObject> & token,int32_t reason,const Want * want)1431 void AbilityManagerProxy::ScheduleRecoverAbility(const sptr<IRemoteObject>& token, int32_t reason, const Want *want)
1432 {
1433 int error;
1434 MessageParcel data;
1435 MessageParcel reply;
1436 MessageOption option(MessageOption::TF_ASYNC);
1437
1438 if (!WriteInterfaceToken(data)) {
1439 HILOG_ERROR("AppRecovery WriteInterfaceToken failed.");
1440 return;
1441 }
1442
1443 if (!data.WriteRemoteObject(token)) {
1444 HILOG_ERROR("AppRecovery WriteRemoteObject failed.");
1445 return;
1446 }
1447
1448 data.WriteInt32(reason);
1449
1450 if (!data.WriteParcelable(want)) {
1451 HILOG_ERROR("AppRecovery write want failed.");
1452 return;
1453 }
1454
1455 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY, data, reply, option);
1456 if (error != NO_ERROR) {
1457 HILOG_ERROR("AppRecovery Send request error: %{public}d", error);
1458 return;
1459 }
1460 return;
1461 }
1462
KillProcess(const std::string & bundleName)1463 int AbilityManagerProxy::KillProcess(const std::string &bundleName)
1464 {
1465 MessageParcel data;
1466 MessageParcel reply;
1467 MessageOption option;
1468
1469 if (!WriteInterfaceToken(data)) {
1470 return INNER_ERR;
1471 }
1472 if (!data.WriteString16(Str8ToStr16(bundleName))) {
1473 HILOG_ERROR("bundleName write failed.");
1474 return ERR_INVALID_VALUE;
1475 }
1476 int error = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS, data, reply, option);
1477 if (error != NO_ERROR) {
1478 HILOG_ERROR("Send request error: %{public}d", error);
1479 return error;
1480 }
1481 return reply.ReadInt32();
1482 }
1483
1484 #ifdef ABILITY_COMMAND_FOR_TEST
ForceTimeoutForTest(const std::string & abilityName,const std::string & state)1485 int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, const std::string &state)
1486 {
1487 MessageParcel data;
1488 MessageParcel reply;
1489 MessageOption option;
1490
1491 if (!WriteInterfaceToken(data)) {
1492 return INNER_ERR;
1493 }
1494 if (!data.WriteString16(Str8ToStr16(abilityName))) {
1495 HILOG_ERROR("abilityName write failed.");
1496 return ERR_INVALID_VALUE;
1497 }
1498 if (!data.WriteString16(Str8ToStr16(state))) {
1499 HILOG_ERROR("abilityName write failed.");
1500 return ERR_INVALID_VALUE;
1501 }
1502 int error = SendRequest(AbilityManagerInterfaceCode::FORCE_TIMEOUT, data, reply, option);
1503 if (error != NO_ERROR) {
1504 HILOG_ERROR("Send request error: %{public}d", error);
1505 return error;
1506 }
1507 return reply.ReadInt32();
1508 }
1509 #endif
1510
ClearUpApplicationData(const std::string & bundleName)1511 int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName)
1512 {
1513 MessageParcel data;
1514 MessageParcel reply;
1515 MessageOption option;
1516
1517 if (!WriteInterfaceToken(data)) {
1518 return INNER_ERR;
1519 }
1520 if (!data.WriteString16(Str8ToStr16(bundleName))) {
1521 HILOG_ERROR("bundleName write failed.");
1522 return ERR_INVALID_VALUE;
1523 }
1524 int error = SendRequest(AbilityManagerInterfaceCode::CLEAR_UP_APPLICATION_DATA, data, reply, option);
1525 if (error != NO_ERROR) {
1526 HILOG_ERROR("Send request error: %{public}d", error);
1527 return error;
1528 }
1529 return reply.ReadInt32();
1530 }
1531
UninstallApp(const std::string & bundleName,int32_t uid)1532 int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid)
1533 {
1534 MessageParcel data;
1535 MessageParcel reply;
1536 MessageOption option;
1537
1538 if (!WriteInterfaceToken(data)) {
1539 return INNER_ERR;
1540 }
1541 if (!data.WriteString16(Str8ToStr16(bundleName))) {
1542 HILOG_ERROR("bundleName write failed.");
1543 return ERR_INVALID_VALUE;
1544 }
1545 if (!data.WriteInt32(uid)) {
1546 HILOG_ERROR("uid write failed.");
1547 return ERR_INVALID_VALUE;
1548 }
1549 int error = SendRequest(AbilityManagerInterfaceCode::UNINSTALL_APP, data, reply, option);
1550 if (error != NO_ERROR) {
1551 HILOG_ERROR("Send request error: %{public}d", error);
1552 return error;
1553 }
1554 return reply.ReadInt32();
1555 }
1556
GetWantSender(const WantSenderInfo & wantSenderInfo,const sptr<IRemoteObject> & callerToken)1557 sptr<IWantSender> AbilityManagerProxy::GetWantSender(
1558 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken)
1559 {
1560 MessageParcel data;
1561 MessageParcel reply;
1562 MessageOption option;
1563 if (!WriteInterfaceToken(data)) {
1564 return nullptr;
1565 }
1566 if (!data.WriteParcelable(&wantSenderInfo)) {
1567 HILOG_ERROR("wantSenderInfo write failed.");
1568 return nullptr;
1569 }
1570 if (callerToken) {
1571 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
1572 HILOG_ERROR("flag and callerToken write failed.");
1573 return nullptr;
1574 }
1575 } else {
1576 if (!data.WriteBool(false)) {
1577 HILOG_ERROR("flag write failed.");
1578 return nullptr;
1579 }
1580 }
1581 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER, data, reply, option);
1582 if (error != NO_ERROR) {
1583 HILOG_ERROR("Send request error: %{public}d", error);
1584 return nullptr;
1585 }
1586 sptr<IWantSender> wantSender = iface_cast<IWantSender>(reply.ReadRemoteObject());
1587 if (!wantSender) {
1588 return nullptr;
1589 }
1590 return wantSender;
1591 }
1592
SendWantSender(const sptr<IWantSender> & target,const SenderInfo & senderInfo)1593 int AbilityManagerProxy::SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo)
1594 {
1595 MessageParcel data;
1596 MessageParcel reply;
1597 MessageOption option;
1598 if (!WriteInterfaceToken(data)) {
1599 return INNER_ERR;
1600 }
1601 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1602 HILOG_ERROR("target write failed.");
1603 return INNER_ERR;
1604 }
1605 if (!data.WriteParcelable(&senderInfo)) {
1606 HILOG_ERROR("senderInfo write failed.");
1607 return INNER_ERR;
1608 }
1609 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER, data, reply, option);
1610 if (error != NO_ERROR) {
1611 HILOG_ERROR("Send request error: %{public}d", error);
1612 return error;
1613 }
1614 return reply.ReadInt32();
1615 }
1616
CancelWantSender(const sptr<IWantSender> & sender)1617 void AbilityManagerProxy::CancelWantSender(const sptr<IWantSender> &sender)
1618 {
1619 MessageParcel data;
1620 MessageParcel reply;
1621 MessageOption option;
1622 if (!WriteInterfaceToken(data)) {
1623 return;
1624 }
1625 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
1626 HILOG_ERROR("sender write failed.");
1627 return;
1628 }
1629 auto error = SendRequest(AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER, data, reply, option);
1630 if (error != NO_ERROR) {
1631 HILOG_ERROR("Send request error: %{public}d", error);
1632 return;
1633 }
1634 }
1635
GetPendingWantUid(const sptr<IWantSender> & target)1636 int AbilityManagerProxy::GetPendingWantUid(const sptr<IWantSender> &target)
1637 {
1638 MessageParcel data;
1639 MessageParcel reply;
1640 MessageOption option;
1641 if (!WriteInterfaceToken(data)) {
1642 return INNER_ERR;
1643 }
1644 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1645 HILOG_ERROR("target write failed.");
1646 return ERR_INVALID_VALUE;
1647 }
1648 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_UID, data, reply, option);
1649 if (error != NO_ERROR) {
1650 HILOG_ERROR("Send request error: %{public}d", error);
1651 return INNER_ERR;
1652 }
1653 return reply.ReadInt32();
1654 }
1655
GetPendingWantUserId(const sptr<IWantSender> & target)1656 int AbilityManagerProxy::GetPendingWantUserId(const sptr<IWantSender> &target)
1657 {
1658 MessageParcel data;
1659 MessageParcel reply;
1660 MessageOption option;
1661 if (!WriteInterfaceToken(data)) {
1662 return INNER_ERR;
1663 }
1664 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1665 HILOG_ERROR("target write failed.");
1666 return ERR_INVALID_VALUE;
1667 }
1668 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID, data, reply, option);
1669 if (error != NO_ERROR) {
1670 HILOG_ERROR("Send request error: %{public}d", error);
1671 return INNER_ERR;
1672 }
1673 return reply.ReadInt32();
1674 }
1675
GetPendingWantBundleName(const sptr<IWantSender> & target)1676 std::string AbilityManagerProxy::GetPendingWantBundleName(const sptr<IWantSender> &target)
1677 {
1678 MessageParcel data;
1679 MessageParcel reply;
1680 MessageOption option;
1681 if (!WriteInterfaceToken(data)) {
1682 return "";
1683 }
1684 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1685 HILOG_ERROR("target write failed.");
1686 return "";
1687 }
1688 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME, data, reply, option);
1689 if (error != NO_ERROR) {
1690 HILOG_ERROR("Send request error: %{public}d", error);
1691 return "";
1692 }
1693 return Str16ToStr8(reply.ReadString16());
1694 }
1695
GetPendingWantCode(const sptr<IWantSender> & target)1696 int AbilityManagerProxy::GetPendingWantCode(const sptr<IWantSender> &target)
1697 {
1698 MessageParcel data;
1699 MessageParcel reply;
1700 MessageOption option;
1701 if (!WriteInterfaceToken(data)) {
1702 return INNER_ERR;
1703 }
1704 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1705 HILOG_ERROR("target write failed.");
1706 return ERR_INVALID_VALUE;
1707 }
1708 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE, data, reply, option);
1709 if (error != NO_ERROR) {
1710 HILOG_ERROR("Send request error: %{public}d", error);
1711 return INNER_ERR;
1712 }
1713 return reply.ReadInt32();
1714 }
1715
GetPendingWantType(const sptr<IWantSender> & target)1716 int AbilityManagerProxy::GetPendingWantType(const sptr<IWantSender> &target)
1717 {
1718 MessageParcel data;
1719 MessageParcel reply;
1720 MessageOption option;
1721 if (!WriteInterfaceToken(data)) {
1722 return INNER_ERR;
1723 }
1724 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1725 HILOG_ERROR("target write failed.");
1726 return ERR_INVALID_VALUE;
1727 }
1728 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE, data, reply, option);
1729 if (error != NO_ERROR) {
1730 HILOG_ERROR("Send request error: %{public}d", error);
1731 return INNER_ERR;
1732 }
1733 return reply.ReadInt32();
1734 }
1735
RegisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)1736 void AbilityManagerProxy::RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
1737 {
1738 MessageParcel data;
1739 MessageParcel reply;
1740 MessageOption option;
1741 if (!WriteInterfaceToken(data)) {
1742 return;
1743 }
1744 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
1745 HILOG_ERROR("sender write failed.");
1746 return;
1747 }
1748 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
1749 HILOG_ERROR("receiver write failed.");
1750 return;
1751 }
1752 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER, data, reply, option);
1753 if (error != NO_ERROR) {
1754 HILOG_ERROR("Send request error: %{public}d", error);
1755 return;
1756 }
1757 }
1758
UnregisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)1759 void AbilityManagerProxy::UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
1760 {
1761 MessageParcel data;
1762 MessageParcel reply;
1763 MessageOption option;
1764 if (!WriteInterfaceToken(data)) {
1765 return;
1766 }
1767 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
1768 HILOG_ERROR("sender write failed.");
1769 return;
1770 }
1771 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
1772 HILOG_ERROR("receiver write failed.");
1773 return;
1774 }
1775 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER, data, reply, option);
1776 if (error != NO_ERROR) {
1777 HILOG_ERROR("Send request error: %{public}d", error);
1778 return;
1779 }
1780 }
1781
GetPendingRequestWant(const sptr<IWantSender> & target,std::shared_ptr<Want> & want)1782 int AbilityManagerProxy::GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want)
1783 {
1784 MessageParcel data;
1785 MessageParcel reply;
1786 MessageOption option;
1787 if (!WriteInterfaceToken(data)) {
1788 return INNER_ERR;
1789 }
1790 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1791 HILOG_ERROR("target write failed.");
1792 return INNER_ERR;
1793 }
1794 if (want == nullptr || !data.WriteParcelable(want.get())) {
1795 HILOG_ERROR("want write failed.");
1796 return INNER_ERR;
1797 }
1798 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT, data, reply, option);
1799 if (error != NO_ERROR) {
1800 HILOG_ERROR("Send request error: %{public}d", error);
1801 return error;
1802 }
1803 std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
1804 if (!wantInfo) {
1805 HILOG_ERROR("readParcelableInfo failed");
1806 return INNER_ERR;
1807 }
1808 want = std::move(wantInfo);
1809
1810 return NO_ERROR;
1811 }
1812
GetWantSenderInfo(const sptr<IWantSender> & target,std::shared_ptr<WantSenderInfo> & info)1813 int AbilityManagerProxy::GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info)
1814 {
1815 MessageParcel data;
1816 MessageParcel reply;
1817 MessageOption option;
1818 if (!WriteInterfaceToken(data)) {
1819 return INNER_ERR;
1820 }
1821 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
1822 HILOG_ERROR("target write failed.");
1823 return INNER_ERR;
1824 }
1825 if (info == nullptr || !data.WriteParcelable(info.get())) {
1826 HILOG_ERROR("info write failed.");
1827 return INNER_ERR;
1828 }
1829 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO, data, reply, option);
1830 if (error != NO_ERROR) {
1831 HILOG_ERROR("Send request error: %{public}d", error);
1832 return error;
1833 }
1834 std::unique_ptr<WantSenderInfo> wantSenderInfo(reply.ReadParcelable<WantSenderInfo>());
1835 if (!wantSenderInfo) {
1836 HILOG_ERROR("readParcelable Info failed");
1837 return INNER_ERR;
1838 }
1839 info = std::move(wantSenderInfo);
1840
1841 return NO_ERROR;
1842 }
1843
GetAppMemorySize()1844 int AbilityManagerProxy::GetAppMemorySize()
1845 {
1846 MessageParcel data;
1847 MessageParcel reply;
1848 MessageOption option;
1849 if (!WriteInterfaceToken(data)) {
1850 HILOG_ERROR("WriteInterfaceToken faild");
1851 return INNER_ERR;
1852 }
1853 auto error = SendRequest(AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE, data, reply, option);
1854 if (error != NO_ERROR) {
1855 HILOG_ERROR("Send request error: %{public}d", error);
1856 return error;
1857 }
1858 return reply.ReadInt32();
1859 }
1860
IsRamConstrainedDevice()1861 bool AbilityManagerProxy::IsRamConstrainedDevice()
1862 {
1863 MessageParcel data;
1864 MessageParcel reply;
1865 MessageOption option;
1866 if (!WriteInterfaceToken(data)) {
1867 HILOG_ERROR("WriteInterfaceToken faild");
1868 return false;
1869 }
1870 auto error = SendRequest(AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE, data, reply, option);
1871 if (error != NO_ERROR) {
1872 HILOG_ERROR("Send request error: %{public}d", error);
1873 return false;
1874 }
1875 return reply.ReadBool();
1876 }
1877
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,int32_t missionId,const sptr<IRemoteObject> & callBack,AAFwk::WantParams & wantParams)1878 int AbilityManagerProxy::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
1879 int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams)
1880 {
1881 HILOG_INFO("amsProxy %{public}s called.", __func__);
1882 MessageParcel data;
1883 MessageParcel reply;
1884 MessageOption option;
1885 if (!WriteInterfaceToken(data)) {
1886 return INNER_ERR;
1887 }
1888 if (!data.WriteString(srcDeviceId)) {
1889 HILOG_ERROR("srcDeviceId write failed.");
1890 return INNER_ERR;
1891 }
1892 if (!data.WriteString(dstDeviceId)) {
1893 HILOG_ERROR("dstDeviceId write failed.");
1894 return INNER_ERR;
1895 }
1896 if (!data.WriteInt32(missionId)) {
1897 HILOG_ERROR("missionId write failed.");
1898 return INNER_ERR;
1899 }
1900 if (!data.WriteRemoteObject(callBack)) {
1901 HILOG_ERROR("callBack write failed.");
1902 return INNER_ERR;
1903 }
1904 if (!data.WriteParcelable(&wantParams)) {
1905 HILOG_ERROR("wantParams write failed.");
1906 return INNER_ERR;
1907 }
1908
1909 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION, data, reply, option);
1910 if (error != NO_ERROR) {
1911 HILOG_ERROR("Send request error: %{public}d", error);
1912 return error;
1913 }
1914 return reply.ReadInt32();
1915 }
1916
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,const std::string & bundleName,const sptr<IRemoteObject> & callBack,AAFwk::WantParams & wantParams)1917 int AbilityManagerProxy::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
1918 const std::string &bundleName, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams)
1919 {
1920 MessageParcel data;
1921 MessageParcel reply;
1922 MessageOption option;
1923 if (!WriteInterfaceToken(data)) {
1924 return INNER_ERR;
1925 }
1926 if (!data.WriteString(srcDeviceId)) {
1927 HILOG_ERROR("srcDeviceId write failed.");
1928 return INNER_ERR;
1929 }
1930 if (!data.WriteString(dstDeviceId)) {
1931 HILOG_ERROR("dstDeviceId write failed.");
1932 return INNER_ERR;
1933 }
1934 if (!data.WriteString(bundleName)) {
1935 HILOG_ERROR("missionId write failed.");
1936 return INNER_ERR;
1937 }
1938 if (!data.WriteRemoteObject(callBack)) {
1939 HILOG_ERROR("callBack write failed.");
1940 return INNER_ERR;
1941 }
1942 if (!data.WriteParcelable(&wantParams)) {
1943 HILOG_ERROR("wantParams write failed.");
1944 return INNER_ERR;
1945 }
1946
1947 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME, data, reply, option);
1948 if (error != NO_ERROR) {
1949 HILOG_ERROR("Send request error: %{public}d", error);
1950 return error;
1951 }
1952 return reply.ReadInt32();
1953 }
1954
ContinueAbility(const std::string & deviceId,int32_t missionId,uint32_t versionCode)1955 int AbilityManagerProxy::ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode)
1956 {
1957 MessageParcel data;
1958 MessageParcel reply;
1959 MessageOption option;
1960 if (!WriteInterfaceToken(data)) {
1961 return INNER_ERR;
1962 }
1963 if (!data.WriteString(deviceId)) {
1964 HILOG_ERROR("deviceId write failed.");
1965 return INNER_ERR;
1966 }
1967 if (!data.WriteInt32(missionId)) {
1968 HILOG_ERROR("missionId write failed.");
1969 return INNER_ERR;
1970 }
1971 if (!data.WriteUint32(versionCode)) {
1972 HILOG_ERROR("versionCode write failed.");
1973 return INNER_ERR;
1974 }
1975
1976 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_ABILITY, data, reply, option);
1977 if (error != NO_ERROR) {
1978 HILOG_ERROR("Send request error: %{public}d", error);
1979 return error;
1980 }
1981 return reply.ReadInt32();
1982 }
1983
StartContinuation(const Want & want,const sptr<IRemoteObject> & abilityToken,int32_t status)1984 int AbilityManagerProxy::StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status)
1985 {
1986 MessageParcel data;
1987 MessageParcel reply;
1988 MessageOption option;
1989 if (!WriteInterfaceToken(data)) {
1990 return INNER_ERR;
1991 }
1992 if (!data.WriteParcelable(&want)) {
1993 HILOG_ERROR("want write failed.");
1994 return INNER_ERR;
1995 }
1996 if (!data.WriteRemoteObject(abilityToken)) {
1997 HILOG_ERROR("abilityToken write failed.");
1998 return INNER_ERR;
1999 }
2000 if (!data.WriteInt32(status)) {
2001 HILOG_ERROR("status write failed.");
2002 return INNER_ERR;
2003 }
2004
2005 auto error = SendRequest(AbilityManagerInterfaceCode::START_CONTINUATION, data, reply, option);
2006 if (error != NO_ERROR) {
2007 HILOG_ERROR("Send request error: %{public}d", error);
2008 return error;
2009 }
2010 return reply.ReadInt32();
2011 }
2012
NotifyCompleteContinuation(const std::string & deviceId,int32_t sessionId,bool isSuccess)2013 void AbilityManagerProxy::NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess)
2014 {
2015 MessageParcel data;
2016 MessageParcel reply;
2017 MessageOption option;
2018 if (!WriteInterfaceToken(data)) {
2019 return;
2020 }
2021 if (!data.WriteString(deviceId)) {
2022 HILOG_ERROR("deviceId write failed.");
2023 return;
2024 }
2025 if (!data.WriteInt32(sessionId)) {
2026 HILOG_ERROR("sessionId write failed.");
2027 return;
2028 }
2029 if (!data.WriteBool(isSuccess)) {
2030 HILOG_ERROR("result write failed.");
2031 return;
2032 }
2033
2034 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION, data, reply, option);
2035 if (error != NO_ERROR) {
2036 HILOG_ERROR("Send request error: %{public}d", error);
2037 return;
2038 }
2039 }
2040
NotifyContinuationResult(int32_t missionId,int32_t result)2041 int AbilityManagerProxy::NotifyContinuationResult(int32_t missionId, int32_t result)
2042 {
2043 MessageParcel data;
2044 MessageParcel reply;
2045 MessageOption option;
2046 if (!WriteInterfaceToken(data)) {
2047 return INNER_ERR;
2048 }
2049 if (!data.WriteInt32(missionId)) {
2050 HILOG_ERROR("missionId write failed.");
2051 return INNER_ERR;
2052 }
2053 if (!data.WriteInt32(result)) {
2054 HILOG_ERROR("result write failed.");
2055 return INNER_ERR;
2056 }
2057
2058 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT, data, reply, option);
2059 if (error != NO_ERROR) {
2060 HILOG_ERROR("Send request error: %{public}d", error);
2061 return error;
2062 }
2063 return reply.ReadInt32();
2064 }
2065
LockMissionForCleanup(int32_t missionId)2066 int AbilityManagerProxy::LockMissionForCleanup(int32_t missionId)
2067 {
2068 int error;
2069 MessageParcel data;
2070 MessageParcel reply;
2071 MessageOption option;
2072
2073 if (!WriteInterfaceToken(data)) {
2074 return INNER_ERR;
2075 }
2076 if (!data.WriteInt32(missionId)) {
2077 HILOG_ERROR("lock mission by id , WriteInt32 fail.");
2078 return ERR_INVALID_VALUE;
2079 }
2080
2081 error = SendRequest(AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP, data, reply, option);
2082 if (error != NO_ERROR) {
2083 HILOG_ERROR("lock mission by id , error: %d", error);
2084 return error;
2085 }
2086 return reply.ReadInt32();
2087 }
2088
UnlockMissionForCleanup(int32_t missionId)2089 int AbilityManagerProxy::UnlockMissionForCleanup(int32_t missionId)
2090 {
2091 int error;
2092 MessageParcel data;
2093 MessageParcel reply;
2094 MessageOption option;
2095
2096 if (!WriteInterfaceToken(data)) {
2097 return INNER_ERR;
2098 }
2099 if (!data.WriteInt32(missionId)) {
2100 HILOG_ERROR("unlock mission by id , WriteInt32 fail.");
2101 return ERR_INVALID_VALUE;
2102 }
2103 error = SendRequest(AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP, data, reply, option);
2104 if (error != NO_ERROR) {
2105 HILOG_ERROR("unlock mission by id , error: %d", error);
2106 return error;
2107 }
2108 return reply.ReadInt32();
2109 }
2110
RegisterMissionListener(const sptr<IMissionListener> & listener)2111 int AbilityManagerProxy::RegisterMissionListener(const sptr<IMissionListener> &listener)
2112 {
2113 int error;
2114 MessageParcel data;
2115 MessageParcel reply;
2116 MessageOption option;
2117 if (!listener) {
2118 HILOG_ERROR("register mission listener, listener is nullptr");
2119 return ERR_INVALID_VALUE;
2120 }
2121
2122 if (!WriteInterfaceToken(data)) {
2123 return INNER_ERR;
2124 }
2125 if (!data.WriteRemoteObject(listener->AsObject())) {
2126 HILOG_ERROR("write mission listener failed when register mission listener.");
2127 return ERR_INVALID_VALUE;
2128 }
2129
2130 error = SendRequest(AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER, data, reply, option);
2131 if (error != NO_ERROR) {
2132 HILOG_ERROR("Send request error: %{public}d", error);
2133 return error;
2134 }
2135 return reply.ReadInt32();
2136 }
2137
RegisterSessionHandler(const sptr<IRemoteObject> & object)2138 int AbilityManagerProxy::RegisterSessionHandler(const sptr<IRemoteObject> &object)
2139 {
2140 if (!object) {
2141 HILOG_ERROR("register session handler, handler is nullptr");
2142 return ERR_INVALID_VALUE;
2143 }
2144 MessageParcel data;
2145 MessageParcel reply;
2146 MessageOption option;
2147 if (!WriteInterfaceToken(data)) {
2148 return INNER_ERR;
2149 }
2150 if (!data.WriteRemoteObject(object)) {
2151 HILOG_ERROR("write session handler failed when register session handler.");
2152 return ERR_INVALID_VALUE;
2153 }
2154 int error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER, data, reply, option);
2155 if (error != NO_ERROR) {
2156 HILOG_ERROR("Send request error: %{public}d", error);
2157 return error;
2158 }
2159 return reply.ReadInt32();
2160 }
2161
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)2162 int AbilityManagerProxy::RegisterMissionListener(const std::string &deviceId,
2163 const sptr<IRemoteMissionListener> &listener)
2164 {
2165 MessageParcel data;
2166 MessageParcel reply;
2167 MessageOption option;
2168 if (!WriteInterfaceToken(data)) {
2169 return INNER_ERR;
2170 }
2171 if (!data.WriteString(deviceId)) {
2172 HILOG_ERROR("deviceId write failed.");
2173 return INNER_ERR;
2174 }
2175 if (!data.WriteRemoteObject(listener->AsObject())) {
2176 HILOG_ERROR("listener write failed.");
2177 return INNER_ERR;
2178 }
2179
2180 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER,
2181 data, reply, option);
2182 if (error != NO_ERROR) {
2183 HILOG_ERROR("Send request error: %{public}d", error);
2184 return error;
2185 }
2186 return reply.ReadInt32();
2187 }
2188
RegisterOnListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2189 int AbilityManagerProxy::RegisterOnListener(const std::string &type,
2190 const sptr<IRemoteOnListener> &listener)
2191 {
2192 MessageParcel data;
2193 MessageParcel reply;
2194 MessageOption option;
2195 if (!WriteInterfaceToken(data)) {
2196 return INNER_ERR;
2197 }
2198 if (!data.WriteString(type)) {
2199 HILOG_ERROR("type write failed.");
2200 return INNER_ERR;
2201 }
2202 if (!data.WriteRemoteObject(listener->AsObject())) {
2203 HILOG_ERROR("listener write failed.");
2204 return INNER_ERR;
2205 }
2206
2207 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER, data, reply, option);
2208 if (error != NO_ERROR) {
2209 HILOG_ERROR("Send request error: %{public}d", error);
2210 return error;
2211 }
2212 return reply.ReadInt32();
2213 }
2214
RegisterOffListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2215 int AbilityManagerProxy::RegisterOffListener(const std::string &type,
2216 const sptr<IRemoteOnListener> &listener)
2217 {
2218 MessageParcel data;
2219 MessageParcel reply;
2220 MessageOption option;
2221 if (!WriteInterfaceToken(data)) {
2222 return INNER_ERR;
2223 }
2224 if (!data.WriteString(type)) {
2225 HILOG_ERROR("type write failed.");
2226 return INNER_ERR;
2227 }
2228 if (!data.WriteRemoteObject(listener->AsObject())) {
2229 HILOG_ERROR("listener write failed.");
2230 return INNER_ERR;
2231 }
2232
2233 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER, data, reply, option);
2234 if (error != NO_ERROR) {
2235 HILOG_ERROR("Send request error: %{public}d", error);
2236 return error;
2237 }
2238 return reply.ReadInt32();
2239 }
2240
UnRegisterMissionListener(const sptr<IMissionListener> & listener)2241 int AbilityManagerProxy::UnRegisterMissionListener(const sptr<IMissionListener> &listener)
2242 {
2243 int error;
2244 MessageParcel data;
2245 MessageParcel reply;
2246 MessageOption option;
2247 if (!listener) {
2248 HILOG_ERROR("unregister mission listener, listener is nullptr");
2249 return ERR_INVALID_VALUE;
2250 }
2251
2252 if (!WriteInterfaceToken(data)) {
2253 return INNER_ERR;
2254 }
2255 if (!data.WriteRemoteObject(listener->AsObject())) {
2256 HILOG_ERROR("write mission listener failed when unregister mission listener.");
2257 return ERR_INVALID_VALUE;
2258 }
2259
2260 error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER, data, reply, option);
2261 if (error != NO_ERROR) {
2262 HILOG_ERROR("Send request error: %{public}d", error);
2263 return error;
2264 }
2265 return reply.ReadInt32();
2266 }
2267
GetMissionInfos(const std::string & deviceId,int32_t numMax,std::vector<MissionInfo> & missionInfos)2268 int AbilityManagerProxy::GetMissionInfos(const std::string& deviceId, int32_t numMax,
2269 std::vector<MissionInfo> &missionInfos)
2270 {
2271 int error;
2272 MessageParcel data;
2273 MessageParcel reply;
2274 MessageOption option;
2275 if (!WriteInterfaceToken(data)) {
2276 return INNER_ERR;
2277 }
2278 if (!data.WriteString16(Str8ToStr16(deviceId))) {
2279 HILOG_ERROR("write deviceId failed when GetMissionInfos.");
2280 return ERR_INVALID_VALUE;
2281 }
2282 if (!data.WriteInt32(numMax)) {
2283 HILOG_ERROR("GetMissionInfos numMax write failed.");
2284 return ERR_INVALID_VALUE;
2285 }
2286 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFOS, data, reply, option);
2287 if (error != NO_ERROR) {
2288 HILOG_ERROR("GetMissionInfos Send request error: %{public}d", error);
2289 return error;
2290 }
2291 error = GetParcelableInfos<MissionInfo>(reply, missionInfos);
2292 if (error != NO_ERROR) {
2293 HILOG_ERROR("GetMissionInfos error: %{public}d", error);
2294 return error;
2295 }
2296 return reply.ReadInt32();
2297 }
2298
GetMissionInfo(const std::string & deviceId,int32_t missionId,MissionInfo & missionInfo)2299 int AbilityManagerProxy::GetMissionInfo(const std::string& deviceId, int32_t missionId,
2300 MissionInfo &missionInfo)
2301 {
2302 int error;
2303 MessageParcel data;
2304 MessageParcel reply;
2305 MessageOption option;
2306 if (!WriteInterfaceToken(data)) {
2307 return INNER_ERR;
2308 }
2309 if (!data.WriteString16(Str8ToStr16(deviceId))) {
2310 HILOG_ERROR("write deviceId failed when GetMissionInfo.");
2311 return ERR_INVALID_VALUE;
2312 }
2313 if (!data.WriteInt32(missionId)) {
2314 HILOG_ERROR("GetMissionInfo write missionId failed.");
2315 return ERR_INVALID_VALUE;
2316 }
2317 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID, data, reply, option);
2318 if (error != NO_ERROR) {
2319 HILOG_ERROR("GetMissionInfo Send request error: %{public}d", error);
2320 return error;
2321 }
2322
2323 std::unique_ptr<MissionInfo> info(reply.ReadParcelable<MissionInfo>());
2324 if (!info) {
2325 HILOG_ERROR("read missioninfo failed.");
2326 return ERR_UNKNOWN_OBJECT;
2327 }
2328 missionInfo = *info;
2329 return reply.ReadInt32();
2330 }
2331
CleanMission(int32_t missionId)2332 int AbilityManagerProxy::CleanMission(int32_t missionId)
2333 {
2334 int error;
2335 MessageParcel data;
2336 MessageParcel reply;
2337 MessageOption option;
2338
2339 if (!WriteInterfaceToken(data)) {
2340 return INNER_ERR;
2341 }
2342 if (!data.WriteInt32(missionId)) {
2343 HILOG_ERROR("clean mission by id , WriteInt32 fail.");
2344 return ERR_INVALID_VALUE;
2345 }
2346 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_MISSION, data, reply, option);
2347 if (error != NO_ERROR) {
2348 HILOG_ERROR("clean mission by id , error: %d", error);
2349 return error;
2350 }
2351 return reply.ReadInt32();
2352 }
2353
CleanAllMissions()2354 int AbilityManagerProxy::CleanAllMissions()
2355 {
2356 int error;
2357 MessageParcel data;
2358 MessageParcel reply;
2359 MessageOption option;
2360
2361 if (!WriteInterfaceToken(data)) {
2362 return INNER_ERR;
2363 }
2364 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS, data, reply, option);
2365 if (error != NO_ERROR) {
2366 HILOG_ERROR("lock mission by id ,SendRequest error: %d", error);
2367 return error;
2368 }
2369 return reply.ReadInt32();
2370 }
2371
MoveMissionToFront(int32_t missionId)2372 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId)
2373 {
2374 int error;
2375 MessageParcel data;
2376 MessageParcel reply;
2377 MessageOption option;
2378
2379 if (!WriteInterfaceToken(data)) {
2380 return INNER_ERR;
2381 }
2382 if (!data.WriteInt32(missionId)) {
2383 HILOG_ERROR("move mission to front , WriteInt32 fail.");
2384 return ERR_INVALID_VALUE;
2385 }
2386 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT, data, reply, option);
2387 if (error != NO_ERROR) {
2388 HILOG_ERROR("move mission to front, SendRequest error: %d", error);
2389 return error;
2390 }
2391 return reply.ReadInt32();
2392 }
2393
MoveMissionToFront(int32_t missionId,const StartOptions & startOptions)2394 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions)
2395 {
2396 int error;
2397 MessageParcel data;
2398 MessageParcel reply;
2399 MessageOption option;
2400
2401 if (!WriteInterfaceToken(data)) {
2402 return INNER_ERR;
2403 }
2404 if (!data.WriteInt32(missionId)) {
2405 HILOG_ERROR("move mission to front , WriteInt32 fail.");
2406 return ERR_INVALID_VALUE;
2407 }
2408 if (!data.WriteParcelable(&startOptions)) {
2409 HILOG_ERROR("startOptions write failed.");
2410 return INNER_ERR;
2411 }
2412 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS, data, reply, option);
2413 if (error != NO_ERROR) {
2414 HILOG_ERROR("move mission to front, SendRequest error: %d", error);
2415 return error;
2416 }
2417 return reply.ReadInt32();
2418 }
2419
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)2420 int AbilityManagerProxy::MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId)
2421 {
2422 MessageParcel data;
2423 MessageParcel reply;
2424 MessageOption option;
2425 if (!WriteInterfaceToken(data)) {
2426 return INNER_ERR;
2427 }
2428
2429 if (!data.WriteInt32Vector(missionIds)) {
2430 HILOG_ERROR("mission id write failed.");
2431 return INNER_ERR;
2432 }
2433
2434 if (!data.WriteInt32(topMissionId)) {
2435 HILOG_ERROR("top mission id write failed.");
2436 return INNER_ERR;
2437 }
2438
2439 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND, data, reply, option);
2440 if (error != NO_ERROR) {
2441 HILOG_ERROR("query front missionInfo failed: send request error: %{public}d", error);
2442 return error;
2443 }
2444
2445 return reply.ReadInt32();
2446 }
2447
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)2448 int AbilityManagerProxy::MoveMissionsToBackground(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result)
2449 {
2450 MessageParcel data;
2451 MessageParcel reply;
2452 MessageOption option;
2453 if (!WriteInterfaceToken(data)) {
2454 return INNER_ERR;
2455 }
2456
2457 if (!data.WriteInt32Vector(missionIds)) {
2458 HILOG_ERROR("mission id write failed.");
2459 return INNER_ERR;
2460 }
2461
2462 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND, data, reply, option);
2463 if (error != NO_ERROR) {
2464 HILOG_ERROR("query front missionInfo failed: send request error: %{public}d", error);
2465 return error;
2466 }
2467
2468 if (!reply.ReadInt32Vector(&result)) {
2469 HILOG_ERROR("read result failed");
2470 return INNER_ERR;
2471 }
2472 return reply.ReadInt32();
2473 }
2474
StartUser(int userId)2475 int AbilityManagerProxy::StartUser(int userId)
2476 {
2477 int error;
2478 MessageParcel data;
2479 MessageParcel reply;
2480 MessageOption option;
2481
2482 if (!WriteInterfaceToken(data)) {
2483 return INNER_ERR;
2484 }
2485 if (!data.WriteInt32(userId)) {
2486 HILOG_ERROR("StartUser:WriteInt32 fail.");
2487 return ERR_INVALID_VALUE;
2488 }
2489 error = SendRequest(AbilityManagerInterfaceCode::START_USER, data, reply, option);
2490 if (error != NO_ERROR) {
2491 HILOG_ERROR("StartUser:SendRequest error: %d", error);
2492 return error;
2493 }
2494 return reply.ReadInt32();
2495 }
2496
SetMissionContinueState(const sptr<IRemoteObject> & token,const AAFwk::ContinueState & state)2497 int AbilityManagerProxy::SetMissionContinueState(const sptr<IRemoteObject> &token, const AAFwk::ContinueState &state)
2498 {
2499 MessageParcel data;
2500 MessageParcel reply;
2501 MessageOption option;
2502 if (!WriteInterfaceToken(data)) {
2503 return INNER_ERR;
2504 }
2505 if (!data.WriteRemoteObject(token)) {
2506 HILOG_ERROR("SetMissionContinueState write token failed.");
2507 return ERR_INVALID_VALUE;
2508 }
2509 if (!data.WriteInt32(static_cast<int32_t>(state))) {
2510 HILOG_ERROR("SetMissionContinueState write state failed.");
2511 return ERR_INVALID_VALUE;
2512 }
2513 sptr<IRemoteObject> remote = Remote();
2514 if (remote == nullptr) {
2515 HILOG_ERROR("Remote() is NULL");
2516 return INNER_ERR;
2517 }
2518 auto error = remote->SendRequest(IAbilityManager::SET_MISSION_CONTINUE_STATE, data, reply, option);
2519 if (error != NO_ERROR) {
2520 HILOG_ERROR("SetMissionContinueState Send request error: %{public}d", error);
2521 return error;
2522 }
2523 return reply.ReadInt32();
2524 }
2525
StopUser(int userId,const sptr<IStopUserCallback> & callback)2526 int AbilityManagerProxy::StopUser(int userId, const sptr<IStopUserCallback> &callback)
2527 {
2528 int error;
2529 MessageParcel data;
2530 MessageParcel reply;
2531 MessageOption option;
2532
2533 if (!WriteInterfaceToken(data)) {
2534 return INNER_ERR;
2535 }
2536 if (!data.WriteInt32(userId)) {
2537 HILOG_ERROR("StopUser:WriteInt32 fail.");
2538 return ERR_INVALID_VALUE;
2539 }
2540
2541 if (!callback) {
2542 data.WriteBool(false);
2543 } else {
2544 data.WriteBool(true);
2545 if (!data.WriteRemoteObject(callback->AsObject())) {
2546 HILOG_ERROR("StopUser:write IStopUserCallback fail.");
2547 return ERR_INVALID_VALUE;
2548 }
2549 }
2550 error = SendRequest(AbilityManagerInterfaceCode::STOP_USER, data, reply, option);
2551 if (error != NO_ERROR) {
2552 HILOG_ERROR("StopUser:SendRequest error: %d", error);
2553 return error;
2554 }
2555 return reply.ReadInt32();
2556 }
2557
2558 #ifdef SUPPORT_GRAPHICS
SetMissionLabel(const sptr<IRemoteObject> & token,const std::string & label)2559 int AbilityManagerProxy::SetMissionLabel(const sptr<IRemoteObject> &token, const std::string &label)
2560 {
2561 MessageParcel data;
2562 MessageParcel reply;
2563 MessageOption option;
2564 if (!WriteInterfaceToken(data)) {
2565 return INNER_ERR;
2566 }
2567 if (!data.WriteRemoteObject(token)) {
2568 HILOG_ERROR("SetMissionLabel write token failed.");
2569 return ERR_INVALID_VALUE;
2570 }
2571 if (!data.WriteString16(Str8ToStr16(label))) {
2572 HILOG_ERROR("SetMissionLabel write label failed.");
2573 return ERR_INVALID_VALUE;
2574 }
2575 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_LABEL, data, reply, option);
2576 if (error != NO_ERROR) {
2577 HILOG_ERROR("SetMissionLabel Send request error: %{public}d", error);
2578 return error;
2579 }
2580 return reply.ReadInt32();
2581 }
2582
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)2583 int AbilityManagerProxy::SetMissionIcon(const sptr<IRemoteObject> &token,
2584 const std::shared_ptr<OHOS::Media::PixelMap> &icon)
2585 {
2586 if (!token || !icon) {
2587 HILOG_ERROR("SetMissionIcon abilitytoken or icon is invalid.");
2588 return ERR_INVALID_VALUE;
2589 }
2590
2591 MessageParcel data;
2592 MessageParcel reply;
2593 MessageOption option;
2594 if (!WriteInterfaceToken(data)) {
2595 return INNER_ERR;
2596 }
2597 if (!data.WriteRemoteObject(token)) {
2598 HILOG_ERROR("SetMissionIcon write token failed.");
2599 return ERR_INVALID_VALUE;
2600 }
2601
2602 if (!data.WriteParcelable(icon.get())) {
2603 HILOG_ERROR("SetMissionIcon write icon failed.");
2604 return ERR_INVALID_VALUE;
2605 }
2606
2607 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_ICON, data, reply, option);
2608 if (error != NO_ERROR) {
2609 HILOG_ERROR("SetMissionIcon Send request error: %{public}d", error);
2610 return error;
2611 }
2612 return reply.ReadInt32();
2613 }
2614
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler)2615 int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler)
2616 {
2617 if (!handler) {
2618 HILOG_ERROR("%{public}s: handler is nullptr.", __func__);
2619 return INNER_ERR;
2620 }
2621 MessageParcel data;
2622 if (!WriteInterfaceToken(data)) {
2623 HILOG_ERROR("%{public}s: write interface token failed.", __func__);
2624 return INNER_ERR;
2625 }
2626 if (!data.WriteRemoteObject(handler->AsObject())) {
2627 HILOG_ERROR("%{public}s: handler write failed.", __func__);
2628 return INNER_ERR;
2629 }
2630 MessageOption option;
2631 MessageParcel reply;
2632 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER, data, reply, option);
2633 if (error != NO_ERROR) {
2634 HILOG_ERROR("%{public}s: send request error: %{public}d", __func__, error);
2635 return error;
2636 }
2637 return reply.ReadInt32();
2638 }
2639
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)2640 void AbilityManagerProxy::CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken)
2641 {
2642 MessageParcel data;
2643 if (!WriteInterfaceToken(data)) {
2644 HILOG_ERROR("%{public}s: write interface token failed.", __func__);
2645 return;
2646 }
2647 if (!data.WriteRemoteObject(abilityToken)) {
2648 HILOG_ERROR("%{public}s: abilityToken write failed.", __func__);
2649 return;
2650 }
2651 MessageOption option;
2652 MessageParcel reply;
2653 auto error = SendRequest(AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING, data, reply, option);
2654 if (error != NO_ERROR) {
2655 HILOG_ERROR("%{public}s: send request error: %{public}d", __func__, error);
2656 }
2657 }
2658
PrepareTerminateAbility(const sptr<IRemoteObject> & token,sptr<IPrepareTerminateCallback> & callback)2659 int AbilityManagerProxy::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
2660 sptr<IPrepareTerminateCallback> &callback)
2661 {
2662 if (!callback) {
2663 HILOG_ERROR("callback is nullptr.");
2664 return INNER_ERR;
2665 }
2666 int error = 0;
2667 MessageParcel data;
2668 MessageParcel reply;
2669 MessageOption option(MessageOption::TF_SYNC);
2670 if (!WriteInterfaceToken(data)) {
2671 HILOG_ERROR("write interface token failed.");
2672 return INNER_ERR;
2673 }
2674 if (token) {
2675 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
2676 HILOG_ERROR("write token failed.");
2677 return INNER_ERR;
2678 }
2679 } else {
2680 if (!data.WriteBool(false)) {
2681 HILOG_ERROR("write token failed.");
2682 return INNER_ERR;
2683 }
2684 }
2685 if (!data.WriteRemoteObject(callback->AsObject())) {
2686 HILOG_ERROR("weite callback failed.");
2687 return INNER_ERR;
2688 }
2689
2690 error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY, data, reply, option);
2691 if (error != NO_ERROR) {
2692 HILOG_ERROR("send request failed. error: %{public}d", error);
2693 return error;
2694 }
2695
2696 return reply.ReadInt32();
2697 }
2698 #endif
2699
GetAbilityRunningInfos(std::vector<AbilityRunningInfo> & info)2700 int AbilityManagerProxy::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
2701 {
2702 MessageParcel data;
2703 MessageParcel reply;
2704 MessageOption option;
2705
2706 if (!WriteInterfaceToken(data)) {
2707 return INNER_ERR;
2708 }
2709
2710 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO, data, reply, option);
2711 if (error != NO_ERROR) {
2712 HILOG_ERROR("Get ability running info, error: %{public}d", error);
2713 return error;
2714 }
2715 error = GetParcelableInfos<AbilityRunningInfo>(reply, info);
2716 if (error != NO_ERROR) {
2717 HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error);
2718 return error;
2719 }
2720 return reply.ReadInt32();
2721 }
2722
GetExtensionRunningInfos(int upperLimit,std::vector<ExtensionRunningInfo> & info)2723 int AbilityManagerProxy::GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info)
2724 {
2725 MessageParcel data;
2726 MessageParcel reply;
2727 MessageOption option;
2728
2729 if (!WriteInterfaceToken(data)) {
2730 return INNER_ERR;
2731 }
2732
2733 if (!data.WriteInt32(upperLimit)) {
2734 HILOG_ERROR("upperLimit write failed.");
2735 return INNER_ERR;
2736 }
2737
2738 auto error = SendRequest(AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO, data, reply, option);
2739 if (error != NO_ERROR) {
2740 HILOG_ERROR("Get extension running info failed., error: %{public}d", error);
2741 return error;
2742 }
2743 error = GetParcelableInfos<ExtensionRunningInfo>(reply, info);
2744 if (error != NO_ERROR) {
2745 HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error);
2746 return error;
2747 }
2748 return reply.ReadInt32();
2749 }
2750
GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> & info)2751 int AbilityManagerProxy::GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info)
2752 {
2753 MessageParcel data;
2754 MessageParcel reply;
2755 MessageOption option;
2756
2757 if (!WriteInterfaceToken(data)) {
2758 return INNER_ERR;
2759 }
2760
2761 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO, data, reply, option);
2762 if (error != NO_ERROR) {
2763 HILOG_ERROR("Get process running info, error: %{public}d", error);
2764 return error;
2765 }
2766 error = GetParcelableInfos<AppExecFwk::RunningProcessInfo>(reply, info);
2767 if (error != NO_ERROR) {
2768 HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error);
2769 return error;
2770 }
2771 return reply.ReadInt32();
2772 }
2773
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)2774 int AbilityManagerProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
2775 {
2776 HILOG_INFO("called");
2777 MessageParcel data;
2778 MessageParcel reply;
2779 MessageOption option;
2780
2781 if (!WriteInterfaceToken(data)) {
2782 HILOG_ERROR("WriteInterfaceToken failed");
2783 return ERR_INVALID_VALUE;
2784 }
2785 if (!data.WriteString(devId)) {
2786 HILOG_ERROR("write deviceId fail.");
2787 return ERR_INVALID_VALUE;
2788 }
2789
2790 if (!data.WriteBool(fixConflict)) {
2791 HILOG_ERROR("WriteBool fail.");
2792 return ERR_INVALID_VALUE;
2793 }
2794
2795 if (!data.WriteInt64(tag)) {
2796 HILOG_ERROR("WriteInt64 fail.");
2797 return ERR_INVALID_VALUE;
2798 }
2799
2800 auto error = SendRequest(AbilityManagerInterfaceCode::START_SYNC_MISSIONS, data, reply, option);
2801 if (error != NO_ERROR) {
2802 HILOG_ERROR("Send request error: %{public}d", error);
2803 return error;
2804 }
2805 return reply.ReadInt32();
2806 }
2807
StopSyncRemoteMissions(const std::string & devId)2808 int32_t AbilityManagerProxy::StopSyncRemoteMissions(const std::string& devId)
2809 {
2810 HILOG_INFO("called");
2811 MessageParcel data;
2812 MessageParcel reply;
2813 MessageOption option;
2814
2815 if (!WriteInterfaceToken(data)) {
2816 HILOG_ERROR("WriteInterfaceToken failed");
2817 return ERR_INVALID_VALUE;
2818 }
2819 if (!data.WriteString(devId)) {
2820 HILOG_ERROR("write deviceId fail.");
2821 return ERR_INVALID_VALUE;
2822 }
2823 auto error = SendRequest(AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS, data, reply, option);
2824 if (error != NO_ERROR) {
2825 HILOG_ERROR("Send request error: %{public}d", error);
2826 return error;
2827 }
2828 return reply.ReadInt32();
2829 }
2830
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)2831 int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId,
2832 const sptr<IRemoteMissionListener> &listener)
2833 {
2834 MessageParcel data;
2835 MessageParcel reply;
2836 MessageOption option;
2837 if (!WriteInterfaceToken(data)) {
2838 return INNER_ERR;
2839 }
2840 if (!data.WriteString(deviceId)) {
2841 HILOG_ERROR("deviceId write failed.");
2842 return INNER_ERR;
2843 }
2844 if (!data.WriteRemoteObject(listener->AsObject())) {
2845 HILOG_ERROR("listener write failed.");
2846 return INNER_ERR;
2847 }
2848
2849 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER,
2850 data, reply, option);
2851 if (error != NO_ERROR) {
2852 HILOG_ERROR("Send request error: %{public}d", error);
2853 return error;
2854 }
2855 return reply.ReadInt32();
2856 }
2857
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId)2858 int AbilityManagerProxy::StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
2859 const sptr<IRemoteObject> &callerToken, int32_t accountId)
2860 {
2861 HILOG_DEBUG("AbilityManagerProxy::StartAbilityByCall begin.");
2862 int error;
2863 MessageParcel data;
2864 MessageParcel reply;
2865 MessageOption option;
2866
2867 if (!WriteInterfaceToken(data)) {
2868 return INNER_ERR;
2869 }
2870 if (!data.WriteParcelable(&want)) {
2871 HILOG_ERROR("want write failed.");
2872 return ERR_INVALID_VALUE;
2873 }
2874 if (connect == nullptr) {
2875 HILOG_ERROR("resolve ability fail, connect is nullptr");
2876 return ERR_INVALID_VALUE;
2877 }
2878 if (!data.WriteRemoteObject(connect->AsObject())) {
2879 HILOG_ERROR("resolve write failed.");
2880 return ERR_INVALID_VALUE;
2881 }
2882 if (callerToken) {
2883 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
2884 HILOG_ERROR("Failed to write flag and callerToken.");
2885 return ERR_INVALID_VALUE;
2886 }
2887 } else {
2888 if (!data.WriteBool(false)) {
2889 HILOG_ERROR("Failed to write flag.");
2890 return ERR_INVALID_VALUE;
2891 }
2892 }
2893 if (!data.WriteInt32(accountId)) {
2894 HILOG_ERROR("accountId write failed.");
2895 return ERR_INVALID_VALUE;
2896 }
2897
2898 HILOG_DEBUG("AbilityManagerProxy::StartAbilityByCall SendRequest Call.");
2899 error = SendRequest(AbilityManagerInterfaceCode::START_CALL_ABILITY, data, reply, option);
2900 if (error != NO_ERROR) {
2901 HILOG_ERROR("Send request error: %{public}d", error);
2902 return error;
2903 }
2904 HILOG_DEBUG("AbilityManagerProxy::StartAbilityByCall end.");
2905 return reply.ReadInt32();
2906 }
2907
CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)2908 void AbilityManagerProxy::CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub)
2909 {
2910 MessageParcel data;
2911 MessageParcel reply;
2912 MessageOption option(MessageOption::TF_ASYNC);
2913
2914 if (token == nullptr) {
2915 HILOG_ERROR("Call request done fail, ability token is nullptr.");
2916 return;
2917 }
2918 if (callStub == nullptr) {
2919 HILOG_ERROR("Call request done fail, callStub is nullptr.");
2920 return;
2921 }
2922
2923 if (!WriteInterfaceToken(data)) {
2924 return;
2925 }
2926 if (!data.WriteRemoteObject(token)) {
2927 HILOG_ERROR("WriteRemoteObject fail, write token fail.");
2928 return;
2929 }
2930 if (!data.WriteRemoteObject(callStub)) {
2931 HILOG_ERROR("WriteRemoteObject fail, write callStub fail.");
2932 return;
2933 }
2934 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_REQUEST_DONE, data, reply, option);
2935 if (error != NO_ERROR) {
2936 HILOG_ERROR("Send request error: %{public}d", error);
2937 return;
2938 }
2939 }
2940
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)2941 int AbilityManagerProxy::ReleaseCall(
2942 const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element)
2943 {
2944 int error;
2945 MessageParcel data;
2946 MessageParcel reply;
2947 MessageOption option;
2948 if (connect == nullptr) {
2949 HILOG_ERROR("release calll ability fail, connect is nullptr");
2950 return ERR_INVALID_VALUE;
2951 }
2952 if (!WriteInterfaceToken(data)) {
2953 return INNER_ERR;
2954 }
2955 if (!data.WriteRemoteObject(connect->AsObject())) {
2956 HILOG_ERROR("release ability connect write failed.");
2957 return ERR_INVALID_VALUE;
2958 }
2959 if (!data.WriteParcelable(&element)) {
2960 HILOG_ERROR("element error.");
2961 return ERR_INVALID_VALUE;
2962 }
2963
2964 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY, data, reply, option);
2965 if (error != NO_ERROR) {
2966 HILOG_ERROR("Send request error: %{public}d", error);
2967 return error;
2968 }
2969 return reply.ReadInt32();
2970 }
2971
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)2972 void AbilityManagerProxy::GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token)
2973 {
2974 MessageParcel data;
2975 MessageParcel reply;
2976 MessageOption option;
2977 if (!WriteInterfaceToken(data)) {
2978 return;
2979 }
2980 if (!data.WriteRemoteObject(callStub)) {
2981 HILOG_ERROR("WriteRemoteObject fail, write callStub fail.");
2982 return;
2983 }
2984
2985 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_TOKEN, data, reply, option);
2986 if (error != NO_ERROR) {
2987 HILOG_ERROR("Send request error: %{public}d", error);
2988 return;
2989 }
2990 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
2991 }
2992
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)2993 int AbilityManagerProxy::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
2994 {
2995 MessageParcel data;
2996 MessageParcel reply;
2997 MessageOption option;
2998 if (!WriteInterfaceToken(data)) {
2999 return INNER_ERR;
3000 }
3001 if (!data.WriteRemoteObject(handler->AsObject())) {
3002 HILOG_ERROR("snapshot: handler write failed.");
3003 return INNER_ERR;
3004 }
3005 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SNAPSHOT_HANDLER, data, reply, option);
3006 if (error != NO_ERROR) {
3007 HILOG_ERROR("snapshot: send request error: %{public}d", error);
3008 return error;
3009 }
3010 return reply.ReadInt32();
3011 }
3012
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)3013 int AbilityManagerProxy::SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,
3014 bool imAStabilityTest)
3015 {
3016 if (!abilityController) {
3017 HILOG_ERROR("abilityController nullptr");
3018 return ERR_INVALID_VALUE;
3019 }
3020 MessageParcel data;
3021 MessageParcel reply;
3022 MessageOption option;
3023 if (!WriteInterfaceToken(data)) {
3024 return INNER_ERR;
3025 }
3026 if (!data.WriteRemoteObject(abilityController->AsObject())) {
3027 HILOG_ERROR("abilityController write failed.");
3028 return ERR_INVALID_VALUE;
3029 }
3030 if (!data.WriteBool(imAStabilityTest)) {
3031 HILOG_ERROR("imAStabilityTest write failed.");
3032 return ERR_INVALID_VALUE;
3033 }
3034 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER, data, reply, option);
3035 if (error != NO_ERROR) {
3036 HILOG_ERROR("Send request error: %{public}d", error);
3037 return error;
3038 }
3039 return reply.ReadInt32();
3040 }
3041
SetComponentInterception(const sptr<AppExecFwk::IComponentInterception> & componentInterception)3042 int AbilityManagerProxy::SetComponentInterception(const sptr<AppExecFwk::IComponentInterception> &componentInterception)
3043 {
3044 if (!componentInterception) {
3045 HILOG_ERROR("componentInterception nullptr");
3046 return ERR_INVALID_VALUE;
3047 }
3048 MessageParcel data;
3049 MessageParcel reply;
3050 MessageOption option;
3051 if (!WriteInterfaceToken(data)) {
3052 return INNER_ERR;
3053 }
3054 if (!data.WriteRemoteObject(componentInterception->AsObject())) {
3055 HILOG_ERROR("componentInterception write failed.");
3056 return ERR_INVALID_VALUE;
3057 }
3058 auto error = SendRequest(AbilityManagerInterfaceCode::SET_COMPONENT_INTERCEPTION, data, reply, option);
3059 if (error != NO_ERROR) {
3060 HILOG_ERROR("Send request error: %{public}d", error);
3061 return error;
3062 }
3063 return reply.ReadInt32();
3064 }
3065
SendResultToAbilityByToken(const Want & want,const sptr<IRemoteObject> & abilityToken,int32_t requestCode,int32_t resultCode,int32_t userId)3066 int32_t AbilityManagerProxy::SendResultToAbilityByToken(const Want &want, const sptr<IRemoteObject> &abilityToken,
3067 int32_t requestCode, int32_t resultCode, int32_t userId)
3068 {
3069 MessageParcel data;
3070 MessageParcel reply;
3071 MessageOption option;
3072
3073 if (!WriteInterfaceToken(data)) {
3074 return INNER_ERR;
3075 }
3076 if (!data.WriteParcelable(&want)) {
3077 HILOG_ERROR("want write failed.");
3078 return INNER_ERR;
3079 }
3080 if (!data.WriteRemoteObject(abilityToken)) {
3081 HILOG_ERROR("observer write failed.");
3082 return INNER_ERR;
3083 }
3084 if (!data.WriteInt32(requestCode)) {
3085 HILOG_ERROR("requestCode write failed.");
3086 return ERR_INVALID_VALUE;
3087 }
3088 if (!data.WriteInt32(resultCode)) {
3089 HILOG_ERROR("resultCode write failed.");
3090 return ERR_INVALID_VALUE;
3091 }
3092 if (!data.WriteInt32(userId)) {
3093 HILOG_ERROR("userId write failed.");
3094 return ERR_INVALID_VALUE;
3095 }
3096 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_ABILITY_RESULT_BY_TOKEN, data, reply, option);
3097 if (error != NO_ERROR) {
3098 HILOG_ERROR("Send request error: %{public}d", error);
3099 return error;
3100 }
3101 return reply.ReadInt32();
3102 }
3103
IsRunningInStabilityTest()3104 bool AbilityManagerProxy::IsRunningInStabilityTest()
3105 {
3106 MessageParcel data;
3107 MessageParcel reply;
3108 MessageOption option;
3109 if (!WriteInterfaceToken(data)) {
3110 return false;
3111 }
3112 auto error = SendRequest(AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST, data, reply, option);
3113 if (error != NO_ERROR) {
3114 HILOG_ERROR("Send request error: %{public}d", error);
3115 return false;
3116 }
3117 return reply.ReadBool();
3118 }
3119
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)3120 int AbilityManagerProxy::StartUserTest(const Want &want, const sptr<IRemoteObject> &observer)
3121 {
3122 MessageParcel data;
3123 MessageParcel reply;
3124 MessageOption option;
3125
3126 if (!WriteInterfaceToken(data)) {
3127 return INNER_ERR;
3128 }
3129 if (!data.WriteParcelable(&want)) {
3130 HILOG_ERROR("want write failed.");
3131 return INNER_ERR;
3132 }
3133 if (!data.WriteRemoteObject(observer)) {
3134 HILOG_ERROR("observer write failed.");
3135 return INNER_ERR;
3136 }
3137 auto error = SendRequest(AbilityManagerInterfaceCode::START_USER_TEST, data, reply, option);
3138 if (error != NO_ERROR) {
3139 HILOG_ERROR("Send request error: %{public}d", error);
3140 return error;
3141 }
3142 return reply.ReadInt32();
3143 }
3144
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)3145 int AbilityManagerProxy::FinishUserTest(
3146 const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
3147 {
3148 MessageParcel data;
3149 MessageParcel reply;
3150 MessageOption option;
3151
3152 if (!WriteInterfaceToken(data)) {
3153 return INNER_ERR;
3154 }
3155 if (!data.WriteString(msg)) {
3156 HILOG_ERROR("msg write failed.");
3157 return ERR_INVALID_VALUE;
3158 }
3159 if (!data.WriteInt64(resultCode)) {
3160 HILOG_ERROR("resultCode:WriteInt64 fail.");
3161 return ERR_INVALID_VALUE;
3162 }
3163 if (!data.WriteString(bundleName)) {
3164 HILOG_ERROR("bundleName write failed.");
3165 return ERR_INVALID_VALUE;
3166 }
3167
3168 auto error = SendRequest(AbilityManagerInterfaceCode::FINISH_USER_TEST, data, reply, option);
3169 if (error != NO_ERROR) {
3170 HILOG_ERROR("Send request error: %{public}d", error);
3171 return error;
3172 }
3173 return reply.ReadInt32();
3174 }
3175
GetTopAbility(sptr<IRemoteObject> & token)3176 int AbilityManagerProxy::GetTopAbility(sptr<IRemoteObject> &token)
3177 {
3178 MessageParcel data;
3179 MessageParcel reply;
3180 MessageOption option;
3181
3182 if (!WriteInterfaceToken(data)) {
3183 return INNER_ERR;
3184 }
3185
3186 auto error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN, data, reply, option);
3187 if (error != NO_ERROR) {
3188 HILOG_ERROR("Send request error: %{public}d", error);
3189 return error;
3190 }
3191
3192 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
3193 if (!token) {
3194 HILOG_ERROR("read IRemoteObject failed.");
3195 return ERR_UNKNOWN_OBJECT;
3196 }
3197
3198 return reply.ReadInt32();
3199 }
3200
CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId,bool & isFocused)3201 int AbilityManagerProxy::CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused)
3202 {
3203 MessageParcel data;
3204 MessageParcel reply;
3205 MessageOption option;
3206
3207 if (!WriteInterfaceToken(data)) {
3208 return INNER_ERR;
3209 }
3210
3211 if (!data.WriteUint32(uiExtensionTokenId)) {
3212 HILOG_ERROR("uiExtensionTokenId write failed.");
3213 return ERR_INVALID_VALUE;
3214 }
3215
3216 sptr<IRemoteObject> remote = Remote();
3217 if (remote == nullptr) {
3218 HILOG_ERROR("Remote() is NULL");
3219 return INNER_ERR;
3220 }
3221 auto error = remote->SendRequest(IAbilityManager::CHECK_UI_EXTENSION_IS_FOCUSED, data, reply, option);
3222 if (error != NO_ERROR) {
3223 HILOG_ERROR("Send request error: %{public}d", error);
3224 return error;
3225 }
3226
3227 isFocused = reply.ReadBool();
3228 return NO_ERROR;
3229 }
3230
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)3231 int AbilityManagerProxy::DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token)
3232 {
3233 MessageParcel data;
3234 MessageParcel reply;
3235 MessageOption option;
3236
3237 if (!WriteInterfaceToken(data)) {
3238 return INNER_ERR;
3239 }
3240
3241 if (!data.WriteRemoteObject(token)) {
3242 HILOG_ERROR("data write failed.");
3243 return ERR_INVALID_VALUE;
3244 }
3245
3246 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND,
3247 data, reply, option);
3248 if (error != NO_ERROR) {
3249 HILOG_ERROR("Send request error: %{public}d", error);
3250 return error;
3251 }
3252
3253 return reply.ReadInt32();
3254 }
3255
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)3256 int AbilityManagerProxy::DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token)
3257 {
3258 MessageParcel data;
3259 MessageParcel reply;
3260 MessageOption option;
3261
3262 if (!WriteInterfaceToken(data)) {
3263 return INNER_ERR;
3264 }
3265
3266 if (!data.WriteRemoteObject(token)) {
3267 HILOG_ERROR("data write failed.");
3268 return ERR_INVALID_VALUE;
3269 }
3270
3271 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND,
3272 data, reply, option);
3273 if (error != NO_ERROR) {
3274 HILOG_ERROR("Send request error: %{public}d", error);
3275 return error;
3276 }
3277
3278 return reply.ReadInt32();
3279 }
3280
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)3281 int AbilityManagerProxy::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
3282 {
3283 MessageParcel data;
3284 MessageParcel reply;
3285 MessageOption option;
3286
3287 if (!WriteInterfaceToken(data)) {
3288 return INNER_ERR;
3289 }
3290
3291 if (!data.WriteRemoteObject(token)) {
3292 HILOG_ERROR("data write failed.");
3293 return ERR_INVALID_VALUE;
3294 }
3295
3296 if (!data.WriteUint32(flag)) {
3297 HILOG_ERROR("flag write failed.");
3298 return ERR_INVALID_VALUE;
3299 }
3300
3301 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND, data, reply, option);
3302 if (error != NO_ERROR) {
3303 HILOG_ERROR("Send request error: %{public}d", error);
3304 return error;
3305 }
3306
3307 return reply.ReadInt32();
3308 }
3309
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)3310 int AbilityManagerProxy::DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag)
3311 {
3312 MessageParcel data;
3313 MessageParcel reply;
3314 MessageOption option;
3315
3316 if (!WriteInterfaceToken(data)) {
3317 return INNER_ERR;
3318 }
3319
3320 if (!data.WriteRemoteObject(token)) {
3321 HILOG_ERROR("data write failed.");
3322 return ERR_INVALID_VALUE;
3323 }
3324
3325 if (!data.WriteUint32(flag)) {
3326 HILOG_ERROR("flag write failed.");
3327 return ERR_INVALID_VALUE;
3328 }
3329
3330 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND, data, reply, option);
3331 if (error != NO_ERROR) {
3332 HILOG_ERROR("Send request error: %{public}d", error);
3333 return error;
3334 }
3335
3336 return reply.ReadInt32();
3337 }
3338
SendANRProcessID(int pid)3339 int AbilityManagerProxy::SendANRProcessID(int pid)
3340 {
3341 MessageParcel data;
3342 MessageParcel reply;
3343 MessageOption option;
3344 if (!WriteInterfaceToken(data)) {
3345 return INNER_ERR;
3346 }
3347 if (!data.WriteInt32(pid)) {
3348 HILOG_ERROR("pid WriteInt32 fail.");
3349 return ERR_INVALID_VALUE;
3350 }
3351
3352 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_APP_NOT_RESPONSE_PROCESS_ID,
3353 data, reply, option);
3354 if (error != NO_ERROR) {
3355 HILOG_ERROR("SendANRProcessID error: %d", error);
3356 return error;
3357 }
3358 return reply.ReadInt32();
3359 }
3360
GetMissionIdByToken(const sptr<IRemoteObject> & token)3361 int32_t AbilityManagerProxy::GetMissionIdByToken(const sptr<IRemoteObject> &token)
3362 {
3363 if (!token) {
3364 HILOG_ERROR("token is nullptr.");
3365 return -1;
3366 }
3367
3368 MessageParcel data;
3369 MessageParcel reply;
3370 MessageOption option;
3371 if (!WriteInterfaceToken(data)) {
3372 HILOG_ERROR("data interface token failed.");
3373 return -1;
3374 }
3375
3376 if (!data.WriteRemoteObject(token)) {
3377 HILOG_ERROR("data write failed.");
3378 return -1;
3379 }
3380
3381 auto error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN,
3382 data, reply, option);
3383 if (error != NO_ERROR) {
3384 HILOG_ERROR("Send request error: %{public}d", error);
3385 return -1;
3386 }
3387
3388 return reply.ReadInt32();
3389 }
3390
3391 #ifdef ABILITY_COMMAND_FOR_TEST
BlockAmsService()3392 int AbilityManagerProxy::BlockAmsService()
3393 {
3394 MessageParcel data;
3395 MessageParcel reply;
3396 MessageOption option;
3397 if (!WriteInterfaceToken(data)) {
3398 return INNER_ERR;
3399 }
3400
3401 auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE, data, reply, option);
3402 if (error != NO_ERROR) {
3403 HILOG_ERROR("BlockAmsService error: %d", error);
3404 return error;
3405 }
3406 return reply.ReadInt32();
3407 }
3408
BlockAbility(int32_t abilityRecordId)3409 int AbilityManagerProxy::BlockAbility(int32_t abilityRecordId)
3410 {
3411 MessageParcel data;
3412 MessageParcel reply;
3413 MessageOption option;
3414 if (!WriteInterfaceToken(data)) {
3415 return INNER_ERR;
3416 }
3417 if (!data.WriteInt32(abilityRecordId)) {
3418 HILOG_ERROR("pid WriteInt32 fail.");
3419 return ERR_INVALID_VALUE;
3420 }
3421
3422 auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_ABILITY, data, reply, option);
3423 if (error != NO_ERROR) {
3424 HILOG_ERROR("BlockAbility error: %d", error);
3425 return error;
3426 }
3427 return reply.ReadInt32();
3428 }
3429
BlockAppService()3430 int AbilityManagerProxy::BlockAppService()
3431 {
3432 MessageParcel data;
3433 MessageParcel reply;
3434 MessageOption option;
3435 if (!WriteInterfaceToken(data)) {
3436 return INNER_ERR;
3437 }
3438
3439 auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_APP_SERVICE, data, reply, option);
3440 if (error != NO_ERROR) {
3441 HILOG_ERROR("BlockAmsService error: %d", error);
3442 return error;
3443 }
3444 return reply.ReadInt32();
3445 }
3446 #endif
FreeInstallAbilityFromRemote(const Want & want,const sptr<IRemoteObject> & callback,int32_t userId,int requestCode)3447 int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
3448 int32_t userId, int requestCode)
3449 {
3450 MessageParcel data;
3451 MessageParcel reply;
3452 MessageOption option;
3453 if (!WriteInterfaceToken(data)) {
3454 HILOG_ERROR("write interface token failed.");
3455 return INNER_ERR;
3456 }
3457
3458 if (!data.WriteParcelable(&want)) {
3459 HILOG_ERROR("want write failed.");
3460 return INNER_ERR;
3461 }
3462
3463 if (!data.WriteRemoteObject(callback)) {
3464 HILOG_ERROR("callback write failed.");
3465 return INNER_ERR;
3466 }
3467
3468 if (!data.WriteInt32(userId)) {
3469 HILOG_ERROR("userId write failed.");
3470 return INNER_ERR;
3471 }
3472
3473 if (!data.WriteInt32(requestCode)) {
3474 HILOG_ERROR("requestCode write failed.");
3475 return INNER_ERR;
3476 }
3477
3478 auto error = SendRequest(AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE,
3479 data, reply, option);
3480 if (error != NO_ERROR) {
3481 HILOG_ERROR("Send request error: %{public}d", error);
3482 return error;
3483 }
3484
3485 return reply.ReadInt32();
3486 }
3487
AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> & observer)3488 int AbilityManagerProxy::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
3489 {
3490 MessageParcel data;
3491 MessageParcel reply;
3492 MessageOption option;
3493 if (!WriteInterfaceToken(data)) {
3494 HILOG_ERROR("write interface token failed.");
3495 return INNER_ERR;
3496 }
3497
3498 if (!data.WriteRemoteObject(observer->AsObject())) {
3499 HILOG_ERROR("observer write failed.");
3500 return INNER_ERR;
3501 }
3502
3503 auto error = SendRequest(AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER, data, reply, option);
3504 if (error != NO_ERROR) {
3505 HILOG_ERROR("Send request error: %{public}d", error);
3506 return error;
3507 }
3508 return reply.ReadInt32();
3509 }
3510
DumpAbilityInfoDone(std::vector<std::string> & infos,const sptr<IRemoteObject> & callerToken)3511 int AbilityManagerProxy::DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken)
3512 {
3513 MessageParcel data;
3514 MessageParcel reply;
3515 MessageOption option;
3516 if (!WriteInterfaceToken(data)) {
3517 HILOG_ERROR("write interface token failed.");
3518 return INNER_ERR;
3519 }
3520
3521 if (!data.WriteStringVector(infos)) {
3522 HILOG_ERROR("infos write failed.");
3523 return INNER_ERR;
3524 }
3525
3526 if (!data.WriteRemoteObject(callerToken)) {
3527 HILOG_ERROR("infos write failed.");
3528 return INNER_ERR;
3529 }
3530
3531 auto error = SendRequest(AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE, data, reply, option);
3532 if (error != NO_ERROR) {
3533 HILOG_ERROR("Send request error: %{public}d", error);
3534 return error;
3535 }
3536
3537 return reply.ReadInt32();
3538 }
3539
IsValidMissionIds(const std::vector<int32_t> & missionIds,std::vector<MissionVaildResult> & results)3540 int32_t AbilityManagerProxy::IsValidMissionIds(
3541 const std::vector<int32_t> &missionIds, std::vector<MissionVaildResult> &results)
3542 {
3543 HILOG_INFO("IsValidMissionIds Call. Quert size is %{public}zu", missionIds.size());
3544 MessageParcel data;
3545 MessageParcel reply;
3546 MessageOption option;
3547 if (!WriteInterfaceToken(data)) {
3548 HILOG_ERROR("write interface token failed.");
3549 return INNER_ERR;
3550 }
3551
3552 constexpr int32_t MAX_COUNT = 20;
3553 int32_t num = missionIds.size() > MAX_COUNT ? MAX_COUNT : missionIds.size();
3554 data.WriteInt32(num);
3555 for (auto i = 0; i < num; ++i) {
3556 data.WriteInt32(missionIds.at(i));
3557 }
3558
3559 auto error = SendRequest(AbilityManagerInterfaceCode::QUERY_MISSION_VAILD, data, reply, option);
3560 if (error != NO_ERROR) {
3561 HILOG_ERROR("Send request error: %{public}d", error);
3562 return error;
3563 }
3564
3565 auto resultCode = reply.ReadInt32();
3566 if (resultCode != ERR_OK) {
3567 HILOG_ERROR("Send request reply error: %{public}d", resultCode);
3568 return resultCode;
3569 }
3570
3571 auto infoSize = reply.ReadInt32();
3572 for (auto i = 0; i < infoSize && i < MAX_COUNT; ++i) {
3573 std::unique_ptr<MissionVaildResult> info(reply.ReadParcelable<MissionVaildResult>());
3574 if (!info) {
3575 HILOG_ERROR("Read Parcelable result infos failed.");
3576 return INNER_ERR;
3577 }
3578 results.emplace_back(*info);
3579 }
3580
3581 return resultCode;
3582 }
3583
VerifyPermission(const std::string & permission,int pid,int uid)3584 int AbilityManagerProxy::VerifyPermission(const std::string &permission, int pid, int uid)
3585 {
3586 HILOG_INFO("VerifyPermission Call");
3587 MessageParcel data;
3588 MessageParcel reply;
3589 MessageOption option;
3590 if (!WriteInterfaceToken(data)) {
3591 HILOG_ERROR("write interface token failed.");
3592 return INNER_ERR;
3593 }
3594
3595 if (!data.WriteString(permission)) {
3596 HILOG_ERROR("permission write failed.");
3597 return INNER_ERR;
3598 }
3599
3600 if (!data.WriteInt32(pid)) {
3601 HILOG_ERROR("pid write failed.");
3602 return INNER_ERR;
3603 }
3604
3605 if (!data.WriteInt32(uid)) {
3606 HILOG_ERROR("uid write failed.");
3607 return INNER_ERR;
3608 }
3609
3610 auto error = SendRequest(AbilityManagerInterfaceCode::VERIFY_PERMISSION, data, reply, option);
3611 if (error != NO_ERROR) {
3612 HILOG_ERROR("Send request error: %{public}d", error);
3613 return error;
3614 }
3615
3616 return reply.ReadInt32();
3617 }
3618
RequestDialogService(const Want & want,const sptr<IRemoteObject> & callerToken)3619 int32_t AbilityManagerProxy::RequestDialogService(const Want &want, const sptr<IRemoteObject> &callerToken)
3620 {
3621 HILOG_INFO("RequestDialogService Call");
3622 if (!callerToken) {
3623 HILOG_ERROR("callerToken is invalid.");
3624 return ERR_INVALID_CALLER;
3625 }
3626
3627 MessageParcel data;
3628 MessageParcel reply;
3629 MessageOption option;
3630 if (!WriteInterfaceToken(data)) {
3631 return INNER_ERR;
3632 }
3633
3634 if (!data.WriteParcelable(&want)) {
3635 HILOG_ERROR("want write failed.");
3636 return INNER_ERR;
3637 }
3638
3639 if (!data.WriteRemoteObject(callerToken)) {
3640 HILOG_ERROR("infos write failed.");
3641 return INNER_ERR;
3642 }
3643
3644 auto error = SendRequest(AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE, data, reply, option);
3645 if (error != NO_ERROR) {
3646 HILOG_ERROR("request dialog service Send request error: %{public}d", error);
3647 return error;
3648 }
3649 return reply.ReadInt32();
3650 }
3651
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)3652 int32_t AbilityManagerProxy::ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken)
3653 {
3654 HILOG_DEBUG("called.");
3655 if (callerToken == nullptr) {
3656 HILOG_ERROR("callerToken is nullptr");
3657 return INNER_ERR;
3658 }
3659
3660 MessageParcel data;
3661 MessageParcel reply;
3662 MessageOption option;
3663 if (!WriteInterfaceToken(data)) {
3664 return INNER_ERR;
3665 }
3666
3667 if (!data.WriteRemoteObject(callerToken)) {
3668 HILOG_ERROR("callerToken write failed.");
3669 return INNER_ERR;
3670 }
3671
3672 auto remote = Remote();
3673 if (remote == nullptr) {
3674 HILOG_ERROR("remote is nullptr.");
3675 return INNER_ERR;
3676 }
3677 auto error = remote->SendRequest(IAbilityManager::REPORT_DRAWN_COMPLETED, data, reply, option);
3678 if (error != NO_ERROR) {
3679 HILOG_ERROR("Send request error: %{public}d", error);
3680 return error;
3681 }
3682 return reply.ReadInt32();
3683 }
3684
AcquireShareData(const int32_t & missionId,const sptr<IAcquireShareDataCallback> & shareData)3685 int32_t AbilityManagerProxy::AcquireShareData(
3686 const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData)
3687 {
3688 HILOG_INFO("AbilityManagerProxy::AcquireShareData start.");
3689 MessageParcel data;
3690 MessageParcel reply;
3691 MessageOption option;
3692
3693 if (!WriteInterfaceToken(data)) {
3694 HILOG_ERROR("write interface token failed.");
3695 return INNER_ERR;
3696 }
3697
3698 if (!data.WriteInt32(missionId)) {
3699 HILOG_ERROR("missionId write failed.");
3700 return INNER_ERR;
3701 }
3702
3703 if (shareData == nullptr || !data.WriteRemoteObject(shareData->AsObject())) {
3704 HILOG_ERROR("shareData write failed.");
3705 return INNER_ERR;
3706 }
3707
3708 int32_t error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA, data, reply, option);
3709 if (error != NO_ERROR) {
3710 HILOG_ERROR("AcquireShareData fail to Send request, err: %{public}d.", error);
3711 return INNER_ERR;
3712 }
3713 HILOG_INFO("AbilityManagerProxy::AcquireShareData end.");
3714 return reply.ReadInt32();
3715 }
3716
ShareDataDone(const sptr<IRemoteObject> & token,const int32_t & resultCode,const int32_t & uniqueId,WantParams & wantParam)3717 int32_t AbilityManagerProxy::ShareDataDone(
3718 const sptr<IRemoteObject> &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)
3719 {
3720 HILOG_INFO("AbilityManagerProxy::ShareDataDone start.");
3721 MessageParcel data;
3722 MessageParcel reply;
3723 MessageOption option(MessageOption::TF_ASYNC);
3724
3725 if (!WriteInterfaceToken(data)) {
3726 HILOG_ERROR("write interface token failed.");
3727 return INNER_ERR;
3728 }
3729
3730 if (!data.WriteRemoteObject(token)) {
3731 HILOG_ERROR("token write failed.");
3732 return INNER_ERR;
3733 }
3734
3735 if (!data.WriteInt32(resultCode)) {
3736 HILOG_ERROR("requestCode write failed.");
3737 return INNER_ERR;
3738 }
3739
3740 if (!data.WriteInt32(uniqueId)) {
3741 HILOG_ERROR("uniqueId write failed.");
3742 return INNER_ERR;
3743 }
3744
3745 if (!data.WriteParcelable(&wantParam)) {
3746 HILOG_ERROR("wantParam write failed.");
3747 return INNER_ERR;
3748 }
3749
3750 int32_t error = SendRequest(AbilityManagerInterfaceCode::SHARE_DATA_DONE, data, reply, option);
3751 if (error != NO_ERROR) {
3752 HILOG_ERROR("ShareDataDone fail to SendRequest, err: %{public}d.", error);
3753 return error;
3754 }
3755 HILOG_INFO("AbilityManagerProxy::ShareDataDone end.");
3756 return reply.ReadInt32();
3757 }
3758
ForceExitApp(const int32_t pid,Reason exitReason)3759 int32_t AbilityManagerProxy::ForceExitApp(const int32_t pid, Reason exitReason)
3760 {
3761 HILOG_DEBUG("start.");
3762 MessageParcel data;
3763 MessageParcel reply;
3764 MessageOption option(MessageOption::TF_ASYNC);
3765
3766 if (!WriteInterfaceToken(data)) {
3767 HILOG_ERROR("write interface token failed.");
3768 return INNER_ERR;
3769 }
3770
3771 if (!data.WriteInt32(pid)) {
3772 HILOG_ERROR("pid write failed.");
3773 return INNER_ERR;
3774 }
3775
3776 if (!data.WriteInt32(static_cast<int32_t>(exitReason))) {
3777 HILOG_ERROR("Reason write failed.");
3778 return INNER_ERR;
3779 }
3780
3781 int32_t error = SendRequest(AbilityManagerInterfaceCode::FORCE_EXIT_APP, data, reply, option);
3782 if (error != NO_ERROR) {
3783 HILOG_ERROR("fail to SendRequest, err: %{public}d.", error);
3784 return error;
3785 }
3786
3787 HILOG_DEBUG("end.");
3788 return reply.ReadInt32();
3789 }
3790
RecordAppExitReason(Reason exitReason)3791 int32_t AbilityManagerProxy::RecordAppExitReason(Reason exitReason)
3792 {
3793 HILOG_DEBUG("start.");
3794 MessageParcel data;
3795 MessageParcel reply;
3796 MessageOption option(MessageOption::TF_ASYNC);
3797
3798 if (!WriteInterfaceToken(data)) {
3799 HILOG_ERROR("write interface token failed.");
3800 return INNER_ERR;
3801 }
3802
3803 if (!data.WriteInt32(static_cast<int32_t>(exitReason))) {
3804 HILOG_ERROR("Reason write failed.");
3805 return INNER_ERR;
3806 }
3807
3808 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON, data, reply, option);
3809 if (error != NO_ERROR) {
3810 HILOG_ERROR("fail to SendRequest, err: %{public}d.", error);
3811 return error;
3812 }
3813
3814 HILOG_DEBUG("end.");
3815 return reply.ReadInt32();
3816 }
3817
SetRootSceneSession(const sptr<IRemoteObject> & rootSceneSession)3818 void AbilityManagerProxy::SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession)
3819 {
3820 MessageParcel data;
3821 if (!WriteInterfaceToken(data)) {
3822 HILOG_ERROR("WriteInterfaceToken failed.");
3823 return;
3824 }
3825 if (!data.WriteRemoteObject(rootSceneSession)) {
3826 HILOG_ERROR("WriteRemoteObject failed.");
3827 return;
3828 }
3829
3830 MessageParcel reply;
3831 MessageOption option(MessageOption::TF_ASYNC);
3832 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ROOT_SCENE_SESSION, data, reply, option);
3833 if (error != NO_ERROR) {
3834 HILOG_ERROR("Send request error: %{public}d", error);
3835 }
3836 }
3837
CallUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo)3838 void AbilityManagerProxy::CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo)
3839 {
3840 MessageParcel data;
3841 if (!WriteInterfaceToken(data)) {
3842 HILOG_ERROR("WriteInterfaceToken failed.");
3843 return;
3844 }
3845 if (sessionInfo) {
3846 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
3847 HILOG_ERROR("flag and sessionInfo write failed.");
3848 return;
3849 }
3850 } else {
3851 if (!data.WriteBool(false)) {
3852 HILOG_ERROR("flag write failed.");
3853 return;
3854 }
3855 }
3856
3857 MessageParcel reply;
3858 MessageOption option(MessageOption::TF_ASYNC);
3859 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_ABILITY_BY_SCB, data, reply, option);
3860 if (error != NO_ERROR) {
3861 HILOG_ERROR("Send request error: %{public}d", error);
3862 }
3863 }
3864
StartSpecifiedAbilityBySCB(const Want & want)3865 void AbilityManagerProxy::StartSpecifiedAbilityBySCB(const Want &want)
3866 {
3867 MessageParcel data;
3868 if (!WriteInterfaceToken(data)) {
3869 HILOG_ERROR("WriteInterfaceToken failed.");
3870 return;
3871 }
3872
3873 if (!data.WriteParcelable(&want)) {
3874 HILOG_ERROR("want write failed.");
3875 return;
3876 }
3877
3878 MessageParcel reply;
3879 MessageOption option(MessageOption::TF_ASYNC);
3880 auto error = SendRequest(AbilityManagerInterfaceCode::START_SPECIFIED_ABILITY_BY_SCB, data, reply, option);
3881 if (error != NO_ERROR) {
3882 HILOG_ERROR("Send request error: %{public}d", error);
3883 }
3884 }
3885
NotifySaveAsResult(const Want & want,int resultCode,int requestCode)3886 int32_t AbilityManagerProxy::NotifySaveAsResult(const Want &want, int resultCode, int requestCode)
3887 {
3888 MessageParcel data;
3889 if (!WriteInterfaceToken(data)) {
3890 HILOG_ERROR("WriteInterfaceToken failed.");
3891 return INNER_ERR;
3892 }
3893 if (!data.WriteParcelable(&want)) {
3894 HILOG_ERROR("WriteWantObject failed.");
3895 return INNER_ERR;
3896 }
3897
3898 if (!data.WriteInt32(resultCode)) {
3899 HILOG_ERROR("resultCode write failed.");
3900 return INNER_ERR;
3901 }
3902
3903 if (!data.WriteInt32(requestCode)) {
3904 HILOG_ERROR("requestCode write failed.");
3905 return INNER_ERR;
3906 }
3907
3908 auto remote = Remote();
3909 if (!remote) {
3910 HILOG_ERROR("remote object is nullptr.");
3911 return INNER_ERR;
3912 }
3913
3914 MessageParcel reply;
3915 MessageOption option;
3916 auto error = remote->SendRequest(IAbilityManager::NOTIFY_SAVE_AS_RESULT, data, reply, option);
3917 if (error != NO_ERROR) {
3918 HILOG_ERROR("Send request error: %{public}d", error);
3919 }
3920
3921 return reply.ReadInt32();
3922 }
3923
SetSessionManagerService(const sptr<IRemoteObject> & sessionManagerService)3924 int32_t AbilityManagerProxy::SetSessionManagerService(const sptr<IRemoteObject> &sessionManagerService)
3925 {
3926 HILOG_INFO("AbilityManagerProxy::SetSessionManagerService start.");
3927 MessageParcel data;
3928 MessageParcel reply;
3929 MessageOption option;
3930
3931 if (!WriteInterfaceToken(data)) {
3932 HILOG_ERROR("write interface token failed.");
3933 return INNER_ERR;
3934 }
3935
3936 if (!data.WriteRemoteObject(sessionManagerService)) {
3937 HILOG_ERROR("token write failed.");
3938 return INNER_ERR;
3939 }
3940
3941 int32_t error = SendRequest(AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE, data, reply, option);
3942 if (error != NO_ERROR) {
3943 HILOG_ERROR("Send request error: %{public}d", error);
3944 return error;
3945 }
3946 HILOG_INFO("AbilityManagerProxy::SetSessionManagerService end.");
3947 return reply.ReadInt32();
3948 }
3949
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<IAbilityManagerCollaborator> & impl)3950 int32_t AbilityManagerProxy::RegisterIAbilityManagerCollaborator(
3951 int32_t type, const sptr<IAbilityManagerCollaborator> &impl)
3952 {
3953 if (!impl) {
3954 HILOG_ERROR("impl is nullptr");
3955 return ERR_INVALID_VALUE;
3956 }
3957 MessageParcel data;
3958 MessageParcel reply;
3959 MessageOption option;
3960
3961 if (!WriteInterfaceToken(data)) {
3962 HILOG_ERROR("Write interface token failed.");
3963 return INNER_ERR;
3964 }
3965 if (!data.WriteInt32(type)) {
3966 HILOG_ERROR("type write failed.");
3967 return INNER_ERR;
3968 }
3969 if (!data.WriteRemoteObject(impl->AsObject())) {
3970 HILOG_ERROR("impl write failed.");
3971 return INNER_ERR;
3972 }
3973
3974 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_COLLABORATOR, data, reply, option);
3975 if (ret != NO_ERROR) {
3976 HILOG_ERROR("Send request error: %{public}d", ret);
3977 return ret;
3978 }
3979 return reply.ReadInt32();
3980 }
3981
UnregisterIAbilityManagerCollaborator(int32_t type)3982 int32_t AbilityManagerProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
3983 {
3984 MessageParcel data;
3985 MessageParcel reply;
3986 MessageOption option;
3987
3988 if (!WriteInterfaceToken(data)) {
3989 HILOG_ERROR("Write interface token failed.");
3990 return INNER_ERR;
3991 }
3992 if (!data.WriteInt32(type)) {
3993 HILOG_ERROR("type write failed.");
3994 return INNER_ERR;
3995 }
3996
3997 auto ret = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR, data, reply, option);
3998 if (ret != NO_ERROR) {
3999 HILOG_ERROR("Send request error: %{public}d", ret);
4000 return ret;
4001 }
4002 return reply.ReadInt32();
4003 }
4004
MoveMissionToBackground(int32_t missionId)4005 int32_t AbilityManagerProxy::MoveMissionToBackground(int32_t missionId)
4006 {
4007 MessageParcel data;
4008 MessageParcel reply;
4009 MessageOption option;
4010
4011 if (!WriteInterfaceToken(data)) {
4012 HILOG_ERROR("Write interface token failed.");
4013 return INNER_ERR;
4014 }
4015 if (!data.WriteInt32(missionId)) {
4016 HILOG_ERROR("missionId write failed.");
4017 return INNER_ERR;
4018 }
4019
4020 auto ret = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_BACKGROUND, data, reply, option);
4021 if (ret != NO_ERROR) {
4022 HILOG_ERROR("Send request error: %{public}d", ret);
4023 return ret;
4024 }
4025 return reply.ReadInt32();
4026 }
4027
TerminateMission(int32_t missionId)4028 int32_t AbilityManagerProxy::TerminateMission(int32_t missionId)
4029 {
4030 MessageParcel data;
4031 MessageParcel reply;
4032 MessageOption option;
4033
4034 if (!WriteInterfaceToken(data)) {
4035 HILOG_ERROR("Write interface token failed.");
4036 return INNER_ERR;
4037 }
4038 if (!data.WriteInt32(missionId)) {
4039 HILOG_ERROR("missionId write failed.");
4040 return INNER_ERR;
4041 }
4042
4043 auto ret = SendRequest(AbilityManagerInterfaceCode::TERMINATE_MISSION, data, reply, option);
4044 if (ret != NO_ERROR) {
4045 HILOG_ERROR("Send request error: %{public}d", ret);
4046 return ret;
4047 }
4048 return reply.ReadInt32();
4049 }
4050
PrepareTerminateAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool & isPrepareTerminate)4051 int AbilityManagerProxy::PrepareTerminateAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isPrepareTerminate)
4052 {
4053 MessageParcel data;
4054 MessageParcel reply;
4055 MessageOption option;
4056
4057 if (!WriteInterfaceToken(data)) {
4058 HILOG_ERROR("Write interface token failed.");
4059 return INNER_ERR;
4060 }
4061 if (sessionInfo) {
4062 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
4063 HILOG_ERROR("flag and sessionInfo write failed.");
4064 return INNER_ERR;
4065 }
4066 } else {
4067 if (!data.WriteBool(false)) {
4068 HILOG_ERROR("flag write failed.");
4069 return INNER_ERR;
4070 }
4071 }
4072
4073 auto error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB,
4074 data, reply, option);
4075 if (error != NO_ERROR) {
4076 HILOG_ERROR("Send request error: %{public}d", error);
4077 return error;
4078 }
4079
4080 isPrepareTerminate = reply.ReadBool();
4081 return NO_ERROR;
4082 }
4083
SendRequest(AbilityManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)4084 ErrCode AbilityManagerProxy::SendRequest(AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply,
4085 MessageOption& option)
4086 {
4087 sptr<IRemoteObject> remote = Remote();
4088 if (remote == nullptr) {
4089 HILOG_ERROR("Remote() is NULL");
4090 return INNER_ERR;
4091 }
4092
4093 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
4094 }
4095 } // namespace AAFwk
4096 } // namespace OHOS
4097