• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <parameters.h>
18 #include <power_mgr_client.h>
19 #include <transaction/rs_transaction.h>
20 #include "window_manager_hilog.h"
21 #include "window_helper.h"
22 #include "wm_common.h"
23 #include "wm_trace.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowController"};
29 }
GenWindowId()30 uint32_t WindowController::GenWindowId()
31 {
32     return ++windowId_;
33 }
34 
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId)35 WMError WindowController::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
36     const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId)
37 {
38     uint32_t parentId = property->GetParentId();
39     if ((parentId != INVALID_WINDOW_ID) && !WindowHelper::IsSubWindow(property->GetWindowType())) {
40         WLOGFE("create window failed, type is error");
41         return WMError::WM_ERROR_INVALID_TYPE;
42     }
43     windowId = GenWindowId();
44     sptr<WindowProperty> windowProperty = new WindowProperty(property);
45     windowProperty->SetWindowId(windowId);
46     sptr<WindowNode> node = new WindowNode(windowProperty, window, surfaceNode);
47     UpdateWindowAnimation(node);
48     return windowRoot_->SaveWindow(node);
49 }
50 
SaveAbilityToken(const sptr<IRemoteObject> & abilityToken,uint32_t windowId)51 WMError WindowController::SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId)
52 {
53     auto node = windowRoot_->GetWindowNode(windowId);
54     if (node == nullptr) {
55         WLOGFE("could not find window");
56         return WMError::WM_ERROR_NULLPTR;
57     }
58     node->abilityToken_ = abilityToken;
59     return WMError::WM_OK;
60 }
61 
AddWindowNode(sptr<WindowProperty> & property)62 WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
63 {
64     auto node = windowRoot_->GetWindowNode(property->GetWindowId());
65     if (node == nullptr) {
66         WLOGFE("could not find window");
67         return WMError::WM_ERROR_NULLPTR;
68     }
69     node->GetWindowProperty()->CopyFrom(property);
70 
71     // Need 'check permission'
72     // Need 'adjust property'
73     WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node);
74     if (res != WMError::WM_OK) {
75         return res;
76     }
77     windowRoot_->FocusFaultDetection();
78     FlushWindowInfo(property->GetWindowId());
79     HandleTurnScreenOn(node);
80 
81     if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR ||
82         node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
83         sysBarWinId_[node->GetWindowType()] = node->GetWindowId();
84         ReSizeSystemBarPropertySizeIfNeed(node);
85     }
86 
87     if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
88         WindowHelper::IsAppWindow(node->GetWindowType())) {
89         WM_SCOPED_TRACE_BEGIN("controller:MinimizeStructuredAppWindowsExceptSelf");
90         res = windowRoot_->MinimizeStructuredAppWindowsExceptSelf(node);
91         WM_SCOPED_TRACE_END();
92         if (res != WMError::WM_OK) {
93             WLOGFE("Minimize other structured window failed");
94             return res;
95         }
96     }
97     StopBootAnimationIfNeed(node->GetWindowType());
98     return WMError::WM_OK;
99 }
100 
ReSizeSystemBarPropertySizeIfNeed(sptr<WindowNode> node)101 void WindowController::ReSizeSystemBarPropertySizeIfNeed(sptr<WindowNode> node)
102 {
103     auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(node->GetDisplayId());
104     if (displayInfo == nullptr) {
105         WLOGFE("displayInfo is null");
106         return;
107     }
108     uint32_t displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
109     uint32_t displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
110     Rect targetRect = node->GetWindowRect();
111     if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) {
112         auto statusBarRectIter =
113             systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight);
114         if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) {
115             targetRect = statusBarRectIter->second;
116         }
117     } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
118         auto navigationBarRectIter =
119             systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight);
120         if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) {
121             targetRect = navigationBarRectIter->second;
122         }
123     }
124     if (curDisplayInfo_.find(displayInfo->GetDisplayId()) == curDisplayInfo_.end()) {
125         curDisplayInfo_[displayInfo->GetDisplayId()] = displayInfo;
126     }
127     Rect propertyRect = node->GetWindowRect();
128     if (propertyRect != targetRect) {
129         ResizeRect(node->GetWindowId(), targetRect, WindowSizeChangeReason::DRAG);
130     }
131 }
132 
HandleTurnScreenOn(const sptr<WindowNode> & node)133 void WindowController::HandleTurnScreenOn(const sptr<WindowNode>& node)
134 {
135     if (node == nullptr) {
136         WLOGFE("window is invalid");
137         return;
138     }
139     WLOGFI("handle turn screen on: [%{public}s, %{public}d]", node->GetWindowName().c_str(), node->IsTurnScreenOn());
140     // reset ipc identity
141     std::string identity = IPCSkeleton::ResetCallingIdentity();
142     if (node->IsTurnScreenOn() && !PowerMgr::PowerMgrClient::GetInstance().IsScreenOn()) {
143         WLOGFI("turn screen on");
144         PowerMgr::PowerMgrClient::GetInstance().WakeupDevice();
145     }
146     // set ipc identity to raw
147     IPCSkeleton::SetCallingIdentity(identity);
148 }
149 
RemoveWindowNode(uint32_t windowId)150 WMError WindowController::RemoveWindowNode(uint32_t windowId)
151 {
152     WMError res = windowRoot_->RemoveWindowNode(windowId);
153     if (res != WMError::WM_OK) {
154         return res;
155     }
156     windowRoot_->FocusFaultDetection();
157     FlushWindowInfo(windowId);
158     return res;
159 }
160 
DestroyWindow(uint32_t windowId,bool onlySelf)161 WMError WindowController::DestroyWindow(uint32_t windowId, bool onlySelf)
162 {
163     DisplayId displayId = DISPLAY_ID_INVALID;
164     auto node = windowRoot_->GetWindowNode(windowId);
165     if (node != nullptr) {
166         displayId = node->GetDisplayId();
167     }
168     WMError res = windowRoot_->DestroyWindow(windowId, onlySelf);
169     if (res != WMError::WM_OK) {
170         return res;
171     }
172     windowRoot_->FocusFaultDetection();
173     FlushWindowInfoWithDisplayId(displayId);
174     return res;
175 }
176 
ResizeRect(uint32_t windowId,const Rect & rect,WindowSizeChangeReason reason)177 WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason)
178 {
179     auto node = windowRoot_->GetWindowNode(windowId);
180     if (node == nullptr) {
181         WLOGFE("could not find window");
182         return WMError::WM_ERROR_NULLPTR;
183     }
184     auto property = node->GetWindowProperty();
185     Rect lastRect = property->GetWindowRect();
186     Rect newRect;
187     node->SetWindowSizeChangeReason(reason);
188     if (reason == WindowSizeChangeReason::MOVE) {
189         newRect = { rect.posX_, rect.posY_, lastRect.width_, lastRect.height_ };
190         if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
191             if (windowRoot_->isVerticalDisplay(node)) {
192                 newRect.posX_ = lastRect.posX_;
193             } else {
194                 newRect.posY_ = lastRect.posY_;
195             }
196         }
197     } else if (reason == WindowSizeChangeReason::RESIZE) {
198         node->hasDecorated_ = false;
199         node->isDefultLayoutRect_ = false;
200         newRect = { lastRect.posX_, lastRect.posY_, rect.width_, rect.height_ };
201     } else if (reason == WindowSizeChangeReason::DRAG) {
202         if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) {
203             // fix rect in case of moving window when dragging
204             float virtualPixelRatio = windowRoot_->GetVirtualPixelRatio(node->GetDisplayId());
205             Rect displayLimitRect = windowRoot_->GetDisplayLimitRect(node->GetDisplayId());
206             newRect = WindowHelper::GetFixedWindowRectByLimitSize(rect, lastRect,
207                 windowRoot_->isVerticalDisplay(node), virtualPixelRatio);
208             newRect = WindowHelper::GetFixedWindowRectByLimitPosition(newRect, lastRect,
209                 virtualPixelRatio, displayLimitRect);
210         } else {
211             newRect = rect;
212         }
213     }
214     property->SetWindowRect(newRect);
215     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_RECT);
216     if (res != WMError::WM_OK) {
217         return res;
218     }
219     FlushWindowInfo(windowId);
220     return WMError::WM_OK;
221 }
222 
RequestFocus(uint32_t windowId)223 WMError WindowController::RequestFocus(uint32_t windowId)
224 {
225     if (windowRoot_ == nullptr) {
226         return WMError::WM_ERROR_NULLPTR;
227     }
228     return windowRoot_->RequestFocus(windowId);
229 }
230 
SetWindowMode(uint32_t windowId,WindowMode dstMode)231 WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode dstMode)
232 {
233     WM_FUNCTION_TRACE();
234     auto node = windowRoot_->GetWindowNode(windowId);
235     if (node == nullptr) {
236         WLOGFE("could not find window");
237         return WMError::WM_ERROR_NULLPTR;
238     }
239     WindowMode srcMode = node->GetWindowMode();
240     if (srcMode == dstMode) {
241         return WMError::WM_OK;
242     }
243     WMError res = WMError::WM_OK;
244     if ((srcMode == WindowMode::WINDOW_MODE_FULLSCREEN) && (dstMode == WindowMode::WINDOW_MODE_FLOATING)) {
245         node->SetWindowSizeChangeReason(WindowSizeChangeReason::RECOVER);
246     } else if (dstMode == WindowMode::WINDOW_MODE_FULLSCREEN) {
247         node->SetWindowSizeChangeReason(WindowSizeChangeReason::MAXIMIZE);
248     } else {
249         node->SetWindowSizeChangeReason(WindowSizeChangeReason::RESIZE);
250     }
251     if (WindowHelper::IsSplitWindowMode(srcMode)) {
252         // change split mode to other
253         res = windowRoot_->ExitSplitWindowMode(node);
254         node->SetWindowMode(dstMode);
255     } else if (!WindowHelper::IsSplitWindowMode(srcMode) && WindowHelper::IsSplitWindowMode(dstMode)) {
256         // change other mode to split
257         node->SetWindowMode(dstMode);
258         res = windowRoot_->EnterSplitWindowMode(node);
259     } else {
260         node->SetWindowMode(dstMode);
261     }
262     if (res != WMError::WM_OK) {
263         node->GetWindowProperty()->ResumeLastWindowMode();
264         return res;
265     }
266     if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
267         WindowHelper::IsAppWindow(node->GetWindowType())) {
268         // minimize other app window
269         res = windowRoot_->MinimizeStructuredAppWindowsExceptSelf(node);
270         if (res != WMError::WM_OK) {
271             return res;
272         }
273     }
274     res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_MODE);
275     if (res != WMError::WM_OK) {
276         WLOGFE("Set window mode failed, update node failed");
277         return res;
278     }
279     node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode());
280     FlushWindowInfo(windowId);
281     return WMError::WM_OK;
282 }
283 
SetWindowBackgroundBlur(uint32_t windowId,WindowBlurLevel dstLevel)284 WMError WindowController::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel dstLevel)
285 {
286     auto node = windowRoot_->GetWindowNode(windowId);
287     if (node == nullptr) {
288         WLOGFE("could not find window");
289         return WMError::WM_ERROR_NULLPTR;
290     }
291 
292     WLOGFI("WindowEffect WindowController SetWindowBackgroundBlur level: %{public}u", dstLevel);
293     node->SetWindowBackgroundBlur(dstLevel);
294     FlushWindowInfo(windowId);
295     return WMError::WM_OK;
296 }
297 
SetAlpha(uint32_t windowId,float dstAlpha)298 WMError WindowController::SetAlpha(uint32_t windowId, float dstAlpha)
299 {
300     auto node = windowRoot_->GetWindowNode(windowId);
301     if (node == nullptr) {
302         WLOGFE("could not find window");
303         return WMError::WM_ERROR_NULLPTR;
304     }
305 
306     WLOGFI("WindowEffect WindowController SetAlpha alpha: %{public}f", dstAlpha);
307     node->SetAlpha(dstAlpha);
308 
309     FlushWindowInfo(windowId);
310     return WMError::WM_OK;
311 }
312 
NotifyDisplayStateChange(DisplayId displayId,DisplayStateChangeType type)313 void WindowController::NotifyDisplayStateChange(DisplayId displayId, DisplayStateChangeType type)
314 {
315     WLOGFD("DisplayStateChangeType:%{public}u", type);
316     switch (type) {
317         case DisplayStateChangeType::BEFORE_SUSPEND: {
318             windowRoot_->NotifyWindowStateChange(WindowState::STATE_FROZEN, WindowStateChangeReason::KEYGUARD);
319             break;
320         }
321         case DisplayStateChangeType::BEFORE_UNLOCK: {
322             windowRoot_->NotifyWindowStateChange(WindowState::STATE_UNFROZEN, WindowStateChangeReason::KEYGUARD);
323             break;
324         }
325         case DisplayStateChangeType::SIZE_CHANGE:
326         case DisplayStateChangeType::UPDATE_ROTATION: {
327             ProcessDisplayChange(displayId, type);
328             break;
329         }
330         case DisplayStateChangeType::DESTROY: {
331             windowRoot_->NotifyDisplayDestroy(displayId);
332             break;
333         }
334         default: {
335             WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
336             return;
337         }
338     }
339 }
340 
ProcessDisplayChange(DisplayId displayId,DisplayStateChangeType type)341 void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type)
342 {
343     const sptr<DisplayInfo> displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId);
344     if (displayInfo == nullptr) {
345         WLOGFE("get display failed displayId:%{public}" PRId64 "", displayId);
346         return;
347     }
348 
349     switch (type) {
350         case DisplayStateChangeType::SIZE_CHANGE:
351         case DisplayStateChangeType::UPDATE_ROTATION: {
352             auto iter = curDisplayInfo_.find(displayId);
353             if (iter != curDisplayInfo_.end()) {
354                 auto lastDisplayInfo = iter->second;
355                 uint32_t lastDisplayWidth = static_cast<uint32_t>(lastDisplayInfo->GetWidth());
356                 uint32_t lastDisplayHeight = static_cast<uint32_t>(lastDisplayInfo->GetHeight());
357                 auto statusBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]);
358                 auto navigationBarNode =
359                     windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR]);
360                 systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][lastDisplayWidth][lastDisplayHeight]
361                     = statusBarNode->GetWindowProperty()->GetWindowRect();
362                 systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][lastDisplayWidth][lastDisplayHeight]
363                     = navigationBarNode->GetWindowProperty()->GetWindowRect();
364             }
365             curDisplayInfo_[displayId] = displayInfo;
366             windowRoot_->NotifyDisplayChange(displayInfo);
367             // Remove 'sysBarWinId_' after SystemUI resize 'systembar'
368             uint32_t width = static_cast<uint32_t>(displayInfo->GetWidth());
369             uint32_t height = static_cast<uint32_t>(displayInfo->GetHeight() * SYSTEM_BAR_HEIGHT_RATIO);
370             Rect newRect = { 0, 0, width, height };
371             uint32_t displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
372             uint32_t displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
373             auto statusBarRectIter =
374                 systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight);
375             if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) {
376                 newRect = statusBarRectIter->second;
377             }
378             ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], newRect, WindowSizeChangeReason::DRAG);
379             newRect = { 0, displayInfo->GetHeight() - static_cast<int32_t>(height), width, height };
380             auto navigationBarRectIter =
381                 systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight);
382             if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) {
383                 newRect = navigationBarRectIter->second;
384             }
385             ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], newRect, WindowSizeChangeReason::DRAG);
386             break;
387         }
388         default: {
389             WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
390             return;
391         }
392     }
393     FlushWindowInfoWithDisplayId(displayId);
394     WLOGFI("Finish ProcessDisplayChange");
395 }
396 
StopBootAnimationIfNeed(WindowType type) const397 void WindowController::StopBootAnimationIfNeed(WindowType type) const
398 {
399     if (WindowType::WINDOW_TYPE_DESKTOP == type) {
400         WLOGFD("stop boot animation");
401         system::SetParameter("persist.window.boot.inited", "1");
402     }
403 }
404 
SetWindowType(uint32_t windowId,WindowType type)405 WMError WindowController::SetWindowType(uint32_t windowId, WindowType type)
406 {
407     auto node = windowRoot_->GetWindowNode(windowId);
408     if (node == nullptr) {
409         WLOGFE("could not find window");
410         return WMError::WM_ERROR_NULLPTR;
411     }
412     auto property = node->GetWindowProperty();
413     property->SetWindowType(type);
414     UpdateWindowAnimation(node);
415     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_TYPE);
416     if (res != WMError::WM_OK) {
417         return res;
418     }
419     FlushWindowInfo(windowId);
420     WLOGFI("SetWindowType end");
421     return res;
422 }
423 
SetWindowFlags(uint32_t windowId,uint32_t flags)424 WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags)
425 {
426     auto node = windowRoot_->GetWindowNode(windowId);
427     if (node == nullptr) {
428         WLOGFE("could not find window");
429         return WMError::WM_ERROR_NULLPTR;
430     }
431     auto property = node->GetWindowProperty();
432     property->SetWindowFlags(flags);
433     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_FLAGS);
434     if (res != WMError::WM_OK) {
435         return res;
436     }
437     FlushWindowInfo(windowId);
438     WLOGFI("SetWindowFlags end");
439     return res;
440 }
441 
SetSystemBarProperty(uint32_t windowId,WindowType type,const SystemBarProperty & property)442 WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property)
443 {
444     auto node = windowRoot_->GetWindowNode(windowId);
445     if (node == nullptr) {
446         WLOGFE("could not find window");
447         return WMError::WM_ERROR_NULLPTR;
448     }
449     node->SetSystemBarProperty(type, property);
450     WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_OTHER_PROPS);
451     if (res != WMError::WM_OK) {
452         return res;
453     }
454     FlushWindowInfo(windowId);
455     WLOGFI("SetSystemBarProperty end");
456     return res;
457 }
458 
NotifySystemBarTints()459 void WindowController::NotifySystemBarTints()
460 {
461     windowRoot_->NotifySystemBarTints();
462 }
463 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType avoidAreaType)464 std::vector<Rect> WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType)
465 {
466     std::vector<Rect> avoidArea = windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType);
467     return avoidArea;
468 }
469 
ProcessPointDown(uint32_t windowId,bool isStartDrag)470 WMError WindowController::ProcessPointDown(uint32_t windowId, bool isStartDrag)
471 {
472     auto node = windowRoot_->GetWindowNode(windowId);
473     if (node == nullptr) {
474         WLOGFW("could not find window");
475         return WMError::WM_ERROR_NULLPTR;
476     }
477     if (!node->currentVisibility_) {
478         WLOGFE("this window is not visibile and not in window tree, windowId: %{public}u", windowId);
479         return WMError::WM_ERROR_INVALID_OPERATION;
480     }
481 
482     if (isStartDrag) {
483         WMError res = windowRoot_->UpdateSizeChangeReason(windowId, WindowSizeChangeReason::DRAG_START);
484         return res;
485     }
486 
487     WLOGFI("process point down, windowId: %{public}u", windowId);
488     WMError zOrderRes = windowRoot_->RaiseZOrderForAppWindow(node);
489     WMError focusRes = windowRoot_->RequestFocus(windowId);
490     windowRoot_->RequestActiveWindow(windowId);
491     if (zOrderRes == WMError::WM_OK || focusRes == WMError::WM_OK) {
492         FlushWindowInfo(windowId);
493         WLOGFI("ProcessPointDown end");
494         return WMError::WM_OK;
495     }
496     windowRoot_->FocusFaultDetection();
497     return WMError::WM_ERROR_INVALID_OPERATION;
498 }
499 
ProcessPointUp(uint32_t windowId)500 WMError WindowController::ProcessPointUp(uint32_t windowId)
501 {
502     auto node = windowRoot_->GetWindowNode(windowId);
503     if (node == nullptr) {
504         WLOGFW("could not find window");
505         return WMError::WM_ERROR_NULLPTR;
506     }
507     WMError res = windowRoot_->UpdateSizeChangeReason(windowId, WindowSizeChangeReason::DRAG_END);
508     if (res != WMError::WM_OK) {
509         return res;
510     }
511     return WMError::WM_OK;
512 }
513 
MinimizeAllAppWindows(DisplayId displayId)514 void WindowController::MinimizeAllAppWindows(DisplayId displayId)
515 {
516     windowRoot_->MinimizeAllAppWindows(displayId);
517 }
518 
MaxmizeWindow(uint32_t windowId)519 WMError WindowController::MaxmizeWindow(uint32_t windowId)
520 {
521     WMError ret = SetWindowMode(windowId, WindowMode::WINDOW_MODE_FULLSCREEN);
522     if (ret != WMError::WM_OK) {
523         return ret;
524     }
525     ret = windowRoot_->MaxmizeWindow(windowId);
526     FlushWindowInfo(windowId);
527     return ret;
528 }
529 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)530 WMError WindowController::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
531 {
532     return windowRoot_->GetTopWindowId(mainWinId, topWinId);
533 }
534 
FlushWindowInfo(uint32_t windowId)535 void WindowController::FlushWindowInfo(uint32_t windowId)
536 {
537     WLOGFI("FlushWindowInfo");
538     RSTransaction::FlushImplicitTransaction();
539     inputWindowMonitor_->UpdateInputWindow(windowId);
540 }
541 
FlushWindowInfoWithDisplayId(DisplayId displayId)542 void WindowController::FlushWindowInfoWithDisplayId(DisplayId displayId)
543 {
544     WLOGFI("FlushWindowInfoWithDisplayId");
545     RSTransaction::FlushImplicitTransaction();
546     inputWindowMonitor_->UpdateInputWindowByDisplayId(displayId);
547 }
548 
UpdateWindowAnimation(const sptr<WindowNode> & node)549 void WindowController::UpdateWindowAnimation(const sptr<WindowNode>& node)
550 {
551     if (node == nullptr || node->surfaceNode_ == nullptr) {
552         WLOGFE("windowNode or surfaceNode is nullptr");
553         return;
554     }
555 
556     uint32_t animationFlag = node->GetWindowProperty()->GetAnimationFlag();
557     uint32_t windowId = node->GetWindowProperty()->GetWindowId();
558     WLOGFI("windowId: %{public}u, animationFlag: %{public}u", windowId, animationFlag);
559     if (animationFlag == static_cast<uint32_t>(WindowAnimation::DEFAULT)) {
560         // set default transition effect for window: scale from 1.0 to 0.7, fade from 1.0 to 0.0
561         static const auto effect = RSTransitionEffect::Create()->Scale(Vector3f(0.7f, 0.7f, 0.0f))->Opacity(0.0f);
562         node->surfaceNode_->SetTransitionEffect(effect);
563     } else {
564         node->surfaceNode_->SetTransitionEffect(nullptr);
565     }
566 }
567 
SetWindowLayoutMode(DisplayId displayId,WindowLayoutMode mode)568 WMError WindowController::SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode)
569 {
570     WMError res = windowRoot_->SetWindowLayoutMode(displayId, mode);
571     if (res != WMError::WM_OK) {
572         return res;
573     }
574     FlushWindowInfoWithDisplayId(displayId);
575     return res;
576 }
577 
UpdateProperty(sptr<WindowProperty> & property,PropertyChangeAction action)578 WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action)
579 {
580     if (property == nullptr) {
581         WLOGFE("property is invalid");
582         return WMError::WM_ERROR_NULLPTR;
583     }
584     uint32_t windowId = property->GetWindowId();
585     auto node = windowRoot_->GetWindowNode(windowId);
586     if (node == nullptr) {
587         WLOGFE("window is invalid");
588         return WMError::WM_ERROR_NULLPTR;
589     }
590     WLOGFI("window: [%{public}s, %{public}u] update property for action: %{public}u", node->GetWindowName().c_str(),
591         node->GetWindowId(), static_cast<uint32_t>(action));
592     switch (action) {
593         case PropertyChangeAction::ACTION_UPDATE_RECT: {
594             ResizeRect(windowId, property->GetWindowRect(), property->GetWindowSizeChangeReason());
595             break;
596         }
597         case PropertyChangeAction::ACTION_UPDATE_MODE: {
598             SetWindowMode(windowId, property->GetWindowMode());
599             break;
600         }
601         case PropertyChangeAction::ACTION_UPDATE_FLAGS: {
602             SetWindowFlags(windowId, property->GetWindowFlags());
603             break;
604         }
605         case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS: {
606             auto& props = property->GetSystemBarProperty();
607             for (auto& iter : props) {
608                 SetSystemBarProperty(windowId, iter.first, iter.second);
609             }
610             break;
611         }
612         case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE: {
613             node->SetFocusable(property->GetFocusable());
614             windowRoot_->UpdateFocusableProperty(windowId);
615             FlushWindowInfo(windowId);
616             break;
617         }
618         case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE: {
619             node->SetTouchable(property->GetTouchable());
620             FlushWindowInfo(windowId);
621             break;
622         }
623         case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW: {
624             node->SetCallingWindow(property->GetCallingWindow());
625             break;
626         }
627         case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: {
628             node->SetRequestedOrientation(property->GetRequestedOrientation());
629             if (WindowHelper::IsMainWindow(node->GetWindowType()) &&
630                 node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
631                 DisplayManagerServiceInner::GetInstance().
632                     SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation());
633             }
634             break;
635         }
636         case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON: {
637             node->SetTurnScreenOn(property->IsTurnScreenOn());
638             HandleTurnScreenOn(node);
639             break;
640         }
641         case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON: {
642             node->SetKeepScreenOn(property->IsKeepScreenOn());
643             windowRoot_->HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn());
644             break;
645         }
646         case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS: {
647             node->SetBrightness(property->GetBrightness());
648             windowRoot_->SetBrightness(node->GetWindowId(), node->GetBrightness());
649             break;
650         }
651         default:
652             break;
653     }
654     return WMError::WM_OK;
655 }
656 } // namespace OHOS
657 } // namespace Rosen