1 /* 2 * Copyright (c) 2021-2022 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 struct JsFrames { 24 std::string functionName; 25 std::string fileName; 26 std::string pos; 27 uintptr_t *nativePointer = nullptr; 28 }; 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class EventRunner; 33 } // namespace AppExecFwk 34 namespace AbilityRuntime { 35 class Runtime { 36 public: 37 enum class Language { 38 JS = 0, 39 }; 40 41 struct Options { 42 Language lang = Language::JS; 43 std::string bundleName; 44 std::string codePath; 45 std::string bundleCodeDir; 46 std::map<std::string, std::vector<std::string>> appLibPaths {}; 47 std::string hapPath; 48 std::string arkNativeFilePath; 49 std::shared_ptr<AppExecFwk::EventRunner> eventRunner; 50 bool loadAce = true; 51 bool preload = false; 52 bool isBundle = true; 53 bool isDebugVersion = false; 54 bool isStageModel = true; 55 // ArkTsCard start 56 bool isUnique = false; 57 // ArkTsCard end 58 }; 59 60 static std::unique_ptr<Runtime> Create(const Options& options); 61 static void SavePreloaded(std::unique_ptr<Runtime>&& instance); 62 static std::unique_ptr<Runtime> GetPreloaded(); 63 64 Runtime() = default; 65 virtual ~Runtime() = default; 66 67 virtual Language GetLanguage() const = 0; 68 69 virtual void StartDebugMode(bool needBreakPoint) = 0; 70 virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0; 71 virtual void DumpHeapSnapshot(bool isPrivate) = 0; 72 virtual void NotifyApplicationState(bool isBackground) = 0; 73 virtual void PreloadSystemModule(const std::string& moduleName) = 0; 74 virtual void FinishPreload() = 0; 75 virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; 76 virtual bool NotifyHotReloadPage() = 0; 77 virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0; 78 virtual void UpdateExtensionType(int32_t extensionType) = 0; 79 80 Runtime(const Runtime&) = delete; 81 Runtime(Runtime&&) = delete; 82 Runtime& operator=(const Runtime&) = delete; 83 Runtime& operator=(Runtime&&) = delete; 84 }; 85 } // namespace AbilityRuntime 86 } // namespace OHOS 87 #endif // OHOS_ABILITY_RUNTIME_RUNTIME_H 88