1 /* 2 * Copyright (c) 2021-2023 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_RUNTIME_H 17 #define OHOS_ABILITY_RUNTIME_RUNTIME_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 class ModuleCheckerDelegate; 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class EventRunner; 28 } // namespace AppExecFwk 29 namespace AbilityRuntime { 30 class Runtime { 31 public: 32 enum class Language { 33 JS = 0, 34 CJ 35 }; 36 37 struct Options { 38 Language lang = Language::JS; 39 std::string bundleName; 40 std::string moduleName; 41 std::string codePath; 42 std::string bundleCodeDir; 43 std::string hapPath; 44 std::string arkNativeFilePath; 45 std::string packagePathStr; 46 std::vector<std::string> assetBasePathStr; 47 std::shared_ptr<AppExecFwk::EventRunner> eventRunner = nullptr; 48 std::map<std::string, std::string> hapModulePath; 49 bool loadAce = true; 50 bool preload = false; 51 bool isBundle = true; 52 bool isDebugVersion = false; 53 bool isJsFramework = false; 54 bool isStageModel = true; 55 bool isTestFramework = false; 56 bool jitEnabled = false; 57 bool isMultiThread = false; 58 bool isErrorInfoEnhance = false; 59 int32_t uid = -1; 60 // ArkTsCard start 61 bool isUnique = false; 62 // ArkTsCard end 63 std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate = nullptr; 64 int32_t apiTargetVersion = 0; 65 std::map<std::string, std::string> pkgContextInfoJsonStringMap; 66 std::map<std::string, std::string> packageNameList; 67 std::map<std::string, int32_t> aotCompileStatusMap; 68 }; 69 70 struct DebugOption { 71 std::string bundleName = ""; 72 std::string perfCmd; 73 std::string processName = ""; 74 std::string appProvisionType = ""; 75 bool isDebugApp = true; 76 bool isStartWithDebug = false; 77 bool isStartWithNative = false; 78 bool isDebugFromLocal = false; 79 bool isDeveloperMode; 80 }; 81 82 static std::unique_ptr<Runtime> Create(const Options& options); 83 static void SavePreloaded(std::unique_ptr<Runtime>&& instance); 84 static std::unique_ptr<Runtime> GetPreloaded(); 85 86 Runtime() = default; 87 virtual ~Runtime() = default; 88 89 virtual Language GetLanguage() const = 0; 90 91 virtual void StartDebugMode(const DebugOption debugOption) = 0; SetDebugOption(const DebugOption debugOption)92 virtual void SetDebugOption(const DebugOption debugOption) {}; StartLocalDebugMode(bool isDebugFromLocal)93 virtual void StartLocalDebugMode(bool isDebugFromLocal) {}; 94 virtual void DumpHeapSnapshot(bool isPrivate) = 0; 95 virtual void DumpCpuProfile() = 0; 96 virtual void DestroyHeapProfiler() = 0; 97 virtual void ForceFullGC() = 0; 98 virtual void ForceFullGC(uint32_t tid) = 0; 99 virtual void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) = 0; 100 virtual void AllowCrossThreadExecution() = 0; 101 virtual void GetHeapPrepare() = 0; 102 virtual void NotifyApplicationState(bool isBackground) = 0; 103 virtual bool SuspendVM(uint32_t tid) = 0; 104 virtual void ResumeVM(uint32_t tid) = 0; 105 virtual void PreloadSystemModule(const std::string& moduleName) = 0; 106 virtual void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath, 107 const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) = 0; 108 virtual void PreloadModule(const std::string& moduleName, const std::string& srcPath, 109 const std::string& hapPath, bool isEsMode, bool useCommonTrunk) = 0; 110 virtual void FinishPreload() = 0; 111 virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; 112 virtual bool NotifyHotReloadPage() = 0; 113 virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0; 114 virtual void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) = 0; 115 virtual void StartProfiler(const DebugOption debugOption) = 0; DoCleanWorkAfterStageCleaned()116 virtual void DoCleanWorkAfterStageCleaned() {} SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)117 virtual void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const {} 118 virtual void SetDeviceDisconnectCallback(const std::function<bool()> &cb) = 0; SetStopPreloadSoCallback(const std::function<void ()> & callback)119 virtual void SetStopPreloadSoCallback(const std::function<void()> &callback) {} 120 Runtime(const Runtime&) = delete; 121 Runtime(Runtime&&) = delete; 122 Runtime& operator=(const Runtime&) = delete; 123 Runtime& operator=(Runtime&&) = delete; 124 }; 125 } // namespace AbilityRuntime 126 } // namespace OHOS 127 #endif // OHOS_ABILITY_RUNTIME_RUNTIME_H 128