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