• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_client.h"
17 
18 #include <cstdio>
19 #include <string>
20 #include <unistd.h>
21 
22 #include "if_system_ability_manager.h"
23 #include "ipc_skeleton.h"
24 
25 #include "app_mem_info.h"
26 #include "app_mgr_interface.h"
27 #include "app_service_manager.h"
28 #include "hilog_tag_wrapper.h"
29 #include "hitrace_meter.h"
30 #include "param.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class AppMgrRemoteHolder : public std::enable_shared_from_this<AppMgrRemoteHolder> {
35 public:
36     AppMgrRemoteHolder() = default;
37 
38     virtual ~AppMgrRemoteHolder() = default;
39 
SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr)40     void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr)
41     {
42         std::lock_guard<std::mutex> lock(mutex_);
43         serviceManager_ = std::move(serviceMgr);
44     }
45 
ConnectAppMgrService()46     AppMgrResultCode ConnectAppMgrService()
47     {
48         std::lock_guard<std::mutex> lock(mutex_);
49         return ConnectAppMgrServiceInner();
50     }
51 
GetRemoteObject()52     sptr<IRemoteObject> GetRemoteObject()
53     {
54         std::lock_guard<std::mutex> lock(mutex_);
55         if (!remote_) {
56             (void) ConnectAppMgrServiceInner();
57         }
58         return remote_;
59     }
60 
61 private:
HandleRemoteDied(const wptr<IRemoteObject> & remote)62     void HandleRemoteDied(const wptr<IRemoteObject>& remote)
63     {
64         std::lock_guard<std::mutex> lock(mutex_);
65         if (!remote_) {
66             return;
67         }
68 
69         if (remote_ == remote.promote()) {
70             remote_->RemoveDeathRecipient(deathRecipient_);
71             remote_ = nullptr;
72             deathRecipient_ = nullptr;
73         }
74     }
75 
ConnectAppMgrServiceInner()76     AppMgrResultCode ConnectAppMgrServiceInner()
77     {
78         if (!serviceManager_) {
79             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
80         }
81         if (remote_) {
82             return AppMgrResultCode::RESULT_OK;
83         }
84         TAG_LOGI(AAFwkTag::APPMGR, "get AppMgrRemote object");
85         remote_ = serviceManager_->GetAppMgrService();
86         if (!remote_) {
87             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
88         }
89 
90         auto me = shared_from_this();
91         deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new AppMgrDeathRecipient(me));
92         if (deathRecipient_ == nullptr) {
93             TAG_LOGE(AAFwkTag::APPMGR, "create AppMgrDeathRecipient failed");
94             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
95         }
96         if ((remote_->IsProxyObject()) && (!remote_->AddDeathRecipient(deathRecipient_))) {
97             TAG_LOGE(AAFwkTag::APPMGR, "AddDeathRecipient to AppMs failed");
98             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
99         }
100 
101         return AppMgrResultCode::RESULT_OK;
102     }
103 
104     class AppMgrDeathRecipient : public IRemoteObject::DeathRecipient {
105     public:
AppMgrDeathRecipient(const std::shared_ptr<AppMgrRemoteHolder> & holder)106         explicit AppMgrDeathRecipient(const std::shared_ptr<AppMgrRemoteHolder>& holder) : owner_(holder) {}
107 
108         virtual ~AppMgrDeathRecipient() = default;
109 
OnRemoteDied(const wptr<IRemoteObject> & remote)110         void OnRemoteDied(const wptr<IRemoteObject>& remote) override
111         {
112             std::shared_ptr<AppMgrRemoteHolder> holder = owner_.lock();
113             if (holder) {
114                 holder->HandleRemoteDied(remote);
115             }
116         }
117 
118     private:
119         std::weak_ptr<AppMgrRemoteHolder> owner_;
120     };
121 
122 private:
123     std::unique_ptr<AppServiceManager> serviceManager_;
124     sptr<IRemoteObject> remote_;
125     std::mutex mutex_;
126     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
127 };
128 
AppMgrClient()129 AppMgrClient::AppMgrClient()
130 {
131     SetServiceManager(std::make_unique<AppServiceManager>());
132 }
133 
~AppMgrClient()134 AppMgrClient::~AppMgrClient()
135 {}
136 
LoadAbility(const AbilityInfo & abilityInfo,const ApplicationInfo & appInfo,const AAFwk::Want & want,AbilityRuntime::LoadParam loadParam)137 AppMgrResultCode AppMgrClient::LoadAbility(const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo,
138     const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam)
139 {
140     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
141     if (service != nullptr) {
142         sptr<IAmsMgr> amsService = service->GetAmsMgr();
143         if (amsService != nullptr) {
144             // From here, separate AbilityInfo and ApplicationInfo from AA.
145             std::shared_ptr<AbilityInfo> abilityInfoPtr = std::make_shared<AbilityInfo>(abilityInfo);
146             std::shared_ptr<ApplicationInfo> appInfoPtr = std::make_shared<ApplicationInfo>(appInfo);
147             std::shared_ptr<AAFwk::Want> wantPtr = std::make_shared<AAFwk::Want>(want);
148             auto loadParamPtr = std::make_shared<AbilityRuntime::LoadParam>(loadParam);
149             amsService->LoadAbility(abilityInfoPtr, appInfoPtr, wantPtr, loadParamPtr);
150             return AppMgrResultCode::RESULT_OK;
151         }
152     }
153     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
154 }
155 
TerminateAbility(const sptr<IRemoteObject> & token,bool clearMissionFlag)156 AppMgrResultCode AppMgrClient::TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag)
157 {
158     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
159     if (service != nullptr) {
160         sptr<IAmsMgr> amsService = service->GetAmsMgr();
161         if (amsService != nullptr) {
162             amsService->TerminateAbility(token, clearMissionFlag);
163             return AppMgrResultCode::RESULT_OK;
164         }
165     }
166     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
167 }
168 
UpdateAbilityState(const sptr<IRemoteObject> & token,const AbilityState state)169 AppMgrResultCode AppMgrClient::UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state)
170 {
171     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
172     if (service != nullptr) {
173         sptr<IAmsMgr> amsService = service->GetAmsMgr();
174         if (amsService != nullptr) {
175             amsService->UpdateAbilityState(token, state);
176             return AppMgrResultCode::RESULT_OK;
177         }
178     }
179     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
180 }
181 
UpdateExtensionState(const sptr<IRemoteObject> & token,const ExtensionState state)182 AppMgrResultCode AppMgrClient::UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state)
183 {
184     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
185     if (service != nullptr) {
186         sptr<IAmsMgr> amsService = service->GetAmsMgr();
187         if (amsService != nullptr) {
188             amsService->UpdateExtensionState(token, state);
189             return AppMgrResultCode::RESULT_OK;
190         }
191     }
192     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
193 }
194 
RegisterAppStateCallback(const sptr<IAppStateCallback> & callback)195 AppMgrResultCode AppMgrClient::RegisterAppStateCallback(const sptr<IAppStateCallback> &callback)
196 {
197     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
198     if (service != nullptr) {
199         sptr<IAmsMgr> amsService = service->GetAmsMgr();
200         if (amsService != nullptr) {
201             amsService->RegisterAppStateCallback(callback);
202             return AppMgrResultCode::RESULT_OK;
203         }
204     }
205     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
206 }
207 
KillProcessByAbilityToken(const sptr<IRemoteObject> & token)208 AppMgrResultCode AppMgrClient::KillProcessByAbilityToken(const sptr<IRemoteObject> &token)
209 {
210     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
211     if (service != nullptr) {
212         sptr<IAmsMgr> amsService = service->GetAmsMgr();
213         if (amsService != nullptr) {
214             amsService->KillProcessByAbilityToken(token);
215             return AppMgrResultCode::RESULT_OK;
216         }
217     }
218     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
219 }
220 
KillProcessesByUserId(int32_t userId,bool isNeedSendAppSpawnMsg,sptr<AAFwk::IUserCallback> callback)221 AppMgrResultCode AppMgrClient::KillProcessesByUserId(int32_t userId, bool isNeedSendAppSpawnMsg,
222     sptr<AAFwk::IUserCallback> callback)
223 {
224     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
225     if (service != nullptr) {
226         sptr<IAmsMgr> amsService = service->GetAmsMgr();
227         if (amsService != nullptr) {
228             amsService->KillProcessesByUserId(userId, isNeedSendAppSpawnMsg, callback);
229             return AppMgrResultCode::RESULT_OK;
230         }
231     }
232     if (callback) {
233         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
234         callback->OnLogoutUserDone(userId, AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED);
235     }
236     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
237 }
238 
KillProcessesByPids(const std::vector<int32_t> & pids,const std::string & reason)239 AppMgrResultCode AppMgrClient::KillProcessesByPids(const std::vector<int32_t> &pids, const std::string &reason)
240 {
241     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
242     if (service != nullptr) {
243         sptr<IAmsMgr> amsService = service->GetAmsMgr();
244         if (amsService != nullptr) {
245             amsService->KillProcessesByPids(pids, reason);
246             return AppMgrResultCode::RESULT_OK;
247         }
248     }
249     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
250 }
251 
AttachPidToParent(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callerToken)252 AppMgrResultCode AppMgrClient::AttachPidToParent(const sptr<IRemoteObject> &token,
253     const sptr<IRemoteObject> &callerToken)
254 {
255     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
256     if (service != nullptr) {
257         sptr<IAmsMgr> amsService = service->GetAmsMgr();
258         if (amsService != nullptr) {
259             amsService->AttachPidToParent(token, callerToken);
260             return AppMgrResultCode::RESULT_OK;
261         }
262     }
263     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
264 }
265 
UpdateApplicationInfoInstalled(const std::string & bundleName,const int uid,const std::string & moduleName)266 AppMgrResultCode AppMgrClient::UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid,
267     const std::string &moduleName)
268 {
269     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
270     if (service != nullptr) {
271         sptr<IAmsMgr> amsService = service->GetAmsMgr();
272         if (amsService != nullptr) {
273             int32_t result = amsService->UpdateApplicationInfoInstalled(bundleName, uid, moduleName);
274             if (result == ERR_OK) {
275                 return AppMgrResultCode::RESULT_OK;
276             }
277             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
278         }
279     }
280     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
281 }
282 
KillApplication(const std::string & bundleName,bool clearPageStack,int32_t appIndex)283 AppMgrResultCode AppMgrClient::KillApplication(const std::string &bundleName, bool clearPageStack, int32_t appIndex)
284 {
285     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
286     if (service != nullptr) {
287         sptr<IAmsMgr> amsService = service->GetAmsMgr();
288         if (amsService != nullptr) {
289             int32_t result = amsService->KillApplication(bundleName, clearPageStack, appIndex);
290             if (result == ERR_OK) {
291                 return AppMgrResultCode::RESULT_OK;
292             }
293             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
294         }
295     }
296     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
297 }
298 
ForceKillApplication(const std::string & bundleName,const int userId,const int appIndex)299 AppMgrResultCode AppMgrClient::ForceKillApplication(const std::string &bundleName,
300     const int userId, const int appIndex)
301 {
302     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
303     if (service != nullptr) {
304         sptr<IAmsMgr> amsService = service->GetAmsMgr();
305         if (amsService != nullptr) {
306             int32_t result = amsService->ForceKillApplication(bundleName, userId, appIndex);
307             if (result == ERR_OK) {
308                 return AppMgrResultCode::RESULT_OK;
309             }
310             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
311         }
312     }
313     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
314 }
315 
KillProcessesByAccessTokenId(const uint32_t accessTokenId)316 AppMgrResultCode AppMgrClient::KillProcessesByAccessTokenId(const uint32_t accessTokenId)
317 {
318     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
319     if (service != nullptr) {
320         sptr<IAmsMgr> amsService = service->GetAmsMgr();
321         if (amsService != nullptr) {
322             int32_t result = amsService->KillProcessesByAccessTokenId(accessTokenId);
323             if (result == ERR_OK) {
324                 return AppMgrResultCode::RESULT_OK;
325             }
326             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
327         }
328     }
329     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
330 }
331 
KillApplicationByUid(const std::string & bundleName,const int uid,const std::string & reason)332 AppMgrResultCode AppMgrClient::KillApplicationByUid(const std::string &bundleName, const int uid,
333     const std::string& reason)
334 {
335     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
336     if (service != nullptr) {
337         sptr<IAmsMgr> amsService = service->GetAmsMgr();
338         if (amsService != nullptr) {
339             int32_t result = amsService->KillApplicationByUid(bundleName, uid, reason);
340             if (result == ERR_OK) {
341                 return AppMgrResultCode::RESULT_OK;
342             }
343             return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
344         }
345     }
346     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
347 }
348 
KillApplicationSelf(const bool clearPageStack,const std::string & reason)349 AppMgrResultCode AppMgrClient::KillApplicationSelf(const bool clearPageStack, const std::string& reason)
350 {
351     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
352     if (service != nullptr) {
353         sptr<IAmsMgr> amsService = service->GetAmsMgr();
354         if (amsService != nullptr) {
355             int32_t result = amsService->KillApplicationSelf(clearPageStack, reason);
356             if (result == ERR_OK) {
357                 return AppMgrResultCode::RESULT_OK;
358             }
359             return AppMgrResultCode::ERROR_KILL_APPLICATION;
360         }
361     }
362     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
363 }
364 
UpdateProcessMemoryState(const std::vector<AppExecFwk::ProcessMemoryState> & procMemState)365 int32_t AppMgrClient::UpdateProcessMemoryState(const std::vector<AppExecFwk::ProcessMemoryState> &procMemState)
366 {
367     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
368     if (service == nullptr) {
369         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
370         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
371     }
372     return service->UpdateProcessMemoryState(procMemState);
373 }
374 
ClearUpApplicationData(const std::string & bundleName,int32_t appCloneIndex,int32_t userId)375 AppMgrResultCode AppMgrClient::ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex,
376     int32_t userId)
377 {
378     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
379     if (service != nullptr) {
380         int32_t result = service->ClearUpApplicationData(bundleName, appCloneIndex, userId);
381         if (result == ERR_OK) {
382             return AppMgrResultCode::RESULT_OK;
383         }
384         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
385     }
386     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
387 }
388 
ClearUpApplicationDataBySelf(int32_t userId)389 AppMgrResultCode AppMgrClient::ClearUpApplicationDataBySelf(int32_t userId)
390 {
391     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
392     if (service != nullptr) {
393         int32_t result = service->ClearUpApplicationDataBySelf(userId);
394         if (result == ERR_OK) {
395             return AppMgrResultCode::RESULT_OK;
396         }
397         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
398     }
399     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
400 }
401 
GetAllRunningProcesses(std::vector<RunningProcessInfo> & info)402 AppMgrResultCode AppMgrClient::GetAllRunningProcesses(std::vector<RunningProcessInfo> &info)
403 {
404     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
405     if (service != nullptr) {
406         int32_t result = service->GetAllRunningProcesses(info);
407         if (result == ERR_OK) {
408             return AppMgrResultCode::RESULT_OK;
409         }
410         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
411     }
412     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
413 }
414 
GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> & info,int32_t userId)415 AppMgrResultCode AppMgrClient::GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId)
416 {
417     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
418     if (service != nullptr) {
419         int32_t result = service->GetProcessRunningInfosByUserId(info, userId);
420         if (result == ERR_OK) {
421             return AppMgrResultCode::RESULT_OK;
422         }
423         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
424     }
425     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
426 }
427 
GetProcessRunningInformation(AppExecFwk::RunningProcessInfo & info)428 AppMgrResultCode AppMgrClient::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info)
429 {
430     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
431     if (service != nullptr) {
432         int32_t result = service->GetProcessRunningInformation(info);
433         if (result == ERR_OK) {
434             return AppMgrResultCode::RESULT_OK;
435         }
436         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
437     }
438     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
439 }
440 
GetAllRunningInstanceKeysBySelf(std::vector<std::string> & instanceKeys)441 AppMgrResultCode AppMgrClient::GetAllRunningInstanceKeysBySelf(std::vector<std::string> &instanceKeys)
442 {
443     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
444     if (service != nullptr) {
445         int32_t result = service->GetAllRunningInstanceKeysBySelf(instanceKeys);
446         if (result == ERR_OK) {
447             return AppMgrResultCode::RESULT_OK;
448         }
449         TAG_LOGE(AAFwkTag::APPMGR, "GetAllRunningInstanceKeysBySelf returns result=%{public}d", result);
450         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
451     }
452     TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
453     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
454 }
455 
GetAllRunningInstanceKeysByBundleName(const std::string & bundleName,std::vector<std::string> & instanceKeys,int32_t userId)456 AppMgrResultCode AppMgrClient::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName,
457     std::vector<std::string> &instanceKeys, int32_t userId)
458 {
459     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
460     if (service != nullptr) {
461         int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId);
462         if (result == ERR_OK) {
463             return AppMgrResultCode::RESULT_OK;
464         }
465         TAG_LOGE(AAFwkTag::APPMGR, "GetAllRunningInstanceKeysByBundleName returns result=%{public}d", result);
466         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
467     }
468     TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
469     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
470 }
471 
GetAllRenderProcesses(std::vector<RenderProcessInfo> & info)472 AppMgrResultCode AppMgrClient::GetAllRenderProcesses(std::vector<RenderProcessInfo> &info)
473 {
474     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
475     if (service != nullptr) {
476         int32_t result = service->GetAllRenderProcesses(info);
477         if (result == ERR_OK) {
478             return AppMgrResultCode::RESULT_OK;
479         }
480         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
481     }
482     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
483 }
484 
GetAllChildrenProcesses(std::vector<ChildProcessInfo> & info)485 AppMgrResultCode AppMgrClient::GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info)
486 {
487 #ifdef SUPPORT_CHILD_PROCESS
488     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
489     if (service == nullptr) {
490         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
491         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
492     }
493     int32_t result = service->GetAllChildrenProcesses(info);
494     if (result != ERR_OK) {
495         TAG_LOGE(AAFwkTag::APPMGR, "service->GetAllChildrenProcesses failed,result=%{public}d", result);
496         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
497     }
498 #endif // SUPPORT_CHILD_PROCESS
499     return AppMgrResultCode::RESULT_OK;
500 }
501 
NotifyMemoryLevel(MemoryLevel level)502 AppMgrResultCode AppMgrClient::NotifyMemoryLevel(MemoryLevel level)
503 {
504     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
505 
506     if (service == nullptr) {
507         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
508         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
509     }
510     return AppMgrResultCode(service->NotifyMemoryLevel(level));
511 }
512 
NotifyProcMemoryLevel(const std::map<pid_t,MemoryLevel> & procLevelMap) const513 AppMgrResultCode AppMgrClient::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap) const
514 {
515     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
516 
517     if (service == nullptr) {
518         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
519         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
520     }
521     return AppMgrResultCode(service->NotifyProcMemoryLevel(procLevelMap));
522 }
523 
DumpHeapMemory(const int32_t pid,OHOS::AppExecFwk::MallocInfo & mallocInfo)524 AppMgrResultCode AppMgrClient::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
525 {
526     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
527     if (service == nullptr) {
528         TAG_LOGE(AAFwkTag::APPMGR, "DumpHeapMemory: service is nullptr");
529         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
530     }
531     return AppMgrResultCode(service->DumpHeapMemory(pid, mallocInfo));
532 }
533 
DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo & info)534 AppMgrResultCode AppMgrClient::DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
535 {
536     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
537     if (service == nullptr) {
538         TAG_LOGE(AAFwkTag::APPMGR, "DumpJsHeapMemory: service is nullptr");
539         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
540     }
541     return AppMgrResultCode(service->DumpJsHeapMemory(info));
542 }
543 
GetConfiguration(Configuration & config)544 AppMgrResultCode AppMgrClient::GetConfiguration(Configuration& config)
545 {
546     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
547     if (service != nullptr) {
548         int32_t result = service->GetConfiguration(config);
549         if (result == ERR_OK) {
550             return AppMgrResultCode::RESULT_OK;
551         }
552         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
553     }
554     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
555 }
556 
ConnectAppMgrService()557 AppMgrResultCode AppMgrClient::ConnectAppMgrService()
558 {
559     if (mgrHolder_) {
560         return mgrHolder_->ConnectAppMgrService();
561     }
562     return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
563 }
564 
IsProcessContainsOnlyUIAbility(const pid_t pid)565 bool AppMgrClient::IsProcessContainsOnlyUIAbility(const pid_t pid)
566 {
567     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
568     if (service != nullptr) {
569         sptr<IAmsMgr> amsService = service->GetAmsMgr();
570         if (amsService != nullptr) {
571             return amsService->IsProcessContainsOnlyUIAbility(pid);
572         }
573     }
574     return false;
575 }
576 
SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr)577 void AppMgrClient::SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr)
578 {
579     if (!mgrHolder_) {
580         mgrHolder_ = std::make_shared<AppMgrRemoteHolder>();
581     }
582     mgrHolder_->SetServiceManager(std::move(serviceMgr));
583 }
584 
AbilityAttachTimeOut(const sptr<IRemoteObject> & token)585 void AppMgrClient::AbilityAttachTimeOut(const sptr<IRemoteObject> &token)
586 {
587     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
588     if (service == nullptr) {
589         return;
590     }
591     sptr<IAmsMgr> amsService = service->GetAmsMgr();
592     if (amsService == nullptr) {
593         return;
594     }
595     amsService->AbilityAttachTimeOut(token);
596 }
597 
PrepareTerminate(const sptr<IRemoteObject> & token,bool clearMissionFlag)598 void AppMgrClient::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
599 {
600     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
601     if (service == nullptr) {
602         return;
603     }
604     sptr<IAmsMgr> amsService = service->GetAmsMgr();
605     if (amsService == nullptr) {
606         return;
607     }
608     amsService->PrepareTerminate(token, clearMissionFlag);
609 }
610 
GetRunningProcessInfoByToken(const sptr<IRemoteObject> & token,AppExecFwk::RunningProcessInfo & info)611 void AppMgrClient::GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info)
612 {
613     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
614     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
615     if (service != nullptr) {
616         sptr<IAmsMgr> amsService = service->GetAmsMgr();
617         if (amsService != nullptr) {
618             amsService->GetRunningProcessInfoByToken(token, info);
619         }
620     }
621 }
622 
GetRunningProcessInfoByPid(const pid_t pid,OHOS::AppExecFwk::RunningProcessInfo & info) const623 int32_t AppMgrClient::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const
624 {
625     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
626     if (service == nullptr) {
627         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
628         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
629     }
630     return service->GetRunningProcessInfoByPid(pid, info);
631 }
632 
GetRunningProcessInfoByChildProcessPid(const pid_t childPid,OHOS::AppExecFwk::RunningProcessInfo & info) const633 int32_t AppMgrClient::GetRunningProcessInfoByChildProcessPid(const pid_t childPid,
634     OHOS::AppExecFwk::RunningProcessInfo &info) const
635 {
636     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
637     if (service == nullptr) {
638         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
639         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
640     }
641     return service->GetRunningProcessInfoByChildProcessPid(childPid, info);
642 }
643 
SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const644 void AppMgrClient::SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const
645 {
646     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
647     if (service != nullptr) {
648         sptr<IAmsMgr> amsService = service->GetAmsMgr();
649         if (amsService != nullptr) {
650             amsService->SetAbilityForegroundingFlagToAppRecord(pid);
651         }
652     }
653 }
654 
AddAbilityStageDone(const int32_t recordId)655 void AppMgrClient::AddAbilityStageDone(const int32_t recordId)
656 {
657     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
658     if (service == nullptr) {
659         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
660         return;
661     }
662 
663     service->AddAbilityStageDone(recordId);
664 }
665 
StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> & bundleInfos)666 void AppMgrClient::StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos)
667 {
668     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
669     if (service == nullptr) {
670         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
671         return;
672     }
673 
674     service->StartupResidentProcess(bundleInfos);
675 }
676 
StartUserTestProcess(const AAFwk::Want & want,const sptr<IRemoteObject> & observer,const BundleInfo & bundleInfo,int32_t userId)677 int AppMgrClient::StartUserTestProcess(
678     const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId)
679 {
680     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
681     if (service == nullptr) {
682         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
683         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
684     }
685     return service->StartUserTestProcess(want, observer, bundleInfo, userId);
686 }
687 
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)688 int AppMgrClient::FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
689 {
690     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
691     if (service == nullptr) {
692         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
693         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
694     }
695     return service->FinishUserTest(msg, resultCode, bundleName);
696 }
697 
StartSpecifiedAbility(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)698 void AppMgrClient::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
699     int32_t requestId)
700 {
701     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
702     if (service == nullptr) {
703         return;
704     }
705     sptr<IAmsMgr> amsService = service->GetAmsMgr();
706     if (amsService == nullptr) {
707         return;
708     }
709     amsService->StartSpecifiedAbility(want, abilityInfo, requestId);
710 }
711 
PrepareTerminateApp(const pid_t pid,const std::string & moduleName)712 void AppMgrClient::PrepareTerminateApp(const pid_t pid, const std::string &moduleName)
713 {
714     TAG_LOGD(AAFwkTag::APPMGR, "called");
715     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
716     if (service == nullptr) {
717         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
718         return;
719     }
720     sptr<IAmsMgr> amsService = service->GetAmsMgr();
721     if (amsService == nullptr) {
722         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr");
723         return;
724     }
725     amsService->PrepareTerminateApp(pid, moduleName);
726 }
727 
SetKeepAliveEnableState(const std::string & bundleName,bool enable,int32_t uid)728 void AppMgrClient::SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid)
729 {
730     if (!IsAmsServiceReady()) {
731         return;
732     }
733     amsService_->SetKeepAliveEnableState(bundleName, enable, uid);
734 }
735 
SetKeepAliveDkv(const std::string & bundleName,bool enable,int32_t uid)736 void AppMgrClient::SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid)
737 {
738     if (!IsAmsServiceReady()) {
739         return;
740     }
741     amsService_->SetKeepAliveDkv(bundleName, enable, uid);
742 }
743 
StartSpecifiedProcess(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)744 void AppMgrClient::StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
745     int32_t requestId)
746 {
747     TAG_LOGD(AAFwkTag::APPMGR, "call.");
748     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
749     if (service == nullptr) {
750         return;
751     }
752     sptr<IAmsMgr> amsService = service->GetAmsMgr();
753     if (amsService == nullptr) {
754         return;
755     }
756     amsService->StartSpecifiedProcess(want, abilityInfo, requestId);
757 }
758 
RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> & response)759 void AppMgrClient::RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response)
760 {
761     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
762     if (service == nullptr) {
763         return;
764     }
765     sptr<IAmsMgr> amsService = service->GetAmsMgr();
766     if (amsService == nullptr) {
767         return;
768     }
769     amsService->RegisterStartSpecifiedAbilityResponse(response);
770 }
771 
ScheduleAcceptWantDone(const int32_t recordId,const AAFwk::Want & want,const std::string & flag)772 void AppMgrClient::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)
773 {
774     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
775     if (service == nullptr) {
776         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
777         return;
778     }
779 
780     service->ScheduleAcceptWantDone(recordId, want, flag);
781 }
782 
UpdateConfiguration(const Configuration & config,const int32_t userId)783 AppMgrResultCode AppMgrClient::UpdateConfiguration(const Configuration &config, const int32_t userId)
784 {
785     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
786     if (service == nullptr) {
787         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
788     }
789     service->UpdateConfiguration(config, userId);
790     return AppMgrResultCode::RESULT_OK;
791 }
792 
UpdateConfigurationByBundleName(const Configuration & config,const std::string & name,int32_t appIndex)793 AppMgrResultCode AppMgrClient::UpdateConfigurationByBundleName(const Configuration &config, const std::string &name,
794     int32_t appIndex)
795 {
796     if (!mgrHolder_) {
797         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
798     }
799     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
800     if (service == nullptr) {
801         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
802     }
803     service->UpdateConfigurationByBundleName(config, name, appIndex);
804     return AppMgrResultCode::RESULT_OK;
805 }
806 
RegisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)807 AppMgrResultCode AppMgrClient::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
808 {
809     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
810     if (service != nullptr) {
811         int32_t result = service->RegisterConfigurationObserver(observer);
812         if (result == ERR_OK) {
813             return AppMgrResultCode::RESULT_OK;
814         }
815         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
816     }
817     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
818 }
819 
UnregisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)820 AppMgrResultCode AppMgrClient::UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
821 {
822     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
823     if (service != nullptr) {
824         int32_t result = service->UnregisterConfigurationObserver(observer);
825         if (result == ERR_OK) {
826             return AppMgrResultCode::RESULT_OK;
827         }
828         return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
829     }
830     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
831 }
832 
GetAbilityRecordsByProcessID(const int pid,std::vector<sptr<IRemoteObject>> & tokens)833 int AppMgrClient::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens)
834 {
835     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
836     if (service == nullptr) {
837         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
838         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
839     }
840 
841     return service->GetAbilityRecordsByProcessID(pid, tokens);
842 }
843 
GetApplicationInfoByProcessID(const int pid,AppExecFwk::ApplicationInfo & application,bool & debug)844 int AppMgrClient::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug)
845 {
846     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
847     if (service == nullptr) {
848         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
849         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
850     }
851     sptr<IAmsMgr> amsService = service->GetAmsMgr();
852     if (amsService == nullptr) {
853         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr");
854         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
855     }
856     return amsService->GetApplicationInfoByProcessID(pid, application, debug);
857 }
858 
NotifyAppMgrRecordExitReason(int32_t pid,int32_t reason,const std::string & exitMsg)859 int32_t AppMgrClient::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg)
860 {
861     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
862     if (service == nullptr) {
863         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
864         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
865     }
866     sptr<IAmsMgr> amsService = service->GetAmsMgr();
867     if (amsService == nullptr) {
868         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr");
869         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
870     }
871     return amsService->NotifyAppMgrRecordExitReason(pid, reason, exitMsg);
872 }
873 
StartNativeProcessForDebugger(const AAFwk::Want & want)874 int32_t AppMgrClient::StartNativeProcessForDebugger(const AAFwk::Want &want)
875 {
876     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
877     if (service == nullptr) {
878         TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr");
879         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
880     }
881     return service->StartNativeProcessForDebugger(want);
882 }
883 
PreStartNWebSpawnProcess()884 int AppMgrClient::PreStartNWebSpawnProcess()
885 {
886     TAG_LOGI(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess");
887 
888     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
889     if (service != nullptr) {
890         return service->PreStartNWebSpawnProcess();
891     }
892     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
893 }
894 
StartRenderProcess(const std::string & renderParam,int32_t ipcFd,int32_t sharedFd,int32_t crashFd,pid_t & renderPid,bool isGPU)895 int AppMgrClient::StartRenderProcess(const std::string &renderParam,
896                                      int32_t ipcFd, int32_t sharedFd,
897                                      int32_t crashFd, pid_t &renderPid, bool isGPU)
898 {
899     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
900     if (service != nullptr) {
901         return service->StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd,
902                                            renderPid, isGPU);
903     }
904     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
905 }
906 
AttachRenderProcess(const sptr<IRenderScheduler> & renderScheduler)907 void AppMgrClient::AttachRenderProcess(const sptr<IRenderScheduler> &renderScheduler)
908 {
909     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
910     if (!renderScheduler) {
911         TAG_LOGI(AAFwkTag::APPMGR, "renderScheduler is nullptr");
912         return;
913     }
914 
915     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
916     if (service != nullptr) {
917         TAG_LOGI(AAFwkTag::APPMGR, "AttachRenderProcess");
918         service->AttachRenderProcess(renderScheduler->AsObject());
919     }
920 }
921 
GetRenderProcessTerminationStatus(pid_t renderPid,int & status)922 int AppMgrClient::GetRenderProcessTerminationStatus(pid_t renderPid, int &status)
923 {
924     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
925     if (service != nullptr) {
926         return service->GetRenderProcessTerminationStatus(renderPid, status);
927     }
928     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
929 }
930 
GetRemoteObject()931 sptr<IRemoteObject> AppMgrClient::GetRemoteObject()
932 {
933     return mgrHolder_->GetRemoteObject();
934 }
935 
SetCurrentUserId(const int32_t userId)936 void AppMgrClient::SetCurrentUserId(const int32_t userId)
937 {
938     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
939     if (service == nullptr) {
940         return;
941     }
942     sptr<IAmsMgr> amsService = service->GetAmsMgr();
943     if (amsService == nullptr) {
944         return;
945     }
946     amsService->SetCurrentUserId(userId);
947 }
948 
SetEnableStartProcessFlagByUserId(int32_t userId,bool enableStartProcess)949 void AppMgrClient::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess)
950 {
951     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
952     if (service == nullptr) {
953         return;
954     }
955     sptr<IAmsMgr> amsService = service->GetAmsMgr();
956     if (amsService == nullptr) {
957         return;
958     }
959     amsService->SetEnableStartProcessFlagByUserId(userId, enableStartProcess);
960 }
961 
GetBundleNameByPid(const int pid,std::string & bundleName,int32_t & uid)962 int32_t AppMgrClient::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid)
963 {
964     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
965     if (service == nullptr) {
966         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
967     }
968 
969     sptr<IAmsMgr> amsService = service->GetAmsMgr();
970     if (amsService != nullptr) {
971         return amsService->GetBundleNameByPid(pid, bundleName, uid);
972     }
973     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
974 }
975 
NotifyAppFault(const FaultData & faultData)976 int32_t AppMgrClient::NotifyAppFault(const FaultData &faultData)
977 {
978     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
979     if (service == nullptr) {
980         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
981     }
982     return service->NotifyAppFault(faultData);
983 }
984 
NotifyAppFaultBySA(const AppFaultDataBySA & faultData)985 int32_t AppMgrClient::NotifyAppFaultBySA(const AppFaultDataBySA &faultData)
986 {
987     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
988     if (service == nullptr) {
989         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
990     }
991     return service->NotifyAppFaultBySA(faultData);
992 }
993 
SetAppFreezeFilter(int32_t pid)994 bool AppMgrClient::SetAppFreezeFilter(int32_t pid)
995 {
996     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
997     if (service == nullptr) {
998         return false;
999     }
1000     return service->SetAppFreezeFilter(pid);
1001 }
1002 
ChangeAppGcState(pid_t pid,int32_t state)1003 int32_t AppMgrClient::ChangeAppGcState(pid_t pid, int32_t state)
1004 {
1005     if (mgrHolder_ == nullptr) {
1006         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1007     }
1008     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1009     if (service == nullptr) {
1010         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1011     }
1012     return service->ChangeAppGcState(pid, state);
1013 }
1014 
RegisterAppDebugListener(const sptr<IAppDebugListener> & listener)1015 int32_t AppMgrClient::RegisterAppDebugListener(const sptr<IAppDebugListener> &listener)
1016 {
1017     if (!IsAmsServiceReady()) {
1018         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1019     }
1020     return amsService_->RegisterAppDebugListener(listener);
1021 }
1022 
UnregisterAppDebugListener(const sptr<IAppDebugListener> & listener)1023 int32_t AppMgrClient::UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener)
1024 {
1025     if (!IsAmsServiceReady()) {
1026         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1027     }
1028     return amsService_->UnregisterAppDebugListener(listener);
1029 }
1030 
AttachAppDebug(const std::string & bundleName,bool isDebugFromLocal)1031 int32_t AppMgrClient::AttachAppDebug(const std::string &bundleName, bool isDebugFromLocal)
1032 {
1033     if (!IsAmsServiceReady()) {
1034         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1035     }
1036     return amsService_->AttachAppDebug(bundleName, isDebugFromLocal);
1037 }
1038 
DetachAppDebug(const std::string & bundleName)1039 int32_t AppMgrClient::DetachAppDebug(const std::string &bundleName)
1040 {
1041     if (!IsAmsServiceReady()) {
1042         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1043     }
1044     return amsService_->DetachAppDebug(bundleName);
1045 }
1046 
SetAppWaitingDebug(const std::string & bundleName,bool isPersist)1047 int32_t AppMgrClient::SetAppWaitingDebug(const std::string &bundleName, bool isPersist)
1048 {
1049     if (!IsAmsServiceReady()) {
1050         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is not ready.");
1051         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1052     }
1053     return amsService_->SetAppWaitingDebug(bundleName, isPersist);
1054 }
1055 
CancelAppWaitingDebug()1056 int32_t AppMgrClient::CancelAppWaitingDebug()
1057 {
1058     if (!IsAmsServiceReady()) {
1059         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is not ready.");
1060         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1061     }
1062     return amsService_->CancelAppWaitingDebug();
1063 }
1064 
GetWaitingDebugApp(std::vector<std::string> & debugInfoList)1065 int32_t AppMgrClient::GetWaitingDebugApp(std::vector<std::string> &debugInfoList)
1066 {
1067     if (!IsAmsServiceReady()) {
1068         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is not ready.");
1069         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1070     }
1071     return amsService_->GetWaitingDebugApp(debugInfoList);
1072 }
1073 
IsWaitingDebugApp(const std::string & bundleName)1074 bool AppMgrClient::IsWaitingDebugApp(const std::string &bundleName)
1075 {
1076     if (!IsAmsServiceReady()) {
1077         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is not ready.");
1078         return false;
1079     }
1080     return amsService_->IsWaitingDebugApp(bundleName);
1081 }
1082 
ClearNonPersistWaitingDebugFlag()1083 void AppMgrClient::ClearNonPersistWaitingDebugFlag()
1084 {
1085     if (!IsAmsServiceReady()) {
1086         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is not ready.");
1087         return;
1088     }
1089     amsService_->ClearNonPersistWaitingDebugFlag();
1090 }
1091 
RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> & response)1092 int32_t AppMgrClient::RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response)
1093 {
1094     if (!IsAmsServiceReady()) {
1095         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1096     }
1097     return amsService_->RegisterAbilityDebugResponse(response);
1098 }
1099 
IsAttachDebug(const std::string & bundleName)1100 bool AppMgrClient::IsAttachDebug(const std::string &bundleName)
1101 {
1102     if (!IsAmsServiceReady()) {
1103         return false;
1104     }
1105     return amsService_->IsAttachDebug(bundleName);
1106 }
1107 
IsAmsServiceReady()1108 bool AppMgrClient::IsAmsServiceReady()
1109 {
1110     if (mgrHolder_ == nullptr) {
1111         TAG_LOGE(AAFwkTag::APPMGR, "mgrHolder_ is nullptr.");
1112         return false;
1113     }
1114 
1115     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1116     if (service == nullptr) {
1117         TAG_LOGE(AAFwkTag::APPMGR, "App manager service is nullptr.");
1118         return false;
1119     }
1120 
1121     amsService_ = service->GetAmsMgr();
1122     if (amsService_ == nullptr) {
1123         TAG_LOGE(AAFwkTag::APPMGR, "amsService_ is nullptr.");
1124         return false;
1125     }
1126     return true;
1127 }
1128 
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)1129 int32_t AppMgrClient::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
1130     const std::vector<std::string> &bundleNameList)
1131 {
1132     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1133     if (service == nullptr) {
1134         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1135     }
1136     return service->RegisterApplicationStateObserver(observer, bundleNameList);
1137 }
1138 
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)1139 int32_t AppMgrClient::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
1140 {
1141     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1142     if (service == nullptr) {
1143         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1144     }
1145     return service->UnregisterApplicationStateObserver(observer);
1146 }
1147 
NotifyPageShow(const sptr<IRemoteObject> & token,const PageStateData & pageStateData)1148 int32_t AppMgrClient::NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData)
1149 {
1150     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1151     if (service == nullptr) {
1152         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1153     }
1154     return service->NotifyPageShow(token, pageStateData);
1155 }
1156 
NotifyPageHide(const sptr<IRemoteObject> & token,const PageStateData & pageStateData)1157 int32_t AppMgrClient::NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData)
1158 {
1159     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1160     if (service == nullptr) {
1161         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1162     }
1163     return service->NotifyPageHide(token, pageStateData);
1164 }
1165 
RegisterAppRunningStatusListener(const sptr<IRemoteObject> & listener)1166 int32_t AppMgrClient::RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
1167 {
1168     if (listener == nullptr) {
1169         TAG_LOGE(AAFwkTag::APPMGR, "Listener is nullptr.");
1170         return ERR_INVALID_DATA;
1171     }
1172 
1173     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1174     if (service == nullptr) {
1175         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1176         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1177     }
1178     return service->RegisterAppRunningStatusListener(listener);
1179 }
1180 
UnregisterAppRunningStatusListener(const sptr<IRemoteObject> & listener)1181 int32_t AppMgrClient::UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
1182 {
1183     if (listener == nullptr) {
1184         TAG_LOGE(AAFwkTag::APPMGR, "Listener is nullptr.");
1185         return ERR_INVALID_DATA;
1186     }
1187 
1188     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1189     if (service == nullptr) {
1190         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1191         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1192     }
1193     return service->UnregisterAppRunningStatusListener(listener);
1194 }
1195 
ClearProcessByToken(sptr<IRemoteObject> token) const1196 void AppMgrClient::ClearProcessByToken(sptr<IRemoteObject> token) const
1197 {
1198     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1199     if (service == nullptr) {
1200         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1201         return;
1202     }
1203     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1204     if (amsService == nullptr) {
1205         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr.");
1206         return;
1207     }
1208     amsService->ClearProcessByToken(token);
1209 }
1210 
IsFinalAppProcess()1211 bool AppMgrClient::IsFinalAppProcess()
1212 {
1213     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1214     if (service == nullptr) {
1215         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1216         return false;
1217     }
1218     return service->IsFinalAppProcess();
1219 }
1220 
RegisterRenderStateObserver(const sptr<IRenderStateObserver> & observer)1221 int32_t AppMgrClient::RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer)
1222 {
1223     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1224     if (service == nullptr) {
1225         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1226     }
1227     return service->RegisterRenderStateObserver(observer);
1228 }
1229 
UnregisterRenderStateObserver(const sptr<IRenderStateObserver> & observer)1230 int32_t AppMgrClient::UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer)
1231 {
1232     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1233     if (service == nullptr) {
1234         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1235     }
1236     return service->UnregisterRenderStateObserver(observer);
1237 }
1238 
UpdateRenderState(pid_t renderPid,int32_t state)1239 int32_t AppMgrClient::UpdateRenderState(pid_t renderPid, int32_t state)
1240 {
1241     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1242     if (service == nullptr) {
1243         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1244     }
1245     return service->UpdateRenderState(renderPid, state);
1246 }
1247 
GetAppRunningUniqueIdByPid(pid_t pid,std::string & appRunningUniqueId)1248 int32_t AppMgrClient::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
1249 {
1250     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1251     if (service == nullptr) {
1252         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1253         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1254     }
1255     return service->GetAppRunningUniqueIdByPid(pid, appRunningUniqueId);
1256 }
1257 
GetAllUIExtensionRootHostPid(pid_t pid,std::vector<pid_t> & hostPids)1258 int32_t AppMgrClient::GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids)
1259 {
1260     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1261     if (service == nullptr) {
1262         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1263         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1264     }
1265     return service->GetAllUIExtensionRootHostPid(pid, hostPids);
1266 }
1267 
GetAllUIExtensionProviderPid(pid_t hostPid,std::vector<pid_t> & providerPids)1268 int32_t AppMgrClient::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids)
1269 {
1270     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1271     if (service == nullptr) {
1272         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1273         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1274     }
1275     return service->GetAllUIExtensionProviderPid(hostPid, providerPids);
1276 }
1277 
NotifyMemorySizeStateChanged(bool isMemorySizeSufficient)1278 int32_t AppMgrClient::NotifyMemorySizeStateChanged(bool isMemorySizeSufficient)
1279 {
1280     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1281     if (service == nullptr) {
1282         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1283         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1284     }
1285     return service->NotifyMemorySizeStateChanged(isMemorySizeSufficient);
1286 }
1287 
IsMemorySizeSufficent() const1288 bool AppMgrClient::IsMemorySizeSufficent() const
1289 {
1290     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1291     if (service == nullptr) {
1292         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1293         return true;
1294     }
1295     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1296     if (amsService == nullptr) {
1297         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr.");
1298         return true;
1299     }
1300     return amsService->IsMemorySizeSufficent();
1301 }
1302 
PreloadApplication(const std::string & bundleName,int32_t userId,AppExecFwk::PreloadMode preloadMode,int32_t appIndex)1303 int32_t AppMgrClient::PreloadApplication(const std::string &bundleName, int32_t userId,
1304     AppExecFwk::PreloadMode preloadMode, int32_t appIndex)
1305 {
1306     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1307     if (service == nullptr) {
1308         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1309     }
1310     return service->PreloadApplication(bundleName, userId, preloadMode, appIndex);
1311 }
1312 
SetSupportedProcessCacheSelf(bool isSupport)1313 int32_t AppMgrClient::SetSupportedProcessCacheSelf(bool isSupport)
1314 {
1315     TAG_LOGI(AAFwkTag::APPMGR, "Called");
1316     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1317     if (service == nullptr) {
1318         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1319         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1320     }
1321     return service->SetSupportedProcessCacheSelf(isSupport);
1322 }
1323 
SetSupportedProcessCache(int32_t pid,bool isSupport)1324 int32_t AppMgrClient::SetSupportedProcessCache(int32_t pid, bool isSupport)
1325 {
1326     TAG_LOGI(AAFwkTag::APPMGR, "Called");
1327     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1328     if (service == nullptr) {
1329         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1330         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1331     }
1332     return service->SetSupportedProcessCache(pid, isSupport);
1333 }
1334 
SaveBrowserChannel(sptr<IRemoteObject> browser)1335 void AppMgrClient::SaveBrowserChannel(sptr<IRemoteObject> browser)
1336 {
1337     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1338     if (service == nullptr) {
1339         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1340         return;
1341     }
1342     service->SaveBrowserChannel(browser);
1343 }
1344 
CheckCallingIsUserTestMode(const pid_t pid,bool & isUserTest)1345 int32_t AppMgrClient::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest)
1346 {
1347     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1348     if (service != nullptr) {
1349         return service->CheckCallingIsUserTestMode(pid, isUserTest);
1350     }
1351     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1352 }
1353 
AttachedToStatusBar(const sptr<IRemoteObject> & token)1354 AppMgrResultCode AppMgrClient::AttachedToStatusBar(const sptr<IRemoteObject> &token)
1355 {
1356     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1357     if (service != nullptr) {
1358         sptr<IAmsMgr> amsService = service->GetAmsMgr();
1359         if (amsService != nullptr) {
1360             amsService->AttachedToStatusBar(token);
1361             return AppMgrResultCode::RESULT_OK;
1362         }
1363     }
1364     TAG_LOGE(AAFwkTag::APPMGR, "Service is not connected.");
1365     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1366 }
1367 
NotifyProcessDependedOnWeb()1368 int32_t AppMgrClient::NotifyProcessDependedOnWeb()
1369 {
1370     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1371     if (service == nullptr) {
1372         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1373         return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1374     }
1375     TAG_LOGD(AAFwkTag::APPMGR, "call");
1376     return service->NotifyProcessDependedOnWeb();
1377 }
1378 
KillProcessDependedOnWeb()1379 void AppMgrClient::KillProcessDependedOnWeb()
1380 {
1381     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1382     if (service == nullptr) {
1383         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1384         return;
1385     }
1386     TAG_LOGD(AAFwkTag::APPMGR, "call");
1387     service->KillProcessDependedOnWeb();
1388 }
1389 
BlockProcessCacheByPids(const std::vector<int32_t> & pids)1390 AppMgrResultCode AppMgrClient::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
1391 {
1392     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1393     if (service != nullptr) {
1394         sptr<IAmsMgr> amsService = service->GetAmsMgr();
1395         if (amsService != nullptr) {
1396             amsService->BlockProcessCacheByPids(pids);
1397             return AppMgrResultCode::RESULT_OK;
1398         }
1399     }
1400     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1401 }
1402 
IsKilledForUpgradeWeb(const std::string & bundleName)1403 bool AppMgrClient::IsKilledForUpgradeWeb(const std::string &bundleName)
1404 {
1405     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1406     if (service == nullptr) {
1407         TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
1408         return false;
1409     }
1410     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1411     if (amsService == nullptr) {
1412         TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr.");
1413         return false;
1414     }
1415     TAG_LOGD(AAFwkTag::APPMGR, "call");
1416     return amsService->IsKilledForUpgradeWeb(bundleName);
1417 }
1418 
CleanAbilityByUserRequest(const sptr<IRemoteObject> & token)1419 bool AppMgrClient::CleanAbilityByUserRequest(const sptr<IRemoteObject> &token)
1420 {
1421     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1422     if (service == nullptr) {
1423         TAG_LOGE(AAFwkTag::APPMGR, "get appmgrservice is nullptr.");
1424         return false;
1425     }
1426     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1427     if (amsService == nullptr) {
1428         TAG_LOGE(AAFwkTag::APPMGR, "get abilityms service is nullptr.");
1429         return false;
1430     }
1431     TAG_LOGD(AAFwkTag::APPMGR, "call");
1432     return amsService->CleanAbilityByUserRequest(token);
1433 }
1434 
IsProcessAttached(sptr<IRemoteObject> token) const1435 bool AppMgrClient::IsProcessAttached(sptr<IRemoteObject> token) const
1436 {
1437     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1438     if (service == nullptr) {
1439         return false;
1440     }
1441     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1442     if (amsService == nullptr) {
1443         return false;
1444     }
1445     return amsService->IsProcessAttached(token);
1446 }
1447 
IsCallerKilling(const std::string & callerKey) const1448 bool AppMgrClient::IsCallerKilling(const std::string& callerKey) const
1449 {
1450     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1451     if (service == nullptr) {
1452         return false;
1453     }
1454     sptr<IAmsMgr> amsService = service->GetAmsMgr();
1455     if (amsService == nullptr) {
1456         return false;
1457     }
1458     return amsService->IsCallerKilling(callerKey);
1459 }
1460 
IsAppRunningByBundleNameAndUserId(const std::string & bundleName,int32_t userId,bool & isRunning)1461 AppMgrResultCode AppMgrClient::IsAppRunningByBundleNameAndUserId(const std::string &bundleName, int32_t userId,
1462     bool &isRunning)
1463 {
1464     sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
1465     if (service != nullptr) {
1466         return AppMgrResultCode(service->IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning));
1467     }
1468     return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
1469 }
1470 }  // namespace AppExecFwk
1471 }  // namespace OHOS
1472