• 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_RUNTIME_H
17 #define OHOS_ABILITY_RUNTIME_RUNTIME_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 class ModuleCheckerDelegate;
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class EventRunner;
28 } // namespace AppExecFwk
29 namespace AbilityRuntime {
30 namespace {
31 const std::string CODE_LANGUAGE_ARKTS_1_0 = "dynamic";
32 const std::string CODE_LANGUAGE_ARKTS_1_2 = "static";
33 const std::string CODE_LANGUAGE_ARKTS_HYBRID = "hybrid";
34 } // namespace
35 
36 class Runtime {
37 public:
38     enum class Language {
39         JS = 0,
40         CJ,
41         ETS,
42         UNKNOWN,
43     };
44 
45     struct Options {
46         Language lang = Language::JS;
47         std::string bundleName;
48         std::string moduleName;
49         std::string codePath;
50         std::string bundleCodeDir;
51         std::string hapPath;
52         std::string arkNativeFilePath;
53         std::string packagePathStr;
54         std::vector<std::string> assetBasePathStr;
55         std::shared_ptr<AppExecFwk::EventRunner> eventRunner = nullptr;
56         std::map<std::string, std::string> hapModulePath;
57         bool loadAce = true;
58         bool preload = false;
59         bool isBundle = true;
60         bool isDebugVersion = false;
61         bool isJsFramework = false;
62         bool isStageModel = true;
63         bool isTestFramework = false;
64         bool jitEnabled = false;
65         bool isMultiThread = false;
66         bool isErrorInfoEnhance = false;
67         bool allowArkTsLargeHeap = false;
68         int32_t uid = -1;
69         // ArkTsCard start
70         bool isUnique = false;
71         // ArkTsCard end
72         std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate = nullptr;
73         int32_t apiTargetVersion = 0;
74         std::map<std::string, std::string> pkgContextInfoJsonStringMap;
75         std::map<std::string, std::string> packageNameList;
76         std::map<std::string, int32_t> aotCompileStatusMap;
77         uint32_t versionCode = 0;
78         bool enableWarmStartupSmartGC = false;
79     };
80 
81     struct DebugOption {
82         std::string bundleName = "";
83         std::string perfCmd;
84         std::string processName = "";
85         std::string appProvisionType = "";
86         bool isDebugApp = true;
87         bool isStartWithDebug = false;
88         bool isStartWithNative = false;
89         bool isDebugFromLocal = false;
90         bool isDeveloperMode;
91     };
92 
93     static std::unique_ptr<Runtime> Create(Options &options);
94     static void SavePreloaded(std::unique_ptr<Runtime> &&instance);
95     static std::unique_ptr<Runtime> GetPreloaded(Language key);
96 
97     Runtime() = default;
98     virtual ~Runtime() = default;
99 
100     virtual Language GetLanguage() const = 0;
101 
102     virtual void StartDebugMode(const DebugOption debugOption) = 0;
SetDebugOption(const DebugOption debugOption)103     virtual void SetDebugOption(const DebugOption debugOption) {};
StartLocalDebugMode(bool isDebugFromLocal)104     virtual void StartLocalDebugMode(bool isDebugFromLocal) {};
105     virtual void DumpHeapSnapshot(bool isPrivate) = 0;
106     virtual void DumpCpuProfile() = 0;
107     virtual void DestroyHeapProfiler() = 0;
108     virtual void ForceFullGC() = 0;
109     virtual void ForceFullGC(uint32_t tid) = 0;
110     virtual void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) = 0;
111     virtual void AllowCrossThreadExecution() = 0;
112     virtual void GetHeapPrepare() = 0;
113     virtual void NotifyApplicationState(bool isBackground) = 0;
114     virtual bool SuspendVM(uint32_t tid) = 0;
115     virtual void ResumeVM(uint32_t tid) = 0;
116     virtual void PreloadSystemModule(const std::string& moduleName) = 0;
117     virtual void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath,
118         const std::string& hapPath,  bool isEsMode, const std::string& srcEntrance) = 0;
119     virtual void PreloadModule(const std::string& moduleName, const std::string& srcPath,
120         const std::string& hapPath, bool isEsMode, bool useCommonTrunk) = 0;
PreloadModule(const std::string & moduleName,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)121     virtual void PreloadModule(const std::string &moduleName, const std::string &hapPath,
122         bool isEsMode, bool useCommonTrunk) {}
123     virtual void FinishPreload() = 0;
124     virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0;
125     virtual bool NotifyHotReloadPage() = 0;
126     virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0;
127     virtual void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) = 0;
128     virtual void StartProfiler(const DebugOption debugOption) = 0;
SetExtensionApiCheckCallback(const std::function<bool (const std::string & className,const std::string & fileName)> & cb)129     virtual void SetExtensionApiCheckCallback(
130         const std::function<bool(const std::string &className, const std::string &fileName)> &cb) {}
DoCleanWorkAfterStageCleaned()131     virtual void DoCleanWorkAfterStageCleaned() {}
SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)132     virtual void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const {}
133     virtual void SetDeviceDisconnectCallback(const std::function<bool()> &cb) = 0;
SetStopPreloadSoCallback(const std::function<void ()> & callback)134     virtual void SetStopPreloadSoCallback(const std::function<void()> &callback) {}
PreloadSystemClass(const char * className)135     virtual bool PreloadSystemClass(const char *className) { return false; }
136     Runtime(const Runtime&) = delete;
137     Runtime(Runtime&&) = delete;
138     Runtime& operator=(const Runtime&) = delete;
139     Runtime& operator=(Runtime&&) = delete;
140 };
141 }  // namespace AbilityRuntime
142 }  // namespace OHOS
143 #endif  // OHOS_ABILITY_RUNTIME_RUNTIME_H
144