• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetLanguage()42     Language GetLanguage() const override
43     {
44         return Language::CJ;
45     }
46 
47     void StartDebugMode(const DebugOption debugOption) override;
DumpHeapSnapshot(bool isPrivate)48     void DumpHeapSnapshot(bool isPrivate) override {}
NotifyApplicationState(bool isBackground)49     void NotifyApplicationState(bool isBackground) override {}
SuspendVM(uint32_t tid)50     bool SuspendVM(uint32_t tid) override { return false; }
ResumeVM(uint32_t tid)51     void ResumeVM(uint32_t tid) override {}
PreloadSystemModule(const std::string & moduleName)52     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)53     void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath,
54         const std::string& hapPath,  bool isEsMode, const std::string& srcEntrance) override {}
PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)55     void PreloadModule(const std::string& moduleName, const std::string& srcPath,
56         const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override {}
FinishPreload()57     void FinishPreload() override {}
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)58     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; }
NotifyHotReloadPage()59     bool NotifyHotReloadPage() override { return false; }
UnLoadRepairPatch(const std::string & patchFile)60     bool UnLoadRepairPatch(const std::string& patchFile) override { return false; }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)61     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override {};
StartProfiler(const DebugOption debugOption)62     void StartProfiler(const DebugOption debugOption) override {};
SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)63     void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override {}
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)64     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {};
IsAppLibLoaded()65     bool IsAppLibLoaded() const { return appLibLoaded_; }
66     void UnLoadCJAppLibrary();
DestroyHeapProfiler()67     void DestroyHeapProfiler() override {};
ForceFullGC()68     void ForceFullGC() override {};
ForceFullGC(uint32_t tid)69     void ForceFullGC(uint32_t tid) override {};
70     void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) override {};
DumpCpuProfile()71     void DumpCpuProfile() override {};
AllowCrossThreadExecution()72     void AllowCrossThreadExecution() override {};
GetHeapPrepare()73     void GetHeapPrepare() override {};
74     void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo);
75     static bool RegisterCangjieCallback();
76 
77 private:
78     bool StartDebugger();
79     bool LoadCJAppLibrary(const AppLibPathVec& appLibPaths);
80     bool Initialize(const Options& options);
81     std::string cjAppLibPath_;
82     bool appLibLoaded_ = false;
83     bool debugModel_ = false;
84     std::string bundleName_;
85     uint32_t instanceId_ = 0;
86     static AppLibPathVec appLibPaths_;
87     static std::string packageName_;
88 };
89 } // namespace AbilityRuntime
90 } // namespace OHOS
91 
92 #endif // OHOS_ABILITY_RUNTIME_CJ_RUNTIME_H
93