1 /*
2  * Copyright (c) 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_CJ_RUNTIME_H
17 #define OHOS_ABILITY_RUNTIME_CJ_RUNTIME_H
18 
19 #include <unordered_map>
20 #include <map>
21 #include <string>
22 
23 #include "runtime.h"
24 #include "cj_envsetup.h"
25 
26 using AppLibPathMap = std::map<std::string, std::vector<std::string>>;
27 using AppLibPathVec = std::vector<std::string>;
28 
29 namespace OHOS {
30 struct CJUncaughtExceptionInfo;
31 namespace AbilityRuntime {
32 
33 class CJRuntime : public Runtime {
34 public:
35     static std::unique_ptr<CJRuntime> Create(const Options& options);
36     static void SetAppLibPath(const AppLibPathMap& appLibPaths);
37     static bool IsCJAbility(const std::string& info);
38     static void SetSanitizerVersion(SanitizerKind kind);
39     static void SetPackageName(std::string srcEntryName);
40     ~CJRuntime() override = default;
41 
42     Language GetLanguage() const override
43     {
44         return Language::CJ;
45     }
46 
47     void StartDebugMode(const DebugOption debugOption) override;
48     void DumpHeapSnapshot(bool isPrivate) override {}
49     void NotifyApplicationState(bool isBackground) override {}
50     bool SuspendVM(uint32_t tid) override { return false; }
51     void ResumeVM(uint32_t tid) override {}
52     void PreloadSystemModule(const std::string& moduleName) override {}
53     void FinishPreload() override {}
54     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; }
55     bool NotifyHotReloadPage() override { return false; }
56     bool UnLoadRepairPatch(const std::string& patchFile) override { return false; }
57     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override {};
58     void StartProfiler(const DebugOption debugOption) override {};
59     void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override {}
60     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {};
IsAppLibLoaded() const61     bool IsAppLibLoaded() const { return appLibLoaded_; }
62     void UnLoadCJAppLibrary();
63     void DestroyHeapProfiler() override {};
64     void ForceFullGC() override {};
65     void ForceFullGC(uint32_t tid) override {};
66     void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {};
67     void DumpCpuProfile() override {};
68     void AllowCrossThreadExecution() override {};
69     void GetHeapPrepare() override {};
70     void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo);
71     void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {};
72 private:
73     bool StartDebugger();
74     bool LoadCJAppLibrary(const AppLibPathVec& appLibPaths);
75     bool Initialize(const Options& options);
76     std::string cjAppLibPath_;
77     bool appLibLoaded_ = false;
78     bool debugModel_ = false;
79     std::string bundleName_;
80     uint32_t instanceId_ = 0;
81     static AppLibPathVec appLibPaths_;
82     static std::string packageName_;
83 };
84 } // namespace AbilityRuntime
85 } // namespace OHOS
86 
87 #endif // OHOS_ABILITY_RUNTIME_CJ_RUNTIME_H
88