125c1cde8Sopenharmony_ci/*
225c1cde8Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
325c1cde8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
425c1cde8Sopenharmony_ci * you may not use this file except in compliance with the License.
525c1cde8Sopenharmony_ci * You may obtain a copy of the License at
625c1cde8Sopenharmony_ci *
725c1cde8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
825c1cde8Sopenharmony_ci *
925c1cde8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1025c1cde8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1125c1cde8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1225c1cde8Sopenharmony_ci * See the License for the specific language governing permissions and
1325c1cde8Sopenharmony_ci * limitations under the License.
1425c1cde8Sopenharmony_ci */
1525c1cde8Sopenharmony_ci
1625c1cde8Sopenharmony_ci#ifndef DATA_STORAGE_PREFERENCES_UTILS_H
1725c1cde8Sopenharmony_ci#define DATA_STORAGE_PREFERENCES_UTILS_H
1825c1cde8Sopenharmony_ci
1925c1cde8Sopenharmony_ci#include <stdint.h>
2025c1cde8Sopenharmony_ci#include <string>
2125c1cde8Sopenharmony_ci
2225c1cde8Sopenharmony_ci#include "preferences.h"
2325c1cde8Sopenharmony_ci#include "preferences_errno.h"
2425c1cde8Sopenharmony_ci#include "singleton.h"
2525c1cde8Sopenharmony_ci
2625c1cde8Sopenharmony_cinamespace OHOS {
2725c1cde8Sopenharmony_cinamespace Telephony {
2825c1cde8Sopenharmony_ciclass PreferencesUtil : public DelayedSingleton<PreferencesUtil> {
2925c1cde8Sopenharmony_ci    DECLARE_DELAYED_SINGLETON(PreferencesUtil);
3025c1cde8Sopenharmony_ci
3125c1cde8Sopenharmony_cipublic:
3225c1cde8Sopenharmony_ci    int SaveString(const std::string &key, const std::string &value);
3325c1cde8Sopenharmony_ci    std::string ObtainString(const std::string &key, const std::string &defValue);
3425c1cde8Sopenharmony_ci    int SaveInt(const std::string &key, int value);
3525c1cde8Sopenharmony_ci    int ObtainInt(const std::string &key, int defValue);
3625c1cde8Sopenharmony_ci    int SaveBool(const std::string &key, bool value);
3725c1cde8Sopenharmony_ci    bool ObtainBool(const std::string &key, bool defValue);
3825c1cde8Sopenharmony_ci    int SaveLong(const std::string &key, int64_t value);
3925c1cde8Sopenharmony_ci    int64_t ObtainLong(const std::string &key, int64_t defValue);
4025c1cde8Sopenharmony_ci    int SaveFloat(const std::string &key, float value);
4125c1cde8Sopenharmony_ci    float ObtainFloat(const std::string &key, float defValue);
4225c1cde8Sopenharmony_ci    bool IsExistKey(const std::string &key);
4325c1cde8Sopenharmony_ci    int RemoveKey(const std::string &key);
4425c1cde8Sopenharmony_ci    int RemoveAll();
4525c1cde8Sopenharmony_ci    void Refresh();
4625c1cde8Sopenharmony_ci    int RefreshSync();
4725c1cde8Sopenharmony_ci    int DeleteProfiles();
4825c1cde8Sopenharmony_ci
4925c1cde8Sopenharmony_ciprivate:
5025c1cde8Sopenharmony_ci    std::shared_ptr<NativePreferences::Preferences> GetProfiles(const std::string &path, int &errCode);
5125c1cde8Sopenharmony_ci
5225c1cde8Sopenharmony_ciprivate:
5325c1cde8Sopenharmony_ci    std::string path_ = "/data/storage/el1/database/telephony_data_preferences.xml";
5425c1cde8Sopenharmony_ci    int errCode_ = NativePreferences::E_OK;
5525c1cde8Sopenharmony_ci    const std::string error_ = "error";
5625c1cde8Sopenharmony_ci};
5725c1cde8Sopenharmony_ci} // namespace Telephony
5825c1cde8Sopenharmony_ci} // namespace OHOS
5925c1cde8Sopenharmony_ci#endif // DATA_STORAGE_PREFERENCES_UTILS_H