• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #ifndef OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
17 #define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
18 
19 #include <list>
20 #include <map>
21 #include <vector>
22 #include <regex>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include "cpp/mutex.h"
26 
27 #include "iremote_object.h"
28 #include "refbase.h"
29 #include "task_handler_wrap.h"
30 #include "ability_info.h"
31 #include "appexecfwk_errors.h"
32 #include "app_death_recipient.h"
33 #include "app_mgr_constants.h"
34 #include "app_record_id.h"
35 #include "app_running_record.h"
36 #include "app_scheduler_interface.h"
37 #include "app_spawn_client.h"
38 #include "app_task_info.h"
39 #include "fault_data.h"
40 #include "iapp_state_callback.h"
41 #include "iapplication_state_observer.h"
42 #include "iconfiguration_observer.h"
43 #include "app_process_manager.h"
44 #include "remote_client_manager.h"
45 #include "app_running_manager.h"
46 #include "record_query_result.h"
47 #include "render_process_info.h"
48 #include "running_process_info.h"
49 #include "bundle_info.h"
50 #include "istart_specified_ability_response.h"
51 #include "shared/base_shared_bundle_info.h"
52 
53 #include "want.h"
54 #include "window_focus_changed_listener.h"
55 #include "app_malloc_info.h"
56 
57 namespace OHOS {
58 namespace AppExecFwk {
59 using OHOS::AAFwk::Want;
60 class AppMgrServiceInner : public std::enable_shared_from_this<AppMgrServiceInner> {
61 public:
62     AppMgrServiceInner();
63     virtual ~AppMgrServiceInner();
64 
65     /**
66      * Initialize the object.
67      */
68     void Init();
69     /**
70      * LoadAbility, load the ability that needed to be started.
71      *
72      * @param token, the unique identification to start the ability.
73      * @param preToken, the unique identification to call the ability.
74      * @param abilityInfo, the ability information.
75      * @param appInfo, the app information.
76      * @param want the ability want.
77      *
78      * @return
79      */
80     virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
81         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo,
82         const std::shared_ptr<AAFwk::Want> &want);
83 
84     /**
85      * TerminateAbility, terminate the token ability.
86      *
87      * @param token, he unique identification to terminate the ability.
88      * @param clearMissionFlag, indicates whether terminate the ability when clearMission.
89      * @return
90      */
91     virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag);
92 
93     /**
94      * UpdateAbilityState, update the ability status.
95      *
96      * @param token, the unique identification to update the ability.
97      * @param state, ability status that needs to be updated.
98      *
99      * @return
100      */
101     virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state);
102 
103     /**
104      * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status.
105      *
106      * @param token, the unique identification to update the extension.
107      * @param state, extension status that needs to be updated.
108      */
109     virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state);
110 
111     /**
112      * StateChangedNotifyObserver, Call ability state change.
113      *
114      * @param ability, the ability info.
115      * @param state, the ability state.
116      *
117      * @return
118      */
119     void StateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility);
120 
121     /**
122      * RegisterAppStateCallback, register the callback.
123      *
124      * @param callback, Ams register the callback.
125      *
126      * @return
127      */
128     virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback);
129 
130     /**
131      * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization.
132      *
133      * @param token, the unique identification to start the ability.
134      * @param preToken, the unique identification to call the ability.
135      * @param visibility, the visibility information about windows info.
136      * @param perceptibility, the Perceptibility information about windows info.
137      * @param connectionState, the service ability connection state.
138      * @return
139      */
140     virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
141         const int32_t visibility, const int32_t perceptibility, const int32_t connectionState);
142 
143     /**
144      * KillProcessByAbilityToken, kill the process by ability token.
145      *
146      * @param token, the unique identification to the ability.
147      * @return
148      */
149     virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token);
150 
151     /**
152      * KillProcessesByUserId, kill the processes by userId.
153      *
154      * @param userId, the user id.
155      * @return
156      */
157     virtual void KillProcessesByUserId(int32_t userId);
158 
159     /**
160      * AttachApplication, get all the information needed to start the Application
161      * (data related to the Application ).
162      *
163      * @param appScheduler, information needed to start the Application.
164      *
165      * @return
166      */
167     virtual void AttachApplication(const pid_t pid, const sptr<IAppScheduler> &appScheduler);
168 
169     /**
170      * ApplicationForegrounded, set the application to Foreground State.
171      *
172      * @param recordId, a unique record that identifies this Application from others.
173      *
174      * @return
175      */
176     virtual void ApplicationForegrounded(const int32_t recordId);
177 
178     /**
179      * ApplicationBackgrounded, set the application to Backgrounded State.
180      *
181      * @param recordId, a unique record that identifies this Application from others.
182      *
183      * @return
184      */
185     virtual void ApplicationBackgrounded(const int32_t recordId);
186 
187     /**
188      * ApplicationTerminated, terminate the application.
189      *
190      * @param recordId, a unique record that identifies this Application from others.
191      *
192      * @return
193      */
194     virtual void ApplicationTerminated(const int32_t recordId);
195 
196     /**
197      * AbilityTerminated, terminate the ability.
198      *
199      * @param token, the unique identification to terminated the ability.
200      *
201      * @return
202      */
203     virtual void AbilityTerminated(const sptr<IRemoteObject> &token);
204 
205      /**
206      * UpdateApplicationInfoInstalled, update the application info after new module installed.
207      *
208      * @param bundleName, bundle name in Application record.
209      * @param  uid, uid.
210      * @return ERR_OK, return back success, others fail.
211      */
212     virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid);
213 
214     /**
215      * KillApplication, kill the application.
216      *
217      * @param  bundleName, bundle name in Application record.
218      *
219      * @return ERR_OK, return back success, others fail.
220      */
221     virtual int32_t KillApplication(const std::string &bundleName);
222 
223     /**
224      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
225      *
226      * @param  bundleName, bundle name in Application record.
227      * @param  uid, uid.
228      * @return ERR_OK, return back success, others fail.
229      */
230     virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid);
231 
232     virtual int32_t KillApplicationSelf();
233 
234     /**
235      * KillApplicationByUserId, kill the application by user ID.
236      *
237      * @param bundleName, bundle name in Application record.
238      * @param userId, user ID.
239      *
240      * @return ERR_OK, return back success, others fail.
241      */
242     virtual int32_t KillApplicationByUserId(const std::string &bundleName, const int userId);
243 
244     /**
245      * ClearUpApplicationData, clear the application data.
246      *
247      * @param bundleName, bundle name in Application record.
248      * @param callerUid, app uid in Application record.
249      * @param callerPid, app pid in Application record.
250      *
251      * @return
252      */
253     virtual void ClearUpApplicationData(const std::string &bundleName, const int32_t callerUid, const pid_t callerPid);
254 
255     /**
256      * GetAllRunningProcesses, Obtains information about application processes that are running on the device.
257      *
258      * @param info, app name in Application record.
259      *
260      * @return ERR_OK ,return back success,others fail.
261      */
262     virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info);
263 
264     /**
265      * GetProcessRunningInfosByUserId, Obtains information about application processes that are running on the device.
266      *
267      * @param info, app name in Application record.
268      * @param userId, userId.
269      *
270      * @return ERR_OK ,return back success,others fail.
271      */
272     virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId);
273 
274     /**
275      * GetProcessRunningInformation, Obtains information about current application process
276      * which is running on the device.
277      * @param info, app name in Application record.
278      *
279      * @return ERR_OK ,return back success,others fail.
280      */
281     virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info);
282 
283     /**
284      * GetAllRenderProcesses, Obtains information about render processes that are running on the device.
285      *
286      * @param info, render process record.
287      *
288      * @return ERR_OK, return back success, others fail.
289      */
290     virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info);
291 
292     /**
293      * NotifyMemoryLevel, Notify applications background the current memory level.
294      *
295      * @param level, current memory level.
296      *
297      * @return ERR_OK ,return back success,others fail.
298      */
299     virtual int32_t NotifyMemoryLevel(int32_t level);
300 
301     /**
302      * DumpHeapMemory, get the application's memory info.
303      * Get the application's memory allocation info.
304      *
305      * @param pid, pid input.
306      * @param mallocInfo, dynamic storage information output.
307      *
308      * @return ERR_OK, return back success,others fail.
309      */
310     virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo);
311 
312     /**
313      * @brief Check whether the shared bundle is running.
314      *
315      * @param bundleName Shared bundle name.
316      * @param versionCode Shared bundle version code.
317      * @return Returns the shared bundle running result. The result is true if running, false otherwise.
318      */
319     virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode);
320 
321     int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) const;
322 
323     std::shared_ptr<AppRunningRecord> CreateAppRunningRecord(
324         const sptr<IRemoteObject> &token,
325         const sptr<IRemoteObject> &preToken,
326         const std::shared_ptr<ApplicationInfo> &appInfo,
327         const std::shared_ptr<AbilityInfo> &abilityInfo,
328         const std::string &processName,
329         const BundleInfo &bundleInfo,
330         const HapModuleInfo &hapModuleInfo,
331         const std::shared_ptr<AAFwk::Want> &want);
332 
333     /**
334      * OnStop, Application management service stopped.
335      *
336      * @return
337      */
338     void OnStop();
339 
340     /**
341      * OpenAppSpawnConnection, Open connection with appspawn.
342      *
343      * @return ERR_OK ,return back success,others fail.
344      */
345     virtual ErrCode OpenAppSpawnConnection();
346 
347     /**
348      * CloseAppSpawnConnection, Close connection with appspawn.
349      *
350      * @return
351      */
352     virtual void CloseAppSpawnConnection() const;
353 
354     /**
355      * QueryAppSpawnConnectionState, Query the connection status with appspawn.
356      *
357      * @return Returns the connection status with appspawn.
358      */
359     virtual SpawnConnectionState QueryAppSpawnConnectionState() const;
360 
361     /**
362      * SetAppSpawnClient, Setting the client to connect with appspawn.
363      *
364      * @param spawnClient, the client to connect with appspawn.
365      *
366      * @return
367      */
368     void SetAppSpawnClient(std::shared_ptr<AppSpawnClient> spawnClient);
369 
370     // Schedule launch application with specified |appRecord|
371 
372     /**
373      * LaunchApplication, Notify application to launch application.
374      *
375      * @param appRecord, the application record.
376      *
377      * @return
378      */
379     void LaunchApplication(const std::shared_ptr<AppRunningRecord> &appRecord);
380 
381     /**
382      * Notice of AddAbilityStageInfo()
383      *
384      * @param recordId, the application record.
385      */
386     virtual void AddAbilityStageDone(const int32_t recordId);
387 
388     /**
389      * GetAppRunningRecordByPid, Get process record by application pid.
390      *
391      * @param pid, the application pid.
392      *
393      * @return process record.
394      */
395     std::shared_ptr<AppRunningRecord> GetAppRunningRecordByPid(const pid_t pid) const;
396 
397     /**
398      * GetAppRunningRecordByAbilityToken, Get process record by ability token.
399      *
400      * @param abilityToken, the ability token.
401      *
402      * @return process record.
403      */
404     std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAbilityToken(const sptr<IRemoteObject> &abilityToken) const;
405 
406     /**
407      * GetTerminatingAppRunningRecord, Get process record by ability token.
408      *
409      * @param abilityToken, the ability token.
410      *
411      * @return process record.
412      */
413     std::shared_ptr<AppRunningRecord> GetTerminatingAppRunningRecord(const sptr<IRemoteObject> &token) const;
414 
415     /**
416      * GetAppRunningRecordByAppRecordId, Get process record by application id.
417      *
418      * @param recordId, the application id.
419      *
420      * @return process record.
421      */
422     std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAppRecordId(const int32_t recordId) const;
423 
424     /**
425      * OnAbilityStateChanged, Call ability state change.
426      *
427      * @param ability, the ability info.
428      * @param state, the ability state.
429      *
430      * @return
431      */
432     void OnAbilityStateChanged(const std::shared_ptr<AbilityRunningRecord> &ability, const AbilityState state);
433 
434     /**
435      * GetRecentAppList, Get a list of recent applications.
436      *
437      * @return a list of recent applications.
438      */
439     const std::list<const std::shared_ptr<AppTaskInfo>> &GetRecentAppList() const;
440 
441     /**
442      * GetRecentAppList, Remove the corresponding latest application list data by applying the name.
443      *
444      * @param appName, the application name.
445      * @param processName, the process name.
446      *
447      * @return
448      */
449     void RemoveAppFromRecentList(const std::string &appName, const std::string &processName);
450 
451     /**
452      * GetRecentAppList, Clear recent application list.
453      *
454      * @return
455      */
456     void ClearRecentAppList();
457 
458     /**
459      * OnRemoteDied, Equipment death notification.
460      *
461      * @param remote, Death client.
462      * @param isRenderProcess is render process died.
463      * @return
464      */
465     void OnRemoteDied(const wptr<IRemoteObject> &remote, bool isRenderProcess = false);
466 
467     /**
468      * AddAppDeathRecipient, Add monitoring death application record.
469      *
470      * @param pid, the application pid.
471      * @param appDeathRecipient, Application death recipient list.
472      *
473      * @return
474      */
475 
476     virtual void AddAppDeathRecipient(const pid_t pid, const sptr<AppDeathRecipient> &appDeathRecipient) const;
477 
478     void HandleTimeOut(const AAFwk::EventWrap &event);
479 
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)480     void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)
481     {
482         taskHandler_ = taskHandler;
483     }
484 
SetEventHandler(const std::shared_ptr<AMSEventHandler> & eventHandler)485     void SetEventHandler(const std::shared_ptr<AMSEventHandler> &eventHandler)
486     {
487         eventHandler_ = eventHandler;
488     }
489 
490     void HandleAbilityAttachTimeOut(const sptr<IRemoteObject> &token);
491 
492     void PrepareTerminate(const sptr<IRemoteObject> &token);
493 
494     void OnAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state,
495         bool needNotifyApp);
496 
497     void OnAppStarted(const std::shared_ptr<AppRunningRecord> &appRecord);
498 
499     void OnAppStopped(const std::shared_ptr<AppRunningRecord> &appRecord);
500 
501     void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info);
502 
503     void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const;
504 
505     /**
506      * Set AbilityForegroundingFlag of an app-record to true.
507      *
508      * @param pid, pid.
509      *
510      */
511     void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const;
512 
513      /**
514      * UpdateConfiguration, ANotify application update system environment changes.
515      *
516      * @param config, System environment change parameters.
517      * @return Returns ERR_OK on success, others on failure.
518      */
519     int32_t UpdateConfiguration(const Configuration &config);
520 
521     std::shared_ptr<AppExecFwk::Configuration> GetConfiguration();
522 
523     int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer);
524 
525     int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver>& observer);
526 
527     /**
528      * Start empty process
529      */
530     void LoadResidentProcess(const std::vector<BundleInfo> &infos);
531 
532     void StartResidentProcess(const std::vector<BundleInfo> &infos,  int restartCount, bool isEmptyKeepAliveApp);
533 
534     bool CheckRemoteClient();
535 
536     /**
537      * Register application or process state observer.
538      * @param observer, ability token.
539      * @return Returns ERR_OK on success, others on failure.
540      */
541     int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
542         const std::vector<std::string> &bundleNameList = {});
543 
544     /**
545      * Unregister application or process state observer.
546      * @param observer, ability token.
547      * @return Returns ERR_OK on success, others on failure.
548      */
549     int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer);
550 
551     /**
552      * Get Foreground Applications.
553      *
554      * @return Foreground Applications.
555      */
556     int32_t GetForegroundApplications(std::vector<AppStateData> &list);
557 
558     /**
559      * Start user test process.
560      * @param want, want object.
561      * @param observer, test observer remote object.
562      * @param bundleInfo, bundle info.
563      * @param userId the user id.
564      * @return Returns ERR_OK on success, others on failure.
565      */
566     int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
567         const AppExecFwk::BundleInfo &bundleInfo, int32_t userId);
568 
569     /**
570      * @brief Finish user test.
571      * @param msg user test message.
572      * @param resultCode user test result Code.
573      * @param bundleName user test bundleName.
574      * @param pid the user test process id.
575      *
576      * @return Returns ERR_OK on success, others on failure.
577      */
578     int FinishUserTest(
579         const std::string &msg, const int64_t &resultCode, const std::string &bundleName, const pid_t &pid);
580 
581     void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo);
582 
583     void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response);
584 
585     void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag);
586 
587     /**
588      *  Get the token of ability records by process ID.
589      *
590      * @param pid The process id.
591      * @param tokens The token of ability records.
592      * @return Returns true on success, others on failure.
593      */
594     int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens);
595 
596     virtual int32_t PreStartNWebSpawnProcess(const pid_t hostPid);
597 
598     virtual int32_t StartRenderProcess(const pid_t hostPid,
599                                        const std::string &renderParam,
600                                        int32_t ipcFd, int32_t sharedFd,
601                                        int32_t crashFd, pid_t &renderPid);
602 
603     virtual void AttachRenderProcess(const pid_t pid, const sptr<IRenderScheduler> &scheduler);
604 
605     virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status);
606 
607     int VerifyProcessPermission(const sptr<IRemoteObject> &token) const;
608 
609     int VerifyAccountPermission(const std::string &permissionName, const int userId) const;
610 
611     int VerifyRequestPermission() const;
612 
613     void ClearAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord, bool containsApp);
614 
615     void TerminateApplication(const std::shared_ptr<AppRunningRecord> &appRecord);
616 
617     int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug);
618     /**
619      * Notify application status.
620      *
621      * @param bundleName Indicates the name of the bundle.
622      * @param eventData Indicates the event defined by CommonEventSupport
623      *
624      * @return
625      */
626     void NotifyAppStatus(const std::string &bundleName, const std::string &eventData);
627 
628     /**
629      * KillProcessByPid, Kill process by PID.
630      *
631      * @param pid_t, the app record pid.
632      *
633      * @return ERR_OK, return back success,others fail.
634      */
635     int32_t KillProcessByPid(const pid_t pid) const;
636 
637     bool GetAppRunningStateByBundleName(const std::string &bundleName);
638 
639     int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback);
640 
641     int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback);
642 
643     int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback);
644 
645     void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
646     void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
647 
648     /**
649      * Set the current userId, only used by abilityMgr.
650      *
651      * @param userId the user id.
652      *
653      * @return
654      */
655     void SetCurrentUserId(const int32_t userId);
656 
657 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
658     int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask);
659 #endif
660 
661     /**
662      * Get bundleName by pid.
663      *
664      * @param pid process id.
665      * @param bundleName Output parameters, return bundleName.
666      * @param uid Output parameters, return userId.
667      * @return Returns ERR_OK on success, others on failure.
668      */
669     int32_t GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid);
670 
671     /**
672      * Notify Fault Data
673      *
674      * @param faultData the fault data.
675      * @return Returns ERR_OK on success, others on failure.
676      */
677     int32_t NotifyAppFault(const FaultData &faultData);
678 
679     /**
680      * Notify Fault Data By SA
681      *
682      * @param faultData the fault data notified by SA.
683      * @return Returns ERR_OK on success, others on failure.
684      */
685     int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData);
686 
687     /**
688      * get memorySize by pid.
689      *
690      * @param pid process id.
691      * @param memorySize Output parameters, return memorySize in KB.
692      * @return Returns ERR_OK on success, others on failure.
693      */
694     virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize);
695 
696     /**
697      * get application processes information list by bundleName.
698      *
699      * @param bundleName Bundle name.
700      * @param userId user Id in Application record.
701      * @param info Output parameters, return running process info list.
702      * @return Returns ERR_OK on success, others on failure.
703      */
704     virtual int32_t GetRunningProcessInformation(
705         const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info) ;
706 
707 private:
708 
709     std::string FaultTypeToString(FaultDataType type);
710 
711     FaultData ConvertDataTypes(const AppFaultDataBySA &faultData);
712 
713     void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount,
714         bool isEmptyKeepAliveApp);
715 
716     void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord);
717 
718     bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token,
719         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo);
720 
721     bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo);
722 
723     bool GenerateRenderUid(int32_t &renderUid);
724 
725     void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
726         const std::shared_ptr<ApplicationInfo> &appInfo,
727         const HapModuleInfo &hapModuleInfo, int32_t appIndex, std::string &processName) const;
728 
729     void MakeProcessName(const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo,
730         std::string &processName) const;
731 
732     bool CheckIsolationMode(const HapModuleInfo &hapModuleInfo) const;
733 
734     /**
735      * StartAbility, load the ability that needed to be started(Start on the basis of the original process).
736      *  Start on a new boot process
737      * @param token, the unique identification to start the ability.
738      * @param preToken, the unique identification to call the ability.
739      * @param abilityInfo, the ability information.
740      * @param appInfo, the app information.
741      *
742      * @return
743      */
744     void StartAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
745         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<AppRunningRecord> &appRecord,
746         const HapModuleInfo &hapModuleInfo, const std::shared_ptr<AAFwk::Want> &want);
747 
748     int32_t StartPerfProcess(const std::shared_ptr<AppRunningRecord> &appRecord, const std::string& perfCmd,
749         const std::string& debugCmd, bool isSanboxApp) const;
750 
751     void StartProcessVerifyPermission(const BundleInfo &bundleInfo, bool &hasAccessBundleDirReq,
752         uint8_t &setAllowInternet, uint8_t &allowInternet, std::vector<int32_t> &gids,
753         std::set<std::string> &permissions);
754 
755     /**
756      * StartProcess, load the ability that needed to be started(Start on a new boot process).
757      *
758      * @param appName, the app name.
759      * @param processName, the process name.
760      * @param appRecord, the app information.
761      * @param uid, the process uid.
762      * @param bundleName, the app bundleName.
763      *
764      * @return
765      */
766     void StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags,
767                       const std::shared_ptr<AppRunningRecord> &appRecord, const int uid,
768                       const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag = true);
769 
770     /**
771      * PushAppFront, Adjust the latest application record to the top level.
772      *
773      * @param recordId, the app record id.
774      *
775      * @return
776      */
777     void PushAppFront(const int32_t recordId);
778 
779     /**
780      * RemoveAppFromRecentListById, Remove the specified recent application record by application record id.
781      *
782      * @param recordId, the app record id.
783      *
784      * @return
785      */
786     void RemoveAppFromRecentListById(const int32_t recordId);
787 
788     /**
789      * AddAppToRecentList, Add application to recent list.
790      *
791      * @param appName, the app name.
792      * @param processName, the process name.
793      * @param pid, the app pid.
794      * @param recordId, the app record id.
795      *
796      * @return
797      */
798     void AddAppToRecentList(
799         const std::string &appName, const std::string &processName, const pid_t pid, const int32_t recordId);
800 
801     /**
802      * AddAppToRecentList, Get application task information through ID.
803      *
804      * @param recordId, the app record id.
805      *
806      * @return application task information.
807      */
808     const std::shared_ptr<AppTaskInfo> GetAppTaskInfoById(const int32_t recordId) const;
809 
810     /**
811      * KillApplicationByUserId, kill the application by user ID.
812      *
813      * @param bundleName, bundle name in Application record.
814      * @param userId, user ID.
815      *
816      * @return ERR_OK, return back success, others fail.
817      */
818     int32_t KillApplicationByUserIdLocked(const std::string &bundleName, const int userId);
819 
820     /**
821      * WaitForRemoteProcessExit, Wait for the process to exit normally.
822      *
823      * @param pids, process number collection to exit.
824      * @param startTime, execution process security exit start time.
825      *
826      * @return true, return back success,others fail.
827      */
828     bool WaitForRemoteProcessExit(std::list<pid_t> &pids, const int64_t startTime);
829 
830     /**
831      * GetAllPids, Get the corresponding pid collection.
832      *
833      * @param pids, process number collection to exit.
834      *
835      * @return true, return back success,others fail.
836      */
837     bool GetAllPids(std::list<pid_t> &pids);
838 
839     /**
840      * ProcessExist, Judge whether the process exists.
841      *
842      * @param pids, process number collection to exit.
843      *
844      * @return true, return back existed,others non-existent.
845      */
846     bool ProcessExist(pid_t &pid);
847 
848     /**
849      * CheckAllProcessExist, Determine whether all processes exist .
850      *
851      * @param pids, process number collection to exit.
852      *
853      * @return true, Returns that a process exists and all other processes do not exist.
854      */
855     bool CheckAllProcessExist(std::list<pid_t> &pids);
856 
857     /**
858      * SystemTimeMillisecond, Get system time.
859      *
860      * @return the system time.
861      */
862     int64_t SystemTimeMillisecond();
863 
864     // Test add the bundle manager instance.
865     void SetBundleManager(sptr<IBundleMgr> bundleManager);
866 
867     void HandleTerminateApplicationTimeOut(const int64_t eventId);
868 
869     void HandleAddAbilityStageTimeOut(const int64_t eventId);
870 
871     void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr);
872 
873     bool GetBundleAndHapInfo(const AbilityInfo &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo,
874         BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex = 0) const;
875     AppProcessData WrapAppProcessData(const std::shared_ptr<AppRunningRecord> &appRecord,
876         const ApplicationState state);
877 
878     int UserTestAbnormalFinish(const sptr<IRemoteObject> &observer, const std::string &msg);
879     int GetHapModuleInfoForTestRunner(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
880         const BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo);
881     int StartEmptyProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &info,
882         const std::string &processName, const int userId);
883 
884     void HandleStartSpecifiedAbilityTimeOut(const int64_t eventId);
885 
886     void InitGlobalConfiguration();
887 
888     void GetRunningProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RunningProcessInfo> &info);
889     void GetRunningProcess(const std::shared_ptr<AppRunningRecord> &appRecord, RunningProcessInfo &info);
890 
891     void GetRenderProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RenderProcessInfo> &info);
892 
893     int StartRenderProcessImpl(const std::shared_ptr<RenderRecord> &renderRecord,
894         const std::shared_ptr<AppRunningRecord> appRecord, pid_t &renderPid);
895 
896     void OnRenderRemoteDied(const wptr<IRemoteObject> &remote);
897 
898     void AddWatchParameter();
899 
900     bool VerifyAPL() const;
901 
902     void InitFocusListener();
903     void RegisterFocusListener();
904 
905     static void PointerDeviceEventCallback(const char *key, const char *value, void *context);
906 
907     int VerifyProcessPermission() const;
908 
909     int VerifyProcessPermission(const std::string &bundleName) const;
910 
911 private:
912     /**
913      * ClearUpApplicationData, clear the application data.
914      *
915      * @param bundleName, bundle name in Application record.
916      * @param uid, app uid in Application record.
917      * @param pid, app pid in Application record.
918      * @param userId, userId.
919      *
920      * @return
921      */
922     void ClearUpApplicationDataByUserId(const std::string &bundleName,
923         int32_t callerUid, pid_t callerPid, const int userId);
924 
925     uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abilityInfo);
926 
927     bool CheckGetRunningInfoPermission() const;
928 
929     int32_t KillApplicationByBundleName(const std::string &bundleName);
930 
931     bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord);
932 
933     void SendAppStartupTypeEvent(const std::shared_ptr<AppRunningRecord> &appRecord,
934         const std::shared_ptr<AbilityInfo> &abilityInfo, const AppStartType startType);
935 
936     void SendProcessExitEvent(pid_t pid);
937 
938     void SendProcessExitEventTask(pid_t pid, time_t exitTime, int32_t count);
939 
940     void UpDateStartupType(const std::shared_ptr<AbilityInfo> &info, int32_t &abilityType, int32_t &extensionType);
941 
942     void SetRunningSharedBundleList(const std::string &bundleName,
943         const std::vector<BaseSharedBundleInfo> baseSharedBundleInfoList);
944 
945     void RemoveRunningSharedBundleList(const std::string &bundleName);
946 
947     void KillRenderProcess(const std::shared_ptr<AppRunningRecord> &appRecord);
948 
949     void SetOverlayInfo(const std::string& bundleName, const int32_t userId, AppSpawnStartMsg& startMsg);
950 
951     void TimeoutNotifyApp(int32_t pid, int32_t uid, const std::string& bundleName, const FaultData &faultData);
952 
953     void AppRecoveryNotifyApp(int32_t pid, const std::string& bundleName,
954         FaultDataType faultType, const std::string& markers);
955 private:
956     /**
957      * Notify application status.
958      *
959      * @param bundleName Indicates the name of the bundle.
960      * @param bundleName Indicates the name of the bundle.
961      * @param eventData Indicates the event defined by CommonEventSupport
962      *
963      * @return
964      */
965     void NotifyAppStatusByCallerUid(const std::string &bundleName, const int32_t userId, const int32_t callerUid,
966         const std::string &eventData);
967     void KillApplicationByRecord(const std::shared_ptr<AppRunningRecord> &appRecord);
968     void SendHiSysEvent(const int32_t innerEventId, const int64_t eventId);
969     int FinishUserTestLocked(
970         const std::string &msg, const int64_t &resultCode, const std::shared_ptr<AppRunningRecord> &appRecord);
971     int32_t GetCurrentAccountId() const;
972     const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
973     std::vector<const sptr<IAppStateCallback>> appStateCallbacks_;
974     std::shared_ptr<AppProcessManager> appProcessManager_;
975     std::shared_ptr<RemoteClientManager> remoteClientManager_;
976     std::shared_ptr<AppRunningManager> appRunningManager_;
977     std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
978     std::shared_ptr<AMSEventHandler> eventHandler_;
979     std::shared_ptr<Configuration> configuration_;
980     ffrt::mutex userTestLock_;
981     ffrt::mutex appStateCallbacksLock_;
982     ffrt::mutex renderUidSetLock_;
983     sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_;
984     ffrt::mutex configurationObserverLock_;
985     std::vector<sptr<IConfigurationObserver>> configurationObservers_;
986     sptr<WindowFocusChangedListener> focusListener_;
987     std::vector<std::shared_ptr<AppRunningRecord>> restartResedentTaskList_;
988     std::map<std::string, std::vector<BaseSharedBundleInfo>> runningSharedBundleList_;
989     std::unordered_set<int32_t> renderUidSet_;
990     std::string supportIsolationMode_ {"false"};
991     std::string deviceType_ {"default"};
992     int32_t currentUserId_ = 0;
993     int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS;
994 };
995 }  // namespace AppExecFwk
996 }  // namespace OHOS
997 #endif  // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
998