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_impl.h"
17
18 #include <ability_manager_client.h>
19 #include <common/rs_common_def.h>
20 #include <filesystem>
21 #include <fstream>
22 #include <hisysevent.h>
23 #include <parameters.h>
24 #include <ipc_skeleton.h>
25 #include <transaction/rs_interfaces.h>
26 #include <transaction/rs_transaction.h>
27 #include <ui/rs_node.h>
28
29 #include "permission.h"
30 #include "color_parser.h"
31 #include "display_manager.h"
32 #include "display_info.h"
33 #include "ressched_report.h"
34 #include "singleton_container.h"
35 #include "surface_capture_future.h"
36 #include "sys_cap_util.h"
37 #include "window_adapter.h"
38 #include "window_agent.h"
39 #include "window_helper.h"
40 #include "window_manager_hilog.h"
41 #include "wm_common.h"
42 #include "wm_common_inner.h"
43 #include "wm_math.h"
44 #include "perform_reporter.h"
45 #include "hitrace_meter.h"
46 #include <hisysevent.h>
47
48 namespace OHOS {
49 namespace Rosen {
50 namespace {
51 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowImpl"};
52 const std::string PARAM_DUMP_HELP = "-h";
53
GetAceContentInfoType(BackupAndRestoreType type)54 Ace::ContentInfoType GetAceContentInfoType(BackupAndRestoreType type)
55 {
56 auto contentInfoType = Ace::ContentInfoType::NONE;
57 switch (type) {
58 case BackupAndRestoreType::CONTINUATION:
59 contentInfoType = Ace::ContentInfoType::CONTINUATION;
60 break;
61 case BackupAndRestoreType::APP_RECOVERY:
62 contentInfoType = Ace::ContentInfoType::APP_RECOVERY;
63 break;
64 case BackupAndRestoreType::RESOURCESCHEDULE_RECOVERY:
65 contentInfoType = Ace::ContentInfoType::RESOURCESCHEDULE_RECOVERY;
66 break;
67 case BackupAndRestoreType::NONE:
68 [[fallthrough]];
69 default:
70 break;
71 }
72 return contentInfoType;
73 }
74 }
75
76 WM_IMPLEMENT_SINGLE_INSTANCE(ResSchedReport);
77
78 const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = {
79 { ColorSpace::COLOR_SPACE_DEFAULT, GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB },
80 { ColorSpace::COLOR_SPACE_WIDE_GAMUT, GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3 },
81 };
82
83 std::map<std::string, std::pair<uint32_t, sptr<Window>>> WindowImpl::windowMap_;
84 std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::subWindowMap_;
85 std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::appFloatingWindowMap_;
86 std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::appDialogWindowMap_;
87 std::map<uint32_t, std::vector<sptr<IScreenshotListener>>> WindowImpl::screenshotListeners_;
88 std::map<uint32_t, std::vector<sptr<ITouchOutsideListener>>> WindowImpl::touchOutsideListeners_;
89 std::map<uint32_t, std::vector<sptr<IDialogTargetTouchListener>>> WindowImpl::dialogTargetTouchListeners_;
90 std::map<uint32_t, std::vector<sptr<IWindowLifeCycle>>> WindowImpl::lifecycleListeners_;
91 std::map<uint32_t, std::vector<sptr<IWindowChangeListener>>> WindowImpl::windowChangeListeners_;
92 std::map<uint32_t, std::vector<sptr<IAvoidAreaChangedListener>>> WindowImpl::avoidAreaChangeListeners_;
93 std::map<uint32_t, std::vector<sptr<IOccupiedAreaChangeListener>>> WindowImpl::occupiedAreaChangeListeners_;
94 std::map<uint32_t, sptr<IDialogDeathRecipientListener>> WindowImpl::dialogDeathRecipientListener_;
95 std::recursive_mutex WindowImpl::globalMutex_;
96 int g_constructorCnt = 0;
97 int g_deConstructorCnt = 0;
WindowImpl(const sptr<WindowOption> & option)98 WindowImpl::WindowImpl(const sptr<WindowOption>& option)
99 {
100 handler_ = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
101 property_ = new (std::nothrow) WindowProperty();
102 if (property_ == nullptr) {
103 WLOGFE("Property is null");
104 return;
105 }
106 InitWindowProperty(option);
107
108 windowTag_ = option->GetWindowTag();
109 isMainHandlerAvailable_ = option->GetMainHandlerAvailable();
110 AdjustWindowAnimationFlag();
111 UpdateDecorEnable();
112 auto& sysBarPropMap = option->GetSystemBarProperty();
113 for (auto it : sysBarPropMap) {
114 property_->SetSystemBarProperty(it.first, it.second);
115 }
116 name_ = option->GetWindowName();
117
118 surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), option->GetWindowType());
119 if (surfaceNode_ != nullptr) {
120 vsyncStation_ = std::make_shared<VsyncStation>(surfaceNode_->GetId());
121 }
122
123 moveDragProperty_ = new (std::nothrow) MoveDragProperty();
124 if (moveDragProperty_ == nullptr) {
125 WLOGFE("MoveDragProperty is null");
126 }
127 WLOGFD("g_constructorCnt: %{public}d name: %{public}s",
128 ++g_constructorCnt, property_->GetWindowName().c_str());
129 }
130
InitWindowProperty(const sptr<WindowOption> & option)131 void WindowImpl::InitWindowProperty(const sptr<WindowOption>& option)
132 {
133 if (option == nullptr) {
134 TLOGE(WmsLogTag::WMS_MAIN, "Init window property failed, option is nullptr.");
135 return;
136 }
137 property_->SetWindowName(option->GetWindowName());
138 property_->SetRequestRect(option->GetWindowRect());
139 property_->SetWindowType(option->GetWindowType());
140 if (WindowHelper::IsAppFloatingWindow(option->GetWindowType())) {
141 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
142 } else {
143 property_->SetWindowMode(option->GetWindowMode());
144 }
145 property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN);
146 property_->SetFocusable(option->GetFocusable());
147 property_->SetTouchable(option->GetTouchable());
148 property_->SetDisplayId(option->GetDisplayId());
149 property_->SetCallingWindow(option->GetCallingWindow());
150 property_->SetWindowFlags(option->GetWindowFlags());
151 property_->SetHitOffset(option->GetHitOffset());
152 property_->SetRequestedOrientation(option->GetRequestedOrientation());
153 property_->SetTurnScreenOn(option->IsTurnScreenOn());
154 property_->SetKeepScreenOn(option->IsKeepScreenOn());
155 property_->SetBrightness(option->GetBrightness());
156 }
157
CreateSurfaceNode(std::string name,WindowType type)158 RSSurfaceNode::SharedPtr WindowImpl::CreateSurfaceNode(std::string name, WindowType type)
159 {
160 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
161 rsSurfaceNodeConfig.SurfaceNodeName = name;
162 RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
163 switch (type) {
164 case WindowType::WINDOW_TYPE_BOOT_ANIMATION:
165 case WindowType::WINDOW_TYPE_POINTER:
166 rsSurfaceNodeType = RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
167 break;
168 case WindowType::WINDOW_TYPE_APP_MAIN_WINDOW:
169 rsSurfaceNodeType = RSSurfaceNodeType::APP_WINDOW_NODE;
170 break;
171 case WindowType::WINDOW_TYPE_PIP:
172 rsSurfaceNodeType = RSSurfaceNodeType::APP_WINDOW_NODE;
173 break;
174 default:
175 rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
176 break;
177 }
178
179 auto isPhone = windowSystemConfig_.uiType_ == UI_TYPE_PHONE;
180 if (isPhone && WindowHelper::IsWindowFollowParent(type)) {
181 rsSurfaceNodeType = RSSurfaceNodeType::ABILITY_COMPONENT_NODE;
182 }
183 return RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
184 }
185
~WindowImpl()186 WindowImpl::~WindowImpl()
187 {
188 WLOGI("windowName: %{public}s, windowId: %{public}d, g_deConstructorCnt: %{public}d, surfaceNode:%{public}d",
189 GetWindowName().c_str(), GetWindowId(), ++g_deConstructorCnt, static_cast<uint32_t>(surfaceNode_.use_count()));
190 Destroy(true, false);
191 }
192
Find(const std::string & name)193 sptr<Window> WindowImpl::Find(const std::string& name)
194 {
195 auto iter = windowMap_.find(name);
196 if (iter == windowMap_.end()) {
197 return nullptr;
198 }
199 return iter->second.second;
200 }
201
GetContext() const202 const std::shared_ptr<AbilityRuntime::Context> WindowImpl::GetContext() const
203 {
204 return context_;
205 }
206
FindWindowById(uint32_t WinId)207 sptr<Window> WindowImpl::FindWindowById(uint32_t WinId)
208 {
209 if (windowMap_.empty()) {
210 WLOGFE("Please create mainWindow First!");
211 return nullptr;
212 }
213 for (auto iter = windowMap_.begin(); iter != windowMap_.end(); iter++) {
214 if (WinId == iter->second.first) {
215 WLOGI("FindWindow id: %{public}u", WinId);
216 return iter->second.second;
217 }
218 }
219 WLOGFE("Cannot find Window!");
220 return nullptr;
221 }
222
GetTopWindowWithId(uint32_t mainWinId)223 sptr<Window> WindowImpl::GetTopWindowWithId(uint32_t mainWinId)
224 {
225 uint32_t topWinId = INVALID_WINDOW_ID;
226 WMError ret = SingletonContainer::Get<WindowAdapter>().GetTopWindowId(mainWinId, topWinId);
227 if (ret != WMError::WM_OK) {
228 WLOGFE("GetTopWindowId failed with errCode:%{public}d", static_cast<int32_t>(ret));
229 return nullptr;
230 }
231 return FindWindowById(topWinId);
232 }
233
GetWindowWithId(uint32_t WinId)234 sptr<Window> WindowImpl::GetWindowWithId(uint32_t WinId)
235 {
236 return FindWindowById(WinId);
237 }
238
GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context> & context)239 sptr<Window> WindowImpl::GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context)
240 {
241 if (windowMap_.empty()) {
242 WLOGFE("Please create mainWindow First!");
243 return nullptr;
244 }
245 uint32_t mainWinId = INVALID_WINDOW_ID;
246 for (auto iter = windowMap_.begin(); iter != windowMap_.end(); iter++) {
247 auto win = iter->second.second;
248 if (context.get() == win->GetContext().get() && WindowHelper::IsMainWindow(win->GetType())) {
249 mainWinId = win->GetWindowId();
250 WLOGI("GetTopWindow Find MainWinId:%{public}u.", mainWinId);
251 break;
252 }
253 }
254 WLOGI("GetTopWindowfinal winId:%{public}u!", mainWinId);
255 if (mainWinId == INVALID_WINDOW_ID) {
256 WLOGFE("Cannot find topWindow!");
257 return nullptr;
258 }
259 uint32_t topWinId = INVALID_WINDOW_ID;
260 WMError ret = SingletonContainer::Get<WindowAdapter>().GetTopWindowId(mainWinId, topWinId);
261 if (ret != WMError::WM_OK) {
262 WLOGFE("GetTopWindowId failed with errCode:%{public}d", static_cast<int32_t>(ret));
263 return nullptr;
264 }
265 return FindWindowById(topWinId);
266 }
267
GetSubWindow(uint32_t parentId)268 std::vector<sptr<Window>> WindowImpl::GetSubWindow(uint32_t parentId)
269 {
270 if (subWindowMap_.find(parentId) == subWindowMap_.end()) {
271 WLOGFE("Cannot parentWindow with id: %{public}u!", parentId);
272 return std::vector<sptr<Window>>();
273 }
274 return std::vector<sptr<Window>>(subWindowMap_[parentId].begin(), subWindowMap_[parentId].end());
275 }
276
UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration> & configuration)277 void WindowImpl::UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
278 {
279 for (const auto& winPair : windowMap_) {
280 auto window = winPair.second.second;
281 window->UpdateConfiguration(configuration);
282 }
283 }
284
UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration> & configuration)285 void WindowImpl::UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
286 {
287 if (uiContent_ != nullptr) {
288 TLOGI(WmsLogTag::WMS_IMMS, "winId: %{public}d", GetWindowId());
289 uiContent_->UpdateConfigurationSyncForAll(configuration);
290 }
291 if (subWindowMap_.count(GetWindowId()) == 0) {
292 TLOGI(WmsLogTag::WMS_IMMS, "no subWindow, winId: %{public}d", GetWindowId());
293 return;
294 }
295 for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
296 subWindow->UpdateConfigurationSync(configuration);
297 }
298 }
299
UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration> & configuration)300 void WindowImpl::UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
301 {
302 for (const auto& winPair : windowMap_) {
303 if (auto window = winPair.second.second) {
304 window->UpdateConfigurationSync(configuration);
305 }
306 }
307 }
308
GetSurfaceNode() const309 std::shared_ptr<RSSurfaceNode> WindowImpl::GetSurfaceNode() const
310 {
311 return surfaceNode_;
312 }
313
GetRect() const314 Rect WindowImpl::GetRect() const
315 {
316 return property_->GetWindowRect();
317 }
318
GetRequestRect() const319 Rect WindowImpl::GetRequestRect() const
320 {
321 return property_->GetRequestRect();
322 }
323
GetType() const324 WindowType WindowImpl::GetType() const
325 {
326 return property_->GetWindowType();
327 }
328
GetMode() const329 WindowMode WindowImpl::GetMode() const
330 {
331 return property_->GetWindowMode();
332 }
333
GetAlpha() const334 float WindowImpl::GetAlpha() const
335 {
336 return property_->GetAlpha();
337 }
338
GetWindowState() const339 WindowState WindowImpl::GetWindowState() const
340 {
341 return state_;
342 }
343
SetFocusable(bool isFocusable)344 WMError WindowImpl::SetFocusable(bool isFocusable)
345 {
346 if (!IsWindowValid()) {
347 return WMError::WM_ERROR_INVALID_WINDOW;
348 }
349 property_->SetFocusable(isFocusable);
350 if (state_ == WindowState::STATE_SHOWN) {
351 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
352 }
353 return WMError::WM_OK;
354 }
355
GetFocusable() const356 bool WindowImpl::GetFocusable() const
357 {
358 return property_->GetFocusable();
359 }
360
SetTouchable(bool isTouchable)361 WMError WindowImpl::SetTouchable(bool isTouchable)
362 {
363 if (!IsWindowValid()) {
364 return WMError::WM_ERROR_INVALID_WINDOW;
365 }
366 property_->SetTouchable(isTouchable);
367 if (state_ == WindowState::STATE_SHOWN) {
368 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
369 }
370 return WMError::WM_OK;
371 }
372
GetTouchable() const373 bool WindowImpl::GetTouchable() const
374 {
375 return property_->GetTouchable();
376 }
377
GetWindowName() const378 const std::string& WindowImpl::GetWindowName() const
379 {
380 return name_;
381 }
382
GetWindowId() const383 uint32_t WindowImpl::GetWindowId() const
384 {
385 return property_->GetWindowId();
386 }
387
GetDisplayId() const388 uint64_t WindowImpl::GetDisplayId() const
389 {
390 return property_->GetDisplayId();
391 }
392
GetWindowFlags() const393 uint32_t WindowImpl::GetWindowFlags() const
394 {
395 return property_->GetWindowFlags();
396 }
397
GetRequestWindowModeSupportType() const398 uint32_t WindowImpl::GetRequestWindowModeSupportType() const
399 {
400 return property_->GetRequestWindowModeSupportType();
401 }
402
GetWindowModeSupportType() const403 uint32_t WindowImpl::GetWindowModeSupportType() const
404 {
405 return property_->GetWindowModeSupportType();
406 }
407
IsMainHandlerAvailable() const408 bool WindowImpl::IsMainHandlerAvailable() const
409 {
410 return isMainHandlerAvailable_;
411 }
412
GetSystemBarPropertyByType(WindowType type) const413 SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const
414 {
415 auto curProperties = property_->GetSystemBarProperty();
416 return curProperties[type];
417 }
418
GetAvoidAreaByType(AvoidAreaType type,AvoidArea & avoidArea)419 WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea)
420 {
421 if (!IsWindowValid()) {
422 return WMError::WM_ERROR_INVALID_WINDOW;
423 }
424 WLOGI("GetAvoidAreaByType Search Type: %{public}u", static_cast<uint32_t>(type));
425 uint32_t windowId = property_->GetWindowId();
426 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAvoidAreaByType(windowId, type, avoidArea);
427 if (ret != WMError::WM_OK) {
428 WLOGFE("GetAvoidAreaByType errCode:%{public}d winId:%{public}u Type is :%{public}u.",
429 static_cast<int32_t>(ret), property_->GetWindowId(), static_cast<uint32_t>(type));
430 }
431 return ret;
432 }
433
SetWindowType(WindowType type)434 WMError WindowImpl::SetWindowType(WindowType type)
435 {
436 WLOGFD("window id: %{public}u, type:%{public}u.", property_->GetWindowId(), static_cast<uint32_t>(type));
437 if (type != WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW && !Permission::IsSystemCalling() &&
438 !Permission::IsStartByHdcd()) {
439 WLOGFE("set window type permission denied!");
440 return WMError::WM_ERROR_NOT_SYSTEM_APP;
441 }
442 if (!IsWindowValid()) {
443 return WMError::WM_ERROR_INVALID_WINDOW;
444 }
445 if (state_ == WindowState::STATE_CREATED) {
446 if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) {
447 WLOGFE("window type is invalid %{public}u.", type);
448 return WMError::WM_ERROR_INVALID_PARAM;
449 }
450 property_->SetWindowType(type);
451 UpdateDecorEnable();
452 AdjustWindowAnimationFlag();
453 return WMError::WM_OK;
454 }
455 if (property_->GetWindowType() != type) {
456 return WMError::WM_ERROR_INVALID_PARAM;
457 }
458 return WMError::WM_OK;
459 }
460
SetWindowMode(WindowMode mode)461 WMError WindowImpl::SetWindowMode(WindowMode mode)
462 {
463 WLOGI("Window %{public}u mode %{public}u", property_->GetWindowId(), static_cast<uint32_t>(mode));
464 if (!IsWindowValid()) {
465 return WMError::WM_ERROR_INVALID_WINDOW;
466 }
467 if (!WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), mode)) {
468 WLOGE("window %{public}u do not support mode: %{public}u",
469 property_->GetWindowId(), static_cast<uint32_t>(mode));
470 return WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE;
471 }
472 if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
473 UpdateMode(mode);
474 } else if (state_ == WindowState::STATE_SHOWN) {
475 WindowMode lastMode = property_->GetWindowMode();
476 property_->SetWindowMode(mode);
477 UpdateDecorEnable();
478 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MODE);
479 if (ret != WMError::WM_OK) {
480 property_->SetWindowMode(lastMode);
481 return ret;
482 }
483 // set client window mode if success.
484 UpdateMode(mode);
485 }
486 if (property_->GetWindowMode() != mode) {
487 WLOGFE("set window mode filed! id: %{public}u.", property_->GetWindowId());
488 return WMError::WM_ERROR_INVALID_PARAM;
489 }
490 return WMError::WM_OK;
491 }
492
SetAlpha(float alpha)493 WMError WindowImpl::SetAlpha(float alpha)
494 {
495 WLOGI("Window %{public}u alpha %{public}f", property_->GetWindowId(), alpha);
496 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
497 WLOGFE("set alpha permission denied!");
498 return WMError::WM_ERROR_NOT_SYSTEM_APP;
499 }
500 if (!IsWindowValid()) {
501 return WMError::WM_ERROR_INVALID_WINDOW;
502 }
503 property_->SetAlpha(alpha);
504 surfaceNode_->SetAlpha(alpha);
505 RSTransaction::FlushImplicitTransaction();
506 return WMError::WM_OK;
507 }
508
SetTransform(const Transform & trans)509 WMError WindowImpl::SetTransform(const Transform& trans)
510 {
511 WLOGI("Window %{public}u", property_->GetWindowId());
512 if (!IsWindowValid()) {
513 return WMError::WM_ERROR_INVALID_WINDOW;
514 }
515 Transform oriTrans = property_->GetTransform();
516 property_->SetTransform(trans);
517 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
518 if (ret != WMError::WM_OK) {
519 WLOGFE("SetTransform errCode:%{public}d winId:%{public}u",
520 static_cast<int32_t>(ret), property_->GetWindowId());
521 property_->SetTransform(oriTrans); // reset to ori transform when update failed
522 }
523 if (property_->IsDisplayZoomOn()) {
524 TransformSurfaceNode(property_->GetZoomTransform());
525 } else {
526 TransformSurfaceNode(trans);
527 }
528 return ret;
529 }
530
GetTransform() const531 const Transform& WindowImpl::GetTransform() const
532 {
533 return property_->GetTransform();
534 }
535
GetZoomTransform() const536 const Transform& WindowImpl::GetZoomTransform() const
537 {
538 return property_->GetZoomTransform();
539 }
540
AddWindowFlag(WindowFlag flag)541 WMError WindowImpl::AddWindowFlag(WindowFlag flag)
542 {
543 if (!IsWindowValid()) {
544 return WMError::WM_ERROR_INVALID_WINDOW;
545 }
546 if (flag == WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED && state_ != WindowState::STATE_CREATED) {
547 WLOGFE("Only support add show when locked when window create, id: %{public}u", property_->GetWindowId());
548 return WMError::WM_ERROR_INVALID_WINDOW;
549 }
550 if (flag == WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE && !Permission::IsSystemCalling()) {
551 WLOGFE("set forbid split move permission denied!");
552 return WMError::WM_ERROR_NOT_SYSTEM_APP;
553 }
554 uint32_t updateFlags = property_->GetWindowFlags() | (static_cast<uint32_t>(flag));
555 return SetWindowFlags(updateFlags);
556 }
557
RemoveWindowFlag(WindowFlag flag)558 WMError WindowImpl::RemoveWindowFlag(WindowFlag flag)
559 {
560 if (!IsWindowValid()) {
561 return WMError::WM_ERROR_INVALID_WINDOW;
562 }
563 if (flag == WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED && state_ != WindowState::STATE_CREATED) {
564 WLOGFE("Only support remove show when locked when window create, id: %{public}u", property_->GetWindowId());
565 return WMError::WM_ERROR_INVALID_WINDOW;
566 }
567 if (flag == WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE && !Permission::IsSystemCalling()) {
568 WLOGFE("set forbid split move permission denied!");
569 return WMError::WM_ERROR_NOT_SYSTEM_APP;
570 }
571 uint32_t updateFlags = property_->GetWindowFlags() & (~(static_cast<uint32_t>(flag)));
572 return SetWindowFlags(updateFlags);
573 }
574
SetWindowFlags(uint32_t flags)575 WMError WindowImpl::SetWindowFlags(uint32_t flags)
576 {
577 WLOGI("Window %{public}u flags %{public}u", property_->GetWindowId(), flags);
578 if (!IsWindowValid()) {
579 return WMError::WM_ERROR_INVALID_WINDOW;
580 }
581 if (property_->GetWindowFlags() == flags) {
582 return WMError::WM_OK;
583 }
584 auto oriFlags = property_->GetWindowFlags();
585 property_->SetWindowFlags(flags);
586 if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
587 return WMError::WM_OK;
588 }
589 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_FLAGS);
590 if (ret != WMError::WM_OK) {
591 WLOGFE("SetWindowFlags errCode:%{public}d winId:%{public}u",
592 static_cast<int32_t>(ret), property_->GetWindowId());
593 property_->SetWindowFlags(oriFlags);
594 }
595 return ret;
596 }
597
OnNewWant(const AAFwk::Want & want)598 void WindowImpl::OnNewWant(const AAFwk::Want& want)
599 {
600 WLOGI("Window [name:%{public}s, id:%{public}u]", name_.c_str(), property_->GetWindowId());
601 if (uiContent_ != nullptr) {
602 uiContent_->OnNewWant(want);
603 }
604 }
605
NapiSetUIContent(const std::string & contentInfo,napi_env env,napi_value storage,BackupAndRestoreType type,sptr<IRemoteObject> token,AppExecFwk::Ability * ability)606 WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
607 BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
608 {
609 return SetUIContentInner(contentInfo, env, storage,
610 type == BackupAndRestoreType::NONE ? WindowSetUIContentType::DEFAULT : WindowSetUIContentType::RESTORE,
611 type, ability);
612 }
613
SetUIContentByName(const std::string & contentInfo,napi_env env,napi_value storage,AppExecFwk::Ability * ability)614 WMError WindowImpl::SetUIContentByName(
615 const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
616 {
617 return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_NAME,
618 BackupAndRestoreType::NONE, ability);
619 }
620
SetUIContentByAbc(const std::string & contentInfo,napi_env env,napi_value storage,AppExecFwk::Ability * ability)621 WMError WindowImpl::SetUIContentByAbc(
622 const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
623 {
624 return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC,
625 BackupAndRestoreType::NONE, ability);
626 }
627
SetUIContentInner(const std::string & contentInfo,napi_env env,napi_value storage,WindowSetUIContentType setUIContentType,BackupAndRestoreType restoreType,AppExecFwk::Ability * ability)628 WMError WindowImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage,
629 WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability)
630 {
631 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "loadContent");
632 if (!IsWindowValid()) {
633 WLOGFD("interrupt set uicontent because window is invalid! window state: %{public}d", state_);
634 return WMError::WM_ERROR_INVALID_WINDOW;
635 }
636 WLOGFD("NapiSetUIContent: %{public}s", contentInfo.c_str());
637 if (uiContent_) {
638 uiContent_->Destroy();
639 }
640 std::unique_ptr<Ace::UIContent> uiContent;
641 if (ability != nullptr) {
642 uiContent = Ace::UIContent::Create(ability);
643 } else {
644 uiContent = Ace::UIContent::Create(context_.get(), reinterpret_cast<NativeEngine*>(env));
645 }
646 if (uiContent == nullptr) {
647 WLOGFE("fail to NapiSetUIContent id: %{public}u", property_->GetWindowId());
648 return WMError::WM_ERROR_NULLPTR;
649 }
650
651 OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
652 switch (setUIContentType) {
653 default:
654 case WindowSetUIContentType::DEFAULT: {
655 auto routerStack = GetRestoredRouterStack();
656 auto type = GetAceContentInfoType(BackupAndRestoreType::RESOURCESCHEDULE_RECOVERY);
657 if (!routerStack.empty() &&
658 uiContent->Restore(this, routerStack, storage, type) == Ace::UIContentErrorCode::NO_ERRORS) {
659 TLOGI(WmsLogTag::WMS_LIFE, "Restore router stack succeed.");
660 break;
661 }
662 aceRet = uiContent->Initialize(this, contentInfo, storage);
663 break;
664 }
665 case WindowSetUIContentType::RESTORE:
666 aceRet = uiContent->Restore(this, contentInfo, storage, GetAceContentInfoType(restoreType));
667 break;
668 case WindowSetUIContentType::BY_NAME:
669 aceRet = uiContent->InitializeByName(this, contentInfo, storage);
670 break;
671 case WindowSetUIContentType::BY_ABC:
672 auto abcContent = GetAbcContent(contentInfo);
673 aceRet = uiContent->Initialize(this, abcContent, storage, contentInfo);
674 break;
675 }
676 // make uiContent available after Initialize/Restore
677 {
678 std::lock_guard<std::recursive_mutex> lock(mutex_);
679 uiContent_ = std::move(uiContent);
680 }
681
682 if (isIgnoreSafeAreaNeedNotify_) {
683 uiContent_->SetIgnoreViewSafeArea(isIgnoreSafeArea_);
684 }
685 UpdateDecorEnable(true);
686
687 if (state_ == WindowState::STATE_SHOWN) {
688 // UIContent may be nullptr when show window, need to notify again when window is shown
689 uiContent_->Foreground();
690 UpdateTitleButtonVisibility();
691 Ace::ViewportConfig config;
692 Rect rect = GetRect();
693 config.SetSize(rect.width_, rect.height_);
694 config.SetPosition(rect.posX_, rect.posY_);
695 auto display = SingletonContainer::IsDestroyed() ? nullptr :
696 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
697 if (display == nullptr) {
698 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
699 property_->GetWindowId());
700 return WMError::WM_ERROR_NULLPTR;
701 }
702 float virtualPixelRatio = display->GetVirtualPixelRatio();
703 config.SetDensity(virtualPixelRatio);
704 auto displayInfo = display->GetDisplayInfo();
705 if (displayInfo != nullptr) {
706 config.SetOrientation(static_cast<int32_t>(displayInfo->GetDisplayOrientation()));
707 TLOGI(WmsLogTag::WMS_LIFE, "notify window orientation change end.");
708 }
709 uiContent_->UpdateViewportConfig(config, WindowSizeChangeReason::UNDEFINED, nullptr);
710 WLOGFD("notify uiContent window size change end");
711 }
712 if (aceRet != OHOS::Ace::UIContentErrorCode::NO_ERRORS) {
713 WLOGFE("failed to init or restore uicontent with file %{public}s. errorCode: %{public}d",
714 contentInfo.c_str(), static_cast<uint16_t>(aceRet));
715 return WMError::WM_ERROR_INVALID_PARAM;
716 }
717 return WMError::WM_OK;
718 }
719
GetVirtualPixelRatio()720 float WindowImpl::GetVirtualPixelRatio()
721 {
722 float vpr = 1.0f; // This is an abnormal value, which is used to identify abnormal scenarios.
723 auto display = SingletonContainer::IsDestroyed() ? nullptr :
724 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
725 if (display == nullptr) {
726 TLOGE(WmsLogTag::WMS_LAYOUT, "get display failed displayId:%{public}" PRIu64 ", window id:%{public}u",
727 property_->GetDisplayId(), property_->GetWindowId());
728 return vpr;
729 }
730 return display->GetVirtualPixelRatio();
731 }
732
GetAbcContent(const std::string & abcPath)733 std::shared_ptr<std::vector<uint8_t>> WindowImpl::GetAbcContent(const std::string& abcPath)
734 {
735 std::filesystem::path abcFile { abcPath };
736 if (abcFile.empty() || !abcFile.is_absolute() || !std::filesystem::exists(abcFile)) {
737 WLOGFE("abc file path is not valid");
738 return nullptr;
739 }
740 int begin, end;
741 std::fstream file(abcFile, std::ios::in | std::ios::binary);
742 if (!file) {
743 WLOGFE("abc file is not valid");
744 return nullptr;
745 }
746 begin = file.tellg();
747 file.seekg(0, std::ios::end);
748 end = file.tellg();
749 int len = end - begin;
750 WLOGFD("abc file: %{public}s, size: %{public}d", abcPath.c_str(), len);
751
752 if (len <= 0) {
753 WLOGFE("abc file size is 0");
754 return nullptr;
755 }
756 std::vector<uint8_t> abcBytes(len);
757 file.seekg(0, std::ios::beg);
758 file.read(reinterpret_cast<char *>(abcBytes.data()), len);
759 return std::make_shared<std::vector<uint8_t>>(abcBytes);
760 }
761
GetUIContent() const762 Ace::UIContent* WindowImpl::GetUIContent() const
763 {
764 return uiContent_.get();
765 }
766
GetUIContentWithId(uint32_t winId) const767 Ace::UIContent* WindowImpl::GetUIContentWithId(uint32_t winId) const
768 {
769 return nullptr;
770 }
771
GetContentInfo(BackupAndRestoreType type)772 std::string WindowImpl::GetContentInfo(BackupAndRestoreType type)
773 {
774 WLOGFD("GetContentInfo");
775 if (type == BackupAndRestoreType::NONE) {
776 return "";
777 }
778
779 if (uiContent_ == nullptr) {
780 WLOGFE("fail to GetContentInfo id: %{public}u", property_->GetWindowId());
781 return "";
782 }
783 return uiContent_->GetContentInfo(GetAceContentInfoType(type));
784 }
785
SetRestoredRouterStack(const std::string & routerStack)786 WMError WindowImpl::SetRestoredRouterStack(const std::string& routerStack)
787 {
788 TLOGD(WmsLogTag::WMS_LIFE, "Set restored router stack.");
789 restoredRouterStack_ = routerStack;
790 return WMError::WM_OK;
791 }
792
GetRestoredRouterStack()793 std::string WindowImpl::GetRestoredRouterStack()
794 {
795 TLOGD(WmsLogTag::WMS_LIFE, "Get restored router stack.");
796 return std::move(restoredRouterStack_);
797 }
798
GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut)799 ColorSpace WindowImpl::GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut)
800 {
801 for (auto item: colorSpaceConvertMap) {
802 if (item.surfaceColorGamut == colorGamut) {
803 return item.colorSpace;
804 }
805 }
806 return ColorSpace::COLOR_SPACE_DEFAULT;
807 }
808
GetSurfaceGamutFromColorSpace(ColorSpace colorSpace)809 GraphicColorGamut WindowImpl::GetSurfaceGamutFromColorSpace(ColorSpace colorSpace)
810 {
811 for (auto item: colorSpaceConvertMap) {
812 if (item.colorSpace == colorSpace) {
813 return item.surfaceColorGamut;
814 }
815 }
816 return GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
817 }
818
IsSupportWideGamut()819 bool WindowImpl::IsSupportWideGamut()
820 {
821 return true;
822 }
823
SetColorSpace(ColorSpace colorSpace)824 void WindowImpl::SetColorSpace(ColorSpace colorSpace)
825 {
826 if (!IsWindowValid()) {
827 return;
828 }
829 if (surfaceNode_ == nullptr) {
830 TLOGE(WmsLogTag::DEFAULT, "surface node is nullptr, winId: %{public}u", GetWindowId());
831 return;
832 }
833 auto surfaceGamut = GetSurfaceGamutFromColorSpace(colorSpace);
834 surfaceNode_->SetColorSpace(surfaceGamut);
835 }
836
GetColorSpace()837 ColorSpace WindowImpl::GetColorSpace()
838 {
839 if (!IsWindowValid()) {
840 return ColorSpace::COLOR_SPACE_DEFAULT;
841 }
842 if (surfaceNode_ == nullptr) {
843 TLOGE(WmsLogTag::DEFAULT, "surface node is nullptr, winId: %{public}u", GetWindowId());
844 return ColorSpace::COLOR_SPACE_DEFAULT;
845 }
846 auto surfaceGamut = surfaceNode_->GetColorSpace();
847 return GetColorSpaceFromSurfaceGamut(surfaceGamut);
848 }
849
Snapshot()850 std::shared_ptr<Media::PixelMap> WindowImpl::Snapshot()
851 {
852 if (!IsWindowValid()) {
853 return nullptr;
854 }
855 std::shared_ptr<SurfaceCaptureFuture> callback = std::make_shared<SurfaceCaptureFuture>();
856 auto isSucceeded = RSInterfaces::GetInstance().TakeSurfaceCapture(surfaceNode_, callback);
857 std::shared_ptr<Media::PixelMap> pixelMap;
858 if (isSucceeded) {
859 pixelMap = callback->GetResult(2000); // wait for <= 2000ms
860 } else {
861 pixelMap = SingletonContainer::Get<WindowAdapter>().GetSnapshot(property_->GetWindowId());
862 }
863 if (pixelMap != nullptr) {
864 WLOGFD("WMS-Client Save WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight());
865 } else {
866 WLOGFE("Failed to get pixelmap, return nullptr!");
867 }
868 return pixelMap;
869 }
870
DumpInfo(const std::vector<std::string> & params,std::vector<std::string> & info)871 void WindowImpl::DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info)
872 {
873 if (params.size() == 1 && params[0] == PARAM_DUMP_HELP) { // 1: params num
874 WLOGFD("Dump ArkUI help Info");
875 Ace::UIContent::ShowDumpHelp(info);
876 SingletonContainer::Get<WindowAdapter>().NotifyDumpInfoResult(info);
877 return;
878 }
879 WLOGFD("ArkUI:DumpInfo");
880 if (uiContent_ != nullptr) {
881 uiContent_->DumpInfo(params, info);
882 }
883 SingletonContainer::Get<WindowAdapter>().NotifyDumpInfoResult(info);
884 }
885
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)886 WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
887 {
888 WLOGI("Window %{public}u type %{public}u enable:%{public}u, bgColor:%{public}x, Color:%{public}x ",
889 property_->GetWindowId(), static_cast<uint32_t>(type), property.enable_,
890 property.backgroundColor_, property.contentColor_);
891 if (!IsWindowValid()) {
892 return WMError::WM_ERROR_INVALID_WINDOW;
893 }
894 if (GetSystemBarPropertyByType(type) == property) {
895 return WMError::WM_OK;
896 }
897 property_->SetSystemBarProperty(type, property);
898 if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
899 return WMError::WM_OK;
900 }
901 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
902 if (ret != WMError::WM_OK) {
903 WLOGFE("SetSystemBarProperty errCode:%{public}d winId:%{public}u",
904 static_cast<int32_t>(ret), property_->GetWindowId());
905 }
906 return ret;
907 }
908
SetSystemBarProperties(const std::map<WindowType,SystemBarProperty> & properties,const std::map<WindowType,SystemBarPropertyFlag> & propertyFlags)909 WMError WindowImpl::SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties,
910 const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags)
911 {
912 SystemBarProperty current = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
913 auto flagIter = propertyFlags.find(WindowType::WINDOW_TYPE_STATUS_BAR);
914 auto propertyIter = properties.find(WindowType::WINDOW_TYPE_STATUS_BAR);
915 if ((flagIter != propertyFlags.end() && flagIter->second.contentColorFlag) &&
916 (propertyIter != properties.end() && current.contentColor_ != propertyIter->second.contentColor_)) {
917 current.contentColor_ = propertyIter->second.contentColor_;
918 current.settingFlag_ = static_cast<SystemBarSettingFlag>(
919 static_cast<uint32_t>(propertyIter->second.settingFlag_) |
920 static_cast<uint32_t>(SystemBarSettingFlag::COLOR_SETTING));
921 WLOGI("Window:%{public}u %{public}s set status bar content color %{public}u",
922 GetWindowId(), GetWindowName().c_str(), current.contentColor_);
923 return SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, current);
924 }
925 return WMError::WM_OK;
926 }
927
GetSystemBarProperties(std::map<WindowType,SystemBarProperty> & properties)928 WMError WindowImpl::GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties)
929 {
930 if (property_ != nullptr) {
931 WLOGI("Window:%{public}u", GetWindowId());
932 properties[WindowType::WINDOW_TYPE_STATUS_BAR] = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
933 } else {
934 WLOGFE("inner property is null");
935 }
936 return WMError::WM_OK;
937 }
938
SetSpecificBarProperty(WindowType type,const SystemBarProperty & property)939 WMError WindowImpl::SetSpecificBarProperty(WindowType type, const SystemBarProperty& property)
940 {
941 return WMError::WM_OK;
942 }
943
UpdateSystemBarProperty(bool status)944 WMError WindowImpl::UpdateSystemBarProperty(bool status)
945 {
946 if (!IsWindowValid()) {
947 WLOGFE("PutSystemBarProperty errCode:%{public}d winId:%{public}u",
948 static_cast<int32_t>(WMError::WM_ERROR_INVALID_WINDOW), property_->GetWindowId());
949 return WMError::WM_ERROR_INVALID_WINDOW;
950 }
951
952 SystemBarProperty statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
953 SystemBarProperty naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
954 if (status) {
955 statusProperty.enable_ = false;
956 naviProperty.enable_ = false;
957 } else {
958 statusProperty.enable_ = true;
959 naviProperty.enable_ = true;
960 }
961
962 if ((GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR) == statusProperty) &&
963 (GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR) == naviProperty)) {
964 return WMError::WM_OK;
965 }
966 if (!(GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR) == statusProperty)) {
967 property_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, statusProperty);
968 }
969 if (!(GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR) == naviProperty)) {
970 property_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, naviProperty);
971 }
972 if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
973 return WMError::WM_OK;
974 }
975
976 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
977 if (ret != WMError::WM_OK) {
978 WLOGFE("SetSystemBarProperty errCode:%{public}d winId:%{public}u",
979 static_cast<int32_t>(ret), property_->GetWindowId());
980 }
981 return ret;
982 }
983
SetLayoutFullScreen(bool status)984 WMError WindowImpl::SetLayoutFullScreen(bool status)
985 {
986 WLOGI("Window %{public}u status: %{public}u", property_->GetWindowId(), status);
987 if (!IsWindowValid() ||
988 !WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), WindowMode::WINDOW_MODE_FULLSCREEN)) {
989 WLOGFE("invalid window or fullscreen mode is not be supported, winId:%{public}u", property_->GetWindowId());
990 return WMError::WM_ERROR_INVALID_WINDOW;
991 }
992 WMError ret = WMError::WM_OK;
993 uint32_t version = 0;
994 if ((context_ != nullptr) && (context_->GetApplicationInfo() != nullptr)) {
995 version = context_->GetApplicationInfo()->apiCompatibleVersion;
996 }
997 ret = SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
998 if (ret != WMError::WM_OK) {
999 WLOGFE("SetWindowMode errCode:%{public}d winId:%{public}u",
1000 static_cast<int32_t>(ret), property_->GetWindowId());
1001 return ret;
1002 }
1003 isIgnoreSafeArea_ = status;
1004 // 10 ArkUI new framework support after API10
1005 if (version >= 10) {
1006 if (uiContent_ != nullptr) {
1007 uiContent_->SetIgnoreViewSafeArea(status);
1008 }
1009 isIgnoreSafeAreaNeedNotify_ = true;
1010 } else {
1011 if (status) {
1012 ret = RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
1013 if (ret != WMError::WM_OK) {
1014 WLOGFE("RemoveWindowFlag errCode:%{public}d winId:%{public}u",
1015 static_cast<int32_t>(ret), property_->GetWindowId());
1016 return ret;
1017 }
1018 } else {
1019 ret = AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
1020 if (ret != WMError::WM_OK) {
1021 WLOGFE("AddWindowFlag errCode:%{public}d winId:%{public}u",
1022 static_cast<int32_t>(ret), property_->GetWindowId());
1023 return ret;
1024 }
1025 }
1026 }
1027 enableImmersiveMode_ = status;
1028 return ret;
1029 }
1030
SetFullScreen(bool status)1031 WMError WindowImpl::SetFullScreen(bool status)
1032 {
1033 WLOGI("Window %{public}u status: %{public}d", property_->GetWindowId(), status);
1034 if (!IsWindowValid() ||
1035 !WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), WindowMode::WINDOW_MODE_FULLSCREEN)) {
1036 WLOGFE("invalid window or fullscreen mode is not be supported, winId:%{public}u", property_->GetWindowId());
1037 return WMError::WM_ERROR_INVALID_WINDOW;
1038 }
1039 WMError ret = UpdateSystemBarProperty(status);
1040 if (ret != WMError::WM_OK) {
1041 WLOGFE("UpdateSystemBarProperty errCode:%{public}d winId:%{public}u",
1042 static_cast<int32_t>(ret), property_->GetWindowId());
1043 }
1044 ret = SetLayoutFullScreen(status);
1045 if (ret != WMError::WM_OK) {
1046 WLOGFE("SetLayoutFullScreen errCode:%{public}d winId:%{public}u",
1047 static_cast<int32_t>(ret), property_->GetWindowId());
1048 }
1049 return ret;
1050 }
1051
SetFloatingMaximize(bool isEnter)1052 WMError WindowImpl::SetFloatingMaximize(bool isEnter)
1053 {
1054 WLOGFI("id:%{public}d SetFloatingMaximize status: %{public}d", property_->GetWindowId(), isEnter);
1055 if (!IsWindowValid() ||
1056 !WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), WindowMode::WINDOW_MODE_FULLSCREEN)) {
1057 WLOGFE("invalid window or maximize mode is not be supported, winId:%{public}u", property_->GetWindowId());
1058 return WMError::WM_ERROR_INVALID_WINDOW;
1059 }
1060
1061 if (isEnter && GetGlobalMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
1062 WMError ret = SetFullScreen(true);
1063 if (ret == WMError::WM_OK) {
1064 property_->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
1065 }
1066 return ret;
1067 }
1068
1069 if (isEnter && GetMode() != WindowMode::WINDOW_MODE_FLOATING) {
1070 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
1071 SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1072 }
1073 }
1074 property_->SetMaximizeMode(isEnter ? MaximizeMode::MODE_AVOID_SYSTEM_BAR : MaximizeMode::MODE_RECOVER);
1075 property_->SetWindowSizeChangeReason(WindowSizeChangeReason::RESIZE);
1076 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE);
1077 }
1078
SetAspectRatio(float ratio)1079 WMError WindowImpl::SetAspectRatio(float ratio)
1080 {
1081 WLOGFI("windowId: %{public}u, ratio: %{public}f", GetWindowId(), ratio);
1082 if (!WindowHelper::IsMainWindow(GetType())) {
1083 WLOGFE("Invalid operation, windowId: %{public}u", GetWindowId());
1084 return WMError::WM_ERROR_INVALID_OPERATION;
1085 }
1086 if (MathHelper::NearZero(ratio) || ratio < 0.0f) {
1087 WLOGFE("Invalid param, ratio: %{public}f", ratio);
1088 return WMError::WM_ERROR_INVALID_PARAM;
1089 }
1090 property_->SetAspectRatio(ratio);
1091 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1092 WLOGFD("window is hidden or created! id: %{public}u, ratio: %{public}f ", property_->GetWindowId(), ratio);
1093 return WMError::WM_OK;
1094 }
1095 auto ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO);
1096 if (ret != WMError::WM_OK) {
1097 WLOGFE("Set AspectRatio failed. errorCode: %{public}u", ret);
1098 }
1099 return ret;
1100 }
1101
ResetAspectRatio()1102 WMError WindowImpl::ResetAspectRatio()
1103 {
1104 if (!IsWindowValid()) {
1105 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
1106 return WMError::WM_ERROR_INVALID_OPERATION;
1107 }
1108
1109 WLOGFI("windowId: %{public}u", GetWindowId());
1110 if (!WindowHelper::IsMainWindow(GetType())) {
1111 WLOGFE("Invalid operation, windowId: %{public}u", GetWindowId());
1112 return WMError::WM_ERROR_INVALID_OPERATION;
1113 }
1114 property_->SetAspectRatio(0.0);
1115 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1116 WLOGFD("window is hidden or created! id: %{public}u", property_->GetWindowId());
1117 return WMError::WM_OK;
1118 }
1119 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO);
1120 return WMError::WM_OK;
1121 }
1122
MapFloatingWindowToAppIfNeeded()1123 void WindowImpl::MapFloatingWindowToAppIfNeeded()
1124 {
1125 if (!WindowHelper::IsAppFloatingWindow(GetType()) || context_.get() == nullptr) {
1126 return;
1127 }
1128
1129 WLOGFI("In");
1130 for (const auto& winPair : windowMap_) {
1131 auto win = winPair.second.second;
1132 if (win->GetType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW &&
1133 context_.get() == win->GetContext().get()) {
1134 sptr<WindowImpl> selfImpl(this);
1135 appFloatingWindowMap_[win->GetWindowId()].push_back(selfImpl);
1136 WLOGFD("Map FloatingWindow %{public}u to AppMainWindow %{public}u, type is %{public}u",
1137 GetWindowId(), win->GetWindowId(), GetType());
1138 return;
1139 }
1140 }
1141 }
1142
MapDialogWindowToAppIfNeeded()1143 void WindowImpl::MapDialogWindowToAppIfNeeded()
1144 {
1145 if (GetType() != WindowType::WINDOW_TYPE_DIALOG) {
1146 return;
1147 }
1148
1149 for (const auto& winPair : windowMap_) {
1150 auto win = winPair.second.second;
1151 if (win->GetType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW &&
1152 context_.get() == win->GetContext().get()) {
1153 sptr<WindowImpl> selfImpl(this);
1154 appDialogWindowMap_[win->GetWindowId()].push_back(selfImpl);
1155 WLOGFD("Map DialogWindow %{public}u to AppMainWindow %{public}u", GetWindowId(), win->GetWindowId());
1156 return;
1157 }
1158 }
1159 }
1160
UpdateProperty(PropertyChangeAction action)1161 WMError WindowImpl::UpdateProperty(PropertyChangeAction action)
1162 {
1163 return SingletonContainer::Get<WindowAdapter>().UpdateProperty(property_, action);
1164 }
1165
GetConfigurationFromAbilityInfo()1166 void WindowImpl::GetConfigurationFromAbilityInfo()
1167 {
1168 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
1169 if (abilityContext == nullptr) {
1170 WLOGFE("id:%{public}u is not ability Window", property_->GetWindowId());
1171 return;
1172 }
1173 auto abilityInfo = abilityContext->GetAbilityInfo();
1174 if (abilityInfo == nullptr) {
1175 WLOGFE("id:%{public}u Ability window get ability info failed", property_->GetWindowId());
1176 return;
1177 }
1178
1179 // get support modes configuration
1180 uint32_t windowModeSupportType = WindowHelper::ConvertSupportModesToSupportType(abilityInfo->windowModes);
1181 if (windowModeSupportType == 0) {
1182 WLOGFD("mode config param is 0, all modes is supported");
1183 windowModeSupportType = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
1184 }
1185 WLOGFD("winId: %{public}u, windowModeSupportType: %{public}u", GetWindowId(), windowModeSupportType);
1186 SetRequestWindowModeSupportType(windowModeSupportType);
1187
1188 // get window size limits configuration
1189 WindowLimits sizeLimits;
1190 sizeLimits.maxWidth_ = abilityInfo->maxWindowWidth;
1191 sizeLimits.maxHeight_ = abilityInfo->maxWindowHeight;
1192 sizeLimits.minWidth_ = abilityInfo->minWindowWidth;
1193 sizeLimits.minHeight_ = abilityInfo->minWindowHeight;
1194 sizeLimits.maxRatio_ = static_cast<float>(abilityInfo->maxWindowRatio);
1195 sizeLimits.minRatio_ = static_cast<float>(abilityInfo->minWindowRatio);
1196 property_->SetSizeLimits(sizeLimits);
1197
1198 // get orientation configuration
1199 OHOS::AppExecFwk::DisplayOrientation displayOrientation =
1200 static_cast<OHOS::AppExecFwk::DisplayOrientation>(
1201 static_cast<uint32_t>(abilityInfo->orientation));
1202 if (ABILITY_TO_WMS_ORIENTATION_MAP.count(displayOrientation) == 0) {
1203 WLOGFE("id:%{public}u Do not support this Orientation type", property_->GetWindowId());
1204 return;
1205 }
1206 Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(displayOrientation);
1207 if (orientation < Orientation::BEGIN || orientation > Orientation::END) {
1208 WLOGFE("Set orientation from ability failed");
1209 return;
1210 }
1211 property_->SetRequestedOrientation(orientation);
1212 }
1213
UpdateTitleButtonVisibility()1214 void WindowImpl::UpdateTitleButtonVisibility()
1215 {
1216 WLOGFD("[Client] UpdateTitleButtonVisibility");
1217 std::lock_guard<std::recursive_mutex> lock(mutex_);
1218 if (uiContent_ == nullptr || !IsDecorEnable()) {
1219 return;
1220 }
1221 auto windowModeSupportType = GetWindowModeSupportType();
1222 bool hideSplitButton = !(windowModeSupportType & WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY);
1223 // not support fullscreen in split and floating mode, or not support float in fullscreen mode
1224 bool hideMaximizeButton = (!(windowModeSupportType & WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN) &&
1225 (GetMode() == WindowMode::WINDOW_MODE_FLOATING || WindowHelper::IsSplitWindowMode(GetMode()))) ||
1226 (!(windowModeSupportType & WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING) &&
1227 GetMode() == WindowMode::WINDOW_MODE_FULLSCREEN);
1228 WLOGD("[Client] [hideSplit, hideMaximize]: [%{public}d, %{public}d]", hideSplitButton, hideMaximizeButton);
1229 uiContent_->HideWindowTitleButton(hideSplitButton, hideMaximizeButton, false, false);
1230 }
1231
IsAppMainOrSubOrFloatingWindow()1232 bool WindowImpl::IsAppMainOrSubOrFloatingWindow()
1233 {
1234 // App main window need decor config, stretchable config and effect config
1235 // App sub window and float window need effect config
1236 if (WindowHelper::IsAppWindow(GetType())) {
1237 return true;
1238 }
1239
1240 if (WindowHelper::IsAppFloatingWindow(GetType())) {
1241 for (const auto& winPair : windowMap_) {
1242 auto win = winPair.second.second;
1243 if (win != nullptr && win->GetType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW &&
1244 context_.get() == win->GetContext().get()) {
1245 isAppFloatingWindow_ = true;
1246 return true;
1247 }
1248 }
1249 }
1250 return false;
1251 }
1252
SetSystemConfig()1253 void WindowImpl::SetSystemConfig()
1254 {
1255 if (!IsAppMainOrSubOrFloatingWindow()) {
1256 return;
1257 }
1258 if (SingletonContainer::Get<WindowAdapter>().GetSystemConfig(windowSystemConfig_) == WMError::WM_OK) {
1259 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
1260 WLOGFD("get system decor enable:%{public}d", windowSystemConfig_.isSystemDecorEnable_);
1261 property_->SetDecorEnable(windowSystemConfig_.isSystemDecorEnable_);
1262 WLOGFD("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_);
1263 property_->SetStretchable(windowSystemConfig_.isStretchable_);
1264 // if window mode is undefined, set it from configuration
1265 if (property_->GetWindowMode() == WindowMode::WINDOW_MODE_UNDEFINED) {
1266 WLOGFD("get default window mode:%{public}u", windowSystemConfig_.defaultWindowMode_);
1267 property_->SetWindowMode(windowSystemConfig_.defaultWindowMode_);
1268 }
1269 if (property_->GetLastWindowMode() == WindowMode::WINDOW_MODE_UNDEFINED) {
1270 property_->SetLastWindowMode(windowSystemConfig_.defaultWindowMode_);
1271 }
1272 }
1273 }
1274 }
1275
GetKeyboardAnimationConfig()1276 KeyboardAnimationConfig WindowImpl::GetKeyboardAnimationConfig()
1277 {
1278 return { windowSystemConfig_.animationIn_, windowSystemConfig_.animationOut_ };
1279 }
1280
WindowCreateCheck(uint32_t parentId)1281 WMError WindowImpl::WindowCreateCheck(uint32_t parentId)
1282 {
1283 if (vsyncStation_ == nullptr || !vsyncStation_->IsVsyncReceiverCreated()) {
1284 return WMError::WM_ERROR_NULLPTR;
1285 }
1286 // check window name, same window names are forbidden
1287 if (windowMap_.find(name_) != windowMap_.end()) {
1288 WLOGFE("WindowName(%{public}s) already exists.", name_.c_str());
1289 return WMError::WM_ERROR_REPEAT_OPERATION;
1290 }
1291 if (CheckCameraFloatingWindowMultiCreated(property_->GetWindowType())) {
1292 WLOGFE("Camera Floating Window already exists.");
1293 return WMError::WM_ERROR_REPEAT_OPERATION;
1294 }
1295 if (parentId == INVALID_WINDOW_ID) {
1296 if (WindowHelper::IsSystemSubWindow(property_->GetWindowType()) ||
1297 WindowHelper::IsSubWindow(property_->GetWindowType())) {
1298 return WMError::WM_ERROR_INVALID_PARENT;
1299 }
1300 return WMError::WM_OK;
1301 }
1302
1303 if (property_->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
1304 property_->SetParentId(parentId);
1305 } else {
1306 sptr<Window> parentWindow = nullptr;
1307 for (const auto& winPair : windowMap_) {
1308 if (winPair.second.first == parentId) {
1309 property_->SetParentId(parentId);
1310 parentWindow = winPair.second.second;
1311 break;
1312 }
1313 }
1314 if (WindowHelper::IsSystemSubWindow(property_->GetWindowType())) {
1315 if (parentWindow == nullptr) {
1316 return WMError::WM_ERROR_INVALID_PARENT;
1317 }
1318 if (!parentWindow->IsAllowHaveSystemSubWindow()) {
1319 return WMError::WM_ERROR_INVALID_PARENT;
1320 }
1321 }
1322 }
1323 if (property_->GetParentId() != parentId) {
1324 WLOGFE("Parent Window does not exist. ParentId is %{public}u", parentId);
1325 return WMError::WM_ERROR_INVALID_PARENT;
1326 }
1327
1328 return WMError::WM_OK;
1329 }
1330
ChangePropertyByApiVersion()1331 void WindowImpl::ChangePropertyByApiVersion()
1332 {
1333 uint32_t version = 0;
1334 if ((context_ != nullptr) && (context_->GetApplicationInfo() != nullptr)) {
1335 version = context_->GetApplicationInfo()->apiCompatibleVersion;
1336 }
1337 // 10 ArkUI new framework support after API10
1338 if (version >= 10) {
1339 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
1340 SystemBarProperty statusSystemBarProperty(true, 0x00FFFFFF, 0xFF000000);
1341 SystemBarProperty navigationSystemBarProperty(true, 0x00FFFFFF, 0xFF000000);
1342 property_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, statusSystemBarProperty);
1343 property_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, navigationSystemBarProperty);
1344 }
1345 }
1346 }
1347
SetDefaultDisplayIdIfNeed()1348 void WindowImpl::SetDefaultDisplayIdIfNeed()
1349 {
1350 auto displayId = property_->GetDisplayId();
1351 if (displayId == DISPLAY_ID_INVALID) {
1352 auto defaultDisplayId = SingletonContainer::IsDestroyed() ? DISPLAY_ID_INVALID :
1353 SingletonContainer::Get<DisplayManager>().GetDefaultDisplayId();
1354 defaultDisplayId = (defaultDisplayId == DISPLAY_ID_INVALID) ? 0 : defaultDisplayId;
1355 property_->SetDisplayId(defaultDisplayId);
1356 TLOGI(WmsLogTag::WMS_LIFE, "Reset displayId: %{public}" PRIu64, defaultDisplayId);
1357 }
1358 }
1359
Create(uint32_t parentId,const std::shared_ptr<AbilityRuntime::Context> & context)1360 WMError WindowImpl::Create(uint32_t parentId, const std::shared_ptr<AbilityRuntime::Context>& context)
1361 {
1362 WLOGFD("Window[%{public}s] Create", name_.c_str());
1363 WMError ret = WindowCreateCheck(parentId);
1364 if (ret != WMError::WM_OK) {
1365 return ret;
1366 }
1367 SetDefaultDisplayIdIfNeed();
1368 context_ = context;
1369 sptr<WindowImpl> window(this);
1370 sptr<IWindow> windowAgent(new WindowAgent(window));
1371 static std::atomic<uint32_t> tempWindowId = 0;
1372 uint32_t windowId = tempWindowId++; // for test
1373 sptr<IRemoteObject> token = context_ ? context_->GetToken() : nullptr;
1374 if (token) {
1375 property_->SetTokenState(true);
1376 }
1377 ChangePropertyByApiVersion();
1378 InitAbilityInfo();
1379 SetSystemConfig();
1380
1381 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
1382 GetConfigurationFromAbilityInfo();
1383 } else if (property_->GetWindowMode() == WindowMode::WINDOW_MODE_UNDEFINED) {
1384 property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1385 }
1386
1387 if (property_->GetWindowType() == WindowType::WINDOW_TYPE_VOLUME_OVERLAY && surfaceNode_) {
1388 surfaceNode_->SetFrameGravity(Gravity::TOP_LEFT);
1389 }
1390
1391 ret = SingletonContainer::Get<WindowAdapter>().CreateWindow(windowAgent, property_, surfaceNode_,
1392 windowId, token);
1393 RecordLifeCycleExceptionEvent(LifeCycleEvent::CREATE_EVENT, ret);
1394 if (ret != WMError::WM_OK) {
1395 WLOGFE("create window failed with errCode:%{public}d", static_cast<int32_t>(ret));
1396 return ret;
1397 }
1398 property_->SetWindowId(windowId);
1399 if (surfaceNode_) {
1400 surfaceNode_->SetWindowId(windowId);
1401 }
1402 sptr<Window> self(this);
1403 windowMap_.insert(std::make_pair(name_, std::pair<uint32_t, sptr<Window>>(windowId, self)));
1404 if (parentId != INVALID_WINDOW_ID) {
1405 subWindowMap_[property_->GetParentId()].push_back(window);
1406 }
1407
1408 MapFloatingWindowToAppIfNeeded();
1409 MapDialogWindowToAppIfNeeded();
1410 UpdateDecorEnable();
1411
1412 state_ = WindowState::STATE_CREATED;
1413 InputTransferStation::GetInstance().AddInputWindow(self);
1414 needRemoveWindowInputChannel_ = true;
1415 return ret;
1416 }
1417
PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)1418 bool WindowImpl::PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
1419 {
1420 if (uiContent_ != nullptr) {
1421 return uiContent_->ProcessKeyEvent(keyEvent, true);
1422 }
1423 return false;
1424 }
1425
InitAbilityInfo()1426 void WindowImpl::InitAbilityInfo()
1427 {
1428 AbilityInfo info;
1429 info.bundleName_ = SysCapUtil::GetBundleName();
1430 auto originalAbilityInfo = GetOriginalAbilityInfo();
1431 if (originalAbilityInfo != nullptr) {
1432 info.abilityName_ = originalAbilityInfo->name;
1433 } else {
1434 WLOGFD("original ability info is null %{public}s", name_.c_str());
1435 }
1436 property_->SetAbilityInfo(info);
1437 }
1438
GetOriginalAbilityInfo() const1439 std::shared_ptr<AppExecFwk::AbilityInfo> WindowImpl::GetOriginalAbilityInfo() const
1440 {
1441 if (context_ == nullptr) {
1442 WLOGFD("context is null %{public}s", name_.c_str());
1443 return nullptr;
1444 }
1445
1446 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
1447 if (abilityContext == nullptr) {
1448 WLOGFD("abilityContext is null %{public}s", name_.c_str());
1449 return nullptr;
1450 }
1451 return abilityContext->GetAbilityInfo();
1452 }
1453
BindDialogTarget(sptr<IRemoteObject> targetToken)1454 WMError WindowImpl::BindDialogTarget(sptr<IRemoteObject> targetToken)
1455 {
1456 if (!IsWindowValid()) {
1457 TLOGE(WmsLogTag::WMS_DIALOG, "window is invalid");
1458 return WMError::WM_ERROR_INVALID_WINDOW;
1459 }
1460 uint32_t windowId = property_->GetWindowId();
1461 WMError ret = SingletonContainer::Get<WindowAdapter>().BindDialogTarget(windowId, targetToken);
1462 if (ret != WMError::WM_OK) {
1463 WLOGFE("bind window failed with errCode:%{public}d", static_cast<int32_t>(ret));
1464 }
1465
1466 return ret;
1467 }
1468
ResetInputWindow(uint32_t winId)1469 void WindowImpl::ResetInputWindow(uint32_t winId)
1470 {
1471 TLOGI(WmsLogTag::WMS_EVENT, "Id:%{public}u", winId);
1472 InputTransferStation::GetInstance().AddInputWindow(this);
1473 }
1474
DestroyDialogWindow()1475 void WindowImpl::DestroyDialogWindow()
1476 {
1477 // remove from appDialogWindowMap_
1478 for (auto& dialogWindows: appDialogWindowMap_) {
1479 for (auto iter = dialogWindows.second.begin(); iter != dialogWindows.second.end(); ++iter) {
1480 if ((*iter) == nullptr) {
1481 continue;
1482 }
1483 if ((*iter)->GetWindowId() == GetWindowId()) {
1484 dialogWindows.second.erase(iter);
1485 break;
1486 }
1487 }
1488 }
1489
1490 // Destroy app dialog window if exist
1491 if (appDialogWindowMap_.count(GetWindowId()) > 0) {
1492 auto& dialogWindows = appDialogWindowMap_.at(GetWindowId());
1493 for (auto iter = dialogWindows.begin(); iter != dialogWindows.end(); iter = dialogWindows.begin()) {
1494 if ((*iter) == nullptr) {
1495 dialogWindows.erase(iter);
1496 continue;
1497 }
1498 (*iter)->Destroy(false);
1499 }
1500 appDialogWindowMap_.erase(GetWindowId());
1501 }
1502 }
1503
DestroyFloatingWindow()1504 void WindowImpl::DestroyFloatingWindow()
1505 {
1506 // remove from appFloatingWindowMap_
1507 TLOGI(WmsLogTag::WMS_LIFE, "Remove from appFloatingWindowMap_");
1508 for (auto& floatingWindows: appFloatingWindowMap_) {
1509 for (auto iter = floatingWindows.second.begin(); iter != floatingWindows.second.end(); ++iter) {
1510 if ((*iter) == nullptr) {
1511 continue;
1512 }
1513 if ((*iter)->GetWindowId() == GetWindowId()) {
1514 floatingWindows.second.erase(iter);
1515 break;
1516 }
1517 }
1518 }
1519
1520 // Destroy app floating window if exist
1521 TLOGI(WmsLogTag::WMS_LIFE, "Destroy app floating window if exist");
1522 if (appFloatingWindowMap_.count(GetWindowId()) > 0) {
1523 auto& floatingWindows = appFloatingWindowMap_.at(GetWindowId());
1524 for (auto iter = floatingWindows.begin(); iter != floatingWindows.end(); iter = floatingWindows.begin()) {
1525 if ((*iter) == nullptr) {
1526 floatingWindows.erase(iter);
1527 continue;
1528 }
1529 (*iter)->Destroy();
1530 }
1531 appFloatingWindowMap_.erase(GetWindowId());
1532 }
1533 }
1534
DestroySubWindow()1535 void WindowImpl::DestroySubWindow()
1536 {
1537 if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_
1538 auto& subWindows = subWindowMap_.at(property_->GetParentId());
1539 for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) {
1540 if ((*iter) == nullptr) {
1541 continue;
1542 }
1543 if ((*iter)->GetWindowId() == GetWindowId()) {
1544 subWindows.erase(iter);
1545 break;
1546 }
1547 }
1548 }
1549
1550 if (subWindowMap_.count(GetWindowId()) > 0) { // remove from subWindowMap_ and windowMap_
1551 auto& subWindows = subWindowMap_.at(GetWindowId());
1552 for (auto iter = subWindows.begin(); iter != subWindows.end(); iter = subWindows.begin()) {
1553 if ((*iter) == nullptr) {
1554 subWindows.erase(iter);
1555 continue;
1556 }
1557 (*iter)->Destroy(false);
1558 }
1559 subWindowMap_[GetWindowId()].clear();
1560 subWindowMap_.erase(GetWindowId());
1561 }
1562 }
1563
ClearVsyncStation()1564 void WindowImpl::ClearVsyncStation()
1565 {
1566 std::lock_guard<std::recursive_mutex> lock(mutex_);
1567 if (vsyncStation_ != nullptr) {
1568 vsyncStation_.reset();
1569 }
1570 }
1571
Destroy()1572 WMError WindowImpl::Destroy()
1573 {
1574 return Destroy(true);
1575 }
1576
Destroy(bool needNotifyServer,bool needClearListener)1577 WMError WindowImpl::Destroy(bool needNotifyServer, bool needClearListener)
1578 {
1579 if (!IsWindowValid()) {
1580 return WMError::WM_OK;
1581 }
1582
1583 WLOGI("Window %{public}u Destroy", property_->GetWindowId());
1584 WMError ret = WMError::WM_OK;
1585 if (needNotifyServer) {
1586 NotifyBeforeDestroy(GetWindowName());
1587 if (subWindowMap_.count(GetWindowId()) > 0) {
1588 for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
1589 NotifyBeforeSubWindowDestroy(subWindow);
1590 }
1591 }
1592 ret = SingletonContainer::Get<WindowAdapter>().DestroyWindow(property_->GetWindowId());
1593 RecordLifeCycleExceptionEvent(LifeCycleEvent::DESTROY_EVENT, ret);
1594 if (ret != WMError::WM_OK) {
1595 WLOGFE("destroy window failed with errCode:%{public}d", static_cast<int32_t>(ret));
1596 if (GetType() != WindowType::WINDOW_TYPE_DIALOG) {
1597 return ret;
1598 }
1599 }
1600 } else {
1601 WLOGI("no need to destroy");
1602 }
1603
1604 if (needRemoveWindowInputChannel_) {
1605 InputTransferStation::GetInstance().RemoveInputWindow(property_->GetWindowId());
1606 }
1607 windowMap_.erase(GetWindowName());
1608 if (needClearListener) {
1609 ClearListenersById(GetWindowId());
1610 }
1611 DestroySubWindow();
1612 DestroyFloatingWindow();
1613 DestroyDialogWindow();
1614 ClearVsyncStation();
1615 {
1616 std::lock_guard<std::recursive_mutex> lock(mutex_);
1617 state_ = WindowState::STATE_DESTROYED;
1618 }
1619 return ret;
1620 }
1621
NeedToStopShowing()1622 bool WindowImpl::NeedToStopShowing()
1623 {
1624 if (!WindowHelper::IsMainWindow(property_->GetWindowType())) {
1625 return false;
1626 }
1627 // show failed when current mode is not support or window only supports split mode and can show when locked
1628 bool isShowWhenLocked = GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
1629 if (!WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), GetMode()) ||
1630 WindowHelper::IsOnlySupportSplitAndShowWhenLocked(isShowWhenLocked, GetWindowModeSupportType())) {
1631 WLOGFE("current mode is not supported, windowId: %{public}u, "
1632 "windowModeSupportType: %{public}u, winMode: %{public}u",
1633 property_->GetWindowId(), GetWindowModeSupportType(), GetMode());
1634 return true;
1635 }
1636 return false;
1637 }
1638
UpdateSurfaceNodeAfterCustomAnimation(bool isAdd)1639 WMError WindowImpl::UpdateSurfaceNodeAfterCustomAnimation(bool isAdd)
1640 {
1641 WLOGI("id: %{public}u UpdateRsTree, isAdd:%{public}u",
1642 property_->GetWindowId(), isAdd);
1643 if (!IsWindowValid()) {
1644 return WMError::WM_ERROR_INVALID_WINDOW;
1645 }
1646 if (!WindowHelper::IsSystemWindow(property_->GetWindowType())) {
1647 WLOGFE("only system window can set");
1648 return WMError::WM_ERROR_INVALID_OPERATION;
1649 }
1650 AdjustWindowAnimationFlag(false); // false means update rs tree with default option
1651 // need time out check
1652 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1653 if (ret != WMError::WM_OK) {
1654 WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast<int32_t>(ret));
1655 return ret;
1656 }
1657 ret = SingletonContainer::Get<WindowAdapter>().UpdateRsTree(property_->GetWindowId(), isAdd);
1658 if (ret != WMError::WM_OK) {
1659 WLOGFE("UpdateRsTree failed with errCode:%{public}d", static_cast<int32_t>(ret));
1660 return ret;
1661 }
1662 return WMError::WM_OK;
1663 }
1664
AdjustWindowAnimationFlag(bool withAnimation)1665 void WindowImpl::AdjustWindowAnimationFlag(bool withAnimation)
1666 {
1667 // when show/hide with animation
1668 // use custom animation when transitionController exists; else use default animation
1669 WindowType winType = property_->GetWindowType();
1670 bool isAppWindow = WindowHelper::IsAppWindow(winType);
1671 if (withAnimation && !isAppWindow && animationTransitionController_) {
1672 // use custom animation
1673 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
1674 } else if ((isAppWindow && needDefaultAnimation_) || (withAnimation && !animationTransitionController_)) {
1675 // use default animation
1676 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::DEFAULT));
1677 } else if (winType == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
1678 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::INPUTE));
1679 } else {
1680 // with no animation
1681 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::NONE));
1682 }
1683 }
1684
PreProcessShow(uint32_t reason,bool withAnimation)1685 WMError WindowImpl::PreProcessShow(uint32_t reason, bool withAnimation)
1686 {
1687 if (state_ == WindowState::STATE_FROZEN) {
1688 WLOGFE("window is frozen, can not be shown, windowId: %{public}u", property_->GetWindowId());
1689 return WMError::WM_ERROR_INVALID_OPERATION;
1690 }
1691 SetDefaultOption();
1692 SetWindowModeSupportType(GetRequestWindowModeSupportType());
1693 AdjustWindowAnimationFlag(withAnimation);
1694
1695 if (NeedToStopShowing()) { // true means stop showing
1696 return WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE;
1697 }
1698
1699 // update title button visibility when show
1700 UpdateTitleButtonVisibility();
1701 return WMError::WM_OK;
1702 }
1703
Show(uint32_t reason,bool withAnimation,bool withFocus)1704 WMError WindowImpl::Show(uint32_t reason, bool withAnimation, bool withFocus)
1705 {
1706 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, __PRETTY_FUNCTION__);
1707 WLOGFD("Window Show [name:%{public}s, id:%{public}u, mode: %{public}u], reason:%{public}u, "
1708 "withAnimation:%{public}d", name_.c_str(), property_->GetWindowId(), GetMode(), reason, withAnimation);
1709 if (!IsWindowValid()) {
1710 return WMError::WM_ERROR_INVALID_WINDOW;
1711 }
1712 UpdateDecorEnable(true);
1713 if (static_cast<WindowStateChangeReason>(reason) == WindowStateChangeReason::KEYGUARD ||
1714 static_cast<WindowStateChangeReason>(reason) == WindowStateChangeReason::TOGGLING) {
1715 state_ = WindowState::STATE_SHOWN;
1716 NotifyAfterForeground();
1717 return WMError::WM_OK;
1718 }
1719 if (state_ == WindowState::STATE_SHOWN) {
1720 if (property_->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1721 SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(property_->GetDisplayId());
1722 } else {
1723 WLOGI("window is already shown id: %{public}u", property_->GetWindowId());
1724 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId(), false);
1725 }
1726 // when show sub window, check its parent state
1727 sptr<Window> parent = FindWindowById(property_->GetParentId());
1728 if (parent != nullptr && parent->GetWindowState() == WindowState::STATE_HIDDEN) {
1729 WLOGFD("sub window can not show, because main window hide");
1730 return WMError::WM_OK;
1731 } else {
1732 NotifyAfterForeground(true, false);
1733 }
1734 return WMError::WM_OK;
1735 }
1736 WMError ret = PreProcessShow(reason, withAnimation);
1737 if (ret != WMError::WM_OK) {
1738 NotifyForegroundFailed(ret);
1739 return ret;
1740 }
1741 // this lock solves the multithreading problem when reading WindowState
1742 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1743 ret = SingletonContainer::Get<WindowAdapter>().AddWindow(property_);
1744 RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret);
1745 if (ret == WMError::WM_OK) {
1746 UpdateWindowStateWhenShow();
1747 } else {
1748 NotifyForegroundFailed(ret);
1749 WLOGFE("show window id:%{public}u errCode:%{public}d", property_->GetWindowId(), static_cast<int32_t>(ret));
1750 }
1751 // systemui make startbar resident, when refactor immersive, this code can delete
1752 if (property_->GetRequestedOrientation() == Orientation::HORIZONTAL
1753 || property_->GetRequestedOrientation() == Orientation::REVERSE_HORIZONTAL) {
1754 RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
1755 }
1756 needNotifyFocusLater_ = false;
1757 return ret;
1758 }
1759
ShowKeyboard(KeyboardViewMode mode)1760 WMError WindowImpl::ShowKeyboard(KeyboardViewMode mode)
1761 {
1762 return Show();
1763 }
1764
Hide(uint32_t reason,bool withAnimation,bool isFromInnerkits)1765 WMError WindowImpl::Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits)
1766 {
1767 WLOGD("id:%{public}u Hide, reason:%{public}u, Animation:%{public}d",
1768 property_->GetWindowId(), reason, withAnimation);
1769 if (!IsWindowValid()) {
1770 return WMError::WM_ERROR_INVALID_WINDOW;
1771 }
1772 WindowStateChangeReason stateChangeReason = static_cast<WindowStateChangeReason>(reason);
1773 if (stateChangeReason == WindowStateChangeReason::KEYGUARD ||
1774 stateChangeReason == WindowStateChangeReason::TOGGLING) {
1775 state_ = stateChangeReason == WindowStateChangeReason::KEYGUARD ?
1776 WindowState::STATE_FROZEN : WindowState::STATE_HIDDEN;
1777 NotifyAfterBackground();
1778 return WMError::WM_OK;
1779 }
1780 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1781 WLOGI("already hidden, id: %{public}u", property_->GetWindowId());
1782 NotifyBackgroundFailed(WMError::WM_DO_NOTHING);
1783 return WMError::WM_OK;
1784 }
1785 WMError ret = WMError::WM_OK;
1786 if (WindowHelper::IsSystemWindow(property_->GetWindowType())) {
1787 AdjustWindowAnimationFlag(withAnimation);
1788 // when show(true) with default, hide() with None, to adjust animationFlag to disabled default animation
1789 ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1790 if (ret != WMError::WM_OK) {
1791 WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast<int32_t>(ret));
1792 return ret;
1793 }
1794 }
1795 ret = SingletonContainer::Get<WindowAdapter>().RemoveWindow(property_->GetWindowId(), isFromInnerkits);
1796 RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret);
1797 if (ret != WMError::WM_OK) {
1798 WLOGFE("hide errCode:%{public}d for winId:%{public}u", static_cast<int32_t>(ret), property_->GetWindowId());
1799 return ret;
1800 }
1801 UpdateWindowStateWhenHide();
1802 uint32_t animationFlag = property_->GetAnimationFlag();
1803 if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
1804 animationTransitionController_->AnimationForHidden();
1805 }
1806 ResetMoveOrDragState();
1807 escKeyEventTriggered_ = false;
1808 return ret;
1809 }
1810
MoveTo(int32_t x,int32_t y,bool isMoveToGlobal)1811 WMError WindowImpl::MoveTo(int32_t x, int32_t y, bool isMoveToGlobal)
1812 {
1813 WLOGFD("id:%{public}d MoveTo %{public}d %{public}d",
1814 property_->GetWindowId(), x, y);
1815 if (!IsWindowValid()) {
1816 return WMError::WM_ERROR_INVALID_WINDOW;
1817 }
1818
1819 Rect rect = (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) ?
1820 GetRect() : property_->GetRequestRect();
1821 Rect moveRect = { x, y, rect.width_, rect.height_ }; // must keep w/h, which may maintain stashed resize info
1822 property_->SetRequestRect(moveRect);
1823 {
1824 // this lock solves the multithreading problem when reading WindowState
1825 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1826 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1827 WLOGFD("window is hidden or created! id: %{public}u, oriPos: [%{public}d, %{public}d, "
1828 "movePos: [%{public}d, %{public}d]", property_->GetWindowId(), rect.posX_, rect.posY_, x, y);
1829 return WMError::WM_OK;
1830 }
1831 }
1832
1833 if (GetMode() != WindowMode::WINDOW_MODE_FLOATING) {
1834 WLOGFE("fullscreen window could not moveto, winId: %{public}u", GetWindowId());
1835 return WMError::WM_ERROR_INVALID_OPERATION;
1836 }
1837 property_->SetWindowSizeChangeReason(WindowSizeChangeReason::MOVE);
1838 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_RECT);
1839 }
1840
Resize(uint32_t width,uint32_t height)1841 WMError WindowImpl::Resize(uint32_t width, uint32_t height)
1842 {
1843 WLOGFD("id:%{public}d Resize %{public}u %{public}u",
1844 property_->GetWindowId(), width, height);
1845 if (!IsWindowValid()) {
1846 return WMError::WM_ERROR_INVALID_WINDOW;
1847 }
1848
1849 Rect rect = (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) ?
1850 GetRect() : property_->GetRequestRect();
1851 Rect resizeRect = { rect.posX_, rect.posY_, width, height };
1852 property_->SetRequestRect(resizeRect);
1853 property_->SetDecoStatus(false);
1854 {
1855 // this lock solves the multithreading problem when reading WindowState
1856 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1857 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1858 WLOGFD("window is hidden or created! id: %{public}u, oriRect: [%{public}u, %{public}u], "
1859 "resizeRect: [%{public}u, %{public}u]", property_->GetWindowId(), rect.width_,
1860 rect.height_, width, height);
1861 return WMError::WM_OK;
1862 }
1863 }
1864
1865 if (GetMode() != WindowMode::WINDOW_MODE_FLOATING) {
1866 WLOGFE("fullscreen window could not resize, winId: %{public}u", GetWindowId());
1867 return WMError::WM_ERROR_INVALID_OPERATION;
1868 }
1869 property_->SetWindowSizeChangeReason(WindowSizeChangeReason::RESIZE);
1870 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_RECT);
1871 }
1872
SetWindowGravity(WindowGravity gravity,uint32_t percent)1873 WMError WindowImpl::SetWindowGravity(WindowGravity gravity, uint32_t percent)
1874 {
1875 WLOGFD("id:%{public}d SetWindowGravity %{public}u %{public}u",
1876 property_->GetWindowId(), gravity, percent);
1877
1878 return SingletonContainer::Get<WindowAdapter>().SetWindowGravity(property_->GetWindowId(), gravity, percent);
1879 }
1880
SetKeepScreenOn(bool keepScreenOn)1881 WMError WindowImpl::SetKeepScreenOn(bool keepScreenOn)
1882 {
1883 if (!IsWindowValid()) {
1884 return WMError::WM_ERROR_INVALID_WINDOW;
1885 }
1886 property_->SetKeepScreenOn(keepScreenOn);
1887 if (state_ == WindowState::STATE_SHOWN) {
1888 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
1889 }
1890 return WMError::WM_OK;
1891 }
1892
IsKeepScreenOn() const1893 bool WindowImpl::IsKeepScreenOn() const
1894 {
1895 if (!IsWindowValid()) {
1896 return false;
1897 }
1898 return property_->IsKeepScreenOn();
1899 }
1900
SetTurnScreenOn(bool turnScreenOn)1901 WMError WindowImpl::SetTurnScreenOn(bool turnScreenOn)
1902 {
1903 if (!IsWindowValid()) {
1904 return WMError::WM_ERROR_INVALID_WINDOW;
1905 }
1906 property_->SetTurnScreenOn(turnScreenOn);
1907 if (state_ == WindowState::STATE_SHOWN) {
1908 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1909 }
1910 return WMError::WM_OK;
1911 }
1912
IsTurnScreenOn() const1913 bool WindowImpl::IsTurnScreenOn() const
1914 {
1915 if (!IsWindowValid()) {
1916 return false;
1917 }
1918 return property_->IsTurnScreenOn();
1919 }
1920
SetBackgroundColor(uint32_t color)1921 WMError WindowImpl::SetBackgroundColor(uint32_t color)
1922 {
1923 // 0xff000000: ARGB style, means Opaque color.
1924 const bool isAlphaZero = !(color & 0xff000000);
1925 auto abilityInfo = property_->GetAbilityInfo();
1926 if (isAlphaZero && WindowHelper::IsMainWindow(property_->GetWindowType())) {
1927 auto& reportInstance = SingletonContainer::Get<WindowInfoReporter>();
1928 reportInstance.ReportZeroOpacityInfoImmediately(abilityInfo.bundleName_,
1929 abilityInfo.abilityName_);
1930 }
1931
1932 if (uiContent_ != nullptr) {
1933 uiContent_->SetBackgroundColor(color);
1934 return WMError::WM_OK;
1935 }
1936 WLOGI("ace is null, Id: %{public}u", GetWindowId());
1937 if (aceAbilityHandler_ != nullptr) {
1938 aceAbilityHandler_->SetBackgroundColor(color);
1939 return WMError::WM_OK;
1940 }
1941 WLOGFE("FA mode could not set bg color: %{public}u", GetWindowId());
1942 return WMError::WM_ERROR_INVALID_OPERATION;
1943 }
1944
GetBackgroundColor() const1945 uint32_t WindowImpl::GetBackgroundColor() const
1946 {
1947 if (uiContent_ != nullptr) {
1948 return uiContent_->GetBackgroundColor();
1949 }
1950 WLOGD("uiContent is nullptr, windowId: %{public}u, use FA mode", GetWindowId());
1951 if (aceAbilityHandler_ != nullptr) {
1952 return aceAbilityHandler_->GetBackgroundColor();
1953 }
1954 WLOGFE("FA mode does not get bg color: %{public}u", GetWindowId());
1955 return 0xffffffff; // means no background color been set, default color is white
1956 }
1957
SetBackgroundColor(const std::string & color)1958 WMError WindowImpl::SetBackgroundColor(const std::string& color)
1959 {
1960 if (!IsWindowValid()) {
1961 return WMError::WM_ERROR_INVALID_WINDOW;
1962 }
1963 uint32_t colorValue;
1964 if (ColorParser::Parse(color, colorValue)) {
1965 WLOGD("SetBackgroundColor: window: %{public}s, value: [%{public}s, %{public}u]",
1966 name_.c_str(), color.c_str(), colorValue);
1967 return SetBackgroundColor(colorValue);
1968 }
1969 WLOGFE("invalid color string: %{public}s", color.c_str());
1970 return WMError::WM_ERROR_INVALID_PARAM;
1971 }
1972
SetTransparent(bool isTransparent)1973 WMError WindowImpl::SetTransparent(bool isTransparent)
1974 {
1975 if (!IsWindowValid()) {
1976 return WMError::WM_ERROR_INVALID_WINDOW;
1977 }
1978 ColorParam backgroundColor;
1979 backgroundColor.value = GetBackgroundColor();
1980 if (isTransparent) {
1981 backgroundColor.argb.alpha = 0x00; // 0x00: completely transparent
1982 return SetBackgroundColor(backgroundColor.value);
1983 } else {
1984 backgroundColor.value = GetBackgroundColor();
1985 if (backgroundColor.argb.alpha == 0x00) {
1986 backgroundColor.argb.alpha = 0xff; // 0xff: completely opaque
1987 return SetBackgroundColor(backgroundColor.value);
1988 }
1989 }
1990 return WMError::WM_OK;
1991 }
1992
IsTransparent() const1993 bool WindowImpl::IsTransparent() const
1994 {
1995 if (!IsWindowValid()) {
1996 return false;
1997 }
1998 ColorParam backgroundColor;
1999 backgroundColor.value = GetBackgroundColor();
2000 WLOGFD("color: %{public}u, alpha: %{public}u", backgroundColor.value, backgroundColor.argb.alpha);
2001 return backgroundColor.argb.alpha == 0x00; // 0x00: completely transparent
2002 }
2003
SetBrightness(float brightness)2004 WMError WindowImpl::SetBrightness(float brightness)
2005 {
2006 if (!IsWindowValid()) {
2007 return WMError::WM_ERROR_INVALID_WINDOW;
2008 }
2009 if ((brightness < MINIMUM_BRIGHTNESS &&
2010 std::fabs(brightness - UNDEFINED_BRIGHTNESS) >= std::numeric_limits<float>::min()) ||
2011 brightness > MAXIMUM_BRIGHTNESS) {
2012 WLOGFE("invalid brightness value: %{public}f", brightness);
2013 return WMError::WM_ERROR_INVALID_PARAM;
2014 }
2015 if (!WindowHelper::IsAppWindow(GetType())) {
2016 WLOGFE("non app window does not support set brightness, type: %{public}u", GetType());
2017 return WMError::WM_ERROR_INVALID_TYPE;
2018 }
2019 property_->SetBrightness(brightness);
2020 if (state_ == WindowState::STATE_SHOWN) {
2021 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
2022 }
2023 return WMError::WM_OK;
2024 }
2025
GetBrightness() const2026 float WindowImpl::GetBrightness() const
2027 {
2028 return property_->GetBrightness();
2029 }
2030
SetCallingWindow(uint32_t windowId)2031 WMError WindowImpl::SetCallingWindow(uint32_t windowId)
2032 {
2033 if (!IsWindowValid()) {
2034 return WMError::WM_ERROR_INVALID_WINDOW;
2035 }
2036 property_->SetCallingWindow(windowId);
2037 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW);
2038 }
2039
RecordLifeCycleExceptionEvent(LifeCycleEvent event,WMError errCode) const2040 void WindowImpl::RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError errCode) const
2041 {
2042 if (!(errCode > WMError::WM_ERROR_NEED_REPORT_BASE && errCode < WMError::WM_ERROR_NEED_REPORT_END)) {
2043 return;
2044 }
2045 std::ostringstream oss;
2046 oss << "life cycle is abnormal: " << "window_name: " << name_
2047 << ", id:" << GetWindowId() << ", event: " << TransferLifeCycleEventToString(event)
2048 << ", errCode: " << static_cast<int32_t>(errCode) << ";";
2049 std::string info = oss.str();
2050 WLOGI("window life cycle exception: %{public}s", info.c_str());
2051 int32_t ret = HiSysEventWrite(
2052 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
2053 "WINDOW_LIFE_CYCLE_EXCEPTION",
2054 OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
2055 "PID", getpid(),
2056 "UID", getuid(),
2057 "MSG", info);
2058 if (ret != 0) {
2059 WLOGFE("Write HiSysEvent error, ret:%{public}d", ret);
2060 }
2061 }
2062
TransferLifeCycleEventToString(LifeCycleEvent type) const2063 std::string WindowImpl::TransferLifeCycleEventToString(LifeCycleEvent type) const
2064 {
2065 std::string event;
2066 switch (type) {
2067 case LifeCycleEvent::CREATE_EVENT:
2068 event = "CREATE";
2069 break;
2070 case LifeCycleEvent::SHOW_EVENT:
2071 event = "SHOW";
2072 break;
2073 case LifeCycleEvent::HIDE_EVENT:
2074 event = "HIDE";
2075 break;
2076 case LifeCycleEvent::DESTROY_EVENT:
2077 event = "DESTROY";
2078 break;
2079 default:
2080 event = "UNDEFINE";
2081 break;
2082 }
2083 return event;
2084 }
2085
SetPrivacyMode(bool isPrivacyMode)2086 WMError WindowImpl::SetPrivacyMode(bool isPrivacyMode)
2087 {
2088 if (!IsWindowValid()) {
2089 return WMError::WM_ERROR_INVALID_WINDOW;
2090 }
2091 WLOGFD("id : %{public}u, SetPrivacyMode, %{public}u", GetWindowId(), isPrivacyMode);
2092 property_->SetPrivacyMode(isPrivacyMode);
2093 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
2094 }
2095
IsPrivacyMode() const2096 bool WindowImpl::IsPrivacyMode() const
2097 {
2098 if (!IsWindowValid()) {
2099 return false;
2100 }
2101 return property_->GetPrivacyMode();
2102 }
2103
SetSystemPrivacyMode(bool isSystemPrivacyMode)2104 void WindowImpl::SetSystemPrivacyMode(bool isSystemPrivacyMode)
2105 {
2106 WLOGFD("id : %{public}u, SetSystemPrivacyMode, %{public}u", GetWindowId(), isSystemPrivacyMode);
2107 property_->SetSystemPrivacyMode(isSystemPrivacyMode);
2108 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
2109 }
2110
SetSnapshotSkip(bool isSkip)2111 WMError WindowImpl::SetSnapshotSkip(bool isSkip)
2112 {
2113 if (!IsWindowValid()) {
2114 return WMError::WM_ERROR_INVALID_WINDOW;
2115 }
2116 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2117 WLOGFE("set snapshot skip permission denied!");
2118 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2119 }
2120 property_->SetSnapshotSkip(isSkip);
2121 auto ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP);
2122 WLOGFD("id : %{public}u, set snapshot skip end. isSkip:%{public}u, systemPrivacyMode:%{public}u, ret:%{public}u",
2123 GetWindowId(), isSkip, property_->GetSystemPrivacyMode(), ret);
2124 return WMError::WM_OK;
2125 }
2126
2127 /** @note @window.hierarchy */
RaiseToAppTop()2128 WMError WindowImpl::RaiseToAppTop()
2129 {
2130 if (!IsWindowValid()) {
2131 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
2132 return WMError::WM_ERROR_INVALID_WINDOW;
2133 }
2134
2135 auto parentId = property_->GetParentId();
2136 if (parentId == INVALID_WINDOW_ID) {
2137 WLOGFE("Only the children of the main window can be raised!");
2138 return WMError::WM_ERROR_INVALID_PARENT;
2139 }
2140
2141 if (!WindowHelper::IsSubWindow(property_->GetWindowType())) {
2142 WLOGFE("Must be app sub window window!");
2143 return WMError::WM_ERROR_INVALID_CALLING;
2144 }
2145
2146 if (state_ != WindowState::STATE_SHOWN) {
2147 WLOGFE("The sub window must be shown!");
2148 return WMError::WM_DO_NOTHING;
2149 }
2150
2151 return SingletonContainer::Get<WindowAdapter>().RaiseToAppTop(GetWindowId());
2152 }
2153
DisableAppWindowDecor()2154 WMError WindowImpl::DisableAppWindowDecor()
2155 {
2156 if (!IsWindowValid()) {
2157 return WMError::WM_ERROR_INVALID_WINDOW;
2158 }
2159 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2160 WLOGFE("disable app window decor permission denied!");
2161 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2162 }
2163 if (!WindowHelper::IsMainWindow(property_->GetWindowType())) {
2164 WLOGFE("window decoration is invalid on sub window");
2165 return WMError::WM_ERROR_INVALID_OPERATION;
2166 }
2167 WLOGI("disable app window decoration.");
2168 windowSystemConfig_.isSystemDecorEnable_ = false;
2169 UpdateDecorEnable(true);
2170 return WMError::WM_OK;
2171 }
2172
IsDecorEnable() const2173 bool WindowImpl::IsDecorEnable() const
2174 {
2175 bool enable = windowSystemConfig_.isSystemDecorEnable_ &&
2176 WindowHelper::IsMainWindow(property_->GetWindowType());
2177 WLOGFD("get decor enable %{public}d", enable);
2178 return enable;
2179 }
2180
Maximize()2181 WMError WindowImpl::Maximize()
2182 {
2183 WLOGI("id: %{public}u Maximize", property_->GetWindowId());
2184 if (!IsWindowValid()) {
2185 return WMError::WM_ERROR_INVALID_WINDOW;
2186 }
2187 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2188 return SetFullScreen(true);
2189 } else {
2190 WLOGI("Maximize fail, not main window");
2191 return WMError::WM_ERROR_INVALID_PARAM;
2192 }
2193 }
2194
MaximizeFloating()2195 WMError WindowImpl::MaximizeFloating()
2196 {
2197 WLOGI("id: %{public}u MaximizeFloating", property_->GetWindowId());
2198 if (!IsWindowValid()) {
2199 return WMError::WM_ERROR_INVALID_WINDOW;
2200 }
2201 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2202 return SetFloatingMaximize(true);
2203 } else {
2204 WLOGI("MaximizeFloating fail, not main window");
2205 return WMError::WM_ERROR_INVALID_PARAM;
2206 }
2207 }
2208
SetGlobalMaximizeMode(MaximizeMode mode)2209 WMError WindowImpl::SetGlobalMaximizeMode(MaximizeMode mode)
2210 {
2211 WLOGI("id: %{public}u SetGlobalMaximizeMode: %{public}u", property_->GetWindowId(),
2212 static_cast<uint32_t>(mode));
2213 if (!IsWindowValid()) {
2214 return WMError::WM_ERROR_INVALID_WINDOW;
2215 }
2216 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2217 SingletonContainer::Get<WindowAdapter>().SetMaximizeMode(mode);
2218 return WMError::WM_OK;
2219 } else {
2220 WLOGI("SetGlobalMaximizeMode fail, not main window");
2221 return WMError::WM_ERROR_INVALID_PARAM;
2222 }
2223 }
2224
GetGlobalMaximizeMode() const2225 MaximizeMode WindowImpl::GetGlobalMaximizeMode() const
2226 {
2227 return SingletonContainer::Get<WindowAdapter>().GetMaximizeMode();
2228 }
2229
SetImmersiveModeEnabledState(bool enable)2230 WMError WindowImpl::SetImmersiveModeEnabledState(bool enable)
2231 {
2232 TLOGD(WmsLogTag::WMS_IMMS, "WindowImpl id: %{public}u SetImmersiveModeEnabledState: %{public}u",
2233 property_->GetWindowId(), static_cast<uint32_t>(enable));
2234 if (!IsWindowValid() ||
2235 !WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), WindowMode::WINDOW_MODE_FULLSCREEN)) {
2236 TLOGE(WmsLogTag::WMS_IMMS, "invalid window or fullscreen mode is not be supported, winId:%{public}u",
2237 property_->GetWindowId());
2238 return WMError::WM_ERROR_INVALID_WINDOW;
2239 }
2240 const WindowType curWindowType = GetType();
2241 if (!WindowHelper::IsMainWindow(curWindowType) && !WindowHelper::IsSubWindow(curWindowType)) {
2242 return WMError::WM_ERROR_INVALID_WINDOW;
2243 }
2244
2245 enableImmersiveMode_ = enable;
2246 const WindowMode mode = GetMode();
2247 if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) {
2248 return SetLayoutFullScreen(enableImmersiveMode_);
2249 }
2250 return WMError::WM_OK;
2251 }
2252
GetImmersiveModeEnabledState() const2253 bool WindowImpl::GetImmersiveModeEnabledState() const
2254 {
2255 if (!IsWindowValid()) {
2256 return false;
2257 }
2258 return enableImmersiveMode_;
2259 }
2260
NotifyWindowTransition(TransitionReason reason)2261 WMError WindowImpl::NotifyWindowTransition(TransitionReason reason)
2262 {
2263 sptr<WindowTransitionInfo> fromInfo = new(std::nothrow) WindowTransitionInfo();
2264 sptr<WindowTransitionInfo> toInfo = new(std::nothrow) WindowTransitionInfo();
2265 if (fromInfo == nullptr || toInfo == nullptr) {
2266 WLOGFE("new windowTransitionInfo failed");
2267 return WMError::WM_ERROR_NO_MEM;
2268 }
2269 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2270 if (abilityContext == nullptr) {
2271 WLOGFE("id:%{public}d is not ability Window", property_->GetWindowId());
2272 return WMError::WM_ERROR_NO_MEM;
2273 }
2274 auto abilityInfo = abilityContext->GetAbilityInfo();
2275 if (abilityInfo == nullptr) {
2276 return WMError::WM_ERROR_NULLPTR;
2277 }
2278 fromInfo->SetBundleName(context_->GetBundleName());
2279 fromInfo->SetAbilityName(abilityInfo->name);
2280 fromInfo->SetWindowMode(property_->GetWindowMode());
2281 fromInfo->SetWindowRect(property_->GetWindowRect());
2282 fromInfo->SetAbilityToken(context_->GetToken());
2283 fromInfo->SetWindowType(property_->GetWindowType());
2284 fromInfo->SetDisplayId(property_->GetDisplayId());
2285 fromInfo->SetTransitionReason(reason);
2286 return SingletonContainer::Get<WindowAdapter>().NotifyWindowTransition(fromInfo, toInfo);
2287 }
2288
Minimize()2289 WMError WindowImpl::Minimize()
2290 {
2291 WLOGI("id: %{public}u Minimize", property_->GetWindowId());
2292 if (!IsWindowValid()) {
2293 return WMError::WM_ERROR_INVALID_WINDOW;
2294 }
2295 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2296 if (context_ != nullptr) {
2297 WMError ret = NotifyWindowTransition(TransitionReason::MINIMIZE);
2298 if (ret != WMError::WM_OK) {
2299 WLOGI("Minimize without animation ret:%{public}u", static_cast<uint32_t>(ret));
2300 AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(context_->GetToken(), true);
2301 }
2302 } else {
2303 Hide();
2304 }
2305 }
2306 return WMError::WM_OK;
2307 }
2308
Recover()2309 WMError WindowImpl::Recover()
2310 {
2311 WLOGI("id: %{public}u Normalize", property_->GetWindowId());
2312 if (!IsWindowValid()) {
2313 return WMError::WM_ERROR_INVALID_WINDOW;
2314 }
2315 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2316 if (property_->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING &&
2317 property_->GetMaximizeMode() == MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
2318 SetFloatingMaximize(false);
2319 return WMError::WM_OK;
2320 }
2321 SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
2322 }
2323 return WMError::WM_OK;
2324 }
2325
Close()2326 WMError WindowImpl::Close()
2327 {
2328 WLOGI("id: %{public}u Close", property_->GetWindowId());
2329 if (!IsWindowValid()) {
2330 return WMError::WM_ERROR_INVALID_WINDOW;
2331 }
2332 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2333 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2334 if (!abilityContext) {
2335 return Destroy();
2336 }
2337 sptr<AAFwk::IPrepareTerminateCallback> callback = this;
2338 if (AAFwk::AbilityManagerClient::GetInstance()->PrepareTerminateAbility(abilityContext->GetToken(),
2339 callback) != ERR_OK) {
2340 WLOGFW("RegisterWindowManagerServiceHandler failed, do close window");
2341 PendingClose();
2342 return WMError::WM_OK;
2343 }
2344 }
2345 return WMError::WM_OK;
2346 }
2347
DoPrepareTerminate()2348 void WindowImpl::DoPrepareTerminate()
2349 {
2350 WLOGFI("do pending close by ability");
2351 PendingClose();
2352 }
2353
PendingClose()2354 void WindowImpl::PendingClose()
2355 {
2356 WLOGFD("begin");
2357 WMError ret = NotifyWindowTransition(TransitionReason::CLOSE_BUTTON);
2358 if (ret != WMError::WM_OK) {
2359 WLOGI("Close without animation ret:%{public}u", static_cast<uint32_t>(ret));
2360 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2361 if (abilityContext != nullptr) {
2362 abilityContext->CloseAbility();
2363 }
2364 }
2365 }
2366
RequestFocus() const2367 WMError WindowImpl::RequestFocus() const
2368 {
2369 if (!IsWindowValid()) {
2370 return WMError::WM_ERROR_INVALID_WINDOW;
2371 }
2372 return SingletonContainer::Get<WindowAdapter>().RequestFocus(property_->GetWindowId());
2373 }
2374
SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer> & inputEventConsumer)2375 void WindowImpl::SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer)
2376 {
2377 std::lock_guard<std::recursive_mutex> lock(mutex_);
2378 inputEventConsumer_ = inputEventConsumer;
2379 }
2380
RegisterLifeCycleListener(const sptr<IWindowLifeCycle> & listener)2381 WMError WindowImpl::RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
2382 {
2383 WLOGFD("Start register");
2384 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2385 return RegisterListener(lifecycleListeners_[GetWindowId()], listener);
2386 }
2387
UnregisterLifeCycleListener(const sptr<IWindowLifeCycle> & listener)2388 WMError WindowImpl::UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
2389 {
2390 WLOGFD("Start unregister");
2391 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2392 return UnregisterListener(lifecycleListeners_[GetWindowId()], listener);
2393 }
2394
RegisterWindowChangeListener(const sptr<IWindowChangeListener> & listener)2395 WMError WindowImpl::RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
2396 {
2397 WLOGFD("Start register");
2398 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2399 return RegisterListener(windowChangeListeners_[GetWindowId()], listener);
2400 }
2401
UnregisterWindowChangeListener(const sptr<IWindowChangeListener> & listener)2402 WMError WindowImpl::UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
2403 {
2404 WLOGFD("Start unregister");
2405 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2406 return UnregisterListener(windowChangeListeners_[GetWindowId()], listener);
2407 }
2408
RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener> & listener)2409 WMError WindowImpl::RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
2410 {
2411 WLOGFD("Start register");
2412 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2413 WMError ret = RegisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
2414 if (avoidAreaChangeListeners_[GetWindowId()].size() == 1) {
2415 SingletonContainer::Get<WindowAdapter>().UpdateAvoidAreaListener(property_->GetWindowId(), true);
2416 }
2417 return ret;
2418 }
2419
UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener> & listener)2420 WMError WindowImpl::UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
2421 {
2422 WLOGFD("Start unregister");
2423 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2424 WMError ret = UnregisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
2425 if (avoidAreaChangeListeners_[GetWindowId()].empty()) {
2426 SingletonContainer::Get<WindowAdapter>().UpdateAvoidAreaListener(property_->GetWindowId(), false);
2427 }
2428 return ret;
2429 }
2430
RegisterDragListener(const sptr<IWindowDragListener> & listener)2431 WMError WindowImpl::RegisterDragListener(const sptr<IWindowDragListener>& listener)
2432 {
2433 WLOGFD("Start register");
2434 std::lock_guard<std::recursive_mutex> lock(mutex_);
2435 return RegisterListener(windowDragListeners_, listener);
2436 }
2437
UnregisterDragListener(const sptr<IWindowDragListener> & listener)2438 WMError WindowImpl::UnregisterDragListener(const sptr<IWindowDragListener>& listener)
2439 {
2440 WLOGFD("Start unregister");
2441 std::lock_guard<std::recursive_mutex> lock(mutex_);
2442 return UnregisterListener(windowDragListeners_, listener);
2443 }
2444
RegisterDisplayMoveListener(sptr<IDisplayMoveListener> & listener)2445 WMError WindowImpl::RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
2446 {
2447 WLOGFD("Start register");
2448 std::lock_guard<std::recursive_mutex> lock(mutex_);
2449 return RegisterListener(displayMoveListeners_, listener);
2450 }
2451
UnregisterDisplayMoveListener(sptr<IDisplayMoveListener> & listener)2452 WMError WindowImpl::UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
2453 {
2454 WLOGFD("Start unregister");
2455 std::lock_guard<std::recursive_mutex> lock(mutex_);
2456 return UnregisterListener(displayMoveListeners_, listener);
2457 }
2458
RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc & func)2459 void WindowImpl::RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func)
2460 {
2461 WLOGFD("Start register");
2462 notifyNativefunc_ = std::move(func);
2463 }
2464
RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener> & listener)2465 WMError WindowImpl::RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
2466 {
2467 WLOGFD("Start register");
2468 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2469 return RegisterListener(occupiedAreaChangeListeners_[GetWindowId()], listener);
2470 }
2471
UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener> & listener)2472 WMError WindowImpl::UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
2473 {
2474 WLOGFD("Start unregister");
2475 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2476 return UnregisterListener(occupiedAreaChangeListeners_[GetWindowId()], listener);
2477 }
2478
RegisterTouchOutsideListener(const sptr<ITouchOutsideListener> & listener)2479 WMError WindowImpl::RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
2480 {
2481 WLOGFD("Start register");
2482 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2483 return RegisterListener(touchOutsideListeners_[GetWindowId()], listener);
2484 }
2485
UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener> & listener)2486 WMError WindowImpl::UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
2487 {
2488 WLOGFD("Start unregister");
2489 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2490 return UnregisterListener(touchOutsideListeners_[GetWindowId()], listener);
2491 }
2492
RegisterAnimationTransitionController(const sptr<IAnimationTransitionController> & listener)2493 WMError WindowImpl::RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener)
2494 {
2495 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2496 WLOGFE("register animation transition controller permission denied!");
2497 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2498 }
2499 if (listener == nullptr) {
2500 WLOGFE("listener is nullptr");
2501 return WMError::WM_ERROR_NULLPTR;
2502 }
2503 animationTransitionController_ = listener;
2504 wptr<WindowProperty> propertyToken(property_);
2505 wptr<IAnimationTransitionController> animationTransitionControllerToken(animationTransitionController_);
2506 if (uiContent_) {
2507 uiContent_->SetNextFrameLayoutCallback([propertyToken, animationTransitionControllerToken]() {
2508 auto property = propertyToken.promote();
2509 auto animationTransitionController = animationTransitionControllerToken.promote();
2510 if (!property || !animationTransitionController) {
2511 return;
2512 }
2513 uint32_t animationFlag = property->GetAnimationFlag();
2514 if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
2515 // CustomAnimation is enabled when animationTransitionController_ exists
2516 animationTransitionController->AnimationForShown();
2517 }
2518 });
2519 }
2520 return WMError::WM_OK;
2521 }
2522
RegisterScreenshotListener(const sptr<IScreenshotListener> & listener)2523 WMError WindowImpl::RegisterScreenshotListener(const sptr<IScreenshotListener>& listener)
2524 {
2525 WLOGFD("Start register");
2526 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2527 return RegisterListener(screenshotListeners_[GetWindowId()], listener);
2528 }
2529
UnregisterScreenshotListener(const sptr<IScreenshotListener> & listener)2530 WMError WindowImpl::UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener)
2531 {
2532 WLOGFD("Start unregister");
2533 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2534 return UnregisterListener(screenshotListeners_[GetWindowId()], listener);
2535 }
2536
RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener> & listener)2537 WMError WindowImpl::RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
2538 {
2539 WLOGFD("Start register");
2540 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2541 return RegisterListener(dialogTargetTouchListeners_[GetWindowId()], listener);
2542 }
2543
UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener> & listener)2544 WMError WindowImpl::UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
2545 {
2546 WLOGFD("Start unregister");
2547 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2548 return UnregisterListener(dialogTargetTouchListeners_[GetWindowId()], listener);
2549 }
2550
RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener> & listener)2551 void WindowImpl::RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
2552 {
2553 WLOGFD("Start register");
2554 if (listener == nullptr) {
2555 WLOGFE("listener is nullptr");
2556 return;
2557 }
2558 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2559 dialogDeathRecipientListener_[GetWindowId()] = listener;
2560 }
2561
UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener> & listener)2562 void WindowImpl::UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
2563 {
2564 WLOGFD("Start unregister");
2565 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2566 dialogDeathRecipientListener_[GetWindowId()] = nullptr;
2567 }
2568
2569 template<typename T>
RegisterListener(std::vector<sptr<T>> & holder,const sptr<T> & listener)2570 WMError WindowImpl::RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
2571 {
2572 if (listener == nullptr) {
2573 WLOGFE("listener is nullptr");
2574 return WMError::WM_ERROR_NULLPTR;
2575 }
2576 if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
2577 WLOGFE("Listener already registered");
2578 return WMError::WM_OK;
2579 }
2580 holder.emplace_back(listener);
2581 return WMError::WM_OK;
2582 }
2583
2584 template<typename T>
UnregisterListener(std::vector<sptr<T>> & holder,const sptr<T> & listener)2585 WMError WindowImpl::UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
2586 {
2587 if (listener == nullptr) {
2588 WLOGFE("listener could not be null");
2589 return WMError::WM_ERROR_NULLPTR;
2590 }
2591 holder.erase(std::remove_if(holder.begin(), holder.end(),
2592 [listener](sptr<T> registeredListener) {
2593 return registeredListener == listener;
2594 }), holder.end());
2595 return WMError::WM_OK;
2596 }
2597
2598 template <typename T>
GetListeners()2599 EnableIfSame<T, IWindowLifeCycle, std::vector<sptr<IWindowLifeCycle>>> WindowImpl::GetListeners()
2600 {
2601 std::vector<sptr<IWindowLifeCycle>> lifecycleListeners;
2602 {
2603 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2604 for (auto &listener : lifecycleListeners_[GetWindowId()]) {
2605 lifecycleListeners.push_back(listener);
2606 }
2607 }
2608 return lifecycleListeners;
2609 }
2610
2611 template <typename T>
GetListeners()2612 EnableIfSame<T, IWindowChangeListener, std::vector<sptr<IWindowChangeListener>>> WindowImpl::GetListeners()
2613 {
2614 std::vector<sptr<IWindowChangeListener>> windowChangeListeners;
2615 {
2616 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2617 for (auto &listener : windowChangeListeners_[GetWindowId()]) {
2618 windowChangeListeners.push_back(listener);
2619 }
2620 }
2621 return windowChangeListeners;
2622 }
2623
2624 template <typename T>
GetListeners()2625 EnableIfSame<T, IAvoidAreaChangedListener, std::vector<sptr<IAvoidAreaChangedListener>>> WindowImpl::GetListeners()
2626 {
2627 std::vector<sptr<IAvoidAreaChangedListener>> avoidAreaChangeListeners;
2628 {
2629 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2630 for (auto &listener : avoidAreaChangeListeners_[GetWindowId()]) {
2631 avoidAreaChangeListeners.push_back(listener);
2632 }
2633 }
2634 return avoidAreaChangeListeners;
2635 }
2636
2637 template <typename T>
GetListeners()2638 EnableIfSame<T, IDisplayMoveListener, std::vector<sptr<IDisplayMoveListener>>> WindowImpl::GetListeners()
2639 {
2640 std::vector<sptr<IDisplayMoveListener>> displayMoveListeners;
2641 {
2642 std::lock_guard<std::recursive_mutex> lock(mutex_);
2643 for (auto &listener : displayMoveListeners_) {
2644 displayMoveListeners.push_back(listener);
2645 }
2646 }
2647 return displayMoveListeners;
2648 }
2649
2650 template <typename T>
GetListeners()2651 EnableIfSame<T, IScreenshotListener, std::vector<sptr<IScreenshotListener>>> WindowImpl::GetListeners()
2652 {
2653 std::vector<sptr<IScreenshotListener>> screenshotListeners;
2654 {
2655 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2656 for (auto &listener : screenshotListeners_[GetWindowId()]) {
2657 screenshotListeners.push_back(listener);
2658 }
2659 }
2660 return screenshotListeners;
2661 }
2662
2663 template <typename T>
GetListeners()2664 EnableIfSame<T, ITouchOutsideListener, std::vector<sptr<ITouchOutsideListener>>> WindowImpl::GetListeners()
2665 {
2666 std::vector<sptr<ITouchOutsideListener>> touchOutsideListeners;
2667 {
2668 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2669 for (auto &listener : touchOutsideListeners_[GetWindowId()]) {
2670 touchOutsideListeners.push_back(listener);
2671 }
2672 }
2673 return touchOutsideListeners;
2674 }
2675
2676 template <typename T>
GetListeners()2677 EnableIfSame<T, IDialogTargetTouchListener, std::vector<sptr<IDialogTargetTouchListener>>> WindowImpl::GetListeners()
2678 {
2679 std::vector<sptr<IDialogTargetTouchListener>> dialogTargetTouchListeners;
2680 {
2681 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2682 for (auto &listener : dialogTargetTouchListeners_[GetWindowId()]) {
2683 dialogTargetTouchListeners.push_back(listener);
2684 }
2685 }
2686 return dialogTargetTouchListeners;
2687 }
2688
2689 template <typename T>
GetListeners()2690 EnableIfSame<T, IWindowDragListener, std::vector<sptr<IWindowDragListener>>> WindowImpl::GetListeners()
2691 {
2692 std::vector<sptr<IWindowDragListener>> windowDragListeners;
2693 {
2694 std::lock_guard<std::recursive_mutex> lock(mutex_);
2695 for (auto &listener : windowDragListeners_) {
2696 windowDragListeners.push_back(listener);
2697 }
2698 }
2699 return windowDragListeners;
2700 }
2701
2702 template <typename T>
GetListeners()2703 EnableIfSame<T, IOccupiedAreaChangeListener, std::vector<sptr<IOccupiedAreaChangeListener>>> WindowImpl::GetListeners()
2704 {
2705 std::vector<sptr<IOccupiedAreaChangeListener>> occupiedAreaChangeListeners;
2706 {
2707 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2708 for (auto &listener : occupiedAreaChangeListeners_[GetWindowId()]) {
2709 occupiedAreaChangeListeners.push_back(listener);
2710 }
2711 }
2712 return occupiedAreaChangeListeners;
2713 }
2714
2715 template <typename T>
GetListener()2716 EnableIfSame<T, IDialogDeathRecipientListener, wptr<IDialogDeathRecipientListener>> WindowImpl::GetListener()
2717 {
2718 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2719 return dialogDeathRecipientListener_[GetWindowId()];
2720 }
2721
SetAceAbilityHandler(const sptr<IAceAbilityHandler> & handler)2722 void WindowImpl::SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler)
2723 {
2724 if (handler == nullptr) {
2725 WLOGI("ace ability handler is nullptr");
2726 }
2727 std::lock_guard<std::recursive_mutex> lock(mutex_);
2728 aceAbilityHandler_ = handler;
2729 }
2730
SetRequestWindowModeSupportType(uint32_t windowModeSupportType)2731 void WindowImpl::SetRequestWindowModeSupportType(uint32_t windowModeSupportType)
2732 {
2733 property_->SetRequestWindowModeSupportType(windowModeSupportType);
2734 SetWindowModeSupportType(windowModeSupportType);
2735 }
2736
SetWindowModeSupportType(uint32_t windowModeSupportType)2737 void WindowImpl::SetWindowModeSupportType(uint32_t windowModeSupportType)
2738 {
2739 property_->SetWindowModeSupportType(windowModeSupportType);
2740 }
2741
UpdateRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)2742 void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason,
2743 const std::shared_ptr<RSTransaction>& rsTransaction)
2744 {
2745 if (state_ == WindowState::STATE_DESTROYED) {
2746 WLOGFW("invalid window state");
2747 return;
2748 }
2749 auto display = SingletonContainer::IsDestroyed() ? nullptr :
2750 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
2751 if (display == nullptr) {
2752 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
2753 property_->GetWindowId());
2754 return;
2755 }
2756 Rect lastOriRect = property_->GetWindowRect();
2757
2758 property_->SetDecoStatus(decoStatus);
2759 if (reason == WindowSizeChangeReason::HIDE) {
2760 property_->SetRequestRect(rect);
2761 return;
2762 }
2763 property_->SetWindowRect(rect);
2764
2765 // update originRect when floating window show for the first time.
2766 if (!isOriginRectSet_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2767 property_->SetOriginRect(rect);
2768 isOriginRectSet_ = true;
2769 }
2770 WLOGFD("winId:%{public}u, rect[%{public}d, %{public}d, %{public}u, %{public}u], reason:%{public}u",
2771 property_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_, reason);
2772 Rect rectToAce = rect;
2773 // update rectToAce for stretchable window
2774 if (windowSystemConfig_.isStretchable_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2775 if (IsStretchableReason(reason)) {
2776 rectToAce = property_->GetOriginRect();
2777 } else {
2778 property_->SetOriginRect(rect);
2779 }
2780 }
2781 ScheduleUpdateRectTask(rectToAce, lastOriRect, reason, rsTransaction, display);
2782 }
2783
ScheduleUpdateRectTask(const Rect & rectToAce,const Rect & lastOriRect,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction,const sptr<class Display> & display)2784 void WindowImpl::ScheduleUpdateRectTask(const Rect& rectToAce, const Rect& lastOriRect, WindowSizeChangeReason reason,
2785 const std::shared_ptr<RSTransaction>& rsTransaction, const sptr<class Display>& display)
2786 {
2787 auto task = [weakThis = wptr(this), reason, rsTransaction, rectToAce, lastOriRect, display]() mutable {
2788 auto window = weakThis.promote();
2789 if (!window) {
2790 TLOGNE(WmsLogTag::WMS_IMMS, "window is null");
2791 return;
2792 }
2793 if (rsTransaction) {
2794 RSTransaction::FlushImplicitTransaction();
2795 rsTransaction->Begin();
2796 }
2797 RSAnimationTimingProtocol protocol;
2798 protocol.SetDuration(600);
2799 auto curve = RSAnimationTimingCurve::CreateCubicCurve(0.2, 0.0, 0.2, 1.0);
2800 RSNode::OpenImplicitAnimation(protocol, curve);
2801 if ((rectToAce != lastOriRect) || (reason != window->lastSizeChangeReason_)) {
2802 window->NotifySizeChange(rectToAce, reason, rsTransaction);
2803 window->lastSizeChangeReason_ = reason;
2804 }
2805 window->UpdateViewportConfig(rectToAce, display, reason, rsTransaction);
2806 RSNode::CloseImplicitAnimation();
2807 if (rsTransaction) {
2808 rsTransaction->Commit();
2809 }
2810 window->postTaskDone_ = true;
2811 };
2812 ResSchedReport::GetInstance().RequestPerfIfNeed(reason, GetType(), GetMode());
2813 if (reason == WindowSizeChangeReason::ROTATION) {
2814 postTaskDone_ = false;
2815 handler_->PostTask(task, "wms:UpdateRect");
2816 } else {
2817 if ((rectToAce != lastOriRect) || (reason != lastSizeChangeReason_) || !postTaskDone_) {
2818 NotifySizeChange(rectToAce, reason, rsTransaction);
2819 lastSizeChangeReason_ = reason;
2820 postTaskDone_ = true;
2821 }
2822 UpdateViewportConfig(rectToAce, display, reason, rsTransaction);
2823 }
2824 }
2825
UpdateMode(WindowMode mode)2826 void WindowImpl::UpdateMode(WindowMode mode)
2827 {
2828 WLOGI("UpdateMode %{public}u", mode);
2829 property_->SetWindowMode(mode);
2830 UpdateTitleButtonVisibility();
2831 UpdateDecorEnable(true);
2832 }
2833
UpdateWindowModeSupportType(uint32_t windowModeSupportType)2834 void WindowImpl::UpdateWindowModeSupportType(uint32_t windowModeSupportType)
2835 {
2836 WLOGFD("windowModeSupportType: %{public}u, winId: %{public}u", windowModeSupportType, GetWindowId());
2837 SetWindowModeSupportType(windowModeSupportType);
2838 UpdateTitleButtonVisibility();
2839 }
2840
HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)2841 void WindowImpl::HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
2842 {
2843 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
2844 {
2845 std::lock_guard<std::recursive_mutex> lock(mutex_);
2846 inputEventConsumer = inputEventConsumer_;
2847 }
2848 SingletonContainer::Get<WindowInfoReporter>().ReportBackButtonInfoImmediately();
2849
2850 bool isConsumed = false;
2851 if (inputEventConsumer != nullptr) {
2852 WLOGD("Transfer back key event to inputEventConsumer");
2853 isConsumed = inputEventConsumer->OnInputEvent(keyEvent);
2854 } else if (uiContent_ != nullptr) {
2855 WLOGD("Transfer back key event to uiContent");
2856 isConsumed = uiContent_->ProcessBackPressed();
2857 } else {
2858 WLOGFE("There is no back key event consumer");
2859 }
2860 if (isConsumed) {
2861 WLOGD("Back key event is consumed");
2862 return;
2863 }
2864 PerformBack();
2865 }
2866
PerformBack()2867 void WindowImpl::PerformBack()
2868 {
2869 auto task = [weakThis = wptr(this)]() {
2870 auto window = weakThis.promote();
2871 if (!window) {
2872 TLOGNE(WmsLogTag::WMS_IMMS, "window is null");
2873 return;
2874 }
2875 if (!WindowHelper::IsMainWindow(window->property_->GetWindowType())) {
2876 WLOGD("it is not a main window");
2877 return;
2878 }
2879 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(window->context_);
2880 if (abilityContext == nullptr) {
2881 WLOGFE("abilityContext is null");
2882 return;
2883 }
2884 bool needMoveToBackground = false;
2885 int ret = abilityContext->OnBackPressedCallBack(needMoveToBackground);
2886 if (ret == ERR_OK && needMoveToBackground) {
2887 abilityContext->MoveAbilityToBackground();
2888 WLOGD("id: %{public}u closed, to move Ability: %{public}u",
2889 window->property_->GetWindowId(), needMoveToBackground);
2890 return;
2891 }
2892 // TerminateAbility will invoke last ability, CloseAbility will not.
2893 bool shouldTerminateAbility = WindowHelper::IsFullScreenWindow(window->property_->GetWindowMode());
2894 if (shouldTerminateAbility) {
2895 abilityContext->TerminateSelf();
2896 } else {
2897 abilityContext->CloseAbility();
2898 }
2899 WLOGD("id: %{public}u closed, to kill Ability: %{public}u",
2900 window->property_->GetWindowId(), static_cast<uint32_t>(shouldTerminateAbility));
2901 };
2902 handler_->PostTask(task, "WindowImpl::PerformBack");
2903 }
2904
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> & keyEvent)2905 void WindowImpl::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent)
2906 {
2907 int32_t keyCode = keyEvent->GetKeyCode();
2908 int32_t keyAction = keyEvent->GetKeyAction();
2909 WLOGFD("KeyCode: %{public}d, action: %{public}d", keyCode, keyAction);
2910 bool shouldMarkProcess = true;
2911 if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) {
2912 HandleBackKeyPressedEvent(keyEvent);
2913 } else {
2914 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
2915 {
2916 std::lock_guard<std::recursive_mutex> lock(mutex_);
2917 inputEventConsumer = inputEventConsumer_;
2918 }
2919 if (inputEventConsumer != nullptr) {
2920 WLOGD("Transfer key event to inputEventConsumer");
2921 (void)inputEventConsumer->OnInputEvent(keyEvent);
2922 shouldMarkProcess = false;
2923 } else if (uiContent_ != nullptr) {
2924 WLOGD("Transfer key event to uiContent");
2925 bool handled = static_cast<bool>(uiContent_->ProcessKeyEvent(keyEvent));
2926 if (!handled && keyCode == MMI::KeyEvent::KEYCODE_ESCAPE &&
2927 GetMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
2928 property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL &&
2929 keyAction == MMI::KeyEvent::KEY_ACTION_DOWN && !escKeyEventTriggered_) {
2930 WLOGI("recover from fullscreen cause KEYCODE_ESCAPE");
2931 Recover();
2932 }
2933 if (keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE) {
2934 escKeyEventTriggered_ = (keyAction == MMI::KeyEvent::KEY_ACTION_UP) ? false : true;
2935 }
2936 shouldMarkProcess = !handled;
2937 } else {
2938 WLOGFE("There is no key event consumer");
2939 }
2940 }
2941 if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
2942 WLOGFI("DispatchKeyEvent: %{public}u", GetWindowId());
2943 SingletonContainer::Get<WindowAdapter>().DispatchKeyEvent(GetWindowId(), keyEvent);
2944 keyEvent->MarkProcessed();
2945 return;
2946 }
2947 if (shouldMarkProcess) {
2948 keyEvent->MarkProcessed();
2949 }
2950 }
2951
HandleModeChangeHotZones(int32_t posX,int32_t posY)2952 void WindowImpl::HandleModeChangeHotZones(int32_t posX, int32_t posY)
2953 {
2954 if (!WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2955 return;
2956 }
2957
2958 ModeChangeHotZones hotZones;
2959 auto res = SingletonContainer::Get<WindowAdapter>().GetModeChangeHotZones(property_->GetDisplayId(), hotZones);
2960 WLOGD("[HotZone] Window %{public}u, Pointer[%{public}d, %{public}d]", GetWindowId(), posX, posY);
2961 if (res == WMError::WM_OK) {
2962 WLOGD("[HotZone] Fullscreen [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.fullscreen_.posX_,
2963 hotZones.fullscreen_.posY_, hotZones.fullscreen_.width_, hotZones.fullscreen_.height_);
2964 WLOGD("[HotZone] Primary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.primary_.posX_,
2965 hotZones.primary_.posY_, hotZones.primary_.width_, hotZones.primary_.height_);
2966 WLOGD("[HotZone] Secondary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.secondary_.posX_,
2967 hotZones.secondary_.posY_, hotZones.secondary_.width_, hotZones.secondary_.height_);
2968
2969 if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.fullscreen_)) {
2970 SetFullScreen(true);
2971 } else if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.primary_)) {
2972 SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
2973 } else if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.secondary_)) {
2974 SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
2975 }
2976 }
2977 }
2978
UpdatePointerEventForStretchableWindow(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)2979 void WindowImpl::UpdatePointerEventForStretchableWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
2980 {
2981 MMI::PointerEvent::PointerItem pointerItem;
2982 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
2983 WLOGFW("Point item is invalid");
2984 return;
2985 }
2986 const Rect& originRect = property_->GetOriginRect();
2987 PointInfo originPos =
2988 WindowHelper::CalculateOriginPosition(originRect, GetRect(),
2989 { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() });
2990 pointerItem.SetDisplayX(originPos.x);
2991 pointerItem.SetDisplayY(originPos.y);
2992 pointerItem.SetWindowX(originPos.x - originRect.posX_);
2993 pointerItem.SetWindowY(originPos.y - originRect.posY_);
2994 pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem);
2995 }
2996
UpdateDragType(int32_t startPointPosX,int32_t startPointPosY)2997 void WindowImpl::UpdateDragType(int32_t startPointPosX, int32_t startPointPosY)
2998 {
2999 const auto& startRectExceptCorner = moveDragProperty_->startRectExceptCorner_;
3000 if (startPointPosX > startRectExceptCorner.posX_ &&
3001 (startPointPosX < startRectExceptCorner.posX_ +
3002 static_cast<int32_t>(startRectExceptCorner.width_))) {
3003 moveDragProperty_->dragType_ = DragType::DRAG_BOTTOM_OR_TOP;
3004 } else if (startPointPosY > startRectExceptCorner.posY_ &&
3005 (startPointPosY < startRectExceptCorner.posY_ +
3006 static_cast<int32_t>(startRectExceptCorner.height_))) {
3007 moveDragProperty_->dragType_ = DragType::DRAG_LEFT_OR_RIGHT;
3008 } else if ((startPointPosX <= startRectExceptCorner.posX_ && startPointPosY <= startRectExceptCorner.posY_) ||
3009 (startPointPosX >= startRectExceptCorner.posX_ + static_cast<int32_t>(startRectExceptCorner.width_) &&
3010 startPointPosY >= startRectExceptCorner.posY_ + static_cast<int32_t>(startRectExceptCorner.height_))) {
3011 moveDragProperty_->dragType_ = DragType::DRAG_LEFT_TOP_CORNER;
3012 } else {
3013 moveDragProperty_->dragType_ = DragType::DRAG_RIGHT_TOP_CORNER;
3014 }
3015 }
3016
CalculateStartRectExceptHotZone(float vpr)3017 void WindowImpl::CalculateStartRectExceptHotZone(float vpr)
3018 {
3019 TransformHelper::Vector2 hotZoneScale(1, 1);
3020 if (property_->isNeedComputerTransform()) {
3021 property_->ComputeTransform();
3022 hotZoneScale = WindowHelper::CalculateHotZoneScale(property_->GetTransformMat());
3023 }
3024
3025 const auto& startPointRect = GetRect();
3026 auto& startRectExceptFrame = moveDragProperty_->startRectExceptFrame_;
3027 startRectExceptFrame.posX_ = startPointRect.posX_ +
3028 static_cast<int32_t>(WINDOW_FRAME_WIDTH * vpr / hotZoneScale.x_);
3029 startRectExceptFrame.posY_ = startPointRect.posY_ +
3030 static_cast<int32_t>(WINDOW_FRAME_WIDTH * vpr / hotZoneScale.y_);
3031 startRectExceptFrame.width_ = startPointRect.width_ -
3032 static_cast<uint32_t>((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * vpr / hotZoneScale.x_);
3033 startRectExceptFrame.height_ = startPointRect.height_ -
3034 static_cast<uint32_t>((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * vpr / hotZoneScale.y_);
3035
3036 auto& startRectExceptCorner = moveDragProperty_->startRectExceptCorner_;
3037 startRectExceptCorner.posX_ = startPointRect.posX_ +
3038 static_cast<int32_t>(WINDOW_FRAME_CORNER_WIDTH * vpr / hotZoneScale.x_);
3039 startRectExceptCorner.posY_ = startPointRect.posY_ +
3040 static_cast<int32_t>(WINDOW_FRAME_CORNER_WIDTH * vpr / hotZoneScale.y_);
3041 startRectExceptCorner.width_ = startPointRect.width_ -
3042 static_cast<uint32_t>((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * vpr / hotZoneScale.x_);
3043 startRectExceptCorner.height_ = startPointRect.height_ -
3044 static_cast<uint32_t>((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * vpr / hotZoneScale.y_);
3045 }
3046
IsPointInDragHotZone(int32_t startPointPosX,int32_t startPointPosY,int32_t sourceType)3047 bool WindowImpl::IsPointInDragHotZone(int32_t startPointPosX, int32_t startPointPosY, int32_t sourceType)
3048 {
3049 // calculate rect with hotzone
3050 Rect rectWithHotzone;
3051 rectWithHotzone.posX_ = GetRect().posX_ - static_cast<int32_t>(HOTZONE_POINTER);
3052 rectWithHotzone.posY_ = GetRect().posY_ - static_cast<int32_t>(HOTZONE_POINTER);
3053 rectWithHotzone.width_ = GetRect().width_ + HOTZONE_POINTER * 2; // 2: calculate width need
3054 rectWithHotzone.height_ = GetRect().height_ + HOTZONE_POINTER * 2; // 2: calculate height need
3055
3056 if (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE &&
3057 !WindowHelper::IsPointInTargetRectWithBound(startPointPosX, startPointPosY, rectWithHotzone)) {
3058 return false;
3059 } else if ((!WindowHelper::IsPointInTargetRect(startPointPosX,
3060 startPointPosY, moveDragProperty_->startRectExceptFrame_)) ||
3061 (!WindowHelper::IsPointInWindowExceptCorner(startPointPosX,
3062 startPointPosY, moveDragProperty_->startRectExceptCorner_))) {
3063 return true;
3064 }
3065 return false;
3066 }
3067
StartMove()3068 void WindowImpl::StartMove()
3069 {
3070 if (!WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
3071 WLOGE("[StartMove] current window can not be moved, windowId %{public}u", GetWindowId());
3072 return;
3073 }
3074 if (!moveDragProperty_->pointEventStarted_ || moveDragProperty_->startDragFlag_) {
3075 WLOGE("[StartMove] pointerEvent has not been started, or is dragging now");
3076 return;
3077 }
3078 moveDragProperty_->startMoveFlag_ = true;
3079 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3080 property_, moveDragProperty_);
3081 WLOGI("[StartMove] windowId %{public}u", GetWindowId());
3082 }
3083
ResetMoveOrDragState()3084 void WindowImpl::ResetMoveOrDragState()
3085 {
3086 if (!WindowHelper::IsMainWindow(GetType())) {
3087 return;
3088 }
3089 moveDragProperty_->pointEventStarted_ = false;
3090 moveDragProperty_->startDragFlag_ = false;
3091 moveDragProperty_->startMoveFlag_ = false;
3092 UpdateRect(GetRect(), property_->GetDecoStatus(), WindowSizeChangeReason::DRAG_END);
3093 }
3094
ReadyToMoveOrDragWindow(const std::shared_ptr<MMI::PointerEvent> & pointerEvent,const MMI::PointerEvent::PointerItem & pointerItem)3095 void WindowImpl::ReadyToMoveOrDragWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
3096 const MMI::PointerEvent::PointerItem& pointerItem)
3097 {
3098 if (moveDragProperty_->pointEventStarted_) {
3099 return;
3100 }
3101
3102 moveDragProperty_->startPointRect_ = GetRect();
3103 moveDragProperty_->startPointPosX_ = pointerItem.GetDisplayX();
3104 moveDragProperty_->startPointPosY_ = pointerItem.GetDisplayY();
3105 moveDragProperty_->startPointerId_ = pointerEvent->GetPointerId();
3106 moveDragProperty_->targetDisplayId_ = pointerEvent->GetTargetDisplayId();
3107 moveDragProperty_->sourceType_ = pointerEvent->GetSourceType();
3108 moveDragProperty_->pointEventStarted_ = true;
3109
3110 // calculate window inner rect except frame
3111 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3112 SingletonContainer::Get<DisplayManager>().GetDisplayById(moveDragProperty_->targetDisplayId_);
3113 if (display == nullptr) {
3114 WLOGFE("get display failed moveDragProperty targetDisplayId:%{public}u, window id:%{public}u",
3115 moveDragProperty_->targetDisplayId_, property_->GetWindowId());
3116 return;
3117 }
3118 auto displayInfo = display->GetDisplayInfo();
3119 if (displayInfo == nullptr) {
3120 WLOGFE("get display info failed moveDragProperty targetDisplayId:%{public}u, window id:%{public}u",
3121 moveDragProperty_->targetDisplayId_, property_->GetWindowId());
3122 return;
3123 }
3124 float vpr = display->GetVirtualPixelRatio();
3125 int32_t startPointPosX = moveDragProperty_->startPointPosX_ + displayInfo->GetOffsetX();
3126 int32_t startPointPosY = moveDragProperty_->startPointPosY_ + displayInfo->GetOffsetY();
3127
3128 CalculateStartRectExceptHotZone(vpr);
3129
3130 if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
3131 moveDragProperty_->startMoveFlag_ = true;
3132 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3133 property_, moveDragProperty_);
3134 } else if (IsPointInDragHotZone(startPointPosX, startPointPosY, moveDragProperty_->sourceType_)
3135 && property_->GetMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
3136 moveDragProperty_->startDragFlag_ = true;
3137 UpdateDragType(startPointPosX, startPointPosY);
3138 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3139 property_, moveDragProperty_);
3140 }
3141 return;
3142 }
3143
EndMoveOrDragWindow(int32_t posX,int32_t posY,int32_t pointId,int32_t sourceType)3144 void WindowImpl::EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType)
3145 {
3146 if (pointId != moveDragProperty_->startPointerId_ || sourceType != moveDragProperty_->sourceType_) {
3147 return;
3148 }
3149
3150 if (moveDragProperty_->startDragFlag_) {
3151 SingletonContainer::Get<WindowAdapter>().ProcessPointUp(GetWindowId());
3152 moveDragProperty_->startDragFlag_ = false;
3153 }
3154
3155 if (moveDragProperty_->startMoveFlag_) {
3156 SingletonContainer::Get<WindowAdapter>().ProcessPointUp(GetWindowId());
3157 moveDragProperty_->startMoveFlag_ = false;
3158 HandleModeChangeHotZones(posX, posY);
3159 }
3160 moveDragProperty_->pointEventStarted_ = false;
3161 ResSchedReport::GetInstance().StopPerfIfNeed();
3162 }
3163
ConsumeMoveOrDragEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3164 void WindowImpl::ConsumeMoveOrDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3165 {
3166 MMI::PointerEvent::PointerItem pointerItem;
3167 int32_t pointId = pointerEvent->GetPointerId();
3168 int32_t sourceType = pointerEvent->GetSourceType();
3169 if (!pointerEvent->GetPointerItem(pointId, pointerItem) ||
3170 (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE &&
3171 pointerEvent->GetButtonId() != MMI::PointerEvent::MOUSE_BUTTON_LEFT)) {
3172 WLOGFW("invalid pointerEvent");
3173 return;
3174 }
3175 int32_t pointDisplayX = pointerItem.GetDisplayX();
3176 int32_t pointDisplayY = pointerItem.GetDisplayY();
3177 int32_t action = pointerEvent->GetPointerAction();
3178 int32_t targetDisplayId = pointerEvent->GetTargetDisplayId();
3179 switch (action) {
3180 // Ready to move or drag
3181 case MMI::PointerEvent::POINTER_ACTION_DOWN:
3182 case MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: {
3183 const auto& rect = GetRect();
3184 ReadyToMoveOrDragWindow(pointerEvent, pointerItem);
3185 if (IsPointerEventConsumed()) {
3186 ResSchedReport::GetInstance().TrigClick();
3187 }
3188 TLOGD(WmsLogTag::WMS_EVENT, "windowId:%{public}u, pointId:%{public}d, sourceType:%{public}d, "
3189 "hasPointStarted:%{public}d, startMove:%{public}d, startDrag:%{public}d, targetDisplayId:"
3190 "%{public}d, pointPos:[%{private}d, %{private}d], winRect:[%{public}d, %{public}d, %{public}u, "
3191 "%{public}u]", GetWindowId(), pointId, sourceType, moveDragProperty_->pointEventStarted_,
3192 moveDragProperty_->startMoveFlag_, moveDragProperty_->startDragFlag_, targetDisplayId,
3193 pointDisplayX, pointDisplayY, rect.posX_, rect.posY_, rect.width_, rect.height_);
3194 break;
3195 }
3196 // End move or drag
3197 case MMI::PointerEvent::POINTER_ACTION_UP:
3198 case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP:
3199 case MMI::PointerEvent::POINTER_ACTION_CANCEL: {
3200 EndMoveOrDragWindow(pointDisplayX, pointDisplayY, pointId, sourceType);
3201 WLOGFD("[Client Point Up/Cancel]: windowId: %{public}u, action: %{public}d, sourceType: %{public}d, "
3202 "startMove: %{public}d, startDrag: %{public}d", GetWindowId(), action, sourceType,
3203 moveDragProperty_->startMoveFlag_, moveDragProperty_->startDragFlag_);
3204 break;
3205 }
3206 default:
3207 break;
3208 }
3209 }
3210
IsPointerEventConsumed()3211 bool WindowImpl::IsPointerEventConsumed()
3212 {
3213 return moveDragProperty_->startDragFlag_ || moveDragProperty_->startMoveFlag_;
3214 }
3215
TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3216 void WindowImpl::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3217 {
3218 if (pointerEvent == nullptr) {
3219 WLOGFE("The pointer event is nullptr");
3220 return;
3221 }
3222 if (windowSystemConfig_.isStretchable_ && GetMode() == WindowMode::WINDOW_MODE_FLOATING) {
3223 UpdatePointerEventForStretchableWindow(pointerEvent);
3224 }
3225 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
3226 {
3227 std::lock_guard<std::recursive_mutex> lock(mutex_);
3228 inputEventConsumer = inputEventConsumer_;
3229 }
3230 if (inputEventConsumer != nullptr) {
3231 WLOGFD("Transfer pointer event to inputEventConsumer");
3232 if (!(inputEventConsumer->OnInputEvent(pointerEvent))) {
3233 WLOGFI("The Input event consumer consumes pointer event failed.");
3234 pointerEvent->MarkProcessed();
3235 }
3236 } else if (uiContent_ != nullptr) {
3237 WLOGFD("Transfer pointer event to uiContent");
3238 if (!(uiContent_->ProcessPointerEvent(pointerEvent))) {
3239 WLOGFI("The UI content consumes pointer event failed.");
3240 pointerEvent->MarkProcessed();
3241 }
3242 } else {
3243 WLOGFW("pointerEvent is not consumed, windowId: %{public}u", GetWindowId());
3244 pointerEvent->MarkProcessed();
3245 }
3246 }
3247
CalculatePointerDirection(int32_t pointerX,int32_t pointerY)3248 uint32_t WindowImpl::CalculatePointerDirection(int32_t pointerX, int32_t pointerY)
3249 {
3250 UpdateDragType(pointerX, pointerY);
3251 return STYLEID_MAP.at(moveDragProperty_->dragType_);
3252 }
3253
HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3254 void WindowImpl::HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3255 {
3256 MMI::PointerEvent::PointerItem pointerItem;
3257 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
3258 WLOGFE("Get pointeritem failed");
3259 pointerEvent->MarkProcessed();
3260 return;
3261 }
3262 auto action = pointerEvent->GetPointerAction();
3263 uint32_t windowId = static_cast<uint32_t>(pointerEvent->GetAgentWindowId());
3264 int32_t mousePointX = pointerItem.GetDisplayX();
3265 int32_t mousePointY = pointerItem.GetDisplayY();
3266 int32_t sourceType = pointerEvent->GetSourceType();
3267 uint32_t oldStyleID = mouseStyleID_;
3268 uint32_t newStyleID = 0;
3269 if (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
3270 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3271 SingletonContainer::Get<DisplayManager>().GetDisplayById(pointerEvent->GetTargetDisplayId());
3272 if (display == nullptr || display->GetDisplayInfo() == nullptr) {
3273 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u",
3274 property_->GetDisplayId(), property_->GetWindowId());
3275 return;
3276 }
3277 float vpr = display->GetVirtualPixelRatio();
3278 CalculateStartRectExceptHotZone(vpr);
3279 if (IsPointInDragHotZone(mousePointX, mousePointY, sourceType) &&
3280 property_->GetMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
3281 newStyleID = CalculatePointerDirection(mousePointX, mousePointY);
3282 } else if (action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) {
3283 newStyleID = MMI::MOUSE_ICON::DEFAULT;
3284 }
3285 } else if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
3286 newStyleID = (GetRect().width_ > GetRect().height_) ?
3287 MMI::MOUSE_ICON::NORTH_SOUTH : MMI::MOUSE_ICON::WEST_EAST;
3288 if (action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) {
3289 newStyleID = MMI::MOUSE_ICON::DEFAULT; // when receive up event, set default style
3290 }
3291 }
3292 TLOGD(WmsLogTag::WMS_EVENT, "winId:%{public}u, Mouse posX:%{private}u, posY:%{private}u, action:%{public}u, "
3293 "winRect posX:%{public}u, posY:%{public}u, W:%{public}u, H:%{public}u, "
3294 "newStyle:%{public}u, oldStyle:%{public}u",
3295 windowId, mousePointX, mousePointY, action, GetRect().posX_,
3296 GetRect().posY_, GetRect().width_, GetRect().height_, newStyleID, oldStyleID);
3297 if (oldStyleID != newStyleID) {
3298 MMI::PointerStyle pointerStyle;
3299 pointerStyle.id = static_cast<int32_t>(newStyleID);
3300 int32_t res = MMI::InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
3301 if (res != 0) {
3302 WLOGFE("set pointer style failed, res is %{public}u", res);
3303 return;
3304 }
3305 mouseStyleID_ = newStyleID;
3306 }
3307 }
3308
PerfLauncherHotAreaIfNeed(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3309 void WindowImpl::PerfLauncherHotAreaIfNeed(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3310 {
3311 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3312 int32_t action = pointerEvent->GetPointerAction();
3313 if (action != MMI::PointerEvent::POINTER_ACTION_CANCEL) {
3314 return;
3315 }
3316 MMI::PointerEvent::PointerItem pointerItem;
3317 int32_t pointId = pointerEvent->GetPointerId();
3318 if (!pointerEvent->GetPointerItem(pointId, pointerItem)) {
3319 WLOGFW("invalid pointerEvent");
3320 return;
3321 }
3322 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3323 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
3324 if (display == nullptr) {
3325 return;
3326 }
3327 auto displayHeight = display->GetHeight();
3328 constexpr float HOT_RATE = 0.07;
3329 auto height = static_cast<int32_t>(displayHeight * HOT_RATE);
3330 int32_t pointDisplayY = pointerItem.GetDisplayY();
3331 if (pointDisplayY > displayHeight - height) {
3332 ResSchedReport::GetInstance().AnimationBoost();
3333 }
3334 #endif
3335 }
3336
ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3337 void WindowImpl::ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3338 {
3339 // If windowRect transformed, transform event back to its origin position
3340 if (property_) {
3341 property_->UpdatePointerEvent(pointerEvent);
3342 }
3343 int32_t action = pointerEvent->GetPointerAction();
3344 if (action == MMI::PointerEvent::POINTER_ACTION_MOVE || action == MMI::PointerEvent::POINTER_ACTION_DOWN ||
3345 action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
3346 ResSchedReport::GetInstance().TrigSlide(GetType(), true);
3347 }
3348 if (action == MMI::PointerEvent::POINTER_ACTION_UP || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP ||
3349 action == MMI::PointerEvent::POINTER_ACTION_CANCEL) {
3350 ResSchedReport::GetInstance().TrigSlide(GetType(), false);
3351 }
3352 if ((action == MMI::PointerEvent::POINTER_ACTION_MOVE || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) &&
3353 pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
3354 HandlePointerStyle(pointerEvent);
3355 }
3356 PerfLauncherHotAreaIfNeed(pointerEvent);
3357 if (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
3358 WLOGFD("WMS process point down, id:%{public}u, action: %{public}d", GetWindowId(), action);
3359 if (GetType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) {
3360 MMI::PointerEvent::PointerItem pointerItem;
3361 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
3362 WLOGFW("Point item is invalid");
3363 pointerEvent->MarkProcessed();
3364 return;
3365 }
3366 if (!WindowHelper::IsPointInTargetRect(pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), GetRect())) {
3367 NotifyAfterUnfocused(false);
3368 pointerEvent->MarkProcessed();
3369 return;
3370 }
3371 }
3372 if (property_ != nullptr) {
3373 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId());
3374 }
3375 }
3376
3377 // If point event type is up, should reset start move flag
3378 if (WindowHelper::IsMainFloatingWindow(GetType(), GetMode()) || GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE ||
3379 (action == MMI::PointerEvent::POINTER_ACTION_UP || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP ||
3380 action == MMI::PointerEvent::POINTER_ACTION_CANCEL)) {
3381 ConsumeMoveOrDragEvent(pointerEvent);
3382 }
3383
3384 if (IsPointerEventConsumed()) {
3385 pointerEvent->MarkProcessed();
3386 return;
3387 }
3388
3389 TransferPointerEvent(pointerEvent);
3390 }
3391
RequestVsync(const std::shared_ptr<VsyncCallback> & vsyncCallback)3392 void WindowImpl::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
3393 {
3394 std::lock_guard<std::recursive_mutex> lock(mutex_);
3395 if (state_ == WindowState::STATE_DESTROYED) {
3396 WLOGFE("[WM] Receive Vsync Request failed, window is destroyed");
3397 return;
3398 }
3399
3400 if (!SingletonContainer::IsDestroyed() && vsyncStation_ != nullptr) {
3401 vsyncStation_->RequestVsync(vsyncCallback);
3402 }
3403 }
3404
GetVSyncPeriod()3405 int64_t WindowImpl::GetVSyncPeriod()
3406 {
3407 std::lock_guard<std::recursive_mutex> lock(mutex_);
3408 if (!SingletonContainer::IsDestroyed() && vsyncStation_ != nullptr) {
3409 return vsyncStation_->GetVSyncPeriod();
3410 }
3411 return 0;
3412 }
3413
UpdateFocusStatus(bool focused)3414 void WindowImpl::UpdateFocusStatus(bool focused)
3415 {
3416 if (!IsWindowValid()) {
3417 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
3418 return;
3419 }
3420
3421 WLOGFD("IsFocused: %{public}d, id: %{public}u", focused, property_->GetWindowId());
3422 isFocused_ = focused;
3423 if (focused) {
3424 HiSysEventWrite(
3425 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
3426 "FOCUS_WINDOW",
3427 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
3428 "PID", getpid(),
3429 "UID", getuid(),
3430 "BUNDLE_NAME", property_->GetAbilityInfo().bundleName_);
3431 if (state_ <= WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
3432 needNotifyFocusLater_ = true;
3433 return;
3434 }
3435 NotifyAfterFocused();
3436 } else {
3437 NotifyAfterUnfocused();
3438 }
3439 }
3440
IsFocused() const3441 bool WindowImpl::IsFocused() const
3442 {
3443 if (!IsWindowValid()) {
3444 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
3445 return false;
3446 }
3447
3448 return isFocused_;
3449 }
3450
UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration> & configuration)3451 void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
3452 {
3453 if (uiContent_ != nullptr) {
3454 WLOGFD("notify ace winId:%{public}u", GetWindowId());
3455 uiContent_->UpdateConfiguration(configuration);
3456 }
3457 if (subWindowMap_.count(GetWindowId()) == 0) {
3458 return;
3459 }
3460 for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
3461 subWindow->UpdateConfiguration(configuration);
3462 }
3463 }
3464
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)3465 void WindowImpl::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
3466 {
3467 WLOGI("Update AvoidArea, id: %{public}u", property_->GetWindowId());
3468 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3469 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
3470 UpdateViewportConfig(GetRect(), display, WindowSizeChangeReason::AVOID_AREA_CHANGE, nullptr, {{type, *avoidArea}});
3471 NotifyAvoidAreaChange(avoidArea, type);
3472 }
3473
UpdateViewportConfig(const Rect & rect,const sptr<Display> & display,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction,const std::map<AvoidAreaType,AvoidArea> & avoidAreas)3474 void WindowImpl::UpdateViewportConfig(const Rect& rect, const sptr<Display>& display, WindowSizeChangeReason reason,
3475 const std::shared_ptr<RSTransaction>& rsTransaction,
3476 const std::map<AvoidAreaType, AvoidArea>& avoidAreas)
3477 {
3478 std::lock_guard<std::recursive_mutex> lock(mutex_);
3479 if (uiContent_ == nullptr) {
3480 return;
3481 }
3482 Ace::ViewportConfig config;
3483 config.SetSize(rect.width_, rect.height_);
3484 config.SetPosition(rect.posX_, rect.posY_);
3485 if (display) {
3486 config.SetDensity(display->GetVirtualPixelRatio());
3487 auto displayInfo = display->GetDisplayInfo();
3488 if (displayInfo != nullptr) {
3489 config.SetOrientation(static_cast<int32_t>(displayInfo->GetDisplayOrientation()));
3490 }
3491 }
3492 uiContent_->UpdateViewportConfig(config, reason, rsTransaction, avoidAreas);
3493 WLOGFD("Id:%{public}u, windowRect:[%{public}d, %{public}d, %{public}u, %{public}u]",
3494 property_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_);
3495 }
3496
UpdateDecorEnable(bool needNotify)3497 void WindowImpl::UpdateDecorEnable(bool needNotify)
3498 {
3499 WLOGFD("Start");
3500 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
3501 bool enable = windowSystemConfig_.isSystemDecorEnable_ &&
3502 WindowHelper::IsWindowModeSupported(windowSystemConfig_.decorWindowModeSupportType_, GetMode());
3503 WLOGFD("Decor enable: %{public}d", static_cast<int32_t>(enable));
3504 property_->SetDecorEnable(enable);
3505 } else {
3506 property_->SetDecorEnable(false);
3507 }
3508 if (needNotify) {
3509 if (uiContent_ != nullptr) {
3510 uiContent_->UpdateWindowMode(GetMode(), property_->GetDecorEnable());
3511 WLOGFD("Notify uiContent window mode change end");
3512 }
3513 NotifyModeChange(GetMode(), property_->GetDecorEnable());
3514 }
3515 }
3516
UpdateWindowStateUnfrozen()3517 void WindowImpl::UpdateWindowStateUnfrozen()
3518 {
3519 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
3520 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3521 WLOGFD("DoAbilityForeground KEYGUARD, id: %{public}u", GetWindowId());
3522 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityForeground(abilityContext->GetToken(),
3523 static_cast<uint32_t>(WindowStateChangeReason::KEYGUARD));
3524 } else if (state_ != WindowState::STATE_SHOWN) {
3525 state_ = WindowState::STATE_SHOWN;
3526 NotifyAfterForeground();
3527 }
3528 }
3529
UpdateWindowState(WindowState state)3530 void WindowImpl::UpdateWindowState(WindowState state)
3531 {
3532 WLOGFI("id: %{public}u, State to set:%{public}u", GetWindowId(), state);
3533 if (!IsWindowValid()) {
3534 return;
3535 }
3536 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
3537 switch (state) {
3538 case WindowState::STATE_FROZEN: {
3539 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3540 WLOGFD("DoAbilityBackground KEYGUARD, id: %{public}u", GetWindowId());
3541 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityBackground(abilityContext->GetToken(),
3542 static_cast<uint32_t>(WindowStateChangeReason::KEYGUARD));
3543 } else {
3544 state_ = WindowState::STATE_FROZEN;
3545 NotifyAfterBackground(false, true);
3546 }
3547 break;
3548 }
3549 case WindowState::STATE_UNFROZEN: {
3550 UpdateWindowStateUnfrozen();
3551 break;
3552 }
3553 case WindowState::STATE_SHOWN: {
3554 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3555 WLOGFD("WindowState::STATE_SHOWN, id: %{public}u", GetWindowId());
3556 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityForeground(abilityContext->GetToken(),
3557 static_cast<uint32_t>(WindowStateChangeReason::TOGGLING));
3558 } else {
3559 state_ = WindowState::STATE_SHOWN;
3560 NotifyAfterForeground();
3561 }
3562 break;
3563 }
3564 case WindowState::STATE_HIDDEN: {
3565 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW &&
3566 state_ == WindowState::STATE_SHOWN) {
3567 WLOGFD("WindowState: STATE_SHOWN, id: %{public}u", GetWindowId());
3568 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityBackground(abilityContext->GetToken(),
3569 static_cast<uint32_t>(WindowStateChangeReason::NORMAL));
3570 } else {
3571 Hide(static_cast<uint32_t>(WindowStateChangeReason::NORMAL), false);
3572 }
3573 break;
3574 }
3575 default: {
3576 WLOGFE("windowState to set is invalid");
3577 break;
3578 }
3579 }
3580 }
3581
UpdateWindowStateWhenShow()3582 WmErrorCode WindowImpl::UpdateWindowStateWhenShow()
3583 {
3584 state_ = WindowState::STATE_SHOWN;
3585 if (WindowHelper::IsMainWindow(property_->GetWindowType()) ||
3586 WindowHelper::IsSystemMainWindow(property_->GetWindowType())) {
3587 // update subwindow subWindowState_ and notify subwindow shown or not
3588 UpdateSubWindowStateAndNotify(GetWindowId());
3589 NotifyAfterForeground();
3590 } else if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
3591 subWindowState_ = WindowState::STATE_SHOWN;
3592 NotifyAfterForeground();
3593 } else {
3594 uint32_t parentId = property_->GetParentId();
3595 sptr<Window> parentWindow = FindWindowById(parentId);
3596 if (parentWindow == nullptr) {
3597 WLOGE("parent window is null");
3598 return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
3599 }
3600 if (parentWindow->GetWindowState() == WindowState::STATE_HIDDEN) {
3601 // not notify user shown and update subwindowState_
3602 subWindowState_ = WindowState::STATE_HIDDEN;
3603 } else if (parentWindow->GetWindowState() == WindowState::STATE_SHOWN) {
3604 NotifyAfterForeground();
3605 subWindowState_ = WindowState::STATE_SHOWN;
3606 }
3607 }
3608 if (needNotifyFocusLater_ && isFocused_) {
3609 UpdateFocusStatus(true);
3610 }
3611 return WmErrorCode::WM_OK;
3612 }
3613
UpdateWindowStateWhenHide()3614 WmErrorCode WindowImpl::UpdateWindowStateWhenHide()
3615 {
3616 state_ = WindowState::STATE_HIDDEN;
3617 if (WindowHelper::IsSystemMainWindow(property_->GetWindowType()) ||
3618 WindowHelper::IsMainWindow(property_->GetWindowType())) {
3619 // main window need to update subwindow subWindowState_ and notify subwindow shown or not
3620 UpdateSubWindowStateAndNotify(GetWindowId());
3621 NotifyAfterBackground();
3622 } else if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
3623 subWindowState_ = WindowState::STATE_HIDDEN;
3624 NotifyAfterBackground();
3625 } else {
3626 uint32_t parentId = property_->GetParentId();
3627 sptr<Window> parentWindow = FindWindowById(parentId);
3628 if (parentWindow == nullptr) {
3629 WLOGE("parent window is null");
3630 return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
3631 }
3632 if (subWindowState_ == WindowState::STATE_SHOWN) {
3633 NotifyAfterBackground();
3634 }
3635 subWindowState_ = WindowState::STATE_HIDDEN;
3636 }
3637 return WmErrorCode::WM_OK;
3638 }
3639
UpdateSubWindowStateAndNotify(uint32_t parentId)3640 WmErrorCode WindowImpl::UpdateSubWindowStateAndNotify(uint32_t parentId)
3641 {
3642 if (subWindowMap_.find(parentId) == subWindowMap_.end()) {
3643 WLOGFD("main window: %{public}u has no child node", parentId);
3644 return WmErrorCode::WM_OK;
3645 }
3646 std::vector<sptr<WindowImpl>> subWindows = subWindowMap_[parentId];
3647 if (subWindows.empty()) {
3648 WLOGFD("main window: %{public}u, its subWindowMap is empty", parentId);
3649 return WmErrorCode::WM_OK;
3650 }
3651 // when main window hide and subwindow whose state is shown should hide and notify user
3652 if (state_ == WindowState::STATE_HIDDEN) {
3653 for (auto subwindow : subWindows) {
3654 if (subwindow->GetWindowState() == WindowState::STATE_SHOWN &&
3655 subwindow->subWindowState_ == WindowState::STATE_SHOWN) {
3656 subwindow->NotifyAfterBackground();
3657 }
3658 subwindow->subWindowState_ = WindowState::STATE_HIDDEN;
3659 }
3660 // when main window show and subwindow whose state is shown should show and notify user
3661 } else if (state_ == WindowState::STATE_SHOWN) {
3662 for (auto subwindow : subWindows) {
3663 if (subwindow->GetWindowState() == WindowState::STATE_SHOWN &&
3664 subwindow->subWindowState_ == WindowState::STATE_HIDDEN) {
3665 subwindow->NotifyAfterForeground();
3666 subwindow->subWindowState_ = WindowState::STATE_SHOWN;
3667 } else {
3668 subwindow->subWindowState_ = WindowState::STATE_HIDDEN;
3669 }
3670 }
3671 }
3672 return WmErrorCode::WM_OK;
3673 }
3674
GetWindowProperty()3675 sptr<WindowProperty> WindowImpl::GetWindowProperty()
3676 {
3677 return property_;
3678 }
3679
RestoreSplitWindowMode(uint32_t mode)3680 void WindowImpl::RestoreSplitWindowMode(uint32_t mode)
3681 {
3682 if (!IsWindowValid()) {
3683 return;
3684 }
3685 auto windowMode = static_cast<WindowMode>(mode);
3686 if (windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) {
3687 UpdateMode(windowMode);
3688 }
3689 }
3690
UpdateDragEvent(const PointInfo & point,DragEvent event)3691 void WindowImpl::UpdateDragEvent(const PointInfo& point, DragEvent event)
3692 {
3693 NotifyDragEvent(point, event);
3694 }
3695
NotifyDragEvent(const PointInfo & point,DragEvent event)3696 void WindowImpl::NotifyDragEvent(const PointInfo& point, DragEvent event)
3697 {
3698 auto windowDragListeners = GetListeners<IWindowDragListener>();
3699 Rect rect = GetRect();
3700 for (auto& listener : windowDragListeners) {
3701 if (listener != nullptr) {
3702 listener->OnDrag(point.x - rect.posX_, point.y - rect.posY_, event);
3703 }
3704 }
3705 }
3706
UpdateDisplayId(DisplayId from,DisplayId to)3707 void WindowImpl::UpdateDisplayId(DisplayId from, DisplayId to)
3708 {
3709 WLOGFD("update displayId. win %{public}u", GetWindowId());
3710 NotifyDisplayMoveChange(from, to);
3711 property_->SetDisplayId(to);
3712 }
3713
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)3714 void WindowImpl::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info,
3715 const std::shared_ptr<RSTransaction>& rsTransaction)
3716 {
3717 WLOGFD("Update OccupiedArea, id: %{public}u", property_->GetWindowId());
3718 NotifyOccupiedAreaChange(info, rsTransaction);
3719 }
3720
UpdateActiveStatus(bool isActive)3721 void WindowImpl::UpdateActiveStatus(bool isActive)
3722 {
3723 WLOGFD("window active status: %{public}d, id: %{public}u", isActive, property_->GetWindowId());
3724 if (isActive) {
3725 NotifyAfterActive();
3726 } else {
3727 NotifyAfterInactive();
3728 }
3729 }
3730
NotifyScreenshot()3731 void WindowImpl::NotifyScreenshot()
3732 {
3733 auto screenshotListeners = GetListeners<IScreenshotListener>();
3734 for (auto& screenshotListener : screenshotListeners) {
3735 if (screenshotListener != nullptr) {
3736 screenshotListener->OnScreenshot();
3737 }
3738 }
3739 }
3740
NotifyTouchOutside()3741 void WindowImpl::NotifyTouchOutside()
3742 {
3743 auto touchOutsideListeners = GetListeners<ITouchOutsideListener>();
3744 for (auto& touchOutsideListener : touchOutsideListeners) {
3745 if (touchOutsideListener != nullptr) {
3746 touchOutsideListener->OnTouchOutside();
3747 }
3748 }
3749 }
3750
NotifyTouchDialogTarget(int32_t posX,int32_t posY)3751 void WindowImpl::NotifyTouchDialogTarget(int32_t posX, int32_t posY)
3752 {
3753 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId());
3754 auto dialogTargetTouchListeners = GetListeners<IDialogTargetTouchListener>();
3755 for (auto& dialogTargetTouchListener : dialogTargetTouchListeners) {
3756 if (dialogTargetTouchListener != nullptr) {
3757 dialogTargetTouchListener->OnDialogTargetTouch();
3758 }
3759 }
3760 }
3761
NotifyDestroy()3762 void WindowImpl::NotifyDestroy()
3763 {
3764 auto dialogDeathRecipientListener = GetListener<IDialogDeathRecipientListener>();
3765 if (dialogDeathRecipientListener != nullptr) {
3766 dialogDeathRecipientListener->OnDialogDeathRecipient();
3767 }
3768 }
3769
NotifyForeground()3770 void WindowImpl::NotifyForeground()
3771 {
3772 NotifyAfterForeground();
3773 }
3774
NotifyBackground()3775 void WindowImpl::NotifyBackground()
3776 {
3777 NotifyAfterBackground();
3778 }
3779
NotifyForegroundInteractiveStatus(bool interactive)3780 void WindowImpl::NotifyForegroundInteractiveStatus(bool interactive)
3781 {
3782 WLOGFI("NotifyForegroundInteractiveStatus %{public}d", interactive);
3783 if (!IsWindowValid() || state_ != WindowState::STATE_SHOWN) {
3784 return;
3785 }
3786 if (interactive) {
3787 NotifyAfterResumed();
3788 } else {
3789 NotifyAfterPaused();
3790 }
3791 }
3792
NotifyMMIServiceOnline(uint32_t winId)3793 void WindowImpl::NotifyMMIServiceOnline(uint32_t winId)
3794 {
3795 TLOGI(WmsLogTag::WMS_EVENT, "Id:%{public}u", winId);
3796 ResetInputWindow(winId);
3797 }
3798
TransformSurfaceNode(const Transform & trans)3799 void WindowImpl::TransformSurfaceNode(const Transform& trans)
3800 {
3801 if (surfaceNode_ == nullptr) {
3802 return;
3803 }
3804 surfaceNode_->SetPivotX(trans.pivotX_);
3805 surfaceNode_->SetPivotY(trans.pivotY_);
3806 surfaceNode_->SetScaleX(trans.scaleX_);
3807 surfaceNode_->SetScaleY(trans.scaleY_);
3808 surfaceNode_->SetTranslateX(trans.translateX_);
3809 surfaceNode_->SetTranslateY(trans.translateY_);
3810 surfaceNode_->SetTranslateZ(trans.translateZ_);
3811 surfaceNode_->SetRotationX(trans.rotationX_);
3812 surfaceNode_->SetRotationY(trans.rotationY_);
3813 surfaceNode_->SetRotation(trans.rotationZ_);
3814 }
3815
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)3816 void WindowImpl::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
3817 {
3818 WLOGFD("%{public}s zoomTrans, pivotX:%{public}f, pivotY:%{public}f, scaleX:%{public}f, scaleY:%{public}f"
3819 ", transX:%{public}f, transY:%{public}f, transZ:%{public}f, rotateX:%{public}f, rotateY:%{public}f "
3820 "rotateZ:%{public}f", property_->GetWindowName().c_str(), trans.pivotX_, trans.pivotY_, trans.scaleX_,
3821 trans.scaleY_, trans.translateX_, trans.translateY_, trans.translateZ_, trans.rotationX_,
3822 trans.rotationY_, trans.rotationZ_);
3823 property_->SetZoomTransform(trans);
3824 property_->SetDisplayZoomState(isDisplayZoomOn);
3825 }
3826
ClearListenersById(uint32_t winId)3827 void WindowImpl::ClearListenersById(uint32_t winId)
3828 {
3829 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
3830 ClearUselessListeners(screenshotListeners_, winId);
3831 ClearUselessListeners(touchOutsideListeners_, winId);
3832 ClearUselessListeners(dialogTargetTouchListeners_, winId);
3833 ClearUselessListeners(lifecycleListeners_, winId);
3834 ClearUselessListeners(windowChangeListeners_, winId);
3835 ClearUselessListeners(avoidAreaChangeListeners_, winId);
3836 ClearUselessListeners(occupiedAreaChangeListeners_, winId);
3837 ClearUselessListeners(dialogDeathRecipientListener_, winId);
3838 }
3839
NotifyAfterForeground(bool needNotifyListeners,bool needNotifyUiContent)3840 void WindowImpl::NotifyAfterForeground(bool needNotifyListeners, bool needNotifyUiContent)
3841 {
3842 if (needNotifyListeners) {
3843 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3844 CALL_LIFECYCLE_LISTENER(AfterForeground, lifecycleListeners);
3845 }
3846 if (needNotifyUiContent) {
3847 CALL_UI_CONTENT(Foreground);
3848 }
3849 }
3850
NotifyAfterBackground(bool needNotifyListeners,bool needNotifyUiContent)3851 void WindowImpl::NotifyAfterBackground(bool needNotifyListeners, bool needNotifyUiContent)
3852 {
3853 if (needNotifyListeners) {
3854 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3855 CALL_LIFECYCLE_LISTENER(AfterBackground, lifecycleListeners);
3856 }
3857 if (needNotifyUiContent) {
3858 CALL_UI_CONTENT(Background);
3859 }
3860 }
3861
NotifyAfterFocused()3862 void WindowImpl::NotifyAfterFocused()
3863 {
3864 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3865 CALL_LIFECYCLE_LISTENER(AfterFocused, lifecycleListeners);
3866 CALL_UI_CONTENT(Focus);
3867 }
3868
NotifyAfterUnfocused(bool needNotifyUiContent)3869 void WindowImpl::NotifyAfterUnfocused(bool needNotifyUiContent)
3870 {
3871 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3872 // use needNotifyUinContent to separate ui content callbacks
3873 CALL_LIFECYCLE_LISTENER(AfterUnfocused, lifecycleListeners);
3874 if (needNotifyUiContent) {
3875 CALL_UI_CONTENT(UnFocus);
3876 }
3877 }
3878
NotifyAfterResumed()3879 void WindowImpl::NotifyAfterResumed()
3880 {
3881 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3882 CALL_LIFECYCLE_LISTENER(AfterResumed, lifecycleListeners);
3883 }
3884
NotifyAfterPaused()3885 void WindowImpl::NotifyAfterPaused()
3886 {
3887 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3888 CALL_LIFECYCLE_LISTENER(AfterPaused, lifecycleListeners);
3889 }
3890
NotifyBeforeDestroy(std::string windowName)3891 void WindowImpl::NotifyBeforeDestroy(std::string windowName)
3892 {
3893 std::lock_guard<std::recursive_mutex> lock(mutex_);
3894 if (uiContent_ != nullptr) {
3895 auto uiContent = std::move(uiContent_);
3896 uiContent_ = nullptr;
3897 uiContent->Destroy();
3898 }
3899 if (notifyNativefunc_) {
3900 notifyNativefunc_(windowName);
3901 }
3902 }
3903
NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)3904 void WindowImpl::NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)
3905 {
3906 auto uiContent = window->GetUIContent();
3907 if (uiContent != nullptr) {
3908 uiContent->Destroy();
3909 }
3910 if (window->GetNativeDestroyCallback()) {
3911 window->GetNativeDestroyCallback()(window->GetWindowName());
3912 }
3913 }
3914
NotifyAfterActive()3915 void WindowImpl::NotifyAfterActive()
3916 {
3917 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3918 CALL_LIFECYCLE_LISTENER(AfterActive, lifecycleListeners);
3919 }
3920
NotifyAfterInactive()3921 void WindowImpl::NotifyAfterInactive()
3922 {
3923 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3924 CALL_LIFECYCLE_LISTENER(AfterInactive, lifecycleListeners);
3925 }
3926
NotifyForegroundFailed(WMError ret)3927 void WindowImpl::NotifyForegroundFailed(WMError ret)
3928 {
3929 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3930 CALL_LIFECYCLE_LISTENER_WITH_PARAM(ForegroundFailed, lifecycleListeners, static_cast<int32_t>(ret));
3931 }
3932
NotifyBackgroundFailed(WMError ret)3933 void WindowImpl::NotifyBackgroundFailed(WMError ret)
3934 {
3935 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3936 CALL_LIFECYCLE_LISTENER_WITH_PARAM(BackgroundFailed, lifecycleListeners, static_cast<int32_t>(ret));
3937 }
3938
IsStretchableReason(WindowSizeChangeReason reason)3939 bool WindowImpl::IsStretchableReason(WindowSizeChangeReason reason)
3940 {
3941 return reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END ||
3942 reason == WindowSizeChangeReason::DRAG_START || reason == WindowSizeChangeReason::RECOVER ||
3943 IsMoveToOrDragMove(reason) || reason == WindowSizeChangeReason::UNDEFINED;
3944 }
3945
NotifySizeChange(Rect rect,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)3946 void WindowImpl::NotifySizeChange(Rect rect, WindowSizeChangeReason reason,
3947 const std::shared_ptr<RSTransaction>& rsTransaction)
3948 {
3949 auto windowChangeListeners = GetListeners<IWindowChangeListener>();
3950 for (auto& listener : windowChangeListeners) {
3951 if (listener != nullptr) {
3952 listener->OnSizeChange(rect, reason, rsTransaction);
3953 }
3954 }
3955 }
3956
NotifyAvoidAreaChange(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)3957 void WindowImpl::NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
3958 {
3959 auto avoidAreaChangeListeners = GetListeners<IAvoidAreaChangedListener>();
3960 for (auto& listener : avoidAreaChangeListeners) {
3961 if (listener != nullptr) {
3962 listener->OnAvoidAreaChanged(*avoidArea, type);
3963 }
3964 }
3965 }
3966
NotifyDisplayMoveChange(DisplayId from,DisplayId to)3967 void WindowImpl::NotifyDisplayMoveChange(DisplayId from, DisplayId to)
3968 {
3969 auto displayMoveListeners = GetListeners<IDisplayMoveListener>();
3970 for (auto& listener : displayMoveListeners) {
3971 if (listener != nullptr) {
3972 listener->OnDisplayMove(from, to);
3973 }
3974 }
3975 }
3976
NotifyModeChange(WindowMode mode,bool hasDeco)3977 void WindowImpl::NotifyModeChange(WindowMode mode, bool hasDeco)
3978 {
3979 auto windowChangeListeners = GetListeners<IWindowChangeListener>();
3980 for (auto& listener : windowChangeListeners) {
3981 if (listener != nullptr) {
3982 listener->OnModeChange(mode, hasDeco);
3983 }
3984 }
3985 }
3986
NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)3987 void WindowImpl::NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo>& info,
3988 const std::shared_ptr<RSTransaction>& rsTransaction)
3989 {
3990 auto occupiedAreaChangeListeners = GetListeners<IOccupiedAreaChangeListener>();
3991 for (auto& listener : occupiedAreaChangeListeners) {
3992 if (listener != nullptr) {
3993 listener->OnSizeChange(info, rsTransaction);
3994 }
3995 }
3996 }
3997
SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel)3998 void WindowImpl::SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel)
3999 {
4000 needRemoveWindowInputChannel_ = needRemoveWindowInputChannel;
4001 }
4002
GetSystemAlarmWindowDefaultSize(Rect defaultRect)4003 Rect WindowImpl::GetSystemAlarmWindowDefaultSize(Rect defaultRect)
4004 {
4005 auto display = SingletonContainer::IsDestroyed() ? nullptr :
4006 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
4007 if (display == nullptr) {
4008 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
4009 property_->GetWindowId());
4010 return defaultRect;
4011 }
4012 uint32_t width = static_cast<uint32_t>(display->GetWidth());
4013 uint32_t height = static_cast<uint32_t>(display->GetHeight());
4014 WLOGFD("width:%{public}u, height:%{public}u, displayId:%{public}" PRIu64"",
4015 width, height, property_->GetDisplayId());
4016 uint32_t alarmWidth = static_cast<uint32_t>((static_cast<float>(width) *
4017 SYSTEM_ALARM_WINDOW_WIDTH_RATIO));
4018 uint32_t alarmHeight = static_cast<uint32_t>((static_cast<float>(height) *
4019 SYSTEM_ALARM_WINDOW_HEIGHT_RATIO));
4020
4021 Rect rect = { static_cast<int32_t>((width - alarmWidth) / 2), static_cast<int32_t>((height - alarmHeight) / 2),
4022 alarmWidth, alarmHeight }; // divided by 2 to middle the window
4023 return rect;
4024 }
4025
SetDefaultOption()4026 void WindowImpl::SetDefaultOption()
4027 {
4028 switch (property_->GetWindowType()) {
4029 case WindowType::WINDOW_TYPE_STATUS_BAR:
4030 case WindowType::WINDOW_TYPE_NAVIGATION_BAR:
4031 case WindowType::WINDOW_TYPE_VOLUME_OVERLAY:
4032 case WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT:
4033 case WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR: {
4034 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4035 property_->SetFocusable(false);
4036 break;
4037 }
4038 case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: {
4039 property_->SetRequestRect(GetSystemAlarmWindowDefaultSize(property_->GetRequestRect()));
4040 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4041 break;
4042 }
4043 case WindowType::WINDOW_TYPE_KEYGUARD: {
4044 RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
4045 property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
4046 break;
4047 }
4048 case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: {
4049 property_->SetWindowFlags(0);
4050 break;
4051 }
4052 case WindowType::WINDOW_TYPE_APP_COMPONENT: {
4053 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4054 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::NONE));
4055 break;
4056 }
4057 case WindowType::WINDOW_TYPE_TOAST:
4058 case WindowType::WINDOW_TYPE_FLOAT:
4059 case WindowType::WINDOW_TYPE_SYSTEM_FLOAT:
4060 case WindowType::WINDOW_TYPE_FLOAT_CAMERA:
4061 case WindowType::WINDOW_TYPE_VOICE_INTERACTION:
4062 case WindowType::WINDOW_TYPE_LAUNCHER_DOCK:
4063 case WindowType::WINDOW_TYPE_SEARCHING_BAR:
4064 case WindowType::WINDOW_TYPE_SCREENSHOT:
4065 case WindowType::WINDOW_TYPE_GLOBAL_SEARCH:
4066 case WindowType::WINDOW_TYPE_DIALOG: {
4067 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4068 break;
4069 }
4070 case WindowType::WINDOW_TYPE_BOOT_ANIMATION:
4071 case WindowType::WINDOW_TYPE_POINTER: {
4072 property_->SetFocusable(false);
4073 break;
4074 }
4075 case WindowType::WINDOW_TYPE_DOCK_SLICE: {
4076 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4077 property_->SetFocusable(false);
4078 break;
4079 }
4080 case WindowType::WINDOW_TYPE_SYSTEM_TOAST: {
4081 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4082 property_->SetTouchable(false);
4083 property_->SetFocusable(false);
4084 break;
4085 }
4086 default:
4087 break;
4088 }
4089 }
4090
IsWindowValid() const4091 bool WindowImpl::IsWindowValid() const
4092 {
4093 bool res = ((state_ > WindowState::STATE_INITIAL) && (state_ < WindowState::STATE_BOTTOM));
4094 if (!res) {
4095 WLOGW("already destroyed or not created! id: %{public}u", GetWindowId());
4096 }
4097 return res;
4098 }
4099
IsLayoutFullScreen() const4100 bool WindowImpl::IsLayoutFullScreen() const
4101 {
4102 if (!IsWindowValid()) {
4103 return false;
4104 }
4105 auto mode = GetMode();
4106 return (mode == WindowMode::WINDOW_MODE_FULLSCREEN && isIgnoreSafeArea_);
4107 }
4108
IsFullScreen() const4109 bool WindowImpl::IsFullScreen() const
4110 {
4111 if (!IsWindowValid()) {
4112 return false;
4113 }
4114 auto statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
4115 auto naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
4116 return (IsLayoutFullScreen() && !statusProperty.enable_ && !naviProperty.enable_);
4117 }
4118
SetRequestedOrientation(Orientation orientation)4119 void WindowImpl::SetRequestedOrientation(Orientation orientation)
4120 {
4121 if (!IsWindowValid()) {
4122 TLOGE(WmsLogTag::DEFAULT, "window is invalid");
4123 return;
4124 }
4125 if (property_->GetRequestedOrientation() == orientation) {
4126 return;
4127 }
4128 property_->SetRequestedOrientation(orientation);
4129 if (state_ == WindowState::STATE_SHOWN) {
4130 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ORIENTATION);
4131 }
4132 }
4133
GetRequestedOrientation()4134 Orientation WindowImpl::GetRequestedOrientation()
4135 {
4136 if (!IsWindowValid()) {
4137 TLOGE(WmsLogTag::DEFAULT, "window is invalid");
4138 return Orientation::UNSPECIFIED;
4139 }
4140 return property_->GetRequestedOrientation();
4141 }
4142
SetTouchHotAreas(const std::vector<Rect> & rects)4143 WMError WindowImpl::SetTouchHotAreas(const std::vector<Rect>& rects)
4144 {
4145 std::vector<Rect> lastTouchHotAreas;
4146 property_->GetTouchHotAreas(lastTouchHotAreas);
4147
4148 property_->SetTouchHotAreas(rects);
4149 WMError result = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
4150 if (result != WMError::WM_OK) {
4151 property_->SetTouchHotAreas(lastTouchHotAreas);
4152 }
4153 return result;
4154 }
4155
GetRequestedTouchHotAreas(std::vector<Rect> & rects) const4156 void WindowImpl::GetRequestedTouchHotAreas(std::vector<Rect>& rects) const
4157 {
4158 property_->GetTouchHotAreas(rects);
4159 }
4160
SetAPPWindowLabel(const std::string & label)4161 WMError WindowImpl::SetAPPWindowLabel(const std::string& label)
4162 {
4163 if (uiContent_ == nullptr) {
4164 WLOGFE("uicontent is empty");
4165 return WMError::WM_ERROR_NULLPTR;
4166 }
4167 uiContent_->SetAppWindowTitle(label);
4168 WLOGI("Set app window label success, label : %{public}s", label.c_str());
4169 return WMError::WM_OK;
4170 }
4171
SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap> & icon)4172 WMError WindowImpl::SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon)
4173 {
4174 if (icon == nullptr) {
4175 WLOGFE("window icon is empty");
4176 return WMError::WM_ERROR_NULLPTR;
4177 }
4178 if (uiContent_ == nullptr) {
4179 WLOGFE("uicontent is empty");
4180 return WMError::WM_ERROR_NULLPTR;
4181 }
4182 uiContent_->SetAppWindowIcon(icon);
4183 WLOGI("Set app window icon success");
4184 return WMError::WM_OK;
4185 }
4186
CheckCameraFloatingWindowMultiCreated(WindowType type)4187 bool WindowImpl::CheckCameraFloatingWindowMultiCreated(WindowType type)
4188 {
4189 if (type != WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
4190 return false;
4191 }
4192
4193 for (auto& winPair : windowMap_) {
4194 if (winPair.second.second->GetType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
4195 return true;
4196 }
4197 }
4198 uint32_t accessTokenId = static_cast<uint32_t>(IPCSkeleton::GetCallingTokenID());
4199 property_->SetAccessTokenId(accessTokenId);
4200 TLOGI(WmsLogTag::DEFAULT, "Create camera float window, TokenId = %{private}u", accessTokenId);
4201 return false;
4202 }
4203
SetCornerRadius(float cornerRadius)4204 WMError WindowImpl::SetCornerRadius(float cornerRadius)
4205 {
4206 WLOGI("Window %{public}s set corner radius %{public}f", name_.c_str(), cornerRadius);
4207 surfaceNode_->SetCornerRadius(cornerRadius);
4208 RSTransaction::FlushImplicitTransaction();
4209 return WMError::WM_OK;
4210 }
4211
SetShadowRadius(float radius)4212 WMError WindowImpl::SetShadowRadius(float radius)
4213 {
4214 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4215 WLOGFE("set shadow radius permission denied!");
4216 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4217 }
4218 WLOGI("Window %{public}s set shadow radius %{public}f", name_.c_str(), radius);
4219 if (MathHelper::LessNotEqual(radius, 0.0)) {
4220 return WMError::WM_ERROR_INVALID_PARAM;
4221 }
4222 surfaceNode_->SetShadowRadius(radius);
4223 RSTransaction::FlushImplicitTransaction();
4224 return WMError::WM_OK;
4225 }
4226
SetShadowColor(std::string color)4227 WMError WindowImpl::SetShadowColor(std::string color)
4228 {
4229 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4230 WLOGFE("set shadow color permission denied!");
4231 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4232 }
4233 WLOGI("Window %{public}s set shadow color %{public}s", name_.c_str(), color.c_str());
4234 uint32_t colorValue;
4235 if (!ColorParser::Parse(color, colorValue)) {
4236 return WMError::WM_ERROR_INVALID_PARAM;
4237 }
4238 surfaceNode_->SetShadowColor(colorValue);
4239 RSTransaction::FlushImplicitTransaction();
4240 return WMError::WM_OK;
4241 }
4242
SetShadowOffsetX(float offsetX)4243 WMError WindowImpl::SetShadowOffsetX(float offsetX)
4244 {
4245 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4246 WLOGFE("set shadow offset x permission denied!");
4247 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4248 }
4249 WLOGI("Window %{public}s set shadow offsetX %{public}f", name_.c_str(), offsetX);
4250 surfaceNode_->SetShadowOffsetX(offsetX);
4251 RSTransaction::FlushImplicitTransaction();
4252 return WMError::WM_OK;
4253 }
4254
SetShadowOffsetY(float offsetY)4255 WMError WindowImpl::SetShadowOffsetY(float offsetY)
4256 {
4257 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4258 WLOGFE("set shadow offset y permission denied!");
4259 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4260 }
4261 WLOGI("Window %{public}s set shadow offsetY %{public}f", name_.c_str(), offsetY);
4262 surfaceNode_->SetShadowOffsetY(offsetY);
4263 RSTransaction::FlushImplicitTransaction();
4264 return WMError::WM_OK;
4265 }
4266
SetBlur(float radius)4267 WMError WindowImpl::SetBlur(float radius)
4268 {
4269 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4270 WLOGFE("set blur permission denied!");
4271 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4272 }
4273 WLOGI("Window %{public}s set blur radius %{public}f", name_.c_str(), radius);
4274 if (MathHelper::LessNotEqual(radius, 0.0)) {
4275 return WMError::WM_ERROR_INVALID_PARAM;
4276 }
4277 radius = ConvertRadiusToSigma(radius);
4278 WLOGFI("[Client] Window %{public}s set blur radius after conversion %{public}f", name_.c_str(), radius);
4279 surfaceNode_->SetFilter(RSFilter::CreateBlurFilter(radius, radius));
4280 RSTransaction::FlushImplicitTransaction();
4281 return WMError::WM_OK;
4282 }
4283
SetBackdropBlur(float radius)4284 WMError WindowImpl::SetBackdropBlur(float radius)
4285 {
4286 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4287 WLOGFE("set backdrop blur permission denied!");
4288 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4289 }
4290 WLOGI("Window %{public}s set backdrop blur radius %{public}f", name_.c_str(), radius);
4291 if (MathHelper::LessNotEqual(radius, 0.0)) {
4292 return WMError::WM_ERROR_INVALID_PARAM;
4293 }
4294 radius = ConvertRadiusToSigma(radius);
4295 WLOGFI("[Client] Window %{public}s set backdrop blur radius after conversion %{public}f", name_.c_str(), radius);
4296 surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(radius, radius));
4297 RSTransaction::FlushImplicitTransaction();
4298 return WMError::WM_OK;
4299 }
4300
SetBackdropBlurStyle(WindowBlurStyle blurStyle)4301 WMError WindowImpl::SetBackdropBlurStyle(WindowBlurStyle blurStyle)
4302 {
4303 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4304 WLOGFE("set backdrop blur style permission denied!");
4305 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4306 }
4307 WLOGI("Window %{public}s set backdrop blur style %{public}u", name_.c_str(), blurStyle);
4308 if (blurStyle < WindowBlurStyle::WINDOW_BLUR_OFF || blurStyle > WindowBlurStyle::WINDOW_BLUR_THICK) {
4309 return WMError::WM_ERROR_INVALID_PARAM;
4310 }
4311
4312 if (blurStyle == WindowBlurStyle::WINDOW_BLUR_OFF) {
4313 surfaceNode_->SetBackgroundFilter(nullptr);
4314 } else {
4315 auto display = SingletonContainer::IsDestroyed() ? nullptr :
4316 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
4317 if (display == nullptr) {
4318 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
4319 property_->GetWindowId());
4320 return WMError::WM_ERROR_INVALID_PARAM;
4321 }
4322 surfaceNode_->SetBackgroundFilter(RSFilter::CreateMaterialFilter(static_cast<int>(blurStyle),
4323 display->GetVirtualPixelRatio()));
4324 }
4325 RSTransaction::FlushImplicitTransaction();
4326 return WMError::WM_OK;
4327 }
4328
NotifyMemoryLevel(int32_t level)4329 WMError WindowImpl::NotifyMemoryLevel(int32_t level)
4330 {
4331 WLOGFD("id: %{public}u, notify memory level: %{public}d", property_->GetWindowId(), level);
4332 std::lock_guard<std::recursive_mutex> lock(mutex_);
4333 if (uiContent_ == nullptr) {
4334 WLOGFE("Window %{public}s notify memory level failed, ace is null.", name_.c_str());
4335 return WMError::WM_ERROR_NULLPTR;
4336 }
4337 // notify memory level
4338 uiContent_->NotifyMemoryLevel(level);
4339 return WMError::WM_OK;
4340 }
4341
IsAllowHaveSystemSubWindow()4342 bool WindowImpl::IsAllowHaveSystemSubWindow()
4343 {
4344 auto windowType = property_->GetWindowType();
4345 if (WindowHelper::IsSystemSubWindow(windowType) ||
4346 WindowHelper::IsSubWindow(windowType) ||
4347 windowType == WindowType::WINDOW_TYPE_DIALOG) {
4348 WLOGI("type %{public}u not allowed to add subwindow", windowType);
4349 return false;
4350 }
4351 return true;
4352 }
4353
SetNeedDefaultAnimation(bool needDefaultAnimation)4354 void WindowImpl::SetNeedDefaultAnimation(bool needDefaultAnimation)
4355 {
4356 needDefaultAnimation_= needDefaultAnimation;
4357 }
4358
SetTextFieldAvoidInfo(double textFieldPositionY,double textFieldHeight)4359 WMError WindowImpl::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight)
4360 {
4361 property_->SetTextFieldPositionY(textFieldPositionY);
4362 property_->SetTextFieldHeight(textFieldHeight);
4363 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO);
4364 return WMError::WM_OK;
4365 }
4366 } // namespace Rosen
4367 } // namespace OHOS
4368