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
DestroyDialogWindow()1469 void WindowImpl::DestroyDialogWindow()
1470 {
1471 // remove from appDialogWindowMap_
1472 for (auto& dialogWindows: appDialogWindowMap_) {
1473 for (auto iter = dialogWindows.second.begin(); iter != dialogWindows.second.end(); ++iter) {
1474 if ((*iter) == nullptr) {
1475 continue;
1476 }
1477 if ((*iter)->GetWindowId() == GetWindowId()) {
1478 dialogWindows.second.erase(iter);
1479 break;
1480 }
1481 }
1482 }
1483
1484 // Destroy app dialog window if exist
1485 if (appDialogWindowMap_.count(GetWindowId()) > 0) {
1486 auto& dialogWindows = appDialogWindowMap_.at(GetWindowId());
1487 for (auto iter = dialogWindows.begin(); iter != dialogWindows.end(); iter = dialogWindows.begin()) {
1488 if ((*iter) == nullptr) {
1489 dialogWindows.erase(iter);
1490 continue;
1491 }
1492 (*iter)->Destroy(false);
1493 }
1494 appDialogWindowMap_.erase(GetWindowId());
1495 }
1496 }
1497
DestroyFloatingWindow()1498 void WindowImpl::DestroyFloatingWindow()
1499 {
1500 // remove from appFloatingWindowMap_
1501 TLOGI(WmsLogTag::WMS_LIFE, "Remove from appFloatingWindowMap_");
1502 for (auto& floatingWindows: appFloatingWindowMap_) {
1503 for (auto iter = floatingWindows.second.begin(); iter != floatingWindows.second.end(); ++iter) {
1504 if ((*iter) == nullptr) {
1505 continue;
1506 }
1507 if ((*iter)->GetWindowId() == GetWindowId()) {
1508 floatingWindows.second.erase(iter);
1509 break;
1510 }
1511 }
1512 }
1513
1514 // Destroy app floating window if exist
1515 TLOGI(WmsLogTag::WMS_LIFE, "Destroy app floating window if exist");
1516 if (appFloatingWindowMap_.count(GetWindowId()) > 0) {
1517 auto& floatingWindows = appFloatingWindowMap_.at(GetWindowId());
1518 for (auto iter = floatingWindows.begin(); iter != floatingWindows.end(); iter = floatingWindows.begin()) {
1519 if ((*iter) == nullptr) {
1520 floatingWindows.erase(iter);
1521 continue;
1522 }
1523 (*iter)->Destroy();
1524 }
1525 appFloatingWindowMap_.erase(GetWindowId());
1526 }
1527 }
1528
DestroySubWindow()1529 void WindowImpl::DestroySubWindow()
1530 {
1531 if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_
1532 auto& subWindows = subWindowMap_.at(property_->GetParentId());
1533 for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) {
1534 if ((*iter) == nullptr) {
1535 continue;
1536 }
1537 if ((*iter)->GetWindowId() == GetWindowId()) {
1538 subWindows.erase(iter);
1539 break;
1540 }
1541 }
1542 }
1543
1544 if (subWindowMap_.count(GetWindowId()) > 0) { // remove from subWindowMap_ and windowMap_
1545 auto& subWindows = subWindowMap_.at(GetWindowId());
1546 for (auto iter = subWindows.begin(); iter != subWindows.end(); iter = subWindows.begin()) {
1547 if ((*iter) == nullptr) {
1548 subWindows.erase(iter);
1549 continue;
1550 }
1551 (*iter)->Destroy(false);
1552 }
1553 subWindowMap_[GetWindowId()].clear();
1554 subWindowMap_.erase(GetWindowId());
1555 }
1556 }
1557
ClearVsyncStation()1558 void WindowImpl::ClearVsyncStation()
1559 {
1560 std::lock_guard<std::recursive_mutex> lock(mutex_);
1561 if (vsyncStation_ != nullptr) {
1562 vsyncStation_.reset();
1563 }
1564 }
1565
Destroy()1566 WMError WindowImpl::Destroy()
1567 {
1568 return Destroy(true);
1569 }
1570
Destroy(bool needNotifyServer,bool needClearListener)1571 WMError WindowImpl::Destroy(bool needNotifyServer, bool needClearListener)
1572 {
1573 if (!IsWindowValid()) {
1574 return WMError::WM_OK;
1575 }
1576
1577 WLOGI("Window %{public}u Destroy", property_->GetWindowId());
1578 WMError ret = WMError::WM_OK;
1579 if (needNotifyServer) {
1580 NotifyBeforeDestroy(GetWindowName());
1581 if (subWindowMap_.count(GetWindowId()) > 0) {
1582 for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
1583 NotifyBeforeSubWindowDestroy(subWindow);
1584 }
1585 }
1586 ret = SingletonContainer::Get<WindowAdapter>().DestroyWindow(property_->GetWindowId());
1587 RecordLifeCycleExceptionEvent(LifeCycleEvent::DESTROY_EVENT, ret);
1588 if (ret != WMError::WM_OK) {
1589 WLOGFE("destroy window failed with errCode:%{public}d", static_cast<int32_t>(ret));
1590 if (GetType() != WindowType::WINDOW_TYPE_DIALOG) {
1591 return ret;
1592 }
1593 }
1594 } else {
1595 WLOGI("no need to destroy");
1596 }
1597
1598 if (needRemoveWindowInputChannel_) {
1599 InputTransferStation::GetInstance().RemoveInputWindow(property_->GetWindowId());
1600 }
1601 windowMap_.erase(GetWindowName());
1602 if (needClearListener) {
1603 ClearListenersById(GetWindowId());
1604 }
1605 DestroySubWindow();
1606 DestroyFloatingWindow();
1607 DestroyDialogWindow();
1608 ClearVsyncStation();
1609 {
1610 std::lock_guard<std::recursive_mutex> lock(mutex_);
1611 state_ = WindowState::STATE_DESTROYED;
1612 }
1613 return ret;
1614 }
1615
NeedToStopShowing()1616 bool WindowImpl::NeedToStopShowing()
1617 {
1618 if (!WindowHelper::IsMainWindow(property_->GetWindowType())) {
1619 return false;
1620 }
1621 // show failed when current mode is not support or window only supports split mode and can show when locked
1622 bool isShowWhenLocked = GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
1623 if (!WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), GetMode()) ||
1624 WindowHelper::IsOnlySupportSplitAndShowWhenLocked(isShowWhenLocked, GetWindowModeSupportType())) {
1625 WLOGFE("current mode is not supported, windowId: %{public}u, "
1626 "windowModeSupportType: %{public}u, winMode: %{public}u",
1627 property_->GetWindowId(), GetWindowModeSupportType(), GetMode());
1628 return true;
1629 }
1630 return false;
1631 }
1632
UpdateSurfaceNodeAfterCustomAnimation(bool isAdd)1633 WMError WindowImpl::UpdateSurfaceNodeAfterCustomAnimation(bool isAdd)
1634 {
1635 WLOGI("id: %{public}u UpdateRsTree, isAdd:%{public}u",
1636 property_->GetWindowId(), isAdd);
1637 if (!IsWindowValid()) {
1638 return WMError::WM_ERROR_INVALID_WINDOW;
1639 }
1640 if (!WindowHelper::IsSystemWindow(property_->GetWindowType())) {
1641 WLOGFE("only system window can set");
1642 return WMError::WM_ERROR_INVALID_OPERATION;
1643 }
1644 AdjustWindowAnimationFlag(false); // false means update rs tree with default option
1645 // need time out check
1646 WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1647 if (ret != WMError::WM_OK) {
1648 WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast<int32_t>(ret));
1649 return ret;
1650 }
1651 ret = SingletonContainer::Get<WindowAdapter>().UpdateRsTree(property_->GetWindowId(), isAdd);
1652 if (ret != WMError::WM_OK) {
1653 WLOGFE("UpdateRsTree failed with errCode:%{public}d", static_cast<int32_t>(ret));
1654 return ret;
1655 }
1656 return WMError::WM_OK;
1657 }
1658
AdjustWindowAnimationFlag(bool withAnimation)1659 void WindowImpl::AdjustWindowAnimationFlag(bool withAnimation)
1660 {
1661 // when show/hide with animation
1662 // use custom animation when transitionController exists; else use default animation
1663 WindowType winType = property_->GetWindowType();
1664 bool isAppWindow = WindowHelper::IsAppWindow(winType);
1665 if (withAnimation && !isAppWindow && animationTransitionController_) {
1666 // use custom animation
1667 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
1668 } else if ((isAppWindow && needDefaultAnimation_) || (withAnimation && !animationTransitionController_)) {
1669 // use default animation
1670 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::DEFAULT));
1671 } else if (winType == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
1672 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::INPUTE));
1673 } else {
1674 // with no animation
1675 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::NONE));
1676 }
1677 }
1678
PreProcessShow(uint32_t reason,bool withAnimation)1679 WMError WindowImpl::PreProcessShow(uint32_t reason, bool withAnimation)
1680 {
1681 if (state_ == WindowState::STATE_FROZEN) {
1682 WLOGFE("window is frozen, can not be shown, windowId: %{public}u", property_->GetWindowId());
1683 return WMError::WM_ERROR_INVALID_OPERATION;
1684 }
1685 SetDefaultOption();
1686 SetWindowModeSupportType(GetRequestWindowModeSupportType());
1687 AdjustWindowAnimationFlag(withAnimation);
1688
1689 if (NeedToStopShowing()) { // true means stop showing
1690 return WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE;
1691 }
1692
1693 // update title button visibility when show
1694 UpdateTitleButtonVisibility();
1695 return WMError::WM_OK;
1696 }
1697
Show(uint32_t reason,bool withAnimation,bool withFocus)1698 WMError WindowImpl::Show(uint32_t reason, bool withAnimation, bool withFocus)
1699 {
1700 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, __PRETTY_FUNCTION__);
1701 WLOGFD("Window Show [name:%{public}s, id:%{public}u, mode: %{public}u], reason:%{public}u, "
1702 "withAnimation:%{public}d", name_.c_str(), property_->GetWindowId(), GetMode(), reason, withAnimation);
1703 if (!IsWindowValid()) {
1704 return WMError::WM_ERROR_INVALID_WINDOW;
1705 }
1706 UpdateDecorEnable(true);
1707 if (static_cast<WindowStateChangeReason>(reason) == WindowStateChangeReason::KEYGUARD ||
1708 static_cast<WindowStateChangeReason>(reason) == WindowStateChangeReason::TOGGLING) {
1709 state_ = WindowState::STATE_SHOWN;
1710 NotifyAfterForeground();
1711 return WMError::WM_OK;
1712 }
1713 if (state_ == WindowState::STATE_SHOWN) {
1714 if (property_->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1715 SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(property_->GetDisplayId());
1716 } else {
1717 WLOGI("window is already shown id: %{public}u", property_->GetWindowId());
1718 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId(), false);
1719 }
1720 // when show sub window, check its parent state
1721 sptr<Window> parent = FindWindowById(property_->GetParentId());
1722 if (parent != nullptr && parent->GetWindowState() == WindowState::STATE_HIDDEN) {
1723 WLOGFD("sub window can not show, because main window hide");
1724 return WMError::WM_OK;
1725 } else {
1726 NotifyAfterForeground(true, false);
1727 }
1728 return WMError::WM_OK;
1729 }
1730 WMError ret = PreProcessShow(reason, withAnimation);
1731 if (ret != WMError::WM_OK) {
1732 NotifyForegroundFailed(ret);
1733 return ret;
1734 }
1735 // this lock solves the multithreading problem when reading WindowState
1736 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1737 ret = SingletonContainer::Get<WindowAdapter>().AddWindow(property_);
1738 RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret);
1739 if (ret == WMError::WM_OK) {
1740 UpdateWindowStateWhenShow();
1741 } else {
1742 NotifyForegroundFailed(ret);
1743 WLOGFE("show window id:%{public}u errCode:%{public}d", property_->GetWindowId(), static_cast<int32_t>(ret));
1744 }
1745 // systemui make startbar resident, when refactor immersive, this code can delete
1746 if (property_->GetRequestedOrientation() == Orientation::HORIZONTAL
1747 || property_->GetRequestedOrientation() == Orientation::REVERSE_HORIZONTAL) {
1748 RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
1749 }
1750 needNotifyFocusLater_ = false;
1751 return ret;
1752 }
1753
Hide(uint32_t reason,bool withAnimation,bool isFromInnerkits)1754 WMError WindowImpl::Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits)
1755 {
1756 WLOGD("id:%{public}u Hide, reason:%{public}u, Animation:%{public}d",
1757 property_->GetWindowId(), reason, withAnimation);
1758 if (!IsWindowValid()) {
1759 return WMError::WM_ERROR_INVALID_WINDOW;
1760 }
1761 WindowStateChangeReason stateChangeReason = static_cast<WindowStateChangeReason>(reason);
1762 if (stateChangeReason == WindowStateChangeReason::KEYGUARD ||
1763 stateChangeReason == WindowStateChangeReason::TOGGLING) {
1764 state_ = stateChangeReason == WindowStateChangeReason::KEYGUARD ?
1765 WindowState::STATE_FROZEN : WindowState::STATE_HIDDEN;
1766 NotifyAfterBackground();
1767 return WMError::WM_OK;
1768 }
1769 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1770 WLOGI("already hidden, id: %{public}u", property_->GetWindowId());
1771 NotifyBackgroundFailed(WMError::WM_DO_NOTHING);
1772 return WMError::WM_OK;
1773 }
1774 WMError ret = WMError::WM_OK;
1775 if (WindowHelper::IsSystemWindow(property_->GetWindowType())) {
1776 AdjustWindowAnimationFlag(withAnimation);
1777 // when show(true) with default, hide() with None, to adjust animationFlag to disabled default animation
1778 ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1779 if (ret != WMError::WM_OK) {
1780 WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast<int32_t>(ret));
1781 return ret;
1782 }
1783 }
1784 ret = SingletonContainer::Get<WindowAdapter>().RemoveWindow(property_->GetWindowId(), isFromInnerkits);
1785 RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret);
1786 if (ret != WMError::WM_OK) {
1787 WLOGFE("hide errCode:%{public}d for winId:%{public}u", static_cast<int32_t>(ret), property_->GetWindowId());
1788 return ret;
1789 }
1790 UpdateWindowStateWhenHide();
1791 uint32_t animationFlag = property_->GetAnimationFlag();
1792 if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
1793 animationTransitionController_->AnimationForHidden();
1794 }
1795 ResetMoveOrDragState();
1796 escKeyEventTriggered_ = false;
1797 return ret;
1798 }
1799
MoveTo(int32_t x,int32_t y,bool isMoveToGlobal)1800 WMError WindowImpl::MoveTo(int32_t x, int32_t y, bool isMoveToGlobal)
1801 {
1802 WLOGFD("id:%{public}d MoveTo %{public}d %{public}d",
1803 property_->GetWindowId(), x, y);
1804 if (!IsWindowValid()) {
1805 return WMError::WM_ERROR_INVALID_WINDOW;
1806 }
1807
1808 Rect rect = (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) ?
1809 GetRect() : property_->GetRequestRect();
1810 Rect moveRect = { x, y, rect.width_, rect.height_ }; // must keep w/h, which may maintain stashed resize info
1811 property_->SetRequestRect(moveRect);
1812 {
1813 // this lock solves the multithreading problem when reading WindowState
1814 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1815 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1816 WLOGFD("window is hidden or created! id: %{public}u, oriPos: [%{public}d, %{public}d, "
1817 "movePos: [%{public}d, %{public}d]", property_->GetWindowId(), rect.posX_, rect.posY_, x, y);
1818 return WMError::WM_OK;
1819 }
1820 }
1821
1822 if (GetMode() != WindowMode::WINDOW_MODE_FLOATING) {
1823 WLOGFE("fullscreen window could not moveto, winId: %{public}u", GetWindowId());
1824 return WMError::WM_ERROR_INVALID_OPERATION;
1825 }
1826 property_->SetWindowSizeChangeReason(WindowSizeChangeReason::MOVE);
1827 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_RECT);
1828 }
1829
Resize(uint32_t width,uint32_t height)1830 WMError WindowImpl::Resize(uint32_t width, uint32_t height)
1831 {
1832 WLOGFD("id:%{public}d Resize %{public}u %{public}u",
1833 property_->GetWindowId(), width, height);
1834 if (!IsWindowValid()) {
1835 return WMError::WM_ERROR_INVALID_WINDOW;
1836 }
1837
1838 Rect rect = (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) ?
1839 GetRect() : property_->GetRequestRect();
1840 Rect resizeRect = { rect.posX_, rect.posY_, width, height };
1841 property_->SetRequestRect(resizeRect);
1842 property_->SetDecoStatus(false);
1843 {
1844 // this lock solves the multithreading problem when reading WindowState
1845 std::lock_guard<std::recursive_mutex> lock(windowStateMutex_);
1846 if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
1847 WLOGFD("window is hidden or created! id: %{public}u, oriRect: [%{public}u, %{public}u], "
1848 "resizeRect: [%{public}u, %{public}u]", property_->GetWindowId(), rect.width_,
1849 rect.height_, width, height);
1850 return WMError::WM_OK;
1851 }
1852 }
1853
1854 if (GetMode() != WindowMode::WINDOW_MODE_FLOATING) {
1855 WLOGFE("fullscreen window could not resize, winId: %{public}u", GetWindowId());
1856 return WMError::WM_ERROR_INVALID_OPERATION;
1857 }
1858 property_->SetWindowSizeChangeReason(WindowSizeChangeReason::RESIZE);
1859 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_RECT);
1860 }
1861
SetWindowGravity(WindowGravity gravity,uint32_t percent)1862 WMError WindowImpl::SetWindowGravity(WindowGravity gravity, uint32_t percent)
1863 {
1864 WLOGFD("id:%{public}d SetWindowGravity %{public}u %{public}u",
1865 property_->GetWindowId(), gravity, percent);
1866
1867 return SingletonContainer::Get<WindowAdapter>().SetWindowGravity(property_->GetWindowId(), gravity, percent);
1868 }
1869
SetKeepScreenOn(bool keepScreenOn)1870 WMError WindowImpl::SetKeepScreenOn(bool keepScreenOn)
1871 {
1872 if (!IsWindowValid()) {
1873 return WMError::WM_ERROR_INVALID_WINDOW;
1874 }
1875 property_->SetKeepScreenOn(keepScreenOn);
1876 if (state_ == WindowState::STATE_SHOWN) {
1877 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
1878 }
1879 return WMError::WM_OK;
1880 }
1881
IsKeepScreenOn() const1882 bool WindowImpl::IsKeepScreenOn() const
1883 {
1884 if (!IsWindowValid()) {
1885 return false;
1886 }
1887 return property_->IsKeepScreenOn();
1888 }
1889
SetTurnScreenOn(bool turnScreenOn)1890 WMError WindowImpl::SetTurnScreenOn(bool turnScreenOn)
1891 {
1892 if (!IsWindowValid()) {
1893 return WMError::WM_ERROR_INVALID_WINDOW;
1894 }
1895 property_->SetTurnScreenOn(turnScreenOn);
1896 if (state_ == WindowState::STATE_SHOWN) {
1897 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1898 }
1899 return WMError::WM_OK;
1900 }
1901
IsTurnScreenOn() const1902 bool WindowImpl::IsTurnScreenOn() const
1903 {
1904 if (!IsWindowValid()) {
1905 return false;
1906 }
1907 return property_->IsTurnScreenOn();
1908 }
1909
SetBackgroundColor(uint32_t color)1910 WMError WindowImpl::SetBackgroundColor(uint32_t color)
1911 {
1912 // 0xff000000: ARGB style, means Opaque color.
1913 const bool isAlphaZero = !(color & 0xff000000);
1914 auto abilityInfo = property_->GetAbilityInfo();
1915 if (isAlphaZero && WindowHelper::IsMainWindow(property_->GetWindowType())) {
1916 auto& reportInstance = SingletonContainer::Get<WindowInfoReporter>();
1917 reportInstance.ReportZeroOpacityInfoImmediately(abilityInfo.bundleName_,
1918 abilityInfo.abilityName_);
1919 }
1920
1921 if (uiContent_ != nullptr) {
1922 uiContent_->SetBackgroundColor(color);
1923 return WMError::WM_OK;
1924 }
1925 WLOGI("ace is null, Id: %{public}u", GetWindowId());
1926 if (aceAbilityHandler_ != nullptr) {
1927 aceAbilityHandler_->SetBackgroundColor(color);
1928 return WMError::WM_OK;
1929 }
1930 WLOGFE("FA mode could not set bg color: %{public}u", GetWindowId());
1931 return WMError::WM_ERROR_INVALID_OPERATION;
1932 }
1933
GetBackgroundColor() const1934 uint32_t WindowImpl::GetBackgroundColor() const
1935 {
1936 if (uiContent_ != nullptr) {
1937 return uiContent_->GetBackgroundColor();
1938 }
1939 WLOGD("uiContent is nullptr, windowId: %{public}u, use FA mode", GetWindowId());
1940 if (aceAbilityHandler_ != nullptr) {
1941 return aceAbilityHandler_->GetBackgroundColor();
1942 }
1943 WLOGFE("FA mode does not get bg color: %{public}u", GetWindowId());
1944 return 0xffffffff; // means no background color been set, default color is white
1945 }
1946
SetBackgroundColor(const std::string & color)1947 WMError WindowImpl::SetBackgroundColor(const std::string& color)
1948 {
1949 if (!IsWindowValid()) {
1950 return WMError::WM_ERROR_INVALID_WINDOW;
1951 }
1952 uint32_t colorValue;
1953 if (ColorParser::Parse(color, colorValue)) {
1954 WLOGD("SetBackgroundColor: window: %{public}s, value: [%{public}s, %{public}u]",
1955 name_.c_str(), color.c_str(), colorValue);
1956 return SetBackgroundColor(colorValue);
1957 }
1958 WLOGFE("invalid color string: %{public}s", color.c_str());
1959 return WMError::WM_ERROR_INVALID_PARAM;
1960 }
1961
SetTransparent(bool isTransparent)1962 WMError WindowImpl::SetTransparent(bool isTransparent)
1963 {
1964 if (!IsWindowValid()) {
1965 return WMError::WM_ERROR_INVALID_WINDOW;
1966 }
1967 ColorParam backgroundColor;
1968 backgroundColor.value = GetBackgroundColor();
1969 if (isTransparent) {
1970 backgroundColor.argb.alpha = 0x00; // 0x00: completely transparent
1971 return SetBackgroundColor(backgroundColor.value);
1972 } else {
1973 backgroundColor.value = GetBackgroundColor();
1974 if (backgroundColor.argb.alpha == 0x00) {
1975 backgroundColor.argb.alpha = 0xff; // 0xff: completely opaque
1976 return SetBackgroundColor(backgroundColor.value);
1977 }
1978 }
1979 return WMError::WM_OK;
1980 }
1981
IsTransparent() const1982 bool WindowImpl::IsTransparent() const
1983 {
1984 if (!IsWindowValid()) {
1985 return false;
1986 }
1987 ColorParam backgroundColor;
1988 backgroundColor.value = GetBackgroundColor();
1989 WLOGFD("color: %{public}u, alpha: %{public}u", backgroundColor.value, backgroundColor.argb.alpha);
1990 return backgroundColor.argb.alpha == 0x00; // 0x00: completely transparent
1991 }
1992
SetBrightness(float brightness)1993 WMError WindowImpl::SetBrightness(float brightness)
1994 {
1995 if (!IsWindowValid()) {
1996 return WMError::WM_ERROR_INVALID_WINDOW;
1997 }
1998 if ((brightness < MINIMUM_BRIGHTNESS &&
1999 std::fabs(brightness - UNDEFINED_BRIGHTNESS) >= std::numeric_limits<float>::min()) ||
2000 brightness > MAXIMUM_BRIGHTNESS) {
2001 WLOGFE("invalid brightness value: %{public}f", brightness);
2002 return WMError::WM_ERROR_INVALID_PARAM;
2003 }
2004 if (!WindowHelper::IsAppWindow(GetType())) {
2005 WLOGFE("non app window does not support set brightness, type: %{public}u", GetType());
2006 return WMError::WM_ERROR_INVALID_TYPE;
2007 }
2008 property_->SetBrightness(brightness);
2009 if (state_ == WindowState::STATE_SHOWN) {
2010 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
2011 }
2012 return WMError::WM_OK;
2013 }
2014
GetBrightness() const2015 float WindowImpl::GetBrightness() const
2016 {
2017 return property_->GetBrightness();
2018 }
2019
SetCallingWindow(uint32_t windowId)2020 WMError WindowImpl::SetCallingWindow(uint32_t windowId)
2021 {
2022 if (!IsWindowValid()) {
2023 return WMError::WM_ERROR_INVALID_WINDOW;
2024 }
2025 property_->SetCallingWindow(windowId);
2026 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW);
2027 }
2028
RecordLifeCycleExceptionEvent(LifeCycleEvent event,WMError errCode) const2029 void WindowImpl::RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError errCode) const
2030 {
2031 if (!(errCode > WMError::WM_ERROR_NEED_REPORT_BASE && errCode < WMError::WM_ERROR_NEED_REPORT_END)) {
2032 return;
2033 }
2034 std::ostringstream oss;
2035 oss << "life cycle is abnormal: " << "window_name: " << name_
2036 << ", id:" << GetWindowId() << ", event: " << TransferLifeCycleEventToString(event)
2037 << ", errCode: " << static_cast<int32_t>(errCode) << ";";
2038 std::string info = oss.str();
2039 WLOGI("window life cycle exception: %{public}s", info.c_str());
2040 int32_t ret = HiSysEventWrite(
2041 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
2042 "WINDOW_LIFE_CYCLE_EXCEPTION",
2043 OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
2044 "PID", getpid(),
2045 "UID", getuid(),
2046 "MSG", info);
2047 if (ret != 0) {
2048 WLOGFE("Write HiSysEvent error, ret:%{public}d", ret);
2049 }
2050 }
2051
TransferLifeCycleEventToString(LifeCycleEvent type) const2052 std::string WindowImpl::TransferLifeCycleEventToString(LifeCycleEvent type) const
2053 {
2054 std::string event;
2055 switch (type) {
2056 case LifeCycleEvent::CREATE_EVENT:
2057 event = "CREATE";
2058 break;
2059 case LifeCycleEvent::SHOW_EVENT:
2060 event = "SHOW";
2061 break;
2062 case LifeCycleEvent::HIDE_EVENT:
2063 event = "HIDE";
2064 break;
2065 case LifeCycleEvent::DESTROY_EVENT:
2066 event = "DESTROY";
2067 break;
2068 default:
2069 event = "UNDEFINE";
2070 break;
2071 }
2072 return event;
2073 }
2074
SetPrivacyMode(bool isPrivacyMode)2075 WMError WindowImpl::SetPrivacyMode(bool isPrivacyMode)
2076 {
2077 if (!IsWindowValid()) {
2078 return WMError::WM_ERROR_INVALID_WINDOW;
2079 }
2080 WLOGFD("id : %{public}u, SetPrivacyMode, %{public}u", GetWindowId(), isPrivacyMode);
2081 property_->SetPrivacyMode(isPrivacyMode);
2082 return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
2083 }
2084
IsPrivacyMode() const2085 bool WindowImpl::IsPrivacyMode() const
2086 {
2087 if (!IsWindowValid()) {
2088 return false;
2089 }
2090 return property_->GetPrivacyMode();
2091 }
2092
SetSystemPrivacyMode(bool isSystemPrivacyMode)2093 void WindowImpl::SetSystemPrivacyMode(bool isSystemPrivacyMode)
2094 {
2095 WLOGFD("id : %{public}u, SetSystemPrivacyMode, %{public}u", GetWindowId(), isSystemPrivacyMode);
2096 property_->SetSystemPrivacyMode(isSystemPrivacyMode);
2097 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
2098 }
2099
SetSnapshotSkip(bool isSkip)2100 WMError WindowImpl::SetSnapshotSkip(bool isSkip)
2101 {
2102 if (!IsWindowValid()) {
2103 return WMError::WM_ERROR_INVALID_WINDOW;
2104 }
2105 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2106 WLOGFE("set snapshot skip permission denied!");
2107 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2108 }
2109 property_->SetSnapshotSkip(isSkip);
2110 auto ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP);
2111 WLOGFD("id : %{public}u, set snapshot skip end. isSkip:%{public}u, systemPrivacyMode:%{public}u, ret:%{public}u",
2112 GetWindowId(), isSkip, property_->GetSystemPrivacyMode(), ret);
2113 return WMError::WM_OK;
2114 }
2115
2116 /** @note @window.hierarchy */
RaiseToAppTop()2117 WMError WindowImpl::RaiseToAppTop()
2118 {
2119 if (!IsWindowValid()) {
2120 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
2121 return WMError::WM_ERROR_INVALID_WINDOW;
2122 }
2123
2124 auto parentId = property_->GetParentId();
2125 if (parentId == INVALID_WINDOW_ID) {
2126 WLOGFE("Only the children of the main window can be raised!");
2127 return WMError::WM_ERROR_INVALID_PARENT;
2128 }
2129
2130 if (!WindowHelper::IsSubWindow(property_->GetWindowType())) {
2131 WLOGFE("Must be app sub window window!");
2132 return WMError::WM_ERROR_INVALID_CALLING;
2133 }
2134
2135 if (state_ != WindowState::STATE_SHOWN) {
2136 WLOGFE("The sub window must be shown!");
2137 return WMError::WM_DO_NOTHING;
2138 }
2139
2140 return SingletonContainer::Get<WindowAdapter>().RaiseToAppTop(GetWindowId());
2141 }
2142
DisableAppWindowDecor()2143 WMError WindowImpl::DisableAppWindowDecor()
2144 {
2145 if (!IsWindowValid()) {
2146 return WMError::WM_ERROR_INVALID_WINDOW;
2147 }
2148 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2149 WLOGFE("disable app window decor permission denied!");
2150 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2151 }
2152 if (!WindowHelper::IsMainWindow(property_->GetWindowType())) {
2153 WLOGFE("window decoration is invalid on sub window");
2154 return WMError::WM_ERROR_INVALID_OPERATION;
2155 }
2156 WLOGI("disable app window decoration.");
2157 windowSystemConfig_.isSystemDecorEnable_ = false;
2158 UpdateDecorEnable(true);
2159 return WMError::WM_OK;
2160 }
2161
IsDecorEnable() const2162 bool WindowImpl::IsDecorEnable() const
2163 {
2164 bool enable = windowSystemConfig_.isSystemDecorEnable_ &&
2165 WindowHelper::IsMainWindow(property_->GetWindowType());
2166 WLOGFD("get decor enable %{public}d", enable);
2167 return enable;
2168 }
2169
Maximize()2170 WMError WindowImpl::Maximize()
2171 {
2172 WLOGI("id: %{public}u Maximize", property_->GetWindowId());
2173 if (!IsWindowValid()) {
2174 return WMError::WM_ERROR_INVALID_WINDOW;
2175 }
2176 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2177 return SetFullScreen(true);
2178 } else {
2179 WLOGI("Maximize fail, not main window");
2180 return WMError::WM_ERROR_INVALID_PARAM;
2181 }
2182 }
2183
MaximizeFloating()2184 WMError WindowImpl::MaximizeFloating()
2185 {
2186 WLOGI("id: %{public}u MaximizeFloating", property_->GetWindowId());
2187 if (!IsWindowValid()) {
2188 return WMError::WM_ERROR_INVALID_WINDOW;
2189 }
2190 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2191 return SetFloatingMaximize(true);
2192 } else {
2193 WLOGI("MaximizeFloating fail, not main window");
2194 return WMError::WM_ERROR_INVALID_PARAM;
2195 }
2196 }
2197
SetGlobalMaximizeMode(MaximizeMode mode)2198 WMError WindowImpl::SetGlobalMaximizeMode(MaximizeMode mode)
2199 {
2200 WLOGI("id: %{public}u SetGlobalMaximizeMode: %{public}u", property_->GetWindowId(),
2201 static_cast<uint32_t>(mode));
2202 if (!IsWindowValid()) {
2203 return WMError::WM_ERROR_INVALID_WINDOW;
2204 }
2205 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2206 SingletonContainer::Get<WindowAdapter>().SetMaximizeMode(mode);
2207 return WMError::WM_OK;
2208 } else {
2209 WLOGI("SetGlobalMaximizeMode fail, not main window");
2210 return WMError::WM_ERROR_INVALID_PARAM;
2211 }
2212 }
2213
GetGlobalMaximizeMode() const2214 MaximizeMode WindowImpl::GetGlobalMaximizeMode() const
2215 {
2216 return SingletonContainer::Get<WindowAdapter>().GetMaximizeMode();
2217 }
2218
SetImmersiveModeEnabledState(bool enable)2219 WMError WindowImpl::SetImmersiveModeEnabledState(bool enable)
2220 {
2221 TLOGD(WmsLogTag::WMS_IMMS, "WindowImpl id: %{public}u SetImmersiveModeEnabledState: %{public}u",
2222 property_->GetWindowId(), static_cast<uint32_t>(enable));
2223 if (!IsWindowValid() ||
2224 !WindowHelper::IsWindowModeSupported(GetWindowModeSupportType(), WindowMode::WINDOW_MODE_FULLSCREEN)) {
2225 TLOGE(WmsLogTag::WMS_IMMS, "invalid window or fullscreen mode is not be supported, winId:%{public}u",
2226 property_->GetWindowId());
2227 return WMError::WM_ERROR_INVALID_WINDOW;
2228 }
2229 const WindowType curWindowType = GetType();
2230 if (!WindowHelper::IsMainWindow(curWindowType) && !WindowHelper::IsSubWindow(curWindowType)) {
2231 return WMError::WM_ERROR_INVALID_WINDOW;
2232 }
2233
2234 enableImmersiveMode_ = enable;
2235 const WindowMode mode = GetMode();
2236 if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) {
2237 return SetLayoutFullScreen(enableImmersiveMode_);
2238 }
2239 return WMError::WM_OK;
2240 }
2241
GetImmersiveModeEnabledState() const2242 bool WindowImpl::GetImmersiveModeEnabledState() const
2243 {
2244 if (!IsWindowValid()) {
2245 return false;
2246 }
2247 return enableImmersiveMode_;
2248 }
2249
NotifyWindowTransition(TransitionReason reason)2250 WMError WindowImpl::NotifyWindowTransition(TransitionReason reason)
2251 {
2252 sptr<WindowTransitionInfo> fromInfo = new(std::nothrow) WindowTransitionInfo();
2253 sptr<WindowTransitionInfo> toInfo = new(std::nothrow) WindowTransitionInfo();
2254 if (fromInfo == nullptr || toInfo == nullptr) {
2255 WLOGFE("new windowTransitionInfo failed");
2256 return WMError::WM_ERROR_NO_MEM;
2257 }
2258 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2259 if (abilityContext == nullptr) {
2260 WLOGFE("id:%{public}d is not ability Window", property_->GetWindowId());
2261 return WMError::WM_ERROR_NO_MEM;
2262 }
2263 auto abilityInfo = abilityContext->GetAbilityInfo();
2264 if (abilityInfo == nullptr) {
2265 return WMError::WM_ERROR_NULLPTR;
2266 }
2267 fromInfo->SetBundleName(context_->GetBundleName());
2268 fromInfo->SetAbilityName(abilityInfo->name);
2269 fromInfo->SetWindowMode(property_->GetWindowMode());
2270 fromInfo->SetWindowRect(property_->GetWindowRect());
2271 fromInfo->SetAbilityToken(context_->GetToken());
2272 fromInfo->SetWindowType(property_->GetWindowType());
2273 fromInfo->SetDisplayId(property_->GetDisplayId());
2274 fromInfo->SetTransitionReason(reason);
2275 return SingletonContainer::Get<WindowAdapter>().NotifyWindowTransition(fromInfo, toInfo);
2276 }
2277
Minimize()2278 WMError WindowImpl::Minimize()
2279 {
2280 WLOGI("id: %{public}u Minimize", property_->GetWindowId());
2281 if (!IsWindowValid()) {
2282 return WMError::WM_ERROR_INVALID_WINDOW;
2283 }
2284 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2285 if (context_ != nullptr) {
2286 WMError ret = NotifyWindowTransition(TransitionReason::MINIMIZE);
2287 if (ret != WMError::WM_OK) {
2288 WLOGI("Minimize without animation ret:%{public}u", static_cast<uint32_t>(ret));
2289 AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(context_->GetToken(), true);
2290 }
2291 } else {
2292 Hide();
2293 }
2294 }
2295 return WMError::WM_OK;
2296 }
2297
Recover()2298 WMError WindowImpl::Recover()
2299 {
2300 WLOGI("id: %{public}u Normalize", property_->GetWindowId());
2301 if (!IsWindowValid()) {
2302 return WMError::WM_ERROR_INVALID_WINDOW;
2303 }
2304 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2305 if (property_->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING &&
2306 property_->GetMaximizeMode() == MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
2307 SetFloatingMaximize(false);
2308 return WMError::WM_OK;
2309 }
2310 SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
2311 }
2312 return WMError::WM_OK;
2313 }
2314
Close()2315 WMError WindowImpl::Close()
2316 {
2317 WLOGI("id: %{public}u Close", property_->GetWindowId());
2318 if (!IsWindowValid()) {
2319 return WMError::WM_ERROR_INVALID_WINDOW;
2320 }
2321 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
2322 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2323 if (!abilityContext) {
2324 return Destroy();
2325 }
2326 sptr<AAFwk::IPrepareTerminateCallback> callback = this;
2327 if (AAFwk::AbilityManagerClient::GetInstance()->PrepareTerminateAbility(abilityContext->GetToken(),
2328 callback) != ERR_OK) {
2329 WLOGFW("RegisterWindowManagerServiceHandler failed, do close window");
2330 PendingClose();
2331 return WMError::WM_OK;
2332 }
2333 }
2334 return WMError::WM_OK;
2335 }
2336
DoPrepareTerminate()2337 void WindowImpl::DoPrepareTerminate()
2338 {
2339 WLOGFI("do pending close by ability");
2340 PendingClose();
2341 }
2342
PendingClose()2343 void WindowImpl::PendingClose()
2344 {
2345 WLOGFD("begin");
2346 WMError ret = NotifyWindowTransition(TransitionReason::CLOSE_BUTTON);
2347 if (ret != WMError::WM_OK) {
2348 WLOGI("Close without animation ret:%{public}u", static_cast<uint32_t>(ret));
2349 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
2350 if (abilityContext != nullptr) {
2351 abilityContext->CloseAbility();
2352 }
2353 }
2354 }
2355
RequestFocus() const2356 WMError WindowImpl::RequestFocus() const
2357 {
2358 if (!IsWindowValid()) {
2359 return WMError::WM_ERROR_INVALID_WINDOW;
2360 }
2361 return SingletonContainer::Get<WindowAdapter>().RequestFocus(property_->GetWindowId());
2362 }
2363
SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer> & inputEventConsumer)2364 void WindowImpl::SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer)
2365 {
2366 std::lock_guard<std::recursive_mutex> lock(mutex_);
2367 inputEventConsumer_ = inputEventConsumer;
2368 }
2369
RegisterLifeCycleListener(const sptr<IWindowLifeCycle> & listener)2370 WMError WindowImpl::RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
2371 {
2372 WLOGFD("Start register");
2373 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2374 return RegisterListener(lifecycleListeners_[GetWindowId()], listener);
2375 }
2376
UnregisterLifeCycleListener(const sptr<IWindowLifeCycle> & listener)2377 WMError WindowImpl::UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
2378 {
2379 WLOGFD("Start unregister");
2380 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2381 return UnregisterListener(lifecycleListeners_[GetWindowId()], listener);
2382 }
2383
RegisterWindowChangeListener(const sptr<IWindowChangeListener> & listener)2384 WMError WindowImpl::RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
2385 {
2386 WLOGFD("Start register");
2387 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2388 return RegisterListener(windowChangeListeners_[GetWindowId()], listener);
2389 }
2390
UnregisterWindowChangeListener(const sptr<IWindowChangeListener> & listener)2391 WMError WindowImpl::UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
2392 {
2393 WLOGFD("Start unregister");
2394 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2395 return UnregisterListener(windowChangeListeners_[GetWindowId()], listener);
2396 }
2397
RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener> & listener)2398 WMError WindowImpl::RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
2399 {
2400 WLOGFD("Start register");
2401 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2402 WMError ret = RegisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
2403 if (avoidAreaChangeListeners_[GetWindowId()].size() == 1) {
2404 SingletonContainer::Get<WindowAdapter>().UpdateAvoidAreaListener(property_->GetWindowId(), true);
2405 }
2406 return ret;
2407 }
2408
UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener> & listener)2409 WMError WindowImpl::UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
2410 {
2411 WLOGFD("Start unregister");
2412 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2413 WMError ret = UnregisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
2414 if (avoidAreaChangeListeners_[GetWindowId()].empty()) {
2415 SingletonContainer::Get<WindowAdapter>().UpdateAvoidAreaListener(property_->GetWindowId(), false);
2416 }
2417 return ret;
2418 }
2419
RegisterDragListener(const sptr<IWindowDragListener> & listener)2420 WMError WindowImpl::RegisterDragListener(const sptr<IWindowDragListener>& listener)
2421 {
2422 WLOGFD("Start register");
2423 std::lock_guard<std::recursive_mutex> lock(mutex_);
2424 return RegisterListener(windowDragListeners_, listener);
2425 }
2426
UnregisterDragListener(const sptr<IWindowDragListener> & listener)2427 WMError WindowImpl::UnregisterDragListener(const sptr<IWindowDragListener>& listener)
2428 {
2429 WLOGFD("Start unregister");
2430 std::lock_guard<std::recursive_mutex> lock(mutex_);
2431 return UnregisterListener(windowDragListeners_, listener);
2432 }
2433
RegisterDisplayMoveListener(sptr<IDisplayMoveListener> & listener)2434 WMError WindowImpl::RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
2435 {
2436 WLOGFD("Start register");
2437 std::lock_guard<std::recursive_mutex> lock(mutex_);
2438 return RegisterListener(displayMoveListeners_, listener);
2439 }
2440
UnregisterDisplayMoveListener(sptr<IDisplayMoveListener> & listener)2441 WMError WindowImpl::UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
2442 {
2443 WLOGFD("Start unregister");
2444 std::lock_guard<std::recursive_mutex> lock(mutex_);
2445 return UnregisterListener(displayMoveListeners_, listener);
2446 }
2447
RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc & func)2448 void WindowImpl::RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func)
2449 {
2450 WLOGFD("Start register");
2451 notifyNativefunc_ = std::move(func);
2452 }
2453
RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener> & listener)2454 WMError WindowImpl::RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
2455 {
2456 WLOGFD("Start register");
2457 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2458 return RegisterListener(occupiedAreaChangeListeners_[GetWindowId()], listener);
2459 }
2460
UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener> & listener)2461 WMError WindowImpl::UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
2462 {
2463 WLOGFD("Start unregister");
2464 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2465 return UnregisterListener(occupiedAreaChangeListeners_[GetWindowId()], listener);
2466 }
2467
RegisterTouchOutsideListener(const sptr<ITouchOutsideListener> & listener)2468 WMError WindowImpl::RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
2469 {
2470 WLOGFD("Start register");
2471 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2472 return RegisterListener(touchOutsideListeners_[GetWindowId()], listener);
2473 }
2474
UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener> & listener)2475 WMError WindowImpl::UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
2476 {
2477 WLOGFD("Start unregister");
2478 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2479 return UnregisterListener(touchOutsideListeners_[GetWindowId()], listener);
2480 }
2481
RegisterAnimationTransitionController(const sptr<IAnimationTransitionController> & listener)2482 WMError WindowImpl::RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener)
2483 {
2484 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
2485 WLOGFE("register animation transition controller permission denied!");
2486 return WMError::WM_ERROR_NOT_SYSTEM_APP;
2487 }
2488 if (listener == nullptr) {
2489 WLOGFE("listener is nullptr");
2490 return WMError::WM_ERROR_NULLPTR;
2491 }
2492 animationTransitionController_ = listener;
2493 wptr<WindowProperty> propertyToken(property_);
2494 wptr<IAnimationTransitionController> animationTransitionControllerToken(animationTransitionController_);
2495 if (uiContent_) {
2496 uiContent_->SetNextFrameLayoutCallback([propertyToken, animationTransitionControllerToken]() {
2497 auto property = propertyToken.promote();
2498 auto animationTransitionController = animationTransitionControllerToken.promote();
2499 if (!property || !animationTransitionController) {
2500 return;
2501 }
2502 uint32_t animationFlag = property->GetAnimationFlag();
2503 if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
2504 // CustomAnimation is enabled when animationTransitionController_ exists
2505 animationTransitionController->AnimationForShown();
2506 }
2507 });
2508 }
2509 return WMError::WM_OK;
2510 }
2511
RegisterScreenshotListener(const sptr<IScreenshotListener> & listener)2512 WMError WindowImpl::RegisterScreenshotListener(const sptr<IScreenshotListener>& listener)
2513 {
2514 WLOGFD("Start register");
2515 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2516 return RegisterListener(screenshotListeners_[GetWindowId()], listener);
2517 }
2518
UnregisterScreenshotListener(const sptr<IScreenshotListener> & listener)2519 WMError WindowImpl::UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener)
2520 {
2521 WLOGFD("Start unregister");
2522 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2523 return UnregisterListener(screenshotListeners_[GetWindowId()], listener);
2524 }
2525
RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener> & listener)2526 WMError WindowImpl::RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
2527 {
2528 WLOGFD("Start register");
2529 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2530 return RegisterListener(dialogTargetTouchListeners_[GetWindowId()], listener);
2531 }
2532
UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener> & listener)2533 WMError WindowImpl::UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
2534 {
2535 WLOGFD("Start unregister");
2536 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2537 return UnregisterListener(dialogTargetTouchListeners_[GetWindowId()], listener);
2538 }
2539
RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener> & listener)2540 void WindowImpl::RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
2541 {
2542 WLOGFD("Start register");
2543 if (listener == nullptr) {
2544 WLOGFE("listener is nullptr");
2545 return;
2546 }
2547 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2548 dialogDeathRecipientListener_[GetWindowId()] = listener;
2549 }
2550
UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener> & listener)2551 void WindowImpl::UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
2552 {
2553 WLOGFD("Start unregister");
2554 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2555 dialogDeathRecipientListener_[GetWindowId()] = nullptr;
2556 }
2557
2558 template<typename T>
RegisterListener(std::vector<sptr<T>> & holder,const sptr<T> & listener)2559 WMError WindowImpl::RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
2560 {
2561 if (listener == nullptr) {
2562 WLOGFE("listener is nullptr");
2563 return WMError::WM_ERROR_NULLPTR;
2564 }
2565 if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
2566 WLOGFE("Listener already registered");
2567 return WMError::WM_OK;
2568 }
2569 holder.emplace_back(listener);
2570 return WMError::WM_OK;
2571 }
2572
2573 template<typename T>
UnregisterListener(std::vector<sptr<T>> & holder,const sptr<T> & listener)2574 WMError WindowImpl::UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
2575 {
2576 if (listener == nullptr) {
2577 WLOGFE("listener could not be null");
2578 return WMError::WM_ERROR_NULLPTR;
2579 }
2580 holder.erase(std::remove_if(holder.begin(), holder.end(),
2581 [listener](sptr<T> registeredListener) {
2582 return registeredListener == listener;
2583 }), holder.end());
2584 return WMError::WM_OK;
2585 }
2586
2587 template <typename T>
GetListeners()2588 EnableIfSame<T, IWindowLifeCycle, std::vector<sptr<IWindowLifeCycle>>> WindowImpl::GetListeners()
2589 {
2590 std::vector<sptr<IWindowLifeCycle>> lifecycleListeners;
2591 {
2592 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2593 for (auto &listener : lifecycleListeners_[GetWindowId()]) {
2594 lifecycleListeners.push_back(listener);
2595 }
2596 }
2597 return lifecycleListeners;
2598 }
2599
2600 template <typename T>
GetListeners()2601 EnableIfSame<T, IWindowChangeListener, std::vector<sptr<IWindowChangeListener>>> WindowImpl::GetListeners()
2602 {
2603 std::vector<sptr<IWindowChangeListener>> windowChangeListeners;
2604 {
2605 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2606 for (auto &listener : windowChangeListeners_[GetWindowId()]) {
2607 windowChangeListeners.push_back(listener);
2608 }
2609 }
2610 return windowChangeListeners;
2611 }
2612
2613 template <typename T>
GetListeners()2614 EnableIfSame<T, IAvoidAreaChangedListener, std::vector<sptr<IAvoidAreaChangedListener>>> WindowImpl::GetListeners()
2615 {
2616 std::vector<sptr<IAvoidAreaChangedListener>> avoidAreaChangeListeners;
2617 {
2618 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2619 for (auto &listener : avoidAreaChangeListeners_[GetWindowId()]) {
2620 avoidAreaChangeListeners.push_back(listener);
2621 }
2622 }
2623 return avoidAreaChangeListeners;
2624 }
2625
2626 template <typename T>
GetListeners()2627 EnableIfSame<T, IDisplayMoveListener, std::vector<sptr<IDisplayMoveListener>>> WindowImpl::GetListeners()
2628 {
2629 std::vector<sptr<IDisplayMoveListener>> displayMoveListeners;
2630 {
2631 std::lock_guard<std::recursive_mutex> lock(mutex_);
2632 for (auto &listener : displayMoveListeners_) {
2633 displayMoveListeners.push_back(listener);
2634 }
2635 }
2636 return displayMoveListeners;
2637 }
2638
2639 template <typename T>
GetListeners()2640 EnableIfSame<T, IScreenshotListener, std::vector<sptr<IScreenshotListener>>> WindowImpl::GetListeners()
2641 {
2642 std::vector<sptr<IScreenshotListener>> screenshotListeners;
2643 {
2644 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2645 for (auto &listener : screenshotListeners_[GetWindowId()]) {
2646 screenshotListeners.push_back(listener);
2647 }
2648 }
2649 return screenshotListeners;
2650 }
2651
2652 template <typename T>
GetListeners()2653 EnableIfSame<T, ITouchOutsideListener, std::vector<sptr<ITouchOutsideListener>>> WindowImpl::GetListeners()
2654 {
2655 std::vector<sptr<ITouchOutsideListener>> touchOutsideListeners;
2656 {
2657 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2658 for (auto &listener : touchOutsideListeners_[GetWindowId()]) {
2659 touchOutsideListeners.push_back(listener);
2660 }
2661 }
2662 return touchOutsideListeners;
2663 }
2664
2665 template <typename T>
GetListeners()2666 EnableIfSame<T, IDialogTargetTouchListener, std::vector<sptr<IDialogTargetTouchListener>>> WindowImpl::GetListeners()
2667 {
2668 std::vector<sptr<IDialogTargetTouchListener>> dialogTargetTouchListeners;
2669 {
2670 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2671 for (auto &listener : dialogTargetTouchListeners_[GetWindowId()]) {
2672 dialogTargetTouchListeners.push_back(listener);
2673 }
2674 }
2675 return dialogTargetTouchListeners;
2676 }
2677
2678 template <typename T>
GetListeners()2679 EnableIfSame<T, IWindowDragListener, std::vector<sptr<IWindowDragListener>>> WindowImpl::GetListeners()
2680 {
2681 std::vector<sptr<IWindowDragListener>> windowDragListeners;
2682 {
2683 std::lock_guard<std::recursive_mutex> lock(mutex_);
2684 for (auto &listener : windowDragListeners_) {
2685 windowDragListeners.push_back(listener);
2686 }
2687 }
2688 return windowDragListeners;
2689 }
2690
2691 template <typename T>
GetListeners()2692 EnableIfSame<T, IOccupiedAreaChangeListener, std::vector<sptr<IOccupiedAreaChangeListener>>> WindowImpl::GetListeners()
2693 {
2694 std::vector<sptr<IOccupiedAreaChangeListener>> occupiedAreaChangeListeners;
2695 {
2696 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2697 for (auto &listener : occupiedAreaChangeListeners_[GetWindowId()]) {
2698 occupiedAreaChangeListeners.push_back(listener);
2699 }
2700 }
2701 return occupiedAreaChangeListeners;
2702 }
2703
2704 template <typename T>
GetListener()2705 EnableIfSame<T, IDialogDeathRecipientListener, wptr<IDialogDeathRecipientListener>> WindowImpl::GetListener()
2706 {
2707 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
2708 return dialogDeathRecipientListener_[GetWindowId()];
2709 }
2710
SetAceAbilityHandler(const sptr<IAceAbilityHandler> & handler)2711 void WindowImpl::SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler)
2712 {
2713 if (handler == nullptr) {
2714 WLOGI("ace ability handler is nullptr");
2715 }
2716 std::lock_guard<std::recursive_mutex> lock(mutex_);
2717 aceAbilityHandler_ = handler;
2718 }
2719
SetRequestWindowModeSupportType(uint32_t windowModeSupportType)2720 void WindowImpl::SetRequestWindowModeSupportType(uint32_t windowModeSupportType)
2721 {
2722 property_->SetRequestWindowModeSupportType(windowModeSupportType);
2723 SetWindowModeSupportType(windowModeSupportType);
2724 }
2725
SetWindowModeSupportType(uint32_t windowModeSupportType)2726 void WindowImpl::SetWindowModeSupportType(uint32_t windowModeSupportType)
2727 {
2728 property_->SetWindowModeSupportType(windowModeSupportType);
2729 }
2730
UpdateRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)2731 void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason,
2732 const std::shared_ptr<RSTransaction>& rsTransaction)
2733 {
2734 if (state_ == WindowState::STATE_DESTROYED) {
2735 WLOGFW("invalid window state");
2736 return;
2737 }
2738 auto display = SingletonContainer::IsDestroyed() ? nullptr :
2739 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
2740 if (display == nullptr) {
2741 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
2742 property_->GetWindowId());
2743 return;
2744 }
2745 Rect lastOriRect = property_->GetWindowRect();
2746
2747 property_->SetDecoStatus(decoStatus);
2748 if (reason == WindowSizeChangeReason::HIDE) {
2749 property_->SetRequestRect(rect);
2750 return;
2751 }
2752 property_->SetWindowRect(rect);
2753
2754 // update originRect when floating window show for the first time.
2755 if (!isOriginRectSet_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2756 property_->SetOriginRect(rect);
2757 isOriginRectSet_ = true;
2758 }
2759 WLOGFD("winId:%{public}u, rect[%{public}d, %{public}d, %{public}u, %{public}u], reason:%{public}u",
2760 property_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_, reason);
2761 Rect rectToAce = rect;
2762 // update rectToAce for stretchable window
2763 if (windowSystemConfig_.isStretchable_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2764 if (IsStretchableReason(reason)) {
2765 rectToAce = property_->GetOriginRect();
2766 } else {
2767 property_->SetOriginRect(rect);
2768 }
2769 }
2770 ScheduleUpdateRectTask(rectToAce, lastOriRect, reason, rsTransaction, display);
2771 }
2772
ScheduleUpdateRectTask(const Rect & rectToAce,const Rect & lastOriRect,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction,const sptr<class Display> & display)2773 void WindowImpl::ScheduleUpdateRectTask(const Rect& rectToAce, const Rect& lastOriRect, WindowSizeChangeReason reason,
2774 const std::shared_ptr<RSTransaction>& rsTransaction, const sptr<class Display>& display)
2775 {
2776 auto task = [weakThis = wptr(this), reason, rsTransaction, rectToAce, lastOriRect, display]() mutable {
2777 auto window = weakThis.promote();
2778 if (!window) {
2779 TLOGNE(WmsLogTag::WMS_IMMS, "window is null");
2780 return;
2781 }
2782 if (rsTransaction) {
2783 RSTransaction::FlushImplicitTransaction();
2784 rsTransaction->Begin();
2785 }
2786 RSAnimationTimingProtocol protocol;
2787 protocol.SetDuration(600);
2788 auto curve = RSAnimationTimingCurve::CreateCubicCurve(0.2, 0.0, 0.2, 1.0);
2789 RSNode::OpenImplicitAnimation(protocol, curve);
2790 if ((rectToAce != lastOriRect) || (reason != window->lastSizeChangeReason_)) {
2791 window->NotifySizeChange(rectToAce, reason, rsTransaction);
2792 window->lastSizeChangeReason_ = reason;
2793 }
2794 window->UpdateViewportConfig(rectToAce, display, reason, rsTransaction);
2795 RSNode::CloseImplicitAnimation();
2796 if (rsTransaction) {
2797 rsTransaction->Commit();
2798 }
2799 window->postTaskDone_ = true;
2800 };
2801 ResSchedReport::GetInstance().RequestPerfIfNeed(reason, GetType(), GetMode());
2802 if (reason == WindowSizeChangeReason::ROTATION) {
2803 postTaskDone_ = false;
2804 handler_->PostTask(task, "wms:UpdateRect");
2805 } else {
2806 if ((rectToAce != lastOriRect) || (reason != lastSizeChangeReason_) || !postTaskDone_) {
2807 NotifySizeChange(rectToAce, reason, rsTransaction);
2808 lastSizeChangeReason_ = reason;
2809 postTaskDone_ = true;
2810 }
2811 UpdateViewportConfig(rectToAce, display, reason, rsTransaction);
2812 }
2813 }
2814
UpdateMode(WindowMode mode)2815 void WindowImpl::UpdateMode(WindowMode mode)
2816 {
2817 WLOGI("UpdateMode %{public}u", mode);
2818 property_->SetWindowMode(mode);
2819 UpdateTitleButtonVisibility();
2820 UpdateDecorEnable(true);
2821 }
2822
UpdateWindowModeSupportType(uint32_t windowModeSupportType)2823 void WindowImpl::UpdateWindowModeSupportType(uint32_t windowModeSupportType)
2824 {
2825 WLOGFD("windowModeSupportType: %{public}u, winId: %{public}u", windowModeSupportType, GetWindowId());
2826 SetWindowModeSupportType(windowModeSupportType);
2827 UpdateTitleButtonVisibility();
2828 }
2829
HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)2830 void WindowImpl::HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
2831 {
2832 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
2833 {
2834 std::lock_guard<std::recursive_mutex> lock(mutex_);
2835 inputEventConsumer = inputEventConsumer_;
2836 }
2837 SingletonContainer::Get<WindowInfoReporter>().ReportBackButtonInfoImmediately();
2838
2839 bool isConsumed = false;
2840 if (inputEventConsumer != nullptr) {
2841 WLOGD("Transfer back key event to inputEventConsumer");
2842 isConsumed = inputEventConsumer->OnInputEvent(keyEvent);
2843 } else if (uiContent_ != nullptr) {
2844 WLOGD("Transfer back key event to uiContent");
2845 isConsumed = uiContent_->ProcessBackPressed();
2846 } else {
2847 WLOGFE("There is no back key event consumer");
2848 }
2849 if (isConsumed) {
2850 WLOGD("Back key event is consumed");
2851 return;
2852 }
2853 PerformBack();
2854 }
2855
PerformBack()2856 void WindowImpl::PerformBack()
2857 {
2858 auto task = [weakThis = wptr(this)]() {
2859 auto window = weakThis.promote();
2860 if (!window) {
2861 TLOGNE(WmsLogTag::WMS_IMMS, "window is null");
2862 return;
2863 }
2864 if (!WindowHelper::IsMainWindow(window->property_->GetWindowType())) {
2865 WLOGD("it is not a main window");
2866 return;
2867 }
2868 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(window->context_);
2869 if (abilityContext == nullptr) {
2870 WLOGFE("abilityContext is null");
2871 return;
2872 }
2873 bool needMoveToBackground = false;
2874 int ret = abilityContext->OnBackPressedCallBack(needMoveToBackground);
2875 if (ret == ERR_OK && needMoveToBackground) {
2876 abilityContext->MoveAbilityToBackground();
2877 WLOGD("id: %{public}u closed, to move Ability: %{public}u",
2878 window->property_->GetWindowId(), needMoveToBackground);
2879 return;
2880 }
2881 // TerminateAbility will invoke last ability, CloseAbility will not.
2882 bool shouldTerminateAbility = WindowHelper::IsFullScreenWindow(window->property_->GetWindowMode());
2883 if (shouldTerminateAbility) {
2884 abilityContext->TerminateSelf();
2885 } else {
2886 abilityContext->CloseAbility();
2887 }
2888 WLOGD("id: %{public}u closed, to kill Ability: %{public}u",
2889 window->property_->GetWindowId(), static_cast<uint32_t>(shouldTerminateAbility));
2890 };
2891 handler_->PostTask(task, "WindowImpl::PerformBack");
2892 }
2893
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> & keyEvent)2894 void WindowImpl::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent)
2895 {
2896 int32_t keyCode = keyEvent->GetKeyCode();
2897 int32_t keyAction = keyEvent->GetKeyAction();
2898 WLOGFD("KeyCode: %{public}d, action: %{public}d", keyCode, keyAction);
2899 bool shouldMarkProcess = true;
2900 if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) {
2901 HandleBackKeyPressedEvent(keyEvent);
2902 } else {
2903 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
2904 {
2905 std::lock_guard<std::recursive_mutex> lock(mutex_);
2906 inputEventConsumer = inputEventConsumer_;
2907 }
2908 if (inputEventConsumer != nullptr) {
2909 WLOGD("Transfer key event to inputEventConsumer");
2910 (void)inputEventConsumer->OnInputEvent(keyEvent);
2911 shouldMarkProcess = false;
2912 } else if (uiContent_ != nullptr) {
2913 WLOGD("Transfer key event to uiContent");
2914 bool handled = static_cast<bool>(uiContent_->ProcessKeyEvent(keyEvent));
2915 if (!handled && keyCode == MMI::KeyEvent::KEYCODE_ESCAPE &&
2916 GetMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
2917 property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL &&
2918 keyAction == MMI::KeyEvent::KEY_ACTION_DOWN && !escKeyEventTriggered_) {
2919 WLOGI("recover from fullscreen cause KEYCODE_ESCAPE");
2920 Recover();
2921 }
2922 if (keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE) {
2923 escKeyEventTriggered_ = (keyAction == MMI::KeyEvent::KEY_ACTION_UP) ? false : true;
2924 }
2925 shouldMarkProcess = !handled;
2926 } else {
2927 WLOGFE("There is no key event consumer");
2928 }
2929 }
2930 if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
2931 WLOGFI("DispatchKeyEvent: %{public}u", GetWindowId());
2932 SingletonContainer::Get<WindowAdapter>().DispatchKeyEvent(GetWindowId(), keyEvent);
2933 keyEvent->MarkProcessed();
2934 return;
2935 }
2936 if (shouldMarkProcess) {
2937 keyEvent->MarkProcessed();
2938 }
2939 }
2940
HandleModeChangeHotZones(int32_t posX,int32_t posY)2941 void WindowImpl::HandleModeChangeHotZones(int32_t posX, int32_t posY)
2942 {
2943 if (!WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
2944 return;
2945 }
2946
2947 ModeChangeHotZones hotZones;
2948 auto res = SingletonContainer::Get<WindowAdapter>().GetModeChangeHotZones(property_->GetDisplayId(), hotZones);
2949 WLOGD("[HotZone] Window %{public}u, Pointer[%{public}d, %{public}d]", GetWindowId(), posX, posY);
2950 if (res == WMError::WM_OK) {
2951 WLOGD("[HotZone] Fullscreen [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.fullscreen_.posX_,
2952 hotZones.fullscreen_.posY_, hotZones.fullscreen_.width_, hotZones.fullscreen_.height_);
2953 WLOGD("[HotZone] Primary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.primary_.posX_,
2954 hotZones.primary_.posY_, hotZones.primary_.width_, hotZones.primary_.height_);
2955 WLOGD("[HotZone] Secondary [%{public}d, %{public}d, %{public}u, %{public}u]", hotZones.secondary_.posX_,
2956 hotZones.secondary_.posY_, hotZones.secondary_.width_, hotZones.secondary_.height_);
2957
2958 if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.fullscreen_)) {
2959 SetFullScreen(true);
2960 } else if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.primary_)) {
2961 SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
2962 } else if (WindowHelper::IsPointInTargetRectWithBound(posX, posY, hotZones.secondary_)) {
2963 SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
2964 }
2965 }
2966 }
2967
UpdatePointerEventForStretchableWindow(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)2968 void WindowImpl::UpdatePointerEventForStretchableWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
2969 {
2970 MMI::PointerEvent::PointerItem pointerItem;
2971 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
2972 WLOGFW("Point item is invalid");
2973 return;
2974 }
2975 const Rect& originRect = property_->GetOriginRect();
2976 PointInfo originPos =
2977 WindowHelper::CalculateOriginPosition(originRect, GetRect(),
2978 { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() });
2979 pointerItem.SetDisplayX(originPos.x);
2980 pointerItem.SetDisplayY(originPos.y);
2981 pointerItem.SetWindowX(originPos.x - originRect.posX_);
2982 pointerItem.SetWindowY(originPos.y - originRect.posY_);
2983 pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem);
2984 }
2985
UpdateDragType(int32_t startPointPosX,int32_t startPointPosY)2986 void WindowImpl::UpdateDragType(int32_t startPointPosX, int32_t startPointPosY)
2987 {
2988 const auto& startRectExceptCorner = moveDragProperty_->startRectExceptCorner_;
2989 if (startPointPosX > startRectExceptCorner.posX_ &&
2990 (startPointPosX < startRectExceptCorner.posX_ +
2991 static_cast<int32_t>(startRectExceptCorner.width_))) {
2992 moveDragProperty_->dragType_ = DragType::DRAG_BOTTOM_OR_TOP;
2993 } else if (startPointPosY > startRectExceptCorner.posY_ &&
2994 (startPointPosY < startRectExceptCorner.posY_ +
2995 static_cast<int32_t>(startRectExceptCorner.height_))) {
2996 moveDragProperty_->dragType_ = DragType::DRAG_LEFT_OR_RIGHT;
2997 } else if ((startPointPosX <= startRectExceptCorner.posX_ && startPointPosY <= startRectExceptCorner.posY_) ||
2998 (startPointPosX >= startRectExceptCorner.posX_ + static_cast<int32_t>(startRectExceptCorner.width_) &&
2999 startPointPosY >= startRectExceptCorner.posY_ + static_cast<int32_t>(startRectExceptCorner.height_))) {
3000 moveDragProperty_->dragType_ = DragType::DRAG_LEFT_TOP_CORNER;
3001 } else {
3002 moveDragProperty_->dragType_ = DragType::DRAG_RIGHT_TOP_CORNER;
3003 }
3004 }
3005
CalculateStartRectExceptHotZone(float vpr)3006 void WindowImpl::CalculateStartRectExceptHotZone(float vpr)
3007 {
3008 TransformHelper::Vector2 hotZoneScale(1, 1);
3009 if (property_->isNeedComputerTransform()) {
3010 property_->ComputeTransform();
3011 hotZoneScale = WindowHelper::CalculateHotZoneScale(property_->GetTransformMat());
3012 }
3013
3014 const auto& startPointRect = GetRect();
3015 auto& startRectExceptFrame = moveDragProperty_->startRectExceptFrame_;
3016 startRectExceptFrame.posX_ = startPointRect.posX_ +
3017 static_cast<int32_t>(WINDOW_FRAME_WIDTH * vpr / hotZoneScale.x_);
3018 startRectExceptFrame.posY_ = startPointRect.posY_ +
3019 static_cast<int32_t>(WINDOW_FRAME_WIDTH * vpr / hotZoneScale.y_);
3020 startRectExceptFrame.width_ = startPointRect.width_ -
3021 static_cast<uint32_t>((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * vpr / hotZoneScale.x_);
3022 startRectExceptFrame.height_ = startPointRect.height_ -
3023 static_cast<uint32_t>((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * vpr / hotZoneScale.y_);
3024
3025 auto& startRectExceptCorner = moveDragProperty_->startRectExceptCorner_;
3026 startRectExceptCorner.posX_ = startPointRect.posX_ +
3027 static_cast<int32_t>(WINDOW_FRAME_CORNER_WIDTH * vpr / hotZoneScale.x_);
3028 startRectExceptCorner.posY_ = startPointRect.posY_ +
3029 static_cast<int32_t>(WINDOW_FRAME_CORNER_WIDTH * vpr / hotZoneScale.y_);
3030 startRectExceptCorner.width_ = startPointRect.width_ -
3031 static_cast<uint32_t>((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * vpr / hotZoneScale.x_);
3032 startRectExceptCorner.height_ = startPointRect.height_ -
3033 static_cast<uint32_t>((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * vpr / hotZoneScale.y_);
3034 }
3035
IsPointInDragHotZone(int32_t startPointPosX,int32_t startPointPosY,int32_t sourceType)3036 bool WindowImpl::IsPointInDragHotZone(int32_t startPointPosX, int32_t startPointPosY, int32_t sourceType)
3037 {
3038 // calculate rect with hotzone
3039 Rect rectWithHotzone;
3040 rectWithHotzone.posX_ = GetRect().posX_ - static_cast<int32_t>(HOTZONE_POINTER);
3041 rectWithHotzone.posY_ = GetRect().posY_ - static_cast<int32_t>(HOTZONE_POINTER);
3042 rectWithHotzone.width_ = GetRect().width_ + HOTZONE_POINTER * 2; // 2: calculate width need
3043 rectWithHotzone.height_ = GetRect().height_ + HOTZONE_POINTER * 2; // 2: calculate height need
3044
3045 if (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE &&
3046 !WindowHelper::IsPointInTargetRectWithBound(startPointPosX, startPointPosY, rectWithHotzone)) {
3047 return false;
3048 } else if ((!WindowHelper::IsPointInTargetRect(startPointPosX,
3049 startPointPosY, moveDragProperty_->startRectExceptFrame_)) ||
3050 (!WindowHelper::IsPointInWindowExceptCorner(startPointPosX,
3051 startPointPosY, moveDragProperty_->startRectExceptCorner_))) {
3052 return true;
3053 }
3054 return false;
3055 }
3056
StartMove()3057 void WindowImpl::StartMove()
3058 {
3059 if (!WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
3060 WLOGE("[StartMove] current window can not be moved, windowId %{public}u", GetWindowId());
3061 return;
3062 }
3063 if (!moveDragProperty_->pointEventStarted_ || moveDragProperty_->startDragFlag_) {
3064 WLOGE("[StartMove] pointerEvent has not been started, or is dragging now");
3065 return;
3066 }
3067 moveDragProperty_->startMoveFlag_ = true;
3068 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3069 property_, moveDragProperty_);
3070 WLOGI("[StartMove] windowId %{public}u", GetWindowId());
3071 }
3072
ResetMoveOrDragState()3073 void WindowImpl::ResetMoveOrDragState()
3074 {
3075 if (!WindowHelper::IsMainWindow(GetType())) {
3076 return;
3077 }
3078 moveDragProperty_->pointEventStarted_ = false;
3079 moveDragProperty_->startDragFlag_ = false;
3080 moveDragProperty_->startMoveFlag_ = false;
3081 UpdateRect(GetRect(), property_->GetDecoStatus(), WindowSizeChangeReason::DRAG_END);
3082 }
3083
ReadyToMoveOrDragWindow(const std::shared_ptr<MMI::PointerEvent> & pointerEvent,const MMI::PointerEvent::PointerItem & pointerItem)3084 void WindowImpl::ReadyToMoveOrDragWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
3085 const MMI::PointerEvent::PointerItem& pointerItem)
3086 {
3087 if (moveDragProperty_->pointEventStarted_) {
3088 return;
3089 }
3090
3091 moveDragProperty_->startPointRect_ = GetRect();
3092 moveDragProperty_->startPointPosX_ = pointerItem.GetDisplayX();
3093 moveDragProperty_->startPointPosY_ = pointerItem.GetDisplayY();
3094 moveDragProperty_->startPointerId_ = pointerEvent->GetPointerId();
3095 moveDragProperty_->targetDisplayId_ = pointerEvent->GetTargetDisplayId();
3096 moveDragProperty_->sourceType_ = pointerEvent->GetSourceType();
3097 moveDragProperty_->pointEventStarted_ = true;
3098
3099 // calculate window inner rect except frame
3100 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3101 SingletonContainer::Get<DisplayManager>().GetDisplayById(moveDragProperty_->targetDisplayId_);
3102 if (display == nullptr) {
3103 WLOGFE("get display failed moveDragProperty targetDisplayId:%{public}u, window id:%{public}u",
3104 moveDragProperty_->targetDisplayId_, property_->GetWindowId());
3105 return;
3106 }
3107 auto displayInfo = display->GetDisplayInfo();
3108 if (displayInfo == nullptr) {
3109 WLOGFE("get display info failed moveDragProperty targetDisplayId:%{public}u, window id:%{public}u",
3110 moveDragProperty_->targetDisplayId_, property_->GetWindowId());
3111 return;
3112 }
3113 float vpr = display->GetVirtualPixelRatio();
3114 int32_t startPointPosX = moveDragProperty_->startPointPosX_ + displayInfo->GetOffsetX();
3115 int32_t startPointPosY = moveDragProperty_->startPointPosY_ + displayInfo->GetOffsetY();
3116
3117 CalculateStartRectExceptHotZone(vpr);
3118
3119 if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
3120 moveDragProperty_->startMoveFlag_ = true;
3121 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3122 property_, moveDragProperty_);
3123 } else if (IsPointInDragHotZone(startPointPosX, startPointPosY, moveDragProperty_->sourceType_)
3124 && property_->GetMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
3125 moveDragProperty_->startDragFlag_ = true;
3126 UpdateDragType(startPointPosX, startPointPosY);
3127 SingletonContainer::Get<WindowAdapter>().NotifyServerReadyToMoveOrDrag(property_->GetWindowId(),
3128 property_, moveDragProperty_);
3129 }
3130 return;
3131 }
3132
EndMoveOrDragWindow(int32_t posX,int32_t posY,int32_t pointId,int32_t sourceType)3133 void WindowImpl::EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType)
3134 {
3135 if (pointId != moveDragProperty_->startPointerId_ || sourceType != moveDragProperty_->sourceType_) {
3136 return;
3137 }
3138
3139 if (moveDragProperty_->startDragFlag_) {
3140 SingletonContainer::Get<WindowAdapter>().ProcessPointUp(GetWindowId());
3141 moveDragProperty_->startDragFlag_ = false;
3142 }
3143
3144 if (moveDragProperty_->startMoveFlag_) {
3145 SingletonContainer::Get<WindowAdapter>().ProcessPointUp(GetWindowId());
3146 moveDragProperty_->startMoveFlag_ = false;
3147 HandleModeChangeHotZones(posX, posY);
3148 }
3149 moveDragProperty_->pointEventStarted_ = false;
3150 ResSchedReport::GetInstance().StopPerfIfNeed();
3151 }
3152
ConsumeMoveOrDragEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3153 void WindowImpl::ConsumeMoveOrDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3154 {
3155 MMI::PointerEvent::PointerItem pointerItem;
3156 int32_t pointId = pointerEvent->GetPointerId();
3157 int32_t sourceType = pointerEvent->GetSourceType();
3158 if (!pointerEvent->GetPointerItem(pointId, pointerItem) ||
3159 (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE &&
3160 pointerEvent->GetButtonId() != MMI::PointerEvent::MOUSE_BUTTON_LEFT)) {
3161 WLOGFW("invalid pointerEvent");
3162 return;
3163 }
3164 int32_t pointDisplayX = pointerItem.GetDisplayX();
3165 int32_t pointDisplayY = pointerItem.GetDisplayY();
3166 int32_t action = pointerEvent->GetPointerAction();
3167 int32_t targetDisplayId = pointerEvent->GetTargetDisplayId();
3168 switch (action) {
3169 // Ready to move or drag
3170 case MMI::PointerEvent::POINTER_ACTION_DOWN:
3171 case MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: {
3172 const auto& rect = GetRect();
3173 ReadyToMoveOrDragWindow(pointerEvent, pointerItem);
3174 if (IsPointerEventConsumed()) {
3175 ResSchedReport::GetInstance().TrigClick();
3176 }
3177 TLOGD(WmsLogTag::WMS_EVENT, "windowId:%{public}u, pointId:%{public}d, sourceType:%{public}d, "
3178 "hasPointStarted:%{public}d, startMove:%{public}d, startDrag:%{public}d, targetDisplayId:"
3179 "%{public}d, pointPos:[%{private}d, %{private}d], winRect:[%{public}d, %{public}d, %{public}u, "
3180 "%{public}u]", GetWindowId(), pointId, sourceType, moveDragProperty_->pointEventStarted_,
3181 moveDragProperty_->startMoveFlag_, moveDragProperty_->startDragFlag_, targetDisplayId,
3182 pointDisplayX, pointDisplayY, rect.posX_, rect.posY_, rect.width_, rect.height_);
3183 break;
3184 }
3185 // End move or drag
3186 case MMI::PointerEvent::POINTER_ACTION_UP:
3187 case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP:
3188 case MMI::PointerEvent::POINTER_ACTION_CANCEL: {
3189 EndMoveOrDragWindow(pointDisplayX, pointDisplayY, pointId, sourceType);
3190 WLOGFD("[Client Point Up/Cancel]: windowId: %{public}u, action: %{public}d, sourceType: %{public}d, "
3191 "startMove: %{public}d, startDrag: %{public}d", GetWindowId(), action, sourceType,
3192 moveDragProperty_->startMoveFlag_, moveDragProperty_->startDragFlag_);
3193 break;
3194 }
3195 default:
3196 break;
3197 }
3198 }
3199
IsPointerEventConsumed()3200 bool WindowImpl::IsPointerEventConsumed()
3201 {
3202 return moveDragProperty_->startDragFlag_ || moveDragProperty_->startMoveFlag_;
3203 }
3204
TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3205 void WindowImpl::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3206 {
3207 if (pointerEvent == nullptr) {
3208 WLOGFE("The pointer event is nullptr");
3209 return;
3210 }
3211 if (windowSystemConfig_.isStretchable_ && GetMode() == WindowMode::WINDOW_MODE_FLOATING) {
3212 UpdatePointerEventForStretchableWindow(pointerEvent);
3213 }
3214 std::shared_ptr<IInputEventConsumer> inputEventConsumer;
3215 {
3216 std::lock_guard<std::recursive_mutex> lock(mutex_);
3217 inputEventConsumer = inputEventConsumer_;
3218 }
3219 if (inputEventConsumer != nullptr) {
3220 WLOGFD("Transfer pointer event to inputEventConsumer");
3221 if (!(inputEventConsumer->OnInputEvent(pointerEvent))) {
3222 WLOGFI("The Input event consumer consumes pointer event failed.");
3223 pointerEvent->MarkProcessed();
3224 }
3225 } else if (uiContent_ != nullptr) {
3226 WLOGFD("Transfer pointer event to uiContent");
3227 if (!(uiContent_->ProcessPointerEvent(pointerEvent))) {
3228 WLOGFI("The UI content consumes pointer event failed.");
3229 pointerEvent->MarkProcessed();
3230 }
3231 } else {
3232 WLOGFW("pointerEvent is not consumed, windowId: %{public}u", GetWindowId());
3233 pointerEvent->MarkProcessed();
3234 }
3235 }
3236
CalculatePointerDirection(int32_t pointerX,int32_t pointerY)3237 uint32_t WindowImpl::CalculatePointerDirection(int32_t pointerX, int32_t pointerY)
3238 {
3239 UpdateDragType(pointerX, pointerY);
3240 return STYLEID_MAP.at(moveDragProperty_->dragType_);
3241 }
3242
HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3243 void WindowImpl::HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3244 {
3245 MMI::PointerEvent::PointerItem pointerItem;
3246 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
3247 WLOGFE("Get pointeritem failed");
3248 pointerEvent->MarkProcessed();
3249 return;
3250 }
3251 auto action = pointerEvent->GetPointerAction();
3252 uint32_t windowId = static_cast<uint32_t>(pointerEvent->GetAgentWindowId());
3253 int32_t mousePointX = pointerItem.GetDisplayX();
3254 int32_t mousePointY = pointerItem.GetDisplayY();
3255 int32_t sourceType = pointerEvent->GetSourceType();
3256 uint32_t oldStyleID = mouseStyleID_;
3257 uint32_t newStyleID = 0;
3258 if (WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) {
3259 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3260 SingletonContainer::Get<DisplayManager>().GetDisplayById(pointerEvent->GetTargetDisplayId());
3261 if (display == nullptr || display->GetDisplayInfo() == nullptr) {
3262 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u",
3263 property_->GetDisplayId(), property_->GetWindowId());
3264 return;
3265 }
3266 float vpr = display->GetVirtualPixelRatio();
3267 CalculateStartRectExceptHotZone(vpr);
3268 if (IsPointInDragHotZone(mousePointX, mousePointY, sourceType) &&
3269 property_->GetMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) {
3270 newStyleID = CalculatePointerDirection(mousePointX, mousePointY);
3271 } else if (action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) {
3272 newStyleID = MMI::MOUSE_ICON::DEFAULT;
3273 }
3274 } else if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
3275 newStyleID = (GetRect().width_ > GetRect().height_) ?
3276 MMI::MOUSE_ICON::NORTH_SOUTH : MMI::MOUSE_ICON::WEST_EAST;
3277 if (action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) {
3278 newStyleID = MMI::MOUSE_ICON::DEFAULT; // when receive up event, set default style
3279 }
3280 }
3281 TLOGD(WmsLogTag::WMS_EVENT, "winId:%{public}u, Mouse posX:%{private}u, posY:%{private}u, action:%{public}u, "
3282 "winRect posX:%{public}u, posY:%{public}u, W:%{public}u, H:%{public}u, "
3283 "newStyle:%{public}u, oldStyle:%{public}u",
3284 windowId, mousePointX, mousePointY, action, GetRect().posX_,
3285 GetRect().posY_, GetRect().width_, GetRect().height_, newStyleID, oldStyleID);
3286 if (oldStyleID != newStyleID) {
3287 MMI::PointerStyle pointerStyle;
3288 pointerStyle.id = static_cast<int32_t>(newStyleID);
3289 int32_t res = MMI::InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
3290 if (res != 0) {
3291 WLOGFE("set pointer style failed, res is %{public}u", res);
3292 return;
3293 }
3294 mouseStyleID_ = newStyleID;
3295 }
3296 }
3297
PerfLauncherHotAreaIfNeed(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3298 void WindowImpl::PerfLauncherHotAreaIfNeed(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3299 {
3300 #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
3301 int32_t action = pointerEvent->GetPointerAction();
3302 if (action != MMI::PointerEvent::POINTER_ACTION_CANCEL) {
3303 return;
3304 }
3305 MMI::PointerEvent::PointerItem pointerItem;
3306 int32_t pointId = pointerEvent->GetPointerId();
3307 if (!pointerEvent->GetPointerItem(pointId, pointerItem)) {
3308 WLOGFW("invalid pointerEvent");
3309 return;
3310 }
3311 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3312 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
3313 if (display == nullptr) {
3314 return;
3315 }
3316 auto displayHeight = display->GetHeight();
3317 constexpr float HOT_RATE = 0.07;
3318 auto height = static_cast<int32_t>(displayHeight * HOT_RATE);
3319 int32_t pointDisplayY = pointerItem.GetDisplayY();
3320 if (pointDisplayY > displayHeight - height) {
3321 ResSchedReport::GetInstance().AnimationBoost();
3322 }
3323 #endif
3324 }
3325
ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)3326 void WindowImpl::ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
3327 {
3328 // If windowRect transformed, transform event back to its origin position
3329 if (property_) {
3330 property_->UpdatePointerEvent(pointerEvent);
3331 }
3332 int32_t action = pointerEvent->GetPointerAction();
3333 if (action == MMI::PointerEvent::POINTER_ACTION_MOVE || action == MMI::PointerEvent::POINTER_ACTION_DOWN ||
3334 action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
3335 ResSchedReport::GetInstance().TrigSlide(GetType(), true);
3336 }
3337 if (action == MMI::PointerEvent::POINTER_ACTION_UP || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP ||
3338 action == MMI::PointerEvent::POINTER_ACTION_CANCEL) {
3339 ResSchedReport::GetInstance().TrigSlide(GetType(), false);
3340 }
3341 if ((action == MMI::PointerEvent::POINTER_ACTION_MOVE || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) &&
3342 pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
3343 HandlePointerStyle(pointerEvent);
3344 }
3345 PerfLauncherHotAreaIfNeed(pointerEvent);
3346 if (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
3347 WLOGFD("WMS process point down, id:%{public}u, action: %{public}d", GetWindowId(), action);
3348 if (GetType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) {
3349 MMI::PointerEvent::PointerItem pointerItem;
3350 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
3351 WLOGFW("Point item is invalid");
3352 pointerEvent->MarkProcessed();
3353 return;
3354 }
3355 if (!WindowHelper::IsPointInTargetRect(pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), GetRect())) {
3356 NotifyAfterUnfocused(false);
3357 pointerEvent->MarkProcessed();
3358 return;
3359 }
3360 }
3361 if (property_ != nullptr) {
3362 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId());
3363 }
3364 }
3365
3366 // If point event type is up, should reset start move flag
3367 if (WindowHelper::IsMainFloatingWindow(GetType(), GetMode()) || GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE ||
3368 (action == MMI::PointerEvent::POINTER_ACTION_UP || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP ||
3369 action == MMI::PointerEvent::POINTER_ACTION_CANCEL)) {
3370 ConsumeMoveOrDragEvent(pointerEvent);
3371 }
3372
3373 if (IsPointerEventConsumed()) {
3374 pointerEvent->MarkProcessed();
3375 return;
3376 }
3377
3378 TransferPointerEvent(pointerEvent);
3379 }
3380
RequestVsync(const std::shared_ptr<VsyncCallback> & vsyncCallback)3381 void WindowImpl::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
3382 {
3383 std::lock_guard<std::recursive_mutex> lock(mutex_);
3384 if (state_ == WindowState::STATE_DESTROYED) {
3385 WLOGFE("[WM] Receive Vsync Request failed, window is destroyed");
3386 return;
3387 }
3388
3389 if (!SingletonContainer::IsDestroyed() && vsyncStation_ != nullptr) {
3390 vsyncStation_->RequestVsync(vsyncCallback);
3391 }
3392 }
3393
GetVSyncPeriod()3394 int64_t WindowImpl::GetVSyncPeriod()
3395 {
3396 std::lock_guard<std::recursive_mutex> lock(mutex_);
3397 if (!SingletonContainer::IsDestroyed() && vsyncStation_ != nullptr) {
3398 return vsyncStation_->GetVSyncPeriod();
3399 }
3400 return 0;
3401 }
3402
UpdateFocusStatus(bool focused)3403 void WindowImpl::UpdateFocusStatus(bool focused)
3404 {
3405 if (!IsWindowValid()) {
3406 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
3407 return;
3408 }
3409
3410 WLOGFD("IsFocused: %{public}d, id: %{public}u", focused, property_->GetWindowId());
3411 isFocused_ = focused;
3412 if (focused) {
3413 HiSysEventWrite(
3414 OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER,
3415 "FOCUS_WINDOW",
3416 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
3417 "PID", getpid(),
3418 "UID", getuid(),
3419 "BUNDLE_NAME", property_->GetAbilityInfo().bundleName_);
3420 if (state_ <= WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
3421 needNotifyFocusLater_ = true;
3422 return;
3423 }
3424 NotifyAfterFocused();
3425 } else {
3426 NotifyAfterUnfocused();
3427 }
3428 }
3429
IsFocused() const3430 bool WindowImpl::IsFocused() const
3431 {
3432 if (!IsWindowValid()) {
3433 TLOGE(WmsLogTag::DEFAULT, "Window is invalid");
3434 return false;
3435 }
3436
3437 return isFocused_;
3438 }
3439
UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration> & configuration)3440 void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
3441 {
3442 if (uiContent_ != nullptr) {
3443 WLOGFD("notify ace winId:%{public}u", GetWindowId());
3444 uiContent_->UpdateConfiguration(configuration);
3445 }
3446 if (subWindowMap_.count(GetWindowId()) == 0) {
3447 return;
3448 }
3449 for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
3450 subWindow->UpdateConfiguration(configuration);
3451 }
3452 }
3453
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)3454 void WindowImpl::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
3455 {
3456 WLOGI("Update AvoidArea, id: %{public}u", property_->GetWindowId());
3457 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3458 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
3459 UpdateViewportConfig(GetRect(), display, WindowSizeChangeReason::UNDEFINED, nullptr, {{type, *avoidArea}});
3460 NotifyAvoidAreaChange(avoidArea, type);
3461 }
3462
UpdateViewportConfig(const Rect & rect,const sptr<Display> & display,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction,const std::map<AvoidAreaType,AvoidArea> & avoidAreas)3463 void WindowImpl::UpdateViewportConfig(const Rect& rect, const sptr<Display>& display, WindowSizeChangeReason reason,
3464 const std::shared_ptr<RSTransaction>& rsTransaction,
3465 const std::map<AvoidAreaType, AvoidArea>& avoidAreas)
3466 {
3467 std::lock_guard<std::recursive_mutex> lock(mutex_);
3468 if (uiContent_ == nullptr) {
3469 return;
3470 }
3471 Ace::ViewportConfig config;
3472 config.SetSize(rect.width_, rect.height_);
3473 config.SetPosition(rect.posX_, rect.posY_);
3474 if (display) {
3475 config.SetDensity(display->GetVirtualPixelRatio());
3476 auto displayInfo = display->GetDisplayInfo();
3477 if (displayInfo != nullptr) {
3478 config.SetOrientation(static_cast<int32_t>(displayInfo->GetDisplayOrientation()));
3479 }
3480 }
3481 uiContent_->UpdateViewportConfig(config, reason, rsTransaction, avoidAreas);
3482 WLOGFD("Id:%{public}u, windowRect:[%{public}d, %{public}d, %{public}u, %{public}u]",
3483 property_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_);
3484 }
3485
UpdateDecorEnable(bool needNotify)3486 void WindowImpl::UpdateDecorEnable(bool needNotify)
3487 {
3488 WLOGFD("Start");
3489 if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
3490 bool enable = windowSystemConfig_.isSystemDecorEnable_ &&
3491 WindowHelper::IsWindowModeSupported(windowSystemConfig_.decorWindowModeSupportType_, GetMode());
3492 WLOGFD("Decor enable: %{public}d", static_cast<int32_t>(enable));
3493 property_->SetDecorEnable(enable);
3494 } else {
3495 property_->SetDecorEnable(false);
3496 }
3497 if (needNotify) {
3498 if (uiContent_ != nullptr) {
3499 uiContent_->UpdateWindowMode(GetMode(), property_->GetDecorEnable());
3500 WLOGFD("Notify uiContent window mode change end");
3501 }
3502 NotifyModeChange(GetMode(), property_->GetDecorEnable());
3503 }
3504 }
3505
UpdateWindowStateUnfrozen()3506 void WindowImpl::UpdateWindowStateUnfrozen()
3507 {
3508 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
3509 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3510 WLOGFD("DoAbilityForeground KEYGUARD, id: %{public}u", GetWindowId());
3511 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityForeground(abilityContext->GetToken(),
3512 static_cast<uint32_t>(WindowStateChangeReason::KEYGUARD));
3513 } else if (state_ != WindowState::STATE_SHOWN) {
3514 state_ = WindowState::STATE_SHOWN;
3515 NotifyAfterForeground();
3516 }
3517 }
3518
UpdateWindowState(WindowState state)3519 void WindowImpl::UpdateWindowState(WindowState state)
3520 {
3521 WLOGFI("id: %{public}u, State to set:%{public}u", GetWindowId(), state);
3522 if (!IsWindowValid()) {
3523 return;
3524 }
3525 auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context_);
3526 switch (state) {
3527 case WindowState::STATE_FROZEN: {
3528 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3529 WLOGFD("DoAbilityBackground KEYGUARD, id: %{public}u", GetWindowId());
3530 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityBackground(abilityContext->GetToken(),
3531 static_cast<uint32_t>(WindowStateChangeReason::KEYGUARD));
3532 } else {
3533 state_ = WindowState::STATE_FROZEN;
3534 NotifyAfterBackground(false, true);
3535 }
3536 break;
3537 }
3538 case WindowState::STATE_UNFROZEN: {
3539 UpdateWindowStateUnfrozen();
3540 break;
3541 }
3542 case WindowState::STATE_SHOWN: {
3543 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW) {
3544 WLOGFD("WindowState::STATE_SHOWN, id: %{public}u", GetWindowId());
3545 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityForeground(abilityContext->GetToken(),
3546 static_cast<uint32_t>(WindowStateChangeReason::TOGGLING));
3547 } else {
3548 state_ = WindowState::STATE_SHOWN;
3549 NotifyAfterForeground();
3550 }
3551 break;
3552 }
3553 case WindowState::STATE_HIDDEN: {
3554 if (abilityContext != nullptr && windowTag_ == WindowTag::MAIN_WINDOW &&
3555 state_ == WindowState::STATE_SHOWN) {
3556 WLOGFD("WindowState: STATE_SHOWN, id: %{public}u", GetWindowId());
3557 AAFwk::AbilityManagerClient::GetInstance()->DoAbilityBackground(abilityContext->GetToken(),
3558 static_cast<uint32_t>(WindowStateChangeReason::NORMAL));
3559 } else {
3560 Hide(static_cast<uint32_t>(WindowStateChangeReason::NORMAL), false);
3561 }
3562 break;
3563 }
3564 default: {
3565 WLOGFE("windowState to set is invalid");
3566 break;
3567 }
3568 }
3569 }
3570
UpdateWindowStateWhenShow()3571 WmErrorCode WindowImpl::UpdateWindowStateWhenShow()
3572 {
3573 state_ = WindowState::STATE_SHOWN;
3574 if (WindowHelper::IsMainWindow(property_->GetWindowType()) ||
3575 WindowHelper::IsSystemMainWindow(property_->GetWindowType())) {
3576 // update subwindow subWindowState_ and notify subwindow shown or not
3577 UpdateSubWindowStateAndNotify(GetWindowId());
3578 NotifyAfterForeground();
3579 } else if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
3580 subWindowState_ = WindowState::STATE_SHOWN;
3581 NotifyAfterForeground();
3582 } else {
3583 uint32_t parentId = property_->GetParentId();
3584 sptr<Window> parentWindow = FindWindowById(parentId);
3585 if (parentWindow == nullptr) {
3586 WLOGE("parent window is null");
3587 return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
3588 }
3589 if (parentWindow->GetWindowState() == WindowState::STATE_HIDDEN) {
3590 // not notify user shown and update subwindowState_
3591 subWindowState_ = WindowState::STATE_HIDDEN;
3592 } else if (parentWindow->GetWindowState() == WindowState::STATE_SHOWN) {
3593 NotifyAfterForeground();
3594 subWindowState_ = WindowState::STATE_SHOWN;
3595 }
3596 }
3597 if (needNotifyFocusLater_ && isFocused_) {
3598 UpdateFocusStatus(true);
3599 }
3600 return WmErrorCode::WM_OK;
3601 }
3602
UpdateWindowStateWhenHide()3603 WmErrorCode WindowImpl::UpdateWindowStateWhenHide()
3604 {
3605 state_ = WindowState::STATE_HIDDEN;
3606 if (WindowHelper::IsSystemMainWindow(property_->GetWindowType()) ||
3607 WindowHelper::IsMainWindow(property_->GetWindowType())) {
3608 // main window need to update subwindow subWindowState_ and notify subwindow shown or not
3609 UpdateSubWindowStateAndNotify(GetWindowId());
3610 NotifyAfterBackground();
3611 } else if (GetType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
3612 subWindowState_ = WindowState::STATE_HIDDEN;
3613 NotifyAfterBackground();
3614 } else {
3615 uint32_t parentId = property_->GetParentId();
3616 sptr<Window> parentWindow = FindWindowById(parentId);
3617 if (parentWindow == nullptr) {
3618 WLOGE("parent window is null");
3619 return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
3620 }
3621 if (subWindowState_ == WindowState::STATE_SHOWN) {
3622 NotifyAfterBackground();
3623 }
3624 subWindowState_ = WindowState::STATE_HIDDEN;
3625 }
3626 return WmErrorCode::WM_OK;
3627 }
3628
UpdateSubWindowStateAndNotify(uint32_t parentId)3629 WmErrorCode WindowImpl::UpdateSubWindowStateAndNotify(uint32_t parentId)
3630 {
3631 if (subWindowMap_.find(parentId) == subWindowMap_.end()) {
3632 WLOGFD("main window: %{public}u has no child node", parentId);
3633 return WmErrorCode::WM_OK;
3634 }
3635 std::vector<sptr<WindowImpl>> subWindows = subWindowMap_[parentId];
3636 if (subWindows.empty()) {
3637 WLOGFD("main window: %{public}u, its subWindowMap is empty", parentId);
3638 return WmErrorCode::WM_OK;
3639 }
3640 // when main window hide and subwindow whose state is shown should hide and notify user
3641 if (state_ == WindowState::STATE_HIDDEN) {
3642 for (auto subwindow : subWindows) {
3643 if (subwindow->GetWindowState() == WindowState::STATE_SHOWN &&
3644 subwindow->subWindowState_ == WindowState::STATE_SHOWN) {
3645 subwindow->NotifyAfterBackground();
3646 }
3647 subwindow->subWindowState_ = WindowState::STATE_HIDDEN;
3648 }
3649 // when main window show and subwindow whose state is shown should show and notify user
3650 } else if (state_ == WindowState::STATE_SHOWN) {
3651 for (auto subwindow : subWindows) {
3652 if (subwindow->GetWindowState() == WindowState::STATE_SHOWN &&
3653 subwindow->subWindowState_ == WindowState::STATE_HIDDEN) {
3654 subwindow->NotifyAfterForeground();
3655 subwindow->subWindowState_ = WindowState::STATE_SHOWN;
3656 } else {
3657 subwindow->subWindowState_ = WindowState::STATE_HIDDEN;
3658 }
3659 }
3660 }
3661 return WmErrorCode::WM_OK;
3662 }
3663
GetWindowProperty()3664 sptr<WindowProperty> WindowImpl::GetWindowProperty()
3665 {
3666 return property_;
3667 }
3668
RestoreSplitWindowMode(uint32_t mode)3669 void WindowImpl::RestoreSplitWindowMode(uint32_t mode)
3670 {
3671 if (!IsWindowValid()) {
3672 return;
3673 }
3674 auto windowMode = static_cast<WindowMode>(mode);
3675 if (windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) {
3676 UpdateMode(windowMode);
3677 }
3678 }
3679
UpdateDragEvent(const PointInfo & point,DragEvent event)3680 void WindowImpl::UpdateDragEvent(const PointInfo& point, DragEvent event)
3681 {
3682 NotifyDragEvent(point, event);
3683 }
3684
NotifyDragEvent(const PointInfo & point,DragEvent event)3685 void WindowImpl::NotifyDragEvent(const PointInfo& point, DragEvent event)
3686 {
3687 auto windowDragListeners = GetListeners<IWindowDragListener>();
3688 Rect rect = GetRect();
3689 for (auto& listener : windowDragListeners) {
3690 if (listener != nullptr) {
3691 listener->OnDrag(point.x - rect.posX_, point.y - rect.posY_, event);
3692 }
3693 }
3694 }
3695
UpdateDisplayId(DisplayId from,DisplayId to)3696 void WindowImpl::UpdateDisplayId(DisplayId from, DisplayId to)
3697 {
3698 WLOGFD("update displayId. win %{public}u", GetWindowId());
3699 NotifyDisplayMoveChange(from, to);
3700 property_->SetDisplayId(to);
3701 }
3702
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)3703 void WindowImpl::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info,
3704 const std::shared_ptr<RSTransaction>& rsTransaction)
3705 {
3706 WLOGFD("Update OccupiedArea, id: %{public}u", property_->GetWindowId());
3707 NotifyOccupiedAreaChange(info, rsTransaction);
3708 }
3709
UpdateActiveStatus(bool isActive)3710 void WindowImpl::UpdateActiveStatus(bool isActive)
3711 {
3712 WLOGFD("window active status: %{public}d, id: %{public}u", isActive, property_->GetWindowId());
3713 if (isActive) {
3714 NotifyAfterActive();
3715 } else {
3716 NotifyAfterInactive();
3717 }
3718 }
3719
NotifyScreenshot()3720 void WindowImpl::NotifyScreenshot()
3721 {
3722 auto screenshotListeners = GetListeners<IScreenshotListener>();
3723 for (auto& screenshotListener : screenshotListeners) {
3724 if (screenshotListener != nullptr) {
3725 screenshotListener->OnScreenshot();
3726 }
3727 }
3728 }
3729
NotifyTouchOutside()3730 void WindowImpl::NotifyTouchOutside()
3731 {
3732 auto touchOutsideListeners = GetListeners<ITouchOutsideListener>();
3733 for (auto& touchOutsideListener : touchOutsideListeners) {
3734 if (touchOutsideListener != nullptr) {
3735 touchOutsideListener->OnTouchOutside();
3736 }
3737 }
3738 }
3739
NotifyTouchDialogTarget(int32_t posX,int32_t posY)3740 void WindowImpl::NotifyTouchDialogTarget(int32_t posX, int32_t posY)
3741 {
3742 SingletonContainer::Get<WindowAdapter>().ProcessPointDown(property_->GetWindowId());
3743 auto dialogTargetTouchListeners = GetListeners<IDialogTargetTouchListener>();
3744 for (auto& dialogTargetTouchListener : dialogTargetTouchListeners) {
3745 if (dialogTargetTouchListener != nullptr) {
3746 dialogTargetTouchListener->OnDialogTargetTouch();
3747 }
3748 }
3749 }
3750
NotifyDestroy()3751 void WindowImpl::NotifyDestroy()
3752 {
3753 auto dialogDeathRecipientListener = GetListener<IDialogDeathRecipientListener>();
3754 if (dialogDeathRecipientListener != nullptr) {
3755 dialogDeathRecipientListener->OnDialogDeathRecipient();
3756 }
3757 }
3758
NotifyForeground()3759 void WindowImpl::NotifyForeground()
3760 {
3761 NotifyAfterForeground();
3762 }
3763
NotifyBackground()3764 void WindowImpl::NotifyBackground()
3765 {
3766 NotifyAfterBackground();
3767 }
3768
NotifyForegroundInteractiveStatus(bool interactive)3769 void WindowImpl::NotifyForegroundInteractiveStatus(bool interactive)
3770 {
3771 WLOGFI("NotifyForegroundInteractiveStatus %{public}d", interactive);
3772 if (!IsWindowValid() || state_ != WindowState::STATE_SHOWN) {
3773 return;
3774 }
3775 if (interactive) {
3776 NotifyAfterResumed();
3777 } else {
3778 NotifyAfterPaused();
3779 }
3780 }
3781
TransformSurfaceNode(const Transform & trans)3782 void WindowImpl::TransformSurfaceNode(const Transform& trans)
3783 {
3784 if (surfaceNode_ == nullptr) {
3785 return;
3786 }
3787 surfaceNode_->SetPivotX(trans.pivotX_);
3788 surfaceNode_->SetPivotY(trans.pivotY_);
3789 surfaceNode_->SetScaleX(trans.scaleX_);
3790 surfaceNode_->SetScaleY(trans.scaleY_);
3791 surfaceNode_->SetTranslateX(trans.translateX_);
3792 surfaceNode_->SetTranslateY(trans.translateY_);
3793 surfaceNode_->SetTranslateZ(trans.translateZ_);
3794 surfaceNode_->SetRotationX(trans.rotationX_);
3795 surfaceNode_->SetRotationY(trans.rotationY_);
3796 surfaceNode_->SetRotation(trans.rotationZ_);
3797 }
3798
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)3799 void WindowImpl::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
3800 {
3801 WLOGFD("%{public}s zoomTrans, pivotX:%{public}f, pivotY:%{public}f, scaleX:%{public}f, scaleY:%{public}f"
3802 ", transX:%{public}f, transY:%{public}f, transZ:%{public}f, rotateX:%{public}f, rotateY:%{public}f "
3803 "rotateZ:%{public}f", property_->GetWindowName().c_str(), trans.pivotX_, trans.pivotY_, trans.scaleX_,
3804 trans.scaleY_, trans.translateX_, trans.translateY_, trans.translateZ_, trans.rotationX_,
3805 trans.rotationY_, trans.rotationZ_);
3806 property_->SetZoomTransform(trans);
3807 property_->SetDisplayZoomState(isDisplayZoomOn);
3808 }
3809
ClearListenersById(uint32_t winId)3810 void WindowImpl::ClearListenersById(uint32_t winId)
3811 {
3812 std::lock_guard<std::recursive_mutex> lock(globalMutex_);
3813 ClearUselessListeners(screenshotListeners_, winId);
3814 ClearUselessListeners(touchOutsideListeners_, winId);
3815 ClearUselessListeners(dialogTargetTouchListeners_, winId);
3816 ClearUselessListeners(lifecycleListeners_, winId);
3817 ClearUselessListeners(windowChangeListeners_, winId);
3818 ClearUselessListeners(avoidAreaChangeListeners_, winId);
3819 ClearUselessListeners(occupiedAreaChangeListeners_, winId);
3820 ClearUselessListeners(dialogDeathRecipientListener_, winId);
3821 }
3822
NotifyAfterForeground(bool needNotifyListeners,bool needNotifyUiContent)3823 void WindowImpl::NotifyAfterForeground(bool needNotifyListeners, bool needNotifyUiContent)
3824 {
3825 if (needNotifyListeners) {
3826 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3827 CALL_LIFECYCLE_LISTENER(AfterForeground, lifecycleListeners);
3828 }
3829 if (needNotifyUiContent) {
3830 CALL_UI_CONTENT(Foreground);
3831 }
3832 }
3833
NotifyAfterBackground(bool needNotifyListeners,bool needNotifyUiContent)3834 void WindowImpl::NotifyAfterBackground(bool needNotifyListeners, bool needNotifyUiContent)
3835 {
3836 if (needNotifyListeners) {
3837 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3838 CALL_LIFECYCLE_LISTENER(AfterBackground, lifecycleListeners);
3839 }
3840 if (needNotifyUiContent) {
3841 CALL_UI_CONTENT(Background);
3842 }
3843 }
3844
NotifyAfterFocused()3845 void WindowImpl::NotifyAfterFocused()
3846 {
3847 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3848 CALL_LIFECYCLE_LISTENER(AfterFocused, lifecycleListeners);
3849 CALL_UI_CONTENT(Focus);
3850 }
3851
NotifyAfterUnfocused(bool needNotifyUiContent)3852 void WindowImpl::NotifyAfterUnfocused(bool needNotifyUiContent)
3853 {
3854 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3855 // use needNotifyUinContent to separate ui content callbacks
3856 CALL_LIFECYCLE_LISTENER(AfterUnfocused, lifecycleListeners);
3857 if (needNotifyUiContent) {
3858 CALL_UI_CONTENT(UnFocus);
3859 }
3860 }
3861
NotifyAfterResumed()3862 void WindowImpl::NotifyAfterResumed()
3863 {
3864 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3865 CALL_LIFECYCLE_LISTENER(AfterResumed, lifecycleListeners);
3866 }
3867
NotifyAfterPaused()3868 void WindowImpl::NotifyAfterPaused()
3869 {
3870 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3871 CALL_LIFECYCLE_LISTENER(AfterPaused, lifecycleListeners);
3872 }
3873
NotifyBeforeDestroy(std::string windowName)3874 void WindowImpl::NotifyBeforeDestroy(std::string windowName)
3875 {
3876 std::lock_guard<std::recursive_mutex> lock(mutex_);
3877 if (uiContent_ != nullptr) {
3878 auto uiContent = std::move(uiContent_);
3879 uiContent_ = nullptr;
3880 uiContent->Destroy();
3881 }
3882 if (notifyNativefunc_) {
3883 notifyNativefunc_(windowName);
3884 }
3885 }
3886
NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)3887 void WindowImpl::NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)
3888 {
3889 auto uiContent = window->GetUIContent();
3890 if (uiContent != nullptr) {
3891 uiContent->Destroy();
3892 }
3893 if (window->GetNativeDestroyCallback()) {
3894 window->GetNativeDestroyCallback()(window->GetWindowName());
3895 }
3896 }
3897
NotifyAfterActive()3898 void WindowImpl::NotifyAfterActive()
3899 {
3900 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3901 CALL_LIFECYCLE_LISTENER(AfterActive, lifecycleListeners);
3902 }
3903
NotifyAfterInactive()3904 void WindowImpl::NotifyAfterInactive()
3905 {
3906 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3907 CALL_LIFECYCLE_LISTENER(AfterInactive, lifecycleListeners);
3908 }
3909
NotifyForegroundFailed(WMError ret)3910 void WindowImpl::NotifyForegroundFailed(WMError ret)
3911 {
3912 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3913 CALL_LIFECYCLE_LISTENER_WITH_PARAM(ForegroundFailed, lifecycleListeners, static_cast<int32_t>(ret));
3914 }
3915
NotifyBackgroundFailed(WMError ret)3916 void WindowImpl::NotifyBackgroundFailed(WMError ret)
3917 {
3918 auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
3919 CALL_LIFECYCLE_LISTENER_WITH_PARAM(BackgroundFailed, lifecycleListeners, static_cast<int32_t>(ret));
3920 }
3921
IsStretchableReason(WindowSizeChangeReason reason)3922 bool WindowImpl::IsStretchableReason(WindowSizeChangeReason reason)
3923 {
3924 return reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END ||
3925 reason == WindowSizeChangeReason::DRAG_START || reason == WindowSizeChangeReason::RECOVER ||
3926 IsMoveToOrDragMove(reason) || reason == WindowSizeChangeReason::UNDEFINED;
3927 }
3928
NotifySizeChange(Rect rect,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)3929 void WindowImpl::NotifySizeChange(Rect rect, WindowSizeChangeReason reason,
3930 const std::shared_ptr<RSTransaction>& rsTransaction)
3931 {
3932 auto windowChangeListeners = GetListeners<IWindowChangeListener>();
3933 for (auto& listener : windowChangeListeners) {
3934 if (listener != nullptr) {
3935 listener->OnSizeChange(rect, reason, rsTransaction);
3936 }
3937 }
3938 }
3939
NotifyAvoidAreaChange(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)3940 void WindowImpl::NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
3941 {
3942 auto avoidAreaChangeListeners = GetListeners<IAvoidAreaChangedListener>();
3943 for (auto& listener : avoidAreaChangeListeners) {
3944 if (listener != nullptr) {
3945 listener->OnAvoidAreaChanged(*avoidArea, type);
3946 }
3947 }
3948 }
3949
NotifyDisplayMoveChange(DisplayId from,DisplayId to)3950 void WindowImpl::NotifyDisplayMoveChange(DisplayId from, DisplayId to)
3951 {
3952 auto displayMoveListeners = GetListeners<IDisplayMoveListener>();
3953 for (auto& listener : displayMoveListeners) {
3954 if (listener != nullptr) {
3955 listener->OnDisplayMove(from, to);
3956 }
3957 }
3958 }
3959
NotifyModeChange(WindowMode mode,bool hasDeco)3960 void WindowImpl::NotifyModeChange(WindowMode mode, bool hasDeco)
3961 {
3962 auto windowChangeListeners = GetListeners<IWindowChangeListener>();
3963 for (auto& listener : windowChangeListeners) {
3964 if (listener != nullptr) {
3965 listener->OnModeChange(mode, hasDeco);
3966 }
3967 }
3968 }
3969
NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)3970 void WindowImpl::NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo>& info,
3971 const std::shared_ptr<RSTransaction>& rsTransaction)
3972 {
3973 auto occupiedAreaChangeListeners = GetListeners<IOccupiedAreaChangeListener>();
3974 for (auto& listener : occupiedAreaChangeListeners) {
3975 if (listener != nullptr) {
3976 listener->OnSizeChange(info, rsTransaction);
3977 }
3978 }
3979 }
3980
SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel)3981 void WindowImpl::SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel)
3982 {
3983 needRemoveWindowInputChannel_ = needRemoveWindowInputChannel;
3984 }
3985
GetSystemAlarmWindowDefaultSize(Rect defaultRect)3986 Rect WindowImpl::GetSystemAlarmWindowDefaultSize(Rect defaultRect)
3987 {
3988 auto display = SingletonContainer::IsDestroyed() ? nullptr :
3989 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
3990 if (display == nullptr) {
3991 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
3992 property_->GetWindowId());
3993 return defaultRect;
3994 }
3995 uint32_t width = static_cast<uint32_t>(display->GetWidth());
3996 uint32_t height = static_cast<uint32_t>(display->GetHeight());
3997 WLOGFD("width:%{public}u, height:%{public}u, displayId:%{public}" PRIu64"",
3998 width, height, property_->GetDisplayId());
3999 uint32_t alarmWidth = static_cast<uint32_t>((static_cast<float>(width) *
4000 SYSTEM_ALARM_WINDOW_WIDTH_RATIO));
4001 uint32_t alarmHeight = static_cast<uint32_t>((static_cast<float>(height) *
4002 SYSTEM_ALARM_WINDOW_HEIGHT_RATIO));
4003
4004 Rect rect = { static_cast<int32_t>((width - alarmWidth) / 2), static_cast<int32_t>((height - alarmHeight) / 2),
4005 alarmWidth, alarmHeight }; // divided by 2 to middle the window
4006 return rect;
4007 }
4008
SetDefaultOption()4009 void WindowImpl::SetDefaultOption()
4010 {
4011 switch (property_->GetWindowType()) {
4012 case WindowType::WINDOW_TYPE_STATUS_BAR:
4013 case WindowType::WINDOW_TYPE_NAVIGATION_BAR:
4014 case WindowType::WINDOW_TYPE_VOLUME_OVERLAY:
4015 case WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT:
4016 case WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR: {
4017 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4018 property_->SetFocusable(false);
4019 break;
4020 }
4021 case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: {
4022 property_->SetRequestRect(GetSystemAlarmWindowDefaultSize(property_->GetRequestRect()));
4023 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4024 break;
4025 }
4026 case WindowType::WINDOW_TYPE_KEYGUARD: {
4027 RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
4028 property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
4029 break;
4030 }
4031 case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: {
4032 property_->SetWindowFlags(0);
4033 break;
4034 }
4035 case WindowType::WINDOW_TYPE_APP_COMPONENT: {
4036 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4037 property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::NONE));
4038 break;
4039 }
4040 case WindowType::WINDOW_TYPE_TOAST:
4041 case WindowType::WINDOW_TYPE_FLOAT:
4042 case WindowType::WINDOW_TYPE_SYSTEM_FLOAT:
4043 case WindowType::WINDOW_TYPE_FLOAT_CAMERA:
4044 case WindowType::WINDOW_TYPE_VOICE_INTERACTION:
4045 case WindowType::WINDOW_TYPE_LAUNCHER_DOCK:
4046 case WindowType::WINDOW_TYPE_SEARCHING_BAR:
4047 case WindowType::WINDOW_TYPE_SCREENSHOT:
4048 case WindowType::WINDOW_TYPE_GLOBAL_SEARCH:
4049 case WindowType::WINDOW_TYPE_DIALOG: {
4050 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4051 break;
4052 }
4053 case WindowType::WINDOW_TYPE_BOOT_ANIMATION:
4054 case WindowType::WINDOW_TYPE_POINTER: {
4055 property_->SetFocusable(false);
4056 break;
4057 }
4058 case WindowType::WINDOW_TYPE_DOCK_SLICE: {
4059 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4060 property_->SetFocusable(false);
4061 break;
4062 }
4063 case WindowType::WINDOW_TYPE_SYSTEM_TOAST: {
4064 property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
4065 property_->SetTouchable(false);
4066 property_->SetFocusable(false);
4067 break;
4068 }
4069 default:
4070 break;
4071 }
4072 }
4073
IsWindowValid() const4074 bool WindowImpl::IsWindowValid() const
4075 {
4076 bool res = ((state_ > WindowState::STATE_INITIAL) && (state_ < WindowState::STATE_BOTTOM));
4077 if (!res) {
4078 WLOGW("already destroyed or not created! id: %{public}u", GetWindowId());
4079 }
4080 return res;
4081 }
4082
IsLayoutFullScreen() const4083 bool WindowImpl::IsLayoutFullScreen() const
4084 {
4085 if (!IsWindowValid()) {
4086 return false;
4087 }
4088 auto mode = GetMode();
4089 return (mode == WindowMode::WINDOW_MODE_FULLSCREEN && isIgnoreSafeArea_);
4090 }
4091
IsFullScreen() const4092 bool WindowImpl::IsFullScreen() const
4093 {
4094 if (!IsWindowValid()) {
4095 return false;
4096 }
4097 auto statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
4098 auto naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
4099 return (IsLayoutFullScreen() && !statusProperty.enable_ && !naviProperty.enable_);
4100 }
4101
SetRequestedOrientation(Orientation orientation)4102 void WindowImpl::SetRequestedOrientation(Orientation orientation)
4103 {
4104 if (!IsWindowValid()) {
4105 TLOGE(WmsLogTag::DEFAULT, "window is invalid");
4106 return;
4107 }
4108 if (property_->GetRequestedOrientation() == orientation) {
4109 return;
4110 }
4111 property_->SetRequestedOrientation(orientation);
4112 if (state_ == WindowState::STATE_SHOWN) {
4113 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ORIENTATION);
4114 }
4115 }
4116
GetRequestedOrientation()4117 Orientation WindowImpl::GetRequestedOrientation()
4118 {
4119 if (!IsWindowValid()) {
4120 TLOGE(WmsLogTag::DEFAULT, "window is invalid");
4121 return Orientation::UNSPECIFIED;
4122 }
4123 return property_->GetRequestedOrientation();
4124 }
4125
SetTouchHotAreas(const std::vector<Rect> & rects)4126 WMError WindowImpl::SetTouchHotAreas(const std::vector<Rect>& rects)
4127 {
4128 std::vector<Rect> lastTouchHotAreas;
4129 property_->GetTouchHotAreas(lastTouchHotAreas);
4130
4131 property_->SetTouchHotAreas(rects);
4132 WMError result = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
4133 if (result != WMError::WM_OK) {
4134 property_->SetTouchHotAreas(lastTouchHotAreas);
4135 }
4136 return result;
4137 }
4138
GetRequestedTouchHotAreas(std::vector<Rect> & rects) const4139 void WindowImpl::GetRequestedTouchHotAreas(std::vector<Rect>& rects) const
4140 {
4141 property_->GetTouchHotAreas(rects);
4142 }
4143
SetAPPWindowLabel(const std::string & label)4144 WMError WindowImpl::SetAPPWindowLabel(const std::string& label)
4145 {
4146 if (uiContent_ == nullptr) {
4147 WLOGFE("uicontent is empty");
4148 return WMError::WM_ERROR_NULLPTR;
4149 }
4150 uiContent_->SetAppWindowTitle(label);
4151 WLOGI("Set app window label success, label : %{public}s", label.c_str());
4152 return WMError::WM_OK;
4153 }
4154
SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap> & icon)4155 WMError WindowImpl::SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon)
4156 {
4157 if (icon == nullptr) {
4158 WLOGFE("window icon is empty");
4159 return WMError::WM_ERROR_NULLPTR;
4160 }
4161 if (uiContent_ == nullptr) {
4162 WLOGFE("uicontent is empty");
4163 return WMError::WM_ERROR_NULLPTR;
4164 }
4165 uiContent_->SetAppWindowIcon(icon);
4166 WLOGI("Set app window icon success");
4167 return WMError::WM_OK;
4168 }
4169
CheckCameraFloatingWindowMultiCreated(WindowType type)4170 bool WindowImpl::CheckCameraFloatingWindowMultiCreated(WindowType type)
4171 {
4172 if (type != WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
4173 return false;
4174 }
4175
4176 for (auto& winPair : windowMap_) {
4177 if (winPair.second.second->GetType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
4178 return true;
4179 }
4180 }
4181 uint32_t accessTokenId = static_cast<uint32_t>(IPCSkeleton::GetCallingTokenID());
4182 property_->SetAccessTokenId(accessTokenId);
4183 TLOGI(WmsLogTag::DEFAULT, "Create camera float window, TokenId = %{private}u", accessTokenId);
4184 return false;
4185 }
4186
SetCornerRadius(float cornerRadius)4187 WMError WindowImpl::SetCornerRadius(float cornerRadius)
4188 {
4189 WLOGI("Window %{public}s set corner radius %{public}f", name_.c_str(), cornerRadius);
4190 surfaceNode_->SetCornerRadius(cornerRadius);
4191 RSTransaction::FlushImplicitTransaction();
4192 return WMError::WM_OK;
4193 }
4194
SetShadowRadius(float radius)4195 WMError WindowImpl::SetShadowRadius(float radius)
4196 {
4197 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4198 WLOGFE("set shadow radius permission denied!");
4199 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4200 }
4201 WLOGI("Window %{public}s set shadow radius %{public}f", name_.c_str(), radius);
4202 if (MathHelper::LessNotEqual(radius, 0.0)) {
4203 return WMError::WM_ERROR_INVALID_PARAM;
4204 }
4205 surfaceNode_->SetShadowRadius(radius);
4206 RSTransaction::FlushImplicitTransaction();
4207 return WMError::WM_OK;
4208 }
4209
SetShadowColor(std::string color)4210 WMError WindowImpl::SetShadowColor(std::string color)
4211 {
4212 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4213 WLOGFE("set shadow color permission denied!");
4214 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4215 }
4216 WLOGI("Window %{public}s set shadow color %{public}s", name_.c_str(), color.c_str());
4217 uint32_t colorValue;
4218 if (!ColorParser::Parse(color, colorValue)) {
4219 return WMError::WM_ERROR_INVALID_PARAM;
4220 }
4221 surfaceNode_->SetShadowColor(colorValue);
4222 RSTransaction::FlushImplicitTransaction();
4223 return WMError::WM_OK;
4224 }
4225
SetShadowOffsetX(float offsetX)4226 WMError WindowImpl::SetShadowOffsetX(float offsetX)
4227 {
4228 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4229 WLOGFE("set shadow offset x permission denied!");
4230 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4231 }
4232 WLOGI("Window %{public}s set shadow offsetX %{public}f", name_.c_str(), offsetX);
4233 surfaceNode_->SetShadowOffsetX(offsetX);
4234 RSTransaction::FlushImplicitTransaction();
4235 return WMError::WM_OK;
4236 }
4237
SetShadowOffsetY(float offsetY)4238 WMError WindowImpl::SetShadowOffsetY(float offsetY)
4239 {
4240 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4241 WLOGFE("set shadow offset y permission denied!");
4242 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4243 }
4244 WLOGI("Window %{public}s set shadow offsetY %{public}f", name_.c_str(), offsetY);
4245 surfaceNode_->SetShadowOffsetY(offsetY);
4246 RSTransaction::FlushImplicitTransaction();
4247 return WMError::WM_OK;
4248 }
4249
SetBlur(float radius)4250 WMError WindowImpl::SetBlur(float radius)
4251 {
4252 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4253 WLOGFE("set blur permission denied!");
4254 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4255 }
4256 WLOGI("Window %{public}s set blur radius %{public}f", name_.c_str(), radius);
4257 if (MathHelper::LessNotEqual(radius, 0.0)) {
4258 return WMError::WM_ERROR_INVALID_PARAM;
4259 }
4260 radius = ConvertRadiusToSigma(radius);
4261 WLOGFI("[Client] Window %{public}s set blur radius after conversion %{public}f", name_.c_str(), radius);
4262 surfaceNode_->SetFilter(RSFilter::CreateBlurFilter(radius, radius));
4263 RSTransaction::FlushImplicitTransaction();
4264 return WMError::WM_OK;
4265 }
4266
SetBackdropBlur(float radius)4267 WMError WindowImpl::SetBackdropBlur(float radius)
4268 {
4269 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4270 WLOGFE("set backdrop blur permission denied!");
4271 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4272 }
4273 WLOGI("Window %{public}s set backdrop 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 backdrop blur radius after conversion %{public}f", name_.c_str(), radius);
4279 surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(radius, radius));
4280 RSTransaction::FlushImplicitTransaction();
4281 return WMError::WM_OK;
4282 }
4283
SetBackdropBlurStyle(WindowBlurStyle blurStyle)4284 WMError WindowImpl::SetBackdropBlurStyle(WindowBlurStyle blurStyle)
4285 {
4286 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
4287 WLOGFE("set backdrop blur style permission denied!");
4288 return WMError::WM_ERROR_NOT_SYSTEM_APP;
4289 }
4290 WLOGI("Window %{public}s set backdrop blur style %{public}u", name_.c_str(), blurStyle);
4291 if (blurStyle < WindowBlurStyle::WINDOW_BLUR_OFF || blurStyle > WindowBlurStyle::WINDOW_BLUR_THICK) {
4292 return WMError::WM_ERROR_INVALID_PARAM;
4293 }
4294
4295 if (blurStyle == WindowBlurStyle::WINDOW_BLUR_OFF) {
4296 surfaceNode_->SetBackgroundFilter(nullptr);
4297 } else {
4298 auto display = SingletonContainer::IsDestroyed() ? nullptr :
4299 SingletonContainer::Get<DisplayManager>().GetDisplayById(property_->GetDisplayId());
4300 if (display == nullptr) {
4301 WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
4302 property_->GetWindowId());
4303 return WMError::WM_ERROR_INVALID_PARAM;
4304 }
4305 surfaceNode_->SetBackgroundFilter(RSFilter::CreateMaterialFilter(static_cast<int>(blurStyle),
4306 display->GetVirtualPixelRatio()));
4307 }
4308 RSTransaction::FlushImplicitTransaction();
4309 return WMError::WM_OK;
4310 }
4311
NotifyMemoryLevel(int32_t level)4312 WMError WindowImpl::NotifyMemoryLevel(int32_t level)
4313 {
4314 WLOGFD("id: %{public}u, notify memory level: %{public}d", property_->GetWindowId(), level);
4315 std::lock_guard<std::recursive_mutex> lock(mutex_);
4316 if (uiContent_ == nullptr) {
4317 WLOGFE("Window %{public}s notify memory level failed, ace is null.", name_.c_str());
4318 return WMError::WM_ERROR_NULLPTR;
4319 }
4320 // notify memory level
4321 uiContent_->NotifyMemoryLevel(level);
4322 return WMError::WM_OK;
4323 }
4324
IsAllowHaveSystemSubWindow()4325 bool WindowImpl::IsAllowHaveSystemSubWindow()
4326 {
4327 auto windowType = property_->GetWindowType();
4328 if (WindowHelper::IsSystemSubWindow(windowType) ||
4329 WindowHelper::IsSubWindow(windowType) ||
4330 windowType == WindowType::WINDOW_TYPE_DIALOG) {
4331 WLOGI("type %{public}u not allowed to add subwindow", windowType);
4332 return false;
4333 }
4334 return true;
4335 }
4336
SetNeedDefaultAnimation(bool needDefaultAnimation)4337 void WindowImpl::SetNeedDefaultAnimation(bool needDefaultAnimation)
4338 {
4339 needDefaultAnimation_= needDefaultAnimation;
4340 }
4341
SetTextFieldAvoidInfo(double textFieldPositionY,double textFieldHeight)4342 WMError WindowImpl::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight)
4343 {
4344 property_->SetTextFieldPositionY(textFieldPositionY);
4345 property_->SetTextFieldHeight(textFieldHeight);
4346 UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO);
4347 return WMError::WM_OK;
4348 }
4349 } // namespace Rosen
4350 } // namespace OHOS
4351