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 SETTINGS_DATA_UTILS_H 17 #define SETTINGS_DATA_UTILS_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "datashare_helper.h" 25 #include "settings_data_observer.h" 26 #include "global.h" 27 #include "input_method_property.h" 28 #include "uri.h" 29 30 namespace OHOS { 31 namespace MiscServices { 32 class SettingsDataUtils : public RefBase { 33 public: 34 static sptr<SettingsDataUtils> GetInstance(); 35 int32_t GetStringValue(const std::string &key, std::string &value); 36 sptr<IRemoteObject> GetToken(); 37 std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(); 38 bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper); 39 int32_t CreateAndRegisterObserver(const std::string &key, SettingsDataObserver::CallbackFunc func); 40 int32_t RegisterObserver(const sptr<SettingsDataObserver> &observer); 41 int32_t UnregisterObserver(const sptr<SettingsDataObserver> &observer); 42 Uri GenerateTargetUri(const std::string &key); 43 44 private: 45 SettingsDataUtils() = default; 46 ~SettingsDataUtils(); 47 48 private: 49 static std::mutex instanceMutex_; 50 static sptr<SettingsDataUtils> instance_; 51 std::mutex tokenMutex_; 52 sptr<IRemoteObject> remoteObj_ = nullptr; 53 std::vector<sptr<SettingsDataObserver>> observerList_; 54 }; 55 } // namespace MiscServices 56 } // namespace OHOS 57 58 #endif // SETTINGS_DATA_UTILS_H 59