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_ACCOUNT_DATA_H 16 #define ACCESSIBILITY_ACCOUNT_DATA_H 17 18 #include <map> 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 #include "accessibility_caption.h" 24 #include "accessibility_state_event.h" 25 #include "accessibility_system_ability_client.h" 26 #include "accessibility_window_connection.h" 27 #include "accessible_ability_connection.h" 28 #include "accessible_ability_manager_service_caption_property_interface.h" 29 #include "accessible_ability_manager_service_state_interface.h" 30 #include "element_name.h" 31 #include "preferences_helper.h" 32 #include "refbase.h" 33 34 namespace OHOS { 35 namespace Accessibility { 36 using CaptionPropertyCallbacks = std::vector<sptr<IAccessibleAbilityManagerServiceCaptionProperty>>; 37 class AccessibleAbilityConnection; 38 39 class IAccessibleAbilityManagerServiceState; 40 41 class AccessibilityWindowConnection; 42 class IAccessibleAbilityManagerServiceCaptionProperty; 43 44 enum STATE : int { 45 ACCESSIBILITY, 46 TOUCHGUIDE, 47 GESTURE, 48 KEYEVENT, 49 CAPTION 50 }; 51 52 class AccessibilityAccountData final : public RefBase { 53 public: 54 AccessibilityAccountData(int accountId); 55 ~AccessibilityAccountData(); 56 57 /** 58 * @brief Get the ID of the account. 59 * @param 60 * @return Returns accountId. 61 */ 62 int GetAccountId(); 63 64 /** 65 * @brief Get Accessibility state. 66 * @param 67 * @return returns whether accessibility is connected and whether can touch browse. 68 */ 69 uint32_t GetAccessibilityState(); 70 71 /** 72 * @brief Switch users and clear old user data. 73 * @param 74 * @return 75 */ 76 void OnAccountSwitched(); 77 78 /** 79 * @brief Add connected accessibility services. 80 * @param connection Accessible ability connection. 81 * @return 82 */ 83 void AddConnectedAbility(sptr<AccessibleAbilityConnection>& connection); 84 85 /** 86 * @brief Remove connected accessibility services. 87 * @param connection Accessible ability connection. 88 * @return 89 */ 90 void RemoveConnectedAbility(sptr<AccessibleAbilityConnection>& connection); 91 92 /** 93 * @brief Remove connecting accessibility services. 94 * @param elementName Accessibility corresponding elementName. 95 * @return 96 */ 97 void RemoveConnectingA11yAbility(const AppExecFwk::ElementName& elementName); 98 99 /** 100 * @brief Add accessibility monitoring connection. 101 * @param callback Accessibility monitoring connection. 102 * @return 103 */ 104 void AddStateCallback(const sptr<IAccessibleAbilityManagerServiceState>& callback); 105 106 /** 107 * @brief Remove accessibility monitoring connection. 108 * @param callback Accessibility monitoring connection. 109 * @return 110 */ 111 void RemoveStateCallback(const wptr<IRemoteObject>& callback); 112 113 void AddCaptionPropertyCallback(const sptr<IAccessibleAbilityManagerServiceCaptionProperty>& callback); 114 void RemoveCaptionPropertyCallback(const wptr<IRemoteObject>& callback); 115 /** 116 * @brief Add interface operation interactive connection. 117 * @param windowId Interface operation interactive connection the 118 * corresponding window id. 119 * @param interactionConnection Interface interface operation 120 * interactive connection. 121 * @return 122 */ 123 void AddAccessibilityWindowConnection( 124 const int windowId, const sptr<AccessibilityWindowConnection>& interactionConnection); 125 126 /** 127 * @brief Remove interface operation interactive connection. 128 * @param windowId Interface operation interactive connection the corresponding window id. 129 * @return 130 */ 131 void RemoveAccessibilityWindowConnection(const int windowId); 132 133 /** 134 * @brief Add connecting accessibility. 135 * @param elementName Accessibility corresponding elementName. 136 * @return 137 */ 138 void AddConnectingA11yAbility(const AppExecFwk::ElementName& elementName); 139 140 void AddEnabledAbility(const AppExecFwk::ElementName& elementName); // For UT 141 142 /** 143 * @brief Remove accessibility that have been opened. 144 * @param elementName Accessibility corresponding elementName. 145 * @return 146 */ 147 void RemoveEnabledAbility(const AppExecFwk::ElementName& elementName); 148 149 void AddInstalledAbility(AccessibilityAbilityInfo& abilityInfo); // For UT 150 151 /** 152 * @brief Empty installed accessibility list. 153 * @param abilityInfo Accessibility ability info. 154 * @return 155 */ 156 void RemoveInstalledAbility(std::string bundleName); 157 158 /** 159 * @brief The real procedure for add connecting ability. 160 * @param 161 * @return 162 */ 163 void ClearInstalledAbility(); 164 165 /** 166 * @brief Get connected accessibility list. 167 * @param 168 * @return Store map of connected accessibility abilities. 169 */ 170 const std::map<std::string, sptr<AccessibleAbilityConnection>> GetConnectedA11yAbilities(); 171 172 /** 173 * @brief Get accessibility listening connection list. 174 * @param 175 * @return Store vector of accessibility listening connection. 176 */ 177 const std::vector<sptr<IAccessibleAbilityManagerServiceState>> GetStateCallbacks(); 178 179 const CaptionPropertyCallbacks GetCaptionPropertyCallbacks(); 180 181 /** 182 * @brief Get interface operation interactive connection list. 183 * @param 184 * @return Store map of interface operation interactive connection. 185 */ 186 const std::map<int, sptr<AccessibilityWindowConnection>> GetAsacConnections(); 187 188 /** 189 * @brief Query accessible ability connection through elementName URI. 190 * @param elementName Accessibility elementName URI 191 * @return Accessible ability connection corresponding to elementName URI. 192 */ 193 const sptr<AccessibleAbilityConnection> GetAccessibleAbilityConnection(const std::string elementName); 194 195 /** 196 * @brief Query interface operation interactive connection through window id. 197 * @param windowId Interface operation interactive connection the corresponding window id. 198 * @return Interface operation interactive connection corresponding to window id. 199 */ 200 const sptr<AccessibilityWindowConnection> GetAccessibilityWindowConnection(const int windowId); 201 202 /** 203 * @brief Get connecting abilities list. 204 * @param 205 * @return Store map of connecting abilities. 206 */ 207 const std::map<std::string, AppExecFwk::ElementName> GetConnectingA11yAbilities(); 208 209 /** 210 * @brief Get the accessibility ability info of the corresponding state according to the 211 * ability state type. 212 * @param state Ability state type. 213 * @return 214 */ 215 const std::vector<AccessibilityAbilityInfo> GetAbilitiesByState(AbilityStateType state); 216 217 /** 218 * @brief Get enable accessibility list. 219 * @param 220 * @return Store map of enable accessibility abilities. 221 */ 222 const std::map<std::string, AppExecFwk::ElementName> GetEnabledAbilities(); 223 224 /** 225 * @brief Get install accessibility list. 226 * @param 227 * @return Store vector of install accessibility abilities. 228 */ 229 const std::vector<AccessibilityAbilityInfo> GetInstalledAbilities(); 230 231 /** 232 * @brief Update user enabled accessibility capabilities. 233 * @param 234 * @return 235 */ 236 void UpdateAccountCapabilities(); 237 238 /** 239 * @brief Read accessibility information in settings. 240 * @param 241 * @return Success return true, failed return false. 242 */ 243 bool ReadConfigurationForAccountData(); 244 245 /** 246 * @brief Get flag with whether have zoom capability. 247 * @param 248 * @return isScreenMagnification_. 249 */ GetScreenMagnificationFlag()250 bool GetScreenMagnificationFlag() 251 { 252 return isScreenMagnification_; 253 } 254 255 /** 256 * @brief Get flag with whether have touch guide capability. 257 * @param 258 * @return isEventTouchGuideState_. 259 */ GetEventTouchGuideStateFlag()260 bool GetEventTouchGuideStateFlag() 261 { 262 return isEventTouchGuideState_; 263 } 264 265 /** 266 * @brief Get flag with whether have key event observer capability. 267 * @param 268 * @return isFilteringKeyEvents_. 269 */ GetFilteringKeyEventsFlag()270 bool GetFilteringKeyEventsFlag() 271 { 272 return isFilteringKeyEvents_; 273 } 274 275 /** 276 * @brief Get flag with whether have gesture capability. 277 * @param 278 * @return isGesturesSimulation_. 279 */ GetGesturesSimulationFlag()280 bool GetGesturesSimulationFlag() 281 { 282 return isGesturesSimulation_; 283 } 284 bool GetInstalledAbilitiesFromBMS(); 285 286 /** 287 * @brief Add enabled event which is needed by accessible ability. 288 * @param type EventType 289 * @return null. 290 */ 291 void AddEventEnabled(EventType type); 292 293 /** 294 * @brief Delet enabled event which is needed by accessible ability. 295 * @param type EventType 296 * @return null. 297 */ 298 void DeleteEventEnabled(EventType type); 299 GetCaptionProperty()300 CaptionProperty GetCaptionProperty() 301 { 302 return captionProperty_; 303 }; 304 305 bool SetCaptionProperty(const CaptionProperty& caption); 306 307 bool SetCaptionState(const bool state); 308 309 bool SetEnabled(const bool state); 310 311 bool SetTouchGuideState(const bool state); 312 313 bool SetGestureState(const bool state); 314 315 bool SetKeyEventObserverState(const bool state); 316 317 bool GetEnabledState(); 318 319 bool GetTouchGuideState(); 320 321 bool GetGestureState(); 322 323 bool GetKeyEventObserverState(); 324 325 bool GetCaptionState(); 326 327 bool SetEnabledObj(std::map<std::string, AppExecFwk::ElementName> it); 328 329 void init(); 330 331 bool DisableAbilities(std::map<std::string, AppExecFwk::ElementName> it); 332 private: 333 /** 334 * @brief Update connected accessibility whether have touch guide 335 * capability. Have touch guide capability isEventTouchGuideState_ is 336 * true, otherwise isEventTouchGuideState_ is false. 337 * @param 338 * @return 339 */ 340 void UpdateEventTouchGuideCapability(); 341 342 /** 343 * @brief Update connected accessibility whether have gesture capability. 344 * Have gesture capability isGesturesSimulation_ is true, 345 * otherwise isGesturesSimulation_ is false. 346 * @param 347 * @return 348 */ 349 void UpdateGesturesSimulationCapability(); 350 351 /** 352 * @brief Update connected accessibility whether have key event observer capability. 353 * Have key event observer capability isFilteringKeyEvents_ is true, 354 * otherwise isFilteringKeyEvents_ is false. 355 * @param 356 * @return 357 */ 358 void UpdateFilteringKeyEventsCapability(); 359 360 /** 361 * @brief Update connected accessibility whether have zoom capability. 362 * Have zoom capability isScreenMagnification_ is true, 363 * otherwise isScreenMagnification_ is false. 364 * @param 365 * @return 366 */ 367 void UpdateMagnificationCapability(); 368 369 void CaptionInit(const std::shared_ptr<NativePreferences::Preferences> &pref); 370 void CapbilityInit(const std::shared_ptr<NativePreferences::Preferences> &pref); 371 void EnabledListInit(const std::shared_ptr<NativePreferences::Preferences> &pref); 372 void StringToVector(std::string &stringIn, std::vector<std::string> &vectorResult); 373 void VectorToString(std::vector<std::string> &vectorVal, std::string &stringOut); 374 void RemoveEnabledFromPref(const std::string bundleName); 375 void UpdateEnabledFromPref(); 376 bool SetStatePref(int type); 377 bool SetCaptionPropertyPref(); 378 std::string StateChange(bool state); 379 380 int id_; 381 bool isEnabled_ = false; 382 bool isEventTouchGuideState_ = false; 383 bool isScreenMagnification_ = false; 384 bool isFilteringKeyEvents_ = false; 385 bool isGesturesSimulation_ = false; 386 bool isCaptionState_ = false; 387 CaptionProperty captionProperty_; 388 std::map<std::string, sptr<AccessibleAbilityConnection>> connectedA11yAbilities_; // key: The URI of the 389 std::vector<sptr<IAccessibleAbilityManagerServiceState>> stateCallbacks_; 390 std::map<int, sptr<AccessibilityWindowConnection>> asacConnections_; // key: windowId 391 CaptionPropertyCallbacks captionPropertyCallbacks_; 392 std::vector<AccessibilityAbilityInfo> installedAbilities_; 393 std::map<std::string, AppExecFwk::ElementName> enabledAbilities_; // key: The URI of the ElementName. 394 std::map<std::string, AppExecFwk::ElementName> connectingA11yAbilities_; // key: The URI of the ElementName. 395 std::shared_ptr<NativePreferences::Preferences> pref_ = nullptr; 396 }; 397 } // namespace Accessibility 398 } // namespace OHOS 399 400 #endif // ACCESSIBILITY_ACCOUNT_DATA_H