1 /*
2  * Copyright (c) 2024 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 HIVIEW_EVENT_FOCUS_LISTENER_H
16 #define HIVIEW_EVENT_FOCUS_LISTENER_H
17 #ifdef WINDOW_MANAGER_ENABLE
18 
19 #include <mutex>
20 
21 #include "focus_change_info.h"
22 #include "window_manager.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 class EventFocusListener : public Rosen::IFocusChangedListener {
27 public:
28     enum REGISTER_STATE {
29         UNREGISTERED,
30         REGISTERING,
31         REGISTERED
32     };
33 
34     static REGISTER_STATE registerState_;
35     static uint64_t lastChangedTime_;
36 
EventFocusListener()37     explicit EventFocusListener(){};
38     ~EventFocusListener() = default;
39     static sptr<EventFocusListener> GetInstance();
40     static void RegisterFocusListener();
41     static void UnRegisterFocusListener();
42 
43     void OnFocused(const sptr<Rosen::FocusChangeInfo>& focusChangeInfo) override;
44     void OnUnfocused(const sptr<Rosen::FocusChangeInfo>& focusChangeInfo) override;
45 
46 private:
47     static sptr<EventFocusListener> instance_;
48     static std::recursive_mutex mutex_;
49 };
50 } // namespace HiviewDFX
51 } // namespace OHOS
52 #endif // WINDOW_MANAGER_ENABLE
53 #endif // HIVIEW_EVENT_FOCUS_LISTENER_H