1eace7efcSopenharmony_ci/*
2eace7efcSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License.
5eace7efcSopenharmony_ci * You may obtain a copy of the License at
6eace7efcSopenharmony_ci *
7eace7efcSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8eace7efcSopenharmony_ci *
9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and
13eace7efcSopenharmony_ci * limitations under the License.
14eace7efcSopenharmony_ci */
15eace7efcSopenharmony_ci
16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_RUNTIME_H
17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_RUNTIME_H
18eace7efcSopenharmony_ci
19eace7efcSopenharmony_ci#include <map>
20eace7efcSopenharmony_ci#include <string>
21eace7efcSopenharmony_ci#include <vector>
22eace7efcSopenharmony_ci
23eace7efcSopenharmony_ciclass ModuleCheckerDelegate;
24eace7efcSopenharmony_ci
25eace7efcSopenharmony_cinamespace OHOS {
26eace7efcSopenharmony_cinamespace AppExecFwk {
27eace7efcSopenharmony_ciclass EventRunner;
28eace7efcSopenharmony_ci} // namespace AppExecFwk
29eace7efcSopenharmony_cinamespace AbilityRuntime {
30eace7efcSopenharmony_ciclass Runtime {
31eace7efcSopenharmony_cipublic:
32eace7efcSopenharmony_ci    enum class Language {
33eace7efcSopenharmony_ci        JS = 0,
34eace7efcSopenharmony_ci        CJ
35eace7efcSopenharmony_ci    };
36eace7efcSopenharmony_ci
37eace7efcSopenharmony_ci    struct Options {
38eace7efcSopenharmony_ci        Language lang = Language::JS;
39eace7efcSopenharmony_ci        std::string bundleName;
40eace7efcSopenharmony_ci        std::string moduleName;
41eace7efcSopenharmony_ci        std::string codePath;
42eace7efcSopenharmony_ci        std::string bundleCodeDir;
43eace7efcSopenharmony_ci        std::string hapPath;
44eace7efcSopenharmony_ci        std::string arkNativeFilePath;
45eace7efcSopenharmony_ci        std::string packagePathStr;
46eace7efcSopenharmony_ci        std::vector<std::string> assetBasePathStr;
47eace7efcSopenharmony_ci        std::shared_ptr<AppExecFwk::EventRunner> eventRunner = nullptr;
48eace7efcSopenharmony_ci        std::map<std::string, std::string> hapModulePath;
49eace7efcSopenharmony_ci        bool loadAce = true;
50eace7efcSopenharmony_ci        bool preload = false;
51eace7efcSopenharmony_ci        bool isBundle = true;
52eace7efcSopenharmony_ci        bool isDebugVersion = false;
53eace7efcSopenharmony_ci        bool isJsFramework = false;
54eace7efcSopenharmony_ci        bool isStageModel = true;
55eace7efcSopenharmony_ci        bool isTestFramework = false;
56eace7efcSopenharmony_ci        bool jitEnabled = false;
57eace7efcSopenharmony_ci        bool isMultiThread = false;
58eace7efcSopenharmony_ci        bool isErrorInfoEnhance = false;
59eace7efcSopenharmony_ci        int32_t uid = -1;
60eace7efcSopenharmony_ci        // ArkTsCard start
61eace7efcSopenharmony_ci        bool isUnique = false;
62eace7efcSopenharmony_ci        // ArkTsCard end
63eace7efcSopenharmony_ci        std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate = nullptr;
64eace7efcSopenharmony_ci        int32_t apiTargetVersion = 0;
65eace7efcSopenharmony_ci        std::map<std::string, std::string> pkgContextInfoJsonStringMap;
66eace7efcSopenharmony_ci        std::map<std::string, std::string> packageNameList;
67eace7efcSopenharmony_ci        std::map<std::string, int32_t> aotCompileStatusMap;
68eace7efcSopenharmony_ci    };
69eace7efcSopenharmony_ci
70eace7efcSopenharmony_ci    struct DebugOption {
71eace7efcSopenharmony_ci        std::string bundleName = "";
72eace7efcSopenharmony_ci        std::string perfCmd;
73eace7efcSopenharmony_ci        std::string processName = "";
74eace7efcSopenharmony_ci        bool isDebugApp = true;
75eace7efcSopenharmony_ci        bool isStartWithDebug = false;
76eace7efcSopenharmony_ci        bool isStartWithNative = false;
77eace7efcSopenharmony_ci    };
78eace7efcSopenharmony_ci
79eace7efcSopenharmony_ci    static std::unique_ptr<Runtime> Create(const Options& options);
80eace7efcSopenharmony_ci    static void SavePreloaded(std::unique_ptr<Runtime>&& instance);
81eace7efcSopenharmony_ci    static std::unique_ptr<Runtime> GetPreloaded();
82eace7efcSopenharmony_ci
83eace7efcSopenharmony_ci    Runtime() = default;
84eace7efcSopenharmony_ci    virtual ~Runtime() = default;
85eace7efcSopenharmony_ci
86eace7efcSopenharmony_ci    virtual Language GetLanguage() const = 0;
87eace7efcSopenharmony_ci
88eace7efcSopenharmony_ci    virtual void StartDebugMode(const DebugOption debugOption) = 0;
89eace7efcSopenharmony_ci    virtual void DumpHeapSnapshot(bool isPrivate) = 0;
90eace7efcSopenharmony_ci    virtual void DumpCpuProfile() = 0;
91eace7efcSopenharmony_ci    virtual void DestroyHeapProfiler() = 0;
92eace7efcSopenharmony_ci    virtual void ForceFullGC() = 0;
93eace7efcSopenharmony_ci    virtual void ForceFullGC(uint32_t tid) = 0;
94eace7efcSopenharmony_ci    virtual void DumpHeapSnapshot(uint32_t tid, bool isFullGC) = 0;
95eace7efcSopenharmony_ci    virtual void AllowCrossThreadExecution() = 0;
96eace7efcSopenharmony_ci    virtual void GetHeapPrepare() = 0;
97eace7efcSopenharmony_ci    virtual void NotifyApplicationState(bool isBackground) = 0;
98eace7efcSopenharmony_ci    virtual bool SuspendVM(uint32_t tid) = 0;
99eace7efcSopenharmony_ci    virtual void ResumeVM(uint32_t tid) = 0;
100eace7efcSopenharmony_ci    virtual void PreloadSystemModule(const std::string& moduleName) = 0;
101eace7efcSopenharmony_ci    virtual void FinishPreload() = 0;
102eace7efcSopenharmony_ci    virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0;
103eace7efcSopenharmony_ci    virtual bool NotifyHotReloadPage() = 0;
104eace7efcSopenharmony_ci    virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0;
105eace7efcSopenharmony_ci    virtual void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) = 0;
106eace7efcSopenharmony_ci    virtual void StartProfiler(const DebugOption debugOption) = 0;
107eace7efcSopenharmony_ci    virtual void DoCleanWorkAfterStageCleaned() {}
108eace7efcSopenharmony_ci    virtual void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const {}
109eace7efcSopenharmony_ci    virtual void SetDeviceDisconnectCallback(const std::function<bool()> &cb) = 0;
110eace7efcSopenharmony_ci    virtual void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) = 0;
111eace7efcSopenharmony_ci    Runtime(const Runtime&) = delete;
112eace7efcSopenharmony_ci    Runtime(Runtime&&) = delete;
113eace7efcSopenharmony_ci    Runtime& operator=(const Runtime&) = delete;
114eace7efcSopenharmony_ci    Runtime& operator=(Runtime&&) = delete;
115eace7efcSopenharmony_ci};
116eace7efcSopenharmony_ci}  // namespace AbilityRuntime
117eace7efcSopenharmony_ci}  // namespace OHOS
118eace7efcSopenharmony_ci#endif  // OHOS_ABILITY_RUNTIME_RUNTIME_H
119