• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "starting_window.h"
39 #include "window_inner_manager.h"
40 #include "window_manager_hilog.h"
41 #include "window_helper.h"
42 #include "window_system_effect.h"
43 #include "wm_common.h"
44 #include "wm_math.h"
45 #include "permission.h"
46 
47 namespace OHOS {
48 namespace Rosen {
49 namespace {
50 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Controller"};
51 constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 50;
52 constexpr float MASKING_SURFACE_NODE_Z_ORDER = 9999;
53 }
54 
GenWindowId()55 uint32_t WindowController::GenWindowId()
56 {
57     return ++windowId_;
58 }
59 
StartingWindow(sptr<WindowTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bkgColor,bool isColdStart)60 void WindowController::StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
61     uint32_t bkgColor, bool isColdStart)
62 {
63     if (!info || info->GetAbilityToken() == nullptr) {
64         TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "info or AbilityToken is nullptr!");
65         return;
66     }
67     StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::STARTING_WINDOW),
68         "wms:async:ShowStartingWindow");
69     auto node = windowRoot_->FindWindowNodeWithToken(info->GetAbilityToken());
70     if (node == nullptr) {
71         if (!isColdStart) {
72             TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "no windowNode exists but is hot start!");
73             return;
74         }
75         node = StartingWindow::CreateWindowNode(info, GenWindowId());
76         if (node == nullptr) {
77             return;
78         }
79         if (windowRoot_->SaveWindow(node) != WMError::WM_OK) {
80             return;
81         }
82         if (!RemoteAnimation::CheckAnimationController()) {
83             UpdateWindowAnimation(node);
84         }
85     } else {
86         if (node->stateMachine_.IsWindowNodeShownOrShowing()) {
87             TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "WindowId: %{public}u state: %{public}u!",
88                 node->GetWindowId(), static_cast<uint32_t>(node->stateMachine_.GetCurrentState()));
89             return;
90         }
91         if (WindowHelper::IsValidWindowMode(info->GetWindowMode()) &&
92             (node->GetWindowMode() != info->GetWindowMode())) {
93             TLOGI(WmsLogTag::WMS_STARTUP_PAGE,
94                 "set starting window mode. starting mode is: %{public}u, window mode is: %{public}u.",
95                 node->GetWindowMode(), info->GetWindowMode());
96             node->SetWindowMode(info->GetWindowMode());
97         }
98     }
99 
100     if (!WindowHelper::CheckSupportWindowMode(node->GetWindowMode(), node->GetWindowModeSupportType(), info)) {
101         TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "need to cancel starting window");
102         return;
103     }
104 
105     if (windowRoot_->AddWindowNode(0, node, true) != WMError::WM_OK) {
106         return;
107     }
108     StartingWindow::DrawStartingWindow(node, pixelMap, bkgColor, isColdStart);
109     FlushWindowInfo(node->GetWindowId());
110     node->startingWindowShown_ = true;
111     TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "Show success, id:%{public}u!", node->GetWindowId());
112 }
113 
CancelStartingWindow(sptr<IRemoteObject> abilityToken)114 void WindowController::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
115 {
116     auto node = windowRoot_->FindWindowNodeWithToken(abilityToken);
117     if (node == nullptr) {
118         TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "Node is nullptr");
119         return;
120     }
121     if (!node->startingWindowShown_) {
122         TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "failed because client window has shown id:%{public}u",
123             node->GetWindowId());
124         return;
125     }
126     HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CancelStartingWindow(%u)", node->GetWindowId());
127     FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::STARTING_WINDOW),
128         "wms:async:ShowStartingWindow");
129     TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "Id:%{public}u!", node->GetWindowId());
130     node->isAppCrash_ = true;
131     WMError res = DestroyWindow(node->GetWindowId(), false);
132     if (res != WMError::WM_OK) {
133         TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "DestroyWindow failed!");
134     }
135 }
136 
NotifyWindowTransition(sptr<WindowTransitionInfo> & srcInfo,sptr<WindowTransitionInfo> & dstInfo)137 WMError WindowController::NotifyWindowTransition(sptr<WindowTransitionInfo>& srcInfo,
138     sptr<WindowTransitionInfo>& dstInfo)
139 {
140     TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "begin!");
141     sptr<WindowNode> dstNode = nullptr;
142     sptr<WindowNode> srcNode = nullptr;
143     if (srcInfo) {
144         srcNode = windowRoot_->FindWindowNodeWithToken(srcInfo->GetAbilityToken());
145     }
146     if (dstInfo) {
147         dstNode = windowRoot_->FindWindowNodeWithToken(dstInfo->GetAbilityToken());
148     }
149     if (!RemoteAnimation::CheckTransition(srcInfo, srcNode, dstInfo, dstNode)) {
150         return WMError::WM_ERROR_NO_REMOTE_ANIMATION;
151     }
152     StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::REMOTE_ANIMATION),
153         "wms:async:ShowRemoteAnimation");
154     auto transitionEvent = RemoteAnimation::GetTransitionEvent(srcInfo, dstInfo, srcNode, dstNode);
155     switch (transitionEvent) {
156         case TransitionEvent::APP_TRANSITION: {
157             return RemoteAnimation::NotifyAnimationTransition(srcInfo, dstInfo, srcNode, dstNode);
158         }
159         case TransitionEvent::MINIMIZE:
160             return RemoteAnimation::NotifyAnimationMinimize(srcInfo, srcNode);
161         case TransitionEvent::CLOSE:
162         case TransitionEvent::CLOSE_BUTTON:
163             return RemoteAnimation::NotifyAnimationClose(srcInfo, srcNode, transitionEvent);
164         case TransitionEvent::BACK_TRANSITION:
165         case TransitionEvent::BACKGROUND_TRANSITION:
166             return RemoteAnimation::NotifyAnimationBackTransition(srcInfo, dstInfo, srcNode, dstNode, transitionEvent);
167         default:
168             return WMError::WM_ERROR_NO_REMOTE_ANIMATION;
169     }
170     return WMError::WM_OK;
171 }
172 
GetFocusWindowNode(DisplayId displayId,sptr<WindowNode> & windowNode)173 WMError WindowController::GetFocusWindowNode(DisplayId displayId, sptr<WindowNode>& windowNode)
174 {
175     auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
176     if (windowNodeContainer == nullptr) {
177         WLOGFE("Container is null, displayId: %{public}" PRIu64"", displayId);
178         return WMError::WM_ERROR_NULLPTR;
179     }
180     uint32_t focusWindowId = windowNodeContainer->GetFocusWindow();
181     WLOGFD("Now focusId: %{public}u", focusWindowId);
182     auto thisWindowNode = windowRoot_->GetWindowNode(focusWindowId);
183     if (thisWindowNode == nullptr || !thisWindowNode->currentVisibility_) {
184         WLOGFE("Node is null or invisible, id: %{public}u", focusWindowId);
185         return WMError::WM_ERROR_INVALID_WINDOW;
186     }
187     windowNode = thisWindowNode;
188     return WMError::WM_OK;
189 }
190 
GetFocusWindowInfo(sptr<IRemoteObject> & abilityToken)191 WMError WindowController::GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken)
192 {
193     DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
194     sptr<WindowNode> windowNode;
195     WMError res = GetFocusWindowNode(displayId, windowNode);
196     if (res == WMError::WM_OK) {
197         abilityToken = windowNode->abilityToken_;
198     }
199     return res;
200 }
201 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)202 WMError WindowController::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
203 {
204     DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
205     sptr<WindowNode> windowNode;
206     WMError res = GetFocusWindowNode(displayId, windowNode);
207     if (res == WMError::WM_OK) {
208         WLOGFD("Get focus window info success");
209         focusInfo.windowId_ = static_cast<int32_t>(windowNode->GetWindowId());
210         focusInfo.displayId_ = windowNode->GetDisplayId();
211         focusInfo.pid_ = windowNode->GetCallingPid();
212         focusInfo.uid_ = windowNode->GetCallingUid();
213         focusInfo.windowType_ = windowNode->GetWindowType();
214         focusInfo.abilityToken_ = windowNode->abilityToken_;
215     }
216     return res;
217 }
218 
CheckParentWindowValid(const sptr<WindowProperty> & property)219 bool WindowController::CheckParentWindowValid(const sptr<WindowProperty>& property)
220 {
221     if (WindowHelper::IsSubWindow(property->GetWindowType())) {
222         if (property->GetParentId() == INVALID_WINDOW_ID) {
223             WLOGFE("failed, sub window parent type is invalid");
224             return false;
225         }
226         sptr<WindowNode> parentWindow = windowRoot_->GetWindowNode(property->GetParentId());
227         if (parentWindow == nullptr) {
228             WLOGFE("failed, sub window parent type is error");
229             return false;
230         }
231     } else if (WindowHelper::IsSystemSubWindow(property->GetWindowType())) {
232         if (property->GetParentId() == INVALID_WINDOW_ID) {
233             WLOGFE("failed, sub system window parent type is invalid");
234             return false;
235         }
236         sptr<WindowNode> parentWindow = windowRoot_->GetWindowNode(property->GetParentId());
237         if (parentWindow == nullptr || !WindowHelper::IsSystemWindow(parentWindow->GetWindowType())) {
238             WLOGFE("failed, sub system window parent type is error");
239             return false;
240         }
241     } else {
242         if (property->GetParentId() != INVALID_WINDOW_ID) {
243             WLOGFE("failed, type is error");
244             return false;
245         }
246     }
247     return true;
248 }
249 
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)250 WMError WindowController::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
251     const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token,
252     int32_t pid, int32_t uid)
253 {
254     if (!CheckParentWindowValid(property)) {
255         return WMError::WM_ERROR_INVALID_PARENT;
256     }
257 
258     if (!surfaceNode) {
259         return WMError::WM_ERROR_NULLPTR;
260     }
261 
262     if (property->GetWindowType() != WindowType::WINDOW_TYPE_BOOT_ANIMATION) {
263         surfaceNode->SetFrameGravity(Gravity::RESIZE);
264     }
265 
266     sptr<WindowNode> node = windowRoot_->FindWindowNodeWithToken(token);
267     if (node != nullptr && WindowHelper::IsMainWindow(property->GetWindowType()) && node->startingWindowShown_) {
268         StartingWindow::HandleClientWindowCreate(node, window, windowId, surfaceNode, property, pid, uid);
269         windowRoot_->AddDeathRecipient(node);
270         windowRoot_->AddSurfaceNodeIdWindowNodePair(surfaceNode->GetId(), node);
271         WLOGFD("Flags: %{public}u, API version: %{public}u", property->GetWindowFlags(),
272             node->GetWindowProperty()->GetApiCompatibleVersion());
273         if (property->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED) &&
274             node->GetWindowProperty()->GetApiCompatibleVersion() >= 9 && !property->isSystemCalling_) { // 9: API ver.
275             property->SetWindowFlags(property->GetWindowFlags() &
276                 ~static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
277         }
278         property->SetApiCompatibleVersion(node->GetWindowProperty()->GetApiCompatibleVersion());
279         return WMError::WM_OK;
280     }
281 
282     windowId = GenWindowId();
283     sptr<WindowProperty> windowProperty = new WindowProperty(property);
284     windowProperty->SetWindowId(windowId);
285     node = new WindowNode(windowProperty, window, surfaceNode, pid, uid);
286     node->abilityToken_ = token;
287     node->dialogTargetToken_ = token;
288     UpdateWindowAnimation(node);
289     // for system and subwindow
290     WindowSystemEffect::SetWindowEffect(node);
291     WLOGFD("createWindow id:%{public}u", windowId);
292 
293     node->stateMachine_.SetWindowId(windowId);
294     node->stateMachine_.SetWindowType(property->GetWindowType());
295     return windowRoot_->SaveWindow(node);
296 }
297 
NotifyAfterAddWindow(sptr<WindowNode> & node)298 void WindowController::NotifyAfterAddWindow(sptr<WindowNode>& node)
299 {
300     std::vector<sptr<WindowNode>> nodes;
301     nodes.emplace_back(node);
302     for (auto& child : node->children_) {
303         if (child->currentVisibility_) {
304             nodes.emplace_back(child);
305         }
306     }
307     for (auto& iter : nodes) {
308         if ((iter->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) &&
309             (node->abilityToken_ != iter->abilityToken_)) {
310             iter->GetWindowToken()->NotifyForeground();
311         }
312     }
313     accessibilityConnection_->NotifyAccessibilityWindowInfo(node->GetDisplayId(), nodes,
314         WindowUpdateType::WINDOW_UPDATE_ADDED);
315 }
316 
AddWindowNode(sptr<WindowProperty> & property)317 WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
318 {
319     auto node = windowRoot_->GetWindowNode(property->GetWindowId());
320     if (node == nullptr) {
321         WLOGFE("could not find window");
322         return WMError::WM_ERROR_NULLPTR;
323     }
324 
325     if (node->currentVisibility_ && !node->startingWindowShown_) {
326         WLOGFE("Current window is visible, windowId: %{public}u", node->GetWindowId());
327         return WMError::WM_ERROR_INVALID_OPERATION;
328     }
329 
330     // using starting window rect if client rect is empty
331     if (WindowHelper::IsEmptyRect(property->GetRequestRect()) && node->startingWindowShown_) { // for tile and cascade
332         property->SetRequestRect(node->GetRequestRect());
333         property->SetWindowRect(node->GetWindowRect());
334         property->SetDecoStatus(true);
335     }
336     node->GetWindowProperty()->CopyFrom(property);
337     UpdateWindowAnimation(node);
338 
339     RelayoutKeyboard(node);
340     WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node);
341     if (res != WMError::WM_OK) {
342         MinimizeApp::ClearNodesWithReason(MinimizeReason::OTHER_WINDOW);
343         return res;
344     }
345     windowRoot_->FocusFaultDetection();
346 
347     FlushWindowInfo(property->GetWindowId());
348     NotifyAfterAddWindow(node);
349     HandleTurnScreenOn(node);
350 
351     if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
352         sysBarWinId_[node->GetWindowType()] = node->GetWindowId();
353     }
354     if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
355         ResizeSoftInputCallingWindowIfNeed(node);
356     }
357     StopBootAnimationIfNeed(node);
358     // when hide with remote animation first and show with default animation, need transform state
359     // minimize should execute in finish callback when remote animation enabled
360     if (!node->stateMachine_.IsShowAnimationPlaying()) {
361         if (WindowHelper::IsMainWindow(node->GetWindowType())) {
362             MinimizeApp::ExecuteMinimizeAll();
363             WLOGI("Id:%{public}u execute minimize all", node->GetWindowId());
364         }
365         node->stateMachine_.TransitionTo(WindowNodeState::SHOWN); // for normal show which not use remote animation
366     } else if (WindowHelper::IsMainWindow(node->GetWindowType())) {
367         MinimizeApp::ExecuteMinimizeTargetReasons(~MinimizeReason::OTHER_WINDOW);
368     }
369 
370     return WMError::WM_OK;
371 }
372 
GetNavigationBarHeight(DisplayId displayId,uint32_t & navigationBarHeight)373 bool WindowController::GetNavigationBarHeight(DisplayId displayId, uint32_t& navigationBarHeight)
374 {
375     auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
376     if (container == nullptr) {
377         WLOGFE("Node container is null");
378         return false;
379     }
380 
381     bool hasFullScreenKeyGuardWindow = false;
382     WindowNodeOperationFunc func = [&navigationBarHeight, &hasFullScreenKeyGuardWindow](sptr<WindowNode> windowNode) {
383         if (!windowNode) {
384             WLOGFE("The window node is nullptr.");
385             return false;
386         }
387         if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD &&
388             windowNode->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
389                 hasFullScreenKeyGuardWindow = true;
390         }
391         if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR &&
392             windowNode->GetVisibilityState() < WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
393             navigationBarHeight = windowNode->GetWindowRect().height_;
394             if (hasFullScreenKeyGuardWindow) {
395                 WLOGFW("The navigation bar is overlaid by the keyguard window and is invisible");
396                 navigationBarHeight = 0;
397             }
398             return true;
399         }
400         return false;
401     };
402     container->TraverseWindowTree(func, true); // FromTopToBottom
403 
404     return true;
405 }
406 
RelayoutKeyboard(const sptr<WindowNode> & node)407 void WindowController::RelayoutKeyboard(const sptr<WindowNode>& node)
408 {
409     if (node == nullptr) {
410         WLOGFE("Node is nullptr");
411         return;
412     }
413     WindowGravity gravity;
414     uint32_t percent = 0;
415     node->GetWindowGravity(gravity, percent);
416     if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT ||
417         gravity == WindowGravity::WINDOW_GRAVITY_FLOAT) {
418         return;
419     }
420 
421     auto container = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
422     if (container == nullptr) {
423         WLOGFE("Node container is null");
424         return;
425     }
426 
427     uint32_t navigationBarHeight = 0;
428     bool res = GetNavigationBarHeight(node->GetDisplayId(), navigationBarHeight);
429     if (res == false) {
430         return;
431     }
432 
433     sptr<DisplayInfo> defaultDisplayInfo = DisplayGroupInfo::GetInstance().GetDefaultDisplayInfo();
434     if (defaultDisplayInfo == nullptr) {
435         WLOGFE("defaultDisplayInfo is null");
436         return;
437     }
438 
439     auto requestRect = node->GetRequestRect();
440     if (gravity == WindowGravity::WINDOW_GRAVITY_BOTTOM) {
441         if (percent != 0) {
442             requestRect.width_ = static_cast<uint32_t>(defaultDisplayInfo->GetWidth());
443             requestRect.height_ =
444                 static_cast<uint32_t>(defaultDisplayInfo->GetHeight()) * percent / 100u; // 100: for calc percent.
445             requestRect.posX_ = 0;
446         }
447     }
448     requestRect.posY_ = defaultDisplayInfo->GetHeight() -
449         static_cast<int32_t>(requestRect.height_ + navigationBarHeight);
450     node->SetRequestRect(requestRect);
451 }
452 
NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode> & callingWindow,const Rect & rect,const Rect & occupiedArea)453 void WindowController::NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode>& callingWindow,
454     const Rect& rect, const Rect& occupiedArea)
455 {
456     if (callingWindow->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
457         // update calling window rect
458         callingWindow->SetWindowRect(rect);
459         WindowLayoutPolicy::CalcAndSetNodeHotZone(rect, callingWindow);
460 
461         // set bounds and do animation for calling window
462         wptr<WindowNode> weakNode = callingWindow;
463         auto setBoundsFun = [weakNode, rect]() {
464             auto winNode = weakNode.promote();
465             if (winNode == nullptr) {
466                 WLOGFW("Window node is nullptr");
467                 return;
468             }
469             if (winNode->leashWinSurfaceNode_) {
470                 winNode->leashWinSurfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_);
471                 if (winNode->startingWinSurfaceNode_) {
472                     winNode->startingWinSurfaceNode_->SetBounds(0, 0, rect.width_, rect.height_);
473                 }
474                 if (winNode->surfaceNode_) {
475                     winNode->surfaceNode_->SetBounds(0, 0, rect.width_, rect.height_);
476                 }
477             } else {
478                 if (winNode->surfaceNode_) {
479                     winNode->surfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_);
480                 }
481             }
482         };
483 
484         const AnimationConfig::KeyboardAnimation& animation = WindowHelper::IsEmptyRect(occupiedArea) ?
485             WindowNodeContainer::GetAnimationConfigRef().keyboardAnimationOut_ :
486             WindowNodeContainer::GetAnimationConfigRef().keyboardAnimationIn_;
487         RSNode::Animate(animation.duration_, animation.curve_, setBoundsFun);
488     }
489 
490     // if keyboard will occupy calling, notify calling window the occupied area and safe height
491     const Rect& safeRect = WindowHelper::GetOverlap(occupiedArea, rect, 0, 0);
492     sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT,
493         safeRect, safeRect.height_);
494 
495     if (WindowNodeContainer::GetAnimateTransactionEnabled()) {
496         auto syncTransactionController = RSSyncTransactionController::GetInstance();
497         if (syncTransactionController) {
498             callingWindow->GetWindowToken()->UpdateOccupiedAreaAndRect(info, rect,
499                 syncTransactionController->GetRSTransaction());
500         }
501     } else {
502         callingWindow->GetWindowToken()->UpdateOccupiedAreaAndRect(info, rect);
503     }
504 
505     FlushWindowInfo(callingWindow->GetWindowId());
506     accessibilityConnection_->NotifyAccessibilityWindowInfo(callingWindow, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
507     WLOGFD("Calling windowId: %{public}u, calling winRect: [%{public}d, %{public}d, %{public}u, %{public}u], "
508         "occupiedArea: [%{public}d, %{public}d, %{public}u, %{public}u], safeHeight: %{public}u",
509         callingWindow->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_,
510         occupiedArea.posX_, occupiedArea.posY_, occupiedArea.width_, occupiedArea.height_, safeRect.height_);
511 }
512 
ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode> & node)513 void WindowController::ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode>& node)
514 {
515     auto callingWindowId = node->GetCallingWindow();
516     auto callingWindow = windowRoot_->GetWindowNode(callingWindowId);
517     if (callingWindow == nullptr) {
518         auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
519         if (windowNodeContainer == nullptr) {
520             WLOGFE("NodeContainer is null, displayId:%{public}" PRIu64"", node->GetDisplayId());
521             return;
522         }
523         callingWindowId = windowNodeContainer->GetFocusWindow();
524         callingWindow = windowRoot_->GetWindowNode(callingWindowId);
525     }
526     if (callingWindow == nullptr || !callingWindow->currentVisibility_ ||
527         callingWindow->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) {
528         WLOGFE("callingWindow is null or invisible or not float window, callingWindowId:%{public}u", callingWindowId);
529         return;
530     }
531     WindowGravity gravity;
532     uint32_t percent = 0;
533     node->GetWindowGravity(gravity, percent);
534     if (gravity != WindowGravity::WINDOW_GRAVITY_BOTTOM) {
535         WLOGFI("input method window gravity is not bottom, no need to raise calling window");
536         return;
537     }
538 
539     const Rect& softInputWindowRect = node->GetWindowRect();
540     const Rect& callingWindowRect = callingWindow->GetWindowRect();
541     if (WindowHelper::IsEmptyRect(WindowHelper::GetOverlap(softInputWindowRect, callingWindowRect, 0, 0))) {
542         WLOGFD("There is no overlap area");
543         return;
544     }
545 
546     // calculate new rect of calling window
547     Rect newRect = callingWindowRect;
548     if (callingWindow->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
549         newRect.posY_ = softInputWindowRect.posY_ - static_cast<int32_t>(newRect.height_);
550         Rect statusBarWindowRect = { 0, 0, 0, 0 };
551         auto statusbarWindow = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]);
552         if (statusbarWindow != nullptr && statusbarWindow->parent_ != nullptr) {
553             statusBarWindowRect = statusbarWindow->GetWindowRect();
554         }
555         newRect.posY_ = std::max(newRect.posY_,
556             statusBarWindowRect.posY_ + static_cast<int32_t>(statusBarWindowRect.height_));
557 
558         callingWindowRestoringRect_ = callingWindowRect;
559         callingWindowId_ = callingWindow->GetWindowId();
560     }
561 
562     NotifyInputCallingWindowRectAndOccupiedAreaChange(callingWindow, newRect, softInputWindowRect);
563 }
564 
RestoreCallingWindowSizeIfNeed()565 void WindowController::RestoreCallingWindowSizeIfNeed()
566 {
567     auto callingWindow = windowRoot_->GetWindowNode(callingWindowId_);
568     if (!WindowHelper::IsEmptyRect(callingWindowRestoringRect_) && callingWindow != nullptr &&
569         callingWindow->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING) {
570         Rect overlapRect = { 0, 0, 0, 0 };
571         NotifyInputCallingWindowRectAndOccupiedAreaChange(callingWindow, callingWindowRestoringRect_, overlapRect);
572     }
573     callingWindowRestoringRect_ = { 0, 0, 0, 0 };
574     callingWindowId_ = 0u;
575 }
576 
HandleTurnScreenOn(const sptr<WindowNode> & node)577 void WindowController::HandleTurnScreenOn(const sptr<WindowNode>& node)
578 {
579     if (node == nullptr) {
580         WLOGFE("Node is nullptr");
581         return;
582     }
583     WLOGFD("Win: %{public}s, is turn on%{public}d", node->GetWindowName().c_str(), node->IsTurnScreenOn());
584 #ifdef POWER_MANAGER_ENABLE
585     // reset ipc identity
586     std::string identity = IPCSkeleton::ResetCallingIdentity();
587     if (node->IsTurnScreenOn() && !PowerMgr::PowerMgrClient::GetInstance().IsScreenOn()) {
588         WLOGI("turn screen on");
589         PowerMgr::PowerMgrClient::GetInstance().WakeupDevice();
590     }
591     // set ipc identity to raw
592     IPCSkeleton::SetCallingIdentity(identity);
593 #endif
594 }
595 
RemoveWindowNode(uint32_t windowId,bool fromAnimation)596 WMError WindowController::RemoveWindowNode(uint32_t windowId, bool fromAnimation)
597 {
598     auto windowNode = windowRoot_->GetWindowNode(windowId);
599     if (windowNode == nullptr) {
600         WLOGFE("Could not find window");
601         return WMError::WM_ERROR_NULLPTR;
602     }
603     auto removeFunc = [this, windowId, windowNode, fromAnimation]() {
604         WMError res = windowRoot_->RemoveWindowNode(windowId, fromAnimation);
605         if (res != WMError::WM_OK) {
606             WLOGFE("RemoveWindowNode failed");
607             return res;
608         }
609         windowRoot_->FocusFaultDetection();
610         FlushWindowInfo(windowId);
611         std::vector<sptr<WindowNode>> nodes;
612         nodes.emplace_back(windowNode);
613         for (auto& child : windowNode->children_) {
614             nodes.emplace_back(child);
615         }
616         for (auto& iter : nodes) {
617             if ((iter->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) &&
618                 (windowNode->abilityToken_ != iter->abilityToken_)) {
619                 iter->GetWindowToken()->NotifyBackground();
620             }
621         }
622         displayZoomController_->ClearZoomTransform(nodes);
623         accessibilityConnection_->NotifyAccessibilityWindowInfo(windowNode->GetDisplayId(), nodes,
624             WindowUpdateType::WINDOW_UPDATE_REMOVED);
625         return res;
626     };
627     WMError res = WMError::WM_ERROR_NO_REMOTE_ANIMATION;
628     if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
629         // if has main full screen window, no need to do remote unlock animation
630         if (windowRoot_->NotifyDesktopUnfrozen() == WMError::WM_OK &&
631             !windowRoot_->HasMainFullScreenWindowShown(windowNode->GetDisplayId())) {
632             res = RemoteAnimation::NotifyAnimationScreenUnlock(removeFunc, windowNode);
633             WLOGI("NotifyAnimationScreenUnlock with remote animation");
634         }
635     }
636     if (res != WMError::WM_OK) {
637         res = removeFunc();
638     }
639     if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
640         RestoreCallingWindowSizeIfNeed();
641     }
642     if (!windowNode->stateMachine_.IsHideAnimationPlaying()) {
643         windowNode->stateMachine_.TransitionTo(WindowNodeState::HIDDEN);
644     }
645     return res;
646 }
647 
DestroyWindow(uint32_t windowId,bool onlySelf)648 WMError WindowController::DestroyWindow(uint32_t windowId, bool onlySelf)
649 {
650     DisplayId displayId = DISPLAY_ID_INVALID;
651     auto node = windowRoot_->GetWindowNode(windowId);
652     if (node == nullptr) {
653         WLOGFE("Destroy window %{public}u failed.", windowId);
654         return WMError::WM_ERROR_NULLPTR;
655     }
656     sptr<WindowNode> parent = node->parent_;
657     displayId = node->GetDisplayId();
658     WMError res = windowRoot_->DestroyWindow(windowId, onlySelf);
659     if (res != WMError::WM_OK) {
660         return res;
661     }
662     if (node->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) {
663         if ((parent != nullptr) && WindowHelper::IsSplitWindowMode(parent->GetWindowMode())) {
664             auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId);
665             windowNodeContainer->RaiseSplitRelatedWindowToTop(parent);
666         }
667     }
668     windowRoot_->FocusFaultDetection();
669     FlushWindowInfoWithDisplayId(displayId);
670     std::vector<sptr<WindowNode>> nodes;
671     nodes.emplace_back(node);
672     for (auto& child : node->children_) {
673         nodes.emplace_back(child);
674     }
675     accessibilityConnection_->NotifyAccessibilityWindowInfo(node->GetDisplayId(), nodes,
676         WindowUpdateType::WINDOW_UPDATE_REMOVED);
677     node->stateMachine_.TransitionTo(WindowNodeState::DESTROYED);
678     return res;
679 }
680 
ResizeRect(uint32_t windowId,const Rect & rect,WindowSizeChangeReason reason)681 WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason)
682 {
683     auto node = windowRoot_->GetWindowNode(windowId);
684     if (node == nullptr) {
685         WLOGFE("could not find window");
686         return WMError::WM_ERROR_NULLPTR;
687     }
688     if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) {
689         WLOGFE("fullscreen window could not resize");
690         return WMError::WM_ERROR_INVALID_OPERATION;
691     }
692     /*
693      *  if requestRect of systemBar equals to winRect, not need to resize. This may happen when rotate display
694      */
695     bool isMove = IsMoveToOrDragMove(reason);
696     if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
697         if ((isMove || reason == WindowSizeChangeReason::RESIZE) && rect == node->GetWindowRect()) {
698             return WMError::WM_OK;
699         }
700     }
701     auto property = node->GetWindowProperty();
702     node->SetWindowSizeChangeReason(reason);
703     Rect lastRect = property->GetWindowRect();
704     Rect newRect;
705     if (isMove) {
706         newRect = { rect.posX_, rect.posY_, lastRect.width_, lastRect.height_ };
707         if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
708             if (windowRoot_->IsForbidDockSliceMove(node->GetDisplayId())) {
709                 WLOGI("dock slice is forbidden to move");
710                 newRect = lastRect;
711             } else if (windowRoot_->IsVerticalDisplay(node)) {
712                 newRect.posX_ = lastRect.posX_;
713             } else {
714                 newRect.posY_ = lastRect.posY_;
715             }
716         }
717     } else if (reason == WindowSizeChangeReason::RESIZE) {
718         newRect = { lastRect.posX_, lastRect.posY_, rect.width_, rect.height_ };
719     } else if (reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::MAXIMIZE) {
720         newRect = rect;
721     }
722     property->SetRequestRect(newRect);
723     if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT &&
724         (reason == WindowSizeChangeReason::RESIZE || isMove)) {
725         RelayoutKeyboard(node);
726         ResizeSoftInputCallingWindowIfNeed(node);
727     }
728     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
729     if (res != WMError::WM_OK) {
730         return res;
731     }
732     accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
733     return WMError::WM_OK;
734 }
735 
ResizeRectAndFlush(uint32_t windowId,const Rect & rect,WindowSizeChangeReason reason)736 WMError WindowController::ResizeRectAndFlush(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason)
737 {
738     WMError res = ResizeRect(windowId, rect, reason);
739     if (res != WMError::WM_OK) {
740         return res;
741     } else {
742         FlushWindowInfo(windowId);
743         return WMError::WM_OK;
744     }
745 }
746 
RequestFocus(uint32_t windowId)747 WMError WindowController::RequestFocus(uint32_t windowId)
748 {
749     if (windowRoot_ == nullptr) {
750         return WMError::WM_ERROR_NULLPTR;
751     }
752     WMError res = windowRoot_->RequestFocus(windowId);
753     FlushWindowInfo(windowId);
754     accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
755         WindowUpdateType::WINDOW_UPDATE_FOCUSED);
756     return res;
757 }
758 
SetWindowMode(uint32_t windowId,WindowMode dstMode)759 WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode dstMode)
760 {
761     HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER);
762     auto node = windowRoot_->GetWindowNode(windowId);
763     if (node == nullptr) {
764         WLOGFE("could not find window");
765         return WMError::WM_ERROR_NULLPTR;
766     }
767     WMError ret = windowRoot_->SetWindowMode(node, dstMode);
768     if (ret != WMError::WM_OK) {
769         return ret;
770     }
771     FlushWindowInfo(windowId);
772     accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
773     if (!node->stateMachine_.IsShowAnimationPlaying()) {
774         if (WindowHelper::IsMainWindow(node->GetWindowType())) {
775             MinimizeApp::ExecuteMinimizeAll();
776             WLOGI("id:%{public}u execute minimize all", node->GetWindowId());
777         }
778     }
779     return WMError::WM_OK;
780 }
781 
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)782 void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
783     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
784 {
785     WLOGFD("NotifyDisplayStateChange start: %{public}u", type);
786     switch (type) {
787         case DisplayStateChangeType::BEFORE_SUSPEND: {
788             isScreenLocked_ = true;
789             windowRoot_->ProcessWindowStateChange(WindowState::STATE_FROZEN, WindowStateChangeReason::KEYGUARD);
790             break;
791         }
792         case DisplayStateChangeType::BEFORE_UNLOCK: {
793             windowRoot_->ProcessWindowStateChange(WindowState::STATE_UNFROZEN, WindowStateChangeReason::KEYGUARD);
794             isScreenLocked_ = false;
795             break;
796         }
797         case DisplayStateChangeType::CREATE: {
798             SetDefaultDisplayInfo(defaultDisplayId, displayInfo);
799             windowRoot_->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayInfoMap);
800             FlushWindowInfoWithDisplayId(displayInfo->GetDisplayId());
801             break;
802         }
803         case DisplayStateChangeType::DESTROY: {
804             windowRoot_->ProcessDisplayDestroy(defaultDisplayId, displayInfo, displayInfoMap);
805             FlushWindowInfoWithDisplayId(defaultDisplayId);
806             break;
807         }
808         case DisplayStateChangeType::DISPLAY_COMPRESS:
809         case DisplayStateChangeType::SIZE_CHANGE:
810         case DisplayStateChangeType::UPDATE_ROTATION:
811         case DisplayStateChangeType::UPDATE_ROTATION_FROM_WINDOW:
812         case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: {
813             ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type);
814             /*
815              * Window tile num may change when display rotate or change size, need to execute minimize
816              */
817             MinimizeApp::ExecuteMinimizeTargetReasons(MinimizeReason::LAYOUT_TILE);
818             break;
819         }
820         default: {
821             WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
822             return;
823         }
824     }
825     WLOGFD("NotifyDisplayStateChange end, type: %{public}u", type);
826 }
827 
SetDefaultDisplayInfo(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo)828 void WindowController::SetDefaultDisplayInfo(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo)
829 {
830     if (displayInfo == nullptr) {
831         WLOGFE("display is null");
832         return;
833     }
834     if (displayInfo->GetDisplayId() != defaultDisplayId) {
835         return;
836     }
837     WLOGI("Set defaultDisplayInfo");
838     auto displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
839     auto displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
840     defaultDisplayRect_ = { 0, 0, displayWidth, displayHeight };
841 }
842 
ProcessDisplayChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)843 void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
844     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
845 {
846     if (displayInfo == nullptr) {
847         WLOGFE("get display failed");
848         return;
849     }
850     auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayInfo->GetDisplayId());
851     if (windowNodeContainer != nullptr) {
852         windowNodeContainer->BeforeProcessWindowAvoidAreaChangeWhenDisplayChange();
853         DisplayGroupInfo::GetInstance().UpdateDisplayInfo(displayInfo);
854     }
855     switch (type) {
856         case DisplayStateChangeType::DISPLAY_COMPRESS:
857             ProcessDisplayCompression(defaultDisplayId, displayInfo);
858             [[fallthrough]];
859         case DisplayStateChangeType::SIZE_CHANGE:
860         case DisplayStateChangeType::UPDATE_ROTATION:
861         case DisplayStateChangeType::UPDATE_ROTATION_FROM_WINDOW:
862         case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: {
863             windowRoot_->ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type);
864             break;
865         }
866         default: {
867             WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
868             return;
869         }
870     }
871     auto displayId = displayInfo->GetDisplayId();
872     displayZoomController_->UpdateAllWindowsZoomInfo(displayId);
873     FlushWindowInfoWithDisplayId(displayId);
874     accessibilityConnection_->NotifyAccessibilityWindowInfo(displayId, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
875     if (windowNodeContainer != nullptr) {
876         windowNodeContainer->ProcessWindowAvoidAreaChangeWhenDisplayChange();
877     }
878 }
879 
ProcessDisplayCompression(DisplayId defaultDisplayId,const sptr<DisplayInfo> & displayInfo)880 void WindowController::ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo)
881 {
882     WLOGI("Enter processDisplayCompress");
883     DisplayId displayId = displayInfo->GetDisplayId();
884     if (displayId != defaultDisplayId) {
885         WLOGI("Not default display");
886         return;
887     }
888     auto& dms = DisplayManagerServiceInner::GetInstance();
889     if (!displayInfo->GetWaterfallDisplayCompressionStatus()) {
890         if (maskingSurfaceNode_ == nullptr) {
891             WLOGFD("MaskingSurfaceNode is not created");
892             return;
893         } else {
894             WLOGFD("Remove maskingSurfaceNode");
895             dms.UpdateRSTree(displayId, displayId, maskingSurfaceNode_, false, false);
896             maskingSurfaceNode_ = nullptr;
897             return;
898         }
899     }
900     WLOGFD("Add maskingSurfaceNode");
901     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
902     rsSurfaceNodeConfig.SurfaceNodeName = "maskingSurface";
903     maskingSurfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig);
904     if (maskingSurfaceNode_ == nullptr) {
905         WLOGFE("Create maskingSurfaceNode failed");
906         return;
907     }
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     RSTransaction::FlushImplicitTransaction();
1373     inputWindowMonitor_->UpdateInputWindow(windowId);
1374 }
1375 
FlushWindowInfoWithDisplayId(DisplayId displayId)1376 void WindowController::FlushWindowInfoWithDisplayId(DisplayId displayId)
1377 {
1378     WLOGFD("DisplayId: %{public}" PRIu64"", displayId);
1379     RSTransaction::FlushImplicitTransaction();
1380     inputWindowMonitor_->UpdateInputWindowByDisplayId(displayId);
1381 }
1382 
UpdateWindowAnimation(const sptr<WindowNode> & node)1383 void WindowController::UpdateWindowAnimation(const sptr<WindowNode>& node)
1384 {
1385     if (node == nullptr || (node->leashWinSurfaceNode_ == nullptr && node->surfaceNode_ == nullptr)) {
1386         WLOGFE("windowNode or surfaceNode is nullptr");
1387         return;
1388     }
1389     const auto& windowAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().windowAnimationConfig_;
1390 
1391     uint32_t animationFlag = node->GetWindowProperty()->GetAnimationFlag();
1392     uint32_t windowId = node->GetWindowProperty()->GetWindowId();
1393     WLOGFD("Id: %{public}u, anim_Flag: %{public}u", windowId, animationFlag);
1394     std::shared_ptr<const RSTransitionEffect> effect = nullptr;
1395     if (animationFlag == static_cast<uint32_t>(WindowAnimation::DEFAULT)) {
1396         effect = RSTransitionEffect::Create()
1397             ->Scale(windowAnimationConfig.scale_)
1398             ->Rotate(windowAnimationConfig.rotation_)
1399             ->Translate(windowAnimationConfig.translate_)
1400             ->Opacity(windowAnimationConfig.opacity_);
1401     } else if (animationFlag == static_cast<uint32_t>(WindowAnimation::INPUTE)) {
1402         float translateY = static_cast<float>(node->GetWindowRect().height_);
1403         if (!node->GetWindowRect().height_) {
1404             translateY = static_cast<float>(node->GetRequestRect().height_);
1405         }
1406         effect = RSTransitionEffect::Create()->Translate(Vector3f(0, translateY, 0))->Opacity(1.0f);
1407     };
1408     if (node->leashWinSurfaceNode_) {
1409         node->leashWinSurfaceNode_->SetTransitionEffect(effect);
1410     }
1411     if (node->surfaceNode_) {
1412         node->surfaceNode_->SetTransitionEffect(effect);
1413     }
1414 }
1415 
SetWindowLayoutMode(WindowLayoutMode mode)1416 WMError WindowController::SetWindowLayoutMode(WindowLayoutMode mode)
1417 {
1418     WMError res = WMError::WM_OK;
1419     auto displayIds = windowRoot_->GetAllDisplayIds();
1420     for (auto displayId : displayIds) {
1421         res = windowRoot_->SetWindowLayoutMode(displayId, mode);
1422         if (res != WMError::WM_OK) {
1423             return res;
1424         }
1425         displayZoomController_->UpdateAllWindowsZoomInfo(displayId);
1426         FlushWindowInfoWithDisplayId(displayId);
1427         accessibilityConnection_->NotifyAccessibilityWindowInfo(displayId, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1428     }
1429     MinimizeApp::ExecuteMinimizeAll();
1430     return res;
1431 }
1432 
UpdateProperty(sptr<WindowProperty> & property,PropertyChangeAction action)1433 WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action)
1434 {
1435     if (property == nullptr) {
1436         WLOGFE("property is invalid");
1437         return WMError::WM_ERROR_NULLPTR;
1438     }
1439 
1440     uint32_t windowId = property->GetWindowId();
1441     auto node = windowRoot_->GetWindowNode(windowId);
1442     if (node == nullptr) {
1443         WLOGFE("window is invalid");
1444         return WMError::WM_ERROR_NULLPTR;
1445     }
1446     WLOGI("Id: %{public}u, action: %{public}u", node->GetWindowId(), static_cast<uint32_t>(action));
1447     WMError ret = WMError::WM_OK;
1448     switch (action) {
1449         case PropertyChangeAction::ACTION_UPDATE_RECT: {
1450             node->SetDecoStatus(property->GetDecoStatus());
1451             node->SetOriginRect(property->GetOriginRect());
1452             node->SetDragType(property->GetDragType());
1453             ret = ResizeRectAndFlush(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason());
1454             if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && ret == WMError::WM_OK &&
1455                 callingWindowId_ == windowId && !WindowHelper::IsEmptyRect(callingWindowRestoringRect_)) {
1456                 if (!IsMoveToOrDragMove(property->GetWindowSizeChangeReason())) {
1457                     callingWindowId_ = 0u;
1458                     callingWindowRestoringRect_ = { 0, 0, 0, 0 };
1459                 } else {
1460                     auto windowRect = node->GetWindowRect();
1461                     callingWindowRestoringRect_.posX_ = windowRect.posX_;
1462                     callingWindowRestoringRect_.posY_ = windowRect.posY_;
1463                 }
1464             }
1465             break;
1466         }
1467         case PropertyChangeAction::ACTION_UPDATE_MODE: {
1468             node->SetDecorEnable(property->GetDecorEnable());
1469             ret = SetWindowMode(windowId, property->GetWindowMode());
1470             break;
1471         }
1472         case PropertyChangeAction::ACTION_UPDATE_FLAGS: {
1473             ret = SetWindowFlags(windowId, property->GetWindowFlags(), property->isSystemCalling_);
1474             break;
1475         }
1476         case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS: {
1477             auto& props = property->GetSystemBarProperty();
1478             for (auto& iter : props) {
1479                 SetSystemBarProperty(windowId, iter.first, iter.second);
1480             }
1481             break;
1482         }
1483         case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE: {
1484             node->SetFocusable(property->GetFocusable());
1485             windowRoot_->UpdateFocusableProperty(windowId);
1486             FlushWindowInfo(windowId);
1487             accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1488             break;
1489         }
1490         case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE: {
1491             node->SetTouchable(property->GetTouchable());
1492             FlushWindowInfo(windowId);
1493             accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1494             break;
1495         }
1496         case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW: {
1497             node->SetCallingWindow(property->GetCallingWindow());
1498             break;
1499         }
1500         case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: {
1501             node->SetRequestedOrientation(property->GetRequestedOrientation());
1502             if (WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) {
1503                 DisplayManagerServiceInner::GetInstance().
1504                     SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation());
1505             }
1506             break;
1507         }
1508         case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON: {
1509             node->SetTurnScreenOn(property->IsTurnScreenOn());
1510             HandleTurnScreenOn(node);
1511             break;
1512         }
1513         case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON: {
1514             node->SetKeepScreenOn(property->IsKeepScreenOn());
1515             windowRoot_->HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn());
1516             break;
1517         }
1518         case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS: {
1519             node->SetBrightness(property->GetBrightness());
1520             windowRoot_->SetBrightness(node->GetWindowId(), node->GetBrightness());
1521             break;
1522         }
1523         case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO: {
1524             node->SetWindowModeSupportType(property->GetWindowModeSupportType());
1525             break;
1526         }
1527         case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA: {
1528             std::vector<Rect> rects;
1529             property->GetTouchHotAreas(rects);
1530             ret = UpdateTouchHotAreas(node, rects);
1531             break;
1532         }
1533         case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: {
1534             node->GetWindowProperty()->SetAnimationFlag(property->GetAnimationFlag());
1535             UpdateWindowAnimation(node);
1536             break;
1537         }
1538         case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: {
1539             node->SetTransform(property->GetTransform());
1540             node->SetWindowSizeChangeReason(WindowSizeChangeReason::TRANSFORM);
1541             node->GetWindowProperty()->SetAnimateWindowFlag(true);
1542             ret = UpdateTransform(windowId);
1543             break;
1544         }
1545         case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE: {
1546             bool isPrivacyMode = property->GetPrivacyMode() || property->GetSystemPrivacyMode();
1547             node->GetWindowProperty()->SetPrivacyMode(isPrivacyMode);
1548             node->GetWindowProperty()->SetSystemPrivacyMode(isPrivacyMode);
1549             node->surfaceNode_->SetSecurityLayer(isPrivacyMode);
1550             if (node->leashWinSurfaceNode_ != nullptr) {
1551                 node->leashWinSurfaceNode_->SetSecurityLayer(isPrivacyMode);
1552             }
1553             RSTransaction::FlushImplicitTransaction();
1554             UpdatePrivateStateAndNotify(node);
1555             break;
1556         }
1557         case PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE: {
1558             bool isPrivacyMode = property->GetPrivacyMode() || property->GetSystemPrivacyMode();
1559             node->GetWindowProperty()->SetPrivacyMode(isPrivacyMode);
1560             node->GetWindowProperty()->SetSystemPrivacyMode(isPrivacyMode);
1561             node->surfaceNode_->SetSecurityLayer(isPrivacyMode);
1562             if (node->leashWinSurfaceNode_ != nullptr) {
1563                 node->leashWinSurfaceNode_->SetSecurityLayer(isPrivacyMode);
1564             }
1565             RSTransaction::FlushImplicitTransaction();
1566             UpdatePrivateStateAndNotify(node);
1567             break;
1568         }
1569         case PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP: {
1570             bool isSnapshotSkip = property->GetSnapshotSkip() || property->GetSystemPrivacyMode();
1571             node->GetWindowProperty()->SetSnapshotSkip(isSnapshotSkip);
1572             node->GetWindowProperty()->SetSystemPrivacyMode(isSnapshotSkip);
1573             node->surfaceNode_->SetSkipLayer(isSnapshotSkip);
1574             if (node->leashWinSurfaceNode_ != nullptr) {
1575                 node->leashWinSurfaceNode_->SetSkipLayer(isSnapshotSkip);
1576             }
1577             RSTransaction::FlushImplicitTransaction();
1578             break;
1579         }
1580         case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO: {
1581             ret = SetAspectRatio(windowId, property->GetAspectRatio());
1582             break;
1583         }
1584         case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE: {
1585             MaximizeMode mode = property->GetMaximizeMode();
1586             node->GetWindowProperty()->SetMaximizeMode(mode);
1587             Rect newRect = {0, 0, 0, 0};
1588             if (mode == MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
1589                 node->SetOriginRect(node->GetWindowRect());
1590                 auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1591                 if (windowNodeContainer == nullptr) {
1592                     WLOGFE("window node container is null");
1593                     return WMError::WM_ERROR_NULLPTR;
1594                 }
1595                 windowNodeContainer->GetLayoutPolicy()->GetMaximizeRect(node, newRect);
1596             } else {
1597                 newRect = node->GetOriginRect();
1598             }
1599             WLOGI("window %{public}d maximizeMode %{public}d rect %{public}d %{public}d %{public}d %{public}d",
1600                 windowId, static_cast<uint32_t>(mode), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_);
1601             ret = ResizeRectAndFlush(windowId, newRect, WindowSizeChangeReason::MAXIMIZE);
1602             break;
1603         }
1604         case PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO: {
1605             node->GetWindowProperty()->SetTextFieldPositionY(property->GetTextFieldPositionY());
1606             node->GetWindowProperty()->SetTextFieldHeight(property->GetTextFieldHeight());
1607             break;
1608         }
1609         default:
1610             break;
1611     }
1612     return ret;
1613 }
1614 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)1615 WMError WindowController::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
1616 {
1617     sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
1618     if (node == nullptr) {
1619         return WMError::WM_ERROR_NULLPTR;
1620     }
1621     if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
1622         return WMError::WM_ERROR_INVALID_TYPE;
1623     }
1624     node->SetWindowGravity(gravity, percent);
1625     RelayoutKeyboard(node);
1626     if (gravity == WindowGravity::WINDOW_GRAVITY_FLOAT) {
1627         RestoreCallingWindowSizeIfNeed();
1628     } else {
1629         ResizeSoftInputCallingWindowIfNeed(node);
1630     }
1631     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
1632     if (res != WMError::WM_OK) {
1633         return res;
1634     }
1635     FlushWindowInfo(windowId);
1636     return WMError::WM_OK;
1637 }
1638 
UpdatePrivateStateAndNotify(const sptr<WindowNode> & node)1639 void WindowController::UpdatePrivateStateAndNotify(const sptr<WindowNode>& node)
1640 {
1641     auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1642     if (windowNodeContainer == nullptr) {
1643         WLOGFE("window node container is null");
1644         return;
1645     }
1646     windowNodeContainer->UpdatePrivateStateAndNotify();
1647 }
1648 
SetAspectRatio(uint32_t windowId,float ratio)1649 WMError WindowController::SetAspectRatio(uint32_t windowId, float ratio)
1650 {
1651     WLOGI("SetAspectRatio, windowId: %{public}u, %{public}f", windowId, ratio);
1652     HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER);
1653     auto node = windowRoot_->GetWindowNode(windowId);
1654     if (node == nullptr) {
1655         WLOGFE("could not find window");
1656         return WMError::WM_OK;
1657     }
1658     if (!WindowHelper::IsAspectRatioSatisfiedWithSizeLimits(node->GetWindowUpdatedSizeLimits(), ratio,
1659         DisplayGroupInfo::GetInstance().GetDisplayVirtualPixelRatio(node->GetDisplayId()))) {
1660         return WMError::WM_ERROR_INVALID_PARAM;
1661     }
1662 
1663     node->SetAspectRatio(ratio);
1664 
1665     // perserve aspect ratio
1666     std::vector<std::string> nameVector;
1667     if (node->abilityInfo_.abilityName_.size() > 0) {
1668         nameVector = WindowHelper::Split(node->abilityInfo_.abilityName_, ".");
1669     }
1670     std::string keyName = nameVector.empty() ? node->abilityInfo_.bundleName_ :
1671                                                node->abilityInfo_.bundleName_ + "." + nameVector.back();
1672     if (MathHelper::NearZero(ratio)) { // If ratio is 0.0, need to reset aspect and delete storage
1673         if (PersistentStorage::HasKey(keyName, PersistentStorageType::ASPECT_RATIO)) {
1674             PersistentStorage::Delete(keyName, PersistentStorageType::ASPECT_RATIO);
1675         }
1676         return WMError::WM_OK;
1677     }
1678     PersistentStorage::Insert(keyName, ratio, PersistentStorageType::ASPECT_RATIO);
1679 
1680     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_ASPECT_RATIO);
1681     if (res != WMError::WM_OK) {
1682         return res;
1683     }
1684     FlushWindowInfo(windowId);
1685     return WMError::WM_OK;
1686 }
1687 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos) const1688 WMError WindowController::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const
1689 {
1690     accessibilityConnection_->GetAccessibilityWindowInfo(infos);
1691     return WMError::WM_OK;
1692 }
1693 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos) const1694 WMError WindowController::GetUnreliableWindowInfo(int32_t windowId,
1695     std::vector<sptr<UnreliableWindowInfo>>& infos) const
1696 {
1697     windowRoot_->GetUnreliableWindowInfo(windowId, infos);
1698     return WMError::WM_OK;
1699 }
1700 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos) const1701 WMError WindowController::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const
1702 {
1703     windowRoot_->GetVisibilityWindowInfo(infos);
1704     return WMError::WM_OK;
1705 }
1706 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones,const ModeChangeHotZonesConfig & config)1707 WMError WindowController::GetModeChangeHotZones(DisplayId displayId,
1708     ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config)
1709 {
1710     return windowRoot_->GetModeChangeHotZones(displayId, hotZones, config);
1711 }
1712 
UpdateTouchHotAreas(const sptr<WindowNode> & node,const std::vector<Rect> & rects)1713 WMError WindowController::UpdateTouchHotAreas(const sptr<WindowNode>& node, const std::vector<Rect>& rects)
1714 {
1715     std::ostringstream oss;
1716     int index = 0;
1717     for (const auto& rect : rects) {
1718         oss << "[ " << rect.posX_ << ", " << rect.posY_ << ", " << rect.width_ << ", " << rect.height_ << " ]";
1719         index++;
1720         if (index < static_cast<int32_t>(rects.size())) {
1721             oss <<", ";
1722         }
1723     }
1724     WLOGI("windowId: %{public}u, size: %{public}d, rects: %{public}s",
1725         node->GetWindowId(), static_cast<int32_t>(rects.size()), oss.str().c_str());
1726     if (rects.size() > TOUCH_HOT_AREA_MAX_NUM) {
1727         WLOGFE("the number of touch hot areas exceeds the maximum");
1728         return WMError::WM_ERROR_INVALID_PARAM;
1729     }
1730 
1731     std::vector<Rect> touchHotAreas;
1732     std::vector<Rect> pointerHotAreas;
1733     if (rects.empty()) {
1734         touchHotAreas.emplace_back(node->GetEntireWindowTouchHotArea());
1735         pointerHotAreas.emplace_back(node->GetEntireWindowPointerHotArea());
1736     } else {
1737         Rect windowRect = node->GetWindowRect();
1738         if (!WindowHelper::CalculateTouchHotAreas(windowRect, rects, touchHotAreas)) {
1739             WLOGFE("the requested touch hot areas are incorrect");
1740             return WMError::WM_ERROR_INVALID_PARAM;
1741         }
1742         pointerHotAreas = touchHotAreas;
1743     }
1744     node->GetWindowProperty()->SetTouchHotAreas(rects);
1745     node->SetTouchHotAreas(touchHotAreas);
1746     node->SetPointerHotAreas(pointerHotAreas);
1747     FlushWindowInfo(node->GetWindowId());
1748     accessibilityConnection_->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1749     return WMError::WM_OK;
1750 }
1751 
UpdateTransform(uint32_t windowId)1752 WMError WindowController::UpdateTransform(uint32_t windowId)
1753 {
1754     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_TRANSFORM);
1755     if (res != WMError::WM_OK) {
1756         return res;
1757     }
1758     FlushWindowInfo(windowId);
1759     accessibilityConnection_->NotifyAccessibilityWindowInfo(windowRoot_->GetWindowNode(windowId),
1760         WindowUpdateType::WINDOW_UPDATE_PROPERTY);
1761     return WMError::WM_OK;
1762 }
1763 
NotifyTouchOutside(const sptr<WindowNode> & node)1764 void WindowController::NotifyTouchOutside(const sptr<WindowNode>& node)
1765 {
1766     auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId());
1767     if (windowNodeContainer == nullptr) {
1768         WLOGFE("window node container is null");
1769         return;
1770     }
1771 
1772     std::vector<sptr<WindowNode>> windowNodes;
1773     windowNodeContainer->TraverseContainer(windowNodes);
1774     uint32_t skipNodeId = GetEmbedNodeId(windowNodes, node);
1775     for (const auto& windowNode : windowNodes) {
1776         if (windowNode == nullptr || windowNode->GetWindowToken() == nullptr ||
1777             windowNode->GetWindowId() == skipNodeId ||
1778             windowNode->GetWindowId() == node->GetWindowId()) {
1779             WLOGFD("continue %{public}s", windowNode == nullptr ? "nullptr" : windowNode->GetWindowName().c_str());
1780             continue;
1781         }
1782         WLOGFD("notify %{public}s id %{public}d", windowNode->GetWindowName().c_str(), windowNode->GetWindowId());
1783         windowNode->GetWindowToken()->NotifyTouchOutside();
1784     }
1785 }
1786 
GetEmbedNodeId(const std::vector<sptr<WindowNode>> & windowNodes,const sptr<WindowNode> & node)1787 uint32_t WindowController::GetEmbedNodeId(const std::vector<sptr<WindowNode>>& windowNodes,
1788     const sptr<WindowNode>& node)
1789 {
1790     if (node->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) {
1791         return 0;
1792     }
1793 
1794     Rect nodeRect = node->GetWindowRect();
1795     bool isSkip = true;
1796     for (auto& windowNode : windowNodes) {
1797         if (windowNode == nullptr) {
1798             continue;
1799         }
1800         if (windowNode->GetWindowId() == node->GetWindowId()) {
1801             isSkip = false;
1802             continue;
1803         }
1804         if (isSkip) {
1805             continue;
1806         }
1807         if (nodeRect.IsInsideOf(windowNode->GetWindowRect())) {
1808             WLOGI("TouchOutside window type is component %{public}s windowNode %{public}d",
1809                 windowNode->GetWindowName().c_str(), windowNode->GetWindowId());
1810             return windowNode->GetWindowId();
1811         }
1812     }
1813     return 0;
1814 }
1815 
MinimizeWindowsByLauncher(std::vector<uint32_t> & windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)1816 void WindowController::MinimizeWindowsByLauncher(std::vector<uint32_t>& windowIds, bool isAnimated,
1817     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
1818 {
1819     windowRoot_->MinimizeTargetWindows(windowIds);
1820     auto func = []() {
1821         MinimizeApp::ExecuteMinimizeTargetReasons(MinimizeReason::GESTURE_ANIMATION);
1822     };
1823     if (!isAnimated) {
1824         WLOGFD("no animation minimize size: %{public}u", static_cast<uint32_t>(windowIds.size()));
1825         func();
1826     } else {
1827         WLOGFD("animation minimize size: %{public}u", static_cast<uint32_t>(windowIds.size()));
1828         auto needMinimizeAppNodes = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::GESTURE_ANIMATION);
1829         for (auto& weakNode : needMinimizeAppNodes) {
1830             auto node = weakNode.promote();
1831             if (node) {
1832                 // gesture animation no need to play default animation when minimize
1833                 node->isPlayAnimationHide_ = true;
1834             }
1835         }
1836         finishCallback = RemoteAnimation::CreateAnimationFinishedCallback(func, nullptr);
1837         if (finishCallback == nullptr) {
1838             return;
1839         }
1840     }
1841 }
1842 
OnScreenshot(DisplayId displayId)1843 void WindowController::OnScreenshot(DisplayId displayId)
1844 {
1845     std::vector<sptr<WindowNode>> windowNodes;
1846     windowRoot_->GetForegroundNodes(windowNodes);
1847     for (auto& windowNode : windowNodes) {
1848         auto windowToken = windowNode->GetWindowToken();
1849         if (windowToken != nullptr) {
1850             windowToken->NotifyScreenshot();
1851         }
1852     }
1853 }
1854 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1855 void WindowController::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1856 {
1857     displayZoomController_->SetAnchorOffset(deltaX, deltaY);
1858     DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1859     FlushWindowInfoWithDisplayId(displayId);
1860 }
1861 
OffWindowZoom()1862 void WindowController::OffWindowZoom()
1863 {
1864     displayZoomController_->OffWindowZoom();
1865     DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1866     FlushWindowInfoWithDisplayId(displayId);
1867 }
1868 
SetAnchorAndScale(int32_t x,int32_t y,float scale)1869 void WindowController::SetAnchorAndScale(int32_t x, int32_t y, float scale)
1870 {
1871     displayZoomController_->SetAnchorAndScale(x, y, scale);
1872     DisplayId displayId = DisplayGroupInfo::GetInstance().GetDefaultDisplayId();
1873     FlushWindowInfoWithDisplayId(displayId);
1874 }
1875 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)1876 WMError WindowController::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
1877 {
1878     auto node = windowRoot_->GetWindowNode(windowId);
1879     if (node == nullptr) {
1880         WLOGFE("could not find window");
1881         return WMError::WM_ERROR_NULLPTR;
1882     }
1883 
1884     node->dialogTargetToken_ = targetToken;
1885 
1886     return WMError::WM_OK;
1887 }
1888 
SetDragFrameGravity(int32_t dragGravity)1889 void WindowController::SetDragFrameGravity(int32_t dragGravity)
1890 {
1891     dragFrameGravity_ = dragGravity;
1892 }
1893 } // namespace OHOS
1894 } // namespace Rosen
1895