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 {
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 private:
77     std::unordered_map<std::string, std::unordered_set<std::string>> blocklistConfig_;
78     std::unordered_map<int32_t, std::unordered_set<std::string>> extensionBlocklist_;
79     int32_t extensionType_ = EXTENSION_TYPE_UNKNOWN;
80 };
81 } // namespace OHOS::AbilityRuntime
82 
83 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H
84