1 /*
2 * Copyright (c) 2021-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 "app_mgr_proxy.h"
17
18 #include "ability_manager_errors.h"
19 #include "appexecfwk_errors.h"
20 #include "hilog_tag_wrapper.h"
21 #include "hitrace_chain_utils.h"
22 #include "hitrace_meter.h"
23 #include "ipc_capacity_wrap.h"
24 #include "ipc_types.h"
25 #include "iremote_object.h"
26 #include "parcel_util.h"
27
28 namespace OHOS {
29 namespace AppExecFwk {
30 constexpr int32_t CYCLE_LIMIT = 1000;
31 constexpr int32_t MAX_PROCESS_STATE_COUNT = 1000;
32 constexpr int32_t MAX_BACKGROUND_APP_COUNT = 1000;
AppMgrProxy(const sptr<IRemoteObject> & impl)33 AppMgrProxy::AppMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAppMgr>(impl)
34 {}
35
WriteInterfaceToken(MessageParcel & data)36 bool AppMgrProxy::WriteInterfaceToken(MessageParcel &data)
37 {
38 if (!data.WriteInterfaceToken(AppMgrProxy::GetDescriptor())) {
39 TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
40 return false;
41 }
42 return true;
43 }
44
AttachApplication(const sptr<IRemoteObject> & obj)45 void AppMgrProxy::AttachApplication(const sptr<IRemoteObject> &obj)
46 {
47 MessageParcel data;
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_SYNC);
50 if (!WriteInterfaceToken(data)) {
51 return;
52 }
53 if (obj == nullptr || obj.GetRefPtr() == nullptr) {
54 TAG_LOGE(AAFwkTag::APPMGR, "app scheduler null");
55 }
56 PARCEL_UTIL_WRITE_NORET(data, RemoteObject, obj.GetRefPtr());
57
58 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_ATTACH_APPLICATION, data, reply, option);
59 }
60
PreloadApplication(const std::string & bundleName,int32_t userId,AppExecFwk::PreloadMode preloadMode,int32_t appIndex)61 int32_t AppMgrProxy::PreloadApplication(const std::string &bundleName, int32_t userId,
62 AppExecFwk::PreloadMode preloadMode, int32_t appIndex)
63 {
64 TAG_LOGD(AAFwkTag::APPMGR, "called");
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option(MessageOption::TF_SYNC);
68 if (!WriteInterfaceToken(data)) {
69 TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Write interface token failed.");
70 return IPC_PROXY_ERR;
71 }
72 PARCEL_UTIL_WRITE_RET_INT(data, String16, Str8ToStr16(bundleName));
73 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
74 PARCEL_UTIL_WRITE_RET_INT(data, Int32, static_cast<int32_t>(preloadMode));
75 PARCEL_UTIL_WRITE_RET_INT(data, Int32, appIndex);
76
77 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PRELOAD_APPLICATION, data, reply, option);
78 return reply.ReadInt32();
79 }
80
PreloadModuleFinished(const int32_t recordId)81 void AppMgrProxy::PreloadModuleFinished(const int32_t recordId)
82 {
83 TAG_LOGD(AAFwkTag::APPMGR, "PreloadModuleFinished called");
84 MessageParcel data;
85 MessageParcel reply;
86 MessageOption option(MessageOption::TF_ASYNC);
87 if (!WriteInterfaceToken(data)) {
88 TAG_LOGE(AAFwkTag::APPMGR, "PreloadModuleFinished write interface token failed");
89 return;
90 }
91 PARCEL_UTIL_WRITE_NORET(data, Int32, recordId);
92 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::PRELOAD_MODULE_FINISHED, data, reply, option);
93 }
94
ApplicationForegrounded(const int32_t recordId)95 void AppMgrProxy::ApplicationForegrounded(const int32_t recordId)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option(MessageOption::TF_SYNC);
100 if (!WriteInterfaceToken(data)) {
101 return;
102 }
103 PARCEL_UTIL_WRITE_NORET(data, Int32, recordId);
104
105 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED, data, reply, option);
106 }
107
ApplicationBackgrounded(const int32_t recordId)108 void AppMgrProxy::ApplicationBackgrounded(const int32_t recordId)
109 {
110 MessageParcel data;
111 MessageParcel reply;
112 MessageOption option(MessageOption::TF_SYNC);
113 if (!WriteInterfaceToken(data)) {
114 return;
115 }
116 PARCEL_UTIL_WRITE_NORET(data, Int32, recordId);
117
118 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED, data, reply, option);
119 }
120
ApplicationTerminated(const int32_t recordId)121 void AppMgrProxy::ApplicationTerminated(const int32_t recordId)
122 {
123 MessageParcel data;
124 MessageParcel reply;
125 MessageOption option(MessageOption::TF_SYNC);
126 if (!WriteInterfaceToken(data)) {
127 return;
128 }
129 PARCEL_UTIL_WRITE_NORET(data, Int32, recordId);
130
131 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED, data, reply, option);
132 }
133
AbilityCleaned(const sptr<IRemoteObject> & token)134 void AppMgrProxy::AbilityCleaned(const sptr<IRemoteObject> &token)
135 {
136 MessageParcel data;
137 MessageParcel reply;
138 MessageOption option(MessageOption::TF_SYNC);
139 if (!WriteInterfaceToken(data)) {
140 return;
141 }
142 PARCEL_UTIL_WRITE_NORET(data, RemoteObject, token.GetRefPtr());
143
144 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_ABILITY_CLEANED, data, reply, option);
145 }
146
GetAmsMgr()147 sptr<IAmsMgr> AppMgrProxy::GetAmsMgr()
148 {
149 MessageParcel data;
150 MessageParcel reply;
151 if (!WriteInterfaceToken(data)) {
152 return nullptr;
153 }
154 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_MGR_INSTANCE, data, reply)) {
155 return nullptr;
156 }
157 sptr<IRemoteObject> object = reply.ReadRemoteObject();
158 sptr<IAmsMgr> amsMgr = iface_cast<IAmsMgr>(object);
159 if (!amsMgr) {
160 TAG_LOGE(AAFwkTag::APPMGR, "Ability manager service instance is nullptr. ");
161 return nullptr;
162 }
163 return amsMgr;
164 }
165
ClearUpApplicationData(const std::string & bundleName,int32_t appCloneIndex,const int32_t userId)166 int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex, const int32_t userId)
167 {
168 TAG_LOGI(AAFwkTag::APPMGR, "Called.");
169 MessageParcel data;
170 MessageParcel reply;
171 MessageOption option(MessageOption::TF_SYNC);
172 if (!WriteInterfaceToken(data)) {
173 return ERR_FLATTEN_OBJECT;
174 }
175 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
176 PARCEL_UTIL_WRITE_RET_INT(data, Int32, appCloneIndex);
177 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
178
179 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA, data, reply, option);
180 return reply.ReadInt32();
181 }
182
ClearUpApplicationDataBySelf(int32_t userId)183 int32_t AppMgrProxy::ClearUpApplicationDataBySelf(int32_t userId)
184 {
185 TAG_LOGI(AAFwkTag::APPMGR, "called");
186 MessageParcel data;
187 MessageParcel reply;
188 MessageOption option(MessageOption::TF_SYNC);
189 if (!WriteInterfaceToken(data)) {
190 return ERR_FLATTEN_OBJECT;
191 }
192 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
193
194 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA_BY_SELF, data, reply, option);
195 return reply.ReadInt32();
196 }
197
GetAllRunningProcesses(std::vector<RunningProcessInfo> & info)198 int32_t AppMgrProxy::GetAllRunningProcesses(std::vector<RunningProcessInfo> &info)
199 {
200 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
201 MessageParcel data;
202 MessageParcel reply;
203 MessageOption option(MessageOption::TF_SYNC);
204 if (!WriteInterfaceToken(data)) {
205 return ERR_FLATTEN_OBJECT;
206 }
207 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_ALL_RUNNING_PROCESSES, data, reply)) {
208 return ERR_NULL_OBJECT;
209 }
210 auto error = GetParcelableInfos<RunningProcessInfo>(reply, info);
211 if (error != NO_ERROR) {
212 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
213 return error;
214 }
215 int result = reply.ReadInt32();
216 return result;
217 }
218
GetRunningMultiAppInfoByBundleName(const std::string & bundleName,RunningMultiAppInfo & info)219 int32_t AppMgrProxy::GetRunningMultiAppInfoByBundleName(const std::string &bundleName,
220 RunningMultiAppInfo &info)
221 {
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option(MessageOption::TF_SYNC);
225 if (!WriteInterfaceToken(data)) {
226 return ERR_FLATTEN_OBJECT;
227 }
228 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
229
230 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME, data, reply, option);
231 std::unique_ptr<RunningMultiAppInfo> infoReply(reply.ReadParcelable<RunningMultiAppInfo>());
232 if (infoReply == nullptr) {
233 TAG_LOGW(AAFwkTag::APPMGR, "reply ReadParcelable is nullptr");
234 return ERR_NULL_OBJECT;
235 }
236 info = *infoReply;
237 int result = reply.ReadInt32();
238 return result;
239 }
240
GetAllRunningInstanceKeysBySelf(std::vector<std::string> & instanceKeys)241 int32_t AppMgrProxy::GetAllRunningInstanceKeysBySelf(std::vector<std::string> &instanceKeys)
242 {
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option(MessageOption::TF_SYNC);
246 if (!WriteInterfaceToken(data)) {
247 return ERR_FLATTEN_OBJECT;
248 }
249
250 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF, data, reply, option);
251 if (!reply.ReadStringVector(&instanceKeys)) {
252 return ERR_INVALID_DATA;
253 }
254 int32_t result = reply.ReadInt32();
255 return result;
256 }
257
GetAllRunningInstanceKeysByBundleName(const std::string & bundleName,std::vector<std::string> & instanceKeys,int32_t userId)258 int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName,
259 std::vector<std::string> &instanceKeys, int32_t userId)
260 {
261 MessageParcel data;
262 MessageParcel reply;
263 MessageOption option(MessageOption::TF_SYNC);
264 if (!WriteInterfaceToken(data)) {
265 return ERR_FLATTEN_OBJECT;
266 }
267 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
268 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
269
270 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME, data, reply, option);
271 if (!reply.ReadStringVector(&instanceKeys)) {
272 return ERR_INVALID_DATA;
273 }
274 int32_t result = reply.ReadInt32();
275 return result;
276 }
277
GetRunningProcessesByBundleType(const BundleType bundleType,std::vector<RunningProcessInfo> & info)278 int32_t AppMgrProxy::GetRunningProcessesByBundleType(const BundleType bundleType,
279 std::vector<RunningProcessInfo> &info)
280 {
281 MessageParcel data;
282 MessageParcel reply;
283 MessageOption option(MessageOption::TF_SYNC);
284 if (!WriteInterfaceToken(data)) {
285 return ERR_FLATTEN_OBJECT;
286 }
287 PARCEL_UTIL_WRITE_RET_INT(data, Int32, static_cast<int32_t>(bundleType));
288
289 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_BUNDLE_TYPE, data, reply)) {
290 return ERR_NULL_OBJECT;
291 }
292 auto error = GetParcelableInfos<RunningProcessInfo>(reply, info);
293 if (error != NO_ERROR) {
294 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
295 return error;
296 }
297 int result = reply.ReadInt32();
298 return result;
299 }
300
GetAllRenderProcesses(std::vector<RenderProcessInfo> & info)301 int32_t AppMgrProxy::GetAllRenderProcesses(std::vector<RenderProcessInfo> &info)
302 {
303 MessageParcel data;
304 MessageParcel reply;
305 MessageOption option(MessageOption::TF_SYNC);
306 if (!WriteInterfaceToken(data)) {
307 return ERR_FLATTEN_OBJECT;
308 }
309 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_ALL_RENDER_PROCESSES, data, reply)) {
310 return ERR_NULL_OBJECT;
311 }
312 auto error = GetParcelableInfos<RenderProcessInfo>(reply, info);
313 if (error != NO_ERROR) {
314 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
315 return error;
316 }
317 int result = reply.ReadInt32();
318 return result;
319 }
320
GetAllChildrenProcesses(std::vector<ChildProcessInfo> & info)321 int AppMgrProxy::GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info)
322 {
323 MessageParcel data;
324 MessageParcel reply;
325 #ifdef SUPPORT_CHILD_PROCESS
326 MessageOption option(MessageOption::TF_SYNC);
327 if (!WriteInterfaceToken(data)) {
328 return ERR_FLATTEN_OBJECT;
329 }
330 if (!SendTransactCmd(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES, data, reply)) {
331 return ERR_NULL_OBJECT;
332 }
333 auto error = GetParcelableInfos<ChildProcessInfo>(reply, info);
334 if (error != NO_ERROR) {
335 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
336 return error;
337 }
338 #endif // SUPPORT_CHILD_PROCESS
339 int result = reply.ReadInt32();
340 return result;
341 }
342
JudgeSandboxByPid(pid_t pid,bool & isSandbox)343 int32_t AppMgrProxy::JudgeSandboxByPid(pid_t pid, bool &isSandbox)
344 {
345 MessageParcel data;
346 MessageParcel reply;
347 MessageOption option;
348 if (!WriteInterfaceToken(data)) {
349 return ERR_FLATTEN_OBJECT;
350 }
351 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
352
353 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID, data, reply, option);
354 isSandbox = reply.ReadBool();
355 return reply.ReadInt32();
356 }
357
IsTerminatingByPid(pid_t pid,bool & isTerminating)358 int32_t AppMgrProxy::IsTerminatingByPid(pid_t pid, bool &isTerminating)
359 {
360 MessageParcel data;
361 MessageParcel reply;
362 MessageOption option;
363 if (!WriteInterfaceToken(data)) {
364 return ERR_FLATTEN_OBJECT;
365 }
366 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
367
368 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_TERMINATING_BY_PID, data, reply, option);
369 isTerminating = reply.ReadBool();
370 return reply.ReadInt32();
371 }
372
GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> & info,int32_t userId)373 int32_t AppMgrProxy::GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId)
374 {
375 MessageParcel data;
376 MessageParcel reply;
377 MessageOption option(MessageOption::TF_SYNC);
378
379 if (!WriteInterfaceToken(data)) {
380 return ERR_FLATTEN_OBJECT;
381 }
382 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
383
384 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID, data, reply)) {
385 return ERR_NULL_OBJECT;
386 }
387 auto error = GetParcelableInfos<RunningProcessInfo>(reply, info);
388 if (error != NO_ERROR) {
389 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
390 return error;
391 }
392 int result = reply.ReadInt32();
393 return result;
394 }
395
GetProcessRunningInformation(RunningProcessInfo & info)396 int32_t AppMgrProxy::GetProcessRunningInformation(RunningProcessInfo &info)
397 {
398 MessageParcel data;
399 MessageParcel reply;
400
401 if (!WriteInterfaceToken(data)) {
402 return ERR_FLATTEN_OBJECT;
403 }
404 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_PROCESS_RUNNING_INFORMATION, data, reply)) {
405 return ERR_NULL_OBJECT;
406 }
407 std::unique_ptr<RunningProcessInfo> infoReply(reply.ReadParcelable<RunningProcessInfo>());
408 if (infoReply == nullptr) {
409 TAG_LOGW(AAFwkTag::APPMGR, "reply ReadParcelable is nullptr");
410 return ERR_NULL_OBJECT;
411 }
412 info = *infoReply;
413 return reply.ReadInt32();
414 }
415
NotifyMemoryLevel(int32_t level)416 int32_t AppMgrProxy::NotifyMemoryLevel(int32_t level)
417 {
418 MessageParcel data;
419 MessageParcel reply;
420 MessageOption option(MessageOption::TF_SYNC);
421
422 if (!WriteInterfaceToken(data)) {
423 return ERR_FLATTEN_OBJECT;
424 }
425 PARCEL_UTIL_WRITE_RET_INT(data, Int32, level);
426
427 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_NOTIFY_MEMORY_LEVEL, data, reply, option);
428 return reply.ReadInt32();
429 }
430
NotifyProcMemoryLevel(const std::map<pid_t,MemoryLevel> & procLevelMap)431 int32_t AppMgrProxy::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
432 {
433 MessageParcel data;
434 MessageParcel reply;
435 MessageOption option(MessageOption::TF_SYNC);
436
437 if (!WriteInterfaceToken(data)) {
438 return ERR_FLATTEN_OBJECT;
439 }
440 MemoryLevelInfo memoryLevelInfo(procLevelMap);
441 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &memoryLevelInfo);
442
443 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_NOTIFY_PROC_MEMORY_LEVEL, data, reply, option);
444 return reply.ReadInt32();
445 }
446
DumpHeapMemory(const int32_t pid,OHOS::AppExecFwk::MallocInfo & mallocInfo)447 int32_t AppMgrProxy::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
448 {
449 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy::DumpHeapMemory.");
450 MessageParcel data;
451 MessageParcel reply;
452 if (!WriteInterfaceToken(data)) {
453 return ERR_FLATTEN_OBJECT;
454 }
455 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
456
457 MessageOption option(MessageOption::TF_SYNC);
458 int32_t ret = SendRequest(AppMgrInterfaceCode::DUMP_HEAP_MEMORY_PROCESS, data, reply, option);
459 if (ret != NO_ERROR) {
460 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrProxy SendRequest is failed, error code: %{public}d", ret);
461 return ret;
462 }
463
464 std::unique_ptr<MallocInfo> info(reply.ReadParcelable<MallocInfo>());
465 if (info == nullptr) {
466 TAG_LOGE(AAFwkTag::APPMGR, "MallocInfo ReadParcelable nullptr");
467 return ERR_NULL_OBJECT;
468 }
469 mallocInfo = *info;
470 return ret;
471 }
472
DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo & info)473 int32_t AppMgrProxy::DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
474 {
475 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy::DumpJsHeapMemory.");
476 MessageParcel data;
477 MessageParcel reply;
478 MessageOption option(MessageOption::TF_SYNC);
479 if (!WriteInterfaceToken(data)) {
480 return ERR_FLATTEN_OBJECT;
481 }
482 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &info);
483
484 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::DUMP_JSHEAP_MEMORY_PROCESS, data, reply, option);
485 return reply.ReadInt32();
486 }
487
DumpCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo & info)488 int32_t AppMgrProxy::DumpCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo &info)
489 {
490 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy::DumpCjHeapMemory.");
491 MessageParcel data;
492 MessageParcel reply;
493 MessageOption option(MessageOption::TF_SYNC);
494 if (!WriteInterfaceToken(data)) {
495 return ERR_FLATTEN_OBJECT;
496 }
497 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &info);
498
499 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::DUMP_CJHEAP_MEMORY_PROCESS, data, reply, option);
500 return reply.ReadInt32();
501 }
502
SendTransactCmd(AppMgrInterfaceCode code,MessageParcel & data,MessageParcel & reply)503 bool AppMgrProxy::SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply)
504 {
505 MessageOption option(MessageOption::TF_SYNC);
506 int32_t result = SendRequest(code, data, reply, option);
507 if (result != NO_ERROR) {
508 TAG_LOGE(AAFwkTag::APPMGR, "receive error transact code %{public}d in transact cmd %{public}d", result, code);
509 return false;
510 }
511 return true;
512 }
513
AddAbilityStageDone(const int32_t recordId)514 void AppMgrProxy::AddAbilityStageDone(const int32_t recordId)
515 {
516 MessageParcel data;
517 MessageParcel reply;
518 if (!WriteInterfaceToken(data)) {
519 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
520 return;
521 }
522
523 if (!data.WriteInt32(recordId)) {
524 TAG_LOGE(AAFwkTag::APPMGR, "want write failed.");
525 return;
526 }
527
528 if (!SendTransactCmd(AppMgrInterfaceCode::APP_ADD_ABILITY_STAGE_INFO_DONE, data, reply)) {
529 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd failed");
530 return;
531 }
532 return;
533 }
534
StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> & bundleInfos)535 void AppMgrProxy::StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos)
536 {
537 MessageParcel data;
538 MessageParcel reply;
539 if (!WriteInterfaceToken(data)) {
540 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
541 return;
542 }
543
544 if (!data.WriteInt32(bundleInfos.size())) {
545 TAG_LOGE(AAFwkTag::APPMGR, "write bundle info size failed.");
546 return;
547 }
548
549 for (auto &bundleInfo : bundleInfos) {
550 if (!data.WriteParcelable(&bundleInfo)) {
551 TAG_LOGE(AAFwkTag::APPMGR, "write bundle info failed");
552 return;
553 }
554 }
555
556 if (!SendTransactCmd(AppMgrInterfaceCode::STARTUP_RESIDENT_PROCESS, data, reply)) {
557 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd failed");
558 return;
559 }
560 return;
561 }
562
563 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)564 int AppMgrProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
565 {
566 int32_t infoSize = reply.ReadInt32();
567 if (infoSize > CYCLE_LIMIT) {
568 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
569 return ERR_INVALID_VALUE;
570 }
571 for (int32_t i = 0; i < infoSize; i++) {
572 std::unique_ptr<T> info(reply.ReadParcelable<T>());
573 if (!info) {
574 TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infos failed");
575 return ERR_INVALID_VALUE;
576 }
577 parcelableInfos.emplace_back(*info);
578 }
579 TAG_LOGD(AAFwkTag::APPMGR, "get parcelable infos success");
580 return NO_ERROR;
581 }
582
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)583 int AppMgrProxy::RegisterApplicationStateObserver(
584 const sptr<IApplicationStateObserver> &observer, const std::vector<std::string> &bundleNameList)
585 {
586 if (!observer) {
587 TAG_LOGE(AAFwkTag::APPMGR, "observer null");
588 return ERR_INVALID_VALUE;
589 }
590 TAG_LOGD(AAFwkTag::APPMGR, "RegisterApplicationStateObserver start");
591 MessageParcel data;
592 MessageParcel reply;
593 MessageOption option;
594 if (!WriteInterfaceToken(data)) {
595 return ERR_FLATTEN_OBJECT;
596 }
597 if (!data.WriteRemoteObject(observer->AsObject())) {
598 TAG_LOGE(AAFwkTag::APPMGR, "observer write failed.");
599 return ERR_FLATTEN_OBJECT;
600 }
601 if (!data.WriteStringVector(bundleNameList)) {
602 TAG_LOGE(AAFwkTag::APPMGR, "bundleNameList write failed.");
603 return ERR_FLATTEN_OBJECT;
604 }
605
606 auto error = SendRequest(AppMgrInterfaceCode::REGISTER_APPLICATION_STATE_OBSERVER,
607 data, reply, option);
608 if (error != NO_ERROR) {
609 TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error);
610 return error;
611 }
612 return reply.ReadInt32();
613 }
614
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)615 int AppMgrProxy::UnregisterApplicationStateObserver(
616 const sptr<IApplicationStateObserver> &observer)
617 {
618 if (!observer) {
619 TAG_LOGE(AAFwkTag::APPMGR, "observer null");
620 return ERR_INVALID_VALUE;
621 }
622 TAG_LOGD(AAFwkTag::APPMGR, "UnregisterApplicationStateObserver start");
623 MessageParcel data;
624 MessageParcel reply;
625 MessageOption option;
626 if (!WriteInterfaceToken(data)) {
627 return ERR_FLATTEN_OBJECT;
628 }
629 PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject());
630
631 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER, data, reply, option);
632 return reply.ReadInt32();
633 }
634
RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> & observer)635 int32_t AppMgrProxy::RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
636 {
637 TAG_LOGD(AAFwkTag::APPMGR, "called");
638 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
639 if (observer == nullptr) {
640 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
641 return ERR_INVALID_VALUE;
642 }
643
644 MessageParcel data;
645 if (!WriteInterfaceToken(data)) {
646 return ERR_FLATTEN_OBJECT;
647 }
648 PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject());
649 MessageParcel reply;
650 MessageOption option;
651
652 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option);
653 return reply.ReadInt32();
654 }
655
UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> & observer)656 int32_t AppMgrProxy::UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
657 {
658 TAG_LOGD(AAFwkTag::APPMGR, "called");
659 if (observer == nullptr) {
660 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
661 return ERR_INVALID_VALUE;
662 }
663
664 MessageParcel data;
665 if (!WriteInterfaceToken(data)) {
666 return ERR_FLATTEN_OBJECT;
667 }
668 PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject());
669 MessageParcel reply;
670 MessageOption option;
671 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option);
672 return reply.ReadInt32();
673 }
674
GetForegroundApplications(std::vector<AppStateData> & list)675 int AppMgrProxy::GetForegroundApplications(std::vector<AppStateData> &list)
676 {
677 MessageParcel data;
678 MessageParcel reply;
679 MessageOption option;
680 if (!WriteInterfaceToken(data)) {
681 return ERR_FLATTEN_OBJECT;
682 }
683 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS, data, reply, option);
684 int32_t infoSize = reply.ReadInt32();
685 if (infoSize > CYCLE_LIMIT) {
686 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
687 return ERR_INVALID_VALUE;
688 }
689 for (int32_t i = 0; i < infoSize; i++) {
690 std::unique_ptr<AppStateData> info(reply.ReadParcelable<AppStateData>());
691 if (!info) {
692 TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infos failed.");
693 return ERR_INVALID_VALUE;
694 }
695 list.emplace_back(*info);
696 }
697 return reply.ReadInt32();
698 }
699
StartUserTestProcess(const AAFwk::Want & want,const sptr<IRemoteObject> & observer,const BundleInfo & bundleInfo,int32_t userId)700 int AppMgrProxy::StartUserTestProcess(
701 const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId)
702 {
703 MessageParcel data;
704 MessageParcel reply;
705 MessageOption option;
706
707 if (!WriteInterfaceToken(data)) {
708 return ERR_FLATTEN_OBJECT;
709 }
710 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &want);
711 PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer);
712 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &bundleInfo);
713 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
714
715 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_USER_TEST_PROCESS, data, reply, option);
716 return reply.ReadInt32();
717 }
718
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)719 int AppMgrProxy::FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
720 {
721 MessageParcel data;
722 MessageParcel reply;
723 MessageOption option;
724
725 if (!WriteInterfaceToken(data)) {
726 return ERR_FLATTEN_OBJECT;
727 }
728
729 PARCEL_UTIL_WRITE_RET_INT(data, String, msg);
730 PARCEL_UTIL_WRITE_RET_INT(data, Int64, resultCode);
731 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
732
733 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::FINISH_USER_TEST, data, reply, option);
734 return reply.ReadInt32();
735 }
736
ScheduleAcceptWantDone(const int32_t recordId,const AAFwk::Want & want,const std::string & flag)737 void AppMgrProxy::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)
738 {
739 MessageParcel data;
740 MessageParcel reply;
741 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
742 if (!WriteInterfaceToken(data)) {
743 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
744 return;
745 }
746
747 if (!data.WriteInt32(recordId) || !data.WriteParcelable(&want) || !data.WriteString(flag)) {
748 TAG_LOGE(AAFwkTag::APPMGR, "want write failed.");
749 return;
750 }
751
752 if (!SendTransactCmd(AppMgrInterfaceCode::SCHEDULE_ACCEPT_WANT_DONE, data, reply)) {
753 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd failed");
754 return;
755 }
756 }
757
ScheduleNewProcessRequestDone(const int32_t recordId,const AAFwk::Want & want,const std::string & flag)758 void AppMgrProxy::ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want,
759 const std::string &flag)
760 {
761 MessageParcel data;
762 MessageParcel reply;
763 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
764 if (!WriteInterfaceToken(data)) {
765 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
766 return;
767 }
768
769 if (!data.WriteInt32(recordId) || !data.WriteParcelable(&want) || !data.WriteString(flag)) {
770 TAG_LOGE(AAFwkTag::APPMGR, "want write failed.");
771 return;
772 }
773
774 if (!SendTransactCmd(AppMgrInterfaceCode::SCHEDULE_NEW_PROCESS_REQUEST_DONE, data, reply)) {
775 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd failed");
776 return;
777 }
778 }
779
GetAbilityRecordsByProcessID(const int pid,std::vector<sptr<IRemoteObject>> & tokens)780 int AppMgrProxy::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens)
781 {
782 MessageParcel data;
783 MessageParcel reply;
784 MessageOption option(MessageOption::TF_SYNC);
785
786 if (!WriteInterfaceToken(data)) {
787 return ERR_FLATTEN_OBJECT;
788 }
789 if (!data.WriteInt32(pid)) {
790 TAG_LOGE(AAFwkTag::APPMGR, "write pid failed");
791 return ERR_FLATTEN_OBJECT;
792 }
793 if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID, data, reply)) {
794 return ERR_NULL_OBJECT;
795 }
796 int32_t infoSize = reply.ReadInt32();
797 if (infoSize > CYCLE_LIMIT) {
798 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
799 return ERR_INVALID_VALUE;
800 }
801 for (int32_t i = 0; i < infoSize; i++) {
802 auto iRemote = reply.ReadRemoteObject();
803 tokens.emplace_back(iRemote);
804 }
805 return reply.ReadInt32();
806 }
807
PreStartNWebSpawnProcess()808 int AppMgrProxy::PreStartNWebSpawnProcess()
809 {
810 TAG_LOGI(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess");
811 MessageParcel data;
812 MessageParcel reply;
813 MessageOption option;
814 if (!WriteInterfaceToken(data)) {
815 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
816 return ERR_FLATTEN_OBJECT;
817 }
818
819 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS, data, reply, option);
820 auto result = reply.ReadInt32();
821 if (result != 0) {
822 TAG_LOGW(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess failed, result: %{public}d", result);
823 }
824 return result;
825 }
826
StartRenderProcess(const std::string & renderParam,int32_t ipcFd,int32_t sharedFd,int32_t crashFd,pid_t & renderPid,bool isGPU)827 int AppMgrProxy::StartRenderProcess(const std::string &renderParam,
828 int32_t ipcFd, int32_t sharedFd,
829 int32_t crashFd, pid_t &renderPid, bool isGPU)
830 {
831 if (renderParam.empty() || ipcFd <= 0 || sharedFd <= 0 || crashFd <= 0) {
832 TAG_LOGE(AAFwkTag::APPMGR, "Invalid params, renderParam:%{private}s, ipcFd:%{public}d, "
833 "sharedFd:%{public}d, crashFd:%{public}d", renderParam.c_str(), ipcFd, sharedFd, crashFd);
834 return -1;
835 }
836
837 MessageParcel data;
838 MessageParcel reply;
839 MessageOption option;
840 if (!WriteInterfaceToken(data)) {
841 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
842 return ERR_FLATTEN_OBJECT;
843 }
844
845 if (!data.WriteString(renderParam)) {
846 TAG_LOGE(AAFwkTag::APPMGR, "want paramSize failed.");
847 return -1;
848 }
849
850 if (!data.WriteFileDescriptor(ipcFd) || !data.WriteFileDescriptor(sharedFd) ||
851 !data.WriteFileDescriptor(crashFd)) {
852 TAG_LOGE(AAFwkTag::APPMGR, "want fd failed, ipcFd:%{public}d, sharedFd:%{public}d, "
853 "crashFd:%{public}d", ipcFd, sharedFd, crashFd);
854 return -1;
855 }
856
857 if (!data.WriteBool(isGPU)) {
858 TAG_LOGE(AAFwkTag::APPMGR, "want processType failed.");
859 return -1;
860 }
861
862 int32_t ret = SendRequest(AppMgrInterfaceCode::START_RENDER_PROCESS, data,
863 reply, option);
864 if (ret != NO_ERROR) {
865 TAG_LOGW(AAFwkTag::APPMGR, "StartRenderProcess SendRequest is failed, error code: %{public}d", ret);
866 return ret;
867 }
868
869 auto result = reply.ReadInt32();
870 renderPid = reply.ReadInt32();
871 if (result != 0) {
872 TAG_LOGW(AAFwkTag::APPMGR, "StartRenderProcess failed, result: %{public}d", result);
873 }
874 return result;
875 }
876
AttachRenderProcess(const sptr<IRemoteObject> & renderScheduler)877 void AppMgrProxy::AttachRenderProcess(const sptr<IRemoteObject> &renderScheduler)
878 {
879 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
880 if (!renderScheduler) {
881 TAG_LOGE(AAFwkTag::APPMGR, "renderScheduler is null");
882 return;
883 }
884
885 TAG_LOGD(AAFwkTag::APPMGR, "AttachRenderProcess start");
886 MessageParcel data;
887 MessageParcel reply;
888 MessageOption option;
889 if (!WriteInterfaceToken(data)) {
890 return;
891 }
892 if (!data.WriteRemoteObject(renderScheduler)) {
893 TAG_LOGE(AAFwkTag::APPMGR, "renderScheduler write failed.");
894 return;
895 }
896
897 if (!SendTransactCmd(AppMgrInterfaceCode::ATTACH_RENDER_PROCESS, data, reply)) {
898 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd ATTACH_RENDER_PROCESS failed");
899 return;
900 }
901 }
902
SaveBrowserChannel(sptr<IRemoteObject> browser)903 void AppMgrProxy::SaveBrowserChannel(sptr<IRemoteObject> browser)
904 {
905 if (!browser) {
906 TAG_LOGE(AAFwkTag::APPMGR, "browser is null");
907 return;
908 }
909 MessageParcel data;
910 MessageParcel reply;
911 MessageOption option;
912 if (!WriteInterfaceToken(data)) {
913 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
914 return;
915 }
916
917 if (!data.WriteRemoteObject(browser)) {
918 TAG_LOGE(AAFwkTag::APPMGR, "browser write failed.");
919 return;
920 }
921
922 if (!SendTransactCmd(AppMgrInterfaceCode::SAVE_BROWSER_CHANNEL, data, reply)) {
923 TAG_LOGE(AAFwkTag::APPMGR, "SendTransactCmd SAVE_BROWSER_CHANNEL failed");
924 return;
925 }
926 }
927
GetRenderProcessTerminationStatus(pid_t renderPid,int & status)928 int AppMgrProxy::GetRenderProcessTerminationStatus(pid_t renderPid, int &status)
929 {
930 MessageParcel data;
931 MessageParcel reply;
932 MessageOption option;
933 if (!WriteInterfaceToken(data)) {
934 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
935 return ERR_FLATTEN_OBJECT;
936 }
937
938 if (!data.WriteInt32(renderPid)) {
939 TAG_LOGE(AAFwkTag::APPMGR, "write renderPid failed.");
940 return -1;
941 }
942
943 int32_t ret = SendRequest(AppMgrInterfaceCode::GET_RENDER_PROCESS_TERMINATION_STATUS, data, reply, option);
944 if (ret != NO_ERROR) {
945 TAG_LOGW(AAFwkTag::APPMGR, "GetRenderProcessTerminationStatus SendRequest is failed, error code: %{public}d",
946 ret);
947 return ret;
948 }
949
950 auto result = reply.ReadInt32();
951 if (result != 0) {
952 TAG_LOGW(AAFwkTag::APPMGR, "GetRenderProcessTerminationStatus failed, result: %{public}d", result);
953 return result;
954 }
955 status = reply.ReadInt32();
956 return 0;
957 }
958
UpdateConfiguration(const Configuration & config,const int32_t userId)959 int32_t AppMgrProxy::UpdateConfiguration(const Configuration &config, const int32_t userId)
960 {
961 Ability_MANAGER_HITRACE_CHAIN_NAME("UpdateConfiguration", HITRACE_FLAG_INCLUDE_ASYNC);
962 TAG_LOGI(AAFwkTag::APPMGR, "AppMgrProxy UpdateConfiguration");
963 MessageParcel data;
964 MessageParcel reply;
965 MessageOption option(MessageOption::TF_SYNC);
966 if (!WriteInterfaceToken(data)) {
967 return ERR_INVALID_DATA;
968 }
969 if (!data.WriteParcelable(&config)) {
970 TAG_LOGE(AAFwkTag::APPMGR, "parcel config failed");
971 return ERR_INVALID_DATA;
972 }
973 if (!data.WriteInt32(userId)) {
974 TAG_LOGE(AAFwkTag::APPMGR, "parcel userId failed");
975 return ERR_INVALID_DATA;
976 }
977 int32_t ret = SendRequest(AppMgrInterfaceCode::UPDATE_CONFIGURATION, data, reply, option);
978 if (ret != NO_ERROR) {
979 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
980 return ret;
981 }
982 return reply.ReadInt32();
983 }
984
UpdateConfigurationForBackgroundApp(const std::vector<BackgroundAppInfo> & appInfos,const AppExecFwk::ConfigurationPolicy & policy,const int32_t userId)985 int32_t AppMgrProxy::UpdateConfigurationForBackgroundApp(const std::vector<BackgroundAppInfo>& appInfos,
986 const AppExecFwk::ConfigurationPolicy& policy, const int32_t userId)
987 {
988 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy UpdateConfigurationForBackgroundApp");
989 MessageParcel data;
990 MessageParcel reply;
991 MessageOption option(MessageOption::TF_SYNC);
992 if (!WriteInterfaceToken(data)) {
993 return IPC_PROXY_ERR;
994 }
995 auto size = appInfos.size();
996 if (size == 0 || size > MAX_BACKGROUND_APP_COUNT) {
997 TAG_LOGE(AAFwkTag::APPMGR, "AppInfos size invalid");
998 return ERR_INVALID_DATA;
999 }
1000 if (!data.WriteUint32(size)) {
1001 TAG_LOGE(AAFwkTag::APPMGR, "Write size failed");
1002 return ERR_FLATTEN_OBJECT;
1003 }
1004 for (const auto &info: appInfos) {
1005 if (!data.WriteParcelable(&info)) {
1006 TAG_LOGE(AAFwkTag::APPMGR, "Write appInfos failed");
1007 return ERR_FLATTEN_OBJECT;
1008 }
1009 }
1010 if (!data.WriteParcelable(&policy)) {
1011 TAG_LOGE(AAFwkTag::APPMGR, "parcel policy failed");
1012 return ERR_INVALID_DATA;
1013 }
1014 if (!data.WriteInt32(userId)) {
1015 TAG_LOGE(AAFwkTag::APPMGR, "parcel userId failed");
1016 return ERR_INVALID_DATA;
1017 }
1018 int32_t ret = SendRequest(AppMgrInterfaceCode::UPDATE_CONFIGURATION_POLICY, data, reply, option);
1019 if (ret != NO_ERROR) {
1020 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
1021 return ret;
1022 }
1023 return reply.ReadInt32();
1024 }
1025
UpdateConfigurationByBundleName(const Configuration & config,const std::string & name,int32_t appIndex)1026 int32_t AppMgrProxy::UpdateConfigurationByBundleName(const Configuration &config, const std::string &name,
1027 int32_t appIndex)
1028 {
1029 Ability_MANAGER_HITRACE_CHAIN_NAME("UpdateConfigurationByBundleName", HITRACE_FLAG_INCLUDE_ASYNC);
1030 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy UpdateConfigurationByBundleName");
1031 MessageParcel data;
1032 if (!WriteInterfaceToken(data)) {
1033 return ERR_INVALID_DATA;
1034 }
1035 if (!data.WriteParcelable(&config)) {
1036 TAG_LOGE(AAFwkTag::APPMGR, "parcel config failed");
1037 return ERR_INVALID_DATA;
1038 }
1039 if (!data.WriteString(name)) {
1040 TAG_LOGE(AAFwkTag::APPMGR, "parcel name failed");
1041 return ERR_INVALID_DATA;
1042 }
1043 if (!data.WriteInt32(appIndex)) {
1044 TAG_LOGE(AAFwkTag::APPMGR, "parcel appIndex failed");
1045 return ERR_INVALID_DATA;
1046 }
1047 MessageParcel reply;
1048 MessageOption option(MessageOption::TF_SYNC);
1049 int32_t ret = SendRequest(AppMgrInterfaceCode::UPDATE_CONFIGURATION_BY_BUNDLE_NAME, data, reply, option);
1050 if (ret != NO_ERROR) {
1051 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
1052 return ret;
1053 }
1054 return reply.ReadInt32();
1055 }
1056
GetConfiguration(Configuration & config)1057 int32_t AppMgrProxy::GetConfiguration(Configuration& config)
1058 {
1059 MessageParcel data;
1060 MessageParcel reply;
1061 MessageOption option(MessageOption::TF_SYNC);
1062 if (!WriteInterfaceToken(data)) {
1063 TAG_LOGE(AAFwkTag::APPMGR, "parcel data failed");
1064 return ERR_INVALID_DATA;
1065 }
1066 int32_t ret = SendRequest(AppMgrInterfaceCode::GET_CONFIGURATION, data, reply, option);
1067 if (ret != NO_ERROR) {
1068 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
1069 return ret;
1070 }
1071
1072 std::unique_ptr<Configuration> info(reply.ReadParcelable<Configuration>());
1073 if (!info) {
1074 TAG_LOGE(AAFwkTag::APPMGR, "read configuration failed.");
1075 return ERR_UNKNOWN_OBJECT;
1076 }
1077 config = *info;
1078 return reply.ReadInt32();
1079 }
1080
RegisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)1081 int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer)
1082 {
1083 if (!observer) {
1084 TAG_LOGE(AAFwkTag::APPMGR, "observer null");
1085 return ERR_INVALID_VALUE;
1086 }
1087 TAG_LOGD(AAFwkTag::APPMGR, "RegisterConfigurationObserver start");
1088 MessageParcel data;
1089 MessageParcel reply;
1090 MessageOption option;
1091 if (!WriteInterfaceToken(data)) {
1092 return ERR_FLATTEN_OBJECT;
1093 }
1094
1095 if (!data.WriteRemoteObject(observer->AsObject())) {
1096 TAG_LOGE(AAFwkTag::APPMGR, "observer write failed.");
1097 return ERR_FLATTEN_OBJECT;
1098 }
1099
1100 auto error = SendRequest(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER, data, reply, option);
1101 if (error != NO_ERROR) {
1102 TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error);
1103 return error;
1104 }
1105 return reply.ReadInt32();
1106 }
1107
UnregisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)1108 int32_t AppMgrProxy::UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
1109 {
1110 TAG_LOGD(AAFwkTag::APPMGR, "UnregisterConfigurationObserver start");
1111 MessageParcel data;
1112 MessageParcel reply;
1113 MessageOption option;
1114 if (!WriteInterfaceToken(data)) {
1115 return ERR_FLATTEN_OBJECT;
1116 }
1117
1118 if (!data.WriteRemoteObject(observer->AsObject())) {
1119 TAG_LOGE(AAFwkTag::APPMGR, "observer write failed.");
1120 return ERR_FLATTEN_OBJECT;
1121 }
1122
1123 auto error = SendRequest(AppMgrInterfaceCode::UNREGISTER_CONFIGURATION_OBSERVER,
1124 data, reply, option);
1125 if (error != NO_ERROR) {
1126 TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error);
1127 return error;
1128 }
1129 return reply.ReadInt32();
1130 }
1131
GetAppRunningStateByBundleName(const std::string & bundleName)1132 bool AppMgrProxy::GetAppRunningStateByBundleName(const std::string &bundleName)
1133 {
1134 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1135 TAG_LOGD(AAFwkTag::APPMGR, "called");
1136 MessageParcel data;
1137 if (!WriteInterfaceToken(data)) {
1138 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1139 return false;
1140 }
1141
1142 if (!data.WriteString(bundleName)) {
1143 TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name failed.");
1144 return false;
1145 }
1146
1147 MessageParcel reply;
1148 MessageOption option;
1149 auto ret = SendRequest(AppMgrInterfaceCode::GET_APP_RUNNING_STATE,
1150 data, reply, option);
1151 if (ret != 0) {
1152 TAG_LOGW(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
1153 return false;
1154 }
1155
1156 return reply.ReadBool();
1157 }
1158
NotifyLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)1159 int32_t AppMgrProxy::NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback)
1160 {
1161 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1162 TAG_LOGD(AAFwkTag::APPMGR, "called");
1163 MessageParcel data;
1164 if (!WriteInterfaceToken(data)) {
1165 TAG_LOGE(AAFwkTag::APPMGR, "NotifyLoadRepairPatch, Write interface token failed.");
1166 return ERR_INVALID_DATA;
1167 }
1168
1169 if (!data.WriteString(bundleName)) {
1170 TAG_LOGE(AAFwkTag::APPMGR, "NotifyLoadRepairPatch, Write bundle name failed.");
1171 return ERR_INVALID_DATA;
1172 }
1173
1174 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
1175 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
1176 return ERR_INVALID_DATA;
1177 }
1178
1179 MessageParcel reply;
1180 MessageOption option;
1181 auto ret = SendRequest(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH,
1182 data, reply, option);
1183 if (ret != 0) {
1184 TAG_LOGW(AAFwkTag::APPMGR, "NotifyLoadRepairPatch, Send request failed with error code %{public}d.", ret);
1185 return ret;
1186 }
1187
1188 return reply.ReadInt32();
1189 }
1190
NotifyHotReloadPage(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)1191 int32_t AppMgrProxy::NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback)
1192 {
1193 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1194 TAG_LOGD(AAFwkTag::APPMGR, "called");
1195 MessageParcel data;
1196 if (!WriteInterfaceToken(data)) {
1197 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1198 return ERR_INVALID_DATA;
1199 }
1200
1201 if (!data.WriteString(bundleName)) {
1202 TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name failed.");
1203 return ERR_INVALID_DATA;
1204 }
1205
1206 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
1207 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
1208 return ERR_INVALID_DATA;
1209 }
1210
1211 MessageParcel reply;
1212 MessageOption option;
1213 auto ret = SendRequest(AppMgrInterfaceCode::NOTIFY_HOT_RELOAD_PAGE,
1214 data, reply, option);
1215 if (ret != 0) {
1216 TAG_LOGW(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
1217 return ret;
1218 }
1219
1220 return reply.ReadInt32();
1221 }
1222
1223 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
SetContinuousTaskProcess(int32_t pid,bool isContinuousTask)1224 int32_t AppMgrProxy::SetContinuousTaskProcess(int32_t pid, bool isContinuousTask)
1225 {
1226 TAG_LOGD(AAFwkTag::APPMGR, "SetContinuousTaskProcess start.");
1227 MessageParcel data;
1228 MessageParcel reply;
1229 MessageOption option;
1230
1231 if (!WriteInterfaceToken(data)) {
1232 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1233 return ERR_INVALID_DATA;
1234 }
1235
1236 if (!data.WriteInt32(pid)) {
1237 TAG_LOGE(AAFwkTag::APPMGR, "uid write failed.");
1238 return ERR_INVALID_DATA;
1239 }
1240
1241 if (!data.WriteBool(isContinuousTask)) {
1242 TAG_LOGE(AAFwkTag::APPMGR, "isContinuousTask write failed.");
1243 return ERR_INVALID_DATA;
1244 }
1245
1246 auto ret = SendRequest(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS,
1247 data, reply, option);
1248 if (ret != NO_ERROR) {
1249 TAG_LOGW(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
1250 return ret;
1251 }
1252
1253 return reply.ReadInt32();
1254 }
1255 #endif
1256
NotifyUnLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)1257 int32_t AppMgrProxy::NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback)
1258 {
1259 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1260 TAG_LOGD(AAFwkTag::APPMGR, "called");
1261 MessageParcel data;
1262 if (!WriteInterfaceToken(data)) {
1263 TAG_LOGE(AAFwkTag::APPMGR, "Notify unload patch, Write interface token failed.");
1264 return ERR_INVALID_DATA;
1265 }
1266
1267 if (!data.WriteString(bundleName)) {
1268 TAG_LOGE(AAFwkTag::APPMGR, "Notify unload patch, Write bundle name failed.");
1269 return ERR_INVALID_DATA;
1270 }
1271
1272 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
1273 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
1274 return ERR_INVALID_DATA;
1275 }
1276
1277 MessageParcel reply;
1278 MessageOption option;
1279
1280 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH, data, reply, option);
1281 return reply.ReadInt32();
1282 }
1283
IsSharedBundleRunning(const std::string & bundleName,uint32_t versionCode)1284 bool AppMgrProxy::IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode)
1285 {
1286 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1287 TAG_LOGD(AAFwkTag::APPMGR, "called");
1288 MessageParcel data;
1289 if (!WriteInterfaceToken(data)) {
1290 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1291 return false;
1292 }
1293 if (!data.WriteString(bundleName) || !data.WriteUint32(versionCode)) {
1294 TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name or version code failed.");
1295 return false;
1296 }
1297
1298 MessageParcel reply;
1299 MessageOption option;
1300 auto ret = SendRequest(AppMgrInterfaceCode::IS_SHARED_BUNDLE_RUNNING,
1301 data, reply, option);
1302 if (ret != NO_ERROR) {
1303 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
1304 return false;
1305 }
1306
1307 return reply.ReadBool();
1308 }
1309
StartNativeProcessForDebugger(const AAFwk::Want & want)1310 int32_t AppMgrProxy::StartNativeProcessForDebugger(const AAFwk::Want &want)
1311 {
1312 MessageParcel data;
1313 if (!WriteInterfaceToken(data)) {
1314 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1315 return ERR_FLATTEN_OBJECT;
1316 }
1317 if (!data.WriteParcelable(&want)) {
1318 TAG_LOGE(AAFwkTag::APPMGR, "want write failed.");
1319 return ERR_FLATTEN_OBJECT;
1320 }
1321
1322 MessageParcel reply;
1323 MessageOption option;
1324
1325 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER, data, reply, option);
1326 return reply.ReadInt32();
1327 }
1328
GetBundleNameByPid(const int pid,std::string & bundleName,int32_t & uid)1329 int32_t AppMgrProxy::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid)
1330 {
1331 MessageParcel data;
1332 MessageParcel reply;
1333 MessageOption option;
1334
1335 if (!WriteInterfaceToken(data)) {
1336 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1337 return ERR_INVALID_DATA;
1338 }
1339
1340 if (!data.WriteInt32(pid)) {
1341 TAG_LOGE(AAFwkTag::APPMGR, "pid write failed.");
1342 return ERR_INVALID_DATA;
1343 }
1344
1345 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID, data, reply, option);
1346 bundleName = reply.ReadString();
1347 uid = reply.ReadInt32();
1348 return ERR_NONE;
1349 }
1350
GetRunningProcessInfoByPid(const pid_t pid,OHOS::AppExecFwk::RunningProcessInfo & info)1351 int32_t AppMgrProxy::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info)
1352 {
1353 TAG_LOGD(AAFwkTag::APPMGR, "start");
1354 MessageParcel data;
1355 MessageParcel reply;
1356 MessageOption option;
1357 if (!WriteInterfaceToken(data)) {
1358 return ERR_INVALID_DATA;
1359 }
1360
1361 if (!data.WriteInt32(static_cast<int32_t>(pid))) {
1362 TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteInt32 failed.");
1363 return ERR_INVALID_DATA;
1364 }
1365
1366 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID, data, reply, option);
1367
1368 std::unique_ptr<AppExecFwk::RunningProcessInfo> processInfo(reply.ReadParcelable<AppExecFwk::RunningProcessInfo>());
1369 if (processInfo == nullptr) {
1370 TAG_LOGE(AAFwkTag::APPMGR, "recv process info failded");
1371 return ERR_INVALID_DATA;
1372 }
1373 info = *processInfo;
1374 return reply.ReadInt32();
1375 }
1376
GetRunningProcessInfoByChildProcessPid(const pid_t childPid,OHOS::AppExecFwk::RunningProcessInfo & info)1377 int32_t AppMgrProxy::GetRunningProcessInfoByChildProcessPid(const pid_t childPid,
1378 OHOS::AppExecFwk::RunningProcessInfo &info)
1379 {
1380 TAG_LOGD(AAFwkTag::APPMGR, "start");
1381 MessageParcel data;
1382 MessageParcel reply;
1383 MessageOption option;
1384 if (!WriteInterfaceToken(data)) {
1385 return ERR_INVALID_DATA;
1386 }
1387
1388 if (!data.WriteInt32(static_cast<int32_t>(childPid))) {
1389 TAG_LOGE(AAFwkTag::APPMGR, "parcel childPid failed.");
1390 return ERR_INVALID_DATA;
1391 }
1392
1393 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_CHILD_PROCESS_PID,
1394 data, reply, option);
1395
1396 std::unique_ptr<AppExecFwk::RunningProcessInfo> processInfo(reply.ReadParcelable<AppExecFwk::RunningProcessInfo>());
1397 if (processInfo == nullptr) {
1398 TAG_LOGE(AAFwkTag::APPMGR, "recv process info failded");
1399 return ERR_INVALID_DATA;
1400 }
1401 info = *processInfo;
1402 return reply.ReadInt32();
1403 }
1404
NotifyAppFault(const FaultData & faultData)1405 int32_t AppMgrProxy::NotifyAppFault(const FaultData &faultData)
1406 {
1407 TAG_LOGI(AAFwkTag::APPMGR, "called");
1408 MessageParcel data;
1409
1410 if (!WriteInterfaceToken(data)) {
1411 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1412 return ERR_FLATTEN_OBJECT;
1413 }
1414
1415 if (!data.WriteParcelable(&faultData)) {
1416 TAG_LOGE(AAFwkTag::APPMGR, "Write FaultData error.");
1417 return ERR_FLATTEN_OBJECT;
1418 }
1419
1420 MessageParcel reply;
1421 MessageOption option;
1422
1423 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_APP_FAULT, data, reply, option);
1424 return reply.ReadInt32();
1425 }
1426
NotifyAppFaultBySA(const AppFaultDataBySA & faultData)1427 int32_t AppMgrProxy::NotifyAppFaultBySA(const AppFaultDataBySA &faultData)
1428 {
1429 TAG_LOGI(AAFwkTag::APPMGR, "called");
1430 MessageParcel data;
1431
1432 if (!WriteInterfaceToken(data)) {
1433 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1434 return ERR_FLATTEN_OBJECT;
1435 }
1436
1437 if (!data.WriteParcelable(&faultData)) {
1438 TAG_LOGE(AAFwkTag::APPMGR, "Write FaultDataBySA error.");
1439 return ERR_FLATTEN_OBJECT;
1440 }
1441
1442 MessageParcel reply;
1443 MessageOption option;
1444
1445 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA, data, reply, option);
1446 return reply.ReadInt32();
1447 }
1448
SetAppFreezeFilter(int32_t pid)1449 bool AppMgrProxy::SetAppFreezeFilter(int32_t pid)
1450 {
1451 TAG_LOGD(AAFwkTag::APPMGR, "called");
1452 MessageParcel data;
1453 MessageParcel reply;
1454 MessageOption option;
1455 if (!WriteInterfaceToken(data)) {
1456 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1457 return false;
1458 }
1459 if (!data.WriteInt32(pid)) {
1460 TAG_LOGE(AAFwkTag::APPMGR, "write pid failed.");
1461 return false;
1462 }
1463 auto ret = SendRequest(AppMgrInterfaceCode::SET_APPFREEZE_FILTER,
1464 data, reply, option);
1465 if (ret != NO_ERROR) {
1466 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
1467 return false;
1468 }
1469 return reply.ReadBool();
1470 }
1471
GetProcessMemoryByPid(const int32_t pid,int32_t & memorySize)1472 int32_t AppMgrProxy::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize)
1473 {
1474 TAG_LOGD(AAFwkTag::APPMGR, "GetProcessMemoryByPid start");
1475 MessageParcel data;
1476 MessageParcel reply;
1477 MessageOption option;
1478 if (!WriteInterfaceToken(data)) {
1479 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1480 return ERR_FLATTEN_OBJECT;
1481 }
1482
1483 if (!data.WriteInt32(pid)) {
1484 TAG_LOGE(AAFwkTag::APPMGR, "write pid failed.");
1485 return ERR_INVALID_DATA;
1486 }
1487
1488 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID, data, reply, option);
1489 memorySize = reply.ReadInt32();
1490 auto result = reply.ReadInt32();
1491 return result;
1492 }
1493
GetRunningProcessInformation(const std::string & bundleName,int32_t userId,std::vector<RunningProcessInfo> & info)1494 int32_t AppMgrProxy::GetRunningProcessInformation(
1495 const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info)
1496 {
1497 TAG_LOGD(AAFwkTag::APPMGR, "GetRunningProcessInformation start");
1498 MessageParcel data;
1499 MessageParcel reply;
1500 if (!WriteInterfaceToken(data)) {
1501 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1502 return ERR_FLATTEN_OBJECT;
1503 }
1504
1505 if (!data.WriteString(bundleName)) {
1506 TAG_LOGE(AAFwkTag::APPMGR, "write bundleName failed.");
1507 return ERR_INVALID_DATA;
1508 }
1509
1510 if (!data.WriteInt32(userId)) {
1511 TAG_LOGE(AAFwkTag::APPMGR, "write userId failed.");
1512 return ERR_INVALID_DATA;
1513 }
1514
1515 MessageOption option(MessageOption::TF_SYNC);
1516 auto ret = SendRequest(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME,
1517 data, reply, option);
1518 if (ret != NO_ERROR) {
1519 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
1520 return ret;
1521 }
1522
1523 auto error = GetParcelableInfos<RunningProcessInfo>(reply, info);
1524 if (error != NO_ERROR) {
1525 TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error);
1526 return error;
1527 }
1528 return reply.ReadInt32();
1529 }
1530
ChangeAppGcState(pid_t pid,int32_t state,uint64_t tid)1531 int32_t AppMgrProxy::ChangeAppGcState(pid_t pid, int32_t state, uint64_t tid)
1532 {
1533 TAG_LOGD(AAFwkTag::APPMGR, "called");
1534 MessageParcel data;
1535 MessageParcel reply;
1536 if (!WriteInterfaceToken(data)) {
1537 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1538 return ERR_FLATTEN_OBJECT;
1539 }
1540 MessageOption option(MessageOption::TF_ASYNC);
1541 if (!data.WriteInt32(pid)) {
1542 TAG_LOGE(AAFwkTag::APPMGR, "Pid write failed.");
1543 return ERR_FLATTEN_OBJECT;
1544 }
1545 if (!data.WriteInt32(state)) {
1546 TAG_LOGE(AAFwkTag::APPMGR, "State write failed.");
1547 return ERR_FLATTEN_OBJECT;
1548 }
1549 if (!data.WriteUint64(tid)) {
1550 TAG_LOGE(AAFwkTag::APPMGR, "tid write failed.");
1551 return ERR_FLATTEN_OBJECT;
1552 }
1553
1554 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CHANGE_APP_GC_STATE, data, reply, option);
1555 return NO_ERROR;
1556 }
1557
NotifyPageShow(const sptr<IRemoteObject> & token,const PageStateData & pageStateData)1558 int32_t AppMgrProxy::NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData)
1559 {
1560 TAG_LOGD(AAFwkTag::APPMGR, "call");
1561 MessageParcel data;
1562 MessageParcel reply;
1563 MessageOption option(MessageOption::TF_ASYNC);
1564
1565 if (!WriteInterfaceToken(data)) {
1566 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1567 return ERR_FLATTEN_OBJECT;
1568 }
1569 if (!data.WriteRemoteObject(token)) {
1570 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1571 return ERR_INVALID_DATA;
1572 }
1573 if (!data.WriteParcelable(&pageStateData)) {
1574 TAG_LOGE(AAFwkTag::APPMGR, "Write PageStateData error.");
1575 return ERR_FLATTEN_OBJECT;
1576 }
1577
1578 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PAGE_SHOW, data, reply, option);
1579 return NO_ERROR;
1580 }
1581
NotifyPageHide(const sptr<IRemoteObject> & token,const PageStateData & pageStateData)1582 int32_t AppMgrProxy::NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData)
1583 {
1584 TAG_LOGD(AAFwkTag::APPMGR, "called");
1585 MessageParcel data;
1586 MessageParcel reply;
1587 MessageOption option(MessageOption::TF_ASYNC);
1588
1589 if (!WriteInterfaceToken(data)) {
1590 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1591 return ERR_FLATTEN_OBJECT;
1592 }
1593 if (!data.WriteRemoteObject(token)) {
1594 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1595 return ERR_INVALID_DATA;
1596 }
1597 if (!data.WriteParcelable(&pageStateData)) {
1598 TAG_LOGE(AAFwkTag::APPMGR, "Write PageStateData error.");
1599 return ERR_FLATTEN_OBJECT;
1600 }
1601
1602 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PAGE_HIDE, data, reply, option);
1603 return NO_ERROR;
1604 }
1605
SendRequest(AppMgrInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1606 int32_t AppMgrProxy::SendRequest(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply,
1607 MessageOption& option)
1608 {
1609 sptr<IRemoteObject> remote = Remote();
1610 if (remote == nullptr) {
1611 TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
1612 return ERR_NULL_OBJECT;
1613 }
1614
1615 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
1616 }
1617
RegisterAppRunningStatusListener(const sptr<IRemoteObject> & listener)1618 int32_t AppMgrProxy::RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
1619 {
1620 MessageParcel data;
1621 if (!WriteInterfaceToken(data)) {
1622 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1623 return ERR_FLATTEN_OBJECT;
1624 }
1625 if (listener == nullptr || !data.WriteRemoteObject(listener)) {
1626 TAG_LOGE(AAFwkTag::APPMGR, "Write listener failed.");
1627 return ERR_FLATTEN_OBJECT;
1628 }
1629
1630 MessageParcel reply;
1631 MessageOption option;
1632
1633 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_APP_RUNNING_STATUS_LISTENER, data, reply, option);
1634 return reply.ReadInt32();
1635 }
1636
UnregisterAppRunningStatusListener(const sptr<IRemoteObject> & listener)1637 int32_t AppMgrProxy::UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
1638 {
1639 MessageParcel data;
1640 if (!WriteInterfaceToken(data)) {
1641 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1642 return ERR_FLATTEN_OBJECT;
1643 }
1644 if (listener == nullptr || !data.WriteRemoteObject(listener)) {
1645 TAG_LOGE(AAFwkTag::APPMGR, "Write listener failed.");
1646 return ERR_FLATTEN_OBJECT;
1647 }
1648
1649 MessageParcel reply;
1650 MessageOption option;
1651
1652 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_APP_RUNNING_STATUS_LISTENER, data, reply, option);
1653 return reply.ReadInt32();
1654 }
1655
RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> & observer)1656 int32_t AppMgrProxy::RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer)
1657 {
1658 MessageParcel data;
1659 if (!WriteInterfaceToken(data)) {
1660 return ERR_FLATTEN_OBJECT;
1661 }
1662 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
1663 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null or Write Remote failed.");
1664 return ERR_FLATTEN_OBJECT;
1665 }
1666 MessageParcel reply;
1667 MessageOption option;
1668
1669 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_APP_FOREGROUND_STATE_OBSERVER, data, reply, option);
1670 return reply.ReadInt32();
1671 }
1672
UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> & observer)1673 int32_t AppMgrProxy::UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer)
1674 {
1675 MessageParcel data;
1676 if (!WriteInterfaceToken(data)) {
1677 return ERR_FLATTEN_OBJECT;
1678 }
1679 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
1680 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null or Write Remote failed.");
1681 return ERR_FLATTEN_OBJECT;
1682 }
1683
1684 MessageParcel reply;
1685 MessageOption option;
1686
1687 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_APP_FOREGROUND_STATE_OBSERVER, data, reply, option);
1688 return reply.ReadInt32();
1689 }
1690
IsApplicationRunning(const std::string & bundleName,bool & isRunning)1691 int32_t AppMgrProxy::IsApplicationRunning(const std::string &bundleName, bool &isRunning)
1692 {
1693 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1694 TAG_LOGD(AAFwkTag::APPMGR, "called");
1695 isRunning = false;
1696 MessageParcel data;
1697 MessageParcel reply;
1698 MessageOption option;
1699 if (!WriteInterfaceToken(data)) {
1700 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1701 return ERR_INVALID_DATA;
1702 }
1703 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
1704
1705 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_APPLICATION_RUNNING, data, reply, option);
1706 isRunning = reply.ReadBool();
1707 return reply.ReadInt32();
1708 }
1709
IsAppRunning(const std::string & bundleName,int32_t appCloneIndex,bool & isRunning)1710 int32_t AppMgrProxy::IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)
1711 {
1712 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1713 TAG_LOGD(AAFwkTag::APPMGR, "called");
1714 MessageParcel data;
1715 if (!WriteInterfaceToken(data)) {
1716 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1717 return ERR_INVALID_DATA;
1718 }
1719 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
1720 PARCEL_UTIL_WRITE_RET_INT(data, Int32, appCloneIndex);
1721
1722 MessageParcel reply;
1723 MessageOption option;
1724
1725 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_APP_RUNNING, data, reply, option);
1726 isRunning = reply.ReadBool();
1727 return reply.ReadInt32();
1728 }
1729
IsAppRunningByBundleNameAndUserId(const std::string & bundleName,int32_t userId,bool & isRunning)1730 int32_t AppMgrProxy::IsAppRunningByBundleNameAndUserId(const std::string &bundleName, int32_t userId, bool &isRunning)
1731 {
1732 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1733 TAG_LOGD(AAFwkTag::APPMGR, "called");
1734 MessageParcel data;
1735 if (!WriteInterfaceToken(data)) {
1736 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1737 return ERR_INVALID_DATA;
1738 }
1739 PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName);
1740 PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId);
1741
1742 MessageParcel reply;
1743 MessageOption option;
1744
1745 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_APP_RUNNING_BY_BUNDLE_NAME_AND_USER_ID, data, reply, option);
1746 isRunning = reply.ReadBool();
1747 return reply.ReadInt32();
1748 }
1749
1750 #ifdef SUPPORT_CHILD_PROCESS
StartChildProcess(pid_t & childPid,const ChildProcessRequest & request)1751 int32_t AppMgrProxy::StartChildProcess(pid_t &childPid, const ChildProcessRequest &request)
1752 {
1753 TAG_LOGD(AAFwkTag::APPMGR, "called");
1754 if (request.srcEntry.empty()) {
1755 TAG_LOGE(AAFwkTag::APPMGR, "Invalid params, srcEntry:%{private}s", request.srcEntry.c_str());
1756 return ERR_INVALID_VALUE;
1757 }
1758 MessageParcel data;
1759 if (!WriteInterfaceToken(data)) {
1760 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1761 return IPC_PROXY_ERR;
1762 }
1763 if (!data.WriteParcelable(&request)) {
1764 TAG_LOGE(AAFwkTag::APPMGR, "Write param request failed.");
1765 return IPC_PROXY_ERR;
1766 }
1767
1768 MessageParcel reply;
1769 MessageOption option;
1770
1771 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_CHILD_PROCESS, data, reply, option);
1772 auto result = reply.ReadInt32();
1773 if (result == ERR_OK) {
1774 childPid = reply.ReadInt32();
1775 }
1776 return result;
1777 }
1778
GetChildProcessInfoForSelf(ChildProcessInfo & info)1779 int32_t AppMgrProxy::GetChildProcessInfoForSelf(ChildProcessInfo &info)
1780 {
1781 TAG_LOGD(AAFwkTag::APPMGR, "called");
1782 MessageParcel data;
1783 MessageParcel reply;
1784 MessageOption option;
1785 if (!WriteInterfaceToken(data)) {
1786 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1787 return ERR_FLATTEN_OBJECT;
1788 }
1789
1790 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_CHILD_PROCCESS_INFO_FOR_SELF, data, reply, option);
1791 auto result = reply.ReadInt32();
1792 if (result == ERR_OK) {
1793 std::unique_ptr<ChildProcessInfo> infoReply(reply.ReadParcelable<ChildProcessInfo>());
1794 info = *infoReply;
1795 }
1796 return result;
1797 }
1798
AttachChildProcess(const sptr<IRemoteObject> & childScheduler)1799 void AppMgrProxy::AttachChildProcess(const sptr<IRemoteObject> &childScheduler)
1800 {
1801 TAG_LOGD(AAFwkTag::APPMGR, "called");
1802 if (!childScheduler) {
1803 TAG_LOGE(AAFwkTag::APPMGR, "childScheduler is null");
1804 return;
1805 }
1806 MessageParcel data;
1807 MessageParcel reply;
1808 MessageOption option;
1809 if (!WriteInterfaceToken(data)) {
1810 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1811 return;
1812 }
1813 PARCEL_UTIL_WRITE_NORET(data, RemoteObject, childScheduler.GetRefPtr());
1814
1815 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::ATTACH_CHILD_PROCESS, data, reply, option);
1816 }
1817
ExitChildProcessSafely()1818 void AppMgrProxy::ExitChildProcessSafely()
1819 {
1820 TAG_LOGD(AAFwkTag::APPMGR, "called");
1821 MessageParcel data;
1822 MessageParcel reply;
1823 MessageOption option;
1824 if (!WriteInterfaceToken(data)) {
1825 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1826 return;
1827 }
1828
1829 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY, data, reply, option);
1830 }
1831 #endif // SUPPORT_CHILD_PROCESS
1832
IsFinalAppProcess()1833 bool AppMgrProxy::IsFinalAppProcess()
1834 {
1835 TAG_LOGD(AAFwkTag::APPMGR, "called");
1836 MessageParcel data;
1837 if (!WriteInterfaceToken(data)) {
1838 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1839 return false;
1840 }
1841
1842 MessageParcel reply;
1843 MessageOption option;
1844 auto ret = SendRequest(AppMgrInterfaceCode::IS_FINAL_APP_PROCESS,
1845 data, reply, option);
1846 if (ret != NO_ERROR) {
1847 TAG_LOGE(AAFwkTag::APPMGR, "Send request is failed, error code: %{public}d", ret);
1848 return false;
1849 }
1850
1851 return reply.ReadBool();
1852 }
1853
RegisterRenderStateObserver(const sptr<IRenderStateObserver> & observer)1854 int32_t AppMgrProxy::RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer)
1855 {
1856 TAG_LOGD(AAFwkTag::APPMGR, "called");
1857 MessageParcel data;
1858 if (!WriteInterfaceToken(data)) {
1859 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1860 return ERR_INVALID_DATA;
1861 }
1862 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
1863 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null or Write Remote failed.");
1864 return ERR_FLATTEN_OBJECT;
1865 }
1866
1867 MessageParcel reply;
1868 MessageOption option;
1869
1870 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_RENDER_STATUS_OBSERVER, data, reply, option);
1871 return reply.ReadInt32();
1872 }
1873
UnregisterRenderStateObserver(const sptr<IRenderStateObserver> & observer)1874 int32_t AppMgrProxy::UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer)
1875 {
1876 TAG_LOGD(AAFwkTag::APPMGR, "called");
1877 MessageParcel data;
1878 if (!WriteInterfaceToken(data)) {
1879 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1880 return ERR_INVALID_DATA;
1881 }
1882 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
1883 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null or Write Remote failed.");
1884 return ERR_FLATTEN_OBJECT;
1885 }
1886
1887 MessageParcel reply;
1888 MessageOption option;
1889
1890 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_RENDER_STATUS_OBSERVER, data, reply, option);
1891 return reply.ReadInt32();
1892 }
1893
UpdateRenderState(pid_t renderPid,int32_t state)1894 int32_t AppMgrProxy::UpdateRenderState(pid_t renderPid, int32_t state)
1895 {
1896 TAG_LOGD(AAFwkTag::APPMGR, "called");
1897 MessageParcel data;
1898 if (!WriteInterfaceToken(data)) {
1899 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1900 return ERR_INVALID_DATA;
1901 }
1902 PARCEL_UTIL_WRITE_RET_INT(data, Int32, renderPid);
1903 PARCEL_UTIL_WRITE_RET_INT(data, Int32, state);
1904
1905 MessageParcel reply;
1906 MessageOption option;
1907
1908 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UPDATE_RENDER_STATUS, data, reply, option);
1909 return reply.ReadInt32();
1910 }
1911
SignRestartAppFlag(int32_t uid,const std::string & instanceKey)1912 int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
1913 {
1914 TAG_LOGD(AAFwkTag::APPMGR, "called");
1915 MessageParcel data;
1916 MessageParcel reply;
1917 MessageOption option;
1918 if (!WriteInterfaceToken(data)) {
1919 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1920 return IPC_PROXY_ERR;
1921 }
1922 PARCEL_UTIL_WRITE_RET_INT(data, Int32, uid);
1923 PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
1924
1925 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SIGN_RESTART_APP_FLAG, data, reply, option);
1926 return reply.ReadInt32();
1927 }
1928
GetAppRunningUniqueIdByPid(pid_t pid,std::string & appRunningUniqueId)1929 int32_t AppMgrProxy::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
1930 {
1931 TAG_LOGD(AAFwkTag::APPMGR, "called");
1932 MessageParcel data;
1933 MessageParcel reply;
1934 MessageOption option;
1935 if (!WriteInterfaceToken(data)) {
1936 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1937 return IPC_PROXY_ERR;
1938 }
1939 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
1940
1941 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_APP_RUNNING_UNIQUE_ID_BY_PID, data, reply, option);
1942 auto result = reply.ReadInt32();
1943 if (result == ERR_OK) {
1944 appRunningUniqueId = reply.ReadString();
1945 TAG_LOGD(AAFwkTag::APPMGR, "appRunningUniqueId = %{public}s", appRunningUniqueId.c_str());
1946 }
1947 return result;
1948 }
1949
GetAllUIExtensionRootHostPid(pid_t pid,std::vector<pid_t> & hostPids)1950 int32_t AppMgrProxy::GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids)
1951 {
1952 MessageParcel data;
1953 if (!WriteInterfaceToken(data)) {
1954 TAG_LOGE(AAFwkTag::APPMGR, "Write remote object failed.");
1955 return ERR_INVALID_DATA;
1956 }
1957
1958 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
1959
1960 MessageParcel reply;
1961 MessageOption option;
1962
1963 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID, data, reply, option);
1964
1965 int32_t size = reply.ReadInt32();
1966 if (size > CYCLE_LIMIT) {
1967 TAG_LOGE(AAFwkTag::APPMGR, "Vector is too large.");
1968 return ERR_INVALID_VALUE;
1969 }
1970
1971 for (int32_t i = 0; i < size; i++) {
1972 pid_t temp = reply.ReadInt32();
1973 hostPids.emplace_back(temp);
1974 }
1975
1976 return reply.ReadInt32();
1977 }
1978
GetAllUIExtensionProviderPid(pid_t hostPid,std::vector<pid_t> & providerPids)1979 int32_t AppMgrProxy::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids)
1980 {
1981 MessageParcel data;
1982 if (!WriteInterfaceToken(data)) {
1983 TAG_LOGE(AAFwkTag::APPMGR, "Write remote object failed.");
1984 return ERR_INVALID_DATA;
1985 }
1986 PARCEL_UTIL_WRITE_RET_INT(data, Int32, hostPid);
1987
1988 MessageParcel reply;
1989 MessageOption option;
1990
1991 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_PROVIDER_PID, data, reply, option);
1992
1993 int32_t size = reply.ReadInt32();
1994 if (size > CYCLE_LIMIT) {
1995 TAG_LOGE(AAFwkTag::APPMGR, "Vector is too large.");
1996 return ERR_INVALID_VALUE;
1997 }
1998
1999 for (int32_t i = 0; i < size; i++) {
2000 pid_t temp = reply.ReadInt32();
2001 providerPids.emplace_back(temp);
2002 }
2003
2004 return reply.ReadInt32();
2005 }
2006
NotifyMemorySizeStateChanged(int32_t memorySizeState)2007 int32_t AppMgrProxy::NotifyMemorySizeStateChanged(int32_t memorySizeState)
2008 {
2009 MessageParcel data;
2010 if (!WriteInterfaceToken(data)) {
2011 return ERR_INVALID_DATA;
2012 }
2013 PARCEL_UTIL_WRITE_RET_INT(data, Int32, memorySizeState);
2014
2015 MessageParcel reply;
2016 MessageOption option;
2017
2018 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_MEMORY_SIZE_STATE_CHANGED, data, reply, option);
2019 return reply.ReadInt32();
2020 }
2021
SetSupportedProcessCacheSelf(bool isSupport)2022 int32_t AppMgrProxy::SetSupportedProcessCacheSelf(bool isSupport)
2023 {
2024 TAG_LOGD(AAFwkTag::APPMGR, "called");
2025 MessageParcel data;
2026 if (!WriteInterfaceToken(data)) {
2027 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2028 return ERR_INVALID_DATA;
2029 }
2030 PARCEL_UTIL_WRITE_RET_INT(data, Bool, isSupport);
2031
2032 MessageParcel reply;
2033 MessageOption option;
2034
2035 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF, data, reply, option);
2036 return reply.ReadInt32();
2037 }
2038
SetSupportedProcessCache(int32_t pid,bool isSupport)2039 int32_t AppMgrProxy::SetSupportedProcessCache(int32_t pid, bool isSupport)
2040 {
2041 TAG_LOGD(AAFwkTag::APPMGR, "called");
2042 MessageParcel data;
2043 if (!WriteInterfaceToken(data)) {
2044 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2045 return ERR_INVALID_DATA;
2046 }
2047 PARCEL_UTIL_WRITE_RET_INT(data, Bool, isSupport);
2048 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
2049
2050 MessageParcel reply;
2051 MessageOption option;
2052
2053 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE, data, reply, option);
2054 return reply.ReadInt32();
2055 }
2056
IsProcessCacheSupported(int32_t pid,bool & isSupported)2057 int32_t AppMgrProxy::IsProcessCacheSupported(int32_t pid, bool &isSupported)
2058 {
2059 TAG_LOGD(AAFwkTag::APPMGR, "IsProcessCacheSupported called");
2060 MessageParcel data;
2061 if (!WriteInterfaceToken(data)) {
2062 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2063 return AAFwk::ERR_WRITE_INTERFACE_TOKEN_FAILED;
2064 }
2065 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
2066
2067 MessageParcel reply;
2068 MessageOption option;
2069
2070 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_PROCESS_CACHE_SUPPORTED, data, reply, option);
2071 isSupported = reply.ReadBool();
2072 return reply.ReadInt32();
2073 }
2074
SetProcessCacheEnable(int32_t pid,bool enable)2075 int32_t AppMgrProxy::SetProcessCacheEnable(int32_t pid, bool enable)
2076 {
2077 TAG_LOGD(AAFwkTag::APPMGR, "SetProcessCacheEnable called");
2078 MessageParcel data;
2079 if (!WriteInterfaceToken(data)) {
2080 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2081 return AAFwk::ERR_WRITE_INTERFACE_TOKEN_FAILED;
2082 }
2083 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
2084 PARCEL_UTIL_WRITE_RET_INT(data, Bool, enable);
2085
2086 MessageParcel reply;
2087 MessageOption option;
2088
2089 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SET_PROCESS_CACHE_ENABLE, data, reply, option);
2090 return reply.ReadInt32();
2091 }
2092
SetAppAssertionPauseState(bool flag)2093 void AppMgrProxy::SetAppAssertionPauseState(bool flag)
2094 {
2095 TAG_LOGD(AAFwkTag::APPMGR, "called");
2096 MessageParcel data;
2097 MessageParcel reply;
2098 MessageOption option;
2099 if (!WriteInterfaceToken(data)) {
2100 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2101 return;
2102 }
2103 PARCEL_UTIL_WRITE_NORET(data, Bool, flag);
2104
2105 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::SET_APP_ASSERT_PAUSE_STATE_SELF, data, reply, option);
2106 }
2107
2108 #ifdef SUPPORT_CHILD_PROCESS
CreateNativeChildProcess(const std::string & libName,int32_t childProcessCount,const sptr<IRemoteObject> & callback,const std::string & customProcessName)2109 int32_t AppMgrProxy::CreateNativeChildProcess(const std::string &libName, int32_t childProcessCount,
2110 const sptr<IRemoteObject> &callback, const std::string &customProcessName)
2111 {
2112 TAG_LOGD(AAFwkTag::APPMGR, "called");
2113 if (libName.empty() || !callback) {
2114 TAG_LOGE(AAFwkTag::APPMGR, "Invalid params, libName:%{private}s", libName.c_str());
2115 return ERR_INVALID_VALUE;
2116 }
2117
2118 MessageParcel data;
2119 MessageParcel reply;
2120 MessageOption option;
2121 if (!WriteInterfaceToken(data)) {
2122 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2123 return IPC_PROXY_ERR;
2124 }
2125 PARCEL_UTIL_WRITE_RET_INT(data, String, libName);
2126 PARCEL_UTIL_WRITE_RET_INT(data, Int32, childProcessCount);
2127 PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, callback);
2128 PARCEL_UTIL_WRITE_RET_INT(data, String, customProcessName);
2129
2130 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CREATE_NATIVE_CHILD_PROCESS, data, reply, option);
2131 return reply.ReadInt32();
2132 }
2133 #endif // SUPPORT_CHILD_PROCESS
2134
RegisterNativeChildExitNotify(const sptr<INativeChildNotify> notify)2135 int AppMgrProxy::RegisterNativeChildExitNotify(const sptr<INativeChildNotify> notify)
2136 {
2137 if (!notify) {
2138 TAG_LOGE(AAFwkTag::APPMGR, "notify null");
2139 return ERR_INVALID_VALUE;
2140 }
2141 TAG_LOGD(AAFwkTag::APPMGR, "RegisterNativeChildExitNotify start");
2142 MessageParcel data;
2143 MessageParcel reply;
2144 MessageOption option;
2145 if (!WriteInterfaceToken(data)) {
2146 return ERR_FLATTEN_OBJECT;
2147 }
2148 if (!data.WriteRemoteObject(notify->AsObject())) {
2149 TAG_LOGE(AAFwkTag::APPMGR, "notify write failed.");
2150 return ERR_FLATTEN_OBJECT;
2151 }
2152
2153 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_NATIVE_CHILD_EXIT_NOTIFY, data, reply, option);
2154 return reply.ReadInt32();
2155 }
2156
UnregisterNativeChildExitNotify(const sptr<INativeChildNotify> notify)2157 int AppMgrProxy::UnregisterNativeChildExitNotify(const sptr<INativeChildNotify> notify)
2158 {
2159 if (!notify) {
2160 TAG_LOGE(AAFwkTag::APPMGR, "notify null");
2161 return ERR_INVALID_VALUE;
2162 }
2163 TAG_LOGD(AAFwkTag::APPMGR, "UnregisterNativeChildExitNotify start");
2164 MessageParcel data;
2165 MessageParcel reply;
2166 MessageOption option;
2167 if (!WriteInterfaceToken(data)) {
2168 return ERR_FLATTEN_OBJECT;
2169 }
2170 if (!data.WriteRemoteObject(notify->AsObject())) {
2171 TAG_LOGE(AAFwkTag::APPMGR, "notify write failed.");
2172 return ERR_FLATTEN_OBJECT;
2173 }
2174
2175 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_NATIVE_CHILD_EXIT_NOTIFY, data, reply, option);
2176 return reply.ReadInt32();
2177 }
2178
CheckCallingIsUserTestMode(const pid_t pid,bool & isUserTest)2179 int32_t AppMgrProxy::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest)
2180 {
2181 MessageParcel data;
2182 MessageParcel reply;
2183 MessageOption option(MessageOption::TF_SYNC);
2184 if (!WriteInterfaceToken(data)) {
2185 return ERR_FLATTEN_OBJECT;
2186 }
2187 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
2188 int32_t ret = SendRequest(AppMgrInterfaceCode::CHECK_CALLING_IS_USER_TEST_MODE, data, reply, option);
2189 if (ret != NO_ERROR) {
2190 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
2191 isUserTest = false;
2192 return ret;
2193 }
2194 isUserTest = reply.ReadBool();
2195 return reply.ReadInt32();
2196 }
2197
NotifyProcessDependedOnWeb()2198 int32_t AppMgrProxy::NotifyProcessDependedOnWeb()
2199 {
2200 MessageParcel data;
2201 MessageParcel reply;
2202 MessageOption option;
2203 if (!WriteInterfaceToken(data)) {
2204 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2205 return IPC_PROXY_ERR;
2206 }
2207
2208 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PROCESS_DEPENDED_ON_WEB, data, reply, option);
2209 return reply.ReadInt32();
2210 }
2211
KillProcessDependedOnWeb()2212 void AppMgrProxy::KillProcessDependedOnWeb()
2213 {
2214 MessageParcel data;
2215 MessageParcel reply;
2216 MessageOption option;
2217 if (!WriteInterfaceToken(data)) {
2218 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2219 return;
2220 }
2221
2222 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::KILL_PROCESS_DEPENDED_ON_WEB, data, reply, option);
2223 }
2224
RestartResidentProcessDependedOnWeb()2225 void AppMgrProxy::RestartResidentProcessDependedOnWeb()
2226 {
2227 MessageParcel data;
2228 MessageParcel reply;
2229 MessageOption option(MessageOption::TF_ASYNC);
2230 if (!WriteInterfaceToken(data)) {
2231 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2232 return;
2233 }
2234
2235 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB, data, reply, option);
2236 }
2237
GetSupportedProcessCachePids(const std::string & bundleName,std::vector<int32_t> & pidList)2238 int32_t AppMgrProxy::GetSupportedProcessCachePids(const std::string &bundleName,
2239 std::vector<int32_t> &pidList)
2240 {
2241 TAG_LOGD(AAFwkTag::APPMGR, "Called.");
2242 MessageParcel data;
2243 MessageParcel reply;
2244 MessageOption option(MessageOption::TF_SYNC);
2245 if (!WriteInterfaceToken(data)) {
2246 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2247 return ERR_FLATTEN_OBJECT;
2248 }
2249 if (!data.WriteString(bundleName)) {
2250 TAG_LOGE(AAFwkTag::APPMGR, "write bundleName failed.");
2251 return ERR_INVALID_VALUE;
2252 }
2253 auto ret = SendRequest(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS, data, reply, option);
2254 if (ret != NO_ERROR) {
2255 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
2256 return ret;
2257 }
2258
2259 pidList.clear();
2260 int32_t infoSize = reply.ReadInt32();
2261 if (infoSize > CYCLE_LIMIT) {
2262 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
2263 return ERR_INVALID_VALUE;
2264 }
2265 for (int32_t i = 0; i < infoSize; i++) {
2266 pidList.push_back(reply.ReadInt32());
2267 }
2268 return reply.ReadInt32();
2269 }
2270
RegisterKiaInterceptor(const sptr<IKiaInterceptor> & interceptor)2271 int32_t AppMgrProxy::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
2272 {
2273 if (interceptor == nullptr) {
2274 TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
2275 return ERR_INVALID_VALUE;
2276 }
2277 MessageParcel data;
2278 MessageParcel reply;
2279 MessageOption option(MessageOption::TF_SYNC);
2280 if (!WriteInterfaceToken(data)) {
2281 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2282 return ERR_INVALID_VALUE;
2283 }
2284
2285 if (!data.WriteRemoteObject(interceptor->AsObject())) {
2286 TAG_LOGE(AAFwkTag::APPMGR, "write interceptor failed.");
2287 return ERR_INVALID_VALUE;
2288 }
2289
2290 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR, data, reply, option);
2291 return reply.ReadInt32();
2292 }
2293
CheckIsKiaProcess(pid_t pid,bool & isKia)2294 int32_t AppMgrProxy::CheckIsKiaProcess(pid_t pid, bool &isKia)
2295 {
2296 MessageParcel data;
2297 MessageParcel reply;
2298 MessageOption option(MessageOption::TF_SYNC);
2299 if (!WriteInterfaceToken(data)) {
2300 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2301 return ERR_INVALID_VALUE;
2302 }
2303
2304 if (!data.WriteInt32(pid)) {
2305 TAG_LOGE(AAFwkTag::APPMGR, "write pid failed.");
2306 return ERR_INVALID_VALUE;
2307 }
2308
2309 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS, data, reply, option);
2310 int32_t ret = reply.ReadInt32();
2311 if (ret != ERR_OK) {
2312 TAG_LOGE(AAFwkTag::APPMGR, "failed,ret=%{public}d.", ret);
2313 return ret;
2314 }
2315 isKia = reply.ReadBool();
2316 return ERR_OK;
2317 }
2318
KillAppSelfWithInstanceKey(const std::string & instanceKey,bool clearPageStack,const std::string & reason)2319 int32_t AppMgrProxy::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
2320 const std::string& reason)
2321 {
2322 MessageParcel data;
2323 if (!WriteInterfaceToken(data)) {
2324 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2325 return ERR_INVALID_VALUE;
2326 }
2327 PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
2328 PARCEL_UTIL_WRITE_RET_INT(data, Bool, clearPageStack);
2329 PARCEL_UTIL_WRITE_RET_INT(data, String, reason);
2330
2331 MessageParcel reply;
2332 MessageOption option(MessageOption::TF_SYNC);
2333 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY, data, reply, option);
2334 return reply.ReadInt32();
2335 }
2336
UpdateInstanceKeyBySpecifiedId(int32_t specifiedId,std::string & instanceKey)2337 void AppMgrProxy::UpdateInstanceKeyBySpecifiedId(int32_t specifiedId, std::string &instanceKey)
2338 {
2339 MessageParcel data;
2340 if (!WriteInterfaceToken(data)) {
2341 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2342 return;
2343 }
2344 PARCEL_UTIL_WRITE_NORET(data, Int32, specifiedId);
2345 PARCEL_UTIL_WRITE_NORET(data, String, instanceKey);
2346
2347 MessageParcel reply;
2348 MessageOption option(MessageOption::TF_SYNC);
2349 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::UPDATE_INSTANCE_KEY_BY_SPECIFIED_ID, data, reply, option);
2350 }
2351
IsSpecifiedModuleLoaded(const AAFwk::Want & want,const AbilityInfo & abilityInfo,bool & result,bool & isDebug)2352 int32_t AppMgrProxy::IsSpecifiedModuleLoaded(const AAFwk::Want &want, const AbilityInfo &abilityInfo, bool &result,
2353 bool &isDebug)
2354 {
2355 MessageParcel data;
2356 MessageParcel reply;
2357 MessageOption option;
2358 if (!WriteInterfaceToken(data)) {
2359 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2360 return ERR_FLATTEN_OBJECT;
2361 }
2362 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &want);
2363 PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &abilityInfo);
2364
2365 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_SPECIFIED_MODULE_LOADED, data, reply, option);
2366 result = reply.ReadBool();
2367 isDebug = reply.ReadBool();
2368 return ERR_OK;
2369 }
2370
UpdateProcessMemoryState(const std::vector<ProcessMemoryState> & procMemState)2371 int32_t AppMgrProxy::UpdateProcessMemoryState(const std::vector<ProcessMemoryState> &procMemState)
2372 {
2373 MessageParcel data;
2374 MessageParcel reply;
2375
2376 auto size = procMemState.size();
2377 if (size == 0 || size > MAX_PROCESS_STATE_COUNT) {
2378 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
2379 return ERR_FLATTEN_OBJECT;
2380 }
2381 if (!WriteInterfaceToken(data)) {
2382 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
2383 return IPC_PROXY_ERR;
2384 }
2385 if (!data.WriteUint32(size)) {
2386 TAG_LOGE(AAFwkTag::APPMGR, "Write size failed");
2387 return ERR_FLATTEN_OBJECT;
2388 }
2389 for (const auto &perState: procMemState) {
2390 if (!data.WriteParcelable(&perState)) {
2391 TAG_LOGE(AAFwkTag::APPMGR, "Write perState failed");
2392 return ERR_FLATTEN_OBJECT;
2393 }
2394 }
2395 if (!SendTransactCmd(AppMgrInterfaceCode::UPDATE_PROCESS_MEMORY_STATE, data, reply)) {
2396 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest err");
2397 return IPC_PROXY_ERR;
2398 }
2399 return reply.ReadInt32();
2400 }
2401
LaunchAbility(sptr<IRemoteObject> token)2402 int32_t AppMgrProxy::LaunchAbility(sptr<IRemoteObject> token)
2403 {
2404 MessageParcel data;
2405 MessageParcel reply;
2406 MessageOption option;
2407
2408 if (!WriteInterfaceToken(data)) {
2409 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2410 return ERR_FLATTEN_OBJECT;
2411 }
2412 if (!data.WriteRemoteObject(token)) {
2413 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
2414 return ERR_INVALID_DATA;
2415 }
2416
2417 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::LAUNCH_ABILITY, data, reply, option);
2418 return reply.ReadInt32();
2419 }
2420
PromoteCurrentToCandidateMasterProcess(bool isInsertToHead)2421 int32_t AppMgrProxy::PromoteCurrentToCandidateMasterProcess(bool isInsertToHead)
2422 {
2423 TAG_LOGD(AAFwkTag::APPMGR, "called");
2424 MessageParcel data;
2425 if (!WriteInterfaceToken(data)) {
2426 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2427 return ERR_INVALID_DATA;
2428 }
2429 PARCEL_UTIL_WRITE_RET_INT(data, Bool, isInsertToHead);
2430
2431 MessageParcel reply;
2432 MessageOption option;
2433
2434 PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PROMOTE_CURRENT_TO_CANDIDATE_MASTER_PROCESS, data, reply, option);
2435 return reply.ReadInt32();
2436 }
2437
DemoteCurrentFromCandidateMasterProcess()2438 int32_t AppMgrProxy::DemoteCurrentFromCandidateMasterProcess()
2439 {
2440 TAG_LOGD(AAFwkTag::APPMGR, "called");
2441 MessageParcel data;
2442 MessageParcel reply;
2443 MessageOption option;
2444 if (!WriteInterfaceToken(data)) {
2445 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2446 return ERR_INVALID_DATA;
2447 }
2448
2449 PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::DEMOTE_CURRENT_FROM_CANDIDATE_MASTER_PROCESS, data, reply, option);
2450 return reply.ReadInt32();
2451 }
2452
QueryRunningSharedBundles(pid_t pid,std::map<std::string,uint32_t> & sharedBundles)2453 int32_t AppMgrProxy::QueryRunningSharedBundles(pid_t pid, std::map<std::string, uint32_t> &sharedBundles)
2454 {
2455 MessageParcel data;
2456 MessageParcel reply;
2457 MessageOption option(MessageOption::TF_SYNC);
2458
2459 if (!WriteInterfaceToken(data)) {
2460 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
2461 return AAFwk::ERR_WRITE_INTERFACE_TOKEN_FAILED;
2462 }
2463
2464 PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
2465 int32_t ret = SendRequest(AppMgrInterfaceCode::QUERY_RUNNING_SHARED_BUNDLES, data, reply, option);
2466 if (ret != NO_ERROR) {
2467 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code: %{public}d", ret);
2468 return ret;
2469 }
2470
2471 int32_t result = reply.ReadInt32();
2472 if (result != ERR_OK) {
2473 return result;
2474 }
2475 int32_t size = reply.ReadInt32();
2476 if (size > CYCLE_LIMIT) {
2477 TAG_LOGE(AAFwkTag::APPMGR, "sharedBundles size too large: %{public}d", size);
2478 return ERR_INVALID_VALUE;
2479 }
2480 sharedBundles.clear();
2481 for (int32_t i = 0; i < size; i++) {
2482 std::string bundleName = reply.ReadString();
2483 uint32_t versionCode = reply.ReadUint32();
2484 sharedBundles.emplace(bundleName, versionCode);
2485 }
2486 return ERR_OK;
2487 }
2488 } // namespace AppExecFwk
2489 } // namespace OHOS
2490