• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ABILITY_RUNTIME_MAIN_THREAD_H
17 #define OHOS_ABILITY_RUNTIME_MAIN_THREAD_H
18 
19 #include <string>
20 #include <signal.h>
21 #include <mutex>
22 
23 #include "ability_record_mgr.h"
24 #include "app_jsheap_mem_info.h"
25 #include "app_cjheap_mem_info.h"
26 #include "app_malloc_info.h"
27 #include "app_mgr_interface.h"
28 #include "app_scheduler_host.h"
29 #include "application_impl.h"
30 #include "assert_fault_task_thread.h"
31 #include "common_event_subscriber.h"
32 #include "event_handler.h"
33 #include "extension_config_mgr.h"
34 #include "idle_time.h"
35 #include "inner_event.h"
36 #include "ipc_singleton.h"
37 #include "js_runtime.h"
38 #include "native_engine/native_engine.h"
39 #include "overlay_event_subscriber.h"
40 #include "resource_manager.h"
41 #include "runtime.h"
42 #include "watchdog.h"
43 
44 #ifdef CJ_FRONTEND
45 #include "cj_envsetup.h"
46 #endif
47 #define ABILITY_LIBRARY_LOADER
48 
49 #if defined(NWEB) && defined(NWEB_GRAPHIC)
50 #include "nweb_preload.h"
51 #include "ui/rs_surface_node.h"
52 #endif
53 
54 class Runtime;
55 namespace OHOS {
56 namespace JsEnv {
57 struct ErrorObject;
58 using UncatchableTask = std::function<void(std::string summary, const JsEnv::ErrorObject errorObject)>;
59 }  // namespace JsEnv
60 namespace EtsEnv {
61 struct ETSUncaughtExceptionInfo;
62 } // namespace EtsEnv
63 namespace AppExecFwk {
64 using namespace OHOS::Global;
65 using OHOS::AbilityRuntime::Runtime;
66 struct BaseSharedBundleInfo;
67 using HspList = std::vector<BaseSharedBundleInfo>;
68 enum class MainThreadState { INIT, ATTACH, READY, RUNNING };
69 struct BundleInfo;
70 struct PluginBundleInfo;
71 struct UncatchableTaskInfo {
72     std::string bundleName;
73     uint32_t versionCode;
74     std::string appRunningId;
75     int32_t pid;
76     std::string processName;
77 };
78 class ContextDeal;
79 struct ModuleTestRunner;
80 // class Global::Resource::ResourceManager;
81 class AppMgrDeathRecipient : public IRemoteObject::DeathRecipient {
82 public:
83     /**
84      *
85      * @brief Notify the AppMgrDeathRecipient that the remote is dead.
86      *
87      * @param remote The remote which is dead.
88      */
89     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
90     AppMgrDeathRecipient() = default;
91     ~AppMgrDeathRecipient() override = default;
92 };
93 
94 class MainThread : public AppSchedulerHost {
95     DECLARE_DELAYED_IPCSINGLETON(MainThread);
96 
97 public:
98     /**
99      *
100      * @brief Get the current MainThreadState.
101      *
102      * @return Returns the current MainThreadState.
103      */
104     MainThreadState GetMainThreadState() const;
105 
106     /**
107      *
108      * @brief Get the runner state of mainthread.
109      *
110      * @return Returns the runner state of mainthread.
111      */
112     bool GetRunnerStarted() const;
113 
114     /**
115      *
116      * @brief Get the newThreadId.
117      *
118      * @return Returns the newThreadId.
119      */
120     int GetNewThreadId();
121 
122     /**
123      *
124      * @brief Get the application.
125      *
126      * @return Returns the application.
127      */
128     std::shared_ptr<OHOSApplication> GetApplication() const;
129 
130     /**
131      *
132      * @brief Get the applicationInfo.
133      *
134      * @return Returns the applicationInfo.
135      */
136     std::shared_ptr<ApplicationInfo> GetApplicationInfo() const;
137 
138     /**
139      *
140      * @brief Get the applicationImpl.
141      *
142      * @return Returns the applicationImpl.
143      */
144     std::shared_ptr<ApplicationImpl> GetApplicationImpl();
145 
146     /**
147      *
148      * @brief Get the eventHandler of mainthread.
149      *
150      * @return Returns the eventHandler of mainthread.
151      */
152     std::shared_ptr<EventHandler> GetMainHandler() const;
153 
154     /**
155      *
156      * @brief Schedule the foreground lifecycle of application.
157      *
158      */
159     bool ScheduleForegroundApplication() override;
160 
161     /**
162      *
163      * @brief Schedule the background lifecycle of application.
164      *
165      */
166     void ScheduleBackgroundApplication() override;
167 
168     /**
169      *
170      * @brief Schedule the terminate lifecycle of application.
171      *
172      * @param isLastProcess When it is the last application process, pass in true.
173      */
174     void ScheduleTerminateApplication(bool isLastProcess = false) override;
175 
176     /**
177      *
178      * @brief Shrink the memory which used by application.
179      *
180      * @param level Indicates the memory trim level, which shows the current memory usage status.
181      */
182     void ScheduleShrinkMemory(const int level) override;
183 
184     /**
185      *
186      * @brief Notify the current memory.
187      *
188      * @param level Indicates the memory trim level, which shows the current memory usage status.
189      */
190     void ScheduleMemoryLevel(const int level) override;
191 
192     /**
193      *
194      * @brief Get the application's memory allocation info.
195      *
196      * @param pid, pid input.
197      * @param mallocInfo, dynamic storage information output.
198      */
199     void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override;
200 
201     /**
202      *
203      * @brief triggerGC and dump the application's jsheap memory info.
204      *
205      * @param info, pid, tid, needGc, needSnapshot.
206      */
207     void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) override;
208 
209     /**
210      *
211      * @brief triggerGC and dump the application's cjheap memory info.
212      *
213      * @param info, pid, needGc, needSnapshot.
214      */
215     void ScheduleCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo &info) override;
216 
217     /**
218      *
219      * @brief Low the memory which used by application.
220      *
221      */
222     void ScheduleLowMemory() override;
223 
224     /**
225      *
226      * @brief Launch the application.
227      *
228      * @param data The launchdata of the application witch launced.
229      *
230      */
231     void ScheduleLaunchApplication(const AppLaunchData &data, const Configuration &config) override;
232 
233     /**
234      *
235      * @brief update the application info after new module installed.
236      *
237      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
238      *
239      */
240     void ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo &appInfo, const std::string &moduleName) override;
241 
242     /**
243      * Notify application to launch ability stage.
244      *
245      * @param The resident process data value.
246      */
247     void ScheduleAbilityStage(const HapModuleInfo &abilityStage) override;
248 
249     void ScheduleLaunchAbility(const AbilityInfo &info, const sptr<IRemoteObject> &token,
250         const std::shared_ptr<AAFwk::Want> &want, int32_t abilityRecordId) override;
251 
252     /**
253      *
254      * @brief clean the ability by token.
255      *
256      * @param token The token belong to the ability which want to be cleaned.
257      *
258      */
259     void ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false) override;
260 
261     /**
262      *
263      * @brief send the new profile.
264      *
265      * @param profile The updated profile.
266      *
267      */
268     void ScheduleProfileChanged(const Profile &profile) override;
269 
270     /**
271      *
272      * @brief send the new config to the application.
273      *
274      * @param config The updated config.
275      *
276      */
277     void ScheduleConfigurationUpdated(const Configuration &config) override;
278 
279     /**
280      *
281      * @brief Starts the mainthread.
282      *
283      */
284     static void Start();
285 
286     static void StartChild(const std::map<std::string, int32_t> &fds);
287 
288     /**
289      *
290      * @brief Preload extensions in appspawn.
291      *
292      */
293     static void PreloadExtensionPlugin();
294 
295     /**
296      *
297      * @brief Schedule the application process exit safely.
298      *
299      */
300     void ScheduleProcessSecurityExit() override;
301 
302     void ScheduleClearPageStack() override;
303 
304     void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override;
305 
306     void SchedulePrepareTerminate(const std::string &moduleName) override;
307 
308     void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override;
309 
310     /**
311      *
312      * @brief Check the App main thread state.
313      *
314      */
315     void CheckMainThreadIsAlive();
316 
317     int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
318         const int32_t recordId) override;
319 
320     int32_t ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
321 
322     int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName,
323         const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
324 
325     int32_t ScheduleNotifyAppFault(const FaultData &faultData) override;
326 #ifdef CJ_FRONTEND
327     CJUncaughtExceptionInfo CreateCjExceptionInfo(const std::string &bundleName, uint32_t versionCode,
328         const std::string &hapPath);
329 #endif
330     EtsEnv::ETSUncaughtExceptionInfo CreateEtsExceptionInfo(const std::string &bundleName, uint32_t versionCode,
331         const std::string &hapPath, std::string &appRunningId, int32_t pid, std::string &processName);
332     /**
333      * @brief Notify NativeEngine GC of status change.
334      *
335      * @param state GC state
336      *
337      * @return Is the status change completed.
338      */
339     int32_t ScheduleChangeAppGcState(int32_t state, uint64_t tid = 0) override;
340 
341     void AttachAppDebug(bool isDebugFromLocal) override;
342     void DetachAppDebug() override;
343     bool NotifyDeviceDisConnect();
344 
345     void AssertFaultPauseMainThreadDetection();
346     void AssertFaultResumeMainThreadDetection();
347 
348     /**
349      * ScheduleDumpIpcStart, call ScheduleDumpIpcStart(std::string& result) through proxy project,
350      * Start querying the application's IPC payload info.
351      *
352      * @param result, start IPC dump result output.
353      *
354      * @return Returns 0 on success, error code on failure.
355      */
356     int32_t ScheduleDumpIpcStart(std::string& result) override;
357 
358     /**
359      * ScheduleDumpIpcStop, call ScheduleDumpIpcStop(std::string& result) through proxy project,
360      * Stop querying the application's IPC payload info.
361      *
362      * @param result, stop IPC dump result output.
363      *
364      * @return Returns 0 on success, error code on failure.
365      */
366     int32_t ScheduleDumpIpcStop(std::string& result) override;
367 
368     /**
369      * ScheduleDumpIpcStat, call ScheduleDumpIpcStat(std::string& result) through proxy project,
370      * Collect the application's IPC payload info.
371      *
372      * @param result, IPC payload result output.
373      *
374      * @return Returns 0 on success, error code on failure.
375      */
376     int32_t ScheduleDumpIpcStat(std::string& result) override;
377 
378     void ScheduleCacheProcess() override;
379     /**
380      * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project,
381      * Start querying the application's ffrt usage.
382      *
383      * @param result, ffrt dump result output.
384      *
385      * @return Returns 0 on success, error code on failure.
386      */
387     int32_t ScheduleDumpFfrt(std::string& result) override;
388 
389     /**
390      *
391      * @brief Set watchdog background status of application.
392      *
393      */
394     void SetWatchdogBackgroundStatus(bool status) override;
395 
396 private:
397     /**
398      *
399      * @brief Terminate the application but don't notify ams.
400      *
401      */
402     void HandleTerminateApplicationLocal();
403 
404     void HandleScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName);
405 
406     void HandleScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName);
407 
408     void HandleJsHeapMemory(const OHOS::AppExecFwk::JsHeapDumpInfo &info);
409 
410     void HandleCjHeapMemory(const OHOS::AppExecFwk::CjHeapDumpInfo &info);
411 
412     void HandleSchedulePrepareTerminate(const std::string &moduleName);
413 
414     void PreloadModule(const AppExecFwk::HapModuleInfo &entryHapModuleInfo,
415         const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
416 
417     void ProcessMainAbility(const AbilityInfo &info, const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
418 
419     /**
420      *
421      * @brief Schedule the application process exit safely.
422      *
423      */
424     void HandleProcessSecurityExit();
425 
426     /**
427      *
428      * @brief Clean the ability but don't notify ams.
429      *
430      * @param token The token which belongs to the ability launched.
431      *
432      */
433     void HandleCleanAbilityLocal(const sptr<IRemoteObject> &token);
434 
435     /**
436      *
437      * @brief Launch the application.
438      *
439      * @param appLaunchData The launchdata of the application witch launced.
440      *
441      */
442     void HandleLaunchApplication(const AppLaunchData &appLaunchData, const Configuration &config);
443 
444     /**
445      *
446      * @brief Init the uncatchable task.
447      *
448      * @param uncatchableTaskInfo The info of the uncatchable task.
449      * @param isUncatchable Weather task is uncatcheable.
450      *
451      */
452     void InitUncatchableTask(JsEnv::UncatchableTask &uncatchableTask, const UncatchableTaskInfo &uncatchableTaskInfo,
453         bool isUncatchable = false);
454 
455     /**
456      *
457      * @brief update the application info after new module installed.
458      *
459      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
460      *
461      */
462     void HandleUpdateApplicationInfoInstalled(const ApplicationInfo &appInfo, const std::string &moduleName);
463 
464     /**
465      *
466      * @brief Launch the application.
467      *
468      * @param appLaunchData The launchdata of the application witch launced.
469      *
470      */
471     void HandleAbilityStage(const HapModuleInfo &abilityStage);
472 
473     /**
474      *
475      * @brief Launch the ability.
476      *
477      * @param abilityRecord The abilityRecord which belongs to the ability launched.
478      *
479      */
480     void HandleLaunchAbility(const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
481 
482     /**
483      *
484      * @brief Clean the ability.
485      *
486      * @param token The token which belongs to the ability launched.
487      *
488      */
489     void HandleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false);
490 
491     /**
492      *
493      * @brief Foreground the application.
494      *
495      */
496     void HandleForegroundApplication();
497 
498     /**
499      *
500      * @brief Background the application.
501      *
502      */
503     void HandleBackgroundApplication();
504 
505     /**
506      *
507      * @brief Terminate the application.
508      *
509      */
510     void HandleTerminateApplication(bool isLastProcess = false);
511 
512     /**
513      *
514      * @brief Shrink the memory which used by application.
515      *
516      * @param level Indicates the memory trim level, which shows the current memory usage status.
517      *
518      */
519     void HandleShrinkMemory(const int level);
520 
521     /**
522      *
523      * @brief Notify the memory.
524      *
525      * @param level Indicates the memory trim level, which shows the current memory usage status.
526      *
527      */
528     void HandleMemoryLevel(int level);
529 
530     /**
531      *
532      * @brief send the new config to the application.
533      *
534      * @param config The updated config.
535      *
536      */
537     void HandleConfigurationUpdated(const Configuration &config);
538 
539     /**
540      *
541      * @brief remove the deathRecipient from appMgr.
542      *
543      */
544     void RemoveAppMgrDeathRecipient();
545 
546     /**
547      *
548      * @brief Attach the mainthread to the AppMgr.
549      *
550      */
551     void Attach();
552 
553     /**
554      *
555      * @brief Set the runner state of mainthread.
556      *
557      * @param runnerStart whether the runner is started.
558      */
559     void SetRunnerStarted(bool runnerStart);
560 
561     /**
562      *
563      * @brief Connect the mainthread to the AppMgr.
564      *
565      */
566     bool ConnectToAppMgr();
567 
568     /**
569      *
570      * @brief Check whether the appLaunchData is legal.
571      *
572      * @param appLaunchData The appLaunchData should be checked.
573      *
574      * @return if the appLaunchData is legal, return true. else return false.
575      */
576     bool CheckLaunchApplicationParam(const AppLaunchData &appLaunchData) const;
577 
578     /**
579      *
580      * @brief Check whether the record is legal.
581      *
582      * @param record The record should be checked.
583      *
584      * @return if the record is legal, return true. else return false.
585      */
586     bool CheckAbilityItem(const std::shared_ptr<AbilityLocalRecord> &record) const;
587 
588     /**
589      *
590      * @brief Init the mainthread.
591      *
592      * @param runner the runner belong to the mainthread.
593      *
594      */
595     void Init(const std::shared_ptr<EventRunner> &runner);
596 
597     /**
598      *
599      * @brief Task in event handler timeout detected.
600      *
601      * @param runner the runner belong to the mainthread.
602      *
603      */
604     void TaskTimeoutDetected(const std::shared_ptr<EventRunner>& runner);
605 
606     /**
607      *
608      * @brief Check whether the OHOSApplication is ready.
609      *
610      * @return if the OHOSApplication is ready, return true. else return false.
611      *
612      */
613     bool IsApplicationReady() const;
614 
615     /**
616      * @brief Load all extension so
617      *
618      * @param nativeEngine nativeEngine instance
619      */
620     void LoadAllExtensions(NativeEngine &nativeEngine);
621 
622     void LoadAllExtensions();
623     /**
624      *
625      * @brief Ability Delegator Prepare.
626      *
627      * @param record User Test info.
628      *
629      */
630     bool PrepareAbilityDelegator(const std::shared_ptr<UserTestRecord> &record, bool isStageBased,
631         const AppExecFwk::HapModuleInfo &entryHapModuleInfo, uint32_t targetVersion);
632 
633     /**
634      * @brief Set current process extension type
635      *
636      * @param abilityRecord current running ability record
637      */
638     void SetProcessExtensionType(const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
639 
640     /**
641      * @brief Add Extension block item
642      *
643      * @param extensionName extension name
644      * @param type extension type
645      */
646     void AddExtensionBlockItem(const std::string &extensionName, int32_t type);
647 
648     /**
649      * @brief Update runtime module checker
650      *
651      * @param runtime runtime the ability runtime
652      */
653     void UpdateRuntimeModuleChecker(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
654 
655     static void HandleDumpHeapPrepare();
656     static void HandleDumpHeap(bool isPrivate);
657     static void DestroyHeapProfiler();
658     static void ForceFullGC();
659     static void HandleSignal(int signal, siginfo_t *siginfo, void *context);
660 
661     void NotifyAppFault(const FaultData &faultData);
662 
663     void OnOverlayChanged(const EventFwk::CommonEventData &data,
664         const std::shared_ptr<Global::Resource::ResourceManager> &resourceManager, const std::string &bundleName,
665         const std::string &moduleName, const std::string &loadPath);
666 
667     void HandleOnOverlayChanged(const EventFwk::CommonEventData &data,
668         const std::shared_ptr<Global::Resource::ResourceManager> &resourceManager, const std::string &bundleName,
669         const std::string &moduleName, const std::string &loadPath);
670 
671     int GetOverlayModuleInfos(const std::string &bundleName, const std::string &moduleName,
672         std::vector<OverlayModuleInfo> &overlayModuleInfos) const;
673 
674     std::vector<std::string> GetAddOverlayPaths(const std::vector<OverlayModuleInfo> &overlayModuleInfos);
675 
676     std::vector<std::string> GetRemoveOverlayPaths(const std::vector<OverlayModuleInfo> &overlayModuleInfos);
677 
678     int32_t ChangeAppGcState(int32_t state, uint64_t tid = 0);
679 
680     void HandleCacheProcess();
681 
682     bool IsBgWorkingThread(const AbilityInfo &info);
683 
684     void HandleUpdatePluginInfoInstalled(const ApplicationInfo &pluginAppInfo, const std::string &moduleName);
685 
686     /**
687      * @brief parse app configuration params
688      *
689      * @param configuration input configuration
690      * @config the config of application
691      */
692     void ParseAppConfigurationParams(const std::string configuration, Configuration &config);
693 
694     int32_t OnAttachLocalDebug(bool isDebugFromLocal);
695 
696     void HandleConfigByPlugin(Configuration &config, BundleInfo &bundleInfo);
697 
698 #if defined(NWEB) && defined(NWEB_GRAPHIC)
699     void HandleNWebPreload();
700 #endif
701 
702 #if defined(NWEB)
703     void PreLoadWebLib();
704 #endif
705 
706     class MainHandler : public EventHandler {
707     public:
708         MainHandler(const std::shared_ptr<EventRunner> &runner, const sptr<MainThread> &thread);
709         virtual ~MainHandler() = default;
710 
711         /**
712          *
713          * @brief Process the event.
714          *
715          * @param event the event want to be processed.
716          *
717          */
718         void ProcessEvent(const OHOS::AppExecFwk::InnerEvent::Pointer &event) override;
719 
720     private:
721         wptr<MainThread> mainThreadObj_ = nullptr;
722     };
723 
724     bool isRunnerStarted_ = false;
725     int newThreadId_ = -1;
726     std::shared_ptr<ApplicationInfo> applicationInfo_ = nullptr;
727     std::shared_ptr<ProcessInfo> processInfo_ = nullptr;
728     std::shared_ptr<OHOSApplication> application_ = nullptr;
729     std::shared_ptr<ApplicationImpl> applicationImpl_ = nullptr;
730     static std::shared_ptr<MainHandler> mainHandler_;
731     std::shared_ptr<AbilityRecordMgr> abilityRecordMgr_ = nullptr;
732     std::shared_ptr<Watchdog> watchdog_ = nullptr;
733     std::shared_ptr<AbilityRuntime::ExtensionConfigMgr> extensionConfigMgr_ = nullptr;
734     MainThreadState mainThreadState_ = MainThreadState::INIT;
735     sptr<IAppMgr> appMgr_ = nullptr;  // appMgrService Handler
736     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
737     std::string pathSeparator_ = "/";
738     std::string abilityLibraryType_ = ".so";
739     static std::weak_ptr<OHOSApplication> applicationForDump_;
740     bool isDeveloperMode_ = false;
741 #if defined(NWEB) && defined(NWEB_GRAPHIC)
742     Rosen::RSSurfaceNode::SharedPtr preloadSurfaceNode_ = nullptr;
743     std::shared_ptr<NWeb::NWeb> preloadNWeb_ = nullptr;
744 #endif
745 
746 #ifdef ABILITY_LIBRARY_LOADER
747     /**
748      *
749      * @brief Load the ability library.
750      *
751      * @param libraryPaths the library paths.
752      *
753      */
754     void LoadAbilityLibrary(const std::vector<std::string> &libraryPaths);
755     void LoadAceAbilityLibrary();
756 
757     void CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::string &nativeLibraryPath);
758     void LoadNativeLibrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath);
759 
760     void LoadAppDetailAbilityLibrary(std::string &nativeLibraryPath);
761 
762     void LoadAppLibrary();
763 
764     void ChangeToLocalPath(const std::string &bundleName,
765         const std::vector<std::string> &sourceDirs, std::vector<std::string> &localPath);
766 
767     void ChangeToLocalPath(const std::string &bundleName,
768         const std::string &sourcDir, std::string &localPath);
769 
770     bool ScanDir(const std::string &dirPath, std::vector<std::string> &files);
771 
772     /**
773      *
774      * @brief Check the fileType.
775      *
776      * @param fileName The fileName of the lib.
777      * @param extensionName The extensionName of the lib.
778      *
779      * @return if the FileType is legal, return true. else return false.
780      *
781      */
782     bool CheckFileType(const std::string &fileName, const std::string &extensionName);
783 
784     bool InitCreate(std::shared_ptr<ContextDeal> &contextDeal, ApplicationInfo &appInfo, ProcessInfo &processInfo);
785     bool CheckForHandleLaunchApplication(const AppLaunchData &appLaunchData);
786     bool InitResourceManager(std::shared_ptr<Global::Resource::ResourceManager> &resourceManager,
787         const AppExecFwk::HapModuleInfo &entryHapModuleInfo, const std::string &bundleName,
788         const Configuration &config, const ApplicationInfo &appInfo);
789     void OnStartAbility(const std::string& bundleName,
790         std::shared_ptr<Global::Resource::ResourceManager> &resourceManager,
791         const AppExecFwk::HapModuleInfo &entryHapModuleInfo, const bool isDebugApp);
792     std::vector<std::string> GetOverlayPaths(const std::string &bundleName,
793         const std::vector<OverlayModuleInfo> &overlayModuleInfos);
794     void SubscribeOverlayChange(const std::string &bundleName, const std::string &loadPath,
795         std::shared_ptr<Global::Resource::ResourceManager> &resourceManager,
796         const AppExecFwk::HapModuleInfo &entryHapModuleInfo);
797     void HandleInitAssertFaultTask(bool isDebugModule, bool isDebugApp);
798     void HandleCancelAssertFaultTask();
799 
800     bool GetHqfFileAndHapPath(const std::string &bundleName,
801         std::vector<std::pair<std::string, std::string>> &fileMap);
802     void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppLibPathMap &appLibPaths);
803     void SetAppDebug(uint32_t modeFlag, bool isDebug);
804     void GetPluginNativeLibPath(std::vector<AppExecFwk::PluginBundleInfo> &pluginBundleInfos,
805         AppLibPathMap &appLibPaths);
806     void SetRuntimeLang(ApplicationInfo &appInfo, AbilityRuntime::Runtime::Options &options);
807     bool IsEtsAPP(const ApplicationInfo &appInfo);
808     void SetJsIdleCallback(const std::weak_ptr<OHOSApplication> &wpApplication,
809         const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
810     void PreloadAppStartup(const BundleInfo &bundleInfo, const AppLaunchData &appLaunchData) const;
811     void RunNativeStartupTask(const BundleInfo &bundleInfo, const AppLaunchData &appLaunchData);
812     bool GetTestRunnerTypeAndPath(const std::string bundleName, const std::string moduleName,
813         AppExecFwk::ModuleTestRunner &tsTestRunner);
814 
815     std::vector<std::string> fileEntries_;
816     std::vector<std::string> nativeFileEntries_;
817     std::vector<void *> handleAbilityLib_;  // the handler of ACE Library.
818     std::shared_ptr<IdleTime> idleTime_ = nullptr;
819     std::vector<AppExecFwk::OverlayModuleInfo> overlayModuleInfos_;
820     std::weak_ptr<AbilityRuntime::AssertFaultTaskThread> assertThread_;
821 #endif                                      // ABILITY_LIBRARY_LOADER
822 #ifdef APPLICATION_LIBRARY_LOADER
823     void *handleAppLib_ = nullptr;  // the handler of ACE Library.
824     constexpr static std::string applicationLibraryPath = "/hos/lib/libapplication_native.z.so";
825 #endif  // APPLICATION_LIBRARY_LOADER
826 
827     DISALLOW_COPY_AND_MOVE(MainThread);
828 };
829 }  // namespace AppExecFwk
830 }  // namespace OHOS
831 #endif  // OHOS_ABILITY_RUNTIME_MAIN_THREAD_H
832