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