• 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) 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) 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         // setup method, connect to system ability AAMS
58         bool ConnectToSysAbility(ApiCallErr &error);
59 
60         // teardown method, disconnect from system ability AAMS
61         void DisConnectFromSysAbility();
62 
63         void SetDisplayRotation(DisplayRotation rotation) const override;
64 
65         DisplayRotation GetDisplayRotation(int32_t displayId) const override;
66 
67         void SetDisplayRotationEnabled(bool enabled) const override;
68 
69         Point GetDisplaySize(int32_t displayId) const override;
70 
71         Point GetDisplayDensity(int32_t displayId) const override;
72 
73         bool IsScreenOn() const override;
74 
75         void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const override;
76 
77         void GetHidumperInfo(std::string windowId, char **buf, size_t &len) override;
78     private:
79         void  InjectMouseEvent(const MouseEvent &event) const;
80         int32_t GetValidDisplayId(int32_t id) const;
81         bool connected_ = false;
82         std::mutex dumpMtx;
83         mutable std::vector<int32_t> downKeys_;
84     };
85 }
86 
87 #endif