• 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 #ifndef ACCESSIBILITY_SETTINGS_CONFIG_H
16 #define ACCESSIBILITY_SETTINGS_CONFIG_H
17 
18 #include <map>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 #include "accessibility_caption.h"
24 #include "accessibility_datashare_helper.h"
25 
26 namespace OHOS {
27 namespace Accessibility {
28 
29 enum class A11yDarkModeType : uint32_t {
30     DEFAULT_DARK_MODE_STATE,
31     DARK_MODE_OPEN_ALL_DAY,
32     DARK_MODE_TIMED_ON
33 };
34 
35 class AccessibilitySettingsConfig final {
36 public:
37     explicit AccessibilitySettingsConfig(int id);
38     ~AccessibilitySettingsConfig() = default;
39 
40     RetError SetEnabled(const bool state);
41     RetError SetTouchGuideState(const bool state);
42     RetError SetGestureState(const bool state);
43     RetError SetKeyEventObserverState(const bool state);
44     RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption);
45     RetError SetCaptionState(const bool state);
46     RetError SetScreenMagnificationState(const bool state);
47     RetError SetMagnificationState(const bool state);
48     RetError SetScreenMagnificationType(const uint32_t type);
49     RetError SetScreenMagnificationMode(const uint32_t mode);
50     RetError SetScreenMagnificationScale(const float scale);
51     RetError SetShortKeyState(const bool state);
52     RetError SetShortKeyOnLockScreenState(const bool state);
53     RetError SetShortKeyTimeout(const int32_t time);
54     RetError SetMouseKeyState(const bool state);
55     RetError SetMouseAutoClick(const int32_t time);
56     RetError SetShortkeyTarget(const std::string &name);
57     RetError SetShortkeyMultiTarget(const std::vector<std::string> &name);
58     RetError SetShortkeyMultiTargetInPkgRemove(const std::string &name);
59     RetError SetHighContrastTextState(const bool state);
60     RetError SetInvertColorState(const bool state);
61     RetError SetAnimationOffState(const bool state);
62     RetError SetAudioMonoState(const bool state);
63     RetError SetDaltonizationState(const bool state);
64     RetError SetDaltonizationColorFilter(const uint32_t filter);
65     RetError SetContentTimeout(const uint32_t time);
66     RetError SetBrightnessDiscount(const float discount);
67     RetError SetAudioBalance(const float balance);
68     RetError SetClickResponseTime(const uint32_t time);
69     RetError SetIgnoreRepeatClickState(const bool state);
70     RetError SetIgnoreRepeatClickTime(const uint32_t time);
71     RetError SetStartToHosState(const bool state);
72     RetError SetIgnoreRepeatClickReconfirm(const bool state);
73     RetError SetZoomGestureEnabledReconfirm(const bool state);
74     RetError SetColorModeState(const A11yDarkModeType &type);
75 
76     bool GetEnabledState() const;
77     bool GetTouchGuideState() const;
78     bool GetGestureState() const;
79     bool GetKeyEventObserverState() const;
80     bool GetCaptionState() const;
81     bool GetScreenMagnificationState() const;
82     bool GetShortKeyState() const;
83     bool GetShortKeyOnLockScreenState() const;
84     int32_t GetShortKeyTimeout() const;
85     bool GetMouseKeyState() const;
86     int32_t GetMouseAutoClick() const;
87     const std::string &GetShortkeyTarget() const;
88     const std::vector<std::string> GetShortkeyMultiTarget();
89     bool GetHighContrastTextState() const;
90     bool GetInvertColorState() const;
91     bool GetAnimationOffState() const;
92     bool GetAudioMonoState() const;
93     bool GetDaltonizationState() const;
94     uint32_t GetDaltonizationColorFilter() const;
95     uint32_t GetContentTimeout() const;
96     float GetBrightnessDiscount() const;
97     float GetAudioBalance() const;
98     const AccessibilityConfig::CaptionProperty &GetCaptionProperty() const;
99     uint32_t GetClickResponseTime() const;
100     bool GetIgnoreRepeatClickState() const;
101     uint32_t GetIgnoreRepeatClickTime() const;
102     uint32_t GetScreenMagnificationType() const;
103     uint32_t GetScreenMagnificationMode() const;
104     float GetScreenMagnificationScale() const;
105 
106     RetError SetEnabledAccessibilityServices(const std::vector<std::string> &services);
107     const std::vector<std::string> GetEnabledAccessibilityServices();
108     RetError AddEnabledAccessibilityService(const std::string &serviceName);
109     RetError RemoveEnabledAccessibilityService(const std::string &serviceName);
110     uint32_t GetConfigState();
111     bool GetStartToHosState();
112     void SetDefaultShortcutKeyService();
113     void InitSetting();
114     void CloneShortkeyService(bool isScreenReaderEnabled);
115     void OnDataClone();
116     void CloneAudioState();
117     void InitShortKeyConfig();
118     uint32_t GetShortKeyService(std::vector<std::string> &services);
GetDbHandle()119     std::shared_ptr<AccessibilityDatashareHelper> GetDbHandle()
120     {
121         return datashare_;
122     }
123 
124     void Init();
125     void ClearData();
126     bool GetInitializeState();
127     void SetInitializeState(bool isInitialized);
128 private:
129     void InitCaption();
130     void InitCapability();
131     void InitPrivacySpaceConfig();
132     void InitAnimationOffConfig();
133     void HandleIgnoreRepeatClickCache();
134     void HandleIgnoreRepeatClickState();
135     RetError SetConfigState(const std::string& key, bool value);
136 
137     int32_t accountId_;
138     bool enabled_ = false;
139     bool eventTouchGuideState_ = false;
140     bool gesturesSimulation_ = false;
141     bool filteringKeyEvents_ = false;
142     bool isScreenMagnificationState_ = false;
143     uint32_t screenMagnificationType_ = 0;
144     uint32_t screenMagnificationMode_ = 0;
145     float screenMagnificationScale_ = 2.0f;
146     bool isCaptionState_ = false;
147     AccessibilityConfig::CaptionProperty captionProperty_;
148     bool isMouseKeyState_ = false;
149     bool isShortKeyState_ = false;
150     int32_t mouseAutoClick_ = -1;
151     std::string shortkeyTarget_ = "";
152     bool highContrastTextState_ = false;
153     bool invertColorState_ = false;
154     bool animationOffState_ = false;
155     bool audioMonoState_ = false;
156     bool daltonizationState_ = false;
157     uint32_t daltonizationColorFilter_ = 0;
158     uint32_t contentTimeout_ = 0;
159     float brightnessDiscount_ = 0.0;
160     float audioBalance_ = 0.0;
161     uint32_t clickResponseTime_ = 0;
162     bool ignoreRepeatClickState_ = false;
163     uint32_t ignoreRepeatClickTime_ = 0;
164     bool isShortKeyEnabledOnLockScreen_ = false;
165     int32_t shortKeyTimeout_ = 3;
166 
167     std::vector<std::string> shortkeyMultiTarget_ {};
168     std::vector<std::string> enabledAccessibilityServices_ {}; // bundleName/abilityName
169 
170     std::shared_ptr<AccessibilityDatashareHelper> datashare_ = nullptr;
171     std::shared_ptr<AccessibilityDatashareHelper> systemDatashare_ = nullptr;
172     ffrt::mutex interfaceMutex_;
173     bool isInitialized_ = false;
174 };
175 } // namespace Accessibility
176 } // namespace OHOS
177 #endif // ACCESSIBILITY_SETTINGS_CONFIG_H