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 SetAsanVersion(); 39 static void SetTsanVersion(); 40 static void SetHWAsanVersion(); 41 ~CJRuntime() override = default; 42 GetLanguage()43 Language GetLanguage() const override 44 { 45 return Language::CJ; 46 } 47 48 void StartDebugMode(const DebugOption debugOption) override; DumpHeapSnapshot(bool isPrivate)49 void DumpHeapSnapshot(bool isPrivate) override {} NotifyApplicationState(bool isBackground)50 void NotifyApplicationState(bool isBackground) override {} SuspendVM(uint32_t tid)51 bool SuspendVM(uint32_t tid) override { return false; } ResumeVM(uint32_t tid)52 void ResumeVM(uint32_t tid) override {} PreloadSystemModule(const std::string & moduleName)53 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)54 void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath, 55 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)56 void PreloadModule(const std::string& moduleName, const std::string& srcPath, 57 const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override {} FinishPreload()58 void FinishPreload() override {} LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)59 bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; } NotifyHotReloadPage()60 bool NotifyHotReloadPage() override { return false; } UnLoadRepairPatch(const std::string & patchFile)61 bool UnLoadRepairPatch(const std::string& patchFile) override { return false; } RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)62 void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override {}; StartProfiler(const DebugOption debugOption)63 void StartProfiler(const DebugOption debugOption) override {}; SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)64 void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override {} SetDeviceDisconnectCallback(const std::function<bool ()> & cb)65 void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {}; IsAppLibLoaded()66 bool IsAppLibLoaded() const { return appLibLoaded_; } 67 void UnLoadCJAppLibrary(); DestroyHeapProfiler()68 void DestroyHeapProfiler() override {}; ForceFullGC()69 void ForceFullGC() override {}; ForceFullGC(uint32_t tid)70 void ForceFullGC(uint32_t tid) override {}; DumpHeapSnapshot(uint32_t tid,bool isFullGC)71 void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}; DumpCpuProfile()72 void DumpCpuProfile() override {}; AllowCrossThreadExecution()73 void AllowCrossThreadExecution() override {}; GetHeapPrepare()74 void GetHeapPrepare() override {}; 75 void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo); UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)76 void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}; 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 }; 88 } // namespace AbilityRuntime 89 } // namespace OHOS 90 91 #endif // OHOS_ABILITY_RUNTIME_CJ_RUNTIME_H 92