• 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 struct JsFrames {
24     std::string functionName;
25     std::string fileName;
26     std::string pos;
27     uintptr_t *nativePointer = nullptr;
28 };
29 
30 class ModuleCheckerDelegate;
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class EventRunner;
35 } // namespace AppExecFwk
36 namespace AbilityRuntime {
37 class Runtime {
38 public:
39     enum class Language {
40         JS = 0,
41     };
42 
43     struct Options {
44         Language lang = Language::JS;
45         std::string bundleName;
46         std::string moduleName;
47         std::string codePath;
48         std::string bundleCodeDir;
49         std::string hapPath;
50         std::string arkNativeFilePath;
51         std::string packagePathStr;
52         std::vector<std::string> assetBasePathStr;
53         std::shared_ptr<AppExecFwk::EventRunner> eventRunner;
54         std::map<std::string, std::string> hapModulePath;
55         bool loadAce = true;
56         bool preload = false;
57         bool isBundle = true;
58         bool isDebugVersion = false;
59         bool isJsFramework = false;
60         bool isStageModel = true;
61         bool isTestFramework = false;
62         int32_t uid = -1;
63         // ArkTsCard start
64         bool isUnique = false;
65         // ArkTsCard end
66         std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate;
67         int32_t apiTargetVersion = 0;
68     };
69 
70     static std::unique_ptr<Runtime> Create(const Options& options);
71     static void SavePreloaded(std::unique_ptr<Runtime>&& instance);
72     static std::unique_ptr<Runtime> GetPreloaded();
73 
74     Runtime() = default;
75     virtual ~Runtime() = default;
76 
77     virtual Language GetLanguage() const = 0;
78 
79     virtual void StartDebugMode(bool needBreakPoint, const std::string &processName, bool isDebug = true) = 0;
80     virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0;
81     virtual void DumpHeapSnapshot(bool isPrivate) = 0;
82     virtual void DumpCpuProfile(bool isPrivate) = 0;
83     virtual void DestroyHeapProfiler() = 0;
84     virtual void ForceFullGC() = 0;
85     virtual void AllowCrossThreadExecution() = 0;
86     virtual void GetHeapPrepare() = 0;
87     virtual void NotifyApplicationState(bool isBackground) = 0;
88     virtual bool SuspendVM(uint32_t tid) = 0;
89     virtual void ResumeVM(uint32_t tid) = 0;
90     virtual void PreloadSystemModule(const std::string& moduleName) = 0;
91     virtual void FinishPreload() = 0;
92     virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0;
93     virtual bool NotifyHotReloadPage() = 0;
94     virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0;
95     virtual void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) = 0;
96     virtual void StartProfiler(
97         const std::string &perfCmd, bool needBreakPoint, const std::string &processName, bool isDebug = true) = 0;
98     virtual void DoCleanWorkAfterStageCleaned() = 0;
SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> & moduleCheckerDelegate)99     virtual void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate) const {}
100     virtual void SetDeviceDisconnectCallback(const std::function<bool()> &cb) = 0;
101     Runtime(const Runtime&) = delete;
102     Runtime(Runtime&&) = delete;
103     Runtime& operator=(const Runtime&) = delete;
104     Runtime& operator=(Runtime&&) = delete;
105 };
106 }  // namespace AbilityRuntime
107 }  // namespace OHOS
108 #endif  // OHOS_ABILITY_RUNTIME_RUNTIME_H
109