1 /*
2 * Copyright (C) 2025 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 "window_adapter.h"
17
18 #include "global.h"
19 #include "window.h"
20 #include "wm_common.h"
21
22 namespace OHOS {
23 namespace MiscServices {
24 using namespace OHOS::Rosen;
25 using WMError = OHOS::Rosen::WMError;
26
~WindowAdapter()27 WindowAdapter::~WindowAdapter()
28 {
29 }
30
GetInstance()31 WindowAdapter &WindowAdapter::GetInstance()
32 {
33 static WindowAdapter windowAdapter;
34 return windowAdapter;
35 }
36
GetFocusInfo(FocusChangeInfo & focusInfo)37 void WindowAdapter::GetFocusInfo(FocusChangeInfo &focusInfo)
38 {
39 #ifdef SCENE_BOARD_ENABLE
40 WindowManagerLite::GetInstance().GetFocusWindowInfo(focusInfo);
41 #else
42 WindowManager::GetInstance().GetFocusWindowInfo(focusInfo);
43 #endif
44 }
45
GetCallingWindowInfo(const uint32_t windId,const int32_t userId,CallingWindowInfo & callingWindowInfo)46 bool WindowAdapter::GetCallingWindowInfo(
47 const uint32_t windId, const int32_t userId, CallingWindowInfo &callingWindowInfo)
48 {
49 #ifdef SCENE_BOARD_ENABLE
50 IMSA_HILOGD("[%{public}d,%{public}d] run in.", userId, windId);
51 callingWindowInfo.windowId_ = static_cast<int32_t>(windId);
52 callingWindowInfo.userId_ = userId;
53 auto wmErr = WindowManagerLite::GetInstance().GetCallingWindowInfo(callingWindowInfo);
54 if (wmErr != WMError::WM_OK) {
55 IMSA_HILOGE("[%{public}d,%{public}d,%{public}d] failed to get calling window info.", userId, windId, wmErr);
56 return false;
57 }
58 IMSA_HILOGD("callingWindowInfo:%{public}s",
59 WindowDisplayChangeListener::CallingWindowInfoToString(callingWindowInfo).c_str());
60 return true;
61 #else
62 IMSA_HILOGE("capability not supported");
63 return false;
64 #endif
65 }
66
RegisterCallingWindowInfoChangedListener(const WindowDisplayChangeHandler & handle)67 void WindowAdapter::RegisterCallingWindowInfoChangedListener(const WindowDisplayChangeHandler &handle)
68 {
69 #ifdef SCENE_BOARD_ENABLE
70 sptr<WindowDisplayChangeListener> listener = new (std::nothrow) WindowDisplayChangeListener(handle);
71 if (listener == nullptr) {
72 IMSA_HILOGE("failed to create listener");
73 return;
74 }
75 auto wmErr = WMError::WM_OK;
76 wmErr = WindowManagerLite::GetInstance().RegisterCallingWindowDisplayChangedListener(listener);
77 IMSA_HILOGI("register focus changed listener ret: %{public}d", wmErr);
78 #endif
79 }
80 } // namespace MiscServices
81 } // namespace OHOS
82