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