• 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 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 
47 /*
48  * This must be synchronized with the value in GlobalConfigurationKey
49  */
50 const std::vector<std::string> SystemConfigurationKeyStore {
51     OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE,
52     OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_HOUR,
53     OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE,
54     OHOS::AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE,
55     OHOS::AAFwk::GlobalConfigurationKey::DEVICE_TYPE,
56     OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION,
57     OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI,
58     OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID,
59 };
60 
61 constexpr const char* COLOR_MODE_LIGHT = "light";
62 constexpr const char* COLOR_MODE_DARK = "dark";
63 constexpr const char* DEVICE_TYPE_DEFAULT = "default";
64 constexpr const char* DIRECTION_VERTICAL = "vertical";
65 constexpr const char* DIRECTION_HORIZONTAL = "horizontal";
66 };
67 
68 class Configuration {
69 public:
Configuration()70     Configuration()
71     {
72         AddItem(AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID, "0");
73         AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true");
74     }
75 
Configuration(const Configuration & other)76     Configuration(const Configuration &other)
77     {
78         configParameter_.clear();
79         configParameter_ = other.configParameter_;
80     }
81 
82     Configuration& operator=(const Configuration &other)
83     {
84         if (this == &other) {
85             return *this;
86         }
87 
88         configParameter_.clear();
89         configParameter_ = other.configParameter_;
90         return *this;
91     }
92 
~Configuration()93     ~Configuration() {}
94 
95     /**
96      * @brief obtain the value according to the display number and storage key.
97      *
98      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
99      * Means you want to change the language part
100      * @param value Changed value
101      * @return return true if the deposit is successful, otherwise return false
102      */
AddItem(const std::string & key,const std::string & value)103     bool AddItem(const std::string &key, const std::string &value)
104     {
105         if (key.empty() || value.empty()) {
106             return false;
107         }
108 
109         configParameter_[key] = value;
110         return true;
111     }
112 
113     /**
114      * @brief obtain the value according to the display number and storage key.
115      *
116      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
117      * Means you want to change the language part
118      *
119      * @return return empty string if not found | return val if found
120      */
GetItem(const std::string & key)121     std::string GetItem(const std::string &key) const
122     {
123         if (key.empty()) {
124             return ConfigurationInner::EMPTY_STRING;
125         }
126 
127         auto iter = configParameter_.find(key);
128         if (iter != configParameter_.end()) {
129             return iter->second;
130         }
131 
132         return ConfigurationInner::EMPTY_STRING;
133     }
134 
135 private:
136     std::unordered_map<std::string, std::string> configParameter_;
137 };
138 } // namespace AppExecFwk
139 } // namespace OHOS
140 #endif // FOUNDATION_ABILITY_RUNTIME_SIMULATOR_COMMON_CONFIGURATION_H
141