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