• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_AAFWK_INTERFACES_INNERKITS_CONFIGURATION_H
17 #define OHOS_AAFWK_INTERFACES_INNERKITS_CONFIGURATION_H
18 
19 #include <unordered_map>
20 #include <string>
21 #include <vector>
22 #include <set>
23 #include "parcel.h"
24 #include "global_configuration_key.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 namespace ConfigurationInner {
29     const std::string CONNECTION_SYMBOL {"#"};
30     const std::string EMPTY_STRING {""};
31     const std::string APPLICATION_DIRECTION {"ohos.application.direction"};
32     const std::string APPLICATION_DENSITYDPI {"ohos.application.densitydpi"};
33     const std::string APPLICATION_DISPLAYID {"ohos.application.displayid"};
34 
35     /*
36      * This must be synchronized with the value in GlobalConfigurationKey
37      */
38     const std::vector<std::string> SystemConfigurationKeyStore {
39         OHOS::AppExecFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE,
40         OHOS::AppExecFwk::GlobalConfigurationKey::SYSTEM_COLORMODE,
41         OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION,
42         OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI,
43         OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID,
44     };
45 
46     const std::string COLOR_MODE_LIGHT {"light"};
47     const std::string COLOR_MODE_DARK {"dark"};
48 
49     const std::string DIRECTION_VERTICAL {"vertical"};
50     const std::string DIRECTION_HORIZONTAL {"horizontal"};
51 };
52 
53 class Configuration final: public Parcelable {
54 public:
55     Configuration();
56 
57     Configuration(const Configuration &other);
58 
59     Configuration& operator= (const Configuration &other);
60 
61     ~Configuration();
62 
63     /**
64      * @brief Compare the difference between the current and the passed in object.
65      *
66      * @param diffKeyV Out Ginseng. get the current difference item keys.
67      * @param other Comparisons obj
68      *
69      * @return void
70      */
71     void CompareDifferent(std::vector<std::string> &diffKeyV, const Configuration &other);
72 
73     /**
74      * @brief Update the content according to the key.
75      *
76      * @param mergeItemKey The key of the element currently to be updated.
77      * @param other Provide updated content obj
78      *
79      * @return void
80      */
81     void Merge(const std::vector<std::string> &diffKeyV, const Configuration &other);
82 
83     /**
84      * @brief obtain the value according to the display number and storage key.
85      *
86      * @param displayId Currently displayed id.
87      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
88      * Means you want to change the language part
89      * @param value Changed value
90      * @return return true if the deposit is successful, otherwise return false
91      */
92     bool AddItem(int displayId, const std::string &key, const std::string &value);
93 
94     /**
95      * @brief obtain the value according to the display number and storage key.
96      *
97      * @param displayId Currently displayed id.
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      *
101      * @return return empty string if not found | return val if found
102      */
103     std::string GetItem(int displayId, const std::string &key) const;
104 
105     /**
106      * @brief Delete element.
107      *
108      * @param displayId Currently displayed id.
109      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
110      * Means you want to change the language part
111      *
112      * @return Return an integer greater than 0 if the deletion succeeds, otherwise it returns 0.
113      */
114     int RemoveItem(int displayId, const std::string &key);
115 
116     /**
117      * @brief obtain the value according to the display number and storage key.
118      *
119      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
120      * Means you want to change the language part
121      * @param value Changed value
122      * @return return true if the deposit is successful, otherwise return false
123      */
124     bool AddItem(const std::string &key, const std::string &value);
125 
126     /**
127      * @brief obtain the value according to the display number and storage key.
128      *
129      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
130      * Means you want to change the language part
131      *
132      * @return return empty string if not found | return val if found
133      */
134     std::string GetItem(const std::string &key) const;
135 
136     /**
137      * @brief Delete element.
138      *
139      * @param key The key of the item to access configura. ej : key = GlobalConfigurationKey::SYSTEM_LANGUAGE
140      * Means you want to change the language part
141      *
142      * @return Return an integer greater than 0 if the deletion succeeds, otherwise it returns 0.
143      */
144     int RemoveItem(const std::string &key);
145 
146     /**
147      * @brief Get the currently existing key-value pairs.
148      *
149      * @return return currently item size.
150      */
151     int GetItemSize() const;
152 
153     /**
154      * @brief Return all current key-value pairs.
155      *
156      */
157     const std::string& GetName() const;
158 
159     /**
160      * @brief read this Sequenceable object from a Parcel.
161      *
162      * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled.
163      * @return Returns true if read successed; returns false otherwise.
164      */
165     bool ReadFromParcel(Parcel &parcel);
166 
167     /**
168      * @brief Marshals this Sequenceable object into a Parcel.
169      *
170      * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled.
171      */
172     virtual bool Marshalling(Parcel &parcel) const override;
173 
174     /**
175      * @brief Unmarshals this Sequenceable object from a Parcel.
176      *
177      * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled.
178      */
179     static Configuration *Unmarshalling(Parcel &parcel);
180 
181 private:
182 
183     /**
184      * @brief Make the key by id and param
185      *
186      * @param getKey Key made.
187      * @param id displayId.
188      * @param param The key of the item to access configura.
189      *
190      */
191     bool MakeTheKey(std::string &getKey, int id, const std::string &param) const;
192 
193     /**
194      * @brief Get all current keys.
195      *
196      * @param keychain Out Ginseng. Contains all current keys.
197      */
198     void GetAllKey(std::vector<std::string> &keychain) const;
199 
200     /**
201      * @brief Get value by key.
202      *
203      * @param key the key to get value.
204      */
205     std::string GetValue(const std::string &key) const;
206 
207 private:
208     int defaultDisplayId_ {0};
209     mutable std::string toStrintg_ {""}; /* For interface GetName(), Assign value only when calling the interface */
210     std::unordered_map<std::string, std::string> configParameter_;
211 };
212 }  // namespace AppExecFwk
213 }  // namespace OHOS
214 #endif  // OHOS_AAFWK_INTERFACES_INNERKITS_CONFIGURATION_H
215