• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "session_manager_agent_controller.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace {
21 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionManagerAgentController"};
22 }
WM_IMPLEMENT_SINGLE_INSTANCE(SessionManagerAgentController)23 WM_IMPLEMENT_SINGLE_INSTANCE(SessionManagerAgentController)
24 
25 WMError SessionManagerAgentController::RegisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
26     WindowManagerAgentType type, int32_t pid)
27 {
28     TLOGI(WmsLogTag::WMS_SYSTEM, "type: %{public}u", static_cast<uint32_t>(type));
29     if (smAgentContainer_.RegisterAgent(windowManagerAgent, type)) {
30         std::lock_guard<std::mutex> lock(windowManagerAgentPidMapMutex_);
31         auto it = windowManagerPidAgentMap_.find(pid);
32         if (it != windowManagerPidAgentMap_.end()) {
33             auto& typeAgentMap = it->second;
34             auto typeAgentIter = typeAgentMap.find(type);
35             if (typeAgentIter != typeAgentMap.end()) {
36                 smAgentContainer_.UnregisterAgent(typeAgentIter->second, type);
37                 windowManagerAgentPairMap_.erase((typeAgentIter->second)->AsObject());
38             }
39             typeAgentMap.insert(std::map<WindowManagerAgentType,
40                 sptr<IWindowManagerAgent>>::value_type(type, windowManagerAgent));
41         } else {
42             std::map<WindowManagerAgentType, sptr<IWindowManagerAgent>> typeAgentMap;
43             typeAgentMap.insert(std::map<WindowManagerAgentType,
44                 sptr<IWindowManagerAgent>>::value_type(type, windowManagerAgent));
45             TLOGI(WmsLogTag::WMS_MAIN, "insert pid: %{public}d, type: %{public}u",
46                 pid, static_cast<uint32_t>(type));
47             windowManagerPidAgentMap_.insert(std::map<int32_t,
48                 std::map<WindowManagerAgentType, sptr<IWindowManagerAgent>>>::value_type(pid, typeAgentMap));
49         }
50         std::pair<int32_t, WindowManagerAgentType> pidPair = {pid, type};
51         windowManagerAgentPairMap_.insert(std::map<sptr<IRemoteObject>,
52             std::pair<int32_t, WindowManagerAgentType>>::value_type(windowManagerAgent->AsObject(), pidPair));
53         return WMError::WM_OK;
54     } else {
55         return WMError::WM_ERROR_NULLPTR;
56     }
57 }
58 
UnregisterWindowManagerAgent(const sptr<IWindowManagerAgent> & windowManagerAgent,WindowManagerAgentType type,int32_t pid)59 WMError SessionManagerAgentController::UnregisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
60     WindowManagerAgentType type, int32_t pid)
61 {
62     TLOGI(WmsLogTag::WMS_SYSTEM, "type: %{public}u", static_cast<uint32_t>(type));
63     if (smAgentContainer_.UnregisterAgent(windowManagerAgent, type)) {
64         std::lock_guard<std::mutex> lock(windowManagerAgentPidMapMutex_);
65         auto it = windowManagerPidAgentMap_.find(pid);
66         if (it != windowManagerPidAgentMap_.end()) {
67             auto& typeAgentMap = it->second;
68             auto typeAgentIter = typeAgentMap.find(type);
69             if (typeAgentIter != typeAgentMap.end()) {
70                 windowManagerAgentPairMap_.erase((typeAgentIter->second)->AsObject());
71                 typeAgentMap.erase(type);
72                 if (typeAgentMap.empty()) {
73                     TLOGI(WmsLogTag::WMS_MAIN, "erase pid: %{public}d, type: %{public}u",
74                         pid, static_cast<uint32_t>(type));
75                     windowManagerPidAgentMap_.erase(pid);
76                 }
77             }
78         }
79         return WMError::WM_OK;
80     } else {
81         return WMError::WM_ERROR_NULLPTR;
82     }
83 }
84 
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)85 void SessionManagerAgentController::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
86 {
87     for (auto& agent : smAgentContainer_.GetAgentsByType(
88         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT)) {
89         if (agent != nullptr) {
90             agent->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
91         }
92     }
93 }
94 
UpdateFocusChangeInfo(const sptr<FocusChangeInfo> & focusChangeInfo,bool isFocused)95 void SessionManagerAgentController::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool isFocused)
96 {
97     TLOGD(WmsLogTag::WMS_FOCUS, "in");
98     for (auto& agent : smAgentContainer_.GetAgentsByType(
99         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) {
100         if (agent != nullptr) {
101             agent->UpdateFocusChangeInfo(focusChangeInfo, isFocused);
102         } else {
103             TLOGW(WmsLogTag::WMS_FOCUS, "agent is invalid");
104         }
105     }
106 }
107 
UpdateWindowModeTypeInfo(WindowModeType type)108 void SessionManagerAgentController::UpdateWindowModeTypeInfo(WindowModeType type)
109 {
110     TLOGD(WmsLogTag::WMS_MAIN, "SessionManagerAgentController UpdateWindowModeTypeInfo type: %{public}d",
111         static_cast<uint8_t>(type));
112     for (auto& agent : smAgentContainer_.GetAgentsByType(
113         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE)) {
114         if (agent != nullptr) {
115             agent->UpdateWindowModeTypeInfo(type);
116         }
117     }
118 }
119 
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)120 void SessionManagerAgentController::NotifyAccessibilityWindowInfo(
121     const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type)
122 {
123     for (auto& agent : smAgentContainer_.GetAgentsByType(
124         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE)) {
125         if (agent != nullptr) {
126             agent->NotifyAccessibilityWindowInfo(infos, type);
127         }
128     }
129 }
130 
NotifyWaterMarkFlagChangedResult(bool hasWaterMark)131 void SessionManagerAgentController::NotifyWaterMarkFlagChangedResult(bool hasWaterMark)
132 {
133     WLOGFD("NotifyWaterMarkFlagChanged with result:%{public}u", static_cast<uint32_t>(hasWaterMark));
134     for (auto& agent : smAgentContainer_.GetAgentsByType(
135         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG)) {
136         if (agent != nullptr) {
137             agent->NotifyWaterMarkFlagChangedResult(hasWaterMark);
138         }
139     }
140 }
141 
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos)142 void SessionManagerAgentController::UpdateWindowVisibilityInfo(
143     const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
144 {
145     for (auto& agent : smAgentContainer_.GetAgentsByType(
146         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY)) {
147         agent->UpdateWindowVisibilityInfo(windowVisibilityInfos);
148     }
149 }
150 
UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)151 void SessionManagerAgentController::UpdateVisibleWindowNum(
152     const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
153 {
154     for (const auto& num : visibleWindowNumInfo) {
155         TLOGI(WmsLogTag::WMS_MAIN, "displayId=%{public}d, visibleWindowNum=%{public}d",
156             num.displayId, num.visibleWindowNum);
157     }
158     for (auto& agent : smAgentContainer_.GetAgentsByType(
159         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM)) {
160         if (agent != nullptr) {
161             agent->UpdateVisibleWindowNum(visibleWindowNumInfo);
162         }
163     }
164 }
165 
UpdateWindowDrawingContentInfo(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos)166 void SessionManagerAgentController::UpdateWindowDrawingContentInfo(
167     const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos)
168 {
169     WLOGFD("Size:%{public}zu", windowDrawingContentInfos.size());
170     for (auto& agent : smAgentContainer_.GetAgentsByType(
171         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE)) {
172         agent->UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
173     }
174 }
175 
UpdateCameraWindowStatus(uint32_t accessTokenId,bool isShowing)176 void SessionManagerAgentController::UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing)
177 {
178     TLOGI(WmsLogTag::WMS_SYSTEM, "accessTokenId:%{private}u, isShowing:%{public}d", accessTokenId,
179         static_cast<int>(isShowing));
180     for (auto &agent: smAgentContainer_.GetAgentsByType(
181         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW)) {
182         if (agent != nullptr) {
183             agent->UpdateCameraWindowStatus(accessTokenId, isShowing);
184         }
185     }
186 }
187 
DoAfterAgentDeath(const sptr<IRemoteObject> & remoteObject)188 void SessionManagerAgentController::DoAfterAgentDeath(const sptr<IRemoteObject>& remoteObject)
189 {
190     std::lock_guard<std::mutex> lock(windowManagerAgentPidMapMutex_);
191     auto it = windowManagerAgentPairMap_.find(remoteObject);
192     if (it != windowManagerAgentPairMap_.end()) {
193         auto [pid, type] = it->second;
194         auto pidIter = windowManagerPidAgentMap_.find(pid);
195         if (pidIter != windowManagerPidAgentMap_.end()) {
196             auto& typeAgentMap = pidIter->second;
197             TLOGI(WmsLogTag::WMS_MAIN, "type: %{public}u", static_cast<uint32_t>(type));
198             typeAgentMap.erase(type);
199             if (typeAgentMap.empty()) {
200                 TLOGI(WmsLogTag::WMS_MAIN, "pid: %{public}d", pid);
201                 windowManagerPidAgentMap_.erase(pid);
202             }
203         }
204         windowManagerAgentPairMap_.erase(remoteObject);
205     }
206 }
207 
NotifyGestureNavigationEnabledResult(bool enable)208 void SessionManagerAgentController::NotifyGestureNavigationEnabledResult(bool enable)
209 {
210     WLOGFD("result:%{public}d", enable);
211     for (auto& agent : smAgentContainer_.GetAgentsByType(
212         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED)) {
213         if (agent != nullptr) {
214             agent->NotifyGestureNavigationEnabledResult(enable);
215         }
216     }
217 }
218 
NotifyWindowStyleChange(WindowStyleType type)219 void SessionManagerAgentController::NotifyWindowStyleChange(WindowStyleType type)
220 {
221     TLOGD(WmsLogTag::WMS_MAIN, "windowStyletype: %{public}d",
222           static_cast<uint8_t>(type));
223     for (auto& agent : smAgentContainer_.GetAgentsByType(
224         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE)) {
225         if (agent != nullptr) {
226             agent->NotifyWindowStyleChange(type);
227         }
228     }
229 }
230 
NotifyCallingWindowDisplayChanged(const CallingWindowInfo & callingWindowInfo)231 void SessionManagerAgentController::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo)
232 {
233     TLOGD(WmsLogTag::WMS_KEYBOARD, "notify persistentId: %{public}d, pid: %{public}d, "
234         "displayId: %{public}d, userId: %{public}d", callingWindowInfo.windowId_,
235         callingWindowInfo.callingPid_, static_cast<int32_t>(callingWindowInfo.displayId_), callingWindowInfo.userId_);
236     for (const auto& agent : smAgentContainer_.GetAgentsByType(
237         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY)) {
238         if (agent != nullptr) {
239             agent->NotifyCallingWindowDisplayChanged(callingWindowInfo);
240         } else {
241             TLOGE(WmsLogTag::WMS_KEYBOARD, "agent is nullptr, userId: %{public}d, displayId: %{public}d, "
242                 "persistentId: %{public}d", callingWindowInfo.userId_,
243                 static_cast<int32_t>(callingWindowInfo.displayId_), callingWindowInfo.windowId_);
244         }
245     }
246 }
247 
NotifyWindowPidVisibilityChanged(const sptr<WindowPidVisibilityInfo> & info)248 void SessionManagerAgentController::NotifyWindowPidVisibilityChanged(
249     const sptr<WindowPidVisibilityInfo>& info)
250 {
251     for (auto& agent : smAgentContainer_.GetAgentsByType(
252         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY)) {
253         if (agent != nullptr) {
254             agent->NotifyWindowPidVisibilityChanged(info);
255         }
256     }
257 }
258 
UpdatePiPWindowStateChanged(const std::string & bundleName,bool isForeground)259 void SessionManagerAgentController::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground)
260 {
261     for (auto& agent : smAgentContainer_.GetAgentsByType(
262         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP)) {
263         if (agent != nullptr) {
264             agent->UpdatePiPWindowStateChanged(bundleName, isForeground);
265         }
266     }
267 }
268 } // namespace Rosen
269 } // namespace OHOS