1 /*
2 * Copyright (c) 2021-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 "window_controller.h"
17 #include <ability_manager_client.h>
18 #include <chrono>
19 #include <cstdint>
20 #include <hisysevent.h>
21 #include <hitrace_meter.h>
22 #include <parameters.h>
23 #include <rs_window_animation_finished_callback.h>
24 #include <transaction/rs_transaction.h>
25 #include <transaction/rs_sync_transaction_controller.h>
26 #include <sstream>
27
28 #ifdef POWER_MANAGER_ENABLE
29 #include <power_mgr_client.h>
30 #endif
31
32 #include "display_group_info.h"
33 #include "display_manager_service_inner.h"
34 #include "minimize_app.h"
35 #include "persistent_storage.h"
36 #include "surface_capture_future.h"
37 #include "remote_animation.h"
38 #include "rs_adapter.h"
39 #include "starting_window.h"
40 #include "window_inner_manager.h"
41 #include "window_manager_hilog.h"
42 #include "window_helper.h"
43 #include "window_system_effect.h"
44 #include "wm_common.h"
45 #include "wm_math.h"
46 #include "permission.h"
47
48 namespace OHOS {
49 namespace Rosen {
50 namespace {
51 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Controller"};
52 constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 50;
53 constexpr float MASKING_SURFACE_NODE_Z_ORDER = 9999;
54 }
55
GenWindowId()56 uint32_t WindowController::GenWindowId()
57 {
58 return ++windowId_;
59 }
60
StartingWindow(sptr<WindowTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bkgColor,bool isColdStart)61 void WindowController::StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
62 uint32_t bkgColor, bool isColdStart)
63 {
64 if (!info || info->GetAbilityToken() == nullptr) {
65 TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "info or AbilityToken is nullptr!");
66 return;
67 }
68 StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::STARTING_WINDOW),
69 "wms:async:ShowStartingWindow");
70 auto node = windowRoot_->FindWindowNodeWithToken(info->GetAbilityToken());
71 if (node == nullptr) {
72 if (!isColdStart) {
73 TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "no windowNode exists but is hot start!");
74 return;
75 }
76 node = StartingWindow::CreateWindowNode(info, GenWindowId());
77 if (node == nullptr) {
78 return;
79 }
80 if (windowRoot_->SaveWindow(node) != WMError::WM_OK) {
81 return;
82 }
83 if (!RemoteAnimation::CheckAnimationController()) {
84 UpdateWindowAnimation(node);
85 }
86 } else {
87 if (node->stateMachine_.IsWindowNodeShownOrShowing()) {
88 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "WindowId: %{public}u state: %{public}u!",
89 node->GetWindowId(), static_cast<uint32_t>(node->stateMachine_.GetCurrentState()));
90 return;
91 }
92 if (WindowHelper::IsValidWindowMode(info->GetWindowMode()) &&
93 (node->GetWindowMode() != info->GetWindowMode())) {
94 TLOGI(WmsLogTag::WMS_STARTUP_PAGE,
95 "set starting window mode. starting mode is: %{public}u, window mode is: %{public}u.",
96 node->GetWindowMode(), info->GetWindowMode());
97 node->SetWindowMode(info->GetWindowMode());
98 }
99 }
100
101 if (!WindowHelper::CheckSupportWindowMode(node->GetWindowMode(), node->GetWindowModeSupportType(), info)) {
102 TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "need to cancel starting window");
103 return;
104 }
105
106 if (windowRoot_->AddWindowNode(0, node, true) != WMError::WM_OK) {
107 return;
108 }
109 StartingWindow::DrawStartingWindow(node, pixelMap, bkgColor, isColdStart);
110 FlushWindowInfo(node->GetWindowId());
111 node->startingWindowShown_ = true;
112 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "Show success, id:%{public}u!", node->GetWindowId());
113 }
114
CancelStartingWindow(sptr<IRemoteObject> abilityToken)115 void WindowController::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
116 {
117 auto node = windowRoot_->FindWindowNodeWithToken(abilityToken);
118 if (node == nullptr) {
119 TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "Node is nullptr");
120 return;
121 }
122 if (!node->startingWindowShown_) {
123 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "failed because client window has shown id:%{public}u",
124 node->GetWindowId());
125 return;
126 }
127 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CancelStartingWindow(%u)", node->GetWindowId());
128 FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::STARTING_WINDOW),
129 "wms:async:ShowStartingWindow");
130 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "Id:%{public}u!", node->GetWindowId());
131 node->isAppCrash_ = true;
132 WMError res = DestroyWindow(node->GetWindowId(), false);
133 if (res != WMError::WM_OK) {
134 TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "DestroyWindow failed!");
135 }
136 }
137
NotifyWindowTransition(sptr<WindowTransitionInfo> & srcInfo,sptr<WindowTransitionInfo> & dstInfo)138 WMError WindowController::NotifyWindowTransition(sptr<WindowTransitionInfo>& srcInfo,
139 sptr<WindowTransitionInfo>& dstInfo)
140 {
141 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "begin!");
142 sptr<WindowNode> dstNode = nullptr;
143 sptr<WindowNode> srcNode = nullptr;
144 if (srcInfo) {
145 srcNode = windowRoot_->FindWindowNodeWithToken(srcInfo->GetAbilityToken());
146 }
147 if (dstInfo) {
148 dstNode = windowRoot_->FindWindowNodeWithToken(dstInfo->GetAbilityToken());
149 }
150 if (!RemoteAnimation::CheckTransition(srcInfo, srcNode, dstInfo, dstNode)) {
151 return WMError::WM_ERROR_NO_REMOTE_ANIMATION;
152 }
153 StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::REMOTE_ANIMATION),
154 "wms:async:ShowRemoteAnimation");
155 auto transitionEvent = RemoteAnimation::GetTransitionEvent(srcInfo, dstInfo, srcNode, dstNode);
156 switch (transitionEvent) {
157 case TransitionEvent::APP_TRANSITION: {
158 return RemoteAnimation::NotifyAnimationTransition(srcInfo, dstInfo, srcNode, dstNode);
159 }
160 case TransitionEvent::MINIMIZE:
161 return RemoteAnimation::NotifyAnimationMinimize(srcInfo, srcNode);
162 case TransitionEvent::CLOSE:
163 case TransitionEvent::CLOSE_BUTTON:
164 return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, transitionEvent);
165 case TransitionEvent::BACK_TRANSITION:
166 case TransitionEvent::BACKGROUND_TRANSITION:
167 return RemoteAnimation::NotifyAnimationBackTransition(srcInfo, dstInfo, srcNode, dstNode, transitionEvent);
168 default:
169 return WMError::WM_ERROR_NO_REMOTE_ANIMATION;
170 }
171 return WMError::WM_OK;
172 }
173
GetFocusWindowNode(DisplayId displayId,sptr<WindowNode> & windowNode)174 WMError WindowController::GetFocusWindowNode(DisplayId displayId, sptr<WindowNode>& windowNode)
175 {
176 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
177 if (windowNodeContainer == nullptr) {
178 WLOGFE("Container is null, displayId: %{public}" PRIu64"", displayId);
179 return WMError::WM_ERROR_NULLPTR;
180 }
181 uint32_t focusWindowId = windowNodeContainer->GetFocusWindow();
182 WLOGFD("Now focusId: %{public}u", focusWindowId);
183 auto thisWindowNode = windowRoot_->GetWindowNode(focusWindowId);
184 if (thisWindowNode == nullptr || !thisWindowNode->currentVisibility_) {
185 WLOGFE("Node is null or invisible, id: %{public}u", focusWindowId);
186 return WMError::WM_ERROR_INVALID_WINDOW;
187 }
188 windowNode = thisWindowNode;
189 return WMError::WM_OK;
190 }
191
GetFocusWindowInfo(sptr<IRemoteObject> & abilityToken)192 WMError WindowController::GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken)
193 {
194 DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
195 sptr<WindowNode> windowNode;
196 WMError res = GetFocusWindowNode(displayId, windowNode);
197 if (res == WMError::WM_OK) {
198 abilityToken = windowNode->abilityToken_;
199 }
200 return res;
201 }
202
GetFocusWindowInfo(FocusChangeInfo & focusInfo)203 WMError WindowController::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
204 {
205 DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
206 sptr<WindowNode> windowNode;
207 WMError res = GetFocusWindowNode(displayId, windowNode);
208 if (res == WMError::WM_OK) {
209 WLOGFD("Get focus window info success");
210 focusInfo.windowId_ = static_cast<int32_t>(windowNode->GetWindowId());
211 focusInfo.displayId_ = windowNode->GetDisplayId();
212 focusInfo.pid_ = windowNode->GetCallingPid();
213 focusInfo.uid_ = windowNode->GetCallingUid();
214 focusInfo.windowType_ = windowNode->GetWindowType();
215 focusInfo.abilityToken_ = windowNode->abilityToken_;
216 }
217 return res;
218 }
219
CheckParentWindowValid(const sptr<WindowProperty> & property)220 bool WindowController::CheckParentWindowValid(const sptr<WindowProperty>& property)
221 {
222 if (WindowHelper::IsSubWindow(property->GetWindowType())) {
223 if (property->GetParentId() == INVALID_WINDOW_ID) {
224 WLOGFE("failed, sub window parent type is invalid");
225 return false;
226 }
227 sptr<WindowNode> parentWindow = windowRoot_->GetWindowNode(property->GetParentId());
228 if (parentWindow == nullptr) {
229 WLOGFE("failed, sub window parent type is error");
230 return false;
231 }
232 } else if (WindowHelper::IsSystemSubWindow(property->GetWindowType())) {
233 if (property->GetParentId() == INVALID_WINDOW_ID) {
234 WLOGFE("failed, sub system window parent type is invalid");
235 return false;
236 }
237 sptr<WindowNode> parentWindow = windowRoot_->GetWindowNode(property->GetParentId());
238 if (parentWindow == nullptr || !WindowHelper::IsSystemWindow(parentWindow->GetWindowType())) {
239 WLOGFE("failed, sub system window parent type is error");
240 return false;
241 }
242 } else {
243 if (property->GetParentId() != INVALID_WINDOW_ID) {
244 WLOGFE("failed, type is error");
245 return false;
246 }
247 }
248 return true;
249 }
250
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId,sptr<IRemoteObject> token,int32_t pid,int32_t uid)251 WMError WindowController::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
252 const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token,
253 int32_t pid, int32_t uid)
254 {
255 if (!CheckParentWindowValid(property)) {
256 return WMError::WM_ERROR_INVALID_PARENT;
257 }
258
259 if (!surfaceNode) {
260 return WMError::WM_ERROR_NULLPTR;
261 }
262
263 if (property->GetWindowType() != WindowType::WINDOW_TYPE_BOOT_ANIMATION) {
264 surfaceNode->SetFrameGravity(Gravity::RESIZE);
265 }
266
267 sptr<WindowNode> node = windowRoot_->FindWindowNodeWithToken(token);
268 if (node != nullptr && WindowHelper::IsMainWindow(property->GetWindowType()) && node->startingWindowShown_) {
269 StartingWindow::HandleClientWindowCreate(node, window, windowId, surfaceNode, property, pid, uid);
270 windowRoot_->AddDeathRecipient(node);
271 windowRoot_->AddSurfaceNodeIdWindowNodePair(surfaceNode->GetId(), node);
272 WLOGFD("Flags: %{public}u, API version: %{public}u", property->GetWindowFlags(),
273 node->GetWindowProperty()->GetApiCompatibleVersion());
274 if (property->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED) &&
275 node->GetWindowProperty()->GetApiCompatibleVersion() >= 9 && !property->isSystemCalling_) { // 9: API ver.
276 property->SetWindowFlags(property->GetWindowFlags() &
277 ~static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
278 }
279 property->SetApiCompatibleVersion(node->GetWindowProperty()->GetApiCompatibleVersion());
280 return WMError::WM_OK;
281 }
282
283 windowId = GenWindowId();
284 sptr<WindowProperty> windowProperty = new WindowProperty(property);
285 windowProperty->SetWindowId(windowId);
286 node = new WindowNode(windowProperty, window, surfaceNode, pid, uid);
287 node->abilityToken_ = token;
288 node->dialogTargetToken_ = token;
289 UpdateWindowAnimation(node);
290 // for system and subwindow
291 WindowSystemEffect::SetWindowEffect(node);
292 WLOGFD("createWindow id:%{public}u", windowId);
293
294 node->stateMachine_.SetWindowId(windowId);
295 node->stateMachine_.SetWindowType(property->GetWindowType());
296 return windowRoot_->SaveWindow(node);
297 }
298
NotifyAfterAddWindow(sptr<WindowNode> & node)299 void WindowController::NotifyAfterAddWindow(sptr<WindowNode>& node)
300 {
301 std::vector<sptr<WindowNode>> nodes;
302 nodes.emplace_back(node);
303 for (auto& child : node->children_) {
304 if (child->currentVisibility_) {
305 nodes.emplace_back(child);
306 }
307 }
308 for (auto& iter : nodes) {
309 if ((iter->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) &&
310 (node->abilityToken_ != iter->abilityToken_)) {
311 iter->GetWindowToken()->NotifyForeground();
312 }
313 }
314 accessibilityConnection_->NotifyAccessibilityWindowInfo(node->GetDisplayId(), nodes,
315 WindowUpdateType::WINDOW_UPDATE_ADDED);
316 }
317
AddWindowNode(sptr<WindowProperty> & property)318 WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
319 {
320 auto node = windowRoot_->GetWindowNode(property->GetWindowId());
321 if (node == nullptr) {
322 WLOGFE("could not find window");
323 return WMError::WM_ERROR_NULLPTR;
324 }
325
326 if (node->currentVisibility_ && !node->startingWindowShown_) {
327 WLOGFE("Current window is visible, windowId: %{public}u", node->GetWindowId());
328 return WMError::WM_ERROR_INVALID_OPERATION;
329 }
330
331 // using starting window rect if client rect is empty
332 if (WindowHelper::IsEmptyRect(property->GetRequestRect()) && node->startingWindowShown_) { // for tile and cascade
333 property->SetRequestRect(node->GetRequestRect());
334 property->SetWindowRect(node->GetWindowRect());
335 property->SetDecoStatus(true);
336 }
337 node->GetWindowProperty()->CopyFrom(property);
338 UpdateWindowAnimation(node);
339
340 RelayoutKeyboard(node);
341 WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node);
342 if (res != WMError::WM_OK) {
343 MinimizeApp::ClearNodesWithReason(MinimizeReason::OTHER_WINDOW);
344 return res;
345 }
346 windowRoot_->FocusFaultDetection();
347
348 FlushWindowInfo(property->GetWindowId());
349 NotifyAfterAddWindow(node);
350 HandleTurnScreenOn(node);
351
352 if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
353 sysBarWinId_[node->GetWindowType()] = node->GetWindowId();
354 }
355 if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
356 ResizeSoftInputCallingWindowIfNeed(node);
357 }
358 StopBootAnimationIfNeed(node);
359 // when hide with remote animation first and show with default animation, need transform state
360 // minimize should execute in finish callback when remote animation enabled
361 if (!node->stateMachine_.IsShowAnimationPlaying()) {
362 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
363 MinimizeApp::ExecuteMinimizeAll();
364 WLOGI("Id:%{public}u execute minimize all", node->GetWindowId());
365 }
366 node->stateMachine_.TransitionTo(WindowNodeState::SHOWN); // for normal show which not use remote animation
367 } else if (WindowHelper::IsMainWindow(node->GetWindowType())) {
368 MinimizeApp::ExecuteMinimizeTargetReasons(~MinimizeReason::OTHER_WINDOW);
369 }
370
371 return WMError::WM_OK;
372 }
373
GetNavigationBarHeight(DisplayId displayId,uint32_t & navigationBarHeight)374 bool WindowController::GetNavigationBarHeight(DisplayId displayId, uint32_t& navigationBarHeight)
375 {
376 auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
377 if (container == nullptr) {
378 WLOGFE("Node container is null");
379 return false;
380 }
381
382 bool hasFullScreenKeyGuardWindow = false;
383 WindowNodeOperationFunc func = [&navigationBarHeight, &hasFullScreenKeyGuardWindow](sptr<WindowNode> windowNode) {
384 if (!windowNode) {
385 WLOGFE("The window node is nullptr.");
386 return false;
387 }
388 if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD &&
389 windowNode->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
390 hasFullScreenKeyGuardWindow = true;
391 }
392 if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR &&
393 windowNode->GetVisibilityState() < WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
394 navigationBarHeight = windowNode->GetWindowRect().height_;
395 if (hasFullScreenKeyGuardWindow) {
396 WLOGFW("The navigation bar is overlaid by the keyguard window and is invisible");
397 navigationBarHeight = 0;
398 }
399 return true;
400 }
401 return false;
402 };
403 container->TraverseWindowTree(func, true); // FromTopToBottom
404
405 return true;
406 }
407
RelayoutKeyboard(const sptr<WindowNode> & node)408 void WindowController::RelayoutKeyboard(const sptr<WindowNode>& node)
409 {
410 if (node == nullptr) {
411 WLOGFE("Node is nullptr");
412 return;
413 }
414 WindowGravity gravity;
415 uint32_t percent = 0;
416 node->GetWindowGravity(gravity, percent);
417 if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT ||
418 gravity == WindowGravity::WINDOW_GRAVITY_FLOAT) {
419 return;
420 }
421
422 auto container = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
423 if (container == nullptr) {
424 WLOGFE("Node container is null");
425 return;
426 }
427
428 uint32_t navigationBarHeight = 0;
429 bool res = GetNavigationBarHeight(node->GetDisplayId(), navigationBarHeight);
430 if (res == false) {
431 return;
432 }
433
434 sptr<DisplayInfo> defaultDisplayInfo = DisplayGroupInfo::GetInstance().GetDefaultDisplayInfo();
435 if (defaultDisplayInfo == nullptr) {
436 WLOGFE("defaultDisplayInfo is null");
437 return;
438 }
439
440 auto requestRect = node->GetRequestRect();
441 if (gravity == WindowGravity::WINDOW_GRAVITY_BOTTOM) {
442 if (percent != 0) {
443 requestRect.width_ = static_cast<uint32_t>(defaultDisplayInfo->GetWidth());
444 requestRect.height_ =
445 static_cast<uint32_t>(defaultDisplayInfo->GetHeight()) * percent / 100u; // 100: for calc percent.
446 requestRect.posX_ = 0;
447 }
448 }
449 requestRect.posY_ = defaultDisplayInfo->GetHeight() -
450 static_cast<int32_t>(requestRect.height_ + navigationBarHeight);
451 node->SetRequestRect(requestRect);
452 }
453
NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode> & callingWindow,const Rect & rect,const Rect & occupiedArea)454 void WindowController::NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode>& callingWindow,
455 const Rect& rect, const Rect& occupiedArea)
456 {
457 if (callingWindow->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
458 // update calling window rect
459 callingWindow->SetWindowRect(rect);
460 WindowLayoutPolicy::CalcAndSetNodeHotZone(rect, callingWindow);
461
462 // set bounds and do animation for calling window
463 wptr<WindowNode> weakNode = callingWindow;
464 auto setBoundsFun = [weakNode, rect]() {
465 auto winNode = weakNode.promote();
466 if (winNode == nullptr) {
467 WLOGFW("Window node is nullptr");
468 return;
469 }
470 if (winNode->leashWinSurfaceNode_) {
471 winNode->leashWinSurfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_);
472 if (winNode->startingWinSurfaceNode_) {
473 winNode->startingWinSurfaceNode_->SetBounds(0, 0, rect.width_, rect.height_);
474 }
475 if (winNode->surfaceNode_) {
476 winNode->surfaceNode_->SetBounds(0, 0, rect.width_, rect.height_);
477 }
478 } else {
479 if (winNode->surfaceNode_) {
480 winNode->surfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_);
481 }
482 }
483 };
484
485 const AnimationConfig::KeyboardAnimation& animation = WindowHelper::IsEmptyRect(occupiedArea) ?
486 WindowNodeContainer::GetAnimationConfigRef().keyboardAnimationOut_ :
487 WindowNodeContainer::GetAnimationConfigRef().keyboardAnimationIn_;
488 RSNode::Animate(callingWindow->GetRSUIContext(), animation.duration_, animation.curve_, setBoundsFun);
489 }
490
491 // if keyboard will occupy calling, notify calling window the occupied area and safe height
492 const Rect& safeRect = WindowHelper::GetOverlap(occupiedArea, rect, 0, 0);
493 sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT,
494 safeRect, safeRect.height_);
495
496 auto rsTransaction = RSSyncTransactionAdapter::GetRSTransaction(callingWindow->GetRSUIContext());
497 if (WindowNodeContainer::GetAnimateTransactionEnabled() && rsTransaction) {
498 callingWindow->GetWindowToken()->UpdateOccupiedAreaAndRect(info, rect, rsTransaction);
499 } else {
500 callingWindow->GetWindowToken()->UpdateOccupiedAreaAndRect(info, rect);
501 }
502
503 FlushWindowInfo(callingWindow->GetWindowId());
504 accessibilityConnection_->NotifyAccessibilityWindowInfo(callingWindow, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
505 WLOGFD("Calling windowId: %{public}u, calling winRect: [%{public}d, %{public}d, %{public}u, %{public}u], "
506 "occupiedArea: [%{public}d, %{public}d, %{public}u, %{public}u], safeHeight: %{public}u",
507 callingWindow->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_,
508 occupiedArea.posX_, occupiedArea.posY_, occupiedArea.width_, occupiedArea.height_, safeRect.height_);
509 }
510
ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode> & node)511 void WindowController::ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode>& node)
512 {
513 auto callingWindowId = node->GetCallingWindow();
514 auto callingWindow = windowRoot_->GetWindowNode(callingWindowId);
515 if (callingWindow == nullptr) {
516 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
517 if (windowNodeContainer == nullptr) {
518 WLOGFE("NodeContainer is null, displayId:%{public}" PRIu64"", node->GetDisplayId());
519 return;
520 }
521 callingWindowId = windowNodeContainer->GetFocusWindow();
522 callingWindow = windowRoot_->GetWindowNode(callingWindowId);
523 }
524 if (callingWindow == nullptr || !callingWindow->currentVisibility_ ||
525 callingWindow->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) {
526 WLOGFE("callingWindow is null or invisible or not float window, callingWindowId:%{public}u", callingWindowId);
527 return;
528 }
529 WindowGravity gravity;
530 uint32_t percent = 0;
531 node->GetWindowGravity(gravity, percent);
532 if (gravity != WindowGravity::WINDOW_GRAVITY_BOTTOM) {
533 WLOGFI("input method window gravity is not bottom, no need to raise calling window");
534 return;
535 }
536
537 const Rect& softInputWindowRect = node->GetWindowRect();
538 const Rect& callingWindowRect = callingWindow->GetWindowRect();
539 if (WindowHelper::IsEmptyRect(WindowHelper::GetOverlap(softInputWindowRect, callingWindowRect, 0, 0))) {
540 WLOGFD("There is no overlap area");
541 return;
542 }
543
544 // calculate new rect of calling window
545 Rect newRect = callingWindowRect;
546 if (callingWindow->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
547 newRect.posY_ = softInputWindowRect.posY_ - static_cast<int32_t>(newRect.height_);
548 Rect statusBarWindowRect = { 0, 0, 0, 0 };
549 auto statusbarWindow = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]);
550 if (statusbarWindow != nullptr && statusbarWindow->parent_ != nullptr) {
551 statusBarWindowRect = statusbarWindow->GetWindowRect();
552 }
553 newRect.posY_ = std::max(newRect.posY_,
554 statusBarWindowRect.posY_ + static_cast<int32_t>(statusBarWindowRect.height_));
555
556 callingWindowRestoringRect_ = callingWindowRect;
557 callingWindowId_ = callingWindow->GetWindowId();
558 }
559
560 NotifyInputCallingWindowRectAndOccupiedAreaChange(callingWindow, newRect, softInputWindowRect);
561 }
562
RestoreCallingWindowSizeIfNeed()563 void WindowController::RestoreCallingWindowSizeIfNeed()
564 {
565 auto callingWindow = windowRoot_->GetWindowNode(callingWindowId_);
566 if (!WindowHelper::IsEmptyRect(callingWindowRestoringRect_) && callingWindow != nullptr &&
567 callingWindow->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING) {
568 Rect overlapRect = { 0, 0, 0, 0 };
569 NotifyInputCallingWindowRectAndOccupiedAreaChange(callingWindow, callingWindowRestoringRect_, overlapRect);
570 }
571 callingWindowRestoringRect_ = { 0, 0, 0, 0 };
572 callingWindowId_ = 0u;
573 }
574
HandleTurnScreenOn(const sptr<WindowNode> & node)575 void WindowController::HandleTurnScreenOn(const sptr<WindowNode>& node)
576 {
577 if (node == nullptr) {
578 WLOGFE("Node is nullptr");
579 return;
580 }
581 WLOGFD("Win: %{public}s, is turn on%{public}d", node->GetWindowName().c_str(), node->IsTurnScreenOn());
582 #ifdef POWER_MANAGER_ENABLE
583 // reset ipc identity
584 std::string identity = IPCSkeleton::ResetCallingIdentity();
585 if (node->IsTurnScreenOn() && !PowerMgr::PowerMgrClient::GetInstance().IsScreenOn()) {
586 WLOGI("turn screen on");
587 PowerMgr::PowerMgrClient::GetInstance().WakeupDevice();
588 }
589 // set ipc identity to raw
590 IPCSkeleton::SetCallingIdentity(identity);
591 #endif
592 }
593
RemoveWindowNode(uint32_t windowId,bool fromAnimation)594 WMError WindowController::RemoveWindowNode(uint32_t windowId, bool fromAnimation)
595 {
596 auto windowNode = windowRoot_->GetWindowNode(windowId);
597 if (windowNode == nullptr) {
598 WLOGFE("Could not find window");
599 return WMError::WM_ERROR_NULLPTR;
600 }
601 auto removeFunc = [this, windowId, windowNode, fromAnimation]() {
602 WMError res = windowRoot_->RemoveWindowNode(windowId, fromAnimation);
603 if (res != WMError::WM_OK) {
604 WLOGFE("RemoveWindowNode failed");
605 return res;
606 }
607 windowRoot_->FocusFaultDetection();
608 FlushWindowInfo(windowId);
609 std::vector<sptr<WindowNode>> nodes;
610 nodes.emplace_back(windowNode);
611 for (auto& child : windowNode->children_) {
612 nodes.emplace_back(child);
613 }
614 for (auto& iter : nodes) {
615 if ((iter->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) &&
616 (windowNode->abilityToken_ != iter->abilityToken_)) {
617 iter->GetWindowToken()->NotifyBackground();
618 }
619 }
620 displayZoomController_->ClearZoomTransform(nodes);
621 accessibilityConnection_->NotifyAccessibilityWindowInfo(windowNode->GetDisplayId(), nodes,
622 WindowUpdateType::WINDOW_UPDATE_REMOVED);
623 return res;
624 };
625 WMError res = WMError::WM_ERROR_NO_REMOTE_ANIMATION;
626 if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
627 // if has main full screen window, no need to do remote unlock animation
628 if (windowRoot_->NotifyDesktopUnfrozen() == WMError::WM_OK &&
629 !windowRoot_->HasMainFullScreenWindowShown(windowNode->GetDisplayId())) {
630 res = RemoteAnimation::NotifyAnimationScreenUnlock(removeFunc, windowNode);
631 WLOGI("NotifyAnimationScreenUnlock with remote animation");
632 }
633 }
634 if (res != WMError::WM_OK) {
635 res = removeFunc();
636 }
637 if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
638 RestoreCallingWindowSizeIfNeed();
639 }
640 if (!windowNode->stateMachine_.IsHideAnimationPlaying()) {
641 windowNode->stateMachine_.TransitionTo(WindowNodeState::HIDDEN);
642 }
643 return res;
644 }
645
DestroyWindow(uint32_t windowId,bool onlySelf)646 WMError WindowController::DestroyWindow(uint32_t windowId, bool onlySelf)
647 {
648 DisplayId displayId = DISPLAY_ID_INVALID;
649 auto node = windowRoot_->GetWindowNode(windowId);
650 if (node == nullptr) {
651 WLOGFE("Destroy window %{public}u failed.", windowId);
652 return WMError::WM_ERROR_NULLPTR;
653 }
654 sptr<WindowNode> parent = node->parent_;
655 displayId = node->GetDisplayId();
656 WMError res = windowRoot_->DestroyWindow(windowId, onlySelf);
657 if (res != WMError::WM_OK) {
658 return res;
659 }
660 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) {
661 if ((parent != nullptr) && WindowHelper::IsSplitWindowMode(parent->GetWindowMode())) {
662 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
663 windowNodeContainer->RaiseSplitRelatedWindowToTop(parent);
664 }
665 }
666 windowRoot_->FocusFaultDetection();
667 FlushWindowInfoWithDisplayId(displayId);
668 std::vector<sptr<WindowNode>> nodes;
669 nodes.emplace_back(node);
670 for (auto& child : node->children_) {
671 nodes.emplace_back(child);
672 }
673 accessibilityConnection_->NotifyAccessibilityWindowInfo(node->GetDisplayId(), nodes,
674 WindowUpdateType::WINDOW_UPDATE_REMOVED);
675 node->stateMachine_.TransitionTo(WindowNodeState::DESTROYED);
676 return res;
677 }
678
ResizeRect(uint32_t windowId,const Rect & rect,WindowSizeChangeReason reason)679 WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason)
680 {
681 auto node = windowRoot_->GetWindowNode(windowId);
682 if (node == nullptr) {
683 WLOGFE("could not find window");
684 return WMError::WM_ERROR_NULLPTR;
685 }
686 if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) {
687 WLOGFE("fullscreen window could not resize");
688 return WMError::WM_ERROR_INVALID_OPERATION;
689 }
690 /*
691 * if requestRect of systemBar equals to winRect, not need to resize. This may happen when rotate display
692 */
693 bool isMove = IsMoveToOrDragMove(reason);
694 if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
695 if ((isMove || reason == WindowSizeChangeReason::RESIZE) && rect == node->GetWindowRect()) {
696 return WMError::WM_OK;
697 }
698 }
699 auto property = node->GetWindowProperty();
700 node->SetWindowSizeChangeReason(reason);
701 Rect lastRect = property->GetWindowRect();
702 Rect newRect;
703 if (isMove) {
704 newRect = { rect.posX_, rect.posY_, lastRect.width_, lastRect.height_ };
705 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
706 if (windowRoot_->IsForbidDockSliceMove(node->GetDisplayId())) {
707 WLOGI("dock slice is forbidden to move");
708 newRect = lastRect;
709 } else if (windowRoot_->IsVerticalDisplay(node)) {
710 newRect.posX_ = lastRect.posX_;
711 } else {
712 newRect.posY_ = lastRect.posY_;
713 }
714 }
715 } else if (reason == WindowSizeChangeReason::RESIZE) {
716 newRect = { lastRect.posX_, lastRect.posY_, rect.width_, rect.height_ };
717 } else if (reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::MAXIMIZE) {
718 newRect = rect;
719 }
720 property->SetRequestRect(newRect);
721 if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT &&
722 (reason == WindowSizeChangeReason::RESIZE || isMove)) {
723 RelayoutKeyboard(node);
724 ResizeSoftInputCallingWindowIfNeed(node);
725 }
726 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
727 if (res != WMError::WM_OK) {
728 return res;
729 }
730 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
731 return WMError::WM_OK;
732 }
733
ResizeRectAndFlush(uint32_t windowId,const Rect & rect,WindowSizeChangeReason reason)734 WMError WindowController::ResizeRectAndFlush(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason)
735 {
736 WMError res = ResizeRect(windowId, rect, reason);
737 if (res != WMError::WM_OK) {
738 return res;
739 } else {
740 FlushWindowInfo(windowId);
741 return WMError::WM_OK;
742 }
743 }
744
RequestFocus(uint32_t windowId)745 WMError WindowController::RequestFocus(uint32_t windowId)
746 {
747 if (windowRoot_ == nullptr) {
748 return WMError::WM_ERROR_NULLPTR;
749 }
750 WMError res = windowRoot_->RequestFocus(windowId);
751 FlushWindowInfo(windowId);
752 accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
753 WindowUpdateType::WINDOW_UPDATE_FOCUSED);
754 return res;
755 }
756
SetWindowMode(uint32_t windowId,WindowMode dstMode)757 WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode dstMode)
758 {
759 HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER);
760 auto node = windowRoot_->GetWindowNode(windowId);
761 if (node == nullptr) {
762 WLOGFE("could not find window");
763 return WMError::WM_ERROR_NULLPTR;
764 }
765 WMError ret = windowRoot_->SetWindowMode(node, dstMode);
766 if (ret != WMError::WM_OK) {
767 return ret;
768 }
769 FlushWindowInfo(windowId);
770 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
771 if (!node->stateMachine_.IsShowAnimationPlaying()) {
772 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
773 MinimizeApp::ExecuteMinimizeAll();
774 WLOGI("id:%{public}u execute minimize all", node->GetWindowId());
775 }
776 }
777 return WMError::WM_OK;
778 }
779
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)780 void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
781 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
782 {
783 WLOGFD("NotifyDisplayStateChange start: %{public}u", type);
784 switch (type) {
785 case DisplayStateChangeType::BEFORE_SUSPEND: {
786 isScreenLocked_ = true;
787 windowRoot_->ProcessWindowStateChange(WindowState::STATE_FROZEN, WindowStateChangeReason::KEYGUARD);
788 break;
789 }
790 case DisplayStateChangeType::BEFORE_UNLOCK: {
791 windowRoot_->ProcessWindowStateChange(WindowState::STATE_UNFROZEN, WindowStateChangeReason::KEYGUARD);
792 isScreenLocked_ = false;
793 break;
794 }
795 case DisplayStateChangeType::CREATE: {
796 SetDefaultDisplayInfo(defaultDisplayId, displayInfo);
797 windowRoot_->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayInfoMap);
798 FlushWindowInfoWithDisplayId(displayInfo->GetDisplayId());
799 break;
800 }
801 case DisplayStateChangeType::DESTROY: {
802 windowRoot_->ProcessDisplayDestroy(defaultDisplayId, displayInfo, displayInfoMap);
803 FlushWindowInfoWithDisplayId(defaultDisplayId);
804 break;
805 }
806 case DisplayStateChangeType::DISPLAY_COMPRESS:
807 case DisplayStateChangeType::SIZE_CHANGE:
808 case DisplayStateChangeType::UPDATE_ROTATION:
809 case DisplayStateChangeType::UPDATE_ROTATION_FROM_WINDOW:
810 case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: {
811 ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type);
812 /*
813 * Window tile num may change when display rotate or change size, need to execute minimize
814 */
815 MinimizeApp::ExecuteMinimizeTargetReasons(MinimizeReason::LAYOUT_TILE);
816 break;
817 }
818 default: {
819 WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
820 return;
821 }
822 }
823 WLOGFD("NotifyDisplayStateChange end, type: %{public}u", type);
824 }
825
SetDefaultDisplayInfo(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo)826 void WindowController::SetDefaultDisplayInfo(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo)
827 {
828 if (displayInfo == nullptr) {
829 WLOGFE("display is null");
830 return;
831 }
832 if (displayInfo->GetDisplayId() != defaultDisplayId) {
833 return;
834 }
835 WLOGI("Set defaultDisplayInfo");
836 auto displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
837 auto displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
838 defaultDisplayRect_ = { 0, 0, displayWidth, displayHeight };
839 }
840
ProcessDisplayChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)841 void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
842 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
843 {
844 if (displayInfo == nullptr) {
845 WLOGFE("get display failed");
846 return;
847 }
848 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayInfo->GetDisplayId());
849 if (windowNodeContainer != nullptr) {
850 windowNodeContainer->BeforeProcessWindowAvoidAreaChangeWhenDisplayChange();
851 DisplayGroupInfo::GetInstance().UpdateDisplayInfo(displayInfo);
852 }
853 switch (type) {
854 case DisplayStateChangeType::DISPLAY_COMPRESS:
855 ProcessDisplayCompression(defaultDisplayId, displayInfo);
856 [[fallthrough]];
857 case DisplayStateChangeType::SIZE_CHANGE:
858 case DisplayStateChangeType::UPDATE_ROTATION:
859 case DisplayStateChangeType::UPDATE_ROTATION_FROM_WINDOW:
860 case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: {
861 windowRoot_->ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type);
862 break;
863 }
864 default: {
865 WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
866 return;
867 }
868 }
869 auto displayId = displayInfo->GetDisplayId();
870 displayZoomController_->UpdateAllWindowsZoomInfo(displayId);
871 FlushWindowInfoWithDisplayId(displayId);
872 accessibilityConnection_->NotifyAccessibilityWindowInfo(displayId, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
873 if (windowNodeContainer != nullptr) {
874 windowNodeContainer->ProcessWindowAvoidAreaChangeWhenDisplayChange();
875 }
876 }
877
ProcessDisplayCompression(DisplayId defaultDisplayId,const sptr<DisplayInfo> & displayInfo)878 void WindowController::ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo)
879 {
880 WLOGI("Enter processDisplayCompress");
881 DisplayId displayId = displayInfo->GetDisplayId();
882 if (displayId != defaultDisplayId) {
883 WLOGI("Not default display");
884 return;
885 }
886 auto& dms = DisplayManagerServiceInner::GetInstance();
887 if (!displayInfo->GetWaterfallDisplayCompressionStatus()) {
888 if (maskingSurfaceNode_ == nullptr) {
889 WLOGFD("MaskingSurfaceNode is not created");
890 return;
891 } else {
892 WLOGFD("Remove maskingSurfaceNode");
893 dms.UpdateRSTree(displayId, displayId, maskingSurfaceNode_, false, false);
894 maskingSurfaceNode_ = nullptr;
895 return;
896 }
897 }
898 WLOGFD("Add maskingSurfaceNode");
899 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
900 rsSurfaceNodeConfig.SurfaceNodeName = "maskingSurface";
901 maskingSurfaceNode_ = RSSurfaceNode::Create(
902 rsSurfaceNodeConfig, true, WindowInnerManager::GetInstance().GetRSUIContext());
903 if (maskingSurfaceNode_ == nullptr) {
904 WLOGFE("Create maskingSurfaceNode failed");
905 return;
906 }
907 RSAdapterUtil::SetSkipCheckInMultiInstance(maskingSurfaceNode_, true);
908 auto displayWidth = displayInfo->GetWidth();
909 auto displayHeight = displayInfo->GetHeight();
910 auto maskingSizeX = displayInfo->GetOffsetX();
911 auto maskingSizeY = displayInfo->GetOffsetY();
912 auto fullDisplayWidth = displayWidth + maskingSizeX * 2; // *2: Get full width.
913 auto fullDisplayHeight = displayHeight + maskingSizeY * 2; // *2: Get full height.
914
915 Rect screenRect = Rect {0, 0, fullDisplayWidth, fullDisplayHeight};
916 Rect transparentRect = Rect {maskingSizeX, maskingSizeY, displayWidth, displayHeight};
917 WLOGFD("ScreenRect: fullDisplayWidth: %{public}d, fullDisplayHeight: %{public}d",
918 fullDisplayWidth, fullDisplayHeight);
919 WLOGFD("TransparentRect: X: %{public}u, Y: %{public}u, Width: %{public}d, Height: %{public}d",
920 maskingSizeX, maskingSizeY, displayWidth, displayHeight);
921
922 maskingSurfaceNode_->SetPositionZ(MASKING_SURFACE_NODE_Z_ORDER);
923
924 if (!SurfaceDraw::DrawMasking(maskingSurfaceNode_, screenRect, transparentRect)) {
925 WLOGFE("Draw masking surface failed");
926 return;
927 }
928 maskingSurfaceNode_->SetBounds(0, 0, fullDisplayWidth, fullDisplayHeight);
929 dms.UpdateRSTree(displayId, displayId, maskingSurfaceNode_, true, false);
930 }
931
StopBootAnimationIfNeed(const sptr<WindowNode> & node)932 void WindowController::StopBootAnimationIfNeed(const sptr<WindowNode>& node)
933 {
934 if (isBootAnimationStopped_) {
935 return;
936 }
937 if (node == nullptr) {
938 WLOGFE("Node is nullptr");
939 return;
940 }
941 if (node->GetDisplayId() != DisplayGroupInfo::GetInstance().GetDefaultDisplayId()) {
942 return;
943 }
944 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
945 if (windowNodeContainer == nullptr) {
946 WLOGFE("Node container is nullptr");
947 return;
948 }
949 std::vector<sptr<WindowNode>> windowNodes;
950 windowNodeContainer->TraverseContainer(windowNodes);
951 WmOcclusion::Rect defaultDisplayRect = { defaultDisplayRect_.posX_, defaultDisplayRect_.posY_,
952 defaultDisplayRect_.posX_ + static_cast<int32_t>(defaultDisplayRect_.width_),
953 defaultDisplayRect_.posY_ + static_cast<int32_t>(defaultDisplayRect_.height_)};
954 WmOcclusion::Region defaultDisplayRegion(defaultDisplayRect);
955 WmOcclusion::Region allRegion; // Counts the area of all shown windows
956 for (auto& node : windowNodes) {
957 if (node->GetWindowType() == WindowType::WINDOW_TYPE_BOOT_ANIMATION) {
958 continue;
959 }
960 auto windowRect = node->GetWindowRect();
961 WmOcclusion::Rect curRect = { windowRect.posX_, windowRect.posY_,
962 windowRect.posX_ + static_cast<int32_t>(windowRect.width_),
963 windowRect.posY_ + static_cast<int32_t>(windowRect.height_)};
964 WmOcclusion::Region curRegion(curRect);
965 allRegion = curRegion.Or(allRegion);
966 WmOcclusion::Region subResult = defaultDisplayRegion.Sub(allRegion);
967 if (subResult.GetSize() == 0) {
968 WLOGI("stop boot animation");
969 system::SetParameter("bootevent.wms.fullscreen.ready", "true");
970 isBootAnimationStopped_ = true;
971 RecordBootAnimationEvent();
972 DisplayManagerServiceInner::GetInstance().SetGravitySensorSubscriptionEnabled();
973 }
974 }
975 }
976
RecordBootAnimationEvent() const977 void WindowController::RecordBootAnimationEvent() const
978 {
979 uint64_t time = static_cast<uint64_t>(std::chrono::time_point_cast<std::chrono::seconds>
980 (std::chrono::steady_clock::now()).time_since_epoch().count());
981 WLOGI("boot animation done duration(s): %{public}" PRIu64"", time);
982 std::ostringstream os;
983 os << "boot animation done duration(s): " << time <<";";
984 int32_t ret = HiSysEventWrite(
985 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
986 "WINDOW_BOOT_ANIMATION_DONE",
987 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
988 "MSG", os.str());
989 if (ret != 0) {
990 WLOGFE("Write HiSysEvent error, ret:%{public}d", ret);
991 }
992 }
993
GetSnapshot(int32_t windowId)994 std::shared_ptr<Media::PixelMap> WindowController::GetSnapshot(int32_t windowId)
995 {
996 auto node = windowRoot_->GetWindowNode(windowId);
997 if (node == nullptr) {
998 WLOGFE("could not find window");
999 return nullptr;
1000 }
1001 auto callback = std::make_shared<SurfaceCaptureFuture>();
1002 bool ret = RSInterfaces::GetInstance().TakeSurfaceCapture(node->surfaceNode_, callback);
1003 if (!ret) {
1004 WLOGFE("takeSurfaceCapture failed");
1005 return nullptr;
1006 }
1007 return callback->GetResult(SNAPSHOT_TIMEOUT_MS);
1008 }
1009
SetWindowType(uint32_t windowId,WindowType type)1010 WMError WindowController::SetWindowType(uint32_t windowId, WindowType type)
1011 {
1012 auto node = windowRoot_->GetWindowNode(windowId);
1013 if (node == nullptr) {
1014 WLOGFE("could not find window");
1015 return WMError::WM_ERROR_NULLPTR;
1016 }
1017 auto property = node->GetWindowProperty();
1018 property->SetWindowType(type);
1019 UpdateWindowAnimation(node);
1020 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_TYPE);
1021 if (res != WMError::WM_OK) {
1022 return res;
1023 }
1024 FlushWindowInfo(windowId);
1025 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1026 WLOGI("SetWindowType end");
1027 return res;
1028 }
1029
SetWindowFlags(uint32_t windowId,uint32_t flags,bool isSystemCalling)1030 WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags, bool isSystemCalling)
1031 {
1032 auto node = windowRoot_->GetWindowNode(windowId);
1033 if (node == nullptr) {
1034 WLOGFE("could not find window");
1035 return WMError::WM_ERROR_NULLPTR;
1036 }
1037 auto property = node->GetWindowProperty();
1038 uint32_t oldFlags = property->GetWindowFlags();
1039 if (property->GetApiCompatibleVersion() >= 9 && !isSystemCalling && // 9: api version.
1040 (oldFlags ^ flags) == static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) {
1041 WLOGFW("Only API 9- or system calling support showing when locked.");
1042 return WMError::WM_ERROR_INVALID_PERMISSION;
1043 }
1044 property->SetWindowFlags(flags);
1045 // only forbid_split_move flag change, just set property
1046 if ((oldFlags ^ flags) == static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE)) {
1047 return WMError::WM_OK;
1048 }
1049 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_FLAGS);
1050 if (res != WMError::WM_OK) {
1051 return res;
1052 }
1053 FlushWindowInfo(windowId);
1054 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1055 WLOGI("SetWindowFlags end");
1056 return res;
1057 }
1058
SetSystemBarProperty(uint32_t windowId,WindowType type,const SystemBarProperty & property)1059 WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property)
1060 {
1061 auto node = windowRoot_->GetWindowNode(windowId);
1062 if (node == nullptr) {
1063 WLOGFE("could not find window");
1064 return WMError::WM_ERROR_NULLPTR;
1065 }
1066 node->SetSystemBarProperty(type, property);
1067 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_OTHER_PROPS);
1068 if (res != WMError::WM_OK) {
1069 return res;
1070 }
1071 FlushWindowInfo(windowId);
1072 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1073 WLOGI("SetSystemBarProperty end");
1074 return res;
1075 }
1076
NotifySystemBarTints()1077 void WindowController::NotifySystemBarTints()
1078 {
1079 windowRoot_->NotifySystemBarTints();
1080 }
1081
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)1082 WMError WindowController::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
1083 {
1084 return RemoteAnimation::SetWindowAnimationController(controller);
1085 }
1086
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType avoidAreaType,const Rect & rect) const1087 AvoidArea WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType, const Rect& rect) const
1088 {
1089 return windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType);
1090 }
1091
ChangeMouseStyle(uint32_t windowId,sptr<MoveDragProperty> & moveDragProperty)1092 WMError WindowController::ChangeMouseStyle(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty)
1093 {
1094 auto node = windowRoot_->GetWindowNode(windowId);
1095 int32_t mouseStyle = 0;
1096 MMI::PointerStyle pointerStyle;
1097 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
1098 if (node->GetWindowRect().width_ > node->GetWindowRect().height_) {
1099 mouseStyle = MMI::MOUSE_ICON::NORTH_SOUTH;
1100 } else {
1101 mouseStyle = MMI::MOUSE_ICON::WEST_EAST;
1102 }
1103 pointerStyle.id = mouseStyle;
1104 int32_t res = MMI::InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1105 if (res != 0) {
1106 WLOGFE("set pointer style failed");
1107 return WMError::WM_ERROR_INVALID_OPERATION;
1108 }
1109 return WMError::WM_OK;
1110 }
1111 pointerStyle.id = STYLEID_MAP.at(moveDragProperty->dragType_);
1112 int32_t res = MMI::InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1113 if (res != 0) {
1114 WLOGFE("set pointer style failed");
1115 return WMError::WM_ERROR_INVALID_OPERATION;
1116 }
1117 return WMError::WM_OK;
1118 }
1119
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<MoveDragProperty> & moveDragProperty)1120 WMError WindowController::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty)
1121 {
1122 auto node = windowRoot_->GetWindowNode(windowId);
1123 if (node == nullptr) {
1124 WLOGFW("could not find window");
1125 return WMError::WM_ERROR_NULLPTR;
1126 }
1127 if (!node->currentVisibility_) {
1128 WLOGFE("Window is invisible, windowId: %{public}u", windowId);
1129 return WMError::WM_ERROR_INVALID_OPERATION;
1130 }
1131
1132 if (node->GetWindowProperty()->GetMaximizeMode() == MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
1133 return WMError::WM_OK;
1134 }
1135
1136 // if start dragging or start moving dock_slice, need to update size change reason
1137 if ((moveDragProperty->startMoveFlag_ && node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) ||
1138 moveDragProperty->startDragFlag_) {
1139 WMError res = windowRoot_->UpdateSizeChangeReason(windowId, WindowSizeChangeReason::DRAG_START);
1140 ChangeMouseStyle(windowId, moveDragProperty);
1141 if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && dragFrameGravity_ != INVALID_GRAVITY) {
1142 if (node->surfaceNode_) {
1143 node->surfaceNode_->SetFrameGravity(static_cast<Gravity>(dragFrameGravity_));
1144 }
1145 }
1146 return res;
1147 }
1148 return WMError::WM_OK;
1149 }
1150
ProcessPointDown(uint32_t windowId,bool isPointDown)1151 WMError WindowController::ProcessPointDown(uint32_t windowId, bool isPointDown)
1152 {
1153 auto node = windowRoot_->GetWindowNode(windowId);
1154 if (node == nullptr) {
1155 WLOGFW("could not find window");
1156 return WMError::WM_ERROR_NULLPTR;
1157 }
1158 if (!node->currentVisibility_) {
1159 WLOGFE("Window is invisible, windowId: %{public}u", windowId);
1160 return WMError::WM_ERROR_INVALID_OPERATION;
1161 }
1162
1163 /*
1164 * If not point down, no need to notify touch outside
1165 */
1166 if (isPointDown) {
1167 NotifyTouchOutside(node);
1168 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
1169 windowRoot_->TakeWindowPairSnapshot(node->GetDisplayId());
1170 }
1171 }
1172
1173 WLOGFD("WindowId: %{public}u", windowId);
1174 WMError zOrderRes = windowRoot_->RaiseZOrderForAppWindow(node);
1175 WMError focusRes = windowRoot_->RequestFocus(windowId);
1176 windowRoot_->RequestActiveWindow(windowId);
1177 windowRoot_->FocusFaultDetection();
1178 if (zOrderRes == WMError::WM_OK || focusRes == WMError::WM_OK) {
1179 FlushWindowInfo(windowId);
1180 accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
1181 WindowUpdateType::WINDOW_UPDATE_FOCUSED);
1182 WLOGI("ProcessPointDown end");
1183 return WMError::WM_OK;
1184 }
1185 return WMError::WM_ERROR_INVALID_OPERATION;
1186 }
1187
ProcessPointUp(uint32_t windowId)1188 WMError WindowController::ProcessPointUp(uint32_t windowId)
1189 {
1190 auto node = windowRoot_->GetWindowNode(windowId);
1191 if (node == nullptr) {
1192 WLOGFW("could not find window");
1193 return WMError::WM_ERROR_NULLPTR;
1194 }
1195 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
1196 DisplayId displayId = node->GetDisplayId();
1197 if (windowRoot_->IsDockSliceInExitSplitModeArea(displayId)) {
1198 windowRoot_->ExitSplitMode(displayId);
1199 } else {
1200 windowRoot_->ClearWindowPairSnapshot(node->GetDisplayId());
1201 auto property = node->GetWindowProperty();
1202 node->SetWindowSizeChangeReason(WindowSizeChangeReason::DRAG_END);
1203 property->SetRequestRect(property->GetWindowRect());
1204 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
1205 if (res == WMError::WM_OK) {
1206 FlushWindowInfo(windowId);
1207 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1208 }
1209 }
1210 }
1211 if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && dragFrameGravity_ != INVALID_GRAVITY) {
1212 if (node->surfaceNode_) {
1213 node->surfaceNode_->SetFrameGravity(Gravity::RESIZE);
1214 }
1215 }
1216 WMError res = windowRoot_->UpdateSizeChangeReason(windowId, WindowSizeChangeReason::DRAG_END);
1217 if (res != WMError::WM_OK) {
1218 return res;
1219 }
1220 return WMError::WM_OK;
1221 }
1222
InterceptInputEventToServer(uint32_t windowId)1223 WMError WindowController::InterceptInputEventToServer(uint32_t windowId)
1224 {
1225 auto node = windowRoot_->GetWindowNode(windowId);
1226 if (node == nullptr) {
1227 WLOGFW("could not find window");
1228 return WMError::WM_ERROR_NULLPTR;
1229 }
1230 auto inputPidInServer = WindowInnerManager::GetInstance().GetPid();
1231 WLOGI("InterceptInputEventToServer, windowId: %{public}u, inputPid: %{public}u", windowId, inputPidInServer);
1232 node->SetInputEventCallingPid(static_cast<int32_t>(inputPidInServer));
1233 FlushWindowInfo(windowId);
1234 return WMError::WM_OK;
1235 }
1236
RecoverInputEventToClient(uint32_t windowId)1237 WMError WindowController::RecoverInputEventToClient(uint32_t windowId)
1238 {
1239 auto node = windowRoot_->GetWindowNode(windowId);
1240 if (node == nullptr) {
1241 WLOGFW("could not find window");
1242 return WMError::WM_ERROR_NULLPTR;
1243 }
1244 if (node->GetInputEventCallingPid() == node->GetCallingPid()) {
1245 WLOGFD("There is no need to recover input event to client");
1246 return WMError::WM_OK;
1247 }
1248
1249 node->SetInputEventCallingPid(node->GetCallingPid());
1250 RecoverDefaultMouseStyle(windowId);
1251 FlushWindowInfo(windowId);
1252 return WMError::WM_OK;
1253 }
1254
RecoverDefaultMouseStyle(uint32_t windowId)1255 void WindowController::RecoverDefaultMouseStyle(uint32_t windowId)
1256 {
1257 // asynchronously calls SetMouseStyle of MultiModalInput
1258 MMI::PointerStyle pointerStyle;
1259 pointerStyle.id = MMI::MOUSE_ICON::DEFAULT;
1260 auto task = [this, windowId, pointerStyle]() {
1261 int32_t res = MMI::InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1262 if (res != 0) {
1263 WLOGFE("set pointer style failed");
1264 }
1265 };
1266 WindowInnerManager::GetInstance().PostTask(task, "RecoverDefaultMouseStyle");
1267 }
1268
1269 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)1270 WMError WindowController::RaiseToAppTop(uint32_t windowId)
1271 {
1272 auto node = windowRoot_->GetWindowNode(windowId);
1273 if (node == nullptr) {
1274 WLOGFW("could not find window");
1275 return WMError::WM_ERROR_NULLPTR;
1276 }
1277
1278 auto parentNode = node->parent_;
1279 if (parentNode == nullptr) {
1280 WLOGFW("could not find parent");
1281 return WMError::WM_ERROR_INVALID_PARENT;
1282 }
1283
1284 WMError zOrderRes = windowRoot_->RaiseZOrderForAppWindow(node);
1285 if (zOrderRes != WMError::WM_OK) {
1286 WLOGFE("Raise subwindow zorder fail, ret: %{public}d", zOrderRes);
1287 return WMError::WM_DO_NOTHING;
1288 }
1289
1290 UpdateFocusIfNeededWhenRaiseWindow(node);
1291 FlushWindowInfo(windowId);
1292 return WMError::WM_OK;
1293 }
1294
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1295 void WindowController::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1296 {
1297 auto node = windowRoot_->GetWindowNode(windowId);
1298 if (node == nullptr) {
1299 WLOGFW("Could not find window");
1300 return;
1301 }
1302 if (node->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
1303 WLOGFI("Window type is not WINDOW_TYPE_APP_COMPONENT");
1304 return;
1305 }
1306 windowRoot_->DispatchKeyEvent(node, event);
1307 }
1308
UpdateFocusIfNeededWhenRaiseWindow(const sptr<WindowNode> & node)1309 void WindowController::UpdateFocusIfNeededWhenRaiseWindow(const sptr<WindowNode>& node)
1310 {
1311 auto property = node->GetWindowProperty();
1312 if (!property->GetFocusable()) {
1313 return;
1314 }
1315 uint32_t windowId = node->GetWindowId();
1316 sptr<WindowNode> focusWindow = nullptr;
1317 WMError res = GetFocusWindowNode(node->GetDisplayId(), focusWindow);
1318 if (res != WMError::WM_OK || focusWindow == nullptr) {
1319 return;
1320 }
1321 if (node->parent_->GetWindowId() == focusWindow->GetWindowId() ||
1322 node->parent_->GetWindowId() == focusWindow->GetParentId()) {
1323 windowRoot_->RequestFocus(windowId);
1324 windowRoot_->RequestActiveWindow(windowId);
1325 windowRoot_->FocusFaultDetection();
1326
1327 accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
1328 WindowUpdateType::WINDOW_UPDATE_FOCUSED);
1329 }
1330 }
1331
NotifyWindowClientPointUp(uint32_t windowId,const std::shared_ptr<MMI::PointerEvent> & pointerEvent)1332 WMError WindowController::NotifyWindowClientPointUp(uint32_t windowId,
1333 const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
1334 {
1335 auto node = windowRoot_->GetWindowNode(windowId);
1336 if (node == nullptr) {
1337 WLOGFW("could not find window");
1338 return WMError::WM_ERROR_NULLPTR;
1339 }
1340 if (node->GetWindowToken() != nullptr) {
1341 WLOGI("notify client when receive point_up event, windowId: %{public}u", windowId);
1342 node->GetWindowToken()->NotifyWindowClientPointUp(pointerEvent);
1343 }
1344 return WMError::WM_OK;
1345 }
1346
MinimizeAllAppWindows(DisplayId displayId)1347 void WindowController::MinimizeAllAppWindows(DisplayId displayId)
1348 {
1349 windowRoot_->MinimizeAllAppWindows(displayId);
1350 if (RemoteAnimation::NotifyAnimationByHome() != WMError::WM_OK) {
1351 MinimizeApp::ExecuteMinimizeAll();
1352 }
1353 }
1354
ToggleShownStateForAllAppWindows()1355 WMError WindowController::ToggleShownStateForAllAppWindows()
1356 {
1357 if (isScreenLocked_) {
1358 return WMError::WM_DO_NOTHING;
1359 }
1360 return windowRoot_->ToggleShownStateForAllAppWindows();
1361 }
1362
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)1363 WMError WindowController::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
1364 {
1365 return windowRoot_->GetTopWindowId(mainWinId, topWinId);
1366 }
1367
FlushWindowInfo(uint32_t windowId)1368 void WindowController::FlushWindowInfo(uint32_t windowId)
1369 {
1370 WLOGD("FlushWindowInfo");
1371 displayZoomController_->UpdateWindowZoomInfo(windowId);
1372 auto node = windowRoot_->GetWindowNode(windowId);
1373 RSTransactionAdapter::FlushImplicitTransaction(node ? node->GetRSUIContext() : nullptr);
1374 inputWindowMonitor_->UpdateInputWindow(windowId);
1375 }
1376
FlushWindowInfoWithDisplayId(DisplayId displayId)1377 void WindowController::FlushWindowInfoWithDisplayId(DisplayId displayId)
1378 {
1379 WLOGFD("DisplayId: %{public}" PRIu64"", displayId);
1380 auto rsUIDirector = WindowInnerManager::GetInstance().GetRSUIDirector();
1381 RSTransactionAdapter::FlushImplicitTransaction(rsUIDirector);
1382 inputWindowMonitor_->UpdateInputWindowByDisplayId(displayId);
1383 }
1384
UpdateWindowAnimation(const sptr<WindowNode> & node)1385 void WindowController::UpdateWindowAnimation(const sptr<WindowNode>& node)
1386 {
1387 if (node == nullptr || (node->leashWinSurfaceNode_ == nullptr && node->surfaceNode_ == nullptr)) {
1388 WLOGFE("windowNode or surfaceNode is nullptr");
1389 return;
1390 }
1391 const auto& windowAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().windowAnimationConfig_;
1392
1393 uint32_t animationFlag = node->GetWindowProperty()->GetAnimationFlag();
1394 uint32_t windowId = node->GetWindowProperty()->GetWindowId();
1395 WLOGFD("Id: %{public}u, anim_Flag: %{public}u", windowId, animationFlag);
1396 std::shared_ptr<const RSTransitionEffect> effect = nullptr;
1397 if (animationFlag == static_cast<uint32_t>(WindowAnimation::DEFAULT)) {
1398 effect = RSTransitionEffect::Create()
1399 ->Scale(windowAnimationConfig.scale_)
1400 ->Rotate(windowAnimationConfig.rotation_)
1401 ->Translate(windowAnimationConfig.translate_)
1402 ->Opacity(windowAnimationConfig.opacity_);
1403 } else if (animationFlag == static_cast<uint32_t>(WindowAnimation::INPUTE)) {
1404 float translateY = static_cast<float>(node->GetWindowRect().height_);
1405 if (!node->GetWindowRect().height_) {
1406 translateY = static_cast<float>(node->GetRequestRect().height_);
1407 }
1408 effect = RSTransitionEffect::Create()->Translate(Vector3f(0, translateY, 0))->Opacity(1.0f);
1409 };
1410 if (node->leashWinSurfaceNode_) {
1411 node->leashWinSurfaceNode_->SetTransitionEffect(effect);
1412 }
1413 if (node->surfaceNode_) {
1414 node->surfaceNode_->SetTransitionEffect(effect);
1415 }
1416 }
1417
SetWindowLayoutMode(WindowLayoutMode mode)1418 WMError WindowController::SetWindowLayoutMode(WindowLayoutMode mode)
1419 {
1420 WMError res = WMError::WM_OK;
1421 auto displayIds = windowRoot_->GetAllDisplayIds();
1422 for (auto displayId : displayIds) {
1423 res = windowRoot_->SetWindowLayoutMode(displayId, mode);
1424 if (res != WMError::WM_OK) {
1425 return res;
1426 }
1427 displayZoomController_->UpdateAllWindowsZoomInfo(displayId);
1428 FlushWindowInfoWithDisplayId(displayId);
1429 accessibilityConnection_->NotifyAccessibilityWindowInfo(displayId, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1430 }
1431 MinimizeApp::ExecuteMinimizeAll();
1432 return res;
1433 }
1434
NotifyScreenshotEvent(ScreenshotEventType type)1435 WMError WindowController::NotifyScreenshotEvent(ScreenshotEventType type)
1436 {
1437 std::vector<sptr<WindowNode>> windowNodes;
1438 windowRoot_->GetForegroundNodes(windowNodes);
1439 for (auto& windowNode : windowNodes) {
1440 if (windowNode == nullptr) {
1441 continue;
1442 }
1443 auto windowToken = windowNode->GetWindowToken();
1444 if (windowToken != nullptr) {
1445 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}u, event: %{public}d", windowNode->GetWindowId(), type);
1446 windowToken->NotifyScreenshotAppEvent(type);
1447 }
1448 }
1449 return WMError::WM_OK;
1450 }
1451
UpdateProperty(sptr<WindowProperty> & property,PropertyChangeAction action)1452 WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action)
1453 {
1454 if (property == nullptr) {
1455 WLOGFE("property is invalid");
1456 return WMError::WM_ERROR_NULLPTR;
1457 }
1458
1459 uint32_t windowId = property->GetWindowId();
1460 auto node = windowRoot_->GetWindowNode(windowId);
1461 if (node == nullptr) {
1462 WLOGFE("window is invalid");
1463 return WMError::WM_ERROR_NULLPTR;
1464 }
1465 WLOGI("Id: %{public}u, action: %{public}u", node->GetWindowId(), static_cast<uint32_t>(action));
1466 WMError ret = WMError::WM_OK;
1467 switch (action) {
1468 case PropertyChangeAction::ACTION_UPDATE_RECT: {
1469 node->SetDecoStatus(property->GetDecoStatus());
1470 node->SetOriginRect(property->GetOriginRect());
1471 node->SetDragType(property->GetDragType());
1472 ret = ResizeRectAndFlush(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason());
1473 if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && ret == WMError::WM_OK &&
1474 callingWindowId_ == windowId && !WindowHelper::IsEmptyRect(callingWindowRestoringRect_)) {
1475 if (!IsMoveToOrDragMove(property->GetWindowSizeChangeReason())) {
1476 callingWindowId_ = 0u;
1477 callingWindowRestoringRect_ = { 0, 0, 0, 0 };
1478 } else {
1479 auto windowRect = node->GetWindowRect();
1480 callingWindowRestoringRect_.posX_ = windowRect.posX_;
1481 callingWindowRestoringRect_.posY_ = windowRect.posY_;
1482 }
1483 }
1484 break;
1485 }
1486 case PropertyChangeAction::ACTION_UPDATE_MODE: {
1487 node->SetDecorEnable(property->GetDecorEnable());
1488 ret = SetWindowMode(windowId, property->GetWindowMode());
1489 break;
1490 }
1491 case PropertyChangeAction::ACTION_UPDATE_FLAGS: {
1492 ret = SetWindowFlags(windowId, property->GetWindowFlags(), property->isSystemCalling_);
1493 break;
1494 }
1495 case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS: {
1496 auto& props = property->GetSystemBarProperty();
1497 for (auto& iter : props) {
1498 SetSystemBarProperty(windowId, iter.first, iter.second);
1499 }
1500 break;
1501 }
1502 case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE: {
1503 node->SetFocusable(property->GetFocusable());
1504 windowRoot_->UpdateFocusableProperty(windowId);
1505 FlushWindowInfo(windowId);
1506 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1507 break;
1508 }
1509 case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE: {
1510 node->SetTouchable(property->GetTouchable());
1511 FlushWindowInfo(windowId);
1512 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1513 break;
1514 }
1515 case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW: {
1516 node->SetCallingWindow(property->GetCallingWindow());
1517 break;
1518 }
1519 case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: {
1520 node->SetRequestedOrientation(property->GetRequestedOrientation());
1521 if (WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) {
1522 DisplayManagerServiceInner::GetInstance().
1523 SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation());
1524 }
1525 break;
1526 }
1527 case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON: {
1528 node->SetTurnScreenOn(property->IsTurnScreenOn());
1529 HandleTurnScreenOn(node);
1530 break;
1531 }
1532 case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON: {
1533 node->SetKeepScreenOn(property->IsKeepScreenOn());
1534 windowRoot_->HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn());
1535 break;
1536 }
1537 case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS: {
1538 node->SetBrightness(property->GetBrightness());
1539 windowRoot_->SetBrightness(node->GetWindowId(), node->GetBrightness());
1540 break;
1541 }
1542 case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO: {
1543 node->SetWindowModeSupportType(property->GetWindowModeSupportType());
1544 break;
1545 }
1546 case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA: {
1547 std::vector<Rect> rects;
1548 property->GetTouchHotAreas(rects);
1549 ret = UpdateTouchHotAreas(node, rects);
1550 break;
1551 }
1552 case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: {
1553 node->GetWindowProperty()->SetAnimationFlag(property->GetAnimationFlag());
1554 UpdateWindowAnimation(node);
1555 break;
1556 }
1557 case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: {
1558 node->SetTransform(property->GetTransform());
1559 node->SetWindowSizeChangeReason(WindowSizeChangeReason::TRANSFORM);
1560 node->GetWindowProperty()->SetAnimateWindowFlag(true);
1561 ret = UpdateTransform(windowId);
1562 break;
1563 }
1564 case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE: {
1565 bool isPrivacyMode = property->GetPrivacyMode() || property->GetSystemPrivacyMode();
1566 node->GetWindowProperty()->SetPrivacyMode(isPrivacyMode);
1567 node->GetWindowProperty()->SetSystemPrivacyMode(isPrivacyMode);
1568 node->surfaceNode_->SetSecurityLayer(isPrivacyMode);
1569 if (node->leashWinSurfaceNode_ != nullptr) {
1570 node->leashWinSurfaceNode_->SetSecurityLayer(isPrivacyMode);
1571 }
1572 RSTransactionAdapter::FlushImplicitTransaction(node->GetRSUIContext());
1573 UpdatePrivateStateAndNotify(node);
1574 break;
1575 }
1576 case PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE: {
1577 bool isPrivacyMode = property->GetPrivacyMode() || property->GetSystemPrivacyMode();
1578 node->GetWindowProperty()->SetPrivacyMode(isPrivacyMode);
1579 node->GetWindowProperty()->SetSystemPrivacyMode(isPrivacyMode);
1580 node->surfaceNode_->SetSecurityLayer(isPrivacyMode);
1581 if (node->leashWinSurfaceNode_ != nullptr) {
1582 node->leashWinSurfaceNode_->SetSecurityLayer(isPrivacyMode);
1583 }
1584 RSTransactionAdapter::FlushImplicitTransaction(node->GetRSUIContext());
1585 UpdatePrivateStateAndNotify(node);
1586 break;
1587 }
1588 case PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP: {
1589 bool isSnapshotSkip = property->GetSnapshotSkip() || property->GetSystemPrivacyMode();
1590 node->GetWindowProperty()->SetSnapshotSkip(isSnapshotSkip);
1591 node->GetWindowProperty()->SetSystemPrivacyMode(isSnapshotSkip);
1592 node->surfaceNode_->SetSkipLayer(isSnapshotSkip);
1593 if (node->leashWinSurfaceNode_ != nullptr) {
1594 node->leashWinSurfaceNode_->SetSkipLayer(isSnapshotSkip);
1595 }
1596 RSTransactionAdapter::FlushImplicitTransaction(node->GetRSUIContext());
1597 break;
1598 }
1599 case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO: {
1600 ret = SetAspectRatio(windowId, property->GetAspectRatio());
1601 break;
1602 }
1603 case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE: {
1604 MaximizeMode mode = property->GetMaximizeMode();
1605 node->GetWindowProperty()->SetMaximizeMode(mode);
1606 Rect newRect = {0, 0, 0, 0};
1607 if (mode == MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
1608 node->SetOriginRect(node->GetWindowRect());
1609 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1610 if (windowNodeContainer == nullptr) {
1611 WLOGFE("window node container is null");
1612 return WMError::WM_ERROR_NULLPTR;
1613 }
1614 windowNodeContainer->GetLayoutPolicy()->GetMaximizeRect(node, newRect);
1615 } else {
1616 newRect = node->GetOriginRect();
1617 }
1618 WLOGI("window %{public}d maximizeMode %{public}d rect %{public}d %{public}d %{public}d %{public}d",
1619 windowId, static_cast<uint32_t>(mode), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_);
1620 ret = ResizeRectAndFlush(windowId, newRect, WindowSizeChangeReason::MAXIMIZE);
1621 break;
1622 }
1623 case PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO: {
1624 node->GetWindowProperty()->SetTextFieldPositionY(property->GetTextFieldPositionY());
1625 node->GetWindowProperty()->SetTextFieldHeight(property->GetTextFieldHeight());
1626 break;
1627 }
1628 case PropertyChangeAction::ACTION_UPDATE_FOLLOW_SCREEN_CHANGE: {
1629 node->GetWindowProperty()->SetFollowScreenChange(property->GetFollowScreenChange());
1630 break;
1631 }
1632 default:
1633 break;
1634 }
1635 return ret;
1636 }
1637
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)1638 WMError WindowController::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
1639 {
1640 sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
1641 if (node == nullptr) {
1642 return WMError::WM_ERROR_NULLPTR;
1643 }
1644 if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
1645 return WMError::WM_ERROR_INVALID_TYPE;
1646 }
1647 node->SetWindowGravity(gravity, percent);
1648 RelayoutKeyboard(node);
1649 if (gravity == WindowGravity::WINDOW_GRAVITY_FLOAT) {
1650 RestoreCallingWindowSizeIfNeed();
1651 } else {
1652 ResizeSoftInputCallingWindowIfNeed(node);
1653 }
1654 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
1655 if (res != WMError::WM_OK) {
1656 return res;
1657 }
1658 FlushWindowInfo(windowId);
1659 return WMError::WM_OK;
1660 }
1661
UpdatePrivateStateAndNotify(const sptr<WindowNode> & node)1662 void WindowController::UpdatePrivateStateAndNotify(const sptr<WindowNode>& node)
1663 {
1664 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1665 if (windowNodeContainer == nullptr) {
1666 WLOGFE("window node container is null");
1667 return;
1668 }
1669 windowNodeContainer->UpdatePrivateStateAndNotify();
1670 }
1671
SetAspectRatio(uint32_t windowId,float ratio)1672 WMError WindowController::SetAspectRatio(uint32_t windowId, float ratio)
1673 {
1674 WLOGI("SetAspectRatio, windowId: %{public}u, %{public}f", windowId, ratio);
1675 HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER);
1676 auto node = windowRoot_->GetWindowNode(windowId);
1677 if (node == nullptr) {
1678 WLOGFE("could not find window");
1679 return WMError::WM_OK;
1680 }
1681 if (!WindowHelper::IsAspectRatioSatisfiedWithSizeLimits(node->GetWindowUpdatedSizeLimits(), ratio,
1682 DisplayGroupInfo::GetInstance().GetDisplayVirtualPixelRatio(node->GetDisplayId()))) {
1683 return WMError::WM_ERROR_INVALID_PARAM;
1684 }
1685
1686 node->SetAspectRatio(ratio);
1687
1688 // perserve aspect ratio
1689 std::vector<std::string> nameVector;
1690 if (node->abilityInfo_.abilityName_.size() > 0) {
1691 nameVector = WindowHelper::Split(node->abilityInfo_.abilityName_, ".");
1692 }
1693 std::string keyName = nameVector.empty() ? node->abilityInfo_.bundleName_ :
1694 node->abilityInfo_.bundleName_ + "." + nameVector.back();
1695 if (MathHelper::NearZero(ratio)) { // If ratio is 0.0, need to reset aspect and delete storage
1696 if (PersistentStorage::HasKey(keyName, PersistentStorageType::ASPECT_RATIO)) {
1697 PersistentStorage::Delete(keyName, PersistentStorageType::ASPECT_RATIO);
1698 }
1699 return WMError::WM_OK;
1700 }
1701 PersistentStorage::Insert(keyName, ratio, PersistentStorageType::ASPECT_RATIO);
1702
1703 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_ASPECT_RATIO);
1704 if (res != WMError::WM_OK) {
1705 return res;
1706 }
1707 FlushWindowInfo(windowId);
1708 return WMError::WM_OK;
1709 }
1710
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos) const1711 WMError WindowController::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const
1712 {
1713 accessibilityConnection_->GetAccessibilityWindowInfo(infos);
1714 return WMError::WM_OK;
1715 }
1716
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos) const1717 WMError WindowController::GetUnreliableWindowInfo(int32_t windowId,
1718 std::vector<sptr<UnreliableWindowInfo>>& infos) const
1719 {
1720 windowRoot_->GetUnreliableWindowInfo(windowId, infos);
1721 return WMError::WM_OK;
1722 }
1723
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos) const1724 WMError WindowController::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const
1725 {
1726 windowRoot_->GetVisibilityWindowInfo(infos);
1727 return WMError::WM_OK;
1728 }
1729
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones,const ModeChangeHotZonesConfig & config)1730 WMError WindowController::GetModeChangeHotZones(DisplayId displayId,
1731 ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config)
1732 {
1733 return windowRoot_->GetModeChangeHotZones(displayId, hotZones, config);
1734 }
1735
UpdateTouchHotAreas(const sptr<WindowNode> & node,const std::vector<Rect> & rects)1736 WMError WindowController::UpdateTouchHotAreas(const sptr<WindowNode>& node, const std::vector<Rect>& rects)
1737 {
1738 std::ostringstream oss;
1739 int index = 0;
1740 for (const auto& rect : rects) {
1741 oss << "[ " << rect.posX_ << ", " << rect.posY_ << ", " << rect.width_ << ", " << rect.height_ << " ]";
1742 index++;
1743 if (index < static_cast<int32_t>(rects.size())) {
1744 oss <<", ";
1745 }
1746 }
1747 WLOGI("windowId: %{public}u, size: %{public}d, rects: %{public}s",
1748 node->GetWindowId(), static_cast<int32_t>(rects.size()), oss.str().c_str());
1749 if (rects.size() > TOUCH_HOT_AREA_MAX_NUM) {
1750 WLOGFE("the number of touch hot areas exceeds the maximum");
1751 return WMError::WM_ERROR_INVALID_PARAM;
1752 }
1753
1754 std::vector<Rect> touchHotAreas;
1755 std::vector<Rect> pointerHotAreas;
1756 if (rects.empty()) {
1757 touchHotAreas.emplace_back(node->GetEntireWindowTouchHotArea());
1758 pointerHotAreas.emplace_back(node->GetEntireWindowPointerHotArea());
1759 } else {
1760 Rect windowRect = node->GetWindowRect();
1761 if (!WindowHelper::CalculateTouchHotAreas(windowRect, rects, touchHotAreas)) {
1762 WLOGFE("the requested touch hot areas are incorrect");
1763 return WMError::WM_ERROR_INVALID_PARAM;
1764 }
1765 pointerHotAreas = touchHotAreas;
1766 }
1767 node->GetWindowProperty()->SetTouchHotAreas(rects);
1768 node->SetTouchHotAreas(touchHotAreas);
1769 node->SetPointerHotAreas(pointerHotAreas);
1770 FlushWindowInfo(node->GetWindowId());
1771 accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1772 return WMError::WM_OK;
1773 }
1774
UpdateTransform(uint32_t windowId)1775 WMError WindowController::UpdateTransform(uint32_t windowId)
1776 {
1777 WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_TRANSFORM);
1778 if (res != WMError::WM_OK) {
1779 return res;
1780 }
1781 FlushWindowInfo(windowId);
1782 accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
1783 WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1784 return WMError::WM_OK;
1785 }
1786
NotifyTouchOutside(const sptr<WindowNode> & node)1787 void WindowController::NotifyTouchOutside(const sptr<WindowNode>& node)
1788 {
1789 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1790 if (windowNodeContainer == nullptr) {
1791 WLOGFE("window node container is null");
1792 return;
1793 }
1794
1795 std::vector<sptr<WindowNode>> windowNodes;
1796 windowNodeContainer->TraverseContainer(windowNodes);
1797 uint32_t skipNodeId = GetEmbedNodeId(windowNodes, node);
1798 for (const auto& windowNode : windowNodes) {
1799 if (windowNode == nullptr || windowNode->GetWindowToken() == nullptr ||
1800 windowNode->GetWindowId() == skipNodeId ||
1801 windowNode->GetWindowId() == node->GetWindowId()) {
1802 WLOGFD("continue %{public}s", windowNode == nullptr ? "nullptr" : windowNode->GetWindowName().c_str());
1803 continue;
1804 }
1805 WLOGFD("notify %{public}s id %{public}d", windowNode->GetWindowName().c_str(), windowNode->GetWindowId());
1806 windowNode->GetWindowToken()->NotifyTouchOutside();
1807 }
1808 }
1809
GetEmbedNodeId(const std::vector<sptr<WindowNode>> & windowNodes,const sptr<WindowNode> & node)1810 uint32_t WindowController::GetEmbedNodeId(const std::vector<sptr<WindowNode>>& windowNodes,
1811 const sptr<WindowNode>& node)
1812 {
1813 if (node->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
1814 return 0;
1815 }
1816
1817 Rect nodeRect = node->GetWindowRect();
1818 bool isSkip = true;
1819 for (auto& windowNode : windowNodes) {
1820 if (windowNode == nullptr) {
1821 continue;
1822 }
1823 if (windowNode->GetWindowId() == node->GetWindowId()) {
1824 isSkip = false;
1825 continue;
1826 }
1827 if (isSkip) {
1828 continue;
1829 }
1830 if (nodeRect.IsInsideOf(windowNode->GetWindowRect())) {
1831 WLOGI("TouchOutside window type is component %{public}s windowNode %{public}d",
1832 windowNode->GetWindowName().c_str(), windowNode->GetWindowId());
1833 return windowNode->GetWindowId();
1834 }
1835 }
1836 return 0;
1837 }
1838
MinimizeWindowsByLauncher(std::vector<uint32_t> & windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)1839 void WindowController::MinimizeWindowsByLauncher(std::vector<uint32_t>& windowIds, bool isAnimated,
1840 sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
1841 {
1842 windowRoot_->MinimizeTargetWindows(windowIds);
1843 auto func = []() {
1844 MinimizeApp::ExecuteMinimizeTargetReasons(MinimizeReason::GESTURE_ANIMATION);
1845 };
1846 if (!isAnimated) {
1847 WLOGFD("no animation minimize size: %{public}u", static_cast<uint32_t>(windowIds.size()));
1848 func();
1849 } else {
1850 WLOGFD("animation minimize size: %{public}u", static_cast<uint32_t>(windowIds.size()));
1851 auto needMinimizeAppNodes = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::GESTURE_ANIMATION);
1852 for (auto& weakNode : needMinimizeAppNodes) {
1853 auto node = weakNode.promote();
1854 if (node) {
1855 // gesture animation no need to play default animation when minimize
1856 node->isPlayAnimationHide_ = true;
1857 }
1858 }
1859 finishCallback = RemoteAnimation::CreateAnimationFinishedCallback(func, nullptr);
1860 if (finishCallback == nullptr) {
1861 return;
1862 }
1863 }
1864 }
1865
OnScreenshot(DisplayId displayId)1866 void WindowController::OnScreenshot(DisplayId displayId)
1867 {
1868 std::vector<sptr<WindowNode>> windowNodes;
1869 windowRoot_->GetForegroundNodes(windowNodes);
1870 for (auto& windowNode : windowNodes) {
1871 auto windowToken = windowNode->GetWindowToken();
1872 if (windowToken != nullptr) {
1873 windowToken->NotifyScreenshot();
1874 }
1875 }
1876 }
1877
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1878 void WindowController::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1879 {
1880 displayZoomController_->SetAnchorOffset(deltaX, deltaY);
1881 DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1882 FlushWindowInfoWithDisplayId(displayId);
1883 }
1884
OffWindowZoom()1885 void WindowController::OffWindowZoom()
1886 {
1887 displayZoomController_->OffWindowZoom();
1888 DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1889 FlushWindowInfoWithDisplayId(displayId);
1890 }
1891
SetAnchorAndScale(int32_t x,int32_t y,float scale)1892 void WindowController::SetAnchorAndScale(int32_t x, int32_t y, float scale)
1893 {
1894 displayZoomController_->SetAnchorAndScale(x, y, scale);
1895 DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1896 FlushWindowInfoWithDisplayId(displayId);
1897 }
1898
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)1899 WMError WindowController::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
1900 {
1901 auto node = windowRoot_->GetWindowNode(windowId);
1902 if (node == nullptr) {
1903 WLOGFE("could not find window");
1904 return WMError::WM_ERROR_NULLPTR;
1905 }
1906
1907 node->dialogTargetToken_ = targetToken;
1908
1909 return WMError::WM_OK;
1910 }
1911
SetDragFrameGravity(int32_t dragGravity)1912 void WindowController::SetDragFrameGravity(int32_t dragGravity)
1913 {
1914 dragFrameGravity_ = dragGravity;
1915 }
1916 } // namespace OHOS
1917 } // namespace Rosen
1918