1 /*
2 * Copyright (c) 2021-2022 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_manager_service.h"
17
18 #include <thread>
19
20 #include <ability_manager_client.h>
21 #include <cinttypes>
22 #include <chrono>
23 #include <hisysevent.h>
24 #include <hitrace_meter.h>
25 #include <ipc_skeleton.h>
26 #include <parameters.h>
27 #include <rs_iwindow_animation_controller.h>
28 #include "scene_board_judgement.h"
29 #include <system_ability_definition.h>
30 #include <sstream>
31 #include "xcollie/watchdog.h"
32
33 #include "color_parser.h"
34 #include "display_manager_service_inner.h"
35 #include "dm_common.h"
36 #include "drag_controller.h"
37 #include "memory_guard.h"
38 #include "minimize_app.h"
39 #include "permission.h"
40 #include "persistent_storage.h"
41 #include "remote_animation.h"
42 #include "rs_adapter.h"
43 #include "singleton_container.h"
44 #include "starting_window.h"
45 #include "ui/rs_ui_director.h"
46 #include "window_helper.h"
47 #include "window_inner_manager.h"
48 #include "window_layout_policy.h"
49 #include "window_manager_agent_controller.h"
50 #include "window_manager_hilog.h"
51 #include "wm_common.h"
52 #include "wm_math.h"
53
54 namespace OHOS {
55 namespace Rosen {
56 namespace {
57 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WMS"};
58 }
59 WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService)
60
61 const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false :
62 SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<WindowManagerService>());
63 const std::string BOOTEVENT_WMS_READY = "bootevent.wms.ready";
64
WindowManagerService()65 WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true),
66 rsInterface_(RSInterfaces::GetInstance()),
67 windowShowPerformReport_(new PerformReporter("SHOW_WINDOW_TIME", {20, 35, 50}))
68 {
69 windowRoot_ = new WindowRoot(
__anon3076140d0202(Event event, const sptr<IRemoteObject>& remoteObject) 70 [this](Event event, const sptr<IRemoteObject>& remoteObject) { OnWindowEvent(event, remoteObject); });
71 inputWindowMonitor_ = new InputWindowMonitor(windowRoot_);
72 windowController_ = new WindowController(windowRoot_, inputWindowMonitor_);
73 dragController_ = new DragController(windowRoot_);
74 windowDumper_ = new WindowDumper(windowRoot_);
75 freezeDisplayController_ = new FreezeController();
76 windowCommonEvent_ = std::make_shared<WindowCommonEvent>();
77 startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled
78 windowGroupMgr_ = new WindowGroupMgr(windowRoot_);
79 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
80 return;
81 }
82 runner_ = AppExecFwk::EventRunner::Create(name_);
83 handler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
84 snapshotController_ = new SnapshotController(windowRoot_, handler_);
85 int ret = HiviewDFX::Watchdog::GetInstance().AddThread(name_, handler_);
86 if (ret != 0) {
87 WLOGFE("Add watchdog thread failed");
88 }
__anon3076140d0302() 89 handler_->PostTask([]() { MemoryGuard cacheGuard; }, "WindowManagerService:cacheGuard", 0,
90 AppExecFwk::EventQueue::Priority::IMMEDIATE);
91 // init RSUIDirector, it will handle animation callback
92 InitRSUIDirector();
93 }
94
OnStart()95 void WindowManagerService::OnStart()
96 {
97 WLOGI("start");
98 if (!Init()) {
99 WLOGFE("Init failed");
100 return;
101 }
102 WindowInnerManager::GetInstance().Start(system::GetParameter("persist.window.holder.enable", "0") == "1");
103 WindowInnerManager::GetInstance().StartWindowInfoReportLoop();
104 WindowInnerManager::GetInstance().SetWindowRoot(windowRoot_);
105 sptr<IDisplayChangeListener> listener = new DisplayChangeListener();
106 DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener);
107
108 sptr<IWindowInfoQueriedListener> windowInfoQueriedListener = new WindowInfoQueriedListener();
109 DisplayManagerServiceInner::GetInstance().RegisterWindowInfoQueriedListener(windowInfoQueriedListener);
110 system::SetParameter(BOOTEVENT_WMS_READY.c_str(), "true");
111 AddSystemAbilityListener(RENDER_SERVICE);
112 AddSystemAbilityListener(ABILITY_MGR_SERVICE_ID);
113 AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
114 AddSystemAbilityListener(MULTIMODAL_INPUT_SERVICE_ID);
115 sptr<WindowManagerService> wms = this;
116 wms->IncStrongRef(nullptr);
117 if (!Publish(sptr<WindowManagerService>(this))) {
118 WLOGFE("Publish failed");
119 }
120 WLOGI("end");
121 }
122
PostAsyncTask(Task task,const std::string & taskName,uint32_t delay)123 void WindowManagerService::PostAsyncTask(Task task, const std::string& taskName, uint32_t delay)
124 {
125 if (handler_) {
126 bool ret = handler_->PostTask(task, "wms:" + taskName, delay, AppExecFwk::EventQueue::Priority::IMMEDIATE);
127 if (!ret) {
128 WLOGFE("EventHandler PostTask Failed");
129 }
130 }
131 }
132
PostVoidSyncTask(Task task,const std::string & taskName)133 void WindowManagerService::PostVoidSyncTask(Task task, const std::string& taskName)
134 {
135 if (handler_) {
136 bool ret = handler_->PostSyncTask(task, "wms:" + taskName, AppExecFwk::EventQueue::Priority::IMMEDIATE);
137 if (!ret) {
138 WLOGFE("EventHandler PostVoidSyncTask Failed");
139 }
140 }
141 }
142
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)143 void WindowManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
144 {
145 WLOGI("systemAbilityId: %{public}d, start", systemAbilityId);
146 switch (systemAbilityId) {
147 case RENDER_SERVICE:
148 WLOGI("RENDER_SERVICE");
149 InitWithRanderServiceAdded();
150 break;
151 case ABILITY_MGR_SERVICE_ID:
152 WLOGI("ABILITY_MGR_SERVICE_ID");
153 InitWithAbilityManagerServiceAdded();
154 break;
155 case COMMON_EVENT_SERVICE_ID:
156 WLOGI("COMMON_EVENT_SERVICE_ID");
157 windowCommonEvent_->SubscriberEvent();
158 break;
159 case MULTIMODAL_INPUT_SERVICE_ID:
160 WLOGI("MULTIMODAL_INPUT_SERVICE_ID");
161 if (windowRoot_ == nullptr) {
162 WLOGFE("windowRoot_ is nullptr.");
163 return;
164 }
165 windowRoot_->NotifyMMIServiceOnline();
166 break;
167 default:
168 WLOGFW("unhandled sysabilityId: %{public}d", systemAbilityId);
169 break;
170 }
171 WLOGI("systemAbilityId: %{public}d, end", systemAbilityId);
172 }
173
SetWindowInputEventConsumer()174 void WindowManagerService::SetWindowInputEventConsumer()
175 {
176 WindowInnerManager::GetInstance().SetInputEventConsumer();
177 }
178
OnAccountSwitched(int accountId)179 void WindowManagerService::OnAccountSwitched(int accountId)
180 {
181 auto task = [this, accountId]() {
182 windowRoot_->RemoveSingleUserWindowNodes(accountId);
183 };
184 PostAsyncTask(task, "OnAccountSwitched");
185 WLOGI("called");
186 }
187
WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData)188 void WindowManagerService::WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData)
189 {
190 WLOGI("NotifyWindowVisibilityChange: enter");
191 std::weak_ptr<RSOcclusionData> weak(occlusionData);
192 auto task = [this, weak]() {
193 auto weakOcclusionData = weak.lock();
194 if (weakOcclusionData == nullptr) {
195 WLOGFE("weak occlusionData is nullptr");
196 return;
197 }
198 windowRoot_->NotifyWindowVisibilityChange(weakOcclusionData);
199 };
200 PostVoidSyncTask(task, "WindowVisibilityChangeCallback");
201 }
202
InitWithRanderServiceAdded()203 void WindowManagerService::InitWithRanderServiceAdded()
204 {
205 auto windowVisibilityChangeCb =
206 [this](std::shared_ptr<RSOcclusionData> occlusionData) { this->WindowVisibilityChangeCallback(occlusionData); };
207 WLOGI("RegisterWindowVisibilityChangeCallback");
208 if (rsInterface_.RegisterOcclusionChangeCallback(windowVisibilityChangeCb) != WM_OK) {
209 WLOGFE("RegisterWindowVisibilityChangeCallback failed");
210 }
211 }
212
InitWithAbilityManagerServiceAdded()213 void WindowManagerService::InitWithAbilityManagerServiceAdded()
214 {
215 if (snapshotController_ == nullptr) {
216 snapshotController_ = new SnapshotController(windowRoot_, handler_);
217 }
218 WLOGI("RegisterSnapshotHandler");
219 if (AAFwk::AbilityManagerClient::GetInstance()->RegisterSnapshotHandler(snapshotController_) != ERR_OK) {
220 WLOGFE("RegisterSnapshotHandler failed");
221 }
222
223 if (wmsHandler_ == nullptr) {
224 wmsHandler_ = new WindowManagerServiceHandler();
225 }
226 WLOGI("RegisterWindowManagerServiceHandler");
227 bool animaEnabled = RemoteAnimation::CheckAnimationController();
228 if (AAFwk::AbilityManagerClient::GetInstance()->RegisterWindowManagerServiceHandler(
229 wmsHandler_, animaEnabled) != ERR_OK) {
230 WLOGFE("RegisterWindowManagerServiceHandler failed");
231 }
232 }
233
NotifyWindowTransition(sptr<AAFwk::AbilityTransitionInfo> from,sptr<AAFwk::AbilityTransitionInfo> to,bool & animaEnabled)234 void WindowManagerServiceHandler::NotifyWindowTransition(
235 sptr<AAFwk::AbilityTransitionInfo> from, sptr<AAFwk::AbilityTransitionInfo> to, bool& animaEnabled)
236 {
237 sptr<WindowTransitionInfo> fromInfo = nullptr;
238 sptr<WindowTransitionInfo> toInfo = nullptr;
239 if (from) { // if exists, transition to window transition info
240 fromInfo = new WindowTransitionInfo(from);
241 }
242 if (to) {
243 toInfo = new WindowTransitionInfo(to);
244 }
245 animaEnabled = RemoteAnimation::CheckAnimationController();
246 WindowManagerService::GetInstance().NotifyWindowTransition(fromInfo, toInfo, false);
247 }
248
NotifyAnimationAbilityDied(sptr<AAFwk::AbilityTransitionInfo> info)249 void WindowManagerServiceHandler::NotifyAnimationAbilityDied(sptr<AAFwk::AbilityTransitionInfo> info)
250 {
251 sptr<WindowTransitionInfo> windowTransitionInfo = new WindowTransitionInfo(info);
252 WindowManagerService::GetInstance().NotifyAnimationAbilityDied(windowTransitionInfo);
253 }
254
GetFocusWindow(sptr<IRemoteObject> & abilityToken)255 int32_t WindowManagerServiceHandler::GetFocusWindow(sptr<IRemoteObject>& abilityToken)
256 {
257 return static_cast<int32_t>(WindowManagerService::GetInstance().GetFocusWindowInfo(abilityToken));
258 }
259
StartingWindow(sptr<AAFwk::AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap)260 void WindowManagerServiceHandler::StartingWindow(
261 sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap)
262 {
263 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "hot start is called");
264 sptr<WindowTransitionInfo> windowInfo = new WindowTransitionInfo(info);
265 WindowManagerService::GetInstance().StartingWindow(windowInfo, pixelMap, false);
266 }
267
StartingWindow(sptr<AAFwk::AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bgColor)268 void WindowManagerServiceHandler::StartingWindow(
269 sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor)
270 {
271 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "cold start is called");
272 sptr<WindowTransitionInfo> windowInfo = new WindowTransitionInfo(info);
273 WindowManagerService::GetInstance().StartingWindow(windowInfo, pixelMap, true, bgColor);
274 }
275
CancelStartingWindow(sptr<IRemoteObject> abilityToken)276 void WindowManagerServiceHandler::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
277 {
278 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "called");
279 WindowManagerService::GetInstance().CancelStartingWindow(abilityToken);
280 }
281
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)282 int32_t WindowManagerServiceHandler::MoveMissionsToForeground(const std::vector<int32_t>& missionIds,
283 int32_t topMissionId)
284 {
285 TLOGD(WmsLogTag::WMS_STARTUP_PAGE, "called");
286 return static_cast<int32_t>(WindowManagerService::GetInstance().MoveMissionsToForeground(missionIds, topMissionId));
287 }
288
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)289 int32_t WindowManagerServiceHandler::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
290 std::vector<int32_t>& result)
291 {
292 TLOGD(WmsLogTag::WMS_STARTUP_PAGE, "called");
293 return static_cast<int32_t>(WindowManagerService::GetInstance().MoveMissionsToBackground(missionIds, result));
294 }
295
Init()296 bool WindowManagerService::Init()
297 {
298 WLOGI("Init start");
299 if (WindowManagerConfig::LoadConfigXml()) {
300 if (WindowManagerConfig::GetConfig().IsMap()) {
301 WindowManagerConfig::DumpConfig(*WindowManagerConfig::GetConfig().mapValue_);
302 }
303 LoadWindowParameter();
304 ConfigureWindowManagerService();
305 StartingWindow::SetAnimationConfig(WindowNodeContainer::GetAnimationConfigRef());
306 }
307 if (PersistentStorage::HasKey("maximize_state", PersistentStorageType::MAXIMIZE_STATE)) {
308 int32_t storageMode = -1;
309 PersistentStorage::Get("maximize_state", storageMode, PersistentStorageType::MAXIMIZE_STATE);
310 if (storageMode == static_cast<int32_t>(MaximizeMode::MODE_AVOID_SYSTEM_BAR) ||
311 storageMode == static_cast<int32_t>(MaximizeMode::MODE_FULL_FILL)) {
312 maximizeMode_ = static_cast<MaximizeMode>(storageMode);
313 }
314 }
315 WindowSystemEffect::SetWindowRoot(windowRoot_);
316 WLOGI("Init success");
317 return true;
318 }
319
Dump(int fd,const std::vector<std::u16string> & args)320 int WindowManagerService::Dump(int fd, const std::vector<std::u16string>& args)
321 {
322 if (windowDumper_ == nullptr) {
323 windowDumper_ = new WindowDumper(windowRoot_);
324 }
325 WLOGFI("Pid : %{public}d", IPCSkeleton::GetCallingPid());
326 auto task = [this, fd, &args]() {
327 return static_cast<int>(windowDumper_->Dump(fd, args));
328 };
329 return PostSyncTask(task, "Dump");
330 }
331
LoadWindowParameter()332 void WindowManagerService::LoadWindowParameter()
333 {
334 const std::string multiWindowUIType = system::GetParameter("const.window.multiWindowUIType", "");
335 if (multiWindowUIType == "HandsetSmartWindow") {
336 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
337 WindowNodeContainer::windowUIType_ = WindowUIType::PHONE_WINDOW;
338 } else if (multiWindowUIType == "FreeFormMultiWindow") {
339 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
340 WindowNodeContainer::windowUIType_ = WindowUIType::PC_WINDOW;
341 } else if (multiWindowUIType == "TabletSmartWindow") {
342 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
343 WindowNodeContainer::windowUIType_ = WindowUIType::PAD_WINDOW;
344 } else {
345 WLOGFE("unknown multiWindowUIType:%{public}s.", multiWindowUIType.c_str());
346 }
347 }
348
ConfigureWindowManagerService()349 void WindowManagerService::ConfigureWindowManagerService()
350 {
351 const auto& config = WindowManagerConfig::GetConfig();
352 WindowManagerConfig::ConfigItem item = config["decor"];
353 if (item.IsMap()) {
354 ConfigDecor(item);
355 }
356 item = config["minimizeByOther"].GetProp("enable");
357 if (item.IsBool()) {
358 MinimizeApp::SetMinimizedByOtherConfig(item.boolValue_);
359 }
360 item = config["stretchable"].GetProp("enable");
361 if (item.IsBool()) {
362 systemConfig_.isStretchable_ = item.boolValue_;
363 }
364 item = config["defaultWindowMode"];
365 if (item.IsInts()) {
366 auto numbers = *item.intsValue_;
367 if (numbers.size() == 1 &&
368 (numbers[0] == static_cast<int32_t>(WindowMode::WINDOW_MODE_FULLSCREEN) ||
369 numbers[0] == static_cast<int32_t>(WindowMode::WINDOW_MODE_FLOATING))) {
370 systemConfig_.defaultWindowMode_ = static_cast<WindowMode>(static_cast<uint32_t>(numbers[0]));
371 StartingWindow::SetDefaultWindowMode(systemConfig_.defaultWindowMode_);
372 }
373 }
374 item = config["dragFrameGravity"];
375 if (item.IsInts()) {
376 auto numbers = *item.intsValue_;
377 if (numbers.size() == 1
378 && (numbers[0] == static_cast<int32_t>(Gravity::RESIZE)
379 || numbers[0] == static_cast<int32_t>(Gravity::TOP_LEFT))) {
380 windowController_->SetDragFrameGravity(static_cast<int32_t>(numbers[0]));
381 }
382 }
383 item = config["remoteAnimation"].GetProp("enable");
384 if (item.IsBool()) {
385 RemoteAnimation::isRemoteAnimationEnable_ = item.boolValue_;
386 }
387 item = config["maxAppWindowNumber"];
388 if (item.IsInts()) {
389 auto numbers = *item.intsValue_;
390 if (numbers.size() == 1 && numbers[0] > 0) {
391 windowRoot_->SetMaxAppWindowNumber(static_cast<uint32_t>(numbers[0]));
392 }
393 }
394 item = config["modeChangeHotZones"];
395 if (item.IsInts()) {
396 ConfigHotZones(*item.intsValue_);
397 }
398 item = config["splitRatios"];
399 if (item.IsFloats()) {
400 windowRoot_->SetSplitRatios(*item.floatsValue_);
401 }
402 item = config["exitSplitRatios"];
403 if (item.IsFloats()) {
404 windowRoot_->SetExitSplitRatios(*item.floatsValue_);
405 }
406 item = config["windowAnimation"];
407 if (item.IsMap()) {
408 ConfigWindowAnimation(item);
409 }
410 item = config["keyboardAnimation"];
411 if (item.IsMap()) {
412 ConfigKeyboardAnimation(item);
413 }
414 item = config["startWindowTransitionAnimation"];
415 if (item.IsMap()) {
416 ConfigStartingWindowAnimation(item);
417 }
418 item = config["windowEffect"];
419 if (item.IsMap()) {
420 ConfigWindowEffect(item);
421 }
422 item = config["floatingBottomPosY"];
423 if (item.IsInts()) {
424 auto numbers = *item.intsValue_;
425 if (numbers.size() == 1 && numbers[0] > 0) {
426 WindowLayoutPolicy::SetCascadeRectBottomPosYLimit(static_cast<uint32_t>(numbers[0]));
427 }
428 }
429 item = config["configMainFloatingWindowAbove"].GetProp("enable");
430 if (item.IsBool()) {
431 WindowNodeContainer::SetConfigMainFloatingWindowAbove(item.boolValue_);
432 }
433 item = config["maxMainFloatingWindowNumber"];
434 if (item.IsInts()) {
435 auto numbers = *item.intsValue_;
436 if (numbers.size() == 1 && numbers[0] > 0) {
437 WindowNodeContainer::SetMaxMainFloatingWindowNumber(static_cast<uint32_t>(numbers[0]));
438 }
439 }
440 item = config["maxFloatingWindowSize"];
441 if (item.IsInts()) {
442 auto numbers = *item.intsValue_;
443 if (numbers.size() == 1 && numbers[0] > 0) {
444 WindowLayoutPolicy::SetMaxFloatingWindowSize(static_cast<uint32_t>(numbers[0]));
445 }
446 }
447 item = config["defaultMaximizeMode"];
448 if (item.IsInts()) {
449 auto numbers = *item.intsValue_;
450 if (numbers.size() == 1 &&
451 (numbers[0] == static_cast<int32_t>(MaximizeMode::MODE_AVOID_SYSTEM_BAR) ||
452 numbers[0] == static_cast<int32_t>(MaximizeMode::MODE_FULL_FILL))) {
453 maximizeMode_ = static_cast<MaximizeMode>(numbers[0]);
454 }
455 }
456 item = config["supportTypeFloatWindow"].GetProp("enable");
457 if (item.IsBool()) {
458 systemConfig_.supportTypeFloatWindow_ = item.boolValue_;
459 }
460 }
461
ConfigHotZones(const std::vector<int> & numbers)462 void WindowManagerService::ConfigHotZones(const std::vector<int>& numbers)
463 {
464 if (numbers.size() == 3) { // 3 hot zones
465 hotZonesConfig_.fullscreenRange_ = static_cast<uint32_t>(numbers[0]); // 0 fullscreen
466 hotZonesConfig_.primaryRange_ = static_cast<uint32_t>(numbers[1]); // 1 primary
467 hotZonesConfig_.secondaryRange_ = static_cast<uint32_t>(numbers[2]); // 2 secondary
468 hotZonesConfig_.isModeChangeHotZoneConfigured_ = true;
469 }
470 }
471
ConfigDecor(const WindowManagerConfig::ConfigItem & decorConfig)472 void WindowManagerService::ConfigDecor(const WindowManagerConfig::ConfigItem& decorConfig)
473 {
474 WindowManagerConfig::ConfigItem item = decorConfig.GetProp("enable");
475 if (item.IsBool()) {
476 systemConfig_.isSystemDecorEnable_ = item.boolValue_;
477 std::vector<std::string> supportedModes;
478 item = decorConfig["supportedMode"];
479 if (item.IsStrings()) {
480 systemConfig_.decorWindowModeSupportType_ = 0;
481 supportedModes = *item.stringsValue_;
482 }
483 for (auto mode : supportedModes) {
484 if (mode == "fullscreen") {
485 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN;
486 } else if (mode == "floating") {
487 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
488 } else if (mode == "pip") {
489 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_PIP;
490 } else if (mode == "split") {
491 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
492 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY;
493 } else {
494 WLOGFW("Invalid supporedMode");
495 systemConfig_.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
496 break;
497 }
498 }
499 }
500 }
501
ConfigWindowAnimation(const WindowManagerConfig::ConfigItem & animeConfig)502 void WindowManagerService::ConfigWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
503 {
504 auto& windowAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().windowAnimationConfig_;
505 WindowManagerConfig::ConfigItem item = animeConfig["timing"];
506 if (item.IsMap() && item.mapValue_->count("curve")) {
507 windowAnimationConfig.animationTiming_.timingCurve_ = CreateCurve(item["curve"]);
508 }
509 item = animeConfig["timing"]["duration"];
510 if (item.IsInts()) {
511 auto numbers = *item.intsValue_;
512 if (numbers.size() == 1) { // duration
513 windowAnimationConfig.animationTiming_.timingProtocol_ =
514 RSAnimationTimingProtocol(numbers[0]);
515 }
516 }
517 item = animeConfig["scale"];
518 if (item.IsFloats()) {
519 auto numbers = *item.floatsValue_;
520 if (numbers.size() == 1) { // 1 xy scale
521 windowAnimationConfig.scale_.x_ =
522 windowAnimationConfig.scale_.y_ = numbers[0]; // 0 xy scale
523 } else if (numbers.size() == 2) { // 2 x,y sclae
524 windowAnimationConfig.scale_.x_ = numbers[0]; // 0 x scale
525 windowAnimationConfig.scale_.y_ = numbers[1]; // 1 y scale
526 } else if (numbers.size() == 3) { // 3 x,y,z scale
527 windowAnimationConfig.scale_ = Vector3f(&numbers[0]);
528 }
529 }
530 item = animeConfig["rotation"];
531 if (item.IsFloats() && item.floatsValue_->size() == 4) { // 4 (axix,angle)
532 windowAnimationConfig.rotation_ = Vector4f(item.floatsValue_->data());
533 }
534 item = animeConfig["translate"];
535 if (item.IsFloats()) {
536 auto numbers = *item.floatsValue_;
537 if (numbers.size() == 2) { // 2 translate xy
538 windowAnimationConfig.translate_.x_ = numbers[0]; // 0 translate x
539 windowAnimationConfig.translate_.y_ = numbers[1]; // 1 translate y
540 } else if (numbers.size() == 3) { // 3 translate xyz
541 windowAnimationConfig.translate_.x_ = numbers[0]; // 0 translate x
542 windowAnimationConfig.translate_.y_ = numbers[1]; // 1 translate y
543 windowAnimationConfig.translate_.z_ = numbers[2]; // 2 translate z
544 }
545 }
546 item = animeConfig["opacity"];
547 if (item.IsFloats()) {
548 auto numbers = *item.floatsValue_;
549 numbers.size() == 1 ? (windowAnimationConfig.opacity_ = numbers[0]) : float();
550 }
551 }
552
ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem & animeConfig)553 void WindowManagerService::ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
554 {
555 auto& animationConfig = WindowNodeContainer::GetAnimationConfigRef();
556 WindowManagerConfig::ConfigItem inItem = animeConfig["animationIn"]["timing"];
557 if (inItem.IsMap() && inItem.mapValue_ != nullptr && inItem.mapValue_->count("curve")) {
558 CreateKeyboardCurve(inItem, animationConfig.keyboardAnimationIn_, systemConfig_.animationIn_);
559 }
560
561 WindowManagerConfig::ConfigItem outItem = animeConfig["animationOut"]["timing"];
562 if (outItem.IsMap() && outItem.mapValue_ != nullptr && outItem.mapValue_->count("curve")) {
563 CreateKeyboardCurve(outItem, animationConfig.keyboardAnimationOut_, systemConfig_.animationOut_);
564 }
565 WLOGFI("curveIn:[%{public}s, %{public}u], curveOut:[%{public}s, %{public}u]",
566 systemConfig_.animationIn_.curveType_.c_str(), systemConfig_.animationIn_.duration_,
567 systemConfig_.animationOut_.curveType_.c_str(), systemConfig_.animationOut_.duration_);
568 }
569
ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem & animeConfig)570 void WindowManagerService::ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
571 {
572 WindowManagerConfig::ConfigItem item = animeConfig.GetProp("enable");
573 if (item.IsBool()) {
574 StartingWindow::transAnimateEnable_ = item.boolValue_;
575 }
576 auto& startWinAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().startWinAnimationConfig_;
577 item = animeConfig["timing"];
578 if (item.IsMap() && item.mapValue_->count("curve")) {
579 startWinAnimationConfig.timingCurve_ = CreateCurve(item["curve"]);
580 }
581 item = animeConfig["timing"]["duration"];
582 if (item.IsInts()) {
583 auto numbers = *item.intsValue_;
584 if (numbers.size() == 1) { // duration
585 startWinAnimationConfig.timingProtocol_ = RSAnimationTimingProtocol(numbers[0]);
586 }
587 }
588 item = animeConfig["opacityStart"];
589 if (item.IsFloats()) {
590 auto numbers = *item.floatsValue_;
591 numbers.size() == 1 ? (startWinAnimationConfig.opacityStart_ = numbers[0]) : float();
592 }
593 item = animeConfig["opacityEnd"];
594 if (item.IsFloats()) {
595 auto numbers = *item.floatsValue_;
596 numbers.size() == 1 ? (startWinAnimationConfig.opacityEnd_ = numbers[0]) : float();
597 }
598 }
599
ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem & item,float & out)600 bool WindowManagerService::ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out)
601 {
602 std::map<std::string, float> stringToCornerRadius = {
603 {"off", 0.0f}, {"defaultCornerRadiusXS", 4.0f}, {"defaultCornerRadiusS", 8.0f},
604 {"defaultCornerRadiusM", 12.0f}, {"defaultCornerRadiusL", 16.0f}, {"defaultCornerRadiusXL", 24.0f}
605 };
606
607 if (item.IsString()) {
608 auto value = item.stringValue_;
609 if (stringToCornerRadius.find(value) != stringToCornerRadius.end()) {
610 out = stringToCornerRadius[value];
611 return true;
612 }
613 }
614 return false;
615 }
616
ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem & shadowConfig,WindowShadowParameters & outShadow)617 bool WindowManagerService::ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig,
618 WindowShadowParameters& outShadow)
619 {
620 WindowManagerConfig::ConfigItem item = shadowConfig["elevation"];
621 if (item.IsFloats()) {
622 auto elevation = *item.floatsValue_;
623 if (elevation.size() != 1 || MathHelper::LessNotEqual(elevation[0], 0.0)) {
624 return false;
625 }
626 outShadow.elevation_ = elevation[0];
627 }
628
629 item = shadowConfig["color"];
630 if (item.IsString()) {
631 auto color = item.stringValue_;
632 uint32_t colorValue;
633 if (!ColorParser::Parse(color, colorValue)) {
634 return false;
635 }
636 outShadow.color_ = color;
637 }
638
639 item = shadowConfig["offsetX"];
640 if (item.IsFloats()) {
641 auto offsetX = *item.floatsValue_;
642 if (offsetX.size() != 1) {
643 return false;
644 }
645 outShadow.offsetX_ = offsetX[0];
646 }
647
648 item = shadowConfig["offsetY"];
649 if (item.IsFloats()) {
650 auto offsetY = *item.floatsValue_;
651 if (offsetY.size() != 1) {
652 return false;
653 }
654 outShadow.offsetY_ = offsetY[0];
655 }
656
657 item = shadowConfig["alpha"];
658 if (item.IsFloats()) {
659 auto alpha = *item.floatsValue_;
660 if (alpha.size() != 1 ||
661 (MathHelper::LessNotEqual(alpha[0], 0.0) && MathHelper::GreatNotEqual(alpha[0], 1.0))) {
662 return false;
663 }
664 outShadow.alpha_ = alpha[0];
665 }
666
667 item = shadowConfig["radius"];
668 if (item.IsFloats()) {
669 auto radius = *item.floatsValue_;
670 if (radius.size() != 1 || MathHelper::LessNotEqual(radius[0], 0.0)) {
671 return false;
672 }
673 outShadow.radius_ = radius[0];
674 }
675
676 return true;
677 }
678
ConfigWindowEffect(const WindowManagerConfig::ConfigItem & effectConfig)679 void WindowManagerService::ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig)
680 {
681 AppWindowEffectConfig config;
682 AppWindowEffectConfig systemEffectConfig;
683 // config corner radius
684 WindowManagerConfig::ConfigItem item = effectConfig["appWindows"]["cornerRadius"];
685 if (item.IsMap()) {
686 if (ConfigAppWindowCornerRadius(item["fullScreen"], config.fullScreenCornerRadius_) &&
687 ConfigAppWindowCornerRadius(item["split"], config.splitCornerRadius_) &&
688 ConfigAppWindowCornerRadius(item["float"], config.floatCornerRadius_)) {
689 systemEffectConfig = config;
690 }
691 }
692
693 // config shadow
694 item = effectConfig["appWindows"]["shadow"]["focused"];
695 if (item.IsMap()) {
696 if (ConfigAppWindowShadow(item, config.focusedShadow_)) {
697 systemEffectConfig.focusedShadow_ = config.focusedShadow_;
698 }
699 }
700
701 item = effectConfig["appWindows"]["shadow"]["unfocused"];
702 if (item.IsMap()) {
703 if (ConfigAppWindowShadow(item, config.unfocusedShadow_)) {
704 systemEffectConfig.unfocusedShadow_ = config.unfocusedShadow_;
705 }
706 }
707 WindowSystemEffect::SetWindowSystemEffectConfig(systemEffectConfig);
708 }
709
CreateKeyboardCurve(const WindowManagerConfig::ConfigItem & config,AnimationConfig::KeyboardAnimation & animateConfig,KeyboardAnimationCurve & sysCurveConfig)710 void WindowManagerService::CreateKeyboardCurve(const WindowManagerConfig::ConfigItem& config,
711 AnimationConfig::KeyboardAnimation& animateConfig, KeyboardAnimationCurve& sysCurveConfig)
712 {
713 // parse curve params
714 const WindowManagerConfig::ConfigItem& curveConfig = config["curve"];
715 static std::map<std::string, RSAnimationTimingCurve> curveMap = {
716 { "easeOut", RSAnimationTimingCurve::EASE_OUT },
717 { "ease", RSAnimationTimingCurve::EASE },
718 { "easeIn", RSAnimationTimingCurve::EASE_IN },
719 { "easeInOut", RSAnimationTimingCurve::EASE_IN_OUT },
720 { "default", RSAnimationTimingCurve::DEFAULT },
721 { "linear", RSAnimationTimingCurve::LINEAR },
722 { "spring", RSAnimationTimingCurve::SPRING },
723 { "interactiveSpring", RSAnimationTimingCurve::INTERACTIVE_SPRING }
724 };
725 RSAnimationTimingCurve curve = RSAnimationTimingCurve::EASE_OUT;
726 std::string keyboardCurveName = "easeOut";
727 std::vector<float> keyboardCurveParams = {};
728 const auto& nameItem = curveConfig.GetProp("name");
729 if (nameItem.IsString()) {
730 std::string name = nameItem.stringValue_;
731 if (name == "cubic" && curveConfig.IsFloats() && curveConfig.floatsValue_ != nullptr &&
732 curveConfig.floatsValue_->size() == 4) { // 4: param size
733 const auto& numbers = *curveConfig.floatsValue_;
734 keyboardCurveName = name;
735 keyboardCurveParams.assign(numbers.begin(), numbers.end());
736 curve = RSAnimationTimingCurve::CreateCubicCurve(
737 numbers[0], // 0 ctrlX1
738 numbers[1], // 1 ctrlY1
739 numbers[2], // 2 ctrlX2
740 numbers[3]); // 3 ctrlY2
741 } else {
742 auto iter = curveMap.find(name);
743 if (iter != curveMap.end()) {
744 keyboardCurveName = name;
745 curve = iter->second;
746 }
747 }
748 }
749 animateConfig.curve_ = curve;
750 sysCurveConfig.curveType_ = keyboardCurveName;
751 sysCurveConfig.curveParams_.assign(keyboardCurveParams.begin(), keyboardCurveParams.end());
752
753 // parse curve duration
754 const WindowManagerConfig::ConfigItem& duration = config["duration"];
755 if (duration.IsInts() && duration.intsValue_ != nullptr) {
756 auto numbers = *duration.intsValue_;
757 if (numbers.size() == 1) { // duration
758 animateConfig.duration_ = RSAnimationTimingProtocol(numbers[0]);
759 sysCurveConfig.duration_ = static_cast<uint32_t>(numbers[0]);
760 }
761 }
762 }
763
CreateCurve(const WindowManagerConfig::ConfigItem & curveConfig)764 RSAnimationTimingCurve WindowManagerService::CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig)
765 {
766 static std::map<std::string, RSAnimationTimingCurve> curveMap = {
767 { "easeOut", RSAnimationTimingCurve::EASE_OUT },
768 { "ease", RSAnimationTimingCurve::EASE },
769 { "easeIn", RSAnimationTimingCurve::EASE_IN },
770 { "easeInOut", RSAnimationTimingCurve::EASE_IN_OUT },
771 { "default", RSAnimationTimingCurve::DEFAULT },
772 { "linear", RSAnimationTimingCurve::LINEAR },
773 { "spring", RSAnimationTimingCurve::SPRING },
774 { "interactiveSpring", RSAnimationTimingCurve::INTERACTIVE_SPRING }
775 };
776
777 RSAnimationTimingCurve curve = RSAnimationTimingCurve::EASE_OUT;
778 const auto& nameItem = curveConfig.GetProp("name");
779 if (nameItem.IsString()) {
780 std::string name = nameItem.stringValue_;
781 if (name == "cubic" && curveConfig.IsFloats() && curveConfig.floatsValue_ != nullptr &&
782 curveConfig.floatsValue_->size() == 4) { // 4 curve parameter
783 const auto& numbers = *curveConfig.floatsValue_;
784 curve = RSAnimationTimingCurve::CreateCubicCurve(
785 numbers[0], // 0 ctrlX1
786 numbers[1], // 1 ctrlY1
787 numbers[2], // 2 ctrlX2
788 numbers[3]); // 3 ctrlY2
789 } else {
790 if (auto iter = curveMap.find(name); iter != curveMap.end()) {
791 curve = iter->second;
792 }
793 }
794 }
795 return curve;
796 }
797
OnStop()798 void WindowManagerService::OnStop()
799 {
800 windowCommonEvent_->UnSubscriberEvent();
801 WindowInnerManager::GetInstance().Stop();
802 WLOGI("ready to stop service.");
803 }
804
NotifyWindowTransition(sptr<WindowTransitionInfo> & fromInfo,sptr<WindowTransitionInfo> & toInfo,bool isFromClient)805 WMError WindowManagerService::NotifyWindowTransition(
806 sptr<WindowTransitionInfo>& fromInfo, sptr<WindowTransitionInfo>& toInfo, bool isFromClient)
807 {
808 if (!isFromClient) {
809 WLOGI("NotifyWindowTransition asynchronously.");
810 auto task = [this, fromInfo, toInfo]() mutable {
811 return windowController_->NotifyWindowTransition(fromInfo, toInfo);
812 };
813 PostAsyncTask(task, "NotifyWindowTransition");
814 return WMError::WM_OK;
815 } else {
816 WLOGI("NotifyWindowTransition synchronously.");
817 auto task = [this, &fromInfo, &toInfo]() {
818 return windowController_->NotifyWindowTransition(fromInfo, toInfo);
819 };
820 return PostSyncTask(task, "NotifyWindowTransition");
821 }
822 }
823
NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info)824 void WindowManagerService::NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info)
825 {
826 auto task = [this, info]() mutable {
827 return RemoteAnimation::NotifyAnimationAbilityDied(info);
828 };
829 PostAsyncTask(task, "NotifyAnimationAbilityDied");
830 }
831
GetFocusWindowInfo(sptr<IRemoteObject> & abilityToken,DisplayId displayId)832 WMError WindowManagerService::GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken, DisplayId displayId)
833 {
834 auto task = [this, &abilityToken]() {
835 return windowController_->GetFocusWindowInfo(abilityToken);
836 };
837 return PostSyncTask(task, "GetFocusWindowInfo");
838 }
839
StartingWindow(sptr<WindowTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,bool isColdStart,uint32_t bkgColor)840 void WindowManagerService::StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
841 bool isColdStart, uint32_t bkgColor)
842 {
843 if (!startingOpen_) {
844 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "startingWindow not open!");
845 return;
846 }
847 if (info) {
848 info->isSystemCalling_ = Permission::IsSystemCalling();
849 }
850 auto task = [this, info, pixelMap, isColdStart, bkgColor]() {
851 windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart);
852 };
853 PostAsyncTask(task, "StartingWindow");
854 }
855
CancelStartingWindow(sptr<IRemoteObject> abilityToken)856 void WindowManagerService::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
857 {
858 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "begin");
859 if (!startingOpen_) {
860 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "startingWindow not open!");
861 return;
862 }
863 auto task = [this, abilityToken]() {
864 windowController_->CancelStartingWindow(abilityToken);
865 };
866 PostAsyncTask(task, "CancelStartingWindow");
867 }
868
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)869 WMError WindowManagerService::MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId)
870 {
871 if (windowGroupMgr_) {
872 auto task = [this, &missionIds, topMissionId]() {
873 WMError res = windowGroupMgr_->MoveMissionsToForeground(missionIds, topMissionId);
874 // no need to return inner error to caller
875 if (res > WMError::WM_ERROR_NEED_REPORT_BASE) {
876 return res;
877 }
878 return WMError::WM_OK;
879 };
880 return PostSyncTask(task, "MoveMissionsToForeground");
881 }
882 return WMError::WM_ERROR_NULLPTR;
883 }
884
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)885 WMError WindowManagerService::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
886 std::vector<int32_t>& result)
887 {
888 if (windowGroupMgr_) {
889 auto task = [this, &missionIds, &result]() {
890 WMError res = windowGroupMgr_->MoveMissionsToBackground(missionIds, result);
891 // no need to return wms inner error to caller
892 if (res > WMError::WM_ERROR_NEED_REPORT_BASE) {
893 return res;
894 }
895 return WMError::WM_OK;
896 };
897 return PostSyncTask(task, "MoveMissionsToBackground");
898 }
899 return WMError::WM_ERROR_NULLPTR;
900 }
901
902
CheckAnimationPermission(const sptr<WindowProperty> & property) const903 bool WindowManagerService::CheckAnimationPermission(const sptr<WindowProperty>& property) const
904 {
905 WindowType type = property->GetWindowType();
906 // If the animation type is NONE or the window type is WINDOW_TYPE_INPUT_METHOD_FLOAT
907 if (property->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::NONE) ||
908 type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
909 return true;
910 }
911 // If the animation type is DEFAULT and the window type is AppWindow
912 if (property->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::DEFAULT) &&
913 WindowHelper::IsAppWindow(type)) {
914 return true;
915 }
916 // If the animation type is CUSTOM
917 if (Permission::IsSystemCalling() || Permission::IsStartByHdcd()) {
918 WLOGFD("check IsSystemCalling permission success, show with animation calling.");
919 return true;
920 }
921 WLOGFE("check animation permission failed");
922 return false;
923 }
924
CheckSystemWindowPermission(const sptr<WindowProperty> & property) const925 bool WindowManagerService::CheckSystemWindowPermission(const sptr<WindowProperty>& property) const
926 {
927 WindowType type = property->GetWindowType();
928 if (!WindowHelper::IsSystemWindow(type)) {
929 // type is not system
930 return true;
931 }
932 if ((type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || type == WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR)
933 && Permission::IsStartByInputMethod()) {
934 // WINDOW_TYPE_INPUT_METHOD_FLOAT counld be created by input method app
935 WLOGFD("check create permission success, input method app create input method window.");
936 return true;
937 }
938 if (type == WindowType::WINDOW_TYPE_DRAGGING_EFFECT || type == WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW ||
939 type == WindowType::WINDOW_TYPE_TOAST || type == WindowType::WINDOW_TYPE_DIALOG) {
940 // some system types counld be created by normal app
941 return true;
942 }
943 if (type == WindowType::WINDOW_TYPE_FLOAT &&
944 Permission::CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
945 // WINDOW_TYPE_FLOAT counld be created by normal app with the corresponding permission
946 WLOGFD("check create permission success, normal app create float window with request permission.");
947 return true;
948 }
949 if (Permission::IsSystemCalling() || Permission::IsStartByHdcd()) {
950 WLOGFD("check create permission success, create with system calling.");
951 return true;
952 }
953 WLOGFE("check system window permission failed.");
954 return false;
955 }
956
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId,sptr<IRemoteObject> token)957 WMError WindowManagerService::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
958 const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token)
959 {
960 if (!window || property == nullptr || surfaceNode == nullptr || !window->AsObject()) {
961 WLOGFE("window is invalid");
962 return WMError::WM_ERROR_NULLPTR;
963 }
964 if (!CheckSystemWindowPermission(property)) {
965 WLOGFE("create system window permission denied!");
966 return WMError::WM_ERROR_NOT_SYSTEM_APP;
967 }
968 int pid = IPCSkeleton::GetCallingRealPid();
969 int uid = IPCSkeleton::GetCallingUid();
970 property->isSystemCalling_ = Permission::IsSystemCalling();
971 if (rsUiDirector_) {
972 RSAdapterUtil::SetRSUIContext(surfaceNode, rsUiDirector_->GetRSUIContext(), true);
973 }
974 auto task = [this, pid, uid, &window, &property, &surfaceNode, &windowId, &token]() {
975 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CreateWindow(%u)", windowId);
976 return windowController_->CreateWindow(window, property, surfaceNode, windowId, token, pid, uid);
977 };
978 WMError ret = PostSyncTask(task, "CreateWindow");
979 accessTokenIdMaps_.insert(std::pair(windowId, IPCSkeleton::GetCallingTokenID()));
980 return ret;
981 }
982
AddWindow(sptr<WindowProperty> & property)983 WMError WindowManagerService::AddWindow(sptr<WindowProperty>& property)
984 {
985 if (property == nullptr) {
986 WLOGFE("property is nullptr");
987 return WMError::WM_ERROR_NULLPTR;
988 }
989 if (!CheckSystemWindowPermission(property) || !CheckAnimationPermission(property)) {
990 WLOGFE("add window permission denied!");
991 return WMError::WM_ERROR_NOT_SYSTEM_APP;
992 }
993 auto task = [this, &property]() {
994 windowShowPerformReport_->start();
995 Rect rect = property->GetRequestRect();
996 uint32_t windowId = property->GetWindowId();
997 WLOGI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \
998 "%{public}4d %{public}4d]", windowId, property->GetWindowType(), property->GetWindowMode(),
999 property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_);
1000 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:AddWindow(%u)", windowId);
1001 WMError res = windowController_->AddWindowNode(property);
1002 if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
1003 dragController_->StartDrag(windowId);
1004 }
1005 if (res == WMError::WM_OK) {
1006 windowShowPerformReport_->end();
1007 }
1008 return res;
1009 };
1010 return PostSyncTask(task, "AddWindow");
1011 }
1012
RemoveWindow(uint32_t windowId,bool isFromInnerkits)1013 WMError WindowManagerService::RemoveWindow(uint32_t windowId, bool isFromInnerkits)
1014 {
1015 if (!isFromInnerkits && !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1016 WLOGFE("remove window permission denied!");
1017 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1018 }
1019 if (!accessTokenIdMaps_.isExist(windowId, IPCSkeleton::GetCallingTokenID())) {
1020 WLOGI("Operation rejected");
1021 return WMError::WM_ERROR_INVALID_OPERATION;
1022 }
1023 auto task = [this, windowId]() {
1024 WLOGI("[WMS] Remove: %{public}u", windowId);
1025 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:RemoveWindow(%u)", windowId);
1026 WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
1027 WMError res = windowController_->RecoverInputEventToClient(windowId);
1028 if (res != WMError::WM_OK) {
1029 return res;
1030 }
1031 return windowController_->RemoveWindowNode(windowId);
1032 };
1033 return PostSyncTask(task, "RemoveWindow");
1034 }
1035
DestroyWindow(uint32_t windowId,bool onlySelf)1036 WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf)
1037 {
1038 if (!accessTokenIdMaps_.isExistAndRemove(windowId, IPCSkeleton::GetCallingTokenID())) {
1039 WLOGI("Operation rejected");
1040 return WMError::WM_ERROR_INVALID_OPERATION;
1041 }
1042 auto task = [this, windowId, onlySelf]() {
1043 auto node = windowRoot_->GetWindowNode(windowId);
1044 if (node == nullptr) {
1045 return WMError::WM_ERROR_NULLPTR;
1046 }
1047 node->stateMachine_.SetDestroyTaskParam(onlySelf);
1048 auto func = [this, windowId]() {
1049 WLOGI("[WMS] Destroy: %{public}u", windowId);
1050 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:DestroyWindow(%u)", windowId);
1051 WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
1052 windowGroupMgr_->OnWindowDestroyed(windowId);
1053 auto node = windowRoot_->GetWindowNode(windowId);
1054 if (node == nullptr) {
1055 return WMError::WM_OK;
1056 }
1057 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
1058 dragController_->FinishDrag(windowId);
1059 }
1060 return windowController_->DestroyWindow(windowId, node->stateMachine_.GetDestroyTaskParam());
1061 };
1062 if (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
1063 node->stateMachine_.IsRemoteAnimationPlaying()) {
1064 WLOGI("SetDestroyTask id:%{public}u", node->GetWindowId());
1065 node->stateMachine_.SetDestroyTask(func);
1066 return WMError::WM_OK;
1067 }
1068 WLOGI("DestroyWindow windowId: %{public}u, name:%{public}s state: %{public}u",
1069 node->GetWindowId(), node->GetWindowName().c_str(),
1070 static_cast<uint32_t>(node->stateMachine_.GetCurrentState()));
1071 return func();
1072 };
1073 return PostSyncTask(task, "DestroyWindow");
1074 }
1075
RequestFocus(uint32_t windowId)1076 WMError WindowManagerService::RequestFocus(uint32_t windowId)
1077 {
1078 auto task = [this, windowId]() {
1079 WLOGI("[WMS] RequestFocus: %{public}u", windowId);
1080 return windowController_->RequestFocus(windowId);
1081 };
1082 return PostSyncTask(task, "RequestFocus");
1083 }
1084
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType avoidAreaType,const Rect & rect)1085 AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType, const Rect& rect)
1086 {
1087 auto task = [this, windowId, avoidAreaType]() {
1088 WLOGI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId,
1089 static_cast<uint32_t>(avoidAreaType));
1090 return windowController_->GetAvoidAreaByType(windowId, avoidAreaType);
1091 };
1092 return PostSyncTask(task, "GetAvoidAreaByType");
1093 }
1094
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)1095 WMError WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type,
1096 const sptr<IWindowManagerAgent>& windowManagerAgent)
1097 {
1098 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1099 WLOGFE("register windowManager agent permission denied!");
1100 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1101 }
1102 if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
1103 WLOGFE("windowManagerAgent is null");
1104 return WMError::WM_ERROR_NULLPTR;
1105 }
1106 auto task = [this, &windowManagerAgent, type]() {
1107 WMError ret = WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type);
1108 if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR) { // if system bar, notify once
1109 windowController_->NotifySystemBarTints();
1110 }
1111 return ret;
1112 };
1113 return PostSyncTask(task, "RegisterWindowManagerAgent");
1114 }
1115
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)1116 WMError WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type,
1117 const sptr<IWindowManagerAgent>& windowManagerAgent)
1118 {
1119 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1120 WLOGFE("unregister windowManager agent permission denied!");
1121 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1122 }
1123 if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
1124 WLOGFE("windowManagerAgent is null");
1125 return WMError::WM_ERROR_NULLPTR;
1126 }
1127 auto task = [this, &windowManagerAgent, type]() {
1128 return WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type);
1129 };
1130 return PostSyncTask(task, "UnregisterWindowManagerAgent");
1131 }
1132
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)1133 WMError WindowManagerService::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
1134 {
1135 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1136 WLOGFE("set window animation controller permission denied!");
1137 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1138 }
1139 if (controller == nullptr) {
1140 WLOGFE("RSWindowAnimation: Failed to set window animation controller, controller is null!");
1141 return WMError::WM_ERROR_NULLPTR;
1142 }
1143
1144 sptr<AgentDeathRecipient> deathRecipient = new AgentDeathRecipient(
1145 [this](sptr<IRemoteObject>& remoteObject) {
1146 auto task = [&remoteObject]() {
1147 RemoteAnimation::OnRemoteDie(remoteObject);
1148 };
1149 PostVoidSyncTask(task, "OnRemoteDie");
1150 }
1151 );
1152 controller->AsObject()->AddDeathRecipient(deathRecipient);
1153 RemoteAnimation::SetWindowControllerAndRoot(windowController_, windowRoot_);
1154 RemoteAnimation::SetMainTaskHandler(handler_);
1155 auto task = [this, &controller]() {
1156 WMError ret = windowController_->SetWindowAnimationController(controller);
1157 RemoteAnimation::SetAnimationFirst(system::GetParameter("persist.window.af.enabled", "1") == "1");
1158 return ret;
1159 };
1160 return PostSyncTask(task, "SetWindowAnimationController");
1161 }
1162
OnWindowEvent(Event event,const sptr<IRemoteObject> & remoteObject)1163 void WindowManagerService::OnWindowEvent(Event event, const sptr<IRemoteObject>& remoteObject)
1164 {
1165 if (event == Event::REMOTE_DIED) {
1166 auto task = [this, &remoteObject]() {
1167 uint32_t windowId = windowRoot_->GetWindowIdByObject(remoteObject);
1168 auto node = windowRoot_->GetWindowNode(windowId);
1169 if (node == nullptr) {
1170 WLOGFD("window node is nullptr, REMOTE_DIED no need to destroy");
1171 return;
1172 }
1173 WLOGI("window %{public}u received REMOTE_DIED", windowId);
1174 node->stateMachine_.SetDestroyTaskParam(true);
1175 auto func = [this, windowId]() {
1176 auto node = windowRoot_->GetWindowNode(windowId);
1177 if (node == nullptr) {
1178 WLOGFD("window node is nullptr");
1179 return;
1180 }
1181 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
1182 dragController_->FinishDrag(windowId);
1183 }
1184 WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
1185 windowGroupMgr_->OnWindowDestroyed(windowId);
1186 windowController_->DestroyWindow(windowId, node->stateMachine_.GetDestroyTaskParam());
1187 };
1188
1189 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1190 RemoteAnimation::OnRemoteDie(remoteObject);
1191 }
1192 if (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
1193 node->stateMachine_.IsRemoteAnimationPlaying()) {
1194 WLOGI("set destroy task windowId:%{public}u", node->GetWindowId());
1195 node->stateMachine_.SetDestroyTask(func);
1196 handler_->PostTask(func, "destroyTimeOutTask", 6000); // 6000 is time out 6s
1197 return;
1198 }
1199 func();
1200 };
1201 PostVoidSyncTask(task, "OnWindowEvent");
1202 }
1203 }
1204
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)1205 void WindowManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
1206 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
1207 {
1208 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:NotifyDisplayStateChange(%u)", type);
1209 DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId();
1210 if (type == DisplayStateChangeType::FREEZE) {
1211 freezeDisplayController_->FreezeDisplay(displayId);
1212 } else if (type == DisplayStateChangeType::UNFREEZE) {
1213 freezeDisplayController_->UnfreezeDisplay(displayId);
1214 /*
1215 * Set 'InnerInputManager Listener' to MMI, ensure that the listener
1216 * for move/drag won't be replaced by freeze-display-window
1217 */
1218 WindowInnerManager::GetInstance().SetInputEventConsumer();
1219 } else {
1220 auto task = [this, defaultDisplayId, displayInfo, displayInfoMap, type]() mutable {
1221 windowController_->NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1222 windowGroupMgr_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1223 };
1224 PostAsyncTask(task, "NotifyDisplayStateChange");
1225 }
1226 }
1227
OnDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)1228 void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
1229 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
1230 {
1231 WindowManagerService::GetInstance().NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1232 }
1233
OnScreenshot(DisplayId displayId)1234 void DisplayChangeListener::OnScreenshot(DisplayId displayId)
1235 {
1236 WindowManagerService::GetInstance().OnScreenshot(displayId);
1237 }
1238
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)1239 void WindowManagerService::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
1240 sptr<MoveDragProperty>& moveDragProperty)
1241 {
1242 if (windowProperty == nullptr || moveDragProperty == nullptr) {
1243 WLOGFE("windowProperty or moveDragProperty is invalid");
1244 return;
1245 }
1246
1247 auto task = [this, windowId, windowProperty, moveDragProperty]() mutable {
1248 if (moveDragProperty->startDragFlag_ || moveDragProperty->startMoveFlag_) {
1249 bool res = WindowInnerManager::GetInstance().NotifyServerReadyToMoveOrDrag(windowId,
1250 windowProperty, moveDragProperty);
1251 if (!res) {
1252 WLOGFE("invalid operation");
1253 return;
1254 }
1255 windowController_->InterceptInputEventToServer(windowId);
1256 }
1257 windowController_->NotifyServerReadyToMoveOrDrag(windowId, moveDragProperty);
1258 };
1259 PostAsyncTask(task, "NotifyServerReadyToMoveOrDrag");
1260 }
1261
ProcessPointDown(uint32_t windowId,bool isPointDown)1262 void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isPointDown)
1263 {
1264 auto task = [this, windowId, isPointDown]() {
1265 windowController_->ProcessPointDown(windowId, isPointDown);
1266 };
1267 PostAsyncTask(task, "ProcessPointDown");
1268 }
1269
ProcessPointUp(uint32_t windowId)1270 void WindowManagerService::ProcessPointUp(uint32_t windowId)
1271 {
1272 auto task = [this, windowId]() {
1273 WindowInnerManager::GetInstance().NotifyWindowEndUpMovingOrDragging(windowId);
1274 windowController_->RecoverInputEventToClient(windowId);
1275 windowController_->ProcessPointUp(windowId);
1276 };
1277 PostAsyncTask(task, "ProcessPointUp");
1278 }
1279
NotifyWindowClientPointUp(uint32_t windowId,const std::shared_ptr<MMI::PointerEvent> & pointerEvent)1280 void WindowManagerService::NotifyWindowClientPointUp(uint32_t windowId,
1281 const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
1282 {
1283 auto task = [this, windowId, pointerEvent]() mutable {
1284 windowController_->NotifyWindowClientPointUp(windowId, pointerEvent);
1285 };
1286 PostAsyncTask(task, "NotifyWindowClientPointUp");
1287 }
1288
MinimizeAllAppWindows(DisplayId displayId)1289 WMError WindowManagerService::MinimizeAllAppWindows(DisplayId displayId)
1290 {
1291 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1292 WLOGFE("minimize all appWindows permission denied!");
1293 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1294 }
1295 auto task = [this, displayId]() {
1296 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:MinimizeAllAppWindows(%" PRIu64")", displayId);
1297 WLOGI("displayId %{public}" PRIu64"", displayId);
1298 windowController_->MinimizeAllAppWindows(displayId);
1299 };
1300 PostAsyncTask(task, "MinimizeAllAppWindows");
1301 return WMError::WM_OK;
1302 }
1303
ToggleShownStateForAllAppWindows()1304 WMError WindowManagerService::ToggleShownStateForAllAppWindows()
1305 {
1306 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1307 WLOGFE("toggle shown state for all appwindows permission denied!");
1308 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1309 }
1310 auto task = [this]() {
1311 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:ToggleShownStateForAllAppWindows");
1312 return windowController_->ToggleShownStateForAllAppWindows();
1313 };
1314 PostAsyncTask(task, "ToggleShownStateForAllAppWindows");
1315 return WMError::WM_OK;
1316 }
1317
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)1318 WMError WindowManagerService::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
1319 {
1320 auto task = [this, &topWinId, mainWinId]() {
1321 return windowController_->GetTopWindowId(mainWinId, topWinId);
1322 };
1323 return PostSyncTask(task, "GetTopWindowId");
1324 }
1325
SetWindowLayoutMode(WindowLayoutMode mode)1326 WMError WindowManagerService::SetWindowLayoutMode(WindowLayoutMode mode)
1327 {
1328 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1329 WLOGFE("set window layout mode permission denied!");
1330 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1331 }
1332 auto task = [this, mode]() {
1333 WLOGI("layoutMode: %{public}u", mode);
1334 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:SetWindowLayoutMode");
1335 return windowController_->SetWindowLayoutMode(mode);
1336 };
1337 return PostSyncTask(task, "SetWindowLayoutMode");
1338 }
1339
NotifyScreenshotEvent(ScreenshotEventType type)1340 WMError WindowManagerService::NotifyScreenshotEvent(ScreenshotEventType type)
1341 {
1342 if (!Permission::IsSystemCalling()) {
1343 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "notify screen shot event type permission denied!");
1344 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1345 }
1346 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "event: %{public}d", type);
1347 auto task = [this, type]() {
1348 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:NotifyScreenshotEvent");
1349 return windowController_->NotifyScreenshotEvent(type);
1350 };
1351 return PostSyncTask(task, "SetWindowLayoutMode");
1352 }
1353
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)1354 WMError WindowManagerService::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
1355 bool isAsyncTask)
1356 {
1357 if (windowProperty == nullptr) {
1358 WLOGFE("windowProperty is nullptr");
1359 return WMError::WM_ERROR_NULLPTR;
1360 }
1361
1362 if ((windowProperty->GetWindowFlags() == static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE) ||
1363 action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) &&
1364 !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1365 WLOGFE("SetForbidSplitMove or SetShowWhenLocked or SetTranform or SetTurnScreenOn permission denied!");
1366 return WMError::WM_ERROR_INVALID_PERMISSION;
1367 }
1368
1369 WindowType type = windowProperty->GetWindowType();
1370 if (type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT ||
1371 type == WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR) {
1372 if (!Permission::IsStartByInputMethod()) {
1373 WLOGI("Keyboard only hide by input method it'self, operation rejected.");
1374 return WMError::WM_ERROR_INVALID_OPERATION;
1375 }
1376 } else if (!accessTokenIdMaps_.isExist(windowProperty->GetWindowId(), IPCSkeleton::GetCallingTokenID()) &&
1377 !Permission::IsSystemCalling()) {
1378 WLOGI("Operation rejected");
1379 return WMError::WM_ERROR_INVALID_OPERATION;
1380 }
1381
1382 if (action == PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE &&
1383 !Permission::CheckCallingPermission("ohos.permission.PRIVACY_WINDOW")) {
1384 WLOGFE("Set privacy mode permission denied!");
1385 return WMError::WM_ERROR_INVALID_PERMISSION;
1386 }
1387
1388 windowProperty->isSystemCalling_ = Permission::IsSystemCalling();
1389 if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) {
1390 auto task = [this, windowProperty, action]() mutable {
1391 windowController_->UpdateProperty(windowProperty, action);
1392 return WMError::WM_OK;
1393 };
1394 return PostSyncTask(task, "UpdateProperty");
1395 }
1396
1397 if (isAsyncTask || action == PropertyChangeAction::ACTION_UPDATE_RECT) {
1398 auto task = [this, windowProperty, action]() mutable {
1399 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1400 WMError res = windowController_->UpdateProperty(windowProperty, action);
1401 if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1402 (IsMoveToOrDragMove(windowProperty->GetWindowSizeChangeReason()))) {
1403 dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1404 }
1405 };
1406 PostAsyncTask(task, "UpdateProperty");
1407 return WMError::WM_OK;
1408 }
1409
1410 auto task = [this, &windowProperty, action]() {
1411 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1412 WMError res = windowController_->UpdateProperty(windowProperty, action);
1413 if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1414 IsMoveToOrDragMove(windowProperty->GetWindowSizeChangeReason())) {
1415 dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1416 }
1417 return res;
1418 };
1419 return PostSyncTask(task, "UpdateProperty");
1420 }
1421
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)1422 WMError WindowManagerService::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
1423 {
1424 auto task = [this, windowId, gravity, percent]() {
1425 WMError res = windowController_->SetWindowGravity(windowId, gravity, percent);
1426 return res;
1427 };
1428 return PostSyncTask(task, "SetWindowGravity");
1429 }
1430
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1431 WMError WindowManagerService::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1432 {
1433 if (!Permission::IsSystemServiceCalling()) {
1434 WLOGFE("get accessibility window info permission denied!");
1435 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1436 }
1437 auto task = [this, &infos]() {
1438 return windowController_->GetAccessibilityWindowInfo(infos);
1439 };
1440 return PostSyncTask(task, "GetAccessibilityWindowInfo");
1441 }
1442
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)1443 WMError WindowManagerService::GetUnreliableWindowInfo(int32_t windowId,
1444 std::vector<sptr<UnreliableWindowInfo>>& infos)
1445 {
1446 if (!Permission::IsSystemServiceCalling()) {
1447 WLOGFE("get unreliable window info permission denied!");
1448 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1449 }
1450 auto task = [this, windowId, &infos]() {
1451 return windowController_->GetUnreliableWindowInfo(windowId, infos);
1452 };
1453 return PostSyncTask(task, "GetUnreliableWindowInfo");
1454 }
1455
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)1456 WMError WindowManagerService::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
1457 {
1458 auto task = [this, &infos]() {
1459 return windowController_->GetVisibilityWindowInfo(infos);
1460 };
1461 return PostSyncTask(task, "GetVisibilityWindowInfo");
1462 }
1463
1464 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)1465 WMError WindowManagerService::RaiseToAppTop(uint32_t windowId)
1466 {
1467 auto task = [this, windowId]() {
1468 return windowController_->RaiseToAppTop(windowId);
1469 };
1470 return PostSyncTask(task, "RaiseToAppTop");
1471 }
1472
GetSnapshot(int32_t windowId)1473 std::shared_ptr<Media::PixelMap> WindowManagerService::GetSnapshot(int32_t windowId)
1474 {
1475 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1476 WLOGFE("permission denied!");
1477 return nullptr;
1478 }
1479 auto task = [this, windowId]() {
1480 return windowController_->GetSnapshot(windowId);
1481 };
1482 return PostSyncTask(task, "GetSnapshot");
1483 }
1484
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1485 void WindowManagerService::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1486 {
1487 auto task = [this, windowId, event]() {
1488 windowController_->DispatchKeyEvent(windowId, event);
1489 };
1490 PostVoidSyncTask(task, "DispatchKeyEvent");
1491 }
1492
NotifyDumpInfoResult(const std::vector<std::string> & info)1493 void WindowManagerService::NotifyDumpInfoResult(const std::vector<std::string>& info)
1494 {
1495 if (windowDumper_) {
1496 windowDumper_->dumpInfoFuture_.SetValue(info);
1497 }
1498 }
1499
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)1500 WMError WindowManagerService::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
1501 std::vector<sptr<RSWindowAnimationTarget>>& targets)
1502 {
1503 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1504 WLOGFE("get window animation targets permission denied!");
1505 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1506 }
1507 auto task = [this, missionIds, &targets]() {
1508 return RemoteAnimation::GetWindowAnimationTargets(missionIds, targets);
1509 };
1510 return PostSyncTask(task, "GetWindowAnimationTargets");
1511 }
1512
GetSystemConfig(SystemConfig & systemConfig)1513 WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig)
1514 {
1515 systemConfig = systemConfig_;
1516 return WMError::WM_OK;
1517 }
1518
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)1519 WMError WindowManagerService::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
1520 {
1521 if (!hotZonesConfig_.isModeChangeHotZoneConfigured_) {
1522 return WMError::WM_DO_NOTHING;
1523 }
1524
1525 return windowController_->GetModeChangeHotZones(displayId, hotZones, hotZonesConfig_);
1526 }
1527
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)1528 void WindowManagerService::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
1529 sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
1530 {
1531 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1532 WLOGFE("minimize windows by launcher permission denied!");
1533 return;
1534 }
1535 auto task = [this, windowIds, isAnimated, &finishCallback]() mutable {
1536 windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
1537 };
1538 PostVoidSyncTask(task, "MinimizeWindowsByLauncher");
1539 }
1540
UpdateAvoidAreaListener(uint32_t windowId,bool haveAvoidAreaListener)1541 WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener)
1542 {
1543 auto task = [this, windowId, haveAvoidAreaListener]() {
1544 sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
1545 if (node == nullptr) {
1546 WLOGFE("get window node failed. win %{public}u", windowId);
1547 return WMError::WM_DO_NOTHING;
1548 }
1549 sptr<WindowNodeContainer> container = windowRoot_->GetWindowNodeContainer(node->GetDisplayId());
1550 if (container == nullptr) {
1551 WLOGFE("get container failed. win %{public}u display %{public}" PRIu64"", windowId, node->GetDisplayId());
1552 return WMError::WM_DO_NOTHING;
1553 }
1554 container->UpdateAvoidAreaListener(node, haveAvoidAreaListener);
1555 return WMError::WM_OK;
1556 };
1557 return PostSyncTask(task, "UpdateAvoidAreaListener");
1558 }
1559
SetAnchorAndScale(int32_t x,int32_t y,float scale)1560 void WindowManagerService::SetAnchorAndScale(int32_t x, int32_t y, float scale)
1561 {
1562 auto task = [this, x, y, scale]() {
1563 windowController_->SetAnchorAndScale(x, y, scale);
1564 };
1565 PostAsyncTask(task, "SetAnchorAndScale");
1566 }
1567
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1568 void WindowManagerService::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1569 {
1570 auto task = [this, deltaX, deltaY]() {
1571 windowController_->SetAnchorOffset(deltaX, deltaY);
1572 };
1573 PostAsyncTask(task, "SetAnchorOffset");
1574 }
1575
OffWindowZoom()1576 void WindowManagerService::OffWindowZoom()
1577 {
1578 auto task = [this]() {
1579 windowController_->OffWindowZoom();
1580 };
1581 PostAsyncTask(task, "OffWindowZoom");
1582 }
1583
UpdateRsTree(uint32_t windowId,bool isAdd)1584 WMError WindowManagerService::UpdateRsTree(uint32_t windowId, bool isAdd)
1585 {
1586 auto task = [this, windowId, isAdd]() {
1587 return windowRoot_->UpdateRsTree(windowId, isAdd);
1588 };
1589 return PostSyncTask(task, "UpdateRsTree");
1590 }
1591
OnScreenshot(DisplayId displayId)1592 void WindowManagerService::OnScreenshot(DisplayId displayId)
1593 {
1594 auto task = [this, displayId]() {
1595 windowController_->OnScreenshot(displayId);
1596 };
1597 PostAsyncTask(task, "OnScreenshot");
1598 }
1599
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)1600 WMError WindowManagerService::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
1601 {
1602 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1603 WLOGFE("bind dialog target permission denied!");
1604 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1605 }
1606 auto task = [this, &windowId, targetToken]() {
1607 return windowController_->BindDialogTarget(windowId, targetToken);
1608 };
1609 return PostSyncTask(task, "BindDialogTarget");
1610 }
1611
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1612 void WindowManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1613 {
1614 auto task = [this, displayId, &hasPrivateWindow]() mutable {
1615 hasPrivateWindow = windowRoot_->HasPrivateWindow(displayId);
1616 };
1617 PostVoidSyncTask(task, "HasPrivateWindow");
1618 WLOGI("called %{public}u", hasPrivateWindow);
1619 }
1620
SetGestureNavigationEnabled(bool enable)1621 WMError WindowManagerService::SetGestureNavigationEnabled(bool enable)
1622 {
1623 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1624 WLOGFE("permission denied!");
1625 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1626 }
1627 auto task = [this, enable]() {
1628 return windowRoot_->SetGestureNavigationEnabled(enable);
1629 };
1630 return PostSyncTask(task, "SetGestureNavigationEnabled");
1631 }
1632
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1633 void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1634 {
1635 WLOGI("called");
1636 WindowManagerService::GetInstance().HasPrivateWindow(displayId, hasPrivateWindow);
1637 }
1638
SetMaximizeMode(MaximizeMode maximizeMode)1639 void WindowManagerService::SetMaximizeMode(MaximizeMode maximizeMode)
1640 {
1641 maximizeMode_ = maximizeMode;
1642 int32_t storageMode = -1;
1643 if (PersistentStorage::HasKey("maximize_state", PersistentStorageType::MAXIMIZE_STATE)) {
1644 PersistentStorage::Get("maximize_state", storageMode, PersistentStorageType::MAXIMIZE_STATE);
1645 PersistentStorage::Delete("maximize_state", PersistentStorageType::MAXIMIZE_STATE);
1646 }
1647 PersistentStorage::Insert("maximize_state", static_cast<int32_t>(maximizeMode),
1648 PersistentStorageType::MAXIMIZE_STATE);
1649 WLOGI("globalMaximizeMode changed from %{public}d to %{public}d", storageMode, static_cast<int32_t>(maximizeMode));
1650 }
1651
GetMaximizeMode()1652 MaximizeMode WindowManagerService::GetMaximizeMode()
1653 {
1654 return maximizeMode_;
1655 }
1656
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)1657 void WindowManagerService::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
1658 {
1659 WLOGFD("Get Focus window info in wms");
1660 windowController_->GetFocusWindowInfo(focusInfo);
1661 }
1662
InitRSUIDirector()1663 void WindowManagerService::InitRSUIDirector()
1664 {
1665 rsUiDirector_ = RSUIDirector::Create();
1666 if (!rsUiDirector_) {
1667 TLOGE(WmsLogTag::WMS_SCB, "Failed to create RSUIDirector");
1668 return;
1669 }
1670 int32_t instanceId = INSTANCE_ID_UNDEFINED;
1671 bool useMultiInstance = false;
1672 RunIfRSClientMultiInstanceEnabled([&] {
1673 instanceId = 0;
1674 useMultiInstance = true;
1675 WindowInnerManager::GetInstance().SetRSUIDirector(rsUiDirector_);
1676 });
1677 rsUiDirector_->SetUITaskRunner([this](const std::function<void()>& task, uint32_t delay) {
1678 PostAsyncTask(task, "WindowManagerService:cacheGuard", delay);
1679 }, instanceId, useMultiInstance);
1680 rsUiDirector_->Init(false, useMultiInstance);
1681 TLOGI(WmsLogTag::WMS_SCB, "Create RSUIDirector: %{public}s",
1682 RSAdapterUtil::RSUIDirectorToStr(rsUiDirector_).c_str());
1683 }
1684 } // namespace Rosen
1685 } // namespace OHOS
1686