1 /*
2  * Copyright (c) 2023 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 #include "focus_monitor_manager.h"
17 
18 #include "focus_change_listener.h"
19 #include "global.h"
20 #ifdef SCENE_BOARD_ENABLE
21 #include "window_manager_lite.h"
22 #else
23 #include "window_manager.h"
24 #endif
25 
26 namespace OHOS {
27 namespace MiscServices {
28 using namespace Rosen;
GetInstance()29 FocusMonitorManager &FocusMonitorManager::GetInstance()
30 {
31     static FocusMonitorManager focusMonitorManager;
32     return focusMonitorManager;
33 }
34 
RegisterFocusChangedListener(const FocusHandle & handle)35 void FocusMonitorManager::RegisterFocusChangedListener(const FocusHandle &handle)
36 {
37     sptr<IFocusChangedListener> listener = new (std::nothrow) FocusChangedListener(handle);
38     if (listener == nullptr) {
39         IMSA_HILOGE("failed to create listener");
40         return;
41     }
42 #ifdef SCENE_BOARD_ENABLE
43     WMError ret = WindowManagerLite::GetInstance().RegisterFocusChangedListener(listener);
44 #else
45     WMError ret = WindowManager::GetInstance().RegisterFocusChangedListener(listener);
46 #endif
47     IMSA_HILOGI("register focus changed listener ret: %{public}d", ret);
48 }
49 } // namespace MiscServices
50 } // namespace OHOS