1 /*
2  * Copyright (c) 2022 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 ACCESSIBILITY_SETTING_PROVIDER_H
17 #define ACCESSIBILITY_SETTING_PROVIDER_H
18 
19 #include "datashare_helper.h"
20 #include "errors.h"
21 #include "mutex"
22 #include "accessibility_setting_observer.h"
23 #include "accessibility_datashare_helper.h"
24 #include "accessibility_caption.h"
25 
26 namespace OHOS {
27 namespace Accessibility {
28 class AccessibilitySettingProvider : public AccessibilityDatashareHelper {
29 public:
30     static std::shared_ptr<AccessibilitySettingProvider> GetInstance(int32_t systemAbilityId);
31     static std::shared_ptr<AccessibilitySettingProvider> instance_;
32     AccessibilitySettingProvider();
33     ~AccessibilitySettingProvider();
34     void DeleteInstance();
35     RetError GetStringValue(const std::string& key, std::string& value);
36     RetError GetIntValue(const std::string& key, int32_t& value);
37     RetError GetLongValue(const std::string& key, int64_t& value);
38     RetError GetBoolValue(const std::string& key, bool& value);
39     RetError GetFloatValue(const std::string& key, float& value);
40     RetError PutStringValue(const std::string& key, const std::string& value, bool needNotify = true);
41     RetError PutIntValue(const std::string& key, int32_t value, bool needNotify = true);
42     RetError PutLongValue(const std::string& key, int64_t value, bool needNotify = true);
43     RetError PutBoolValue(const std::string& key, bool value, bool needNotify = true);
44     bool IsValidKey(const std::string& key);
45     sptr<AccessibilitySettingObserver> CreateObserver(const std::string& key,
46         AccessibilitySettingObserver::UpdateFunc& func);
47 
48     RetError RegisterObserver(const std::string& key, AccessibilitySettingObserver::UpdateFunc& func);
49     RetError UnregisterObserver(const std::string& key);
50 private:
51     std::string GetConfigKey(int32_t state);
52 
53 private:
54     static ffrt::mutex mutex_;
55 };
56 } // namespace Accessibility
57 } // namespace OHOS
58 #endif // ACCESSIBILITY_SETTING_PROVIDER_H