• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_EXTENSION_CONFIG_HANDLER_H
17 #define OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 
23 #include "bundle_info.h"
24 #include "extension_ability_info.h"
25 #include "native_engine/native_engine.h"
26 #include "runtime.h"
27 
28 namespace OHOS::AbilityRuntime {
29 namespace ExtensionConfigItem {
30     constexpr char ITEM_NAME_BLOCKLIST[] = "blocklist";
31 }
32 namespace {
33     constexpr int32_t EXTENSION_TYPE_UNKNOWN = 255;
34 }
35 
36 /**
37  * @brief Manage extension configuration.
38  */
39 class ExtensionConfigMgr : public std::enable_shared_from_this<ExtensionConfigMgr> {
40 public:
41     ExtensionConfigMgr() = default;
42 
43     virtual ~ExtensionConfigMgr() = default;
44 
45     /**
46      * @brief ExtensionConfigMgr initialization
47      *
48      */
49     void Init();
50 
51     /**
52      * @brief Set the Process Extension Type object
53      *
54      * @param extensionType
55      */
SetProcessExtensionType(int32_t extensionType)56     void SetProcessExtensionType(int32_t extensionType)
57     {
58         extensionType_ = extensionType;
59     }
60 
61     /**
62      * @brief Add extension blocklist item
63      *
64      * @param name Extension name
65      * @param type Extension type
66      */
67     void AddBlockListItem(const std::string &name, int32_t type);
68 
69     /**
70      * @brief Update runtime module checker
71      *
72      * @param runtime the runtime pointer
73      */
74     void UpdateRuntimeModuleChecker(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
75 
76     /**
77      * @brief Check Whether the ets module can be loaded
78      *
79      * @param className the className of the ets module
80      * @param fileName the fileName of the ets module
81      * @return Return true if the module can be loaded, false if the module can not be loaded.
82      */
83     bool CheckEtsModuleLoadable(const std::string &className, const std::string &fileName);
84 
85 private:
86     /**
87      * @brief Generate ets blocklist be extension_blocklist_config
88      *
89      */
90     void GenerateExtensionEtsBlocklists();
91 
92     /**
93      * @brief Get string after remove special prefix.
94      *
95      * @param name The string for which you want to remove the prefix.
96      * @return Return the string after the prefix is removed.
97      */
98     std::string GetStringAfterRemovePreFix(const std::string &name);
99     /**
100      * @brief set ets runtime module checker
101      *
102      * @param runtime the runtime pointer
103      */
104     void SetExtensionEtsCheckCallback(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
105     std::unordered_map<std::string, std::unordered_set<std::string>> blocklistConfig_;
106     std::unordered_map<int32_t, std::unordered_set<std::string>> extensionBlocklist_;
107     std::unordered_set<std::string> extensionEtsBlocklist_;
108     int32_t extensionType_ = EXTENSION_TYPE_UNKNOWN;
109 };
110 } // namespace OHOS::AbilityRuntime
111 
112 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H
113