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