• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ability_manager_collaborator_proxy.h"
17 
18 #include "configuration.h"
19 #include "hilog_tag_wrapper.h"
20 #include "ipc_capacity_wrap.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
NotifyStartAbility(const AppExecFwk::AbilityInfo & abilityInfo,int32_t userId,Want & want,uint64_t accessTokenIDEx)24 int32_t AbilityManagerCollaboratorProxy::NotifyStartAbility(
25     const AppExecFwk::AbilityInfo &abilityInfo, int32_t userId, Want &want, uint64_t accessTokenIDEx)
26 {
27     MessageParcel data;
28     MessageParcel reply;
29     MessageOption option(MessageOption::TF_SYNC);
30     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
31 
32     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
33         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
34         return ERR_INVALID_OPERATION;
35     }
36     if (!data.WriteParcelable(&abilityInfo)) {
37         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
38         return ERR_INVALID_OPERATION;
39     }
40     if (!data.WriteInt32(userId)) {
41         TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
42         return ERR_INVALID_OPERATION;
43     }
44     if (!data.WriteParcelable(&want)) {
45         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
46         return ERR_INVALID_OPERATION;
47     }
48     if (!data.WriteUint64(accessTokenIDEx)) {
49         TAG_LOGE(AAFwkTag::ABILITYMGR, "accessTokenIDEx write fail");
50         return ERR_INVALID_OPERATION;
51     }
52     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_START_ABILITY, data, reply, option);
53     if (ret != NO_ERROR) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
55         return ret;
56     }
57     ret = reply.ReadInt32();
58     if (ret != NO_ERROR) {
59         TAG_LOGE(AAFwkTag::ABILITYMGR, "start ability failed");
60         return ERR_INVALID_OPERATION;
61     }
62     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
63     if (!wantInfo) {
64         TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable fail");
65         return ERR_INVALID_OPERATION;
66     }
67     want = *wantInfo;
68     return NO_ERROR;
69 }
70 
NotifyMissionCreated(int32_t missionId,const Want & want)71 int32_t AbilityManagerCollaboratorProxy::NotifyMissionCreated(int32_t missionId, const Want &want)
72 {
73     MessageParcel data;
74     MessageParcel reply;
75     MessageOption option(MessageOption::TF_SYNC);
76     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
77 
78     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
79         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
80         return ERR_INVALID_OPERATION;
81     }
82     if (!data.WriteInt32(missionId)) {
83         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
84         return ERR_INVALID_OPERATION;
85     }
86     if (!data.WriteParcelable(&want)) {
87         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
88         return ERR_INVALID_OPERATION;
89     }
90     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_CREATED, data, reply, option);
91     if (ret != NO_ERROR) {
92         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
93         return ret;
94     }
95     return NO_ERROR;
96 }
97 
NotifyMissionCreated(const sptr<SessionInfo> & sessionInfo)98 int32_t AbilityManagerCollaboratorProxy::NotifyMissionCreated(const sptr<SessionInfo> &sessionInfo)
99 {
100     MessageParcel data;
101     MessageParcel reply;
102     MessageOption option(MessageOption::TF_SYNC);
103 
104     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
105         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
106         return ERR_INVALID_OPERATION;
107     }
108     if (sessionInfo) {
109         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
110         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
111             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
112             return ERR_INVALID_OPERATION;
113         }
114     } else {
115         if (!data.WriteBool(false)) {
116             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
117             return ERR_INVALID_OPERATION;
118         }
119     }
120     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_CREATED_BY_SCB, data, reply, option);
121     if (ret != NO_ERROR) {
122         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
123         return ret;
124     }
125     return NO_ERROR;
126 }
127 
NotifyLoadAbility(const AppExecFwk::AbilityInfo & abilityInfo,int32_t missionId,const Want & want)128 int32_t AbilityManagerCollaboratorProxy::NotifyLoadAbility(
129     const AppExecFwk::AbilityInfo &abilityInfo, int32_t missionId, const Want &want)
130 {
131     MessageParcel data;
132     MessageParcel reply;
133     MessageOption option(MessageOption::TF_SYNC);
134     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
135 
136     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
137         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
138         return ERR_INVALID_OPERATION;
139     }
140     if (!data.WriteParcelable(&abilityInfo)) {
141         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
142         return ERR_INVALID_OPERATION;
143     }
144     if (!data.WriteInt32(missionId)) {
145         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
146         return ERR_INVALID_OPERATION;
147     }
148     if (!data.WriteParcelable(&want)) {
149         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
150         return ERR_INVALID_OPERATION;
151     }
152     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_LOAD_ABILITY, data, reply, option);
153     if (ret != NO_ERROR) {
154         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
155         return ret;
156     }
157     return NO_ERROR;
158 }
159 
NotifyLoadAbility(const AppExecFwk::AbilityInfo & abilityInfo,const sptr<SessionInfo> & sessionInfo)160 int32_t AbilityManagerCollaboratorProxy::NotifyLoadAbility(
161     const AppExecFwk::AbilityInfo &abilityInfo, const sptr<SessionInfo> &sessionInfo)
162 {
163     MessageParcel data;
164     MessageParcel reply;
165     MessageOption option(MessageOption::TF_SYNC);
166 
167     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
168         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
169         return ERR_INVALID_OPERATION;
170     }
171     if (!data.WriteParcelable(&abilityInfo)) {
172         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
173         return ERR_INVALID_OPERATION;
174     }
175     if (sessionInfo) {
176         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
177         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
178             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
179             return ERR_INVALID_OPERATION;
180         }
181     } else {
182         if (!data.WriteBool(false)) {
183             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
184             return ERR_INVALID_OPERATION;
185         }
186     }
187     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_LOAD_ABILITY_BY_SCB, data, reply, option);
188     if (ret != NO_ERROR) {
189         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
190         return ret;
191     }
192     return NO_ERROR;
193 }
194 
NotifyMoveMissionToBackground(int32_t missionId)195 int32_t AbilityManagerCollaboratorProxy::NotifyMoveMissionToBackground(int32_t missionId)
196 {
197     MessageParcel data;
198     MessageParcel reply;
199     MessageOption option(MessageOption::TF_ASYNC);
200 
201     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
202         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
203         return ERR_INVALID_OPERATION;
204     }
205     if (!data.WriteInt32(missionId)) {
206         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
207         return ERR_INVALID_OPERATION;
208     }
209     int32_t ret = SendTransactCmd(
210         IAbilityManagerCollaborator::NOTIFY_MOVE_MISSION_TO_BACKGROUND, data, reply, option);
211     if (ret != NO_ERROR) {
212         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
213         return ret;
214     }
215     return NO_ERROR;
216 }
217 
NotifyPreloadAbility(const std::string & bundleName)218 int32_t AbilityManagerCollaboratorProxy::NotifyPreloadAbility(const std::string &bundleName)
219 {
220     MessageParcel data;
221     MessageParcel reply;
222     MessageOption option(MessageOption::TF_ASYNC);
223 
224     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
225         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
226         return ERR_INVALID_OPERATION;
227     }
228     if (!data.WriteString16(Str8ToStr16(bundleName))) {
229         TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
230         return ERR_INVALID_OPERATION;
231     }
232     auto remote = Remote();
233     if (!remote) {
234         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
235         return ERR_INVALID_OPERATION;
236     }
237     int32_t ret = remote->SendRequest(
238         IAbilityManagerCollaborator::NOTIFY_PRELOAD_ABILITY, data, reply, option);
239     if (ret != NO_ERROR) {
240         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
241         return ret;
242     }
243     return NO_ERROR;
244 }
245 
NotifyMoveMissionToForeground(int32_t missionId)246 int32_t AbilityManagerCollaboratorProxy::NotifyMoveMissionToForeground(int32_t missionId)
247 {
248     MessageParcel data;
249     MessageParcel reply;
250     MessageOption option(MessageOption::TF_ASYNC);
251 
252     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
253         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
254         return ERR_INVALID_OPERATION;
255     }
256     if (!data.WriteInt32(missionId)) {
257         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
258         return ERR_INVALID_OPERATION;
259     }
260     int32_t ret = SendTransactCmd(
261         IAbilityManagerCollaborator::NOTIFY_MOVE_MISSION_TO_FOREGROUND, data, reply, option);
262     if (ret != NO_ERROR) {
263         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
264         return ret;
265     }
266     return NO_ERROR;
267 }
268 
NotifyTerminateMission(int32_t missionId)269 int32_t AbilityManagerCollaboratorProxy::NotifyTerminateMission(int32_t missionId)
270 {
271     MessageParcel data;
272     MessageParcel reply;
273     MessageOption option(MessageOption::TF_ASYNC);
274 
275     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
276         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
277         return ERR_INVALID_OPERATION;
278     }
279     if (!data.WriteInt32(missionId)) {
280         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
281         return ERR_INVALID_OPERATION;
282     }
283     int32_t ret = SendTransactCmd(
284         IAbilityManagerCollaborator::NOTIFY_TERMINATE_MISSION, data, reply, option);
285     if (ret != NO_ERROR) {
286         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
287         return ret;
288     }
289     return NO_ERROR;
290 }
291 
NotifyClearMission(int32_t missionId)292 int32_t AbilityManagerCollaboratorProxy::NotifyClearMission(int32_t missionId)
293 {
294     MessageParcel data;
295     MessageParcel reply;
296     MessageOption option(MessageOption::TF_SYNC);
297 
298     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
299         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
300         return ERR_INVALID_OPERATION;
301     }
302     if (!data.WriteInt32(missionId)) {
303         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
304         return ERR_INVALID_OPERATION;
305     }
306     int32_t ret = SendTransactCmd(
307         IAbilityManagerCollaborator::NOTIFY_CLEAR_MISSION, data, reply, option);
308     if (ret != NO_ERROR) {
309         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
310         return ret;
311     }
312     return NO_ERROR;
313 }
314 
NotifyRemoveShellProcess(int32_t pid,int32_t type,const std::string & reason)315 int32_t AbilityManagerCollaboratorProxy::NotifyRemoveShellProcess(int32_t pid, int32_t type, const std::string &reason)
316 {
317     MessageParcel data;
318     MessageParcel reply;
319     MessageOption option(MessageOption::TF_ASYNC);
320 
321     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
322         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
323         return ERR_INVALID_OPERATION;
324     }
325     if (!data.WriteInt32(pid)) {
326         TAG_LOGE(AAFwkTag::ABILITYMGR, "pid write fail");
327         return ERR_INVALID_OPERATION;
328     }
329     if (!data.WriteInt32(type)) {
330         TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
331         return ERR_INVALID_OPERATION;
332     }
333     if (!data.WriteString16(Str8ToStr16(reason))) {
334         TAG_LOGE(AAFwkTag::ABILITYMGR, "reason write fail");
335         return ERR_INVALID_OPERATION;
336     }
337     int32_t ret = SendTransactCmd(
338         IAbilityManagerCollaborator::NOTIFY_REMOVE_SHELL_PROCESS, data, reply, option);
339     if (ret != NO_ERROR) {
340         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
341         return ret;
342     }
343     return NO_ERROR;
344 }
345 
UpdateMissionInfo(sptr<SessionInfo> & sessionInfo)346 void AbilityManagerCollaboratorProxy::UpdateMissionInfo(sptr<SessionInfo> &sessionInfo)
347 {
348     MessageParcel data;
349     MessageParcel reply;
350     MessageOption option;
351 
352     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
353         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
354         return;
355     }
356 
357     if (sessionInfo) {
358         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
359         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
360             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
361             return;
362         }
363     } else {
364         if (!data.WriteBool(false)) {
365             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
366             return;
367         }
368     }
369 
370     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_MISSION_INFO_BY_SCB, data, reply, option);
371     if (ret != NO_ERROR) {
372         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
373         return;
374     }
375 
376     sessionInfo = reply.ReadParcelable<SessionInfo>();
377     return;
378 }
379 
CheckCallAbilityPermission(const Want & want)380 int32_t AbilityManagerCollaboratorProxy::CheckCallAbilityPermission(const Want &want)
381 {
382     MessageParcel data;
383     MessageParcel reply;
384     MessageOption option;
385     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
386 
387     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
388         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
389         return ERR_INVALID_OPERATION;
390     }
391 
392     if (!data.WriteParcelable(&want)) {
393         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
394         return ERR_INVALID_OPERATION;
395     }
396     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::CHECK_CALL_ABILITY_PERMISSION,
397         data, reply, option);
398     if (ret != NO_ERROR) {
399         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
400         return ret;
401     }
402     return reply.ReadInt32();
403 }
404 
UpdateConfiguration(const AppExecFwk::Configuration & config,int32_t userId)405 bool AbilityManagerCollaboratorProxy::UpdateConfiguration(const AppExecFwk::Configuration &config, int32_t userId)
406 {
407     MessageParcel data;
408     MessageParcel reply;
409     MessageOption option(MessageOption::TF_ASYNC);
410     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
411         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
412         return false;
413     }
414     if (!data.WriteParcelable(&config)) {
415         TAG_LOGE(AAFwkTag::ABILITYMGR, "write config fail");
416         return false;
417     }
418     if (!data.WriteInt32(userId)) {
419         TAG_LOGE(AAFwkTag::ABILITYMGR, "write usr fail");
420         return false;
421     }
422     auto error = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_CONFIGURATION, data, reply, option);
423     if (error != NO_ERROR) {
424         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
425         return true;
426     }
427     return true;
428 }
429 
OpenFile(const Uri & uri,uint32_t flag)430 int32_t AbilityManagerCollaboratorProxy::OpenFile(const Uri& uri, uint32_t flag)
431 {
432     MessageParcel data;
433     MessageParcel reply;
434     MessageOption option;
435     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
436         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
437         return false;
438     }
439     if (!data.WriteParcelable(&uri)) {
440         TAG_LOGE(AAFwkTag::ABILITYMGR, "write uri fail");
441         return false;
442     }
443     if (!data.WriteInt32(flag)) {
444         TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
445         return false;
446     }
447 
448     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::OPEN_FILE, data, reply, option);
449     if (ret != NO_ERROR) {
450         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
451         return -1;
452     }
453     return reply.ReadFileDescriptor();
454 }
455 
NotifyMissionBindPid(int32_t missionId,int32_t pid)456 void AbilityManagerCollaboratorProxy::NotifyMissionBindPid(int32_t missionId, int32_t pid)
457 {
458     MessageParcel data;
459     MessageParcel reply;
460     MessageOption option(MessageOption::TF_ASYNC);
461     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
462         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
463         return;
464     }
465     if (!data.WriteInt32(missionId)) {
466         TAG_LOGE(AAFwkTag::ABILITYMGR, "write missionId fail");
467         return;
468     }
469     if (!data.WriteInt32(pid)) {
470         TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid fail");
471         return;
472     }
473     auto error = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_BIND_PID, data, reply, option);
474     if (error != NO_ERROR) {
475         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
476     }
477 }
478 
CheckStaticCfgPermission(const Want & want,bool isImplicit)479 int32_t AbilityManagerCollaboratorProxy::CheckStaticCfgPermission(const Want &want, bool isImplicit)
480 {
481     MessageParcel data;
482     MessageParcel reply;
483     MessageOption option(MessageOption::TF_SYNC);
484     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
485     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
486         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
487         return ERR_INVALID_OPERATION;
488     }
489     if (!data.WriteParcelable(&want)) {
490         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
491         return ERR_INVALID_OPERATION;
492     }
493     if (!data.WriteBool(isImplicit)) {
494         TAG_LOGE(AAFwkTag::ABILITYMGR, "isImplicit write failed.");
495         return ERR_INVALID_OPERATION;
496     }
497     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::CHECK_STATIC_CFG_PERMISSION,
498         data, reply, option);
499     if (ret != NO_ERROR) {
500         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
501         return ret;
502     }
503     return reply.ReadInt32();
504 }
505 
UpdateCallerIfNeed(Want & want)506 int32_t AbilityManagerCollaboratorProxy::UpdateCallerIfNeed(Want &want)
507 {
508     MessageParcel data;
509     MessageParcel reply;
510     MessageOption option(MessageOption::TF_SYNC);
511     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
512     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
513         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
514         return ERR_INVALID_OPERATION;
515     }
516     if (!data.WriteParcelable(&want)) {
517         TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
518         return ERR_INVALID_OPERATION;
519     }
520     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_CALLER_IF_NEED,
521         data, reply, option);
522     if (ret != NO_ERROR) {
523         TAG_LOGE(AAFwkTag::ABILITYMGR, "update caller error:%{public}d", ret);
524         return ret;
525     }
526     ret = reply.ReadInt32();
527     if (ret != NO_ERROR) {
528         TAG_LOGE(AAFwkTag::ABILITYMGR, "update caller failed:%{public}d", ret);
529         return ERR_INVALID_OPERATION;
530     }
531     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
532     if (!wantInfo) {
533         TAG_LOGE(AAFwkTag::ABILITYMGR, "read want failed");
534         return ERR_INVALID_OPERATION;
535     }
536     want = *wantInfo;
537     return NO_ERROR;
538 }
539 
UpdateTargetIfNeed(Want & want)540 int32_t AbilityManagerCollaboratorProxy::UpdateTargetIfNeed(Want &want)
541 {
542     MessageParcel data;
543     MessageParcel reply;
544     MessageOption option(MessageOption::TF_SYNC);
545     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
546     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
547         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
548         return ERR_INVALID_OPERATION;
549     }
550     if (!data.WriteParcelable(&want)) {
551         TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
552         return ERR_INVALID_OPERATION;
553     }
554     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_TARGET_IF_NEED,
555         data, reply, option);
556     if (ret != NO_ERROR) {
557         TAG_LOGE(AAFwkTag::ABILITYMGR, "update target error:%{public}d", ret);
558         return ret;
559     }
560     ret = reply.ReadInt32();
561     if (ret != NO_ERROR) {
562         TAG_LOGE(AAFwkTag::ABILITYMGR, "update target failed:%{public}d", ret);
563         return ERR_INVALID_OPERATION;
564     }
565     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
566     if (!wantInfo) {
567         TAG_LOGE(AAFwkTag::ABILITYMGR, "read want failed");
568         return ERR_INVALID_OPERATION;
569     }
570     want = *wantInfo;
571     return NO_ERROR;
572 }
573 
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)574 int32_t AbilityManagerCollaboratorProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
575     MessageParcel &reply, MessageOption &option)
576 {
577     sptr<IRemoteObject> remote = Remote();
578     if (remote == nullptr) {
579         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
580         return ERR_NULL_OBJECT;
581     }
582 
583     return remote->SendRequest(code, data, reply, option);
584 }
585 }   // namespace AAFwk
586 }   // namespace OHOS
587