• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ETS_RUNTIME_H
17 #define OHOS_ABILITY_RUNTIME_ETS_RUNTIME_H
18 
19 #include <unordered_map>
20 #include <map>
21 #include <string>
22 #include <cstdint>
23 #include <functional>
24 #include <memory>
25 #include <vector>
26 
27 #include "runtime.h"
28 #include "js_runtime.h"
29 
30 using AppLibPathMap = std::map<std::string, std::vector<std::string>>;
31 using AppLibPathVec = std::vector<std::string>;
32 struct __ani_env;
33 using ani_env = __ani_env;
34 
35 namespace OHOS {
36 namespace EtsEnv {
37 class ETSEnvironment;
38 struct ETSUncaughtExceptionInfo;
39 }
40 
41 namespace AppExecFwk {
42 struct ETSNativeReference;
43 }
44 
45 namespace AbilityRuntime {
46 class ETSRuntime : public Runtime {
47 public:
48     static std::unique_ptr<ETSRuntime> Create(const Options &options, std::unique_ptr<JsRuntime> &jsRuntime);
49     static void SetAppLibPath(const AppLibPathMap& appLibPaths,
50         const std::map<std::string, std::string>& abcPathsToBundleModuleNameMap, bool isSystemApp);
51     ~ETSRuntime() override;
GetLanguage()52     Language GetLanguage() const override
53     {
54         return Language::ETS;
55     }
56 
StartDebugMode(const DebugOption debugOption)57     void StartDebugMode(const DebugOption debugOption) override {}
DumpHeapSnapshot(bool isPrivate)58     void DumpHeapSnapshot(bool isPrivate) override {}
NotifyApplicationState(bool isBackground)59     void NotifyApplicationState(bool isBackground) override {}
SuspendVM(uint32_t tid)60     bool SuspendVM(uint32_t tid) override { return false; }
ResumeVM(uint32_t tid)61     void ResumeVM(uint32_t tid) override {}
62     void PreloadSystemModule(const std::string &moduleName) override;
PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)63     void PreloadMainAbility(const std::string &moduleName, const std::string &srcPath, const std::string &hapPath,
64         bool isEsMode, const std::string &srcEntrance) override {}
PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)65     void PreloadModule(const std::string &moduleName, const std::string &srcPath, const std::string &hapPath,
66         bool isEsMode, bool useCommonTrunk) override {}
67     void PreloadModule(
68         const std::string &moduleName, const std::string &hapPath, bool isEsMode, bool useCommonTrunk) override;
69     void FinishPreload() override;
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)70     bool LoadRepairPatch(const std::string &patchFile, const std::string &baseFile) override { return false; }
NotifyHotReloadPage()71     bool NotifyHotReloadPage() override { return false; }
UnLoadRepairPatch(const std::string & patchFile)72     bool UnLoadRepairPatch(const std::string &patchFile) override { return false; }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)73     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string> &moduleAndPath) override {};
StartProfiler(const DebugOption debugOption)74     void StartProfiler(const DebugOption debugOption) override {};
75     void SetExtensionApiCheckCallback(
76         const std::function<bool(const std::string &className, const std::string &fileName)> &cb) override;
77     void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override;
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)78     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {};
DestroyHeapProfiler()79     void DestroyHeapProfiler() override {};
ForceFullGC()80     void ForceFullGC() override {};
ForceFullGC(uint32_t tid)81     void ForceFullGC(uint32_t tid) override {};
82     void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) override {};
DumpCpuProfile()83     void DumpCpuProfile() override {};
AllowCrossThreadExecution()84     void AllowCrossThreadExecution() override {};
GetHeapPrepare()85     void GetHeapPrepare() override {};
86     void RegisterUncaughtExceptionHandler(const EtsEnv::ETSUncaughtExceptionInfo &uncaughtExceptionInfo);
87     ani_env *GetAniEnv();
88     std::unique_ptr<AppExecFwk::ETSNativeReference> LoadModule(const std::string &moduleName,
89         const std::string &modulePath, const std::string &hapPath, bool esmodule,
90         bool useCommonChunk, const std::string &srcEntrance);
91     bool HandleUncaughtError();
92     const std::unique_ptr<AbilityRuntime::Runtime> &GetJsRuntime() const;
93     std::unique_ptr<AbilityRuntime::Runtime> MoveJsRuntime();
94     static std::unique_ptr<ETSRuntime> PreFork(const Options &options, std::unique_ptr<JsRuntime> &jsRuntime);
95     bool PreloadSystemClass(const char *className) override;
96 
97 private:
98     bool Initialize(const Options &options, std::unique_ptr<JsRuntime> &jsRuntime);
99     void Deinitialize();
100     bool CreateEtsEnv(const Options &options);
101     std::unique_ptr<AppExecFwk::ETSNativeReference> LoadEtsModule(const std::string &moduleName,
102         const std::string &fileName, const std::string &hapPath, const std::string &srcEntrance);
103     bool PostFork(const Options &options, std::unique_ptr<JsRuntime> &jsRuntime);
104     std::string HandleOhmUrlSrcEntry(const std::string &srcEntry);
105     void HandleOhmUrlFileName(std::string &fileName);
106     int32_t apiTargetVersion_ = 0;
107     std::string codePath_;
108     std::string moduleName_;
109     std::unique_ptr<AbilityRuntime::Runtime> jsRuntime_ = nullptr;
110 };
111 } // namespace AbilityRuntime
112 } // namespace OHOS
113 #endif // OHOS_ABILITY_RUNTIME_ETS_RUNTIME_H
114