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 {} FinishPreload()54 void FinishPreload() override {} LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)55 bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; } NotifyHotReloadPage()56 bool NotifyHotReloadPage() override { return false; } UnLoadRepairPatch(const std::string & patchFile)57 bool UnLoadRepairPatch(const std::string& patchFile) override { return false; } RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)58 void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override {}; StartProfiler(const DebugOption debugOption)59 void StartProfiler(const DebugOption debugOption) override {}; SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)60 void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override {} SetDeviceDisconnectCallback(const std::function<bool ()> & cb)61 void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {}; IsAppLibLoaded()62 bool IsAppLibLoaded() const { return appLibLoaded_; } 63 void UnLoadCJAppLibrary(); DestroyHeapProfiler()64 void DestroyHeapProfiler() override {}; ForceFullGC()65 void ForceFullGC() override {}; ForceFullGC(uint32_t tid)66 void ForceFullGC(uint32_t tid) override {}; DumpHeapSnapshot(uint32_t tid,bool isFullGC)67 void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}; DumpCpuProfile()68 void DumpCpuProfile() override {}; AllowCrossThreadExecution()69 void AllowCrossThreadExecution() override {}; GetHeapPrepare()70 void GetHeapPrepare() override {}; 71 void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo); UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)72 void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}; 73 private: 74 bool StartDebugger(); 75 bool LoadCJAppLibrary(const AppLibPathVec& appLibPaths); 76 bool Initialize(const Options& options); 77 std::string cjAppLibPath_; 78 bool appLibLoaded_ = false; 79 bool debugModel_ = false; 80 std::string bundleName_; 81 uint32_t instanceId_ = 0; 82 static AppLibPathVec appLibPaths_; 83 }; 84 } // namespace AbilityRuntime 85 } // namespace OHOS 86 87 #endif // OHOS_ABILITY_RUNTIME_CJ_RUNTIME_H 88