• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GetUiWindows(std::vector<Window> &out) override;
32 
33         bool GetWidgetsInWindow(const Window &winInfo, unique_ptr<ElementNodeIterator> &elementIterator) override;
34 
35         bool WaitForUiSteady(uint32_t idleThresholdMs, uint32_t timeoutMs) const override;
36 
37         void InjectTouchEventSequence(const PointerMatrix &events) const override;
38 
39         void InjectMouseEventSequence(const vector<MouseEvent> &events) const override;
40 
41         void InjectKeyEventSequence(const std::vector<KeyEvent> &events) const override;
42 
43         void PutTextToClipboard(std::string_view text) const override;
44 
45         bool TakeScreenCap(int32_t fd, std::stringstream &errReceiver, Rect rect = {0, 0, 0, 0}) const override;
46 
47         bool GetCharKeyCode(char ch, int32_t& code, int32_t& ctrlCode) const override;
48 
49         bool IsWorkable() const override;
50 
51         // setup method, connect to system ability AAMS
52         bool ConnectToSysAbility();
53 
54         // teardown method, disconnect from system ability AAMS
55         void DisConnectFromSysAbility();
56 
57         void SetDisplayRotation(DisplayRotation rotation) const override;
58 
59         DisplayRotation GetDisplayRotation() const override;
60 
61         void SetDisplayRotationEnabled(bool enabled) const override;
62 
63         Point GetDisplaySize() const override;
64 
65         Point GetDisplayDensity() const override;
66 
67         bool IsScreenOn() const override;
68 
69         void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const override;
70 
71         void GetHidumperInfo(std::string windowId, char **buf, size_t &len) override;
72     private:
73         void  InjectMouseEvent(const MouseEvent &event) const;
74         bool connected_ = false;
75         std::mutex dumpMtx;
76     };
77 }
78 
79 #endif