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