• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_caption.h"
24 
25 namespace OHOS {
26 namespace Accessibility {
27 class AccessibilitySettingProvider : public NoCopyable {
28 public:
29     static AccessibilitySettingProvider& GetInstance(int32_t systemAbilityId);
30     void DeleteInstance();
31     ErrCode GetStringValue(const std::string& key, std::string& value);
32     ErrCode GetIntValue(const std::string& key, int32_t& value);
33     ErrCode GetLongValue(const std::string& key, int64_t& value);
34     ErrCode GetBoolValue(const std::string& key, bool& value);
35     ErrCode GetFloatValue(const std::string& key, float& value);
36     ErrCode PutStringValue(const std::string& key, const std::string& value, bool needNotify = true);
37     ErrCode PutIntValue(const std::string& key, int32_t value, bool needNotify = true);
38     ErrCode PutLongValue(const std::string& key, int64_t value, bool needNotify = true);
39     ErrCode PutBoolValue(const std::string& key, bool value, bool needNotify = true);
40     bool IsValidKey(const std::string& key);
41     sptr<AccessibilitySettingObserver> CreateObserver(const std::string& key,
42         AccessibilitySettingObserver::UpdateFunc& func);
43     ErrCode RegisterObserver(const sptr<AccessibilitySettingObserver>& observer);
44     ErrCode UnregisterObserver(const sptr<AccessibilitySettingObserver>& observer);
45 
46 protected:
47     ~AccessibilitySettingProvider() override;
48 
49 private:
50     static AccessibilitySettingProvider* instance_;
51     static std::mutex mutex_;
52     static sptr<IRemoteObject> remoteObj_;
53 
54     static void Initialize(int32_t systemAbilityId);
55     static std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
56     static bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper>& helper);
57     static Uri AssembleUri(const std::string& key);
58 };
59 } // namespace Accessibility
60 } // namespace OHOS
61 #endif // ACCESSIBILITY_SETTING_PROVIDER_H