1/*
2 * Copyright (c) 2021-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
16#include "window_manager_agent_controller.h"
17#include "window_manager_hilog.h"
18#include "wm_common.h"
19
20namespace OHOS {
21namespace Rosen {
22namespace {
23constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerAgentController"};
24}
25WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerAgentController)
26
27WMError WindowManagerAgentController::RegisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
28    WindowManagerAgentType type)
29{
30    return wmAgentContainer_.RegisterAgent(windowManagerAgent, type) ? WMError::WM_OK : WMError::WM_ERROR_NULLPTR;
31}
32
33WMError WindowManagerAgentController::UnregisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
34    WindowManagerAgentType type)
35{
36    return wmAgentContainer_.UnregisterAgent(windowManagerAgent, type) ? WMError::WM_OK : WMError::WM_ERROR_NULLPTR;
37}
38
39void WindowManagerAgentController::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused)
40{
41    for (auto& agent : wmAgentContainer_.GetAgentsByType(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) {
42        agent->UpdateFocusChangeInfo(focusChangeInfo, focused);
43    }
44}
45
46void WindowManagerAgentController::UpdateWindowModeTypeInfo(WindowModeType type)
47{
48    for (auto& agent : wmAgentContainer_.GetAgentsByType(
49        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE)) {
50        agent->UpdateWindowModeTypeInfo(type);
51    }
52}
53
54void WindowManagerAgentController::UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints)
55{
56    WLOGFD("tints size: %{public}u", static_cast<uint32_t>(tints.size()));
57    if (tints.empty()) {
58        return;
59    }
60    for (auto& agent : wmAgentContainer_.GetAgentsByType(
61        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) {
62        agent->UpdateSystemBarRegionTints(displayId, tints);
63    }
64}
65
66void WindowManagerAgentController::NotifyAccessibilityWindowInfo(
67    const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type)
68{
69    WLOGD("NotifyAccessibilityWindowInfo");
70    for (auto& agent : wmAgentContainer_.GetAgentsByType(
71        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE)) {
72        agent->NotifyAccessibilityWindowInfo(infos, type);
73    }
74}
75
76void WindowManagerAgentController::UpdateWindowVisibilityInfo(
77    const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
78{
79    WLOGFD("Size:%{public}zu", windowVisibilityInfos.size());
80    for (auto& agent : wmAgentContainer_.GetAgentsByType(
81        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY)) {
82        agent->UpdateWindowVisibilityInfo(windowVisibilityInfos);
83    }
84}
85
86void WindowManagerAgentController::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
87{
88    for (auto& agent : wmAgentContainer_.GetAgentsByType(
89        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT)) {
90        agent->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
91    }
92}
93
94void WindowManagerAgentController::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
95{
96    WLOGFD("NotifyWaterMarkFlagChanged with result:%{public}d", showWaterMark);
97    for (auto& agent : wmAgentContainer_.GetAgentsByType(
98        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG)) {
99        agent->NotifyWaterMarkFlagChangedResult(showWaterMark);
100    }
101}
102
103void WindowManagerAgentController::NotifyGestureNavigationEnabledResult(bool enable)
104{
105    WLOGFD("NotifyGestureNavigationEnabledResult with result:%{public}d", enable);
106    for (auto& agent : wmAgentContainer_.GetAgentsByType(
107        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED)) {
108        agent->NotifyGestureNavigationEnabledResult(enable);
109    }
110}
111
112void WindowManagerAgentController::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground)
113{
114    TLOGD(WmsLogTag::WMS_PIP, "bundleName:%{public}s, state:%{public}d", bundleName.c_str(), isForeground);
115    for (auto& agent : wmAgentContainer_.GetAgentsByType(
116        WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP)) {
117        agent->UpdatePiPWindowStateChanged(bundleName, isForeground);
118    }
119}
120} // namespace Rosen
121} // namespace OHOS