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 TEST_WUKONG_COMPONENT_MANAGER_H 16 #define TEST_WUKONG_COMPONENT_MANAGER_H 17 18 #include "accessibility_element_info.h" 19 #include "component_tree.h" 20 #include "wukong_define.h" 21 22 namespace OHOS { 23 namespace WuKong { 24 enum ComponentStatus { 25 COMPONENT_STATUS_DISCONNECT, 26 COMPONENT_STATUS_CONNECTED, 27 COMPONENT_STATUS_CONNECTING 28 }; 29 30 class ComponentManagerListener { 31 public: 32 virtual void OnStatusUpdated(ComponentStatus status) = 0; 33 virtual void OnScreenUpdated() = 0; 34 virtual void OnPermissionScreenShown() = 0; 35 }; 36 class ComponentManager : public DelayedSingleton<ComponentManager> { 37 public: 38 bool Connect(); 39 40 void Disconnect(); 41 42 uint32_t AddRegisterListener(std::shared_ptr<ComponentManagerListener> listener); 43 44 void DeleteRegisterListener(const uint32_t handle); 45 46 ErrCode GetReportInfo(std::string& info); 47 48 ErrCode PermoissionInput(); 49 50 std::vector<std::shared_ptr<ComponentManagerListener>> GetListenerList(); 51 52 /** 53 * @brief input multimode event for the current page. 54 * @param elementInfo current component 55 * @param actionType the action type of current component 56 * @return Return ERR_OK on success, others on failure. 57 */ 58 ErrCode ComponentEventInput(OHOS::Accessibility::AccessibilityElementInfo& elementInfo, const int actionType); 59 60 /** 61 * @brief input back event for the current page. 62 * @return Return ERR_OK on success, others on failure. 63 */ 64 ErrCode BackToPrePage(); 65 66 /** 67 * @brief get locate info. 68 * @return Return startX_. 69 */ GetStartX()70 int32_t GetStartX() 71 { 72 return startX_; 73 } 74 75 /** 76 * @brief get locate info. 77 * @return Return startY_. 78 */ GetStartY()79 int32_t GetStartY() 80 { 81 return startY_; 82 } 83 84 /** 85 * @brief get locate info. 86 * @return Return endX_. 87 */ GetEndX()88 int32_t GetEndX() 89 { 90 return endX_; 91 } 92 93 /** 94 * @brief get locate info. 95 * @return Return endY_. 96 */ GetEndY()97 int32_t GetEndY() 98 { 99 return endY_; 100 } 101 102 DECLARE_DELAYED_SINGLETON(ComponentManager); 103 104 private: 105 bool connected_ = false; 106 107 int32_t startX_ = -1; 108 int32_t endX_ = -1; 109 int32_t startY_ = -1; 110 int32_t endY_ = -1; 111 112 std::vector<std::shared_ptr<ComponentManagerListener>> listenerList_; 113 std::map<int, std::function<ErrCode(Accessibility::AccessibilityElementInfo&)>> componentMap_; 114 115 /** 116 * @brief get the positin of current component . 117 * @param elementInfo current component. 118 */ 119 void GetComponentPosition(Accessibility::AccessibilityElementInfo& elementInfo); 120 121 /** 122 * @brief input up swap event for the current component. 123 * @param elementInfo current component. 124 * @return Return ERR_OK on success, others on failure. 125 */ 126 ErrCode ComponentUpSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 127 128 /** 129 * @brief input dowan swap event for the target component. 130 * @param elementInfo element, also call component. 131 * @return Return ERR_OK on success, others on failure. 132 */ 133 ErrCode ComponentDownSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 134 135 /** 136 * @brief input keyboard event for the target component. 137 * @param elementInfo element, also call component. 138 * @return Return ERR_OK on success, others on failure. 139 */ 140 ErrCode ComponentMultikeyInput(Accessibility::AccessibilityElementInfo& elementInfo); 141 142 /** 143 * @brief input left swap event for the target component. 144 * @param elementInfo element, also call component. 145 * @return Return ERR_OK on success, others on failure. 146 */ 147 ErrCode ComponentLeftSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 148 149 /** 150 * @brief input touch event for the target component. 151 * @param elementInfo element, also call component. 152 * @return Return ERR_OK on success, others on failure. 153 */ 154 ErrCode ComponentTouchInput(Accessibility::AccessibilityElementInfo& elementInfo); 155 156 /** 157 * @brief Create a Event Input Map. 158 * @return Return ERR_OK on success, others on failure. 159 */ 160 ErrCode CreateEventInputMap(); 161 }; 162 } // namespace WuKong 163 } // namespace OHOS 164 #endif // TEST_WUKONG_COMPONENT_MANAGER_H 165