1 /* 2 * Copyright (C) 2021 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 "iosfwd" 23 #include "memory" 24 #include "preferences_errno.h" 25 #include "singleton.h" 26 27 namespace OHOS { 28 namespace NativePreferences { 29 class Preferences; 30 class PreferencesObserver; 31 } // namespace NativePreferences 32 namespace Telephony { 33 class PreferencesUtil : public DelayedSingleton<PreferencesUtil> { 34 DECLARE_DELAYED_SINGLETON(PreferencesUtil); 35 36 public: 37 int SaveString(const std::string &key, const std::string &value); 38 std::string ObtainString(const std::string &key, const std::string &defValue); 39 int SaveInt(const std::string &key, int value); 40 int ObtainInt(const std::string &key, int defValue); 41 int SaveBool(const std::string &key, bool value); 42 bool ObtainBool(const std::string &key, bool defValue); 43 int SaveLong(const std::string &key, int64_t value); 44 int64_t ObtainLong(const std::string &key, int64_t defValue); 45 int SaveFloat(const std::string &key, float value); 46 float ObtainFloat(const std::string &key, float defValue); 47 bool IsExistKey(const std::string &key); 48 int RemoveKey(const std::string &key); 49 int RemoveAll(); 50 void Refresh(); 51 int RefreshSync(); 52 void RegisterObserver(std::shared_ptr<NativePreferences::PreferencesObserver> preferencesObserver); 53 void UnRegisterObserver(std::shared_ptr<NativePreferences::PreferencesObserver> preferencesObserver); 54 int DeleteProfiles(); 55 56 private: 57 std::shared_ptr<NativePreferences::Preferences> GetProfiles(const std::string &path, int &errCode); 58 59 private: 60 std::string path_ = "/data/data_storage/telephonyProperties.xml"; 61 int errCode_ = NativePreferences::E_OK; 62 const std::string error_ = "error"; 63 }; 64 } // namespace Telephony 65 } // namespace OHOS 66 #endif // DATA_STORAGE_PREFERENCES_UTILS_H