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