1/* 2 * Copyright (c) 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#ifndef TEST_WUKONG_EVENT_MONITOR_H 16#define TEST_WUKONG_EVENT_MONITOR_H 17 18#include "accessibility_ui_test_ability.h" 19 20namespace OHOS { 21namespace WuKong { 22class EventMonitor final : public Accessibility::AccessibleAbilityListener { 23public: 24 virtual ~EventMonitor() = default; 25 26 void OnAbilityConnected() override; 27 28 void OnAbilityDisconnected() override; 29 30 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo &eventInfo) override; 31 32 void SetOnAbilityConnectCallback(std::function<void()> onConnectCb); 33 34 void SetOnAbilityDisConnectCallback(std::function<void()> onDisConnectCb); 35 36 bool OnKeyPressEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent) override 37 { 38 return false; 39 } 40 41 uint64_t GetLastEventMillis(); 42 43 bool WaitEventIdle(uint32_t idleThresholdMs, uint32_t timeoutMs); 44 45private: 46 std::function<void()> onConnectCallback_ = nullptr; 47 std::function<void()> onDisConnectCallback_ = nullptr; 48 std::atomic<uint64_t> lastEventMillis_ = 0; 49}; 50} // namespace WuKong 51} // namespace OHOS 52#endif 53