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 "datashare_helper.h" 20 #include "input_method_property.h" 21 #include "serializable.h" 22 #include "settings_data_observer.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 constexpr const char *SETTING_COLUMN_KEYWORD = "KEYWORD"; 27 constexpr const char *SETTING_COLUMN_VALUE = "VALUE"; 28 constexpr const char *SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/" 29 "SETTINGSDATA?Proxy=true"; 30 constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; 31 constexpr const char *SETTINGS_USER_DATA_URI = "datashare:///com.ohos.settingsdata/" 32 "entry/settingsdata/USER_SETTINGSDATA_"; 33 struct UserImeConfig : public Serializable { 34 std::string userId; 35 std::vector<std::string> identities; UnmarshalUserImeConfig36 bool Unmarshal(cJSON *node) override 37 { 38 GetValue(node, userId, identities); 39 return true; 40 } MarshalUserImeConfig41 bool Marshal(cJSON *node) const override 42 { 43 SetValue(node, userId, identities); 44 return true; 45 } 46 }; 47 48 class SettingsDataUtils : public RefBase { 49 public: 50 static sptr<SettingsDataUtils> GetInstance(); 51 std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string &uriProxy); 52 int32_t CreateAndRegisterObserver(const std::string &key, SettingsDataObserver::CallbackFunc func); 53 int32_t GetStringValue(const std::string &uriProxy, const std::string &key, std::string &value); 54 bool SetStringValue(const std::string &uriProxy, const std::string &key, const std::string &value); 55 bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper); 56 Uri GenerateTargetUri(const std::string &uriProxy, const std::string &key); 57 bool EnableIme(int32_t userId, const std::string &bundleName); 58 59 private: 60 SettingsDataUtils() = default; 61 ~SettingsDataUtils(); 62 int32_t RegisterObserver(const sptr<SettingsDataObserver> &observer); 63 int32_t UnregisterObserver(const sptr<SettingsDataObserver> &observer); 64 sptr<IRemoteObject> GetToken(); 65 std::vector<std::string> split(const std::string &text, char separator); 66 std::string SetSettingValues(const std::string &settingValue, const std::string &bundleName); 67 68 private: 69 static std::mutex instanceMutex_; 70 static sptr<SettingsDataUtils> instance_; 71 std::mutex remoteObjMutex_; 72 sptr<IRemoteObject> remoteObj_ = nullptr; 73 std::mutex observerListMutex_; 74 std::vector<sptr<SettingsDataObserver>> observerList_; 75 }; 76 } // namespace MiscServices 77 } // namespace OHOS 78 79 #endif // SETTINGS_DATA_UTILS_H 80