• 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         bool loadAce = true;
55         bool preload = false;
56         bool isBundle = true;
57         bool isDebugVersion = false;
58         bool isJsFramework = false;
59         bool isStageModel = true;
60         bool isTestFramework = false;
61         int32_t uid = -1;
62         // ArkTsCard start
63         bool isUnique = false;
64         // ArkTsCard end
65         std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate;
66         int32_t apiTargetVersion = 0;
67     };
68 
69     static std::unique_ptr<Runtime> Create(const Options& options);
70     static void SavePreloaded(std::unique_ptr<Runtime>&& instance);
71     static std::unique_ptr<Runtime> GetPreloaded();
72 
73     Runtime() = default;
74     virtual ~Runtime() = default;
75 
76     virtual Language GetLanguage() const = 0;
77 
78     virtual void StartDebugMode(bool needBreakPoint) = 0;
79     virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0;
80     virtual void DumpHeapSnapshot(bool isPrivate) = 0;
81     virtual void NotifyApplicationState(bool isBackground) = 0;
82     virtual bool SuspendVM(uint32_t tid) = 0;
83     virtual void ResumeVM(uint32_t tid) = 0;
84     virtual void PreloadSystemModule(const std::string& moduleName) = 0;
85     virtual void FinishPreload() = 0;
86     virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0;
87     virtual bool NotifyHotReloadPage() = 0;
88     virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0;
89     virtual void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) = 0;
90     virtual void StartProfiler(const std::string &perfCmd) = 0;
91     virtual void DoCleanWorkAfterStageCleaned() = 0;
SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> & moduleCheckerDelegate)92     virtual void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate) const {}
93 
94     Runtime(const Runtime&) = delete;
95     Runtime(Runtime&&) = delete;
96     Runtime& operator=(const Runtime&) = delete;
97     Runtime& operator=(Runtime&&) = delete;
98 };
99 }  // namespace AbilityRuntime
100 }  // namespace OHOS
101 #endif  // OHOS_ABILITY_RUNTIME_RUNTIME_H
102