1a69a01cdSopenharmony_ci/*
2a69a01cdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a69a01cdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a69a01cdSopenharmony_ci * you may not use this file except in compliance with the License.
5a69a01cdSopenharmony_ci * You may obtain a copy of the License at
6a69a01cdSopenharmony_ci *
7a69a01cdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a69a01cdSopenharmony_ci *
9a69a01cdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a69a01cdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a69a01cdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a69a01cdSopenharmony_ci * See the License for the specific language governing permissions and
13a69a01cdSopenharmony_ci * limitations under the License.
14a69a01cdSopenharmony_ci */
15a69a01cdSopenharmony_ci#ifndef TEST_WUKONG_EVENT_MONITOR_H
16a69a01cdSopenharmony_ci#define TEST_WUKONG_EVENT_MONITOR_H
17a69a01cdSopenharmony_ci
18a69a01cdSopenharmony_ci#include "accessibility_ui_test_ability.h"
19a69a01cdSopenharmony_ci
20a69a01cdSopenharmony_cinamespace OHOS {
21a69a01cdSopenharmony_cinamespace WuKong {
22a69a01cdSopenharmony_ciclass EventMonitor final : public Accessibility::AccessibleAbilityListener {
23a69a01cdSopenharmony_cipublic:
24a69a01cdSopenharmony_ci    virtual ~EventMonitor() = default;
25a69a01cdSopenharmony_ci
26a69a01cdSopenharmony_ci    void OnAbilityConnected() override;
27a69a01cdSopenharmony_ci
28a69a01cdSopenharmony_ci    void OnAbilityDisconnected() override;
29a69a01cdSopenharmony_ci
30a69a01cdSopenharmony_ci    void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo &eventInfo) override;
31a69a01cdSopenharmony_ci
32a69a01cdSopenharmony_ci    void SetOnAbilityConnectCallback(std::function<void()> onConnectCb);
33a69a01cdSopenharmony_ci
34a69a01cdSopenharmony_ci    void SetOnAbilityDisConnectCallback(std::function<void()> onDisConnectCb);
35a69a01cdSopenharmony_ci
36a69a01cdSopenharmony_ci    bool OnKeyPressEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent) override
37a69a01cdSopenharmony_ci    {
38a69a01cdSopenharmony_ci        return false;
39a69a01cdSopenharmony_ci    }
40a69a01cdSopenharmony_ci
41a69a01cdSopenharmony_ci    uint64_t GetLastEventMillis();
42a69a01cdSopenharmony_ci
43a69a01cdSopenharmony_ci    bool WaitEventIdle(uint32_t idleThresholdMs, uint32_t timeoutMs);
44a69a01cdSopenharmony_ci
45a69a01cdSopenharmony_ciprivate:
46a69a01cdSopenharmony_ci    std::function<void()> onConnectCallback_ = nullptr;
47a69a01cdSopenharmony_ci    std::function<void()> onDisConnectCallback_ = nullptr;
48a69a01cdSopenharmony_ci    std::atomic<uint64_t> lastEventMillis_ = 0;
49a69a01cdSopenharmony_ci};
50a69a01cdSopenharmony_ci}  // namespace WuKong
51a69a01cdSopenharmony_ci}  // namespace OHOS
52a69a01cdSopenharmony_ci#endif
53