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 FOUNDATION_ABILITY_RUNTIME_SIMULATOR_COMMON_CONFIGURATION_H 17 #define FOUNDATION_ABILITY_RUNTIME_SIMULATOR_COMMON_CONFIGURATION_H 18 19 #include <mutex> 20 #include <set> 21 #include <string> 22 #include <algorithm> 23 #include <unordered_map> 24 #include <vector> 25 26 namespace OHOS { 27 namespace AAFwk { 28 namespace GlobalConfigurationKey { 29 /* For the time being, there is no uniform standard */ 30 /* Must be synchronized with the keystore(SystemConfigurationKeyStore)in the configuration */ 31 constexpr const char* SYSTEM_LANGUAGE = "ohos.system.language"; 32 constexpr const char* SYSTEM_HOUR = "ohos.system.hour"; 33 constexpr const char* SYSTEM_COLORMODE = "ohos.system.colorMode"; 34 constexpr const char* INPUT_POINTER_DEVICE = "input.pointer.device"; 35 constexpr const char* DEVICE_TYPE = "const.build.characteristics"; 36 } // namespace GlobalConfigurationKey 37 } // namespace AAFwk 38 39 namespace AppExecFwk { 40 namespace ConfigurationInner { 41 constexpr const char* CONNECTION_SYMBOL = "#"; 42 constexpr const char* EMPTY_STRING = ""; 43 constexpr const char* APPLICATION_DIRECTION = "ohos.application.direction"; 44 constexpr const char* APPLICATION_DENSITYDPI = "ohos.application.densitydpi"; 45 constexpr const char* APPLICATION_DISPLAYID = "ohos.application.displayid"; 46 constexpr const char* APPLICATION_FONT = "ohos.application.font"; 47 48 constexpr const char* COLOR_MODE_LIGHT = "light"; 49 constexpr const char* COLOR_MODE_DARK = "dark"; 50 constexpr const char* DEVICE_TYPE_DEFAULT = "default"; 51 constexpr const char* DIRECTION_VERTICAL = "vertical"; 52 constexpr const char* DIRECTION_HORIZONTAL = "horizontal"; 53 }; 54 55 class Configuration { 56 public: Configuration()57 Configuration() 58 { 59 AddItem(AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID, "0"); 60 AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true"); 61 } 62 Configuration(const Configuration & other)63 Configuration(const Configuration &other) 64 { 65 configParameter_.clear(); 66 configParameter_ = other.configParameter_; 67 } 68 69 Configuration& operator=(const Configuration &other) 70 { 71 if (this == &other) { 72 return *this; 73 } 74 75 configParameter_.clear(); 76 configParameter_ = other.configParameter_; 77 return *this; 78 } 79 ~Configuration()80 ~Configuration() {} 81 82 /** 83 * @brief obtain the value according to the display number and storage key. 84 * 85 * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE 86 * Means you want to change the language part 87 * @param value Changed value 88 * @return return true if the deposit is successful, otherwise return false 89 */ AddItem(const std::string & key,const std::string & value)90 bool AddItem(const std::string &key, const std::string &value) 91 { 92 if (key.empty() || value.empty()) { 93 return false; 94 } 95 96 configParameter_[key] = value; 97 return true; 98 } 99 100 /** 101 * @brief obtain the value according to the display number and storage key. 102 * 103 * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE 104 * Means you want to change the language part 105 * 106 * @return return empty string if not found | return val if found 107 */ GetItem(const std::string & key)108 std::string GetItem(const std::string &key) const 109 { 110 if (key.empty()) { 111 return ConfigurationInner::EMPTY_STRING; 112 } 113 114 auto iter = configParameter_.find(key); 115 if (iter != configParameter_.end()) { 116 return iter->second; 117 } 118 119 return ConfigurationInner::EMPTY_STRING; 120 } 121 122 private: 123 std::unordered_map<std::string, std::string> configParameter_; 124 }; 125 } // namespace AppExecFwk 126 } // namespace OHOS 127 #endif // FOUNDATION_ABILITY_RUNTIME_SIMULATOR_COMMON_CONFIGURATION_H 128