• 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(ApiCallErr &error) override;
30 
31         void GetUiWindows(std::map<int32_t, vector<Window>> &out, int32_t targetDisplay = -1) override;
32 
33         bool GetWidgetsInWindow(const Window &winInfo, unique_ptr<ElementNodeIterator> &elementIterator,
34             AamsWorkMode mode) override;
35 
36         bool WaitForUiSteady(uint32_t idleThresholdMs, uint32_t timeoutMs) const override;
37 
38         void InjectTouchEventSequence(const PointerMatrix &events) const override;
39 
40         void InjectMouseEventSequence(const vector<MouseEvent> &events) const override;
41 
42         void InjectKeyEventSequence(const std::vector<KeyEvent> &events, int32_t displayId) const override;
43 
44         bool IsTouchPadExist() const override;
45 
46         void InjectTouchPadEventSequence(const vector<TouchPadEvent>& events) const override;
47 
48         void PutTextToClipboard(std::string_view text, ApiCallErr &error) const override;
49 
50         bool TakeScreenCap(int32_t fd, std::stringstream &errReceiver, int32_t displayId, Rect rect = {0, 0, 0, 0})
51             const override;
52 
53         bool GetCharKeyCode(char ch, int32_t& code, int32_t& ctrlCode) const override;
54 
55         bool IsWorkable() const override;
56 
57         bool IsWearable() const override;
58 
59         bool IsAdjustWindowModeEnable() const override;
60 
61         // setup method, connect to system ability AAMS
62         bool ConnectToSysAbility(ApiCallErr &error);
63 
64         // teardown method, disconnect from system ability AAMS
65         void DisConnectFromSysAbility();
66 
67         void SetDisplayRotation(DisplayRotation rotation) const override;
68 
69         DisplayRotation GetDisplayRotation(int32_t displayId) const override;
70 
71         void SetDisplayRotationEnabled(bool enabled) const override;
72 
73         Point GetDisplaySize(int32_t displayId) const override;
74 
75         Point GetDisplayDensity(int32_t displayId) const override;
76 
77         bool IsScreenOn() const override;
78 
79         void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const override;
80 
81         void GetHidumperInfo(std::string windowId, char **buf, size_t &len) override;
82 
83         bool CheckDisplayExist(int32_t displayId) const override;
84 
85         void CloseAamsEvent() const override;
86 
87         void OpenAamsEvent() const override;
88 
89         void ChangeWindowMode(int32_t windowId, WindowMode mode) const override;
90     private:
91         void  InjectMouseEvent(const MouseEvent &event) const;
92         int32_t GetValidDisplayId(int32_t id) const;
93         bool connected_ = false;
94         std::mutex dumpMtx;
95         mutable std::vector<int32_t> downKeys_;
96     };
97 }
98 
99 #endif