1 /*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ability_manager_proxy.h"
17
18 #include "ability_scheduler_stub.h"
19 #include "ability_util.h"
20 #include "freeze_util.h"
21 #include "hitrace_meter.h"
22 #include "status_bar_delegate_interface.h"
23
24 namespace OHOS {
25 namespace AAFwk {
26 namespace {
27 #define PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(messageParcel, type, value) \
28 do { \
29 if (!(messageParcel).Write##type(value)) { \
30 TAG_LOGE(AAFwkTag::ABILITYMGR, \
31 "failed to write %{public}s", #value); \
32 return INNER_ERR; \
33 } \
34 } while (0)
35 }
36 using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
37 constexpr int32_t CYCLE_LIMIT = 1000;
38 constexpr int32_t MAX_AUTO_STARTUP_COUNT = 100;
39 constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100;
WriteInterfaceToken(MessageParcel & data)40 bool AbilityManagerProxy::WriteInterfaceToken(MessageParcel &data)
41 {
42 if (!data.WriteInterfaceToken(AbilityManagerProxy::GetDescriptor())) {
43 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
44 return false;
45 }
46 return true;
47 }
48
StartAbility(const Want & want,int32_t userId,int requestCode)49 int AbilityManagerProxy::StartAbility(const Want &want, int32_t userId, int requestCode)
50 {
51 int error;
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption option;
55
56 if (!WriteInterfaceToken(data)) {
57 return INNER_ERR;
58 }
59 if (!data.WriteParcelable(&want)) {
60 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
61 return INNER_ERR;
62 }
63
64 if (!data.WriteInt32(userId)) {
65 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
66 return INNER_ERR;
67 }
68
69 if (!data.WriteInt32(requestCode)) {
70 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
71 return INNER_ERR;
72 }
73
74 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY, data, reply, option);
75 if (error != NO_ERROR) {
76 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
77 return error;
78 }
79 return reply.ReadInt32();
80 }
81
GetTopAbility(bool isNeedLocalDeviceId)82 AppExecFwk::ElementName AbilityManagerProxy::GetTopAbility(bool isNeedLocalDeviceId)
83 {
84 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
85 MessageParcel data;
86 MessageParcel reply;
87 MessageOption option;
88 if (!WriteInterfaceToken(data)) {
89 return {};
90 }
91 if (!data.WriteBool(isNeedLocalDeviceId)) {
92 return {};
93 }
94
95 int error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY, data, reply, option);
96 if (error != NO_ERROR) {
97 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
98 return {};
99 }
100 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
101 if (!name) {
102 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read info failed.");
103 return {};
104 }
105 AppExecFwk::ElementName result = *name;
106 return result;
107 }
108
GetElementNameByToken(sptr<IRemoteObject> token,bool isNeedLocalDeviceId)109 AppExecFwk::ElementName AbilityManagerProxy::GetElementNameByToken(sptr<IRemoteObject> token,
110 bool isNeedLocalDeviceId)
111 {
112 MessageParcel data;
113 MessageParcel reply;
114 MessageOption option;
115 if (!WriteInterfaceToken(data)) {
116 return {};
117 }
118 if (!data.WriteRemoteObject(token)) {
119 return {};
120 }
121 if (!data.WriteBool(isNeedLocalDeviceId)) {
122 return {};
123 }
124 int error = SendRequest(AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN, data, reply, option);
125 if (error != NO_ERROR) {
126 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
127 return {};
128 }
129 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
130 if (!name) {
131 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read info failed.");
132 return {};
133 }
134 AppExecFwk::ElementName result = *name;
135 return result;
136 }
137
StartAbility(const Want & want,const AbilityStartSetting & abilityStartSetting,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)138 int AbilityManagerProxy::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
139 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
140 {
141 int error;
142 MessageParcel data;
143 MessageParcel reply;
144 MessageOption option;
145 if (!WriteInterfaceToken(data)) {
146 return INNER_ERR;
147 }
148 if (!data.WriteParcelable(&want)) {
149 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
150 return INNER_ERR;
151 }
152 if (!data.WriteParcelable(&abilityStartSetting)) {
153 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityStartSetting write failed.");
154 return INNER_ERR;
155 }
156 if (callerToken) {
157 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
158 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
159 return INNER_ERR;
160 }
161 } else {
162 if (!data.WriteBool(false)) {
163 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
164 return INNER_ERR;
165 }
166 }
167 if (!data.WriteInt32(userId)) {
168 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
169 return INNER_ERR;
170 }
171 if (!data.WriteInt32(requestCode)) {
172 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
173 return INNER_ERR;
174 }
175 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS, data, reply, option);
176 if (error != NO_ERROR) {
177 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
178 return error;
179 }
180 return reply.ReadInt32();
181 }
182
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)183 int AbilityManagerProxy::StartAbility(
184 const Want &want, const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
185 {
186 int error;
187 MessageParcel data;
188 MessageParcel reply;
189 MessageOption option;
190
191 if (!WriteInterfaceToken(data)) {
192 return INNER_ERR;
193 }
194 if (!data.WriteParcelable(&want)) {
195 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
196 return INNER_ERR;
197 }
198 if (callerToken) {
199 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
200 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write failed.");
201 return INNER_ERR;
202 }
203 } else {
204 if (!data.WriteBool(false)) {
205 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
206 return INNER_ERR;
207 }
208 }
209 if (!data.WriteInt32(userId)) {
210 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
211 return INNER_ERR;
212 }
213 if (!data.WriteInt32(requestCode)) {
214 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
215 return INNER_ERR;
216 }
217 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER, data, reply, option);
218 if (error != NO_ERROR) {
219 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
220 return error;
221 }
222 return reply.ReadInt32();
223 }
224
StartAbilityWithSpecifyTokenId(const Want & want,const sptr<IRemoteObject> & callerToken,uint32_t specifyTokenId,int32_t userId,int requestCode)225 int AbilityManagerProxy::StartAbilityWithSpecifyTokenId(
226 const Want &want, const sptr<IRemoteObject> &callerToken, uint32_t specifyTokenId, int32_t userId, int requestCode)
227 {
228 int error;
229 MessageParcel data;
230 MessageParcel reply;
231 MessageOption option;
232
233 if (!WriteInterfaceToken(data)) {
234 return INNER_ERR;
235 }
236 if (!data.WriteParcelable(&want)) {
237 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
238 return INNER_ERR;
239 }
240 if (callerToken) {
241 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
242 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write failed.");
243 return INNER_ERR;
244 }
245 } else {
246 if (!data.WriteBool(false)) {
247 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
248 return INNER_ERR;
249 }
250 }
251 if (!data.WriteInt32(specifyTokenId)) {
252 TAG_LOGE(AAFwkTag::ABILITYMGR, "specifyTokenId write failed.");
253 return INNER_ERR;
254 }
255 if (!data.WriteInt32(userId)) {
256 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
257 return INNER_ERR;
258 }
259 if (!data.WriteInt32(requestCode)) {
260 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
261 return INNER_ERR;
262 }
263 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_WITH_SPECIFY_TOKENID, data, reply, option);
264 if (error != NO_ERROR) {
265 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
266 return error;
267 }
268 return reply.ReadInt32();
269 }
270
StartAbilityByInsightIntent(const Want & want,const sptr<IRemoteObject> & callerToken,uint64_t intentId,int32_t userId)271 int32_t AbilityManagerProxy::StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
272 uint64_t intentId, int32_t userId)
273 {
274 MessageParcel data;
275 if (callerToken == nullptr) {
276 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid callertoken.");
277 return INNER_ERR;
278 }
279
280 if (!WriteInterfaceToken(data)) {
281 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
282 return INNER_ERR;
283 }
284
285 if (!data.WriteParcelable(&want)) {
286 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
287 return INNER_ERR;
288 }
289
290 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
291 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write failed.");
292 return INNER_ERR;
293 }
294
295 if (!data.WriteUint64(intentId)) {
296 TAG_LOGE(AAFwkTag::ABILITYMGR, "intentId write failed.");
297 return INNER_ERR;
298 }
299
300 if (!data.WriteInt32(userId)) {
301 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
302 return INNER_ERR;
303 }
304
305 MessageParcel reply;
306 MessageOption option;
307 int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT, data, reply, option);
308 if (error != NO_ERROR) {
309 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to start ability err: %{public}d", error);
310 return error;
311 }
312 return reply.ReadInt32();
313 }
314
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)315 int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &startOptions,
316 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
317 {
318 int error;
319 MessageParcel data;
320 MessageParcel reply;
321 MessageOption option;
322 if (!WriteInterfaceToken(data)) {
323 return INNER_ERR;
324 }
325 if (!data.WriteParcelable(&want)) {
326 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
327 return INNER_ERR;
328 }
329 if (!data.WriteParcelable(&startOptions)) {
330 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write failed.");
331 return INNER_ERR;
332 }
333 if (callerToken) {
334 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
335 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
336 return INNER_ERR;
337 }
338 } else {
339 if (!data.WriteBool(false)) {
340 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
341 return INNER_ERR;
342 }
343 }
344 if (!data.WriteInt32(userId)) {
345 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
346 return INNER_ERR;
347 }
348 if (!data.WriteInt32(requestCode)) {
349 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
350 return INNER_ERR;
351 }
352 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS, data, reply, option);
353 if (error != NO_ERROR) {
354 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
355 return error;
356 }
357 return reply.ReadInt32();
358 }
359
StartAbilityAsCaller(const Want & want,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int32_t userId,int requestCode)360 int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const sptr<IRemoteObject> &callerToken,
361 sptr<IRemoteObject> asCallerSourceToken, int32_t userId, int requestCode)
362 {
363 MessageParcel data;
364 MessageParcel reply;
365 MessageOption option;
366 if (!WriteInterfaceToken(data)) {
367 return INNER_ERR;
368 }
369 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
370 if (callerToken) {
371 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
372 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
373 } else {
374 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
375 }
376 if (asCallerSourceToken) {
377 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
378 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, asCallerSourceToken);
379 } else {
380 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
381 }
382 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
383 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
384 int error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN, data, reply, option);
385 if (error != NO_ERROR) {
386 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
387 return error;
388 }
389 return reply.ReadInt32();
390 }
391
StartAbilityAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int32_t userId,int requestCode)392 int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const StartOptions &startOptions,
393 const sptr<IRemoteObject> &callerToken, sptr<IRemoteObject> asCallerSourceToken,
394 int32_t userId, int requestCode)
395 {
396 int error;
397 MessageParcel data;
398 MessageParcel reply;
399 MessageOption option;
400 if (!WriteInterfaceToken(data)) {
401 return INNER_ERR;
402 }
403 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
404 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &startOptions);
405 if (callerToken) {
406 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
407 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
408 } else {
409 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
410 }
411 if (asCallerSourceToken) {
412 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
413 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, asCallerSourceToken);
414 } else {
415 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
416 }
417 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
418 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
419
420 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS, data, reply, option);
421 if (error != NO_ERROR) {
422 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
423 return error;
424 }
425 return reply.ReadInt32();
426 }
427
StartAbilityForResultAsCaller(const Want & want,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)428 int AbilityManagerProxy::StartAbilityForResultAsCaller(
429 const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
430 {
431 MessageParcel data;
432 if (!WriteInterfaceToken(data)) {
433 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
434 return INNER_ERR;
435 }
436 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
437 if (callerToken) {
438 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
439 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
440 } else {
441 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
442 }
443 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
444 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
445 MessageParcel reply;
446 MessageOption option;
447 int error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER, data, reply, option);
448 if (error != NO_ERROR) {
449 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
450 return error;
451 }
452 return reply.ReadInt32();
453 }
454
StartAbilityForResultAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)455 int AbilityManagerProxy::StartAbilityForResultAsCaller(const Want &want, const StartOptions &startOptions,
456 const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
457 {
458 MessageParcel data;
459 if (!WriteInterfaceToken(data)) {
460 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
461 return INNER_ERR;
462 }
463 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
464 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &startOptions);
465 if (callerToken) {
466 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
467 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
468 } else {
469 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
470 }
471 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
472 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
473 MessageParcel reply;
474 MessageOption option;
475 int error =
476 SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER_FOR_OPTIONS, data, reply, option);
477 if (error != NO_ERROR) {
478 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
479 return error;
480 }
481 return reply.ReadInt32();
482 }
483
CheckUISessionParams(MessageParcel & data,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)484 int AbilityManagerProxy::CheckUISessionParams(MessageParcel &data, const sptr<IRemoteObject> &callerToken,
485 const sptr<SessionInfo> &sessionInfo, int32_t userId, int requestCode)
486 {
487 if (callerToken) {
488 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
489 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write failed.");
490 return INNER_ERR;
491 }
492 } else {
493 if (!data.WriteBool(false)) {
494 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
495 return INNER_ERR;
496 }
497 }
498 if (sessionInfo) {
499 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
500 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
501 return INNER_ERR;
502 }
503 } else {
504 if (!data.WriteBool(false)) {
505 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
506 return INNER_ERR;
507 }
508 }
509 if (!data.WriteInt32(userId)) {
510 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
511 return INNER_ERR;
512 }
513 if (!data.WriteInt32(requestCode)) {
514 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
515 return INNER_ERR;
516 }
517 return ERR_OK;
518 }
519
StartAbilityByUIContentSession(const Want & want,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)520 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want,
521 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
522 int32_t userId, int requestCode)
523 {
524 int error;
525 MessageParcel data;
526 MessageParcel reply;
527 MessageOption option;
528 if (!WriteInterfaceToken(data)) {
529 return INNER_ERR;
530 }
531 if (!data.WriteParcelable(&want)) {
532 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
533 return INNER_ERR;
534 }
535 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
536 return INNER_ERR;
537 }
538 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER, data, reply, option);
539 if (error != NO_ERROR) {
540 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
541 return error;
542 }
543 return reply.ReadInt32();
544 }
545
StartAbilityByUIContentSession(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)546 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want, const StartOptions &startOptions,
547 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
548 int32_t userId, int requestCode)
549 {
550 int error;
551 MessageParcel data;
552 MessageParcel reply;
553 MessageOption option;
554 if (!WriteInterfaceToken(data)) {
555 return INNER_ERR;
556 }
557 if (!data.WriteParcelable(&want)) {
558 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
559 return INNER_ERR;
560 }
561 if (!data.WriteParcelable(&startOptions)) {
562 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write failed.");
563 return INNER_ERR;
564 }
565 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
566 return INNER_ERR;
567 }
568 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS, data, reply, option);
569 if (error != NO_ERROR) {
570 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
571 return error;
572 }
573 return reply.ReadInt32();
574 }
575
StartAbilityOnlyUIAbility(const Want & want,const sptr<IRemoteObject> & callerToken,uint32_t specifyTokenId)576 int AbilityManagerProxy::StartAbilityOnlyUIAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
577 uint32_t specifyTokenId)
578 {
579 MessageParcel data;
580 if (callerToken == nullptr) {
581 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid callertoken.");
582 return INNER_ERR;
583 }
584
585 if (!WriteInterfaceToken(data)) {
586 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
587 return INNER_ERR;
588 }
589
590 if (!data.WriteParcelable(&want)) {
591 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
592 return INNER_ERR;
593 }
594
595 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
596 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write failed.");
597 return INNER_ERR;
598 }
599
600 if (!data.WriteUint32(specifyTokenId)) {
601 TAG_LOGE(AAFwkTag::ABILITYMGR, "specifyTokenId write failed.");
602 return INNER_ERR;
603 }
604
605 MessageParcel reply;
606 MessageOption option;
607 int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_ONLY_UI_ABILITY, data, reply, option);
608 if (error != NO_ERROR) {
609 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to start ability err: %{public}d", error);
610 return error;
611 }
612 return reply.ReadInt32();
613 }
614
StartExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)615 int AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
616 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
617 {
618 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
619 int error;
620 MessageParcel data;
621 MessageParcel reply;
622 MessageOption option;
623 if (!WriteInterfaceToken(data)) {
624 return INNER_ERR;
625 }
626 if (!data.WriteParcelable(&want)) {
627 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
628 return INNER_ERR;
629 }
630 if (callerToken) {
631 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
632 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
633 return INNER_ERR;
634 }
635 } else {
636 if (!data.WriteBool(false)) {
637 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
638 return INNER_ERR;
639 }
640 }
641 if (!data.WriteInt32(userId)) {
642 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility, userId write failed.");
643 return INNER_ERR;
644 }
645 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
646 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility, extensionType write failed.");
647 return INNER_ERR;
648 }
649 error = SendRequest(AbilityManagerInterfaceCode::START_EXTENSION_ABILITY, data, reply, option);
650 if (error != NO_ERROR) {
651 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility, Send request error: %{public}d", error);
652 return error;
653 }
654 return reply.ReadInt32();
655 }
656
RequestModalUIExtension(const Want & want)657 int AbilityManagerProxy::RequestModalUIExtension(const Want &want)
658 {
659 MessageParcel data;
660 if (!WriteInterfaceToken(data)) {
661 return INNER_ERR;
662 }
663 if (!data.WriteParcelable(&want)) {
664 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
665 return INNER_ERR;
666 }
667
668 int error;
669 MessageParcel reply;
670 MessageOption option;
671 error = SendRequest(AbilityManagerInterfaceCode::REQUESET_MODAL_UIEXTENSION, data, reply, option);
672 if (error != NO_ERROR) {
673 TAG_LOGE(AAFwkTag::ABILITYMGR, "RequestModalUIExtension, Send request error: %{public}d", error);
674 return error;
675 }
676 return reply.ReadInt32();
677 }
678
PreloadUIExtensionAbility(const Want & want,std::string & hostBundleName,int32_t userId)679 int AbilityManagerProxy::PreloadUIExtensionAbility(const Want &want, std::string &hostBundleName, int32_t userId)
680 {
681 MessageParcel data;
682 if (!WriteInterfaceToken(data)) {
683 return INNER_ERR;
684 }
685
686 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
687
688 if (!data.WriteString16(Str8ToStr16(hostBundleName))) {
689 TAG_LOGE(AAFwkTag::ABILITYMGR, "hostBundleName write failed.");
690 return ERR_INVALID_VALUE;
691 }
692
693 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
694 int error;
695 MessageParcel reply;
696 MessageOption option;
697 error = SendRequest(AbilityManagerInterfaceCode::PRELOAD_UIEXTENSION_ABILITY, data, reply, option);
698 if (error != NO_ERROR) {
699 TAG_LOGE(AAFwkTag::ABILITYMGR, "PreloadUIExtensionAbility, Send request error: %{public}d", error);
700 return error;
701 }
702 return reply.ReadInt32();
703 }
704
ChangeAbilityVisibility(sptr<IRemoteObject> token,bool isShow)705 int AbilityManagerProxy::ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow)
706 {
707 MessageParcel data;
708 MessageParcel reply;
709 MessageOption option;
710 if (!WriteInterfaceToken(data)) {
711 return ERR_NATIVE_IPC_PARCEL_FAILED;
712 }
713 if (!data.WriteRemoteObject(token)) {
714 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed.");
715 return ERR_NATIVE_IPC_PARCEL_FAILED;
716 }
717 if (!data.WriteBool(isShow)) {
718 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isShow failed.");
719 return ERR_NATIVE_IPC_PARCEL_FAILED;
720 }
721 auto error = SendRequest(AbilityManagerInterfaceCode::CHANGE_ABILITY_VISIBILITY, data, reply, option);
722 if (error != NO_ERROR) {
723 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
724 return error;
725 }
726 return reply.ReadInt32();
727 }
728
ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo,bool isShow)729 int AbilityManagerProxy::ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow)
730 {
731 MessageParcel data;
732 MessageParcel reply;
733 MessageOption option;
734 if (!WriteInterfaceToken(data)) {
735 return ERR_NATIVE_IPC_PARCEL_FAILED;
736 }
737 if (!data.WriteParcelable(sessionInfo)) {
738 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed.");
739 return ERR_NATIVE_IPC_PARCEL_FAILED;
740 }
741 if (!data.WriteBool(isShow)) {
742 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isShow failed.");
743 return ERR_NATIVE_IPC_PARCEL_FAILED;
744 }
745 auto error = SendRequest(AbilityManagerInterfaceCode::CHANGE_UI_ABILITY_VISIBILITY_BY_SCB, data, reply, option);
746 if (error != NO_ERROR) {
747 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
748 return error;
749 }
750 return reply.ReadInt32();
751 }
752
StartUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int32_t userId)753 int AbilityManagerProxy::StartUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int32_t userId)
754 {
755 int error;
756 MessageParcel data;
757 MessageParcel reply;
758 MessageOption option;
759 if (!WriteInterfaceToken(data)) {
760 return INNER_ERR;
761 }
762
763 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
764 "connect ability fail, extensionSessionInfo is nullptr");
765 if (extensionSessionInfo) {
766 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
767 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write failed.");
768 return INNER_ERR;
769 }
770 } else {
771 if (!data.WriteBool(false)) {
772 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
773 return INNER_ERR;
774 }
775 }
776
777 if (!data.WriteInt32(userId)) {
778 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility, userId write failed.");
779 return INNER_ERR;
780 }
781
782 if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::EMBEDDED) {
783 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_EMBEDDED, data, reply, option);
784 } else if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::MODAL) {
785 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY, data, reply, option);
786 } else {
787 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_CONSTRAINED_EMBEDDED, data, reply, option);
788 }
789
790 if (error != NO_ERROR) {
791 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility, Send request error: %{public}d", error);
792 return error;
793 }
794 return reply.ReadInt32();
795 }
796
StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo,bool & isColdStart,uint32_t sceneFlag)797 int AbilityManagerProxy::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isColdStart, uint32_t sceneFlag)
798 {
799 MessageParcel data;
800 MessageParcel reply;
801 MessageOption option;
802 if (!WriteInterfaceToken(data)) {
803 return INNER_ERR;
804 }
805 if (sessionInfo) {
806 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
807 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
808 return INNER_ERR;
809 }
810 } else {
811 if (!data.WriteBool(false)) {
812 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
813 return INNER_ERR;
814 }
815 }
816 if (!data.WriteUint32(sceneFlag)) {
817 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write failed.");
818 return INNER_ERR;
819 }
820 auto error = SendRequest(AbilityManagerInterfaceCode::START_UI_ABILITY_BY_SCB, data, reply, option);
821 if (error != NO_ERROR) {
822 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
823 return error;
824 }
825 isColdStart = reply.ReadBool();
826 return reply.ReadInt32();
827 }
828
StopExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)829 int AbilityManagerProxy::StopExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
830 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
831 {
832 int error;
833 MessageParcel data;
834 MessageParcel reply;
835 MessageOption option;
836 if (!WriteInterfaceToken(data)) {
837 return INNER_ERR;
838 }
839 if (!data.WriteParcelable(&want)) {
840 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
841 return INNER_ERR;
842 }
843 if (callerToken) {
844 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
845 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
846 return INNER_ERR;
847 }
848 } else {
849 if (!data.WriteBool(false)) {
850 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
851 return INNER_ERR;
852 }
853 }
854 if (!data.WriteInt32(userId)) {
855 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
856 return INNER_ERR;
857 }
858 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
859 TAG_LOGE(AAFwkTag::ABILITYMGR, "extensionType write failed.");
860 return INNER_ERR;
861 }
862 error = SendRequest(AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY, data, reply, option);
863 if (error != NO_ERROR) {
864 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
865 return error;
866 }
867 return reply.ReadInt32();
868 }
869
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)870 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
871 {
872 return TerminateAbility(token, resultCode, resultWant, true);
873 }
874
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant,bool flag)875 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token,
876 int resultCode, const Want *resultWant, bool flag)
877 {
878 int error;
879 MessageParcel data;
880 MessageParcel reply;
881 MessageOption option;
882
883 if (!WriteInterfaceToken(data)) {
884 return INNER_ERR;
885 }
886 if (token) {
887 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
888 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write failed.");
889 return INNER_ERR;
890 }
891 } else {
892 if (!data.WriteBool(false)) {
893 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
894 return INNER_ERR;
895 }
896 }
897 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
898 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
899 return INNER_ERR;
900 }
901 if (!data.WriteBool(flag)) {
902 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write flag failed.");
903 return INNER_ERR;
904 }
905 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_ABILITY, data, reply, option);
906 if (error != NO_ERROR) {
907 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
908 return error;
909 }
910 return reply.ReadInt32();
911 }
912
BackToCallerAbilityWithResult(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant,int64_t callerRequestCode)913 int AbilityManagerProxy::BackToCallerAbilityWithResult(const sptr<IRemoteObject> &token, int resultCode,
914 const Want *resultWant, int64_t callerRequestCode)
915 {
916 int error;
917 MessageParcel data;
918 MessageParcel reply;
919 MessageOption option;
920
921 CHECK_POINTER_AND_RETURN_LOG(token, ERR_INVALID_VALUE, "null token");
922
923 if (!WriteInterfaceToken(data)) {
924 return INNER_ERR;
925 }
926
927 if (token) {
928 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
929 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed");
930 return INNER_ERR;
931 }
932 } else {
933 if (!data.WriteBool(false)) {
934 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed");
935 return INNER_ERR;
936 }
937 }
938 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
939 TAG_LOGE(AAFwkTag::ABILITYMGR, "write ability result failed");
940 return INNER_ERR;
941 }
942 if (!data.WriteInt64(callerRequestCode)) {
943 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestCode failed");
944 return INNER_ERR;
945 }
946 error = SendRequest(AbilityManagerInterfaceCode::BACK_TO_CALLER_UIABILITY, data, reply, option);
947 if (error != NO_ERROR) {
948 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
949 return error;
950 }
951 return reply.ReadInt32();
952 }
953
TerminateUIServiceExtensionAbility(const sptr<IRemoteObject> & token)954 int32_t AbilityManagerProxy::TerminateUIServiceExtensionAbility(const sptr<IRemoteObject> &token)
955 {
956 int error;
957 MessageParcel data;
958 MessageParcel reply;
959 MessageOption option;
960
961 if (!WriteInterfaceToken(data)) {
962 return INNER_ERR;
963 }
964 if (token) {
965 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
966 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write fail");
967 return INNER_ERR;
968 }
969 } else {
970 if (!data.WriteBool(false)) {
971 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
972 return INNER_ERR;
973 }
974 }
975
976 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_UI_SERVICE_EXTENSION_ABILITY, data, reply, option);
977 if (error != NO_ERROR) {
978 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
979 return error;
980 }
981 return reply.ReadInt32();
982 }
983
TerminateUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int resultCode,const Want * resultWant)984 int AbilityManagerProxy::TerminateUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int resultCode,
985 const Want *resultWant)
986 {
987 int error;
988 MessageParcel data;
989 MessageParcel reply;
990 MessageOption option;
991
992 if (!WriteInterfaceToken(data)) {
993 return INNER_ERR;
994 }
995
996 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
997 "connect ability fail, extensionSessionInfo is nullptr");
998 if (extensionSessionInfo) {
999 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
1000 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write failed.");
1001 return INNER_ERR;
1002 }
1003 } else {
1004 if (!data.WriteBool(false)) {
1005 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
1006 return INNER_ERR;
1007 }
1008 }
1009
1010 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
1011 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1012 return INNER_ERR;
1013 }
1014
1015 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY, data, reply, option);
1016 if (error != NO_ERROR) {
1017 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1018 return error;
1019 }
1020 return reply.ReadInt32();
1021 }
1022
CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token)1023 int AbilityManagerProxy::CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token)
1024 {
1025 if (token == nullptr) {
1026 TAG_LOGE(AAFwkTag::ABILITYMGR, "input invalid");
1027 return ERR_INVALID_VALUE;
1028 }
1029
1030 MessageParcel data;
1031 if (!WriteInterfaceToken(data)) {
1032 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
1033 return INNER_ERR;
1034 }
1035
1036 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1037 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and token fail");
1038 return INNER_ERR;
1039 }
1040
1041 MessageParcel reply;
1042 MessageOption option;
1043 auto error = SendRequest(AbilityManagerInterfaceCode::CLOSE_UI_EXTENSION_ABILITY_BY_SCB, data, reply, option);
1044 if (error != NO_ERROR) {
1045 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1046 return error;
1047 }
1048 return reply.ReadInt32();
1049 }
1050
CloseUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo)1051 int AbilityManagerProxy::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo)
1052 {
1053 int error;
1054 MessageParcel data;
1055 MessageParcel reply;
1056 MessageOption option;
1057
1058 if (!WriteInterfaceToken(data)) {
1059 return INNER_ERR;
1060 }
1061
1062 if (sessionInfo) {
1063 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
1064 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
1065 return INNER_ERR;
1066 }
1067 } else {
1068 if (!data.WriteBool(false)) {
1069 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
1070 return INNER_ERR;
1071 }
1072 }
1073
1074 error = SendRequest(AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB, data, reply, option);
1075 if (error != NO_ERROR) {
1076 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed, Send request error: %{public}d", error);
1077 return error;
1078 }
1079 return reply.ReadInt32();
1080 }
1081
SendResultToAbility(int32_t requestCode,int32_t resultCode,Want & resultWant)1082 int AbilityManagerProxy::SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant)
1083 {
1084 int error;
1085 MessageParcel data;
1086 MessageParcel reply;
1087 MessageOption option;
1088
1089 if (!WriteInterfaceToken(data)) {
1090 return INNER_ERR;
1091 }
1092 if (!data.WriteInt32(requestCode)) {
1093 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
1094 return INNER_ERR;
1095 }
1096 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(&resultWant)) {
1097 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1098 return INNER_ERR;
1099 }
1100 error = SendRequest(AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY, data, reply, option);
1101 if (error != NO_ERROR) {
1102 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1103 return error;
1104 }
1105 return reply.ReadInt32();
1106 }
1107
MoveAbilityToBackground(const sptr<IRemoteObject> & token)1108 int AbilityManagerProxy::MoveAbilityToBackground(const sptr<IRemoteObject> &token)
1109 {
1110 int error;
1111 MessageParcel data;
1112 MessageParcel reply;
1113 MessageOption option;
1114
1115 if (!WriteInterfaceToken(data)) {
1116 return INNER_ERR;
1117 }
1118 if (token) {
1119 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1120 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write failed.");
1121 return INNER_ERR;
1122 }
1123 } else {
1124 if (!data.WriteBool(false)) {
1125 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
1126 return INNER_ERR;
1127 }
1128 }
1129 error = SendRequest(AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND, data, reply, option);
1130 if (error != NO_ERROR) {
1131 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", error);
1132 return error;
1133 }
1134 return reply.ReadInt32();
1135 }
1136
MoveUIAbilityToBackground(const sptr<IRemoteObject> token)1137 int32_t AbilityManagerProxy::MoveUIAbilityToBackground(const sptr<IRemoteObject> token)
1138 {
1139 CHECK_POINTER_AND_RETURN_LOG(token, ERR_INVALID_VALUE, "MoveUIAbilityToBackground fail, token is null");
1140 MessageParcel data;
1141 MessageParcel reply;
1142 MessageOption option;
1143
1144 if (!WriteInterfaceToken(data)) {
1145 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
1146 return IPC_PROXY_ERR;
1147 }
1148 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, token);
1149 int32_t error = SendRequest(AbilityManagerInterfaceCode::MOVE_UI_ABILITY_TO_BACKGROUND, data, reply, option);
1150 if (error != NO_ERROR) {
1151 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", error);
1152 return error;
1153 }
1154 return reply.ReadInt32();
1155 }
1156
CloseAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)1157 int AbilityManagerProxy::CloseAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
1158 {
1159 return TerminateAbility(token, resultCode, resultWant, false);
1160 }
1161
ConnectAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)1162 int AbilityManagerProxy::ConnectAbility(
1163 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken, int32_t userId)
1164 {
1165 return ConnectAbilityCommon(want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId);
1166 }
1167
ConnectAbilityCommon(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,AppExecFwk::ExtensionAbilityType extensionType,int32_t userId,bool isQueryExtensionOnly)1168 int AbilityManagerProxy::ConnectAbilityCommon(
1169 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken,
1170 AppExecFwk::ExtensionAbilityType extensionType, int32_t userId, bool isQueryExtensionOnly)
1171 {
1172 MessageParcel data;
1173 MessageParcel reply;
1174 MessageOption option;
1175 if (!WriteInterfaceToken(data)) {
1176 return INNER_ERR;
1177 }
1178 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
1179 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "connect ability fail, connect is nullptr");
1180 if (connect->AsObject()) {
1181 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1182 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, connect->AsObject());
1183 } else {
1184 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1185 }
1186 if (callerToken) {
1187 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1188 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
1189 } else {
1190 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1191 }
1192 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
1193 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, static_cast<int32_t>(extensionType));
1194 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, isQueryExtensionOnly);
1195 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE, data, reply, option);
1196 if (error != NO_ERROR) {
1197 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s, Send request error: %{public}d", __func__, error);
1198 return error;
1199 }
1200 return reply.ReadInt32();
1201 }
1202
ConnectUIExtensionAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<SessionInfo> & sessionInfo,int32_t userId,sptr<UIExtensionAbilityConnectInfo> connectInfo)1203 int AbilityManagerProxy::ConnectUIExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect,
1204 const sptr<SessionInfo> &sessionInfo, int32_t userId, sptr<UIExtensionAbilityConnectInfo> connectInfo)
1205 {
1206 MessageParcel data;
1207 MessageParcel reply;
1208 MessageOption option;
1209
1210 if (!WriteInterfaceToken(data)) {
1211 return INNER_ERR;
1212 }
1213 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
1214 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "connect ability fail, connect is nullptr");
1215 if (connect->AsObject()) {
1216 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1217 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, connect->AsObject());
1218 } else {
1219 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1220 }
1221 CHECK_POINTER_AND_RETURN_LOG(sessionInfo, ERR_INVALID_VALUE, "connect ability fail, sessionInfo is nullptr");
1222 if (sessionInfo) {
1223 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1224 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, sessionInfo);
1225 } else {
1226 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1227 }
1228 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
1229 if (connectInfo != nullptr) {
1230 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1231 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, connectInfo);
1232 } else {
1233 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1234 }
1235
1236 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY, data, reply, option);
1237 if (error != NO_ERROR) {
1238 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1239 return error;
1240 }
1241 if (connectInfo != nullptr) {
1242 sptr<UIExtensionAbilityConnectInfo> replyInfo = reply.ReadParcelable<UIExtensionAbilityConnectInfo>();
1243 if (replyInfo != nullptr) {
1244 connectInfo->uiExtensionAbilityId = replyInfo->uiExtensionAbilityId;
1245 TAG_LOGD(AAFwkTag::ABILITYMGR, "UIExtensionAbilityId is %{public}d.", connectInfo->uiExtensionAbilityId);
1246 }
1247 }
1248 return reply.ReadInt32();
1249 }
1250
DisconnectAbility(sptr<IAbilityConnection> connect)1251 int AbilityManagerProxy::DisconnectAbility(sptr<IAbilityConnection> connect)
1252 {
1253 int error;
1254 MessageParcel data;
1255 MessageParcel reply;
1256 MessageOption option;
1257 if (connect == nullptr) {
1258 TAG_LOGE(AAFwkTag::ABILITYMGR, "disconnect ability fail, connect is nullptr");
1259 return ERR_INVALID_VALUE;
1260 }
1261 if (!WriteInterfaceToken(data)) {
1262 return INNER_ERR;
1263 }
1264 if (!data.WriteRemoteObject(connect->AsObject())) {
1265 TAG_LOGE(AAFwkTag::ABILITYMGR, "connect write failed.");
1266 return ERR_INVALID_VALUE;
1267 }
1268
1269 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY, data, reply, option);
1270 if (error != NO_ERROR) {
1271 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1272 return error;
1273 }
1274 return reply.ReadInt32();
1275 }
1276
AcquireDataAbility(const Uri & uri,bool tryBind,const sptr<IRemoteObject> & callerToken)1277 sptr<IAbilityScheduler> AbilityManagerProxy::AcquireDataAbility(
1278 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken)
1279 {
1280 int error;
1281 MessageParcel data;
1282 MessageParcel reply;
1283 MessageOption option;
1284
1285 if (!callerToken) {
1286 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid parameters for acquire data ability.");
1287 return nullptr;
1288 }
1289 if (!WriteInterfaceToken(data)) {
1290 return nullptr;
1291 }
1292 if (!data.WriteString(uri.ToString()) || !data.WriteBool(tryBind) || !data.WriteRemoteObject(callerToken)) {
1293 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1294 return nullptr;
1295 }
1296
1297 error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY, data, reply, option);
1298 if (error != NO_ERROR) {
1299 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1300 return nullptr;
1301 }
1302
1303 return iface_cast<IAbilityScheduler>(reply.ReadRemoteObject());
1304 }
1305
ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler,const sptr<IRemoteObject> & callerToken)1306 int AbilityManagerProxy::ReleaseDataAbility(
1307 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken)
1308 {
1309 int error;
1310 MessageParcel data;
1311 MessageParcel reply;
1312 MessageOption option;
1313
1314 if (!dataAbilityScheduler || !callerToken) {
1315 return ERR_INVALID_VALUE;
1316 }
1317 if (!WriteInterfaceToken(data)) {
1318 return INNER_ERR;
1319 }
1320 if (!data.WriteRemoteObject(dataAbilityScheduler->AsObject()) || !data.WriteRemoteObject(callerToken)) {
1321 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1322 return INNER_ERR;
1323 }
1324
1325 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY, data, reply, option);
1326 if (error != NO_ERROR) {
1327 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1328 return error;
1329 }
1330 return reply.ReadInt32();
1331 }
1332
AttachAbilityThread(const sptr<IAbilityScheduler> & scheduler,const sptr<IRemoteObject> & token)1333 int AbilityManagerProxy::AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)
1334 {
1335 int error;
1336 MessageParcel data;
1337 MessageParcel reply;
1338 MessageOption option;
1339 AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
1340 if (scheduler == nullptr) {
1341 return ERR_INVALID_VALUE;
1342 }
1343 if (!WriteInterfaceToken(data)) {
1344 return INNER_ERR;
1345 }
1346 if (!data.WriteRemoteObject(scheduler->AsObject()) || !data.WriteRemoteObject(token)) {
1347 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1348 return ERR_INVALID_VALUE;
1349 }
1350
1351 error = SendRequest(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD, data, reply, option);
1352 if (error != NO_ERROR) {
1353 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1354 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
1355 std::string("ERROR AttachAbilityThread failed IPC error") + std::to_string(error));
1356 return error;
1357 }
1358 return reply.ReadInt32();
1359 }
1360
AbilityTransitionDone(const sptr<IRemoteObject> & token,int state,const PacMap & saveData)1361 int AbilityManagerProxy::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData)
1362 {
1363 int error;
1364 MessageParcel data;
1365 MessageParcel reply;
1366 MessageOption option;
1367
1368 AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::FOREGROUND};
1369 if (!WriteInterfaceToken(data)) {
1370 return INNER_ERR;
1371 }
1372 if (!data.WriteRemoteObject(token) || !data.WriteInt32(state)) {
1373 TAG_LOGE(AAFwkTag::ABILITYMGR, "token or state write failed.");
1374 return ERR_INVALID_VALUE;
1375 }
1376 if (!data.WriteParcelable(&saveData)) {
1377 TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write failed.");
1378 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
1379 "write saveData failed");
1380 return INNER_ERR;
1381 }
1382
1383 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE, data, reply, option);
1384 if (error != NO_ERROR) {
1385 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1386 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
1387 std::string("ERROR AbilityTransitionDone failed IPC error") + std::to_string(error));
1388 return error;
1389 }
1390 return reply.ReadInt32();
1391 }
1392
AbilityWindowConfigTransitionDone(const sptr<IRemoteObject> & token,const WindowConfig & windowConfig)1393 int AbilityManagerProxy::AbilityWindowConfigTransitionDone(
1394 const sptr<IRemoteObject> &token, const WindowConfig &windowConfig)
1395 {
1396 int error;
1397 MessageParcel data;
1398 MessageParcel reply;
1399 MessageOption option(MessageOption::TF_ASYNC);
1400
1401 if (!WriteInterfaceToken(data)) {
1402 return INNER_ERR;
1403 }
1404 if (!data.WriteRemoteObject(token)) {
1405 TAG_LOGE(AAFwkTag::ABILITYMGR, "token or state write failed.");
1406 return ERR_INVALID_VALUE;
1407 }
1408 if (!data.WriteParcelable(&windowConfig)) {
1409 TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write failed.");
1410 return INNER_ERR;
1411 }
1412
1413 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_WINDOW_CONFIG_TRANSITION_DONE, data, reply, option);
1414 if (error != NO_ERROR) {
1415 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1416 return error;
1417 }
1418 return reply.ReadInt32();
1419 }
1420
ScheduleConnectAbilityDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & remoteObject)1421 int AbilityManagerProxy::ScheduleConnectAbilityDone(
1422 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject)
1423 {
1424 int error;
1425 MessageParcel data;
1426 MessageParcel reply;
1427 MessageOption option;
1428
1429 if (!WriteInterfaceToken(data)) {
1430 return INNER_ERR;
1431 }
1432
1433 if (token) {
1434 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1435 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and token.");
1436 return ERR_INVALID_VALUE;
1437 }
1438 } else {
1439 if (!data.WriteBool(false)) {
1440 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
1441 return ERR_INVALID_VALUE;
1442 }
1443 }
1444
1445 if (remoteObject) {
1446 if (!data.WriteBool(true) || !data.WriteRemoteObject(remoteObject)) {
1447 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and remoteObject.");
1448 return ERR_INVALID_VALUE;
1449 }
1450 } else {
1451 if (!data.WriteBool(false)) {
1452 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
1453 return ERR_INVALID_VALUE;
1454 }
1455 }
1456
1457 error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE, data, reply, option);
1458 if (error != NO_ERROR) {
1459 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1460 return error;
1461 }
1462 return reply.ReadInt32();
1463 }
1464
ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> & token)1465 int AbilityManagerProxy::ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token)
1466 {
1467 int error;
1468 MessageParcel data;
1469 MessageParcel reply;
1470 MessageOption option;
1471
1472 if (!WriteInterfaceToken(data)) {
1473 return INNER_ERR;
1474 }
1475 if (!data.WriteRemoteObject(token)) {
1476 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
1477 return ERR_INVALID_VALUE;
1478 }
1479
1480 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE, data, reply, option);
1481 if (error != NO_ERROR) {
1482 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1483 return error;
1484 }
1485 return reply.ReadInt32();
1486 }
1487
ScheduleCommandAbilityDone(const sptr<IRemoteObject> & token)1488 int AbilityManagerProxy::ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token)
1489 {
1490 int error;
1491 MessageParcel data;
1492 MessageParcel reply;
1493 MessageOption option;
1494
1495 if (!WriteInterfaceToken(data)) {
1496 return INNER_ERR;
1497 }
1498 if (!data.WriteRemoteObject(token)) {
1499 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
1500 return ERR_INVALID_VALUE;
1501 }
1502
1503 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE, data, reply, option);
1504 if (error != NO_ERROR) {
1505 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1506 return error;
1507 }
1508 return reply.ReadInt32();
1509 }
1510
ScheduleCommandAbilityWindowDone(const sptr<IRemoteObject> & token,const sptr<SessionInfo> & sessionInfo,WindowCommand winCmd,AbilityCommand abilityCmd)1511 int AbilityManagerProxy::ScheduleCommandAbilityWindowDone(
1512 const sptr<IRemoteObject> &token,
1513 const sptr<SessionInfo> &sessionInfo,
1514 WindowCommand winCmd,
1515 AbilityCommand abilityCmd)
1516 {
1517 int error;
1518 MessageParcel data;
1519 MessageParcel reply;
1520 MessageOption option;
1521
1522 if (!WriteInterfaceToken(data)) {
1523 return INNER_ERR;
1524 }
1525 if (!data.WriteRemoteObject(token)) {
1526 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
1527 return ERR_INVALID_VALUE;
1528 }
1529 if (!data.WriteParcelable(sessionInfo)) {
1530 TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo write failed.");
1531 return ERR_INVALID_VALUE;
1532 }
1533 if (!data.WriteInt32(winCmd)) {
1534 TAG_LOGE(AAFwkTag::ABILITYMGR, "winCmd write failed.");
1535 return ERR_INVALID_VALUE;
1536 }
1537 if (!data.WriteInt32(abilityCmd)) {
1538 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityCmd write failed.");
1539 return ERR_INVALID_VALUE;
1540 }
1541
1542 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE, data, reply, option);
1543 if (error != NO_ERROR) {
1544 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1545 return error;
1546 }
1547 return reply.ReadInt32();
1548 }
1549
DumpSysState(const std::string & args,std::vector<std::string> & state,bool isClient,bool isUserId,int UserId)1550 void AbilityManagerProxy::DumpSysState(
1551 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserId, int UserId)
1552 {
1553 int error;
1554 MessageParcel data;
1555 MessageParcel reply;
1556 MessageOption option;
1557
1558 if (!WriteInterfaceToken(data)) {
1559 return;
1560 }
1561 data.WriteString16(Str8ToStr16(args));
1562
1563 if (!data.WriteBool(isClient)) {
1564 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1565 return ;
1566 }
1567 if (!data.WriteBool(isUserId)) {
1568 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1569 return ;
1570 }
1571 if (!data.WriteInt32(UserId)) {
1572 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1573 return ;
1574 }
1575
1576 error = SendRequest(AbilityManagerInterfaceCode::DUMPSYS_STATE, data, reply, option);
1577 if (error != NO_ERROR) {
1578 TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerProxy: SendRequest err %{public}d", error);
1579 return;
1580 }
1581 int32_t stackNum = reply.ReadInt32();
1582 for (int i = 0; i < stackNum; i++) {
1583 std::string stac = Str16ToStr8(reply.ReadString16());
1584 state.emplace_back(stac);
1585 }
1586 }
1587
DumpState(const std::string & args,std::vector<std::string> & state)1588 void AbilityManagerProxy::DumpState(const std::string &args, std::vector<std::string> &state)
1589 {
1590 int error;
1591 MessageParcel data;
1592 MessageParcel reply;
1593 MessageOption option;
1594
1595 if (!WriteInterfaceToken(data)) {
1596 return;
1597 }
1598 data.WriteString16(Str8ToStr16(args));
1599
1600 error = SendRequest(AbilityManagerInterfaceCode::DUMP_STATE, data, reply, option);
1601 if (error != NO_ERROR) {
1602 TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerProxy: SendRequest err %{public}d", error);
1603 return;
1604 }
1605 int32_t stackNum = reply.ReadInt32();
1606 for (int i = 0; i < stackNum; i++) {
1607 std::string stac = Str16ToStr8(reply.ReadString16());
1608 state.emplace_back(stac);
1609 }
1610 }
1611
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser)1612 int AbilityManagerProxy::MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser)
1613 {
1614 int error;
1615 MessageParcel data;
1616 MessageParcel reply;
1617 MessageOption option;
1618
1619 if (!WriteInterfaceToken(data)) {
1620 return INNER_ERR;
1621 }
1622 if (!data.WriteRemoteObject(token)) {
1623 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
1624 return ERR_INVALID_VALUE;
1625 }
1626 if (!data.WriteBool(fromUser)) {
1627 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1628 return ERR_INVALID_VALUE;
1629 }
1630
1631 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_ABILITY, data, reply, option);
1632 if (error != NO_ERROR) {
1633 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1634 return error;
1635 }
1636 return reply.ReadInt32();
1637 }
1638
MinimizeUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,bool fromUser)1639 int AbilityManagerProxy::MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo,
1640 bool fromUser)
1641 {
1642 int error;
1643 MessageParcel data;
1644 MessageParcel reply;
1645 MessageOption option;
1646
1647 if (!WriteInterfaceToken(data)) {
1648 return INNER_ERR;
1649 }
1650 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
1651 "connect ability fail, extensionSessionInfo is nullptr");
1652 if (extensionSessionInfo) {
1653 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
1654 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write failed.");
1655 return INNER_ERR;
1656 }
1657 } else {
1658 if (!data.WriteBool(false)) {
1659 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
1660 return INNER_ERR;
1661 }
1662 }
1663 if (!data.WriteBool(fromUser)) {
1664 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
1665 return ERR_INVALID_VALUE;
1666 }
1667
1668 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY, data, reply, option);
1669 if (error != NO_ERROR) {
1670 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1671 return error;
1672 }
1673 return reply.ReadInt32();
1674 }
1675
MinimizeUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool fromUser,uint32_t sceneFlag)1676 int AbilityManagerProxy::MinimizeUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool fromUser, uint32_t sceneFlag)
1677 {
1678 int error;
1679 MessageParcel data;
1680 MessageParcel reply;
1681 MessageOption option;
1682
1683 if (!WriteInterfaceToken(data)) {
1684 return INNER_ERR;
1685 }
1686 if (sessionInfo) {
1687 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
1688 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
1689 return INNER_ERR;
1690 }
1691 } else {
1692 if (!data.WriteBool(false)) {
1693 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
1694 return INNER_ERR;
1695 }
1696 }
1697 if (!data.WriteBool(fromUser)) {
1698 TAG_LOGE(AAFwkTag::ABILITYMGR, "fromUser write failed.");
1699 return INNER_ERR;
1700 }
1701 if (!data.WriteUint32(sceneFlag)) {
1702 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write failed.");
1703 return INNER_ERR;
1704 }
1705
1706 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB, data, reply, option);
1707 if (error != NO_ERROR) {
1708 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed, Send request error: %{public}d", error);
1709 return error;
1710 }
1711 return reply.ReadInt32();
1712 }
1713
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token)1714 int AbilityManagerProxy::StopServiceAbility(const Want &want, int32_t userId, const sptr<IRemoteObject> &token)
1715 {
1716 int error;
1717 MessageParcel data;
1718 MessageParcel reply;
1719 MessageOption option;
1720
1721 if (!WriteInterfaceToken(data)) {
1722 return INNER_ERR;
1723 }
1724 if (!data.WriteParcelable(&want)) {
1725 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
1726 return INNER_ERR;
1727 }
1728 if (!data.WriteInt32(userId)) {
1729 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
1730 return INNER_ERR;
1731 }
1732 if (token) {
1733 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1734 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and token.");
1735 return ERR_INVALID_VALUE;
1736 }
1737 } else {
1738 if (!data.WriteBool(false)) {
1739 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
1740 return ERR_INVALID_VALUE;
1741 }
1742 }
1743 error = SendRequest(AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY, data, reply, option);
1744 if (error != NO_ERROR) {
1745 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1746 return error;
1747 }
1748 return reply.ReadInt32();
1749 }
1750
1751 template <typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)1752 int AbilityManagerProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
1753 {
1754 int32_t infoSize = reply.ReadInt32();
1755 if (infoSize > CYCLE_LIMIT) {
1756 TAG_LOGE(AAFwkTag::ABILITYMGR, "infoSize is too large");
1757 return ERR_INVALID_VALUE;
1758 }
1759
1760 for (int32_t i = 0; i < infoSize; i++) {
1761 std::unique_ptr<T> info(reply.ReadParcelable<T>());
1762 if (!info) {
1763 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read Parcelable infos failed.");
1764 return ERR_INVALID_VALUE;
1765 }
1766 parcelableInfos.emplace_back(*info);
1767 }
1768 return NO_ERROR;
1769 }
1770
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)1771 int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
1772 MissionSnapshot& snapshot, bool isLowResolution)
1773 {
1774 int error;
1775 MessageParcel data;
1776 MessageParcel reply;
1777 MessageOption option;
1778
1779 if (!WriteInterfaceToken(data)) {
1780 return INNER_ERR;
1781 }
1782 if (!data.WriteString(deviceId)) {
1783 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write failed.");
1784 return INNER_ERR;
1785 }
1786 if (!data.WriteInt32(missionId)) {
1787 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
1788 return ERR_INVALID_VALUE;
1789 }
1790 if (!data.WriteBool(isLowResolution)) {
1791 TAG_LOGE(AAFwkTag::ABILITYMGR, "isLowResolution write failed.");
1792 return ERR_INVALID_VALUE;
1793 }
1794 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO, data, reply, option);
1795 if (error != NO_ERROR) {
1796 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1797 return error;
1798 }
1799 std::unique_ptr<MissionSnapshot> info(reply.ReadParcelable<MissionSnapshot>());
1800 if (!info) {
1801 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfo failed.");
1802 auto errorCode = reply.ReadInt32();
1803 return errorCode ? errorCode : ERR_UNKNOWN_OBJECT;
1804 }
1805 snapshot = *info;
1806 return reply.ReadInt32();
1807 }
1808
UpdateMissionSnapShot(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & pixelMap)1809 void AbilityManagerProxy::UpdateMissionSnapShot(const sptr<IRemoteObject> &token,
1810 const std::shared_ptr<Media::PixelMap> &pixelMap)
1811 {
1812 MessageParcel data;
1813 MessageParcel reply;
1814 MessageOption option(MessageOption::TF_ASYNC);
1815
1816 if (!WriteInterfaceToken(data)) {
1817 return;
1818 }
1819 if (!data.WriteRemoteObject(token)) {
1820 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed.");
1821 return;
1822 }
1823 if (!data.WriteParcelable(pixelMap.get())) {
1824 TAG_LOGE(AAFwkTag::ABILITYMGR, "write pixelMap failed.");
1825 return;
1826 }
1827 auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS,
1828 data, reply, option);
1829 if (error != NO_ERROR) {
1830 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1831 }
1832 }
1833
EnableRecoverAbility(const sptr<IRemoteObject> & token)1834 void AbilityManagerProxy::EnableRecoverAbility(const sptr<IRemoteObject>& token)
1835 {
1836 int error;
1837 MessageParcel data;
1838 MessageParcel reply;
1839 MessageOption option(MessageOption::TF_ASYNC);
1840
1841 if (!WriteInterfaceToken(data)) {
1842 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteInterfaceToken failed.");
1843 return;
1844 }
1845
1846 if (!data.WriteRemoteObject(token)) {
1847 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteRemoteObject failed.");
1848 return;
1849 }
1850
1851 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE, data, reply, option);
1852 if (error != NO_ERROR) {
1853 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery Send request error: %{public}d", error);
1854 return;
1855 }
1856 return;
1857 }
1858
ScheduleRecoverAbility(const sptr<IRemoteObject> & token,int32_t reason,const Want * want)1859 void AbilityManagerProxy::ScheduleRecoverAbility(const sptr<IRemoteObject>& token, int32_t reason, const Want *want)
1860 {
1861 int error;
1862 MessageParcel data;
1863 MessageParcel reply;
1864 MessageOption option(MessageOption::TF_ASYNC);
1865
1866 if (!WriteInterfaceToken(data)) {
1867 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteInterfaceToken failed.");
1868 return;
1869 }
1870
1871 if (!data.WriteRemoteObject(token)) {
1872 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteRemoteObject failed.");
1873 return;
1874 }
1875
1876 data.WriteInt32(reason);
1877
1878 if (!data.WriteParcelable(want)) {
1879 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery write want failed.");
1880 return;
1881 }
1882
1883 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY, data, reply, option);
1884 if (error != NO_ERROR) {
1885 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery Send request error: %{public}d", error);
1886 return;
1887 }
1888 return;
1889 }
1890
SubmitSaveRecoveryInfo(const sptr<IRemoteObject> & token)1891 void AbilityManagerProxy::SubmitSaveRecoveryInfo(const sptr<IRemoteObject>& token)
1892 {
1893 int error;
1894 MessageParcel data;
1895 MessageParcel reply;
1896 MessageOption option(MessageOption::TF_ASYNC);
1897
1898 if (!WriteInterfaceToken(data)) {
1899 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteInterfaceToken failed.");
1900 return;
1901 }
1902
1903 if (!data.WriteRemoteObject(token)) {
1904 TAG_LOGE(AAFwkTag::ABILITYMGR, "AppRecovery WriteRemoteObject failed.");
1905 return;
1906 }
1907
1908 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY_SUBMITINFO, data, reply, option);
1909 if (error != NO_ERROR) {
1910 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1911 return;
1912 }
1913 return;
1914 }
1915
KillProcess(const std::string & bundleName,const bool clearPageStack)1916 int AbilityManagerProxy::KillProcess(const std::string &bundleName, const bool clearPageStack)
1917 {
1918 MessageParcel data;
1919 MessageParcel reply;
1920 MessageOption option;
1921
1922 if (!WriteInterfaceToken(data)) {
1923 return INNER_ERR;
1924 }
1925 if (!data.WriteString16(Str8ToStr16(bundleName))) {
1926 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write failed.");
1927 return ERR_INVALID_VALUE;
1928 }
1929 if (!data.WriteBool(clearPageStack)) {
1930 TAG_LOGE(AAFwkTag::ABILITYMGR, "clearPageStack write failed.");
1931 return ERR_INVALID_VALUE;
1932 }
1933 int error = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS, data, reply, option);
1934 if (error != NO_ERROR) {
1935 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1936 return error;
1937 }
1938 return reply.ReadInt32();
1939 }
1940
ScheduleClearRecoveryPageStack()1941 void AbilityManagerProxy::ScheduleClearRecoveryPageStack()
1942 {
1943 MessageParcel data;
1944 MessageParcel reply;
1945 MessageOption option;
1946
1947 if (!WriteInterfaceToken(data)) {
1948 TAG_LOGE(AAFwkTag::ABILITYMGR, "ScheduleClearRecoveryPageStack WriteInterfaceToken failed.");
1949 return;
1950 }
1951
1952 int error = SendRequest(AbilityManagerInterfaceCode::CLEAR_RECOVERY_PAGE_STACK, data, reply, option);
1953 if (error != NO_ERROR) {
1954 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1955 return;
1956 }
1957 return;
1958 }
1959
1960 #ifdef ABILITY_COMMAND_FOR_TEST
ForceTimeoutForTest(const std::string & abilityName,const std::string & state)1961 int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, const std::string &state)
1962 {
1963 MessageParcel data;
1964 MessageParcel reply;
1965 MessageOption option;
1966
1967 if (!WriteInterfaceToken(data)) {
1968 return INNER_ERR;
1969 }
1970 if (!data.WriteString16(Str8ToStr16(abilityName))) {
1971 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityName write failed.");
1972 return ERR_INVALID_VALUE;
1973 }
1974 if (!data.WriteString16(Str8ToStr16(state))) {
1975 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityName write failed.");
1976 return ERR_INVALID_VALUE;
1977 }
1978 int error = SendRequest(AbilityManagerInterfaceCode::FORCE_TIMEOUT, data, reply, option);
1979 if (error != NO_ERROR) {
1980 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
1981 return error;
1982 }
1983 return reply.ReadInt32();
1984 }
1985 #endif
1986
UninstallApp(const std::string & bundleName,int32_t uid)1987 int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid)
1988 {
1989 return UninstallApp(bundleName, uid, 0);
1990 }
1991
UninstallApp(const std::string & bundleName,int32_t uid,int32_t appIndex)1992 int32_t AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
1993 {
1994 MessageParcel data;
1995 MessageParcel reply;
1996 MessageOption option;
1997
1998 if (!WriteInterfaceToken(data)) {
1999 return INNER_ERR;
2000 }
2001 if (!data.WriteString16(Str8ToStr16(bundleName))) {
2002 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write failed.");
2003 return ERR_INVALID_VALUE;
2004 }
2005 if (!data.WriteInt32(uid)) {
2006 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write failed.");
2007 return ERR_INVALID_VALUE;
2008 }
2009 if (!data.WriteInt32(appIndex)) {
2010 TAG_LOGE(AAFwkTag::ABILITYMGR, "appIndex write failed.");
2011 return ERR_INVALID_VALUE;
2012 }
2013 int error = SendRequest(AbilityManagerInterfaceCode::UNINSTALL_APP, data, reply, option);
2014 if (error != NO_ERROR) {
2015 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2016 return error;
2017 }
2018 return reply.ReadInt32();
2019 }
2020
UpgradeApp(const std::string & bundleName,const int32_t uid,const std::string & exitMsg,int32_t appIndex)2021 int32_t AbilityManagerProxy::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg,
2022 int32_t appIndex)
2023 {
2024 MessageParcel data;
2025 MessageParcel reply;
2026 MessageOption option;
2027
2028 if (!WriteInterfaceToken(data)) {
2029 return INNER_ERR;
2030 }
2031 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(bundleName));
2032 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, uid);
2033 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(exitMsg));
2034 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, appIndex);
2035 int error = SendRequest(AbilityManagerInterfaceCode::UPGRADE_APP, data, reply, option);
2036 if (error != NO_ERROR) {
2037 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2038 return error;
2039 }
2040 return reply.ReadInt32();
2041 }
2042
GetWantSender(const WantSenderInfo & wantSenderInfo,const sptr<IRemoteObject> & callerToken,int32_t uid)2043 sptr<IWantSender> AbilityManagerProxy::GetWantSender(
2044 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t uid)
2045 {
2046 MessageParcel data;
2047 MessageParcel reply;
2048 MessageOption option;
2049 if (!WriteInterfaceToken(data)) {
2050 return nullptr;
2051 }
2052 if (!data.WriteParcelable(&wantSenderInfo)) {
2053 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantSenderInfo write failed.");
2054 return nullptr;
2055 }
2056 if (callerToken) {
2057 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
2058 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
2059 return nullptr;
2060 }
2061 } else {
2062 if (!data.WriteBool(false)) {
2063 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
2064 return nullptr;
2065 }
2066 }
2067
2068 if (!data.WriteInt32(uid)) {
2069 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write fail");
2070 return nullptr;
2071 }
2072
2073 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER, data, reply, option);
2074 if (error != NO_ERROR) {
2075 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2076 return nullptr;
2077 }
2078 sptr<IWantSender> wantSender = iface_cast<IWantSender>(reply.ReadRemoteObject());
2079 if (!wantSender) {
2080 return nullptr;
2081 }
2082 return wantSender;
2083 }
2084
SendWantSender(sptr<IWantSender> target,const SenderInfo & senderInfo)2085 int AbilityManagerProxy::SendWantSender(sptr<IWantSender> target, const SenderInfo &senderInfo)
2086 {
2087 MessageParcel data;
2088 MessageParcel reply;
2089 MessageOption option;
2090 if (!WriteInterfaceToken(data)) {
2091 return INNER_ERR;
2092 }
2093 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2094 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2095 return INNER_ERR;
2096 }
2097 if (!data.WriteParcelable(&senderInfo)) {
2098 TAG_LOGE(AAFwkTag::ABILITYMGR, "senderInfo write failed.");
2099 return INNER_ERR;
2100 }
2101 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER, data, reply, option);
2102 if (error != NO_ERROR) {
2103 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2104 return error;
2105 }
2106 return reply.ReadInt32();
2107 }
2108
CancelWantSender(const sptr<IWantSender> & sender)2109 void AbilityManagerProxy::CancelWantSender(const sptr<IWantSender> &sender)
2110 {
2111 MessageParcel data;
2112 MessageParcel reply;
2113 MessageOption option;
2114 if (!WriteInterfaceToken(data)) {
2115 return;
2116 }
2117 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2118 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write failed.");
2119 return;
2120 }
2121 auto error = SendRequest(AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER, data, reply, option);
2122 if (error != NO_ERROR) {
2123 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2124 return;
2125 }
2126 }
2127
GetPendingWantUid(const sptr<IWantSender> & target)2128 int AbilityManagerProxy::GetPendingWantUid(const sptr<IWantSender> &target)
2129 {
2130 MessageParcel data;
2131 MessageParcel reply;
2132 MessageOption option;
2133 if (!WriteInterfaceToken(data)) {
2134 return INNER_ERR;
2135 }
2136 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2137 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2138 return ERR_INVALID_VALUE;
2139 }
2140 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_UID, data, reply, option);
2141 if (error != NO_ERROR) {
2142 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2143 return INNER_ERR;
2144 }
2145 return reply.ReadInt32();
2146 }
2147
GetPendingWantUserId(const sptr<IWantSender> & target)2148 int AbilityManagerProxy::GetPendingWantUserId(const sptr<IWantSender> &target)
2149 {
2150 MessageParcel data;
2151 MessageParcel reply;
2152 MessageOption option;
2153 if (!WriteInterfaceToken(data)) {
2154 return INNER_ERR;
2155 }
2156 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2157 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2158 return ERR_INVALID_VALUE;
2159 }
2160 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID, data, reply, option);
2161 if (error != NO_ERROR) {
2162 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2163 return INNER_ERR;
2164 }
2165 return reply.ReadInt32();
2166 }
2167
GetPendingWantBundleName(const sptr<IWantSender> & target)2168 std::string AbilityManagerProxy::GetPendingWantBundleName(const sptr<IWantSender> &target)
2169 {
2170 MessageParcel data;
2171 MessageParcel reply;
2172 MessageOption option;
2173 if (!WriteInterfaceToken(data)) {
2174 return "";
2175 }
2176 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2177 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2178 return "";
2179 }
2180 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME, data, reply, option);
2181 if (error != NO_ERROR) {
2182 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2183 return "";
2184 }
2185 return Str16ToStr8(reply.ReadString16());
2186 }
2187
GetPendingWantCode(const sptr<IWantSender> & target)2188 int AbilityManagerProxy::GetPendingWantCode(const sptr<IWantSender> &target)
2189 {
2190 MessageParcel data;
2191 MessageParcel reply;
2192 MessageOption option;
2193 if (!WriteInterfaceToken(data)) {
2194 return INNER_ERR;
2195 }
2196 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2197 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2198 return ERR_INVALID_VALUE;
2199 }
2200 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE, data, reply, option);
2201 if (error != NO_ERROR) {
2202 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2203 return INNER_ERR;
2204 }
2205 return reply.ReadInt32();
2206 }
2207
GetPendingWantType(const sptr<IWantSender> & target)2208 int AbilityManagerProxy::GetPendingWantType(const sptr<IWantSender> &target)
2209 {
2210 MessageParcel data;
2211 MessageParcel reply;
2212 MessageOption option;
2213 if (!WriteInterfaceToken(data)) {
2214 return INNER_ERR;
2215 }
2216 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2217 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2218 return ERR_INVALID_VALUE;
2219 }
2220 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE, data, reply, option);
2221 if (error != NO_ERROR) {
2222 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2223 return INNER_ERR;
2224 }
2225 return reply.ReadInt32();
2226 }
2227
RegisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)2228 void AbilityManagerProxy::RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
2229 {
2230 MessageParcel data;
2231 MessageParcel reply;
2232 MessageOption option;
2233 if (!WriteInterfaceToken(data)) {
2234 return;
2235 }
2236 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2237 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write failed.");
2238 return;
2239 }
2240 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
2241 TAG_LOGE(AAFwkTag::ABILITYMGR, "receiver write failed.");
2242 return;
2243 }
2244 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER, data, reply, option);
2245 if (error != NO_ERROR) {
2246 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2247 return;
2248 }
2249 }
2250
UnregisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)2251 void AbilityManagerProxy::UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
2252 {
2253 MessageParcel data;
2254 MessageParcel reply;
2255 MessageOption option;
2256 if (!WriteInterfaceToken(data)) {
2257 return;
2258 }
2259 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2260 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write failed.");
2261 return;
2262 }
2263 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
2264 TAG_LOGE(AAFwkTag::ABILITYMGR, "receiver write failed.");
2265 return;
2266 }
2267 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER, data, reply, option);
2268 if (error != NO_ERROR) {
2269 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2270 return;
2271 }
2272 }
2273
GetPendingRequestWant(const sptr<IWantSender> & target,std::shared_ptr<Want> & want)2274 int AbilityManagerProxy::GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want)
2275 {
2276 MessageParcel data;
2277 MessageParcel reply;
2278 MessageOption option;
2279 if (!WriteInterfaceToken(data)) {
2280 return INNER_ERR;
2281 }
2282 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2283 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2284 return INNER_ERR;
2285 }
2286 if (want == nullptr || !data.WriteParcelable(want.get())) {
2287 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
2288 return INNER_ERR;
2289 }
2290 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT, data, reply, option);
2291 if (error != NO_ERROR) {
2292 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2293 return error;
2294 }
2295 std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
2296 if (!wantInfo) {
2297 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfo failed");
2298 return INNER_ERR;
2299 }
2300 want = std::move(wantInfo);
2301
2302 return NO_ERROR;
2303 }
2304
GetWantSenderInfo(const sptr<IWantSender> & target,std::shared_ptr<WantSenderInfo> & info)2305 int AbilityManagerProxy::GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info)
2306 {
2307 MessageParcel data;
2308 MessageParcel reply;
2309 MessageOption option;
2310 if (!WriteInterfaceToken(data)) {
2311 return INNER_ERR;
2312 }
2313 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2314 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write failed.");
2315 return INNER_ERR;
2316 }
2317 if (info == nullptr || !data.WriteParcelable(info.get())) {
2318 TAG_LOGE(AAFwkTag::ABILITYMGR, "info write failed.");
2319 return INNER_ERR;
2320 }
2321 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO, data, reply, option);
2322 if (error != NO_ERROR) {
2323 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2324 return error;
2325 }
2326 std::unique_ptr<WantSenderInfo> wantSenderInfo(reply.ReadParcelable<WantSenderInfo>());
2327 if (!wantSenderInfo) {
2328 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable Info failed");
2329 return INNER_ERR;
2330 }
2331 info = std::move(wantSenderInfo);
2332
2333 return NO_ERROR;
2334 }
2335
GetAppMemorySize()2336 int AbilityManagerProxy::GetAppMemorySize()
2337 {
2338 MessageParcel data;
2339 MessageParcel reply;
2340 MessageOption option;
2341 if (!WriteInterfaceToken(data)) {
2342 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken faild");
2343 return INNER_ERR;
2344 }
2345 auto error = SendRequest(AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE, data, reply, option);
2346 if (error != NO_ERROR) {
2347 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2348 return error;
2349 }
2350 return reply.ReadInt32();
2351 }
2352
IsRamConstrainedDevice()2353 bool AbilityManagerProxy::IsRamConstrainedDevice()
2354 {
2355 MessageParcel data;
2356 MessageParcel reply;
2357 MessageOption option;
2358 if (!WriteInterfaceToken(data)) {
2359 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken faild");
2360 return false;
2361 }
2362 auto error = SendRequest(AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE, data, reply, option);
2363 if (error != NO_ERROR) {
2364 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2365 return false;
2366 }
2367 return reply.ReadBool();
2368 }
2369
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,int32_t missionId,const sptr<IRemoteObject> & callBack,AAFwk::WantParams & wantParams)2370 int AbilityManagerProxy::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
2371 int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams)
2372 {
2373 TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
2374 MessageParcel data;
2375 MessageParcel reply;
2376 MessageOption option;
2377 if (!WriteInterfaceToken(data)) {
2378 return INNER_ERR;
2379 }
2380 if (!data.WriteString(srcDeviceId)) {
2381 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcDeviceId write failed.");
2382 return INNER_ERR;
2383 }
2384 if (!data.WriteString(dstDeviceId)) {
2385 TAG_LOGE(AAFwkTag::ABILITYMGR, "dstDeviceId write failed.");
2386 return INNER_ERR;
2387 }
2388 if (!data.WriteInt32(missionId)) {
2389 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
2390 return INNER_ERR;
2391 }
2392 if (!data.WriteRemoteObject(callBack)) {
2393 TAG_LOGE(AAFwkTag::ABILITYMGR, "callBack write failed.");
2394 return INNER_ERR;
2395 }
2396 if (!data.WriteParcelable(&wantParams)) {
2397 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParams write failed.");
2398 return INNER_ERR;
2399 }
2400
2401 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION, data, reply, option);
2402 if (error != NO_ERROR) {
2403 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2404 return error;
2405 }
2406 return reply.ReadInt32();
2407 }
2408
ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo,const sptr<IRemoteObject> & callback)2409 int AbilityManagerProxy::ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo,
2410 const sptr<IRemoteObject> &callback)
2411 {
2412 MessageParcel data;
2413 MessageParcel reply;
2414 MessageOption option;
2415 if (!WriteInterfaceToken(data)) {
2416 return INNER_ERR;
2417 }
2418 if (!data.WriteString(continueMissionInfo.srcDeviceId)) {
2419 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcDeviceId write failed.");
2420 return INNER_ERR;
2421 }
2422 if (!data.WriteString(continueMissionInfo.dstDeviceId)) {
2423 TAG_LOGE(AAFwkTag::ABILITYMGR, "dstDeviceId write failed.");
2424 return INNER_ERR;
2425 }
2426 if (!data.WriteString(continueMissionInfo.bundleName)) {
2427 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
2428 return INNER_ERR;
2429 }
2430 if (!data.WriteRemoteObject(callback)) {
2431 TAG_LOGE(AAFwkTag::ABILITYMGR, "callBack write failed.");
2432 return INNER_ERR;
2433 }
2434 if (!data.WriteParcelable(&continueMissionInfo.wantParams)) {
2435 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParams write failed.");
2436 return INNER_ERR;
2437 }
2438 if (!data.WriteString(continueMissionInfo.srcBundleName)) {
2439 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcBundleName write failed.");
2440 return INNER_ERR;
2441 }
2442 if (!data.WriteString(continueMissionInfo.continueType)) {
2443 TAG_LOGE(AAFwkTag::ABILITYMGR, "continueType write failed.");
2444 return INNER_ERR;
2445 }
2446 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME, data, reply, option);
2447 if (error != NO_ERROR) {
2448 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2449 return error;
2450 }
2451 return reply.ReadInt32();
2452 }
2453
ContinueAbility(const std::string & deviceId,int32_t missionId,uint32_t versionCode)2454 int AbilityManagerProxy::ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode)
2455 {
2456 MessageParcel data;
2457 MessageParcel reply;
2458 MessageOption option;
2459 if (!WriteInterfaceToken(data)) {
2460 return INNER_ERR;
2461 }
2462 if (!data.WriteString(deviceId)) {
2463 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write failed.");
2464 return INNER_ERR;
2465 }
2466 if (!data.WriteInt32(missionId)) {
2467 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
2468 return INNER_ERR;
2469 }
2470 if (!data.WriteUint32(versionCode)) {
2471 TAG_LOGE(AAFwkTag::ABILITYMGR, "versionCode write failed.");
2472 return INNER_ERR;
2473 }
2474
2475 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_ABILITY, data, reply, option);
2476 if (error != NO_ERROR) {
2477 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2478 return error;
2479 }
2480 return reply.ReadInt32();
2481 }
2482
StartContinuation(const Want & want,const sptr<IRemoteObject> & abilityToken,int32_t status)2483 int AbilityManagerProxy::StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status)
2484 {
2485 MessageParcel data;
2486 MessageParcel reply;
2487 MessageOption option = {MessageOption::TF_ASYNC};
2488 if (!WriteInterfaceToken(data)) {
2489 return INNER_ERR;
2490 }
2491 if (!data.WriteParcelable(&want)) {
2492 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
2493 return INNER_ERR;
2494 }
2495 if (!data.WriteRemoteObject(abilityToken)) {
2496 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityToken write failed.");
2497 return INNER_ERR;
2498 }
2499 if (!data.WriteInt32(status)) {
2500 TAG_LOGE(AAFwkTag::ABILITYMGR, "status write failed.");
2501 return INNER_ERR;
2502 }
2503
2504 auto error = SendRequest(AbilityManagerInterfaceCode::START_CONTINUATION, data, reply, option);
2505 if (error != NO_ERROR) {
2506 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2507 return error;
2508 }
2509 return reply.ReadInt32();
2510 }
2511
NotifyCompleteContinuation(const std::string & deviceId,int32_t sessionId,bool isSuccess)2512 void AbilityManagerProxy::NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess)
2513 {
2514 MessageParcel data;
2515 MessageParcel reply;
2516 MessageOption option = {MessageOption::TF_ASYNC};
2517 if (!WriteInterfaceToken(data)) {
2518 return;
2519 }
2520 if (!data.WriteString(deviceId)) {
2521 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write failed.");
2522 return;
2523 }
2524 if (!data.WriteInt32(sessionId)) {
2525 TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionId write failed.");
2526 return;
2527 }
2528 if (!data.WriteBool(isSuccess)) {
2529 TAG_LOGE(AAFwkTag::ABILITYMGR, "result write failed.");
2530 return;
2531 }
2532 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION, data, reply, option);
2533 if (error != NO_ERROR) {
2534 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2535 return;
2536 }
2537 }
2538
NotifyContinuationResult(int32_t missionId,int32_t result)2539 int AbilityManagerProxy::NotifyContinuationResult(int32_t missionId, int32_t result)
2540 {
2541 MessageParcel data;
2542 MessageParcel reply;
2543 MessageOption option;
2544 if (!WriteInterfaceToken(data)) {
2545 return INNER_ERR;
2546 }
2547 if (!data.WriteInt32(missionId)) {
2548 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
2549 return INNER_ERR;
2550 }
2551 if (!data.WriteInt32(result)) {
2552 TAG_LOGE(AAFwkTag::ABILITYMGR, "result write failed.");
2553 return INNER_ERR;
2554 }
2555
2556 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT, data, reply, option);
2557 if (error != NO_ERROR) {
2558 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2559 return error;
2560 }
2561 return reply.ReadInt32();
2562 }
2563
LockMissionForCleanup(int32_t missionId)2564 int AbilityManagerProxy::LockMissionForCleanup(int32_t missionId)
2565 {
2566 int error;
2567 MessageParcel data;
2568 MessageParcel reply;
2569 MessageOption option;
2570
2571 if (!WriteInterfaceToken(data)) {
2572 return INNER_ERR;
2573 }
2574 if (!data.WriteInt32(missionId)) {
2575 TAG_LOGE(AAFwkTag::ABILITYMGR, "lock mission by id , WriteInt32 fail.");
2576 return ERR_INVALID_VALUE;
2577 }
2578
2579 error = SendRequest(AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP, data, reply, option);
2580 if (error != NO_ERROR) {
2581 TAG_LOGE(AAFwkTag::ABILITYMGR, "lock mission by id , error: %d", error);
2582 return error;
2583 }
2584 return reply.ReadInt32();
2585 }
2586
UnlockMissionForCleanup(int32_t missionId)2587 int AbilityManagerProxy::UnlockMissionForCleanup(int32_t missionId)
2588 {
2589 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2590 int error;
2591 MessageParcel data;
2592 MessageParcel reply;
2593 MessageOption option;
2594
2595 if (!WriteInterfaceToken(data)) {
2596 return INNER_ERR;
2597 }
2598 if (!data.WriteInt32(missionId)) {
2599 TAG_LOGE(AAFwkTag::ABILITYMGR, "unlock mission by id , WriteInt32 fail.");
2600 return ERR_INVALID_VALUE;
2601 }
2602 error = SendRequest(AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP, data, reply, option);
2603 if (error != NO_ERROR) {
2604 TAG_LOGE(AAFwkTag::ABILITYMGR, "unlock mission by id , error: %d", error);
2605 return error;
2606 }
2607 return reply.ReadInt32();
2608 }
2609
SetLockedState(int32_t sessionId,bool lockedState)2610 void AbilityManagerProxy::SetLockedState(int32_t sessionId, bool lockedState)
2611 {
2612 MessageParcel data;
2613
2614 if (!WriteInterfaceToken(data)) {
2615 return;
2616 }
2617
2618 if (!data.WriteInt32(sessionId)) {
2619 TAG_LOGE(AAFwkTag::ABILITYMGR, "lock abilityRecord by id , WriteInt32 fail.");
2620 return;
2621 }
2622
2623 if (!data.WriteBool(lockedState)) {
2624 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteBool fail.");
2625 return;
2626 }
2627
2628 MessageParcel reply;
2629 MessageOption option(MessageOption::TF_ASYNC);
2630 auto error = SendRequest(AbilityManagerInterfaceCode::SET_SESSION_LOCKED_STATE, data, reply, option);
2631 if (error != NO_ERROR) {
2632 TAG_LOGE(AAFwkTag::ABILITYMGR, "lock or unlock abilityRecord by sessionId , error: %d", error);
2633 return;
2634 }
2635 return;
2636 }
2637
RegisterMissionListener(const sptr<IMissionListener> & listener)2638 int AbilityManagerProxy::RegisterMissionListener(const sptr<IMissionListener> &listener)
2639 {
2640 int error;
2641 MessageParcel data;
2642 MessageParcel reply;
2643 MessageOption option;
2644 if (!listener) {
2645 TAG_LOGE(AAFwkTag::ABILITYMGR, "register mission listener, listener is nullptr");
2646 return ERR_INVALID_VALUE;
2647 }
2648
2649 if (!WriteInterfaceToken(data)) {
2650 return INNER_ERR;
2651 }
2652 if (!data.WriteRemoteObject(listener->AsObject())) {
2653 TAG_LOGE(AAFwkTag::ABILITYMGR, "write mission listener failed when register mission listener.");
2654 return ERR_INVALID_VALUE;
2655 }
2656
2657 error = SendRequest(AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER, data, reply, option);
2658 if (error != NO_ERROR) {
2659 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2660 return error;
2661 }
2662 return reply.ReadInt32();
2663 }
2664
RegisterSessionHandler(const sptr<IRemoteObject> & object)2665 int AbilityManagerProxy::RegisterSessionHandler(const sptr<IRemoteObject> &object)
2666 {
2667 if (!object) {
2668 TAG_LOGE(AAFwkTag::ABILITYMGR, "register session handler, handler is nullptr");
2669 return ERR_INVALID_VALUE;
2670 }
2671 MessageParcel data;
2672 MessageParcel reply;
2673 MessageOption option;
2674 if (!WriteInterfaceToken(data)) {
2675 return INNER_ERR;
2676 }
2677 if (!data.WriteRemoteObject(object)) {
2678 TAG_LOGE(AAFwkTag::ABILITYMGR, "write session handler failed when register session handler.");
2679 return ERR_INVALID_VALUE;
2680 }
2681 int error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER, data, reply, option);
2682 if (error != NO_ERROR) {
2683 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2684 return error;
2685 }
2686 return reply.ReadInt32();
2687 }
2688
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)2689 int AbilityManagerProxy::RegisterMissionListener(const std::string &deviceId,
2690 const sptr<IRemoteMissionListener> &listener)
2691 {
2692 MessageParcel data;
2693 MessageParcel reply;
2694 MessageOption option;
2695 if (!WriteInterfaceToken(data)) {
2696 return INNER_ERR;
2697 }
2698 if (!data.WriteString(deviceId)) {
2699 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write failed.");
2700 return INNER_ERR;
2701 }
2702 if (!data.WriteRemoteObject(listener->AsObject())) {
2703 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write failed.");
2704 return INNER_ERR;
2705 }
2706
2707 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER,
2708 data, reply, option);
2709 if (error != NO_ERROR) {
2710 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2711 return error;
2712 }
2713 return reply.ReadInt32();
2714 }
2715
RegisterOnListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2716 int AbilityManagerProxy::RegisterOnListener(const std::string &type,
2717 const sptr<IRemoteOnListener> &listener)
2718 {
2719 MessageParcel data;
2720 MessageParcel reply;
2721 MessageOption option;
2722 if (!WriteInterfaceToken(data)) {
2723 return INNER_ERR;
2724 }
2725 if (!data.WriteString(type)) {
2726 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write failed.");
2727 return INNER_ERR;
2728 }
2729 if (!data.WriteRemoteObject(listener->AsObject())) {
2730 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write failed.");
2731 return INNER_ERR;
2732 }
2733
2734 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER, data, reply, option);
2735 if (error != NO_ERROR) {
2736 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2737 return error;
2738 }
2739 return reply.ReadInt32();
2740 }
2741
RegisterOffListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2742 int AbilityManagerProxy::RegisterOffListener(const std::string &type,
2743 const sptr<IRemoteOnListener> &listener)
2744 {
2745 MessageParcel data;
2746 MessageParcel reply;
2747 MessageOption option;
2748 if (!WriteInterfaceToken(data)) {
2749 return INNER_ERR;
2750 }
2751 if (!data.WriteString(type)) {
2752 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write failed.");
2753 return INNER_ERR;
2754 }
2755 if (!data.WriteRemoteObject(listener->AsObject())) {
2756 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write failed.");
2757 return INNER_ERR;
2758 }
2759
2760 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER, data, reply, option);
2761 if (error != NO_ERROR) {
2762 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2763 return error;
2764 }
2765 return reply.ReadInt32();
2766 }
2767
UnRegisterMissionListener(const sptr<IMissionListener> & listener)2768 int AbilityManagerProxy::UnRegisterMissionListener(const sptr<IMissionListener> &listener)
2769 {
2770 int error;
2771 MessageParcel data;
2772 MessageParcel reply;
2773 MessageOption option;
2774 if (!listener) {
2775 TAG_LOGE(AAFwkTag::ABILITYMGR, "unregister mission listener, listener is nullptr");
2776 return ERR_INVALID_VALUE;
2777 }
2778
2779 if (!WriteInterfaceToken(data)) {
2780 return INNER_ERR;
2781 }
2782 if (!data.WriteRemoteObject(listener->AsObject())) {
2783 TAG_LOGE(AAFwkTag::ABILITYMGR, "write mission listener failed when unregister mission listener.");
2784 return ERR_INVALID_VALUE;
2785 }
2786
2787 error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER, data, reply, option);
2788 if (error != NO_ERROR) {
2789 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
2790 return error;
2791 }
2792 return reply.ReadInt32();
2793 }
2794
GetMissionInfos(const std::string & deviceId,int32_t numMax,std::vector<MissionInfo> & missionInfos)2795 int AbilityManagerProxy::GetMissionInfos(const std::string& deviceId, int32_t numMax,
2796 std::vector<MissionInfo> &missionInfos)
2797 {
2798 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2799 int error;
2800 MessageParcel data;
2801 MessageParcel reply;
2802 MessageOption option;
2803 if (!WriteInterfaceToken(data)) {
2804 return INNER_ERR;
2805 }
2806 if (!data.WriteString16(Str8ToStr16(deviceId))) {
2807 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId failed when GetMissionInfos.");
2808 return ERR_INVALID_VALUE;
2809 }
2810 if (!data.WriteInt32(numMax)) {
2811 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetMissionInfos numMax write failed.");
2812 return ERR_INVALID_VALUE;
2813 }
2814 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFOS, data, reply, option);
2815 if (error != NO_ERROR) {
2816 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetMissionInfos Send request error: %{public}d", error);
2817 return error;
2818 }
2819 error = GetParcelableInfos<MissionInfo>(reply, missionInfos);
2820 if (error != NO_ERROR) {
2821 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetMissionInfos error: %{public}d", error);
2822 return error;
2823 }
2824 return reply.ReadInt32();
2825 }
2826
GetMissionInfo(const std::string & deviceId,int32_t missionId,MissionInfo & missionInfo)2827 int AbilityManagerProxy::GetMissionInfo(const std::string& deviceId, int32_t missionId,
2828 MissionInfo &missionInfo)
2829 {
2830 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2831 int error;
2832 MessageParcel data;
2833 MessageParcel reply;
2834 MessageOption option;
2835 if (!WriteInterfaceToken(data)) {
2836 return INNER_ERR;
2837 }
2838 if (!data.WriteString16(Str8ToStr16(deviceId))) {
2839 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId failed when GetMissionInfo.");
2840 return ERR_INVALID_VALUE;
2841 }
2842 if (!data.WriteInt32(missionId)) {
2843 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetMissionInfo write missionId failed.");
2844 return ERR_INVALID_VALUE;
2845 }
2846 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID, data, reply, option);
2847 if (error != NO_ERROR) {
2848 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetMissionInfo Send request error: %{public}d", error);
2849 return error;
2850 }
2851
2852 std::unique_ptr<MissionInfo> info(reply.ReadParcelable<MissionInfo>());
2853 if (!info) {
2854 TAG_LOGE(AAFwkTag::ABILITYMGR, "read missioninfo failed.");
2855 return ERR_UNKNOWN_OBJECT;
2856 }
2857 missionInfo = *info;
2858 return reply.ReadInt32();
2859 }
2860
CleanMission(int32_t missionId)2861 int AbilityManagerProxy::CleanMission(int32_t missionId)
2862 {
2863 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2864 int error;
2865 MessageParcel data;
2866 MessageParcel reply;
2867 MessageOption option;
2868
2869 if (!WriteInterfaceToken(data)) {
2870 return INNER_ERR;
2871 }
2872 if (!data.WriteInt32(missionId)) {
2873 TAG_LOGE(AAFwkTag::ABILITYMGR, "clean mission by id , WriteInt32 fail.");
2874 return ERR_INVALID_VALUE;
2875 }
2876 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_MISSION, data, reply, option);
2877 if (error != NO_ERROR) {
2878 TAG_LOGE(AAFwkTag::ABILITYMGR, "clean mission by id , error: %d", error);
2879 return error;
2880 }
2881 return reply.ReadInt32();
2882 }
2883
CleanAllMissions()2884 int AbilityManagerProxy::CleanAllMissions()
2885 {
2886 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2887 int error;
2888 MessageParcel data;
2889 MessageParcel reply;
2890 MessageOption option;
2891
2892 if (!WriteInterfaceToken(data)) {
2893 return INNER_ERR;
2894 }
2895 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS, data, reply, option);
2896 if (error != NO_ERROR) {
2897 TAG_LOGE(AAFwkTag::ABILITYMGR, "lock mission by id ,SendRequest error: %d", error);
2898 return error;
2899 }
2900 return reply.ReadInt32();
2901 }
2902
MoveMissionToFront(int32_t missionId)2903 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId)
2904 {
2905 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2906 int error;
2907 MessageParcel data;
2908 MessageParcel reply;
2909 MessageOption option;
2910
2911 if (!WriteInterfaceToken(data)) {
2912 return INNER_ERR;
2913 }
2914 if (!data.WriteInt32(missionId)) {
2915 TAG_LOGE(AAFwkTag::ABILITYMGR, "move mission to front , WriteInt32 fail.");
2916 return ERR_INVALID_VALUE;
2917 }
2918 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT, data, reply, option);
2919 if (error != NO_ERROR) {
2920 TAG_LOGE(AAFwkTag::ABILITYMGR, "move mission to front, SendRequest error: %d", error);
2921 return error;
2922 }
2923 return reply.ReadInt32();
2924 }
2925
MoveMissionToFront(int32_t missionId,const StartOptions & startOptions)2926 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions)
2927 {
2928 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2929 int error;
2930 MessageParcel data;
2931 MessageParcel reply;
2932 MessageOption option;
2933
2934 if (!WriteInterfaceToken(data)) {
2935 return INNER_ERR;
2936 }
2937 if (!data.WriteInt32(missionId)) {
2938 TAG_LOGE(AAFwkTag::ABILITYMGR, "move mission to front , WriteInt32 fail.");
2939 return ERR_INVALID_VALUE;
2940 }
2941 if (!data.WriteParcelable(&startOptions)) {
2942 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write failed.");
2943 return INNER_ERR;
2944 }
2945 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS, data, reply, option);
2946 if (error != NO_ERROR) {
2947 TAG_LOGE(AAFwkTag::ABILITYMGR, "move mission to front, SendRequest error: %d", error);
2948 return error;
2949 }
2950 return reply.ReadInt32();
2951 }
2952
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)2953 int AbilityManagerProxy::MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId)
2954 {
2955 MessageParcel data;
2956 MessageParcel reply;
2957 MessageOption option;
2958 if (!WriteInterfaceToken(data)) {
2959 return INNER_ERR;
2960 }
2961
2962 if (!data.WriteInt32Vector(missionIds)) {
2963 TAG_LOGE(AAFwkTag::ABILITYMGR, "mission id write failed.");
2964 return INNER_ERR;
2965 }
2966
2967 if (!data.WriteInt32(topMissionId)) {
2968 TAG_LOGE(AAFwkTag::ABILITYMGR, "top mission id write failed.");
2969 return INNER_ERR;
2970 }
2971
2972 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND, data, reply, option);
2973 if (error != NO_ERROR) {
2974 TAG_LOGE(AAFwkTag::ABILITYMGR, "query front missionInfo failed: send request error: %{public}d", error);
2975 return error;
2976 }
2977
2978 return reply.ReadInt32();
2979 }
2980
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)2981 int AbilityManagerProxy::MoveMissionsToBackground(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result)
2982 {
2983 MessageParcel data;
2984 MessageParcel reply;
2985 MessageOption option;
2986 if (!WriteInterfaceToken(data)) {
2987 return INNER_ERR;
2988 }
2989
2990 if (!data.WriteInt32Vector(missionIds)) {
2991 TAG_LOGE(AAFwkTag::ABILITYMGR, "mission id write failed.");
2992 return INNER_ERR;
2993 }
2994
2995 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND, data, reply, option);
2996 if (error != NO_ERROR) {
2997 TAG_LOGE(AAFwkTag::ABILITYMGR, "query front missionInfo failed: send request error: %{public}d", error);
2998 return error;
2999 }
3000
3001 if (!reply.ReadInt32Vector(&result)) {
3002 TAG_LOGE(AAFwkTag::ABILITYMGR, "read result failed");
3003 return INNER_ERR;
3004 }
3005 return reply.ReadInt32();
3006 }
3007
StartUser(int userId,sptr<IUserCallback> callback)3008 int AbilityManagerProxy::StartUser(int userId, sptr<IUserCallback> callback)
3009 {
3010 MessageParcel data;
3011 if (!WriteInterfaceToken(data)) {
3012 return INNER_ERR;
3013 }
3014 if (!data.WriteInt32(userId)) {
3015 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUser:WriteInt32 fail.");
3016 return ERR_INVALID_VALUE;
3017 }
3018 if (!callback) {
3019 data.WriteBool(false);
3020 } else {
3021 data.WriteBool(true);
3022 if (!data.WriteRemoteObject(callback->AsObject())) {
3023 TAG_LOGE(AAFwkTag::ABILITYMGR, "write IUserCallback fail.");
3024 return ERR_INVALID_VALUE;
3025 }
3026 }
3027
3028 MessageParcel reply;
3029 MessageOption option(MessageOption::TF_ASYNC);
3030 auto error = SendRequest(AbilityManagerInterfaceCode::START_USER, data, reply, option);
3031 if (error != NO_ERROR) {
3032 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUser:SendRequest error: %d", error);
3033 return error;
3034 }
3035 return reply.ReadInt32();
3036 }
3037
SetMissionContinueState(const sptr<IRemoteObject> & token,const AAFwk::ContinueState & state)3038 int AbilityManagerProxy::SetMissionContinueState(const sptr<IRemoteObject> &token, const AAFwk::ContinueState &state)
3039 {
3040 MessageParcel data;
3041 MessageParcel reply;
3042 MessageOption option;
3043 if (!WriteInterfaceToken(data)) {
3044 return INNER_ERR;
3045 }
3046 if (!data.WriteRemoteObject(token)) {
3047 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionContinueState write token failed.");
3048 return ERR_INVALID_VALUE;
3049 }
3050 if (!data.WriteInt32(static_cast<int32_t>(state))) {
3051 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionContinueState write state failed.");
3052 return ERR_INVALID_VALUE;
3053 }
3054 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_CONTINUE_STATE, data, reply, option);
3055 if (error != NO_ERROR) {
3056 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionContinueState Send request error: %{public}d", error);
3057 return error;
3058 }
3059 return reply.ReadInt32();
3060 }
3061
StopUser(int userId,const sptr<IUserCallback> & callback)3062 int AbilityManagerProxy::StopUser(int userId, const sptr<IUserCallback> &callback)
3063 {
3064 MessageParcel data;
3065 if (!WriteInterfaceToken(data)) {
3066 return INNER_ERR;
3067 }
3068 if (!data.WriteInt32(userId)) {
3069 TAG_LOGE(AAFwkTag::ABILITYMGR, "StopUser:WriteInt32 fail.");
3070 return ERR_INVALID_VALUE;
3071 }
3072
3073 if (!callback) {
3074 data.WriteBool(false);
3075 } else {
3076 data.WriteBool(true);
3077 if (!data.WriteRemoteObject(callback->AsObject())) {
3078 TAG_LOGE(AAFwkTag::ABILITYMGR, "write IUserCallback fail.");
3079 return ERR_INVALID_VALUE;
3080 }
3081 }
3082 MessageParcel reply;
3083 MessageOption option(MessageOption::TF_ASYNC);
3084 auto error = SendRequest(AbilityManagerInterfaceCode::STOP_USER, data, reply, option);
3085 if (error != NO_ERROR) {
3086 TAG_LOGE(AAFwkTag::ABILITYMGR, "StopUser:SendRequest error: %d", error);
3087 return error;
3088 }
3089 return reply.ReadInt32();
3090 }
3091
LogoutUser(int32_t userId)3092 int AbilityManagerProxy::LogoutUser(int32_t userId)
3093 {
3094 MessageParcel data;
3095 MessageParcel reply;
3096 MessageOption option;
3097
3098 if (!WriteInterfaceToken(data)) {
3099 return INNER_ERR;
3100 }
3101 if (!data.WriteInt32(userId)) {
3102 TAG_LOGE(AAFwkTag::ABILITYMGR, "LogoutUser:WriteInt32 fail.");
3103 return ERR_INVALID_VALUE;
3104 }
3105 int error = SendRequest(AbilityManagerInterfaceCode::LOGOUT_USER, data, reply, option);
3106 if (error != NO_ERROR) {
3107 TAG_LOGE(AAFwkTag::ABILITYMGR, "LogoutUser:SendRequest error: %{public}d", error);
3108 return error;
3109 }
3110 return reply.ReadInt32();
3111 }
3112
3113 #ifdef SUPPORT_GRAPHICS
SetMissionLabel(const sptr<IRemoteObject> & token,const std::string & label)3114 int AbilityManagerProxy::SetMissionLabel(const sptr<IRemoteObject> &token, const std::string &label)
3115 {
3116 MessageParcel data;
3117 MessageParcel reply;
3118 MessageOption option;
3119 if (!WriteInterfaceToken(data)) {
3120 return INNER_ERR;
3121 }
3122 if (!data.WriteRemoteObject(token)) {
3123 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionLabel write token failed.");
3124 return ERR_INVALID_VALUE;
3125 }
3126 if (!data.WriteString16(Str8ToStr16(label))) {
3127 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionLabel write label failed.");
3128 return ERR_INVALID_VALUE;
3129 }
3130 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_LABEL, data, reply, option);
3131 if (error != NO_ERROR) {
3132 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionLabel Send request error: %{public}d", error);
3133 return error;
3134 }
3135 return reply.ReadInt32();
3136 }
3137
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)3138 int AbilityManagerProxy::SetMissionIcon(const sptr<IRemoteObject> &token,
3139 const std::shared_ptr<OHOS::Media::PixelMap> &icon)
3140 {
3141 if (!token || !icon) {
3142 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionIcon abilitytoken or icon is invalid.");
3143 return ERR_INVALID_VALUE;
3144 }
3145
3146 MessageParcel data;
3147 MessageParcel reply;
3148 MessageOption option;
3149 if (!WriteInterfaceToken(data)) {
3150 return INNER_ERR;
3151 }
3152 if (!data.WriteRemoteObject(token)) {
3153 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionIcon write token failed.");
3154 return ERR_INVALID_VALUE;
3155 }
3156
3157 if (!data.WriteParcelable(icon.get())) {
3158 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionIcon write icon failed.");
3159 return ERR_INVALID_VALUE;
3160 }
3161
3162 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_ICON, data, reply, option);
3163 if (error != NO_ERROR) {
3164 TAG_LOGE(AAFwkTag::ABILITYMGR, "SetMissionIcon Send request error: %{public}d", error);
3165 return error;
3166 }
3167 return reply.ReadInt32();
3168 }
3169
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler,bool animationEnabled)3170 int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
3171 bool animationEnabled)
3172 {
3173 if (!handler) {
3174 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: handler is nullptr.", __func__);
3175 return INNER_ERR;
3176 }
3177 MessageParcel data;
3178 if (!WriteInterfaceToken(data)) {
3179 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: write interface token failed.", __func__);
3180 return INNER_ERR;
3181 }
3182 if (!data.WriteRemoteObject(handler->AsObject())) {
3183 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: handler write failed.", __func__);
3184 return INNER_ERR;
3185 }
3186 if (!data.WriteBool(animationEnabled)) {
3187 TAG_LOGE(AAFwkTag::ABILITYMGR, "write animationEnabled fail.");
3188 return ERR_INVALID_VALUE;
3189 }
3190 MessageOption option;
3191 MessageParcel reply;
3192 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER, data, reply, option);
3193 if (error != NO_ERROR) {
3194 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: send request error: %{public}d", __func__, error);
3195 return error;
3196 }
3197 return reply.ReadInt32();
3198 }
3199
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)3200 void AbilityManagerProxy::CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken)
3201 {
3202 MessageParcel data;
3203 if (!WriteInterfaceToken(data)) {
3204 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: write interface token failed.", __func__);
3205 return;
3206 }
3207 if (!data.WriteRemoteObject(abilityToken)) {
3208 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: abilityToken write failed.", __func__);
3209 return;
3210 }
3211 MessageOption option;
3212 MessageParcel reply;
3213 auto error = SendRequest(AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING, data, reply, option);
3214 if (error != NO_ERROR) {
3215 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: send request error: %{public}d", __func__, error);
3216 }
3217 }
3218
PrepareTerminateAbility(const sptr<IRemoteObject> & token,sptr<IPrepareTerminateCallback> & callback)3219 int AbilityManagerProxy::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
3220 sptr<IPrepareTerminateCallback> &callback)
3221 {
3222 if (!callback) {
3223 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback is nullptr.");
3224 return INNER_ERR;
3225 }
3226 int error = 0;
3227 MessageParcel data;
3228 MessageParcel reply;
3229 MessageOption option(MessageOption::TF_SYNC);
3230 if (!WriteInterfaceToken(data)) {
3231 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
3232 return INNER_ERR;
3233 }
3234 if (token) {
3235 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
3236 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed.");
3237 return INNER_ERR;
3238 }
3239 } else {
3240 if (!data.WriteBool(false)) {
3241 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed.");
3242 return INNER_ERR;
3243 }
3244 }
3245 if (!data.WriteRemoteObject(callback->AsObject())) {
3246 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite callback failed.");
3247 return INNER_ERR;
3248 }
3249
3250 error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY, data, reply, option);
3251 if (error != NO_ERROR) {
3252 TAG_LOGE(AAFwkTag::ABILITYMGR, "send request failed. error: %{public}d", error);
3253 return error;
3254 }
3255
3256 return reply.ReadInt32();
3257 }
3258
GetDialogSessionInfo(const std::string & dialogSessionId,sptr<DialogSessionInfo> & info)3259 int AbilityManagerProxy::GetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &info)
3260 {
3261 MessageParcel data;
3262 MessageParcel reply;
3263 MessageOption option;
3264 if (!WriteInterfaceToken(data)) {
3265 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface fail.");
3266 return INNER_ERR;
3267 }
3268 if (!data.WriteString(dialogSessionId)) {
3269 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail.");
3270 return ERR_INVALID_VALUE;
3271 }
3272 auto error = SendRequest(AbilityManagerInterfaceCode::GET_DIALOG_SESSION_INFO, data, reply, option);
3273 if (error != NO_ERROR) {
3274 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get extension running info failed., error: %{public}d", error);
3275 return error;
3276 }
3277 info = reply.ReadParcelable<DialogSessionInfo>();
3278 if (!info) {
3279 TAG_LOGE(AAFwkTag::ABILITYMGR, "read IRemoteObject failed.");
3280 return ERR_UNKNOWN_OBJECT;
3281 }
3282 return reply.ReadInt32();
3283 }
3284
SendDialogResult(const Want & want,const std::string & dialogSessionId,const bool isAllow)3285 int AbilityManagerProxy::SendDialogResult(const Want &want, const std::string &dialogSessionId, const bool isAllow)
3286 {
3287 MessageParcel data;
3288 MessageParcel reply;
3289 MessageOption option;
3290 if (!WriteInterfaceToken(data)) {
3291 return INNER_ERR;
3292 }
3293 if (!data.WriteParcelable(&want)) {
3294 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
3295 return ERR_INVALID_VALUE;
3296 }
3297 if (!data.WriteString(dialogSessionId)) {
3298 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail.");
3299 return ERR_INVALID_VALUE;
3300 }
3301 if (!data.WriteBool(isAllow)) {
3302 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail.");
3303 return ERR_INVALID_VALUE;
3304 }
3305 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_DIALOG_RESULT, data, reply, option);
3306 if (error != NO_ERROR) {
3307 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get extension running info failed., error: %{public}d", error);
3308 return error;
3309 }
3310 return reply.ReadInt32();
3311 }
3312
RegisterAbilityFirstFrameStateObserver(const sptr<IAbilityFirstFrameStateObserver> & observer,const std::string & targetBundleName)3313 int32_t AbilityManagerProxy::RegisterAbilityFirstFrameStateObserver(
3314 const sptr<IAbilityFirstFrameStateObserver> &observer, const std::string &targetBundleName)
3315 {
3316 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
3317 MessageParcel data;
3318 if (!WriteInterfaceToken(data)) {
3319 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
3320 return INNER_ERR;
3321 }
3322
3323 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
3324 TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null or Write Remote failed.");
3325 return ERR_INVALID_VALUE;
3326 }
3327 if (!data.WriteString(targetBundleName)) {
3328 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write target bundleName failed.");
3329 return ERR_INVALID_VALUE;
3330 }
3331
3332 MessageParcel reply;
3333 MessageOption option;
3334 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER,
3335 data, reply, option);
3336 if (ret != NO_ERROR) {
3337 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request is failed, error code: %{public}d", ret);
3338 return ret;
3339 }
3340 return reply.ReadInt32();
3341 }
3342
UnregisterAbilityFirstFrameStateObserver(const sptr<IAbilityFirstFrameStateObserver> & observer)3343 int32_t AbilityManagerProxy::UnregisterAbilityFirstFrameStateObserver(
3344 const sptr<IAbilityFirstFrameStateObserver> &observer)
3345 {
3346 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
3347 MessageParcel data;
3348 if (!WriteInterfaceToken(data)) {
3349 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
3350 return INNER_ERR;
3351 }
3352 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
3353 TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null or Write Remote failed.");
3354 return ERR_INVALID_VALUE;
3355 }
3356
3357 MessageParcel reply;
3358 MessageOption option;
3359 auto ret =
3360 SendRequest(AbilityManagerInterfaceCode::UNREGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER, data, reply, option);
3361 if (ret != NO_ERROR) {
3362 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request is failed, error code: %{public}d", ret);
3363 return ret;
3364 }
3365 return reply.ReadInt32();
3366 }
3367
CompleteFirstFrameDrawing(int32_t sessionId)3368 void AbilityManagerProxy::CompleteFirstFrameDrawing(int32_t sessionId)
3369 {
3370 MessageParcel data;
3371 if (!WriteInterfaceToken(data)) {
3372 TAG_LOGE(AAFwkTag::ABILITYMGR, "CompleteFirstFrameDrawing, write interface token failed.");
3373 return;
3374 }
3375 if (!data.WriteInt32(sessionId)) {
3376 TAG_LOGE(AAFwkTag::ABILITYMGR, "CompleteFirstFrameDrawing, sessionId write failed.");
3377 return;
3378 }
3379 MessageOption option;
3380 MessageParcel reply;
3381 auto error = SendRequest(AbilityManagerInterfaceCode::COMPLETE_FIRST_FRAME_DRAWING_BY_SCB, data, reply, option);
3382 if (error != NO_ERROR) {
3383 TAG_LOGE(AAFwkTag::ABILITYMGR, "CompleteFirstFrameDrawing, send request error: %{public}d", error);
3384 }
3385 }
3386 #endif
3387
GetAbilityRunningInfos(std::vector<AbilityRunningInfo> & info)3388 int AbilityManagerProxy::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
3389 {
3390 MessageParcel data;
3391 MessageParcel reply;
3392 MessageOption option;
3393
3394 if (!WriteInterfaceToken(data)) {
3395 return INNER_ERR;
3396 }
3397
3398 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO, data, reply, option);
3399 if (error != NO_ERROR) {
3400 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get ability running info, error: %{public}d", error);
3401 return error;
3402 }
3403 error = GetParcelableInfos<AbilityRunningInfo>(reply, info);
3404 if (error != NO_ERROR) {
3405 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos fail, error: %{public}d", error);
3406 return error;
3407 }
3408 return reply.ReadInt32();
3409 }
3410
GetExtensionRunningInfos(int upperLimit,std::vector<ExtensionRunningInfo> & info)3411 int AbilityManagerProxy::GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info)
3412 {
3413 MessageParcel data;
3414 MessageParcel reply;
3415 MessageOption option;
3416
3417 if (!WriteInterfaceToken(data)) {
3418 return INNER_ERR;
3419 }
3420
3421 if (!data.WriteInt32(upperLimit)) {
3422 TAG_LOGE(AAFwkTag::ABILITYMGR, "upperLimit write failed.");
3423 return INNER_ERR;
3424 }
3425
3426 auto error = SendRequest(AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO, data, reply, option);
3427 if (error != NO_ERROR) {
3428 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get extension running info failed., error: %{public}d", error);
3429 return error;
3430 }
3431 error = GetParcelableInfos<ExtensionRunningInfo>(reply, info);
3432 if (error != NO_ERROR) {
3433 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos fail, error: %{public}d", error);
3434 return error;
3435 }
3436 return reply.ReadInt32();
3437 }
3438
GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> & info)3439 int AbilityManagerProxy::GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info)
3440 {
3441 MessageParcel data;
3442 MessageParcel reply;
3443 MessageOption option;
3444
3445 if (!WriteInterfaceToken(data)) {
3446 return INNER_ERR;
3447 }
3448
3449 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO, data, reply, option);
3450 if (error != NO_ERROR) {
3451 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get process running info, error: %{public}d", error);
3452 return error;
3453 }
3454 error = GetParcelableInfos<AppExecFwk::RunningProcessInfo>(reply, info);
3455 if (error != NO_ERROR) {
3456 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos fail, error: %{public}d", error);
3457 return error;
3458 }
3459 return reply.ReadInt32();
3460 }
3461
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)3462 int AbilityManagerProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
3463 {
3464 TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
3465 MessageParcel data;
3466 MessageParcel reply;
3467 MessageOption option;
3468
3469 if (!WriteInterfaceToken(data)) {
3470 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
3471 return ERR_INVALID_VALUE;
3472 }
3473 if (!data.WriteString(devId)) {
3474 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId fail.");
3475 return ERR_INVALID_VALUE;
3476 }
3477
3478 if (!data.WriteBool(fixConflict)) {
3479 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteBool fail.");
3480 return ERR_INVALID_VALUE;
3481 }
3482
3483 if (!data.WriteInt64(tag)) {
3484 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInt64 fail.");
3485 return ERR_INVALID_VALUE;
3486 }
3487
3488 auto error = SendRequest(AbilityManagerInterfaceCode::START_SYNC_MISSIONS, data, reply, option);
3489 if (error != NO_ERROR) {
3490 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3491 return error;
3492 }
3493 return reply.ReadInt32();
3494 }
3495
StopSyncRemoteMissions(const std::string & devId)3496 int32_t AbilityManagerProxy::StopSyncRemoteMissions(const std::string& devId)
3497 {
3498 TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
3499 MessageParcel data;
3500 MessageParcel reply;
3501 MessageOption option;
3502
3503 if (!WriteInterfaceToken(data)) {
3504 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
3505 return ERR_INVALID_VALUE;
3506 }
3507 if (!data.WriteString(devId)) {
3508 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId fail.");
3509 return ERR_INVALID_VALUE;
3510 }
3511 auto error = SendRequest(AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS, data, reply, option);
3512 if (error != NO_ERROR) {
3513 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3514 return error;
3515 }
3516 return reply.ReadInt32();
3517 }
3518
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)3519 int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId,
3520 const sptr<IRemoteMissionListener> &listener)
3521 {
3522 MessageParcel data;
3523 MessageParcel reply;
3524 MessageOption option;
3525 if (!WriteInterfaceToken(data)) {
3526 return INNER_ERR;
3527 }
3528 if (!data.WriteString(deviceId)) {
3529 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write failed.");
3530 return INNER_ERR;
3531 }
3532 if (!data.WriteRemoteObject(listener->AsObject())) {
3533 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write failed.");
3534 return INNER_ERR;
3535 }
3536
3537 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER,
3538 data, reply, option);
3539 if (error != NO_ERROR) {
3540 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3541 return error;
3542 }
3543 return reply.ReadInt32();
3544 }
3545
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId)3546 int AbilityManagerProxy::StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
3547 const sptr<IRemoteObject> &callerToken, int32_t accountId)
3548 {
3549 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::StartAbilityByCall begin.");
3550 int error;
3551 MessageParcel data;
3552 MessageParcel reply;
3553 MessageOption option;
3554
3555 if (!WriteInterfaceToken(data)) {
3556 return INNER_ERR;
3557 }
3558 if (!data.WriteParcelable(&want)) {
3559 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
3560 return ERR_INVALID_VALUE;
3561 }
3562 if (connect == nullptr) {
3563 TAG_LOGE(AAFwkTag::ABILITYMGR, "resolve ability fail, connect is nullptr");
3564 return ERR_INVALID_VALUE;
3565 }
3566 if (!data.WriteRemoteObject(connect->AsObject())) {
3567 TAG_LOGE(AAFwkTag::ABILITYMGR, "resolve write failed.");
3568 return ERR_INVALID_VALUE;
3569 }
3570 if (callerToken) {
3571 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
3572 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and callerToken.");
3573 return ERR_INVALID_VALUE;
3574 }
3575 } else {
3576 if (!data.WriteBool(false)) {
3577 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
3578 return ERR_INVALID_VALUE;
3579 }
3580 }
3581 if (!data.WriteInt32(accountId)) {
3582 TAG_LOGE(AAFwkTag::ABILITYMGR, "accountId write failed.");
3583 return ERR_INVALID_VALUE;
3584 }
3585
3586 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::StartAbilityByCall SendRequest Call.");
3587 error = SendRequest(AbilityManagerInterfaceCode::START_CALL_ABILITY, data, reply, option);
3588 if (error != NO_ERROR) {
3589 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3590 return error;
3591 }
3592 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::StartAbilityByCall end.");
3593 return reply.ReadInt32();
3594 }
3595
CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)3596 void AbilityManagerProxy::CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub)
3597 {
3598 MessageParcel data;
3599 MessageParcel reply;
3600 MessageOption option(MessageOption::TF_ASYNC);
3601
3602 if (token == nullptr) {
3603 TAG_LOGE(AAFwkTag::ABILITYMGR, "Call request done fail, ability token is nullptr.");
3604 return;
3605 }
3606 if (callStub == nullptr) {
3607 TAG_LOGE(AAFwkTag::ABILITYMGR, "Call request done fail, callStub is nullptr.");
3608 return;
3609 }
3610
3611 if (!WriteInterfaceToken(data)) {
3612 return;
3613 }
3614 if (!data.WriteRemoteObject(token)) {
3615 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteRemoteObject fail, write token fail.");
3616 return;
3617 }
3618 if (!data.WriteRemoteObject(callStub)) {
3619 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteRemoteObject fail, write callStub fail.");
3620 return;
3621 }
3622 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_REQUEST_DONE, data, reply, option);
3623 if (error != NO_ERROR) {
3624 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3625 return;
3626 }
3627 }
3628
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)3629 int AbilityManagerProxy::ReleaseCall(
3630 const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element)
3631 {
3632 int error;
3633 MessageParcel data;
3634 MessageParcel reply;
3635 MessageOption option;
3636 if (connect == nullptr) {
3637 TAG_LOGE(AAFwkTag::ABILITYMGR, "release calll ability fail, connect is nullptr");
3638 return ERR_INVALID_VALUE;
3639 }
3640 if (!WriteInterfaceToken(data)) {
3641 return INNER_ERR;
3642 }
3643 if (!data.WriteRemoteObject(connect->AsObject())) {
3644 TAG_LOGE(AAFwkTag::ABILITYMGR, "release ability connect write failed.");
3645 return ERR_INVALID_VALUE;
3646 }
3647 if (!data.WriteParcelable(&element)) {
3648 TAG_LOGE(AAFwkTag::ABILITYMGR, "element error.");
3649 return ERR_INVALID_VALUE;
3650 }
3651
3652 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY, data, reply, option);
3653 if (error != NO_ERROR) {
3654 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3655 return error;
3656 }
3657 return reply.ReadInt32();
3658 }
3659
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)3660 void AbilityManagerProxy::GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token)
3661 {
3662 MessageParcel data;
3663 MessageParcel reply;
3664 MessageOption option;
3665 if (!WriteInterfaceToken(data)) {
3666 return;
3667 }
3668 if (!data.WriteRemoteObject(callStub)) {
3669 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteRemoteObject fail, write callStub fail.");
3670 return;
3671 }
3672
3673 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_TOKEN, data, reply, option);
3674 if (error != NO_ERROR) {
3675 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3676 return;
3677 }
3678 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
3679 }
3680
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)3681 int AbilityManagerProxy::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
3682 {
3683 MessageParcel data;
3684 MessageParcel reply;
3685 MessageOption option;
3686 if (!WriteInterfaceToken(data)) {
3687 return INNER_ERR;
3688 }
3689 if (!data.WriteRemoteObject(handler->AsObject())) {
3690 TAG_LOGE(AAFwkTag::ABILITYMGR, "snapshot: handler write failed.");
3691 return INNER_ERR;
3692 }
3693 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SNAPSHOT_HANDLER, data, reply, option);
3694 if (error != NO_ERROR) {
3695 TAG_LOGE(AAFwkTag::ABILITYMGR, "snapshot: send request error: %{public}d", error);
3696 return error;
3697 }
3698 return reply.ReadInt32();
3699 }
3700
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)3701 int AbilityManagerProxy::SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,
3702 bool imAStabilityTest)
3703 {
3704 if (!abilityController) {
3705 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityController nullptr");
3706 return ERR_INVALID_VALUE;
3707 }
3708 MessageParcel data;
3709 MessageParcel reply;
3710 MessageOption option;
3711 if (!WriteInterfaceToken(data)) {
3712 return INNER_ERR;
3713 }
3714 if (!data.WriteRemoteObject(abilityController->AsObject())) {
3715 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityController write failed.");
3716 return ERR_INVALID_VALUE;
3717 }
3718 if (!data.WriteBool(imAStabilityTest)) {
3719 TAG_LOGE(AAFwkTag::ABILITYMGR, "imAStabilityTest write failed.");
3720 return ERR_INVALID_VALUE;
3721 }
3722 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER, data, reply, option);
3723 if (error != NO_ERROR) {
3724 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3725 return error;
3726 }
3727 return reply.ReadInt32();
3728 }
3729
IsRunningInStabilityTest()3730 bool AbilityManagerProxy::IsRunningInStabilityTest()
3731 {
3732 MessageParcel data;
3733 MessageParcel reply;
3734 MessageOption option;
3735 if (!WriteInterfaceToken(data)) {
3736 return false;
3737 }
3738 auto error = SendRequest(AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST, data, reply, option);
3739 if (error != NO_ERROR) {
3740 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3741 return false;
3742 }
3743 return reply.ReadBool();
3744 }
3745
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)3746 int AbilityManagerProxy::StartUserTest(const Want &want, const sptr<IRemoteObject> &observer)
3747 {
3748 MessageParcel data;
3749 MessageParcel reply;
3750 MessageOption option;
3751
3752 if (!WriteInterfaceToken(data)) {
3753 return INNER_ERR;
3754 }
3755 if (!data.WriteParcelable(&want)) {
3756 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
3757 return INNER_ERR;
3758 }
3759 if (!data.WriteRemoteObject(observer)) {
3760 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write failed.");
3761 return INNER_ERR;
3762 }
3763 auto error = SendRequest(AbilityManagerInterfaceCode::START_USER_TEST, data, reply, option);
3764 if (error != NO_ERROR) {
3765 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3766 return error;
3767 }
3768 return reply.ReadInt32();
3769 }
3770
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)3771 int AbilityManagerProxy::FinishUserTest(
3772 const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
3773 {
3774 MessageParcel data;
3775 MessageParcel reply;
3776 MessageOption option;
3777
3778 if (!WriteInterfaceToken(data)) {
3779 return INNER_ERR;
3780 }
3781 if (!data.WriteString(msg)) {
3782 TAG_LOGE(AAFwkTag::ABILITYMGR, "msg write failed.");
3783 return ERR_INVALID_VALUE;
3784 }
3785 if (!data.WriteInt64(resultCode)) {
3786 TAG_LOGE(AAFwkTag::ABILITYMGR, "resultCode:WriteInt64 fail.");
3787 return ERR_INVALID_VALUE;
3788 }
3789 if (!data.WriteString(bundleName)) {
3790 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write failed.");
3791 return ERR_INVALID_VALUE;
3792 }
3793
3794 auto error = SendRequest(AbilityManagerInterfaceCode::FINISH_USER_TEST, data, reply, option);
3795 if (error != NO_ERROR) {
3796 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3797 return error;
3798 }
3799 return reply.ReadInt32();
3800 }
3801
GetTopAbility(sptr<IRemoteObject> & token)3802 int AbilityManagerProxy::GetTopAbility(sptr<IRemoteObject> &token)
3803 {
3804 MessageParcel data;
3805 MessageParcel reply;
3806 MessageOption option;
3807
3808 if (!WriteInterfaceToken(data)) {
3809 return INNER_ERR;
3810 }
3811
3812 auto error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN, data, reply, option);
3813 if (error != NO_ERROR) {
3814 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3815 return error;
3816 }
3817
3818 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
3819 if (!token) {
3820 TAG_LOGE(AAFwkTag::ABILITYMGR, "read IRemoteObject failed.");
3821 return ERR_UNKNOWN_OBJECT;
3822 }
3823
3824 return reply.ReadInt32();
3825 }
3826
CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId,bool & isFocused)3827 int AbilityManagerProxy::CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused)
3828 {
3829 MessageParcel data;
3830 MessageParcel reply;
3831 MessageOption option;
3832
3833 if (!WriteInterfaceToken(data)) {
3834 return INNER_ERR;
3835 }
3836
3837 if (!data.WriteUint32(uiExtensionTokenId)) {
3838 TAG_LOGE(AAFwkTag::ABILITYMGR, "uiExtensionTokenId write failed.");
3839 return ERR_INVALID_VALUE;
3840 }
3841
3842 auto error = SendRequest(AbilityManagerInterfaceCode::CHECK_UI_EXTENSION_IS_FOCUSED, data, reply, option);
3843 if (error != NO_ERROR) {
3844 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3845 return error;
3846 }
3847
3848 isFocused = reply.ReadBool();
3849 return NO_ERROR;
3850 }
3851
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)3852 int AbilityManagerProxy::DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token)
3853 {
3854 MessageParcel data;
3855 MessageParcel reply;
3856 MessageOption option;
3857
3858 if (!WriteInterfaceToken(data)) {
3859 return INNER_ERR;
3860 }
3861
3862 if (!data.WriteRemoteObject(token)) {
3863 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
3864 return ERR_INVALID_VALUE;
3865 }
3866
3867 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND,
3868 data, reply, option);
3869 if (error != NO_ERROR) {
3870 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3871 return error;
3872 }
3873
3874 return reply.ReadInt32();
3875 }
3876
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)3877 int AbilityManagerProxy::DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token)
3878 {
3879 MessageParcel data;
3880 MessageParcel reply;
3881 MessageOption option;
3882
3883 if (!WriteInterfaceToken(data)) {
3884 return INNER_ERR;
3885 }
3886
3887 if (!data.WriteRemoteObject(token)) {
3888 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
3889 return ERR_INVALID_VALUE;
3890 }
3891
3892 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND,
3893 data, reply, option);
3894 if (error != NO_ERROR) {
3895 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3896 return error;
3897 }
3898
3899 return reply.ReadInt32();
3900 }
3901
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)3902 int AbilityManagerProxy::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
3903 {
3904 MessageParcel data;
3905 MessageParcel reply;
3906 MessageOption option;
3907
3908 if (!WriteInterfaceToken(data)) {
3909 return INNER_ERR;
3910 }
3911
3912 if (!data.WriteRemoteObject(token)) {
3913 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
3914 return ERR_INVALID_VALUE;
3915 }
3916
3917 if (!data.WriteUint32(flag)) {
3918 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
3919 return ERR_INVALID_VALUE;
3920 }
3921
3922 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND, data, reply, option);
3923 if (error != NO_ERROR) {
3924 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3925 return error;
3926 }
3927
3928 return reply.ReadInt32();
3929 }
3930
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)3931 int AbilityManagerProxy::DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag)
3932 {
3933 MessageParcel data;
3934 MessageParcel reply;
3935 MessageOption option;
3936
3937 if (!WriteInterfaceToken(data)) {
3938 return INNER_ERR;
3939 }
3940
3941 if (!data.WriteRemoteObject(token)) {
3942 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
3943 return ERR_INVALID_VALUE;
3944 }
3945
3946 if (!data.WriteUint32(flag)) {
3947 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
3948 return ERR_INVALID_VALUE;
3949 }
3950
3951 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND, data, reply, option);
3952 if (error != NO_ERROR) {
3953 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3954 return error;
3955 }
3956
3957 return reply.ReadInt32();
3958 }
3959
GetMissionIdByToken(const sptr<IRemoteObject> & token)3960 int32_t AbilityManagerProxy::GetMissionIdByToken(const sptr<IRemoteObject> &token)
3961 {
3962 if (!token) {
3963 TAG_LOGE(AAFwkTag::ABILITYMGR, "token is nullptr.");
3964 return -1;
3965 }
3966
3967 MessageParcel data;
3968 MessageParcel reply;
3969 MessageOption option;
3970 if (!WriteInterfaceToken(data)) {
3971 TAG_LOGE(AAFwkTag::ABILITYMGR, "data interface token failed.");
3972 return -1;
3973 }
3974
3975 if (!data.WriteRemoteObject(token)) {
3976 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write failed.");
3977 return -1;
3978 }
3979
3980 auto error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN,
3981 data, reply, option);
3982 if (error != NO_ERROR) {
3983 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
3984 return -1;
3985 }
3986
3987 return reply.ReadInt32();
3988 }
3989
FreeInstallAbilityFromRemote(const Want & want,const sptr<IRemoteObject> & callback,int32_t userId,int requestCode)3990 int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
3991 int32_t userId, int requestCode)
3992 {
3993 MessageParcel data;
3994 MessageParcel reply;
3995 MessageOption option;
3996 if (!WriteInterfaceToken(data)) {
3997 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
3998 return INNER_ERR;
3999 }
4000
4001 if (!data.WriteParcelable(&want)) {
4002 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
4003 return INNER_ERR;
4004 }
4005
4006 if (!data.WriteRemoteObject(callback)) {
4007 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback write failed.");
4008 return INNER_ERR;
4009 }
4010
4011 if (!data.WriteInt32(userId)) {
4012 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
4013 return INNER_ERR;
4014 }
4015
4016 if (!data.WriteInt32(requestCode)) {
4017 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
4018 return INNER_ERR;
4019 }
4020
4021 auto error = SendRequest(AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE,
4022 data, reply, option);
4023 if (error != NO_ERROR) {
4024 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4025 return error;
4026 }
4027
4028 return reply.ReadInt32();
4029 }
4030
AddFreeInstallObserver(const sptr<IRemoteObject> & callerToken,const sptr<AbilityRuntime::IFreeInstallObserver> & observer)4031 int AbilityManagerProxy::AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
4032 const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
4033 {
4034 MessageParcel data;
4035 MessageParcel reply;
4036 MessageOption option;
4037 if (observer == nullptr) {
4038 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer is nullptr.");
4039 return INNER_ERR;
4040 }
4041
4042 if (!WriteInterfaceToken(data)) {
4043 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4044 return INNER_ERR;
4045 }
4046
4047 if (callerToken) {
4048 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
4049 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and callerToken.");
4050 return INNER_ERR;
4051 }
4052 } else {
4053 if (!data.WriteBool(false)) {
4054 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
4055 return INNER_ERR;
4056 }
4057 }
4058
4059 if (!data.WriteRemoteObject(observer->AsObject())) {
4060 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write failed.");
4061 return INNER_ERR;
4062 }
4063
4064 auto error = SendRequest(AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER, data, reply, option);
4065 if (error != NO_ERROR) {
4066 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4067 return error;
4068 }
4069 return reply.ReadInt32();
4070 }
4071
DumpAbilityInfoDone(std::vector<std::string> & infos,const sptr<IRemoteObject> & callerToken)4072 int AbilityManagerProxy::DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken)
4073 {
4074 MessageParcel data;
4075 MessageParcel reply;
4076 MessageOption option;
4077 if (!WriteInterfaceToken(data)) {
4078 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4079 return INNER_ERR;
4080 }
4081
4082 if (!data.WriteStringVector(infos)) {
4083 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write failed.");
4084 return INNER_ERR;
4085 }
4086
4087 if (!data.WriteRemoteObject(callerToken)) {
4088 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write failed.");
4089 return INNER_ERR;
4090 }
4091
4092 auto error = SendRequest(AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE, data, reply, option);
4093 if (error != NO_ERROR) {
4094 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4095 return error;
4096 }
4097
4098 return reply.ReadInt32();
4099 }
4100
IsValidMissionIds(const std::vector<int32_t> & missionIds,std::vector<MissionValidResult> & results)4101 int32_t AbilityManagerProxy::IsValidMissionIds(
4102 const std::vector<int32_t> &missionIds, std::vector<MissionValidResult> &results)
4103 {
4104 TAG_LOGI(AAFwkTag::ABILITYMGR, "IsValidMissionIds Call. Quert size is %{public}zu", missionIds.size());
4105 MessageParcel data;
4106 MessageParcel reply;
4107 MessageOption option;
4108 if (!WriteInterfaceToken(data)) {
4109 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4110 return INNER_ERR;
4111 }
4112
4113 constexpr int32_t MAX_COUNT = 20;
4114 int32_t num = static_cast<int32_t>(missionIds.size() > MAX_COUNT ? MAX_COUNT : missionIds.size());
4115 data.WriteInt32(num);
4116 for (auto i = 0; i < num; ++i) {
4117 data.WriteInt32(missionIds.at(i));
4118 }
4119
4120 auto error = SendRequest(AbilityManagerInterfaceCode::QUERY_MISSION_VAILD, data, reply, option);
4121 if (error != NO_ERROR) {
4122 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4123 return error;
4124 }
4125
4126 auto resultCode = reply.ReadInt32();
4127 if (resultCode != ERR_OK) {
4128 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request reply error: %{public}d", resultCode);
4129 return resultCode;
4130 }
4131
4132 auto infoSize = reply.ReadInt32();
4133 for (auto i = 0; i < infoSize && i < MAX_COUNT; ++i) {
4134 std::unique_ptr<MissionValidResult> info(reply.ReadParcelable<MissionValidResult>());
4135 if (!info) {
4136 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read Parcelable result infos failed.");
4137 return INNER_ERR;
4138 }
4139 results.emplace_back(*info);
4140 }
4141
4142 return resultCode;
4143 }
4144
VerifyPermission(const std::string & permission,int pid,int uid)4145 int AbilityManagerProxy::VerifyPermission(const std::string &permission, int pid, int uid)
4146 {
4147 TAG_LOGI(AAFwkTag::ABILITYMGR, "VerifyPermission Call");
4148 MessageParcel data;
4149 MessageParcel reply;
4150 MessageOption option;
4151 if (!WriteInterfaceToken(data)) {
4152 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4153 return INNER_ERR;
4154 }
4155
4156 if (!data.WriteString(permission)) {
4157 TAG_LOGE(AAFwkTag::ABILITYMGR, "permission write failed.");
4158 return INNER_ERR;
4159 }
4160
4161 if (!data.WriteInt32(pid)) {
4162 TAG_LOGE(AAFwkTag::ABILITYMGR, "pid write failed.");
4163 return INNER_ERR;
4164 }
4165
4166 if (!data.WriteInt32(uid)) {
4167 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write failed.");
4168 return INNER_ERR;
4169 }
4170
4171 auto error = SendRequest(AbilityManagerInterfaceCode::VERIFY_PERMISSION, data, reply, option);
4172 if (error != NO_ERROR) {
4173 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4174 return error;
4175 }
4176
4177 return reply.ReadInt32();
4178 }
4179
RequestDialogService(const Want & want,const sptr<IRemoteObject> & callerToken)4180 int32_t AbilityManagerProxy::RequestDialogService(const Want &want, const sptr<IRemoteObject> &callerToken)
4181 {
4182 TAG_LOGI(AAFwkTag::ABILITYMGR, "RequestDialogService Call");
4183 if (!callerToken) {
4184 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken is invalid.");
4185 return ERR_INVALID_CALLER;
4186 }
4187
4188 MessageParcel data;
4189 MessageParcel reply;
4190 MessageOption option;
4191 if (!WriteInterfaceToken(data)) {
4192 return INNER_ERR;
4193 }
4194
4195 if (!data.WriteParcelable(&want)) {
4196 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
4197 return INNER_ERR;
4198 }
4199
4200 if (!data.WriteRemoteObject(callerToken)) {
4201 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write failed.");
4202 return INNER_ERR;
4203 }
4204
4205 auto error = SendRequest(AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE, data, reply, option);
4206 if (error != NO_ERROR) {
4207 TAG_LOGE(AAFwkTag::ABILITYMGR, "request dialog service Send request error: %{public}d", error);
4208 return error;
4209 }
4210 return reply.ReadInt32();
4211 }
4212
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)4213 int32_t AbilityManagerProxy::ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken)
4214 {
4215 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4216 if (callerToken == nullptr) {
4217 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken is nullptr");
4218 return INNER_ERR;
4219 }
4220
4221 MessageParcel data;
4222 MessageParcel reply;
4223 MessageOption option;
4224 if (!WriteInterfaceToken(data)) {
4225 return INNER_ERR;
4226 }
4227
4228 if (!data.WriteRemoteObject(callerToken)) {
4229 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken write failed.");
4230 return INNER_ERR;
4231 }
4232
4233 auto error = SendRequest(AbilityManagerInterfaceCode::REPORT_DRAWN_COMPLETED, data, reply, option);
4234 if (error != NO_ERROR) {
4235 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4236 return error;
4237 }
4238 return reply.ReadInt32();
4239 }
4240
AcquireShareData(const int32_t & missionId,const sptr<IAcquireShareDataCallback> & shareData)4241 int32_t AbilityManagerProxy::AcquireShareData(
4242 const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData)
4243 {
4244 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::AcquireShareData start.");
4245 MessageParcel data;
4246 MessageParcel reply;
4247 MessageOption option;
4248
4249 if (!WriteInterfaceToken(data)) {
4250 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4251 return INNER_ERR;
4252 }
4253
4254 if (!data.WriteInt32(missionId)) {
4255 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write failed.");
4256 return INNER_ERR;
4257 }
4258
4259 if (shareData == nullptr || !data.WriteRemoteObject(shareData->AsObject())) {
4260 TAG_LOGE(AAFwkTag::ABILITYMGR, "shareData write failed.");
4261 return INNER_ERR;
4262 }
4263
4264 int32_t error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA, data, reply, option);
4265 if (error != NO_ERROR) {
4266 TAG_LOGE(AAFwkTag::ABILITYMGR, "AcquireShareData fail to Send request, err: %{public}d.", error);
4267 return INNER_ERR;
4268 }
4269 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::AcquireShareData end.");
4270 return reply.ReadInt32();
4271 }
4272
ShareDataDone(const sptr<IRemoteObject> & token,const int32_t & resultCode,const int32_t & uniqueId,WantParams & wantParam)4273 int32_t AbilityManagerProxy::ShareDataDone(
4274 const sptr<IRemoteObject> &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)
4275 {
4276 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::ShareDataDone start.");
4277 MessageParcel data;
4278 MessageParcel reply;
4279 MessageOption option(MessageOption::TF_ASYNC);
4280
4281 if (!WriteInterfaceToken(data)) {
4282 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4283 return INNER_ERR;
4284 }
4285
4286 if (!data.WriteRemoteObject(token)) {
4287 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
4288 return INNER_ERR;
4289 }
4290
4291 if (!data.WriteInt32(resultCode)) {
4292 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
4293 return INNER_ERR;
4294 }
4295
4296 if (!data.WriteInt32(uniqueId)) {
4297 TAG_LOGE(AAFwkTag::ABILITYMGR, "uniqueId write failed.");
4298 return INNER_ERR;
4299 }
4300
4301 if (!data.WriteParcelable(&wantParam)) {
4302 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParam write failed.");
4303 return INNER_ERR;
4304 }
4305
4306 int32_t error = SendRequest(AbilityManagerInterfaceCode::SHARE_DATA_DONE, data, reply, option);
4307 if (error != NO_ERROR) {
4308 TAG_LOGE(AAFwkTag::ABILITYMGR, "ShareDataDone fail to SendRequest, err: %{public}d.", error);
4309 return error;
4310 }
4311 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::ShareDataDone end.");
4312 return reply.ReadInt32();
4313 }
4314
ForceExitApp(const int32_t pid,const ExitReason & exitReason)4315 int32_t AbilityManagerProxy::ForceExitApp(const int32_t pid, const ExitReason &exitReason)
4316 {
4317 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4318 MessageParcel data;
4319 MessageParcel reply;
4320 MessageOption option(MessageOption::TF_ASYNC);
4321
4322 if (!WriteInterfaceToken(data)) {
4323 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4324 return INNER_ERR;
4325 }
4326 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, pid);
4327 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4328
4329 int32_t error = SendRequest(AbilityManagerInterfaceCode::FORCE_EXIT_APP, data, reply, option);
4330 if (error != NO_ERROR) {
4331 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to SendRequest, err: %{public}d.", error);
4332 return error;
4333 }
4334
4335 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4336 return reply.ReadInt32();
4337 }
4338
RecordAppExitReason(const ExitReason & exitReason)4339 int32_t AbilityManagerProxy::RecordAppExitReason(const ExitReason &exitReason)
4340 {
4341 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4342 MessageParcel data;
4343 MessageParcel reply;
4344 MessageOption option;
4345
4346 if (!WriteInterfaceToken(data)) {
4347 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4348 return INNER_ERR;
4349 }
4350 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4351
4352 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON, data, reply, option);
4353 if (error != NO_ERROR) {
4354 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to SendRequest, err: %{public}d.", error);
4355 return error;
4356 }
4357
4358 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4359 return reply.ReadInt32();
4360 }
4361
RecordProcessExitReason(const int32_t pid,const ExitReason & exitReason)4362 int32_t AbilityManagerProxy::RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason)
4363 {
4364 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4365 MessageParcel data;
4366 MessageParcel reply;
4367 MessageOption option;
4368
4369 if (!WriteInterfaceToken(data)) {
4370 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4371 return INNER_ERR;
4372 }
4373 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, pid);
4374 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4375
4376 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_PROCESS_EXIT_REASON, data, reply, option);
4377 if (error != NO_ERROR) {
4378 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to SendRequest, err: %{public}d.", error);
4379 return error;
4380 }
4381
4382 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4383 return reply.ReadInt32();
4384 }
4385
SetRootSceneSession(const sptr<IRemoteObject> & rootSceneSession)4386 void AbilityManagerProxy::SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession)
4387 {
4388 MessageParcel data;
4389 if (!WriteInterfaceToken(data)) {
4390 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed.");
4391 return;
4392 }
4393 if (!data.WriteRemoteObject(rootSceneSession)) {
4394 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteRemoteObject failed.");
4395 return;
4396 }
4397
4398 MessageParcel reply;
4399 MessageOption option(MessageOption::TF_ASYNC);
4400 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ROOT_SCENE_SESSION, data, reply, option);
4401 if (error != NO_ERROR) {
4402 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4403 }
4404 }
4405
CallUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool & isColdStart)4406 void AbilityManagerProxy::CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isColdStart)
4407 {
4408 MessageParcel data;
4409 if (!WriteInterfaceToken(data)) {
4410 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed.");
4411 return;
4412 }
4413 if (sessionInfo) {
4414 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
4415 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
4416 return;
4417 }
4418 } else {
4419 if (!data.WriteBool(false)) {
4420 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
4421 return;
4422 }
4423 }
4424
4425 MessageParcel reply;
4426 MessageOption option;
4427 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_ABILITY_BY_SCB, data, reply, option);
4428 if (error != NO_ERROR) {
4429 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4430 return;
4431 }
4432 isColdStart = reply.ReadBool();
4433 }
4434
StartSpecifiedAbilityBySCB(const Want & want)4435 void AbilityManagerProxy::StartSpecifiedAbilityBySCB(const Want &want)
4436 {
4437 MessageParcel data;
4438 if (!WriteInterfaceToken(data)) {
4439 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed.");
4440 return;
4441 }
4442
4443 if (!data.WriteParcelable(&want)) {
4444 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
4445 return;
4446 }
4447
4448 MessageParcel reply;
4449 MessageOption option(MessageOption::TF_ASYNC);
4450 auto error = SendRequest(AbilityManagerInterfaceCode::START_SPECIFIED_ABILITY_BY_SCB, data, reply, option);
4451 if (error != NO_ERROR) {
4452 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4453 }
4454 }
4455
NotifySaveAsResult(const Want & want,int resultCode,int requestCode)4456 int32_t AbilityManagerProxy::NotifySaveAsResult(const Want &want, int resultCode, int requestCode)
4457 {
4458 MessageParcel data;
4459 if (!WriteInterfaceToken(data)) {
4460 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed.");
4461 return INNER_ERR;
4462 }
4463 if (!data.WriteParcelable(&want)) {
4464 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteWantObject failed.");
4465 return INNER_ERR;
4466 }
4467
4468 if (!data.WriteInt32(resultCode)) {
4469 TAG_LOGE(AAFwkTag::ABILITYMGR, "resultCode write failed.");
4470 return INNER_ERR;
4471 }
4472
4473 if (!data.WriteInt32(requestCode)) {
4474 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
4475 return INNER_ERR;
4476 }
4477
4478 MessageParcel reply;
4479 MessageOption option;
4480 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_SAVE_AS_RESULT, data, reply, option);
4481 if (error != NO_ERROR) {
4482 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4483 }
4484
4485 return reply.ReadInt32();
4486 }
4487
SetSessionManagerService(const sptr<IRemoteObject> & sessionManagerService)4488 int32_t AbilityManagerProxy::SetSessionManagerService(const sptr<IRemoteObject> &sessionManagerService)
4489 {
4490 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::SetSessionManagerService start.");
4491 MessageParcel data;
4492 MessageParcel reply;
4493 MessageOption option;
4494
4495 if (!WriteInterfaceToken(data)) {
4496 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed.");
4497 return INNER_ERR;
4498 }
4499
4500 if (!data.WriteRemoteObject(sessionManagerService)) {
4501 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write failed.");
4502 return INNER_ERR;
4503 }
4504
4505 int32_t error = SendRequest(AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE, data, reply, option);
4506 if (error != NO_ERROR) {
4507 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4508 return error;
4509 }
4510 TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::SetSessionManagerService end.");
4511 return reply.ReadInt32();
4512 }
4513
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<IAbilityManagerCollaborator> & impl)4514 int32_t AbilityManagerProxy::RegisterIAbilityManagerCollaborator(
4515 int32_t type, const sptr<IAbilityManagerCollaborator> &impl)
4516 {
4517 if (!impl) {
4518 TAG_LOGE(AAFwkTag::ABILITYMGR, "impl is nullptr");
4519 return ERR_INVALID_VALUE;
4520 }
4521 MessageParcel data;
4522 MessageParcel reply;
4523 MessageOption option;
4524
4525 if (!WriteInterfaceToken(data)) {
4526 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4527 return INNER_ERR;
4528 }
4529 if (!data.WriteInt32(type)) {
4530 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write failed.");
4531 return INNER_ERR;
4532 }
4533 if (!data.WriteRemoteObject(impl->AsObject())) {
4534 TAG_LOGE(AAFwkTag::ABILITYMGR, "impl write failed.");
4535 return INNER_ERR;
4536 }
4537
4538 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_COLLABORATOR, data, reply, option);
4539 if (ret != NO_ERROR) {
4540 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret);
4541 return ret;
4542 }
4543 return reply.ReadInt32();
4544 }
4545
UnregisterIAbilityManagerCollaborator(int32_t type)4546 int32_t AbilityManagerProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
4547 {
4548 MessageParcel data;
4549 MessageParcel reply;
4550 MessageOption option;
4551
4552 if (!WriteInterfaceToken(data)) {
4553 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4554 return INNER_ERR;
4555 }
4556 if (!data.WriteInt32(type)) {
4557 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write failed.");
4558 return INNER_ERR;
4559 }
4560
4561 auto ret = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR, data, reply, option);
4562 if (ret != NO_ERROR) {
4563 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret);
4564 return ret;
4565 }
4566 return reply.ReadInt32();
4567 }
4568
RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate)4569 int32_t AbilityManagerProxy::RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate)
4570 {
4571 MessageParcel data;
4572 MessageParcel reply;
4573 MessageOption option;
4574
4575 if (delegate == nullptr) {
4576 TAG_LOGE(AAFwkTag::ABILITYMGR, "delegate is nullptr.");
4577 return ERR_NULL_OBJECT;
4578 }
4579
4580 if (!WriteInterfaceToken(data)) {
4581 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4582 return ERR_NATIVE_IPC_PARCEL_FAILED;
4583 }
4584 if (!data.WriteRemoteObject(delegate->AsObject())) {
4585 TAG_LOGE(AAFwkTag::ABILITYMGR, "write delegate failed.");
4586 return ERR_NATIVE_IPC_PARCEL_FAILED;
4587 }
4588
4589 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_STATUS_BAR_DELEGATE, data, reply, option);
4590 if (ret != NO_ERROR) {
4591 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4592 return ret;
4593 }
4594 return reply.ReadInt32();
4595 }
4596
KillProcessWithPrepareTerminate(const std::vector<int32_t> & pids)4597 int32_t AbilityManagerProxy::KillProcessWithPrepareTerminate(const std::vector<int32_t>& pids)
4598 {
4599 MessageParcel data;
4600 MessageParcel reply;
4601 MessageOption option(MessageOption::TF_ASYNC);
4602
4603 if (!WriteInterfaceToken(data)) {
4604 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4605 return ERR_NATIVE_IPC_PARCEL_FAILED;
4606 }
4607 if (!data.WriteUint32(pids.size())) {
4608 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write size failed.");
4609 return ERR_NATIVE_IPC_PARCEL_FAILED;
4610 }
4611 for (const auto &pid : pids) {
4612 if (!data.WriteInt32(pid)) {
4613 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write pid failed.");
4614 return ERR_NATIVE_IPC_PARCEL_FAILED;
4615 }
4616 }
4617
4618 auto ret = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS_WITH_PREPARE_TERMINATE, data, reply, option);
4619 if (ret != NO_ERROR) {
4620 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4621 }
4622 return ret;
4623 }
4624
RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> & callback)4625 int32_t AbilityManagerProxy::RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
4626 {
4627 MessageParcel data;
4628 MessageParcel reply;
4629 MessageOption option;
4630
4631 if (!WriteInterfaceToken(data)) {
4632 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4633 return INNER_ERR;
4634 }
4635 if (!data.WriteRemoteObject(callback)) {
4636 TAG_LOGE(AAFwkTag::ABILITYMGR, "Callback write failed.");
4637 return INNER_ERR;
4638 }
4639
4640 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_AUTO_STARTUP_SYSTEM_CALLBACK, data, reply, option);
4641 if (ret != NO_ERROR) {
4642 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4643 return ret;
4644 }
4645 return reply.ReadInt32();
4646 }
4647
UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> & callback)4648 int32_t AbilityManagerProxy::UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
4649 {
4650 MessageParcel data;
4651 MessageParcel reply;
4652 MessageOption option;
4653
4654 if (!WriteInterfaceToken(data)) {
4655 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4656 return INNER_ERR;
4657 }
4658 if (!data.WriteRemoteObject(callback)) {
4659 TAG_LOGE(AAFwkTag::ABILITYMGR, "Callback write failed.");
4660 return INNER_ERR;
4661 }
4662
4663 auto ret = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_AUTO_STARTUP_SYSTEM_CALLBACK, data, reply, option);
4664 if (ret != NO_ERROR) {
4665 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4666 return ret;
4667 }
4668 return reply.ReadInt32();
4669 }
4670
SetApplicationAutoStartup(const AutoStartupInfo & info)4671 int32_t AbilityManagerProxy::SetApplicationAutoStartup(const AutoStartupInfo &info)
4672 {
4673 MessageParcel data;
4674 MessageParcel reply;
4675 MessageOption option;
4676
4677 if (!WriteInterfaceToken(data)) {
4678 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4679 return INNER_ERR;
4680 }
4681 if (!data.WriteParcelable(&info)) {
4682 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write AutoStartupInfo failed.");
4683 return INNER_ERR;
4684 }
4685
4686 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP, data, reply, option);
4687 if (ret != NO_ERROR) {
4688 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4689 return ret;
4690 }
4691 return reply.ReadInt32();
4692 }
4693
CancelApplicationAutoStartup(const AutoStartupInfo & info)4694 int32_t AbilityManagerProxy::CancelApplicationAutoStartup(const AutoStartupInfo &info)
4695 {
4696 MessageParcel data;
4697 MessageParcel reply;
4698 MessageOption option;
4699
4700 if (!WriteInterfaceToken(data)) {
4701 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4702 return INNER_ERR;
4703 }
4704 if (!data.WriteParcelable(&info)) {
4705 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write AutoStartupInfo failed.");
4706 return INNER_ERR;
4707 }
4708
4709 auto ret = SendRequest(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP, data, reply, option);
4710 if (ret != NO_ERROR) {
4711 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4712 return ret;
4713 }
4714 return reply.ReadInt32();
4715 }
4716
QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> & infoList)4717 int32_t AbilityManagerProxy::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
4718 {
4719 MessageParcel data;
4720 MessageParcel reply;
4721 MessageOption option;
4722
4723 if (!WriteInterfaceToken(data)) {
4724 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4725 return INNER_ERR;
4726 }
4727
4728 auto ret = SendRequest(AbilityManagerInterfaceCode::QUERY_ALL_AUTO_STARTUP_APPLICATION, data, reply, option);
4729 if (ret != NO_ERROR) {
4730 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
4731 return ret;
4732 }
4733
4734 auto resultCode = reply.ReadInt32();
4735 if (resultCode != ERR_OK) {
4736 TAG_LOGE(AAFwkTag::ABILITYMGR, "Reply error: %{public}d.", resultCode);
4737 return resultCode;
4738 }
4739
4740 auto infoSize = reply.ReadInt32();
4741 for (auto i = 0; i < infoSize && i < MAX_AUTO_STARTUP_COUNT; ++i) {
4742 std::unique_ptr<AutoStartupInfo> info(reply.ReadParcelable<AutoStartupInfo>());
4743 if (!info) {
4744 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read Parcelable result infos failed.");
4745 return INNER_ERR;
4746 }
4747 infoList.emplace_back(*info);
4748 }
4749 return ERR_OK;
4750 }
4751
PrepareTerminateAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool & isPrepareTerminate)4752 int AbilityManagerProxy::PrepareTerminateAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isPrepareTerminate)
4753 {
4754 MessageParcel data;
4755 MessageParcel reply;
4756 MessageOption option;
4757
4758 if (!WriteInterfaceToken(data)) {
4759 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4760 return INNER_ERR;
4761 }
4762 if (sessionInfo) {
4763 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
4764 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write failed.");
4765 return INNER_ERR;
4766 }
4767 } else {
4768 if (!data.WriteBool(false)) {
4769 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
4770 return INNER_ERR;
4771 }
4772 }
4773
4774 auto error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB,
4775 data, reply, option);
4776 if (error != NO_ERROR) {
4777 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4778 return error;
4779 }
4780
4781 isPrepareTerminate = reply.ReadBool();
4782 return NO_ERROR;
4783 }
4784
RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)4785 int32_t AbilityManagerProxy::RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)
4786 {
4787 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4788 MessageParcel data;
4789 if (!WriteInterfaceToken(data)) {
4790 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4791 return INNER_ERR;
4792 }
4793
4794 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
4795 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write listener failed.");
4796 return INNER_ERR;
4797 }
4798
4799 MessageParcel reply;
4800 MessageOption option(MessageOption::TF_SYNC);
4801 int32_t error = SendRequest(AbilityManagerInterfaceCode::REGISTER_APP_DEBUG_LISTENER, data, reply, option);
4802 if (error != NO_ERROR) {
4803 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, err: %{public}d", error);
4804 return error;
4805 }
4806 return reply.ReadInt32();
4807 }
4808
UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)4809 int32_t AbilityManagerProxy::UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)
4810 {
4811 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4812 MessageParcel data;
4813 if (!WriteInterfaceToken(data)) {
4814 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4815 return INNER_ERR;
4816 }
4817
4818 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
4819 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write listener failed.");
4820 return INNER_ERR;
4821 }
4822
4823 MessageParcel reply;
4824 MessageOption option(MessageOption::TF_SYNC);
4825 int32_t error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_APP_DEBUG_LISTENER, data, reply, option);
4826 if (error != NO_ERROR) {
4827 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, err: %{public}d", error);
4828 return error;
4829 }
4830 return reply.ReadInt32();
4831 }
4832
AttachAppDebug(const std::string & bundleName)4833 int32_t AbilityManagerProxy::AttachAppDebug(const std::string &bundleName)
4834 {
4835 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4836 MessageParcel data;
4837 if (!WriteInterfaceToken(data)) {
4838 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4839 return INNER_ERR;
4840 }
4841
4842 if (!data.WriteString(bundleName)) {
4843 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write failed.");
4844 return INNER_ERR;
4845 }
4846
4847 MessageParcel reply;
4848 MessageOption option;
4849 int32_t error = SendRequest(AbilityManagerInterfaceCode::ATTACH_APP_DEBUG, data, reply, option);
4850 if (error != NO_ERROR) {
4851 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, err: %{public}d", error);
4852 return error;
4853 }
4854 return reply.ReadInt32();
4855 }
4856
DetachAppDebug(const std::string & bundleName)4857 int32_t AbilityManagerProxy::DetachAppDebug(const std::string &bundleName)
4858 {
4859 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4860 MessageParcel data;
4861 if (!WriteInterfaceToken(data)) {
4862 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4863 return INNER_ERR;
4864 }
4865
4866 if (!data.WriteString(bundleName)) {
4867 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write bundleName failed.");
4868 return INNER_ERR;
4869 }
4870
4871 MessageParcel reply;
4872 MessageOption option;
4873 int32_t error = SendRequest(AbilityManagerInterfaceCode::DETACH_APP_DEBUG, data, reply, option);
4874 if (error != NO_ERROR) {
4875 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, err: %{public}d", error);
4876 return error;
4877 }
4878 return reply.ReadInt32();
4879 }
4880
ExecuteIntent(uint64_t key,const sptr<IRemoteObject> & callerToken,const InsightIntentExecuteParam & param)4881 int32_t AbilityManagerProxy::ExecuteIntent(uint64_t key, const sptr<IRemoteObject> &callerToken,
4882 const InsightIntentExecuteParam ¶m)
4883 {
4884 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4885 MessageParcel data;
4886 MessageParcel reply;
4887 MessageOption option;
4888 if (!WriteInterfaceToken(data)) {
4889 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4890 return INNER_ERR;
4891 }
4892
4893 if (!data.WriteUint64(key)) {
4894 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write key failed.");
4895 return INNER_ERR;
4896 }
4897
4898 if (!data.WriteRemoteObject(callerToken)) {
4899 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write callerToken.");
4900 return INNER_ERR;
4901 }
4902
4903 if (!data.WriteParcelable(¶m)) {
4904 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write param failed.");
4905 return INNER_ERR;
4906 }
4907
4908 int32_t error = SendRequest(AbilityManagerInterfaceCode::EXECUTE_INTENT, data, reply, option);
4909 if (error != NO_ERROR) {
4910 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, err: %{public}d", error);
4911 return error;
4912 }
4913
4914 return reply.ReadInt32();
4915 }
4916
IsAbilityControllerStart(const Want & want)4917 bool AbilityManagerProxy::IsAbilityControllerStart(const Want &want)
4918 {
4919 MessageParcel data;
4920 MessageParcel reply;
4921 MessageOption option;
4922
4923 if (!WriteInterfaceToken(data)) {
4924 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
4925 return true;
4926 }
4927 if (!data.WriteParcelable(&want)) {
4928 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteWantObject failed.");
4929 return true;
4930 }
4931
4932 auto error = SendRequest(AbilityManagerInterfaceCode::IS_ABILITY_CONTROLLER_START,
4933 data, reply, option);
4934 if (error != NO_ERROR) {
4935 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
4936 return true;
4937 }
4938 return reply.ReadBool();
4939 }
4940
ExecuteInsightIntentDone(const sptr<IRemoteObject> & token,uint64_t intentId,const InsightIntentExecuteResult & result)4941 int32_t AbilityManagerProxy::ExecuteInsightIntentDone(const sptr<IRemoteObject> &token, uint64_t intentId,
4942 const InsightIntentExecuteResult &result)
4943 {
4944 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4945 MessageParcel data;
4946 if (!WriteInterfaceToken(data)) {
4947 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write remote object failed.");
4948 return INNER_ERR;
4949 }
4950
4951 if (!data.WriteRemoteObject(token)) {
4952 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed.");
4953 return INNER_ERR;
4954 }
4955
4956 if (!data.WriteInt64(intentId) || !data.WriteParcelable(&result)) {
4957 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write insight intent params failed.");
4958 return INNER_ERR;
4959 }
4960
4961 MessageParcel reply;
4962 MessageOption option(MessageOption::TF_ASYNC);
4963 auto ret = SendRequest(AbilityManagerInterfaceCode::EXECUTE_INSIGHT_INTENT_DONE, data, reply, option);
4964 if (ret != NO_ERROR) {
4965 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed with %{public}d", ret);
4966 return ret;
4967 }
4968 return reply.ReadInt32();
4969 }
4970
GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> & list)4971 int32_t AbilityManagerProxy::GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list)
4972 {
4973 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4974 MessageParcel data;
4975 if (!WriteInterfaceToken(data)) {
4976 return ERR_FLATTEN_OBJECT;
4977 }
4978
4979 MessageParcel reply;
4980 MessageOption option;
4981 auto error = SendRequest(AbilityManagerInterfaceCode::GET_FOREGROUND_UI_ABILITIES, data, reply, option);
4982 if (error != NO_ERROR) {
4983 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed, error: %{public}d.", error);
4984 return error;
4985 }
4986
4987 auto errorCode = GetParcelableInfos<AppExecFwk::AbilityStateData>(reply, list);
4988 if (errorCode != NO_ERROR) {
4989 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get foreground ui abilities error: %{public}d.", errorCode);
4990 return errorCode;
4991 }
4992 return reply.ReadInt32();
4993 }
4994
OpenFile(const Uri & uri,uint32_t flag)4995 int32_t AbilityManagerProxy::OpenFile(const Uri& uri, uint32_t flag)
4996 {
4997 MessageParcel data;
4998 MessageParcel reply;
4999 MessageOption option;
5000 if (!WriteInterfaceToken(data)) {
5001 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5002 return false;
5003 }
5004 if (!data.WriteParcelable(&uri)) {
5005 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write uri failed.");
5006 return false;
5007 }
5008 if (!data.WriteInt32(flag)) {
5009 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag failed.");
5010 return false;
5011 }
5012
5013 auto ret = SendRequest(AbilityManagerInterfaceCode::OPEN_FILE, data, reply, option);
5014 if (ret != NO_ERROR) {
5015 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed with %{public}d", ret);
5016 return ret;
5017 }
5018 return reply.ReadFileDescriptor();
5019 }
5020
RequestAssertFaultDialog(const sptr<IRemoteObject> & callback,const AAFwk::WantParams & wantParams)5021 int32_t AbilityManagerProxy::RequestAssertFaultDialog(
5022 const sptr<IRemoteObject> &callback, const AAFwk::WantParams &wantParams)
5023 {
5024 TAG_LOGD(AAFwkTag::ABILITYMGR, "Request to display assert fault dialog.");
5025 if (callback == nullptr) {
5026 TAG_LOGE(AAFwkTag::ABILITYMGR, "Params callback is nullptr.");
5027 return INNER_ERR;
5028 }
5029
5030 MessageParcel data;
5031 if (!WriteInterfaceToken(data)) {
5032 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5033 return INNER_ERR;
5034 }
5035
5036 if (!data.WriteRemoteObject(callback)) {
5037 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write callback failed.");
5038 return INNER_ERR;
5039 }
5040
5041 if (!data.WriteParcelable(&wantParams)) {
5042 TAG_LOGE(AAFwkTag::ABILITYMGR, "Want params write failed.");
5043 return INNER_ERR;
5044 }
5045
5046 MessageParcel reply;
5047 MessageOption option;
5048 auto ret = SendRequest(AbilityManagerInterfaceCode::REQUEST_ASSERT_FAULT_DIALOG, data, reply, option);
5049 if (ret != NO_ERROR) {
5050 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed with %{public}d", ret);
5051 return ret;
5052 }
5053
5054 return reply.ReadInt32();
5055 }
5056
NotifyDebugAssertResult(uint64_t assertFaultSessionId,AAFwk::UserStatus userStatus)5057 int32_t AbilityManagerProxy::NotifyDebugAssertResult(uint64_t assertFaultSessionId, AAFwk::UserStatus userStatus)
5058 {
5059 TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify user action result to assert fault callback.");
5060 MessageParcel data;
5061 if (!WriteInterfaceToken(data)) {
5062 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5063 return INNER_ERR;
5064 }
5065
5066 if (!data.WriteUint64(assertFaultSessionId)) {
5067 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write assertFaultSessionId failed.");
5068 return INNER_ERR;
5069 }
5070
5071 if (!data.WriteInt32(static_cast<int32_t>(userStatus))) {
5072 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userStatus failed.");
5073 return INNER_ERR;
5074 }
5075
5076 MessageParcel reply;
5077 MessageOption option;
5078 auto ret = SendRequest(AbilityManagerInterfaceCode::NOTIFY_DEBUG_ASSERT_RESULT, data, reply, option);
5079 if (ret != NO_ERROR) {
5080 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed with %{public}d", ret);
5081 return ret;
5082 }
5083
5084 return reply.ReadInt32();
5085 }
5086
UpdateSessionInfoBySCB(std::list<SessionInfo> & sessionInfos,int32_t userId,std::vector<int32_t> & sessionIds)5087 int32_t AbilityManagerProxy::UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, int32_t userId,
5088 std::vector<int32_t> &sessionIds)
5089 {
5090 MessageParcel data;
5091 if (!WriteInterfaceToken(data)) {
5092 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5093 return ERR_NATIVE_IPC_PARCEL_FAILED;
5094 }
5095 auto size = static_cast<int32_t>(sessionInfos.size());
5096 int32_t threshold = 512;
5097 if (size > threshold) {
5098 TAG_LOGE(AAFwkTag::ABILITYMGR, "Size of vector too large.");
5099 return ERR_NATIVE_IPC_PARCEL_FAILED;
5100 }
5101 if (!data.WriteInt32(size)) {
5102 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write size failed.");
5103 return ERR_NATIVE_IPC_PARCEL_FAILED;
5104 }
5105 for (const auto &info : sessionInfos) {
5106 if (!data.WriteParcelable(&info)) {
5107 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write sessionInfo failed.");
5108 return ERR_NATIVE_IPC_PARCEL_FAILED;
5109 }
5110 }
5111 if (!data.WriteInt32(userId)) {
5112 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userId failed.");
5113 return ERR_NATIVE_IPC_PARCEL_FAILED;
5114 }
5115
5116 MessageParcel reply;
5117 MessageOption option;
5118 auto ret = SendRequest(AbilityManagerInterfaceCode::UPDATE_SESSION_INFO, data, reply, option);
5119 if (ret != NO_ERROR) {
5120 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request failed with %{public}d", ret);
5121 return ret;
5122 }
5123 size = reply.ReadInt32();
5124 if (size > threshold) {
5125 TAG_LOGE(AAFwkTag::ABILITYMGR, "Size of vector too large.");
5126 return ERR_NATIVE_IPC_PARCEL_FAILED;
5127 }
5128 sessionIds.clear();
5129 for (auto index = 0; index < size; index++) {
5130 sessionIds.emplace_back(reply.ReadInt32());
5131 }
5132 return NO_ERROR;
5133 }
5134
SendRequest(AbilityManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)5135 ErrCode AbilityManagerProxy::SendRequest(AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply,
5136 MessageOption& option)
5137 {
5138 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
5139 sptr<IRemoteObject> remote = Remote();
5140 if (remote == nullptr) {
5141 TAG_LOGE(AAFwkTag::ABILITYMGR, "Remote() is NULL");
5142 return INNER_ERR;
5143 }
5144
5145 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
5146 }
5147
SetApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)5148 int32_t AbilityManagerProxy::SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
5149 {
5150 MessageParcel data;
5151 if (!WriteInterfaceToken(data)) {
5152 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5153 return INNER_ERR;
5154 }
5155 if (!data.WriteParcelable(&info)) {
5156 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write AutoStartupInfo failed.");
5157 return INNER_ERR;
5158 }
5159 if (!data.WriteBool(flag)) {
5160 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag failed.");
5161 return INNER_ERR;
5162 }
5163
5164 MessageParcel reply;
5165 MessageOption option;
5166 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP_BY_EDM, data, reply, option);
5167 if (ret != NO_ERROR) {
5168 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
5169 return ret;
5170 }
5171 return reply.ReadInt32();
5172 }
5173
CancelApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)5174 int32_t AbilityManagerProxy::CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
5175 {
5176 MessageParcel data;
5177 if (!WriteInterfaceToken(data)) {
5178 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5179 return INNER_ERR;
5180 }
5181 if (!data.WriteParcelable(&info)) {
5182 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write AutoStartupInfo failed.");
5183 return INNER_ERR;
5184 }
5185 if (!data.WriteBool(flag)) {
5186 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag failed.");
5187 return INNER_ERR;
5188 }
5189
5190 MessageParcel reply;
5191 MessageOption option;
5192 auto ret = SendRequest(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP_BY_EDM, data, reply, option);
5193 if (ret != NO_ERROR) {
5194 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
5195 return ret;
5196 }
5197 return reply.ReadInt32();
5198 }
5199
RestartApp(const AAFwk::Want & want,bool isAppRecovery)5200 int32_t AbilityManagerProxy::RestartApp(const AAFwk::Want &want, bool isAppRecovery)
5201 {
5202 MessageParcel data;
5203 MessageParcel reply;
5204 MessageOption option;
5205 if (!WriteInterfaceToken(data)) {
5206 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5207 return IPC_PROXY_ERR;
5208 }
5209 if (!data.WriteParcelable(&want)) {
5210 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
5211 return IPC_PROXY_ERR;
5212 }
5213 if (!data.WriteBool(isAppRecovery)) {
5214 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write isAppRecovery failed.");
5215 return IPC_PROXY_ERR;
5216 }
5217 auto ret = SendRequest(AbilityManagerInterfaceCode::RESTART_APP, data, reply, option);
5218 if (ret != NO_ERROR) {
5219 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request is failed, error code: %{public}d", ret);
5220 return ret;
5221 }
5222 return reply.ReadInt32();
5223 }
5224
GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token,UIExtensionHostInfo & hostInfo,int32_t userId)5225 int32_t AbilityManagerProxy::GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token,
5226 UIExtensionHostInfo &hostInfo, int32_t userId)
5227 {
5228 if (token == nullptr) {
5229 TAG_LOGE(AAFwkTag::ABILITYMGR, "Input param invalid.");
5230 return ERR_INVALID_VALUE;
5231 }
5232
5233 MessageParcel data;
5234 if (!WriteInterfaceToken(data)) {
5235 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write remote object failed.");
5236 return INNER_ERR;
5237 }
5238
5239 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
5240 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag and token failed.");
5241 return INNER_ERR;
5242 }
5243
5244 if (!data.WriteInt32(userId)) {
5245 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userId failed.");
5246 return INNER_ERR;
5247 }
5248
5249 MessageParcel reply;
5250 MessageOption option;
5251 auto error = SendRequest(AbilityManagerInterfaceCode::GET_UI_EXTENSION_ROOT_HOST_INFO, data, reply, option);
5252 if (error != NO_ERROR) {
5253 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5254 return error;
5255 }
5256
5257 std::unique_ptr<UIExtensionHostInfo> info(reply.ReadParcelable<UIExtensionHostInfo>());
5258 if (info == nullptr) {
5259 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get host info failed.");
5260 return INNER_ERR;
5261 }
5262 hostInfo = *info;
5263 return reply.ReadInt32();
5264 }
5265
GetUIExtensionSessionInfo(const sptr<IRemoteObject> token,UIExtensionSessionInfo & uiExtensionSessionInfo,int32_t userId)5266 int32_t AbilityManagerProxy::GetUIExtensionSessionInfo(const sptr<IRemoteObject> token,
5267 UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId)
5268 {
5269 if (token == nullptr) {
5270 TAG_LOGE(AAFwkTag::ABILITYMGR, "Input param invalid.");
5271 return ERR_INVALID_VALUE;
5272 }
5273
5274 MessageParcel data;
5275 if (!WriteInterfaceToken(data)) {
5276 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write remote object failed.");
5277 return INNER_ERR;
5278 }
5279
5280 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
5281 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag and token failed.");
5282 return INNER_ERR;
5283 }
5284
5285 if (!data.WriteInt32(userId)) {
5286 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userId failed.");
5287 return INNER_ERR;
5288 }
5289
5290 MessageParcel reply;
5291 MessageOption option;
5292 auto error = SendRequest(AbilityManagerInterfaceCode::GET_UI_EXTENSION_SESSION_INFO, data, reply, option);
5293 if (error != NO_ERROR) {
5294 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5295 return error;
5296 }
5297
5298 std::unique_ptr<UIExtensionSessionInfo> info(reply.ReadParcelable<UIExtensionSessionInfo>());
5299 if (info == nullptr) {
5300 TAG_LOGE(AAFwkTag::ABILITYMGR, "Get host info failed.");
5301 return INNER_ERR;
5302 }
5303 uiExtensionSessionInfo = *info;
5304 return reply.ReadInt32();
5305 }
5306
OpenAtomicService(Want & want,const StartOptions & options,sptr<IRemoteObject> callerToken,int32_t requestCode,int32_t userId)5307 int32_t AbilityManagerProxy::OpenAtomicService(Want& want, const StartOptions &options,
5308 sptr<IRemoteObject> callerToken, int32_t requestCode, int32_t userId)
5309 {
5310 MessageParcel data;
5311 if (!WriteInterfaceToken(data)) {
5312 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5313 return INNER_ERR;
5314 }
5315 if (!data.WriteParcelable(&want)) {
5316 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write want failed.");
5317 return INNER_ERR;
5318 }
5319 if (!data.WriteParcelable(&options)) {
5320 TAG_LOGE(AAFwkTag::ABILITYMGR, "options write failed.");
5321 return INNER_ERR;
5322 }
5323 if (callerToken != nullptr) {
5324 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
5325 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write failed.");
5326 return INNER_ERR;
5327 }
5328 } else {
5329 if (!data.WriteBool(false)) {
5330 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write failed.");
5331 return INNER_ERR;
5332 }
5333 }
5334 if (!data.WriteInt32(requestCode)) {
5335 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
5336 return INNER_ERR;
5337 }
5338 if (!data.WriteInt32(userId)) {
5339 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
5340 return INNER_ERR;
5341 }
5342
5343 MessageParcel reply;
5344 MessageOption option;
5345 auto ret = SendRequest(AbilityManagerInterfaceCode::OPEN_ATOMIC_SERVICE, data, reply, option);
5346 if (ret != NO_ERROR) {
5347 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
5348 return ret;
5349 }
5350 return reply.ReadInt32();
5351 }
5352
SetResidentProcessEnabled(const std::string & bundleName,bool enable)5353 int32_t AbilityManagerProxy::SetResidentProcessEnabled(const std::string &bundleName, bool enable)
5354 {
5355 MessageParcel data;
5356 if (!WriteInterfaceToken(data)) {
5357 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5358 return INNER_ERR;
5359 }
5360 if (!data.WriteString(bundleName)) {
5361 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write bundl name failed.");
5362 return INNER_ERR;
5363 }
5364 if (!data.WriteBool(enable)) {
5365 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write enable status failed.");
5366 return INNER_ERR;
5367 }
5368 MessageParcel reply;
5369 MessageOption option;
5370 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_RESIDENT_PROCESS_ENABLE, data, reply, option);
5371 if (ret != NO_ERROR) {
5372 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret);
5373 return ret;
5374 }
5375
5376 return reply.ReadInt32();
5377 }
5378
IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken,const std::string & appId)5379 bool AbilityManagerProxy::IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId)
5380 {
5381 if (callerToken == nullptr) {
5382 TAG_LOGE(AAFwkTag::ABILITYMGR, "Input param invalid.");
5383 return false;
5384 }
5385
5386 MessageParcel data;
5387 if (!WriteInterfaceToken (data)) {
5388 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write remote object failed.");
5389 return false;
5390 }
5391
5392 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
5393 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag and callerToken failed.");
5394 return false;
5395 }
5396
5397 if (!data.WriteString(appId)) {
5398 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userId failed.");
5399 return false;
5400 }
5401
5402 MessageParcel reply;
5403 MessageOption option;
5404 auto error = SendRequest(AbilityManagerInterfaceCode::IS_EMBEDDED_OPEN_ALLOWED, data, reply, option);
5405 if (error != NO_ERROR) {
5406 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5407 return false;
5408 }
5409 return reply.ReadBool();
5410 }
5411
StartShortcut(const Want & want,const StartOptions & startOptions)5412 int32_t AbilityManagerProxy::StartShortcut(const Want &want, const StartOptions &startOptions)
5413 {
5414 MessageParcel data;
5415 MessageParcel reply;
5416 MessageOption option;
5417 if (!WriteInterfaceToken(data)) {
5418 return INNER_ERR;
5419 }
5420 if (!data.WriteParcelable(&want)) {
5421 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
5422 return INNER_ERR;
5423 }
5424 if (!data.WriteParcelable(&startOptions)) {
5425 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write failed.");
5426 return INNER_ERR;
5427 }
5428
5429 auto error = SendRequest(AbilityManagerInterfaceCode::START_SHORTCUT, data, reply, option);
5430 if (error != NO_ERROR) {
5431 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5432 return error;
5433 }
5434 return reply.ReadInt32();
5435 }
5436
GetAbilityStateByPersistentId(int32_t persistentId,bool & state)5437 int32_t AbilityManagerProxy::GetAbilityStateByPersistentId(int32_t persistentId, bool &state)
5438 {
5439 MessageParcel data;
5440 MessageParcel reply;
5441 MessageOption option;
5442 if (!WriteInterfaceToken(data)) {
5443 return IPC_PROXY_ERR;
5444 }
5445 if (!data.WriteInt32(persistentId)) {
5446 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
5447 return IPC_PROXY_ERR;
5448 }
5449 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_STATE_BY_PERSISTENT_ID, data, reply, option);
5450 if (error != NO_ERROR) {
5451 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5452 return error;
5453 }
5454 state = reply.ReadBool();
5455 return NO_ERROR;
5456 }
5457
5458
TransferAbilityResultForExtension(const sptr<IRemoteObject> & callerToken,int32_t resultCode,const Want & want)5459 int32_t AbilityManagerProxy::TransferAbilityResultForExtension(const sptr<IRemoteObject> &callerToken,
5460 int32_t resultCode, const Want &want)
5461 {
5462 if (callerToken == nullptr) {
5463 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken is nullptr");
5464 return INNER_ERR;
5465 }
5466 MessageParcel data;
5467 MessageParcel reply;
5468 MessageOption option;
5469 if (!WriteInterfaceToken(data)) {
5470 return IPC_PROXY_ERR;
5471 }
5472 if (!data.WriteRemoteObject(callerToken) || !data.WriteInt32(resultCode)) {
5473 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken or resultCode write failed.");
5474 return INNER_ERR;
5475 }
5476 if (!data.WriteParcelable(&want)) {
5477 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
5478 return INNER_ERR;
5479 }
5480 auto error = SendRequest(AbilityManagerInterfaceCode::TRANSFER_ABILITY_RESULT, data, reply, option);
5481 if (error != NO_ERROR) {
5482 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5483 return error;
5484 }
5485 return NO_ERROR;
5486 }
5487
NotifyFrozenProcessByRSS(const std::vector<int32_t> & pidList,int32_t uid)5488 void AbilityManagerProxy::NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid)
5489 {
5490 MessageParcel data;
5491 MessageParcel reply;
5492 MessageOption option(MessageOption::TF_ASYNC);
5493
5494 if (!WriteInterfaceToken(data)) {
5495 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
5496 return;
5497 }
5498 if (!data.WriteInt32Vector(pidList)) {
5499 TAG_LOGE(AAFwkTag::ABILITYMGR, "pid list write failed.");
5500 return;
5501 }
5502 if (!data.WriteInt32(uid)) {
5503 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write failed.");
5504 return;
5505 }
5506
5507 int error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_FROZEN_PROCESS_BY_RSS, data, reply, option);
5508 if (error != NO_ERROR) {
5509 TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerProxy: SendRequest err %{public}d", error);
5510 }
5511 }
5512
CleanUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo)5513 int AbilityManagerProxy::CleanUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo)
5514 {
5515 int error;
5516 MessageParcel data;
5517 MessageParcel reply;
5518 MessageOption option;
5519 if (!WriteInterfaceToken(data)) {
5520 return INNER_ERR;
5521 }
5522
5523 if (sessionInfo) {
5524 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
5525 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag or sessionInfo failed.");
5526 return INNER_ERR;
5527 }
5528 } else {
5529 if (!data.WriteBool(false)) {
5530 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag failed.");
5531 return INNER_ERR;
5532 }
5533 }
5534
5535 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_UI_ABILITY_BY_SCB, data, reply, option);
5536 if (error != NO_ERROR) {
5537 TAG_LOGE(AAFwkTag::ABILITYMGR, "cleanUIAbility failed, Send request error: %{public}d", error);
5538 return error;
5539 }
5540 return reply.ReadInt32();
5541 }
5542
PreStartMission(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const std::string & startTime)5543 int32_t AbilityManagerProxy::PreStartMission(const std::string& bundleName, const std::string& moduleName,
5544 const std::string& abilityName, const std::string& startTime)
5545 {
5546 MessageParcel data;
5547 MessageParcel reply;
5548 MessageOption option;
5549 if (!WriteInterfaceToken(data)) {
5550 return IPC_PROXY_ERR;
5551 }
5552 if (!data.WriteString(bundleName)) {
5553 TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName failed.");
5554 return INNER_ERR;
5555 }
5556 if (!data.WriteString(moduleName)) {
5557 TAG_LOGE(AAFwkTag::ABILITYMGR, "write moduleName failed.");
5558 return INNER_ERR;
5559 }
5560 if (!data.WriteString(abilityName)) {
5561 TAG_LOGE(AAFwkTag::ABILITYMGR, "write abilityName failed.");
5562 return INNER_ERR;
5563 }
5564 if (!data.WriteString(startTime)) {
5565 TAG_LOGE(AAFwkTag::ABILITYMGR, "write startTime failed.");
5566 return INNER_ERR;
5567 }
5568 auto error = SendRequest(AbilityManagerInterfaceCode::PRE_START_MISSION, data, reply, option);
5569 if (error != NO_ERROR) {
5570 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5571 return error;
5572 }
5573 return reply.ReadInt32();
5574 }
5575
OpenLink(const Want & want,sptr<IRemoteObject> callerToken,int32_t userId,int requestCode)5576 ErrCode AbilityManagerProxy::OpenLink(const Want& want, sptr<IRemoteObject> callerToken,
5577 int32_t userId, int requestCode)
5578 {
5579 if (callerToken == nullptr) {
5580 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken is nullptr");
5581 return INNER_ERR;
5582 }
5583 MessageParcel data;
5584 MessageParcel reply;
5585 MessageOption option;
5586 if (!WriteInterfaceToken(data)) {
5587 return IPC_PROXY_ERR;
5588 }
5589 if (!data.WriteParcelable(&want)) {
5590 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed.");
5591 return INNER_ERR;
5592 }
5593 if (!data.WriteRemoteObject(callerToken)) {
5594 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken write failed.");
5595 return INNER_ERR;
5596 }
5597 if (!data.WriteInt32(userId)) {
5598 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed.");
5599 return INNER_ERR;
5600 }
5601 if (!data.WriteInt32(requestCode)) {
5602 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write failed.");
5603 return INNER_ERR;
5604 }
5605 auto error = SendRequest(AbilityManagerInterfaceCode::OPEN_LINK, data, reply, option);
5606 if (error != NO_ERROR) {
5607 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5608 return error;
5609 }
5610 return reply.ReadInt32();
5611 }
5612
TerminateMission(int32_t missionId)5613 int32_t AbilityManagerProxy::TerminateMission(int32_t missionId)
5614 {
5615 MessageParcel data;
5616 MessageParcel reply;
5617 MessageOption option;
5618 if (!WriteInterfaceToken(data)) {
5619 return IPC_PROXY_ERR;
5620 }
5621 if (!data.WriteInt32(missionId)) {
5622 TAG_LOGE(AAFwkTag::ABILITYMGR, "appCloneIndex write failed.");
5623 return INNER_ERR;
5624 }
5625
5626 auto error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_MISSION,
5627 data, reply, option);
5628 if (error != NO_ERROR) {
5629 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
5630 return error;
5631 }
5632
5633 return reply.ReadInt32();
5634 }
5635
UpdateAssociateConfigList(const std::map<std::string,std::list<std::string>> & configs,const std::list<std::string> & exportConfigs,int32_t flag)5636 int32_t AbilityManagerProxy::UpdateAssociateConfigList(const std::map<std::string, std::list<std::string>>& configs,
5637 const std::list<std::string>& exportConfigs, int32_t flag)
5638 {
5639 MessageParcel data;
5640 MessageParcel reply;
5641 MessageOption option;
5642 if (!WriteInterfaceToken(data)) {
5643 return IPC_PROXY_ERR;
5644 }
5645
5646 if (!UpdateAssociateConfigInner(configs, data)) {
5647 return INNER_ERR;
5648 }
5649
5650 int32_t size = static_cast<int32_t>(exportConfigs.size());
5651 if (size > MAX_UPDATE_CONFIG_SIZE) {
5652 TAG_LOGE(AAFwkTag::ABILITYMGR, "export configs size too large");
5653 return INNER_ERR;
5654 }
5655 if (!data.WriteInt32(size)) {
5656 TAG_LOGE(AAFwkTag::ABILITYMGR, "write export configs size fail");
5657 return INNER_ERR;
5658 }
5659 for (const auto& config : exportConfigs) {
5660 if (!data.WriteString(config)) {
5661 TAG_LOGE(AAFwkTag::ABILITYMGR, "write export config item fail");
5662 return INNER_ERR;
5663 }
5664 }
5665 if (!data.WriteInt32(flag)) {
5666 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
5667 return INNER_ERR;
5668 }
5669 auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_ASSOCIATE_CONFIG_LIST, data, reply, option);
5670 if (error != NO_ERROR) {
5671 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
5672 return error;
5673 }
5674 return reply.ReadInt32();
5675 }
5676
UpdateAssociateConfigInner(const std::map<std::string,std::list<std::string>> & configs,MessageParcel & data)5677 bool AbilityManagerProxy::UpdateAssociateConfigInner(const std::map<std::string, std::list<std::string>>& configs,
5678 MessageParcel& data)
5679 {
5680 int32_t size = static_cast<int32_t>(configs.size());
5681 if (size > MAX_UPDATE_CONFIG_SIZE) {
5682 TAG_LOGE(AAFwkTag::ABILITYMGR, "configs size too large");
5683 return false;
5684 }
5685 if (!data.WriteInt32(size)) {
5686 TAG_LOGE(AAFwkTag::ABILITYMGR, "write configs size fail");
5687 return false;
5688 }
5689 for (const auto& config : configs) {
5690 if (!data.WriteString(config.first)) {
5691 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config key fail");
5692 return false;
5693 }
5694 size = static_cast<int32_t>(config.second.size());
5695 if (size > MAX_UPDATE_CONFIG_SIZE) {
5696 TAG_LOGE(AAFwkTag::ABILITYMGR, "config size too large");
5697 return false;
5698 }
5699 if (!data.WriteInt32(size)) {
5700 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item size fail");
5701 return false;
5702 }
5703 for (const auto& item : config.second) {
5704 if (!data.WriteString(item)) {
5705 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item fail");
5706 return false;
5707 }
5708 }
5709 }
5710 return true;
5711 }
5712 } // namespace AAFwk
5713 } // namespace OHOS
5714