1 /* 2 * Copyright (c) 2021-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 SYSTEM_UI_CONTROLLER_H 17 #define SYSTEM_UI_CONTROLLER_H 18 19 #include "ui_controller.h" 20 21 namespace OHOS::uitest { 22 /**The default UiController of ohos, which is effective for all apps.*/ 23 class SysUiController final : public UiController { 24 public: 25 SysUiController(); 26 27 ~SysUiController() override; 28 29 bool Initialize() override; 30 31 void GetUiHierarchy(std::vector<std::pair<Window, nlohmann::json>>& out, bool getWidgetNodes, 32 string targetApp = "") override; 33 34 bool WaitForUiSteady(uint32_t idleThresholdMs, uint32_t timeoutMs) const override; 35 36 void InjectTouchEventSequence(const PointerMatrix &events) const override; 37 38 void InjectMouseClick(MouseOpArgs mouseOpArgs) const override; 39 40 void InjectMouseScroll(MouseOpArgs mouseOpArgs) const override; 41 42 void InjectMouseMove(MouseOpArgs mouseOpArgs) const override; 43 44 void InjectKeyEventSequence(const std::vector<KeyEvent> &events) const override; 45 46 void PutTextToClipboard(std::string_view text) const override; 47 48 bool TakeScreenCap(int32_t fd, std::stringstream &errReceiver, Rect rect = {0, 0, 0, 0}) const override; 49 50 bool GetCharKeyCode(char ch, int32_t& code, int32_t& ctrlCode) const override; 51 52 bool IsWorkable() const override; 53 54 // setup method, connect to system ability AAMS 55 bool ConnectToSysAbility(); 56 57 // teardown method, disconnect from system ability AAMS 58 void DisConnectFromSysAbility(); 59 60 void SetDisplayRotation(DisplayRotation rotation) const override; 61 62 DisplayRotation GetDisplayRotation() const override; 63 64 void SetDisplayRotationEnabled(bool enabled) const override; 65 66 Point GetDisplaySize() const override; 67 68 Point GetDisplayDensity() const override; 69 70 bool IsScreenOn() const override; 71 72 void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const override; 73 74 private: 75 bool connected_ = false; 76 }; 77 } 78 79 #endif