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 ErrCode BackToHome(); 67 GetConnectStatus()68 bool GetConnectStatus() 69 { 70 return connected_; 71 } 72 73 /** 74 * @brief get locate info. 75 * @return Return startX_. 76 */ GetStartX()77 int32_t GetStartX() 78 { 79 return startX_; 80 } 81 82 /** 83 * @brief get locate info. 84 * @return Return startY_. 85 */ GetStartY()86 int32_t GetStartY() 87 { 88 return startY_; 89 } 90 91 /** 92 * @brief get locate info. 93 * @return Return endX_. 94 */ GetEndX()95 int32_t GetEndX() 96 { 97 return endX_; 98 } 99 100 /** 101 * @brief get locate info. 102 * @return Return endY_. 103 */ GetEndY()104 int32_t GetEndY() 105 { 106 return endY_; 107 } 108 109 DECLARE_DELAYED_SINGLETON(ComponentManager); 110 111 private: 112 bool connected_ = false; 113 114 int32_t startX_ = -1; 115 int32_t endX_ = -1; 116 int32_t startY_ = -1; 117 int32_t endY_ = -1; 118 119 std::vector<std::shared_ptr<ComponentManagerListener>> listenerList_; 120 std::map<int, std::function<ErrCode(Accessibility::AccessibilityElementInfo&)>> componentMap_; 121 122 /** 123 * @brief get the positin of current component . 124 * @param elementInfo current component. 125 */ 126 void GetComponentPosition(Accessibility::AccessibilityElementInfo& elementInfo); 127 128 /** 129 * @brief input up swap event for the current component. 130 * @param elementInfo current component. 131 * @return Return ERR_OK on success, others on failure. 132 */ 133 ErrCode ComponentUpSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 134 135 /** 136 * @brief input dowan swap 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 ComponentDownSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 141 142 /** 143 * @brief input keyboard 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 ComponentMultikeyInput(Accessibility::AccessibilityElementInfo& elementInfo); 148 149 /** 150 * @brief input left swap 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 ComponentLeftSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 155 156 /** 157 * @brief input touch event for the target component. 158 * @param elementInfo element, also call component. 159 * @return Return ERR_OK on success, others on failure. 160 */ 161 ErrCode ComponentTouchInput(Accessibility::AccessibilityElementInfo& elementInfo); 162 163 /** 164 * @brief Create a Event Input Map. 165 * @return Return ERR_OK on success, others on failure. 166 */ 167 ErrCode CreateEventInputMap(); 168 }; 169 } // namespace WuKong 170 } // namespace OHOS 171 #endif // TEST_WUKONG_COMPONENT_MANAGER_H 172