1 /* 2 * Copyright (c) 2023-2024 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_H 17 #define OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_H 18 19 #include <map> 20 #include <mutex> 21 #include <nlohmann/json.hpp> 22 #include <unordered_map> 23 #include <unordered_set> 24 25 #include "extension_ability_info.h" 26 #include "singleton.h" 27 28 namespace OHOS { 29 namespace AAFwk { 30 constexpr static int32_t DEFAULT_EXTENSION_AUTO_DISCONNECT_TIME = -1; 31 constexpr static bool EXTENSION_NETWORK_ENABLE_FLAG_DEFAULT = true; 32 constexpr static bool EXTENSION_SA_ENABLE_FLAG_DEFAULT = true; 33 constexpr static bool EXTENSION_THIRD_PARTY_APP_ENABLE_FLAG_DEFAULT = true; 34 constexpr static bool EXTENSION_START_SERVICE_ENABLE_FLAG_DEFAULT = true; 35 36 struct ExtensionConfigItem { 37 bool networkEnableFlag = EXTENSION_NETWORK_ENABLE_FLAG_DEFAULT; 38 bool saEnableFlag = EXTENSION_SA_ENABLE_FLAG_DEFAULT; 39 bool thirdPartyAppEnableFlag = EXTENSION_THIRD_PARTY_APP_ENABLE_FLAG_DEFAULT; 40 bool serviceEnableFlag = EXTENSION_START_SERVICE_ENABLE_FLAG_DEFAULT; 41 int32_t extensionAutoDisconnectTime = DEFAULT_EXTENSION_AUTO_DISCONNECT_TIME; 42 std::unordered_set<std::string> serviceBlockedList; 43 }; 44 45 class ExtensionConfig : public DelayedSingleton<ExtensionConfig> { 46 public: 47 explicit ExtensionConfig() = default; 48 virtual ~ExtensionConfig() = default; 49 void LoadExtensionConfiguration(); 50 int32_t GetExtensionAutoDisconnectTime(const std::string &extensionTypeName); 51 bool IsExtensionStartThirdPartyAppEnable(const std::string &extensionTypeName); 52 bool IsExtensionStartServiceEnable(const std::string &extensionTypeName, const std::string &targetUri); 53 bool IsExtensionNetworkEnable(const std::string &extensionTypeName); 54 bool IsExtensionSAEnable(const std::string &extensionTypeName); 55 private: 56 void LoadExtensionConfig(const nlohmann::json &object); 57 bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); 58 59 std::string GetExtensionConfigPath() const; 60 void LoadExtensionAutoDisconnectTime(const nlohmann::json &object, std::string extensionTypeName); 61 void LoadExtensionThirdPartyAppBlockedList(const nlohmann::json &object, std::string extensionTypeName); 62 void LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeNameobject); 63 void LoadExtensionNetworkEnable(const nlohmann::json &object, const std::string &extensionTypeName); 64 void LoadExtensionSAEnable(const nlohmann::json &object, const std::string &extensionTypeName); 65 66 bool CheckServiceExtensionUriValid(const std::string &uri); 67 68 std::unordered_map<std::string, ExtensionConfigItem> configMap_; 69 std::mutex configMapMutex_; 70 }; 71 } // OHOS 72 } // AAFwk 73 74 #endif // OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_H