• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <list>
20 
21 #include "datashare_helper.h"
22 #include "input_method_property.h"
23 #include "serializable.h"
24 #include "settings_data_observer.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28 constexpr const char *SETTING_COLUMN_KEYWORD = "KEYWORD";
29 constexpr const char *SETTING_COLUMN_VALUE = "VALUE";
30 constexpr const char *SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/"
31                                           "SETTINGSDATA?Proxy=true";
32 constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
33 constexpr const char *SETTINGS_USER_DATA_URI = "datashare:///com.ohos.settingsdata/"
34                                                "entry/settingsdata/USER_SETTINGSDATA_";
35 class SettingsDataUtils : public RefBase {
36 public:
37     static constexpr const char *ENABLE_IME = "settings.inputmethod.enable_ime";
38     static constexpr const char *SECURITY_MODE = "settings.inputmethod.full_experience";
39     static SettingsDataUtils &GetInstance();
40     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string &uriProxy);
41     int32_t CreateAndRegisterObserver(
42         const std::string &uriProxy, const std::string &key, const SettingsDataObserver::CallbackFunc &func);
43     int32_t RegisterObserver(const std::string &uriProxy, const std::string &key,
44         const SettingsDataObserver::CallbackFunc &func, sptr<SettingsDataObserver> &observer);
45     int32_t UnregisterObserver(const sptr<SettingsDataObserver> &observer);
46     int32_t GetStringValue(const std::string &uriProxy, const std::string &key, std::string &value);
47     bool SetStringValue(const std::string &uriProxy, const std::string &key, const std::string &value);
48     bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper);
49     Uri GenerateTargetUri(const std::string &uriProxy, const std::string &key);
50     void NotifyDataShareReady();
51     bool IsDataShareReady();
52     void Release();
53 
54 private:
55     SettingsDataUtils() = default;
56     ~SettingsDataUtils();
57     int32_t RegisterObserver(const sptr<SettingsDataObserver> &observer);
58     sptr<IRemoteObject> GetToken();
59 
60 private:
61     std::mutex remoteObjMutex_;
62     sptr<IRemoteObject> remoteObj_ = nullptr;
63     std::mutex observerListMutex_;
64     std::list<sptr<SettingsDataObserver>> observerList_;
65     std::atomic<bool> isDataShareReady_{ false };
66 };
67 } // namespace MiscServices
68 } // namespace OHOS
69 
70 #endif // SETTINGS_DATA_UTILS_H
71