• 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,int32_t windowMode)24 int32_t AbilityManagerCollaboratorProxy::NotifyStartAbility(
25     const AppExecFwk::AbilityInfo &abilityInfo, int32_t userId, Want &want,
26     uint64_t accessTokenIDEx, int32_t windowMode)
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option(MessageOption::TF_SYNC);
31     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
32 
33     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
34         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
35         return ERR_INVALID_OPERATION;
36     }
37     if (!data.WriteParcelable(&abilityInfo)) {
38         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
39         return ERR_INVALID_OPERATION;
40     }
41     if (!data.WriteInt32(userId)) {
42         TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
43         return ERR_INVALID_OPERATION;
44     }
45     if (!data.WriteParcelable(&want)) {
46         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
47         return ERR_INVALID_OPERATION;
48     }
49     if (!data.WriteUint64(accessTokenIDEx)) {
50         TAG_LOGE(AAFwkTag::ABILITYMGR, "accessTokenIDEx write fail");
51         return ERR_INVALID_OPERATION;
52     }
53     if (!data.WriteInt32(windowMode)) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "windowMode write fail");
55         return ERR_INVALID_OPERATION;
56     }
57     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_START_ABILITY, data, reply, option);
58     if (ret != NO_ERROR) {
59         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
60         return ret;
61     }
62     ret = reply.ReadInt32();
63     if (ret != NO_ERROR) {
64         TAG_LOGE(AAFwkTag::ABILITYMGR, "start ability failed");
65         return ERR_INVALID_OPERATION;
66     }
67     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
68     if (!wantInfo) {
69         TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable fail");
70         return ERR_INVALID_OPERATION;
71     }
72     want = *wantInfo;
73     return NO_ERROR;
74 }
75 
NotifyMissionCreated(int32_t missionId,const Want & want)76 int32_t AbilityManagerCollaboratorProxy::NotifyMissionCreated(int32_t missionId, const Want &want)
77 {
78     MessageParcel data;
79     MessageParcel reply;
80     MessageOption option(MessageOption::TF_SYNC);
81     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
82 
83     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
84         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
85         return ERR_INVALID_OPERATION;
86     }
87     if (!data.WriteInt32(missionId)) {
88         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
89         return ERR_INVALID_OPERATION;
90     }
91     if (!data.WriteParcelable(&want)) {
92         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
93         return ERR_INVALID_OPERATION;
94     }
95     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_CREATED, data, reply, option);
96     if (ret != NO_ERROR) {
97         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
98         return ret;
99     }
100     return NO_ERROR;
101 }
102 
NotifyMissionCreated(const sptr<SessionInfo> & sessionInfo)103 int32_t AbilityManagerCollaboratorProxy::NotifyMissionCreated(const sptr<SessionInfo> &sessionInfo)
104 {
105     MessageParcel data;
106     MessageParcel reply;
107     MessageOption option(MessageOption::TF_SYNC);
108 
109     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
110         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
111         return ERR_INVALID_OPERATION;
112     }
113     if (sessionInfo) {
114         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
115         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
116             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
117             return ERR_INVALID_OPERATION;
118         }
119     } else {
120         if (!data.WriteBool(false)) {
121             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
122             return ERR_INVALID_OPERATION;
123         }
124     }
125     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_CREATED_BY_SCB, data, reply, option);
126     if (ret != NO_ERROR) {
127         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
128         return ret;
129     }
130     return NO_ERROR;
131 }
132 
NotifyLoadAbility(const AppExecFwk::AbilityInfo & abilityInfo,int32_t missionId,const Want & want)133 int32_t AbilityManagerCollaboratorProxy::NotifyLoadAbility(
134     const AppExecFwk::AbilityInfo &abilityInfo, int32_t missionId, const Want &want)
135 {
136     MessageParcel data;
137     MessageParcel reply;
138     MessageOption option(MessageOption::TF_SYNC);
139     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
140 
141     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
142         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
143         return ERR_INVALID_OPERATION;
144     }
145     if (!data.WriteParcelable(&abilityInfo)) {
146         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
147         return ERR_INVALID_OPERATION;
148     }
149     if (!data.WriteInt32(missionId)) {
150         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
151         return ERR_INVALID_OPERATION;
152     }
153     if (!data.WriteParcelable(&want)) {
154         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
155         return ERR_INVALID_OPERATION;
156     }
157     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_LOAD_ABILITY, data, reply, option);
158     if (ret != NO_ERROR) {
159         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
160         return ret;
161     }
162     return NO_ERROR;
163 }
164 
NotifyLoadAbility(const AppExecFwk::AbilityInfo & abilityInfo,const sptr<SessionInfo> & sessionInfo)165 int32_t AbilityManagerCollaboratorProxy::NotifyLoadAbility(
166     const AppExecFwk::AbilityInfo &abilityInfo, const sptr<SessionInfo> &sessionInfo)
167 {
168     MessageParcel data;
169     MessageParcel reply;
170     MessageOption option(MessageOption::TF_SYNC);
171 
172     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
173         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
174         return ERR_INVALID_OPERATION;
175     }
176     if (!data.WriteParcelable(&abilityInfo)) {
177         TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityInfo write fail");
178         return ERR_INVALID_OPERATION;
179     }
180     if (sessionInfo) {
181         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
182         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
183             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
184             return ERR_INVALID_OPERATION;
185         }
186     } else {
187         if (!data.WriteBool(false)) {
188             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
189             return ERR_INVALID_OPERATION;
190         }
191     }
192     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_LOAD_ABILITY_BY_SCB, data, reply, option);
193     if (ret != NO_ERROR) {
194         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
195         return ret;
196     }
197     return NO_ERROR;
198 }
199 
NotifyMoveMissionToBackground(int32_t missionId)200 int32_t AbilityManagerCollaboratorProxy::NotifyMoveMissionToBackground(int32_t missionId)
201 {
202     MessageParcel data;
203     MessageParcel reply;
204     MessageOption option(MessageOption::TF_ASYNC);
205 
206     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
207         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
208         return ERR_INVALID_OPERATION;
209     }
210     if (!data.WriteInt32(missionId)) {
211         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
212         return ERR_INVALID_OPERATION;
213     }
214     int32_t ret = SendTransactCmd(
215         IAbilityManagerCollaborator::NOTIFY_MOVE_MISSION_TO_BACKGROUND, data, reply, option);
216     if (ret != NO_ERROR) {
217         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
218         return ret;
219     }
220     return NO_ERROR;
221 }
222 
NotifyPreloadAbility(const std::string & bundleName)223 int32_t AbilityManagerCollaboratorProxy::NotifyPreloadAbility(const std::string &bundleName)
224 {
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option(MessageOption::TF_ASYNC);
228 
229     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
230         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
231         return ERR_INVALID_OPERATION;
232     }
233     if (!data.WriteString16(Str8ToStr16(bundleName))) {
234         TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
235         return ERR_INVALID_OPERATION;
236     }
237     auto remote = Remote();
238     if (!remote) {
239         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
240         return ERR_INVALID_OPERATION;
241     }
242     int32_t ret = remote->SendRequest(
243         IAbilityManagerCollaborator::NOTIFY_PRELOAD_ABILITY, data, reply, option);
244     if (ret != NO_ERROR) {
245         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
246         return ret;
247     }
248     return NO_ERROR;
249 }
250 
NotifyMoveMissionToForeground(int32_t missionId)251 int32_t AbilityManagerCollaboratorProxy::NotifyMoveMissionToForeground(int32_t missionId)
252 {
253     MessageParcel data;
254     MessageParcel reply;
255     MessageOption option(MessageOption::TF_ASYNC);
256 
257     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
258         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
259         return ERR_INVALID_OPERATION;
260     }
261     if (!data.WriteInt32(missionId)) {
262         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
263         return ERR_INVALID_OPERATION;
264     }
265     int32_t ret = SendTransactCmd(
266         IAbilityManagerCollaborator::NOTIFY_MOVE_MISSION_TO_FOREGROUND, data, reply, option);
267     if (ret != NO_ERROR) {
268         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
269         return ret;
270     }
271     return NO_ERROR;
272 }
273 
NotifyTerminateMission(int32_t missionId)274 int32_t AbilityManagerCollaboratorProxy::NotifyTerminateMission(int32_t missionId)
275 {
276     MessageParcel data;
277     MessageParcel reply;
278     MessageOption option(MessageOption::TF_ASYNC);
279 
280     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
281         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
282         return ERR_INVALID_OPERATION;
283     }
284     if (!data.WriteInt32(missionId)) {
285         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
286         return ERR_INVALID_OPERATION;
287     }
288     int32_t ret = SendTransactCmd(
289         IAbilityManagerCollaborator::NOTIFY_TERMINATE_MISSION, data, reply, option);
290     if (ret != NO_ERROR) {
291         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
292         return ret;
293     }
294     return NO_ERROR;
295 }
296 
NotifyClearMission(int32_t missionId)297 int32_t AbilityManagerCollaboratorProxy::NotifyClearMission(int32_t missionId)
298 {
299     MessageParcel data;
300     MessageParcel reply;
301     MessageOption option(MessageOption::TF_SYNC);
302 
303     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
304         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
305         return ERR_INVALID_OPERATION;
306     }
307     if (!data.WriteInt32(missionId)) {
308         TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
309         return ERR_INVALID_OPERATION;
310     }
311     int32_t ret = SendTransactCmd(
312         IAbilityManagerCollaborator::NOTIFY_CLEAR_MISSION, data, reply, option);
313     if (ret != NO_ERROR) {
314         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
315         return ret;
316     }
317     return NO_ERROR;
318 }
319 
NotifyRemoveShellProcess(int32_t pid,int32_t type,const std::string & reason)320 int32_t AbilityManagerCollaboratorProxy::NotifyRemoveShellProcess(int32_t pid, int32_t type, const std::string &reason)
321 {
322     MessageParcel data;
323     MessageParcel reply;
324     MessageOption option(MessageOption::TF_ASYNC);
325 
326     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
327         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
328         return ERR_INVALID_OPERATION;
329     }
330     if (!data.WriteInt32(pid)) {
331         TAG_LOGE(AAFwkTag::ABILITYMGR, "pid write fail");
332         return ERR_INVALID_OPERATION;
333     }
334     if (!data.WriteInt32(type)) {
335         TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
336         return ERR_INVALID_OPERATION;
337     }
338     if (!data.WriteString16(Str8ToStr16(reason))) {
339         TAG_LOGE(AAFwkTag::ABILITYMGR, "reason write fail");
340         return ERR_INVALID_OPERATION;
341     }
342     int32_t ret = SendTransactCmd(
343         IAbilityManagerCollaborator::NOTIFY_REMOVE_SHELL_PROCESS, data, reply, option);
344     if (ret != NO_ERROR) {
345         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
346         return ret;
347     }
348     return NO_ERROR;
349 }
350 
UpdateMissionInfo(sptr<SessionInfo> & sessionInfo)351 void AbilityManagerCollaboratorProxy::UpdateMissionInfo(sptr<SessionInfo> &sessionInfo)
352 {
353     MessageParcel data;
354     MessageParcel reply;
355     MessageOption option;
356 
357     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
358         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
359         return;
360     }
361 
362     if (sessionInfo) {
363         AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
364         if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
365             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
366             return;
367         }
368     } else {
369         if (!data.WriteBool(false)) {
370             TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
371             return;
372         }
373     }
374 
375     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_MISSION_INFO_BY_SCB, data, reply, option);
376     if (ret != NO_ERROR) {
377         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
378         return;
379     }
380 
381     sessionInfo = reply.ReadParcelable<SessionInfo>();
382     return;
383 }
384 
CheckCallAbilityPermission(const Want & want)385 int32_t AbilityManagerCollaboratorProxy::CheckCallAbilityPermission(const Want &want)
386 {
387     MessageParcel data;
388     MessageParcel reply;
389     MessageOption option;
390     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
391 
392     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
393         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
394         return ERR_INVALID_OPERATION;
395     }
396 
397     if (!data.WriteParcelable(&want)) {
398         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
399         return ERR_INVALID_OPERATION;
400     }
401     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::CHECK_CALL_ABILITY_PERMISSION,
402         data, reply, option);
403     if (ret != NO_ERROR) {
404         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
405         return ret;
406     }
407     return reply.ReadInt32();
408 }
409 
UpdateConfiguration(const AppExecFwk::Configuration & config,int32_t userId)410 bool AbilityManagerCollaboratorProxy::UpdateConfiguration(const AppExecFwk::Configuration &config, int32_t userId)
411 {
412     MessageParcel data;
413     MessageParcel reply;
414     MessageOption option(MessageOption::TF_ASYNC);
415     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
416         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
417         return false;
418     }
419     if (!data.WriteParcelable(&config)) {
420         TAG_LOGE(AAFwkTag::ABILITYMGR, "write config fail");
421         return false;
422     }
423     if (!data.WriteInt32(userId)) {
424         TAG_LOGE(AAFwkTag::ABILITYMGR, "write usr fail");
425         return false;
426     }
427     auto error = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_CONFIGURATION, data, reply, option);
428     if (error != NO_ERROR) {
429         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
430         return true;
431     }
432     return true;
433 }
434 
OpenFile(const Uri & uri,uint32_t flag,uint32_t tokenId)435 int32_t AbilityManagerCollaboratorProxy::OpenFile(const Uri& uri, uint32_t flag, uint32_t tokenId)
436 {
437     MessageParcel data;
438     MessageParcel reply;
439     MessageOption option;
440     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
441         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
442         return -1;
443     }
444     if (!data.WriteParcelable(&uri)) {
445         TAG_LOGE(AAFwkTag::ABILITYMGR, "write uri fail");
446         return -1;
447     }
448     if (!data.WriteUint32(flag)) {
449         TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
450         return -1;
451     }
452     if (!data.WriteUint32(tokenId)) {
453         TAG_LOGE(AAFwkTag::ABILITYMGR, "write tokenId fail");
454         return -1;
455     }
456 
457     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::OPEN_FILE, data, reply, option);
458     if (ret != NO_ERROR) {
459         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
460         return -1;
461     }
462     return reply.ReadFileDescriptor();
463 }
464 
GrantUriPermission(const std::vector<std::string> & uriVec,uint32_t flag,uint32_t targetTokenId,const std::string & targetBundleName)465 int32_t AbilityManagerCollaboratorProxy::GrantUriPermission(const std::vector<std::string> &uriVec, uint32_t flag,
466     uint32_t targetTokenId, const std::string &targetBundleName)
467 {
468     MessageParcel data;
469     MessageParcel reply;
470     MessageOption option;
471     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
472         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
473         return ERR_INVALID_OPERATION;
474     }
475     if (!data.WriteStringVector(uriVec)) {
476         TAG_LOGE(AAFwkTag::ABILITYMGR, "write uriVec fail");
477         return ERR_INVALID_OPERATION;
478     }
479     if (!data.WriteUint32(flag)) {
480         TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
481         return ERR_INVALID_OPERATION;
482     }
483     if (!data.WriteUint32(targetTokenId)) {
484         TAG_LOGE(AAFwkTag::ABILITYMGR, "write targetTokenId fail");
485         return ERR_INVALID_OPERATION;
486     }
487     if (!data.WriteString(targetBundleName)) {
488         TAG_LOGE(AAFwkTag::ABILITYMGR, "write targetBundleName fail");
489         return ERR_INVALID_OPERATION;
490     }
491 
492     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::GRANT_URI_PERMISSION, data, reply, option);
493     if (ret != NO_ERROR) {
494         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
495         return ERR_INVALID_OPERATION;
496     }
497     return reply.ReadInt32();
498 }
499 
RevokeUriPermission(uint32_t tokenId)500 int32_t AbilityManagerCollaboratorProxy::RevokeUriPermission(uint32_t tokenId)
501 {
502     MessageParcel data;
503     MessageParcel reply;
504     MessageOption option;
505     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
506         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
507         return ERR_INVALID_OPERATION;
508     }
509     if (!data.WriteUint32(tokenId)) {
510         TAG_LOGE(AAFwkTag::ABILITYMGR, "write tokenId fail");
511         return ERR_INVALID_OPERATION;
512     }
513 
514     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::REVOKE_URI_PERMISSION, data, reply, option);
515     if (ret != NO_ERROR) {
516         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
517         return ERR_INVALID_OPERATION;
518     }
519     return reply.ReadInt32();
520 }
521 
NotifyMissionBindPid(int32_t missionId,int32_t pid)522 void AbilityManagerCollaboratorProxy::NotifyMissionBindPid(int32_t missionId, int32_t pid)
523 {
524     MessageParcel data;
525     MessageParcel reply;
526     MessageOption option(MessageOption::TF_ASYNC);
527     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
528         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
529         return;
530     }
531     if (!data.WriteInt32(missionId)) {
532         TAG_LOGE(AAFwkTag::ABILITYMGR, "write missionId fail");
533         return;
534     }
535     if (!data.WriteInt32(pid)) {
536         TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid fail");
537         return;
538     }
539     auto error = SendTransactCmd(IAbilityManagerCollaborator::NOTIFY_MISSION_BIND_PID, data, reply, option);
540     if (error != NO_ERROR) {
541         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
542     }
543 }
544 
CheckStaticCfgPermission(const Want & want,bool isImplicit)545 int32_t AbilityManagerCollaboratorProxy::CheckStaticCfgPermission(const Want &want, bool isImplicit)
546 {
547     MessageParcel data;
548     MessageParcel reply;
549     MessageOption option(MessageOption::TF_SYNC);
550     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
551     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
552         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
553         return ERR_INVALID_OPERATION;
554     }
555     if (!data.WriteParcelable(&want)) {
556         TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
557         return ERR_INVALID_OPERATION;
558     }
559     if (!data.WriteBool(isImplicit)) {
560         TAG_LOGE(AAFwkTag::ABILITYMGR, "isImplicit write failed.");
561         return ERR_INVALID_OPERATION;
562     }
563     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::CHECK_STATIC_CFG_PERMISSION,
564         data, reply, option);
565     if (ret != NO_ERROR) {
566         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
567         return ret;
568     }
569     return reply.ReadInt32();
570 }
571 
UpdateCallerIfNeed(Want & want)572 int32_t AbilityManagerCollaboratorProxy::UpdateCallerIfNeed(Want &want)
573 {
574     MessageParcel data;
575     MessageParcel reply;
576     MessageOption option(MessageOption::TF_SYNC);
577     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
578     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
579         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
580         return ERR_INVALID_OPERATION;
581     }
582     if (!data.WriteParcelable(&want)) {
583         TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
584         return ERR_INVALID_OPERATION;
585     }
586     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_CALLER_IF_NEED,
587         data, reply, option);
588     if (ret != NO_ERROR) {
589         TAG_LOGE(AAFwkTag::ABILITYMGR, "update caller error:%{public}d", ret);
590         return ret;
591     }
592     ret = reply.ReadInt32();
593     if (ret != NO_ERROR) {
594         TAG_LOGE(AAFwkTag::ABILITYMGR, "update caller failed:%{public}d", ret);
595         return ERR_INVALID_OPERATION;
596     }
597     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
598     if (!wantInfo) {
599         TAG_LOGE(AAFwkTag::ABILITYMGR, "read want failed");
600         return ERR_INVALID_OPERATION;
601     }
602     want = *wantInfo;
603     return NO_ERROR;
604 }
605 
NotifyKillProcesses(const std::string & bundleName,int32_t userId)606 int32_t AbilityManagerCollaboratorProxy::NotifyKillProcesses(const std::string &bundleName, int32_t userId)
607 {
608     MessageParcel data;
609     MessageParcel reply;
610     MessageOption option(MessageOption::TF_SYNC);
611     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
612         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
613         return ERR_INVALID_OPERATION;
614     }
615     if (!data.WriteString16(Str8ToStr16(bundleName))) {
616         TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
617         return ERR_INVALID_OPERATION;
618     }
619     if (!data.WriteInt32(userId)) {
620         TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
621         return ERR_INVALID_OPERATION;
622     }
623     auto remote = Remote();
624     if (!remote) {
625         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
626         return ERR_INVALID_OPERATION;
627     }
628     int32_t ret = remote->SendRequest(
629         IAbilityManagerCollaborator::NOTIFY_KILL_PROCESSES, data, reply, option);
630     if (ret != NO_ERROR) {
631         TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
632         return ret;
633     }
634     return NO_ERROR;
635 }
636 
UpdateTargetIfNeed(Want & want)637 int32_t AbilityManagerCollaboratorProxy::UpdateTargetIfNeed(Want &want)
638 {
639     MessageParcel data;
640     MessageParcel reply;
641     MessageOption option(MessageOption::TF_SYNC);
642     AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
643     if (!data.WriteInterfaceToken(AbilityManagerCollaboratorProxy::GetDescriptor())) {
644         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
645         return ERR_INVALID_OPERATION;
646     }
647     if (!data.WriteParcelable(&want)) {
648         TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
649         return ERR_INVALID_OPERATION;
650     }
651     int32_t ret = SendTransactCmd(IAbilityManagerCollaborator::UPDATE_TARGET_IF_NEED,
652         data, reply, option);
653     if (ret != NO_ERROR) {
654         TAG_LOGE(AAFwkTag::ABILITYMGR, "update target error:%{public}d", ret);
655         return ret;
656     }
657     ret = reply.ReadInt32();
658     if (ret != NO_ERROR) {
659         TAG_LOGE(AAFwkTag::ABILITYMGR, "update target failed:%{public}d", ret);
660         return ERR_INVALID_OPERATION;
661     }
662     std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
663     if (!wantInfo) {
664         TAG_LOGE(AAFwkTag::ABILITYMGR, "read want failed");
665         return ERR_INVALID_OPERATION;
666     }
667     want = *wantInfo;
668     return NO_ERROR;
669 }
670 
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)671 int32_t AbilityManagerCollaboratorProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
672     MessageParcel &reply, MessageOption &option)
673 {
674     sptr<IRemoteObject> remote = Remote();
675     if (remote == nullptr) {
676         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
677         return ERR_NULL_OBJECT;
678     }
679 
680     return remote->SendRequest(code, data, reply, option);
681 }
682 }   // namespace AAFwk
683 }   // namespace OHOS
684