• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 ACCESSIBILITY_MT_HELPER_H
17 #define ACCESSIBILITY_MT_HELPER_H
18 
19 #include <vector>
20 #include "accessibility_def.h"
21 #include "hilog/log.h"
22 #include "i_accessible_ability_channel.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace Accessibility {
27 class AccessibilityHelper {
28 public:
GetInstance()29     static AccessibilityHelper& GetInstance()
30     {
31         static AccessibilityHelper helper;
32         return helper;
33     }
GetTestWindowId()34     int32_t GetTestWindowId() const
35     {
36         return testWindowId_;
37     }
SetTestWindowId(int32_t windowId)38     void SetTestWindowId(int32_t windowId)
39     {
40         testWindowId_ = windowId;
41     }
GetEventType()42     std::vector<EventType>& GetEventType()
43     {
44         std::lock_guard<std::mutex> lock(mtx_);
45         return mTeventType_;
46     }
GetEventTypeOfTargetIndex(int32_t index)47     EventType GetEventTypeOfTargetIndex(int32_t index)
48     {
49         std::lock_guard<std::mutex> lock(mtx_);
50         int32_t size = static_cast<int32_t>(mTeventType_.size());
51         if (size > index) {
52             return mTeventType_[index];
53         }
54         return TYPE_VIEW_INVALID;
55     }
PushEventType(EventType eventType)56     void PushEventType(EventType eventType)
57     {
58         std::lock_guard<std::mutex> lock(mtx_);
59         mTeventType_.push_back(eventType);
60     }
GetGestureId()61     int32_t GetGestureId() const
62     {
63         return mTgestureId_;
64     }
SetGestureId(int32_t gestureId)65     void SetGestureId(int32_t gestureId)
66     {
67         mTgestureId_ = gestureId;
68     }
GetTestStub()69     OHOS::sptr<OHOS::Accessibility::IAccessibleAbilityChannel>& GetTestStub()
70     {
71         return testStub_;
72     }
SetTestStub(const OHOS::sptr<OHOS::Accessibility::IAccessibleAbilityChannel> & stub)73     void SetTestStub(const OHOS::sptr<OHOS::Accessibility::IAccessibleAbilityChannel>& stub)
74     {
75         testStub_ = stub;
76     }
GetTestStateType()77     uint32_t GetTestStateType() const
78     {
79         return testStateType_;
80     }
SetTestStateType(uint32_t stateType)81     void SetTestStateType(uint32_t stateType)
82     {
83         testStateType_ = stateType;
84     }
GetTestEventType()85     int32_t GetTestEventType() const
86     {
87         return testEventType_;
88     }
SetTestEventType(int32_t testEventType)89     void SetTestEventType(int32_t testEventType)
90     {
91         testEventType_ = testEventType;
92     }
GetTestWindowChangeTypes()93     int32_t GetTestWindowChangeTypes() const
94     {
95         return testWindowChangeTypes_;
96     }
SetTestWindowChangeTypes(int32_t testWindowChangeTypes)97     void SetTestWindowChangeTypes(int32_t testWindowChangeTypes)
98     {
99         testWindowChangeTypes_ = testWindowChangeTypes;
100     }
GetTestChannalId()101     int32_t GetTestChannalId() const
102     {
103         return testChannalId_;
104     }
SetTestChannalId(int32_t testChannalId)105     void SetTestChannalId(int32_t testChannalId)
106     {
107         testChannalId_ = testChannalId;
108     }
GetTestKeyPressEvent()109     int32_t GetTestKeyPressEvent() const
110     {
111         return testKeyPressEvent_;
112     }
SetTestKeyPressEvent(int32_t testKeyPressEvent)113     void SetTestKeyPressEvent(int32_t testKeyPressEvent)
114     {
115         testKeyPressEvent_ = testKeyPressEvent;
116     }
GetTestDisplayId()117     int32_t GetTestDisplayId() const
118     {
119         return testDisplayId_;
120     }
SetTestDisplayId(int32_t testDisplayId)121     void SetTestDisplayId(int32_t testDisplayId)
122     {
123         testDisplayId_ = testDisplayId;
124     }
GetTestGesture()125     int32_t GetTestGesture() const
126     {
127         return testGesture_;
128     }
SetTestGesture(int32_t testGesture)129     void SetTestGesture(int32_t testGesture)
130     {
131         testGesture_ = testGesture;
132     }
GetTestGestureSimulateResult()133     int32_t GetTestGestureSimulateResult() const
134     {
135         return testGestureSimulateResult_;
136     }
SetTestGestureSimulateResult(int32_t testGestureSimulateResult)137     void SetTestGestureSimulateResult(int32_t testGestureSimulateResult)
138     {
139         testGestureSimulateResult_ = testGestureSimulateResult;
140     }
141 public:
142     static const int32_t accountId_ = 100;
143 
144 private:
145     OHOS::sptr<OHOS::Accessibility::IAccessibleAbilityChannel> testStub_ = nullptr;
146     std::vector<EventType> mTeventType_ = {};
147     int32_t mTgestureId_ = 0;
148     uint32_t testStateType_ = 0;
149     int32_t testEventType_ = 0;
150     int32_t testWindowChangeTypes_ = 0;
151     int32_t testWindowId_ = 0;
152     int32_t testChannalId_ = -1;
153     int32_t testGesture_ = -1;
154     int32_t testKeyPressEvent_ = -1;
155     int32_t testDisplayId_ = -1;
156     int32_t testGestureSimulateResult_ = -1;
157     std::mutex mtx_;
158 };
159 } // namespace Accessibility
160 } // namespace OHOS
161 #endif // ACCESSIBILITY_MT_HELPER_H