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 DATA_STORAGE_PREFERENCES_UTILS_H
17 #define DATA_STORAGE_PREFERENCES_UTILS_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "singleton.h"
23 #include "preferences.h"
24 #include "preferences_errno.h"
25 #include "preferences_observer.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class TelProfileUtil {
30     DECLARE_DELAYED_SINGLETON(TelProfileUtil);
31 
32 public:
33     int SaveString(const std::string &key, const std::string &value);
34     std::string ObtainString(const std::string &key, const std::string &defValue);
35     int SaveInt(const std::string &key, int value);
36     int ObtainInt(const std::string &key, int defValue);
37     int SaveBool(const std::string &key, bool value);
38     bool ObtainBool(const std::string &key, bool defValue);
39     int SaveLong(const std::string &key, int64_t value);
40     int64_t ObtainLong(const std::string &key, int64_t defValue);
41     int SaveFloat(const std::string &key, float value);
42     float ObtainFloat(const std::string &key, float defValue);
43     bool IsExistKey(const std::string &key);
44     int RemoveKey(const std::string &key);
45     int RemoveAll();
46     void Refresh();
47     int RefreshSync();
48     int DeleteProfiles();
49 
50 private:
51     std::shared_ptr<NativePreferences::Preferences> GetProfiles(const std::string &path, int &errCode);
52 
53 private:
54     std::string path_ = "/data/service/el1/public/telephony/telephonyProperties.xml";
55     int errCode_ = NativePreferences::E_OK;
56     const std::string error_ = "error";
57 };
58 } // namespace Telephony
59 } // namespace OHOS
60 #endif // DATA_STORAGE_PREFERENCES_UTILS_H