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