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 "singleton_container.h"
43 #include "starting_window.h"
44 #include "ui/rs_ui_director.h"
45 #include "window_helper.h"
46 #include "window_inner_manager.h"
47 #include "window_layout_policy.h"
48 #include "window_manager_agent_controller.h"
49 #include "window_manager_hilog.h"
50 #include "wm_common.h"
51 #include "wm_math.h"
52
53 namespace OHOS {
54 namespace Rosen {
55 namespace {
56 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WMS"};
57 }
58 WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService)
59
60 const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false :
61 SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<WindowManagerService>());
62 const std::string BOOTEVENT_WMS_READY = "bootevent.wms.ready";
63
WindowManagerService()64 WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true),
65 rsInterface_(RSInterfaces::GetInstance()),
66 windowShowPerformReport_(new PerformReporter("SHOW_WINDOW_TIME", {20, 35, 50}))
67 {
68 windowRoot_ = new WindowRoot(
__anon8059612b0202(Event event, const sptr<IRemoteObject>& remoteObject) 69 [this](Event event, const sptr<IRemoteObject>& remoteObject) { OnWindowEvent(event, remoteObject); });
70 inputWindowMonitor_ = new InputWindowMonitor(windowRoot_);
71 windowController_ = new WindowController(windowRoot_, inputWindowMonitor_);
72 dragController_ = new DragController(windowRoot_);
73 windowDumper_ = new WindowDumper(windowRoot_);
74 freezeDisplayController_ = new FreezeController();
75 windowCommonEvent_ = std::make_shared<WindowCommonEvent>();
76 startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled
77 windowGroupMgr_ = new WindowGroupMgr(windowRoot_);
78 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
79 return;
80 }
81 runner_ = AppExecFwk::EventRunner::Create(name_);
82 handler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
83 snapshotController_ = new SnapshotController(windowRoot_, handler_);
84 int ret = HiviewDFX::Watchdog::GetInstance().AddThread(name_, handler_);
85 if (ret != 0) {
86 WLOGFE("Add watchdog thread failed");
87 }
__anon8059612b0302() 88 handler_->PostTask([]() { MemoryGuard cacheGuard; }, "WindowManagerService:cacheGuard", 0,
89 AppExecFwk::EventQueue::Priority::IMMEDIATE);
90 // init RSUIDirector, it will handle animation callback
91 rsUiDirector_ = RSUIDirector::Create();
__anon8059612b0402(const std::function<void()>& task, uint32_t delay) 92 rsUiDirector_->SetUITaskRunner([this](const std::function<void()>& task, uint32_t delay) {
93 PostAsyncTask(task, "WindowManagerService:cacheGuard", delay);
94 });
95 rsUiDirector_->Init(false);
96 }
97
OnStart()98 void WindowManagerService::OnStart()
99 {
100 WLOGI("start");
101 if (!Init()) {
102 WLOGFE("Init failed");
103 return;
104 }
105 WindowInnerManager::GetInstance().Start(system::GetParameter("persist.window.holder.enable", "0") == "1");
106 WindowInnerManager::GetInstance().StartWindowInfoReportLoop();
107 WindowInnerManager::GetInstance().SetWindowRoot(windowRoot_);
108 sptr<IDisplayChangeListener> listener = new DisplayChangeListener();
109 DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener);
110
111 sptr<IWindowInfoQueriedListener> windowInfoQueriedListener = new WindowInfoQueriedListener();
112 DisplayManagerServiceInner::GetInstance().RegisterWindowInfoQueriedListener(windowInfoQueriedListener);
113 system::SetParameter(BOOTEVENT_WMS_READY.c_str(), "true");
114 AddSystemAbilityListener(RENDER_SERVICE);
115 AddSystemAbilityListener(ABILITY_MGR_SERVICE_ID);
116 AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
117 AddSystemAbilityListener(MULTIMODAL_INPUT_SERVICE_ID);
118 sptr<WindowManagerService> wms = this;
119 wms->IncStrongRef(nullptr);
120 if (!Publish(sptr<WindowManagerService>(this))) {
121 WLOGFE("Publish failed");
122 }
123 WLOGI("end");
124 }
125
PostAsyncTask(Task task,const std::string & taskName,uint32_t delay)126 void WindowManagerService::PostAsyncTask(Task task, const std::string& taskName, uint32_t delay)
127 {
128 if (handler_) {
129 bool ret = handler_->PostTask(task, "wms:" + taskName, delay, AppExecFwk::EventQueue::Priority::IMMEDIATE);
130 if (!ret) {
131 WLOGFE("EventHandler PostTask Failed");
132 }
133 }
134 }
135
PostVoidSyncTask(Task task,const std::string & taskName)136 void WindowManagerService::PostVoidSyncTask(Task task, const std::string& taskName)
137 {
138 if (handler_) {
139 bool ret = handler_->PostSyncTask(task, "wms:" + taskName, AppExecFwk::EventQueue::Priority::IMMEDIATE);
140 if (!ret) {
141 WLOGFE("EventHandler PostVoidSyncTask Failed");
142 }
143 }
144 }
145
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)146 void WindowManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
147 {
148 WLOGI("systemAbilityId: %{public}d, start", systemAbilityId);
149 switch (systemAbilityId) {
150 case RENDER_SERVICE:
151 WLOGI("RENDER_SERVICE");
152 InitWithRanderServiceAdded();
153 break;
154 case ABILITY_MGR_SERVICE_ID:
155 WLOGI("ABILITY_MGR_SERVICE_ID");
156 InitWithAbilityManagerServiceAdded();
157 break;
158 case COMMON_EVENT_SERVICE_ID:
159 WLOGI("COMMON_EVENT_SERVICE_ID");
160 windowCommonEvent_->SubscriberEvent();
161 break;
162 case MULTIMODAL_INPUT_SERVICE_ID:
163 WLOGI("MULTIMODAL_INPUT_SERVICE_ID");
164 if (windowRoot_ == nullptr) {
165 WLOGFE("windowRoot_ is nullptr.");
166 return;
167 }
168 windowRoot_->NotifyMMIServiceOnline();
169 break;
170 default:
171 WLOGFW("unhandled sysabilityId: %{public}d", systemAbilityId);
172 break;
173 }
174 WLOGI("systemAbilityId: %{public}d, end", systemAbilityId);
175 }
176
SetWindowInputEventConsumer()177 void WindowManagerService::SetWindowInputEventConsumer()
178 {
179 WindowInnerManager::GetInstance().SetInputEventConsumer();
180 }
181
OnAccountSwitched(int accountId)182 void WindowManagerService::OnAccountSwitched(int accountId)
183 {
184 auto task = [this, accountId]() {
185 windowRoot_->RemoveSingleUserWindowNodes(accountId);
186 };
187 PostAsyncTask(task, "OnAccountSwitched");
188 WLOGI("called");
189 }
190
WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData)191 void WindowManagerService::WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData)
192 {
193 WLOGI("NotifyWindowVisibilityChange: enter");
194 std::weak_ptr<RSOcclusionData> weak(occlusionData);
195 auto task = [this, weak]() {
196 auto weakOcclusionData = weak.lock();
197 if (weakOcclusionData == nullptr) {
198 WLOGFE("weak occlusionData is nullptr");
199 return;
200 }
201 windowRoot_->NotifyWindowVisibilityChange(weakOcclusionData);
202 };
203 PostVoidSyncTask(task, "WindowVisibilityChangeCallback");
204 }
205
InitWithRanderServiceAdded()206 void WindowManagerService::InitWithRanderServiceAdded()
207 {
208 auto windowVisibilityChangeCb =
209 [this](std::shared_ptr<RSOcclusionData> occlusionData) { this->WindowVisibilityChangeCallback(occlusionData); };
210 WLOGI("RegisterWindowVisibilityChangeCallback");
211 if (rsInterface_.RegisterOcclusionChangeCallback(windowVisibilityChangeCb) != WM_OK) {
212 WLOGFE("RegisterWindowVisibilityChangeCallback failed");
213 }
214 }
215
InitWithAbilityManagerServiceAdded()216 void WindowManagerService::InitWithAbilityManagerServiceAdded()
217 {
218 if (snapshotController_ == nullptr) {
219 snapshotController_ = new SnapshotController(windowRoot_, handler_);
220 }
221 WLOGI("RegisterSnapshotHandler");
222 if (AAFwk::AbilityManagerClient::GetInstance()->RegisterSnapshotHandler(snapshotController_) != ERR_OK) {
223 WLOGFE("RegisterSnapshotHandler failed");
224 }
225
226 if (wmsHandler_ == nullptr) {
227 wmsHandler_ = new WindowManagerServiceHandler();
228 }
229 WLOGI("RegisterWindowManagerServiceHandler");
230 bool animaEnabled = RemoteAnimation::CheckAnimationController();
231 if (AAFwk::AbilityManagerClient::GetInstance()->RegisterWindowManagerServiceHandler(
232 wmsHandler_, animaEnabled) != ERR_OK) {
233 WLOGFE("RegisterWindowManagerServiceHandler failed");
234 }
235 }
236
NotifyWindowTransition(sptr<AAFwk::AbilityTransitionInfo> from,sptr<AAFwk::AbilityTransitionInfo> to,bool & animaEnabled)237 void WindowManagerServiceHandler::NotifyWindowTransition(
238 sptr<AAFwk::AbilityTransitionInfo> from, sptr<AAFwk::AbilityTransitionInfo> to, bool& animaEnabled)
239 {
240 sptr<WindowTransitionInfo> fromInfo = nullptr;
241 sptr<WindowTransitionInfo> toInfo = nullptr;
242 if (from) { // if exists, transition to window transition info
243 fromInfo = new WindowTransitionInfo(from);
244 }
245 if (to) {
246 toInfo = new WindowTransitionInfo(to);
247 }
248 animaEnabled = RemoteAnimation::CheckAnimationController();
249 WindowManagerService::GetInstance().NotifyWindowTransition(fromInfo, toInfo, false);
250 }
251
NotifyAnimationAbilityDied(sptr<AAFwk::AbilityTransitionInfo> info)252 void WindowManagerServiceHandler::NotifyAnimationAbilityDied(sptr<AAFwk::AbilityTransitionInfo> info)
253 {
254 sptr<WindowTransitionInfo> windowTransitionInfo = new WindowTransitionInfo(info);
255 WindowManagerService::GetInstance().NotifyAnimationAbilityDied(windowTransitionInfo);
256 }
257
GetFocusWindow(sptr<IRemoteObject> & abilityToken)258 int32_t WindowManagerServiceHandler::GetFocusWindow(sptr<IRemoteObject>& abilityToken)
259 {
260 return static_cast<int32_t>(WindowManagerService::GetInstance().GetFocusWindowInfo(abilityToken));
261 }
262
StartingWindow(sptr<AAFwk::AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap)263 void WindowManagerServiceHandler::StartingWindow(
264 sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap)
265 {
266 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "hot start is called");
267 sptr<WindowTransitionInfo> windowInfo = new WindowTransitionInfo(info);
268 WindowManagerService::GetInstance().StartingWindow(windowInfo, pixelMap, false);
269 }
270
StartingWindow(sptr<AAFwk::AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bgColor)271 void WindowManagerServiceHandler::StartingWindow(
272 sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor)
273 {
274 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "cold start is called");
275 sptr<WindowTransitionInfo> windowInfo = new WindowTransitionInfo(info);
276 WindowManagerService::GetInstance().StartingWindow(windowInfo, pixelMap, true, bgColor);
277 }
278
CancelStartingWindow(sptr<IRemoteObject> abilityToken)279 void WindowManagerServiceHandler::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
280 {
281 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "called");
282 WindowManagerService::GetInstance().CancelStartingWindow(abilityToken);
283 }
284
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)285 int32_t WindowManagerServiceHandler::MoveMissionsToForeground(const std::vector<int32_t>& missionIds,
286 int32_t topMissionId)
287 {
288 TLOGD(WmsLogTag::WMS_STARTUP_PAGE, "called");
289 return static_cast<int32_t>(WindowManagerService::GetInstance().MoveMissionsToForeground(missionIds, topMissionId));
290 }
291
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)292 int32_t WindowManagerServiceHandler::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
293 std::vector<int32_t>& result)
294 {
295 TLOGD(WmsLogTag::WMS_STARTUP_PAGE, "called");
296 return static_cast<int32_t>(WindowManagerService::GetInstance().MoveMissionsToBackground(missionIds, result));
297 }
298
Init()299 bool WindowManagerService::Init()
300 {
301 WLOGI("Init start");
302 if (WindowManagerConfig::LoadConfigXml()) {
303 if (WindowManagerConfig::GetConfig().IsMap()) {
304 WindowManagerConfig::DumpConfig(*WindowManagerConfig::GetConfig().mapValue_);
305 }
306 LoadWindowParameter();
307 ConfigureWindowManagerService();
308 StartingWindow::SetAnimationConfig(WindowNodeContainer::GetAnimationConfigRef());
309 }
310 if (PersistentStorage::HasKey("maximize_state", PersistentStorageType::MAXIMIZE_STATE)) {
311 int32_t storageMode = -1;
312 PersistentStorage::Get("maximize_state", storageMode, PersistentStorageType::MAXIMIZE_STATE);
313 if (storageMode == static_cast<int32_t>(MaximizeMode::MODE_AVOID_SYSTEM_BAR) ||
314 storageMode == static_cast<int32_t>(MaximizeMode::MODE_FULL_FILL)) {
315 maximizeMode_ = static_cast<MaximizeMode>(storageMode);
316 }
317 }
318 WindowSystemEffect::SetWindowRoot(windowRoot_);
319 WLOGI("Init success");
320 return true;
321 }
322
Dump(int fd,const std::vector<std::u16string> & args)323 int WindowManagerService::Dump(int fd, const std::vector<std::u16string>& args)
324 {
325 if (windowDumper_ == nullptr) {
326 windowDumper_ = new WindowDumper(windowRoot_);
327 }
328 WLOGFI("Pid : %{public}d", IPCSkeleton::GetCallingPid());
329 auto task = [this, fd, &args]() {
330 return static_cast<int>(windowDumper_->Dump(fd, args));
331 };
332 return PostSyncTask(task, "Dump");
333 }
334
LoadWindowParameter()335 void WindowManagerService::LoadWindowParameter()
336 {
337 const std::string multiWindowUIType = system::GetParameter("const.window.multiWindowUIType", "");
338 if (multiWindowUIType == "HandsetSmartWindow") {
339 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
340 WindowNodeContainer::windowUIType_ = WindowUIType::PHONE_WINDOW;
341 } else if (multiWindowUIType == "FreeFormMultiWindow") {
342 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
343 WindowNodeContainer::windowUIType_ = WindowUIType::PC_WINDOW;
344 } else if (multiWindowUIType == "TabletSmartWindow") {
345 systemConfig_.windowUIType_ = StartingWindow::windowUIType_ =
346 WindowNodeContainer::windowUIType_ = WindowUIType::PAD_WINDOW;
347 } else {
348 WLOGFE("unknown multiWindowUIType:%{public}s.", multiWindowUIType.c_str());
349 }
350 }
351
ConfigureWindowManagerService()352 void WindowManagerService::ConfigureWindowManagerService()
353 {
354 const auto& config = WindowManagerConfig::GetConfig();
355 WindowManagerConfig::ConfigItem item = config["decor"];
356 if (item.IsMap()) {
357 ConfigDecor(item);
358 }
359 item = config["minimizeByOther"].GetProp("enable");
360 if (item.IsBool()) {
361 MinimizeApp::SetMinimizedByOtherConfig(item.boolValue_);
362 }
363 item = config["stretchable"].GetProp("enable");
364 if (item.IsBool()) {
365 systemConfig_.isStretchable_ = item.boolValue_;
366 }
367 item = config["defaultWindowMode"];
368 if (item.IsInts()) {
369 auto numbers = *item.intsValue_;
370 if (numbers.size() == 1 &&
371 (numbers[0] == static_cast<int32_t>(WindowMode::WINDOW_MODE_FULLSCREEN) ||
372 numbers[0] == static_cast<int32_t>(WindowMode::WINDOW_MODE_FLOATING))) {
373 systemConfig_.defaultWindowMode_ = static_cast<WindowMode>(static_cast<uint32_t>(numbers[0]));
374 StartingWindow::SetDefaultWindowMode(systemConfig_.defaultWindowMode_);
375 }
376 }
377 item = config["dragFrameGravity"];
378 if (item.IsInts()) {
379 auto numbers = *item.intsValue_;
380 if (numbers.size() == 1
381 && (numbers[0] == static_cast<int32_t>(Gravity::RESIZE)
382 || numbers[0] == static_cast<int32_t>(Gravity::TOP_LEFT))) {
383 windowController_->SetDragFrameGravity(static_cast<int32_t>(numbers[0]));
384 }
385 }
386 item = config["remoteAnimation"].GetProp("enable");
387 if (item.IsBool()) {
388 RemoteAnimation::isRemoteAnimationEnable_ = item.boolValue_;
389 }
390 item = config["maxAppWindowNumber"];
391 if (item.IsInts()) {
392 auto numbers = *item.intsValue_;
393 if (numbers.size() == 1 && numbers[0] > 0) {
394 windowRoot_->SetMaxAppWindowNumber(static_cast<uint32_t>(numbers[0]));
395 }
396 }
397 item = config["modeChangeHotZones"];
398 if (item.IsInts()) {
399 ConfigHotZones(*item.intsValue_);
400 }
401 item = config["splitRatios"];
402 if (item.IsFloats()) {
403 windowRoot_->SetSplitRatios(*item.floatsValue_);
404 }
405 item = config["exitSplitRatios"];
406 if (item.IsFloats()) {
407 windowRoot_->SetExitSplitRatios(*item.floatsValue_);
408 }
409 item = config["windowAnimation"];
410 if (item.IsMap()) {
411 ConfigWindowAnimation(item);
412 }
413 item = config["keyboardAnimation"];
414 if (item.IsMap()) {
415 ConfigKeyboardAnimation(item);
416 }
417 item = config["startWindowTransitionAnimation"];
418 if (item.IsMap()) {
419 ConfigStartingWindowAnimation(item);
420 }
421 item = config["windowEffect"];
422 if (item.IsMap()) {
423 ConfigWindowEffect(item);
424 }
425 item = config["floatingBottomPosY"];
426 if (item.IsInts()) {
427 auto numbers = *item.intsValue_;
428 if (numbers.size() == 1 && numbers[0] > 0) {
429 WindowLayoutPolicy::SetCascadeRectBottomPosYLimit(static_cast<uint32_t>(numbers[0]));
430 }
431 }
432 item = config["configMainFloatingWindowAbove"].GetProp("enable");
433 if (item.IsBool()) {
434 WindowNodeContainer::SetConfigMainFloatingWindowAbove(item.boolValue_);
435 }
436 item = config["maxMainFloatingWindowNumber"];
437 if (item.IsInts()) {
438 auto numbers = *item.intsValue_;
439 if (numbers.size() == 1 && numbers[0] > 0) {
440 WindowNodeContainer::SetMaxMainFloatingWindowNumber(static_cast<uint32_t>(numbers[0]));
441 }
442 }
443 item = config["maxFloatingWindowSize"];
444 if (item.IsInts()) {
445 auto numbers = *item.intsValue_;
446 if (numbers.size() == 1 && numbers[0] > 0) {
447 WindowLayoutPolicy::SetMaxFloatingWindowSize(static_cast<uint32_t>(numbers[0]));
448 }
449 }
450 item = config["defaultMaximizeMode"];
451 if (item.IsInts()) {
452 auto numbers = *item.intsValue_;
453 if (numbers.size() == 1 &&
454 (numbers[0] == static_cast<int32_t>(MaximizeMode::MODE_AVOID_SYSTEM_BAR) ||
455 numbers[0] == static_cast<int32_t>(MaximizeMode::MODE_FULL_FILL))) {
456 maximizeMode_ = static_cast<MaximizeMode>(numbers[0]);
457 }
458 }
459 item = config["supportTypeFloatWindow"].GetProp("enable");
460 if (item.IsBool()) {
461 systemConfig_.supportTypeFloatWindow_ = item.boolValue_;
462 }
463 }
464
ConfigHotZones(const std::vector<int> & numbers)465 void WindowManagerService::ConfigHotZones(const std::vector<int>& numbers)
466 {
467 if (numbers.size() == 3) { // 3 hot zones
468 hotZonesConfig_.fullscreenRange_ = static_cast<uint32_t>(numbers[0]); // 0 fullscreen
469 hotZonesConfig_.primaryRange_ = static_cast<uint32_t>(numbers[1]); // 1 primary
470 hotZonesConfig_.secondaryRange_ = static_cast<uint32_t>(numbers[2]); // 2 secondary
471 hotZonesConfig_.isModeChangeHotZoneConfigured_ = true;
472 }
473 }
474
ConfigDecor(const WindowManagerConfig::ConfigItem & decorConfig)475 void WindowManagerService::ConfigDecor(const WindowManagerConfig::ConfigItem& decorConfig)
476 {
477 WindowManagerConfig::ConfigItem item = decorConfig.GetProp("enable");
478 if (item.IsBool()) {
479 systemConfig_.isSystemDecorEnable_ = item.boolValue_;
480 std::vector<std::string> supportedModes;
481 item = decorConfig["supportedMode"];
482 if (item.IsStrings()) {
483 systemConfig_.decorWindowModeSupportType_ = 0;
484 supportedModes = *item.stringsValue_;
485 }
486 for (auto mode : supportedModes) {
487 if (mode == "fullscreen") {
488 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN;
489 } else if (mode == "floating") {
490 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
491 } else if (mode == "pip") {
492 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_PIP;
493 } else if (mode == "split") {
494 systemConfig_.decorWindowModeSupportType_ |= WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
495 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY;
496 } else {
497 WLOGFW("Invalid supporedMode");
498 systemConfig_.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
499 break;
500 }
501 }
502 }
503 }
504
ConfigWindowAnimation(const WindowManagerConfig::ConfigItem & animeConfig)505 void WindowManagerService::ConfigWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
506 {
507 auto& windowAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().windowAnimationConfig_;
508 WindowManagerConfig::ConfigItem item = animeConfig["timing"];
509 if (item.IsMap() && item.mapValue_->count("curve")) {
510 windowAnimationConfig.animationTiming_.timingCurve_ = CreateCurve(item["curve"]);
511 }
512 item = animeConfig["timing"]["duration"];
513 if (item.IsInts()) {
514 auto numbers = *item.intsValue_;
515 if (numbers.size() == 1) { // duration
516 windowAnimationConfig.animationTiming_.timingProtocol_ =
517 RSAnimationTimingProtocol(numbers[0]);
518 }
519 }
520 item = animeConfig["scale"];
521 if (item.IsFloats()) {
522 auto numbers = *item.floatsValue_;
523 if (numbers.size() == 1) { // 1 xy scale
524 windowAnimationConfig.scale_.x_ =
525 windowAnimationConfig.scale_.y_ = numbers[0]; // 0 xy scale
526 } else if (numbers.size() == 2) { // 2 x,y sclae
527 windowAnimationConfig.scale_.x_ = numbers[0]; // 0 x scale
528 windowAnimationConfig.scale_.y_ = numbers[1]; // 1 y scale
529 } else if (numbers.size() == 3) { // 3 x,y,z scale
530 windowAnimationConfig.scale_ = Vector3f(&numbers[0]);
531 }
532 }
533 item = animeConfig["rotation"];
534 if (item.IsFloats() && item.floatsValue_->size() == 4) { // 4 (axix,angle)
535 windowAnimationConfig.rotation_ = Vector4f(item.floatsValue_->data());
536 }
537 item = animeConfig["translate"];
538 if (item.IsFloats()) {
539 auto numbers = *item.floatsValue_;
540 if (numbers.size() == 2) { // 2 translate xy
541 windowAnimationConfig.translate_.x_ = numbers[0]; // 0 translate x
542 windowAnimationConfig.translate_.y_ = numbers[1]; // 1 translate y
543 } else if (numbers.size() == 3) { // 3 translate xyz
544 windowAnimationConfig.translate_.x_ = numbers[0]; // 0 translate x
545 windowAnimationConfig.translate_.y_ = numbers[1]; // 1 translate y
546 windowAnimationConfig.translate_.z_ = numbers[2]; // 2 translate z
547 }
548 }
549 item = animeConfig["opacity"];
550 if (item.IsFloats()) {
551 auto numbers = *item.floatsValue_;
552 numbers.size() == 1 ? (windowAnimationConfig.opacity_ = numbers[0]) : float();
553 }
554 }
555
ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem & animeConfig)556 void WindowManagerService::ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
557 {
558 auto& animationConfig = WindowNodeContainer::GetAnimationConfigRef();
559 WindowManagerConfig::ConfigItem inItem = animeConfig["animationIn"]["timing"];
560 if (inItem.IsMap() && inItem.mapValue_ != nullptr && inItem.mapValue_->count("curve")) {
561 CreateKeyboardCurve(inItem, animationConfig.keyboardAnimationIn_, systemConfig_.animationIn_);
562 }
563
564 WindowManagerConfig::ConfigItem outItem = animeConfig["animationOut"]["timing"];
565 if (outItem.IsMap() && outItem.mapValue_ != nullptr && outItem.mapValue_->count("curve")) {
566 CreateKeyboardCurve(outItem, animationConfig.keyboardAnimationOut_, systemConfig_.animationOut_);
567 }
568 WLOGFI("curveIn:[%{public}s, %{public}u], curveOut:[%{public}s, %{public}u]",
569 systemConfig_.animationIn_.curveType_.c_str(), systemConfig_.animationIn_.duration_,
570 systemConfig_.animationOut_.curveType_.c_str(), systemConfig_.animationOut_.duration_);
571 }
572
ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem & animeConfig)573 void WindowManagerService::ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig)
574 {
575 WindowManagerConfig::ConfigItem item = animeConfig.GetProp("enable");
576 if (item.IsBool()) {
577 StartingWindow::transAnimateEnable_ = item.boolValue_;
578 }
579 auto& startWinAnimationConfig = WindowNodeContainer::GetAnimationConfigRef().startWinAnimationConfig_;
580 item = animeConfig["timing"];
581 if (item.IsMap() && item.mapValue_->count("curve")) {
582 startWinAnimationConfig.timingCurve_ = CreateCurve(item["curve"]);
583 }
584 item = animeConfig["timing"]["duration"];
585 if (item.IsInts()) {
586 auto numbers = *item.intsValue_;
587 if (numbers.size() == 1) { // duration
588 startWinAnimationConfig.timingProtocol_ = RSAnimationTimingProtocol(numbers[0]);
589 }
590 }
591 item = animeConfig["opacityStart"];
592 if (item.IsFloats()) {
593 auto numbers = *item.floatsValue_;
594 numbers.size() == 1 ? (startWinAnimationConfig.opacityStart_ = numbers[0]) : float();
595 }
596 item = animeConfig["opacityEnd"];
597 if (item.IsFloats()) {
598 auto numbers = *item.floatsValue_;
599 numbers.size() == 1 ? (startWinAnimationConfig.opacityEnd_ = numbers[0]) : float();
600 }
601 }
602
ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem & item,float & out)603 bool WindowManagerService::ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out)
604 {
605 std::map<std::string, float> stringToCornerRadius = {
606 {"off", 0.0f}, {"defaultCornerRadiusXS", 4.0f}, {"defaultCornerRadiusS", 8.0f},
607 {"defaultCornerRadiusM", 12.0f}, {"defaultCornerRadiusL", 16.0f}, {"defaultCornerRadiusXL", 24.0f}
608 };
609
610 if (item.IsString()) {
611 auto value = item.stringValue_;
612 if (stringToCornerRadius.find(value) != stringToCornerRadius.end()) {
613 out = stringToCornerRadius[value];
614 return true;
615 }
616 }
617 return false;
618 }
619
ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem & shadowConfig,WindowShadowParameters & outShadow)620 bool WindowManagerService::ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig,
621 WindowShadowParameters& outShadow)
622 {
623 WindowManagerConfig::ConfigItem item = shadowConfig["elevation"];
624 if (item.IsFloats()) {
625 auto elevation = *item.floatsValue_;
626 if (elevation.size() != 1 || MathHelper::LessNotEqual(elevation[0], 0.0)) {
627 return false;
628 }
629 outShadow.elevation_ = elevation[0];
630 }
631
632 item = shadowConfig["color"];
633 if (item.IsString()) {
634 auto color = item.stringValue_;
635 uint32_t colorValue;
636 if (!ColorParser::Parse(color, colorValue)) {
637 return false;
638 }
639 outShadow.color_ = color;
640 }
641
642 item = shadowConfig["offsetX"];
643 if (item.IsFloats()) {
644 auto offsetX = *item.floatsValue_;
645 if (offsetX.size() != 1) {
646 return false;
647 }
648 outShadow.offsetX_ = offsetX[0];
649 }
650
651 item = shadowConfig["offsetY"];
652 if (item.IsFloats()) {
653 auto offsetY = *item.floatsValue_;
654 if (offsetY.size() != 1) {
655 return false;
656 }
657 outShadow.offsetY_ = offsetY[0];
658 }
659
660 item = shadowConfig["alpha"];
661 if (item.IsFloats()) {
662 auto alpha = *item.floatsValue_;
663 if (alpha.size() != 1 ||
664 (MathHelper::LessNotEqual(alpha[0], 0.0) && MathHelper::GreatNotEqual(alpha[0], 1.0))) {
665 return false;
666 }
667 outShadow.alpha_ = alpha[0];
668 }
669
670 item = shadowConfig["radius"];
671 if (item.IsFloats()) {
672 auto radius = *item.floatsValue_;
673 if (radius.size() != 1 || MathHelper::LessNotEqual(radius[0], 0.0)) {
674 return false;
675 }
676 outShadow.radius_ = radius[0];
677 }
678
679 return true;
680 }
681
ConfigWindowEffect(const WindowManagerConfig::ConfigItem & effectConfig)682 void WindowManagerService::ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig)
683 {
684 AppWindowEffectConfig config;
685 AppWindowEffectConfig systemEffectConfig;
686 // config corner radius
687 WindowManagerConfig::ConfigItem item = effectConfig["appWindows"]["cornerRadius"];
688 if (item.IsMap()) {
689 if (ConfigAppWindowCornerRadius(item["fullScreen"], config.fullScreenCornerRadius_) &&
690 ConfigAppWindowCornerRadius(item["split"], config.splitCornerRadius_) &&
691 ConfigAppWindowCornerRadius(item["float"], config.floatCornerRadius_)) {
692 systemEffectConfig = config;
693 }
694 }
695
696 // config shadow
697 item = effectConfig["appWindows"]["shadow"]["focused"];
698 if (item.IsMap()) {
699 if (ConfigAppWindowShadow(item, config.focusedShadow_)) {
700 systemEffectConfig.focusedShadow_ = config.focusedShadow_;
701 }
702 }
703
704 item = effectConfig["appWindows"]["shadow"]["unfocused"];
705 if (item.IsMap()) {
706 if (ConfigAppWindowShadow(item, config.unfocusedShadow_)) {
707 systemEffectConfig.unfocusedShadow_ = config.unfocusedShadow_;
708 }
709 }
710 WindowSystemEffect::SetWindowSystemEffectConfig(systemEffectConfig);
711 }
712
CreateKeyboardCurve(const WindowManagerConfig::ConfigItem & config,AnimationConfig::KeyboardAnimation & animateConfig,KeyboardAnimationCurve & sysCurveConfig)713 void WindowManagerService::CreateKeyboardCurve(const WindowManagerConfig::ConfigItem& config,
714 AnimationConfig::KeyboardAnimation& animateConfig, KeyboardAnimationCurve& sysCurveConfig)
715 {
716 // parse curve params
717 const WindowManagerConfig::ConfigItem& curveConfig = config["curve"];
718 static std::map<std::string, RSAnimationTimingCurve> curveMap = {
719 { "easeOut", RSAnimationTimingCurve::EASE_OUT },
720 { "ease", RSAnimationTimingCurve::EASE },
721 { "easeIn", RSAnimationTimingCurve::EASE_IN },
722 { "easeInOut", RSAnimationTimingCurve::EASE_IN_OUT },
723 { "default", RSAnimationTimingCurve::DEFAULT },
724 { "linear", RSAnimationTimingCurve::LINEAR },
725 { "spring", RSAnimationTimingCurve::SPRING },
726 { "interactiveSpring", RSAnimationTimingCurve::INTERACTIVE_SPRING }
727 };
728 RSAnimationTimingCurve curve = RSAnimationTimingCurve::EASE_OUT;
729 std::string keyboardCurveName = "easeOut";
730 std::vector<float> keyboardCurveParams = {};
731 const auto& nameItem = curveConfig.GetProp("name");
732 if (nameItem.IsString()) {
733 std::string name = nameItem.stringValue_;
734 if (name == "cubic" && curveConfig.IsFloats() && curveConfig.floatsValue_ != nullptr &&
735 curveConfig.floatsValue_->size() == 4) { // 4: param size
736 const auto& numbers = *curveConfig.floatsValue_;
737 keyboardCurveName = name;
738 keyboardCurveParams.assign(numbers.begin(), numbers.end());
739 curve = RSAnimationTimingCurve::CreateCubicCurve(
740 numbers[0], // 0 ctrlX1
741 numbers[1], // 1 ctrlY1
742 numbers[2], // 2 ctrlX2
743 numbers[3]); // 3 ctrlY2
744 } else {
745 auto iter = curveMap.find(name);
746 if (iter != curveMap.end()) {
747 keyboardCurveName = name;
748 curve = iter->second;
749 }
750 }
751 }
752 animateConfig.curve_ = curve;
753 sysCurveConfig.curveType_ = keyboardCurveName;
754 sysCurveConfig.curveParams_.assign(keyboardCurveParams.begin(), keyboardCurveParams.end());
755
756 // parse curve duration
757 const WindowManagerConfig::ConfigItem& duration = config["duration"];
758 if (duration.IsInts() && duration.intsValue_ != nullptr) {
759 auto numbers = *duration.intsValue_;
760 if (numbers.size() == 1) { // duration
761 animateConfig.duration_ = RSAnimationTimingProtocol(numbers[0]);
762 sysCurveConfig.duration_ = static_cast<uint32_t>(numbers[0]);
763 }
764 }
765 }
766
CreateCurve(const WindowManagerConfig::ConfigItem & curveConfig)767 RSAnimationTimingCurve WindowManagerService::CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig)
768 {
769 static std::map<std::string, RSAnimationTimingCurve> curveMap = {
770 { "easeOut", RSAnimationTimingCurve::EASE_OUT },
771 { "ease", RSAnimationTimingCurve::EASE },
772 { "easeIn", RSAnimationTimingCurve::EASE_IN },
773 { "easeInOut", RSAnimationTimingCurve::EASE_IN_OUT },
774 { "default", RSAnimationTimingCurve::DEFAULT },
775 { "linear", RSAnimationTimingCurve::LINEAR },
776 { "spring", RSAnimationTimingCurve::SPRING },
777 { "interactiveSpring", RSAnimationTimingCurve::INTERACTIVE_SPRING }
778 };
779
780 RSAnimationTimingCurve curve = RSAnimationTimingCurve::EASE_OUT;
781 const auto& nameItem = curveConfig.GetProp("name");
782 if (nameItem.IsString()) {
783 std::string name = nameItem.stringValue_;
784 if (name == "cubic" && curveConfig.IsFloats() && curveConfig.floatsValue_ != nullptr &&
785 curveConfig.floatsValue_->size() == 4) { // 4 curve parameter
786 const auto& numbers = *curveConfig.floatsValue_;
787 curve = RSAnimationTimingCurve::CreateCubicCurve(
788 numbers[0], // 0 ctrlX1
789 numbers[1], // 1 ctrlY1
790 numbers[2], // 2 ctrlX2
791 numbers[3]); // 3 ctrlY2
792 } else {
793 if (auto iter = curveMap.find(name); iter != curveMap.end()) {
794 curve = iter->second;
795 }
796 }
797 }
798 return curve;
799 }
800
OnStop()801 void WindowManagerService::OnStop()
802 {
803 windowCommonEvent_->UnSubscriberEvent();
804 WindowInnerManager::GetInstance().Stop();
805 WLOGI("ready to stop service.");
806 }
807
NotifyWindowTransition(sptr<WindowTransitionInfo> & fromInfo,sptr<WindowTransitionInfo> & toInfo,bool isFromClient)808 WMError WindowManagerService::NotifyWindowTransition(
809 sptr<WindowTransitionInfo>& fromInfo, sptr<WindowTransitionInfo>& toInfo, bool isFromClient)
810 {
811 if (!isFromClient) {
812 WLOGI("NotifyWindowTransition asynchronously.");
813 auto task = [this, fromInfo, toInfo]() mutable {
814 return windowController_->NotifyWindowTransition(fromInfo, toInfo);
815 };
816 PostAsyncTask(task, "NotifyWindowTransition");
817 return WMError::WM_OK;
818 } else {
819 WLOGI("NotifyWindowTransition synchronously.");
820 auto task = [this, &fromInfo, &toInfo]() {
821 return windowController_->NotifyWindowTransition(fromInfo, toInfo);
822 };
823 return PostSyncTask(task, "NotifyWindowTransition");
824 }
825 }
826
NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info)827 void WindowManagerService::NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info)
828 {
829 auto task = [this, info]() mutable {
830 return RemoteAnimation::NotifyAnimationAbilityDied(info);
831 };
832 PostAsyncTask(task, "NotifyAnimationAbilityDied");
833 }
834
GetFocusWindowInfo(sptr<IRemoteObject> & abilityToken,DisplayId displayId)835 WMError WindowManagerService::GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken, DisplayId displayId)
836 {
837 auto task = [this, &abilityToken]() {
838 return windowController_->GetFocusWindowInfo(abilityToken);
839 };
840 return PostSyncTask(task, "GetFocusWindowInfo");
841 }
842
StartingWindow(sptr<WindowTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,bool isColdStart,uint32_t bkgColor)843 void WindowManagerService::StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
844 bool isColdStart, uint32_t bkgColor)
845 {
846 if (!startingOpen_) {
847 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "startingWindow not open!");
848 return;
849 }
850 if (info) {
851 info->isSystemCalling_ = Permission::IsSystemCalling();
852 }
853 auto task = [this, info, pixelMap, isColdStart, bkgColor]() {
854 windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart);
855 };
856 PostAsyncTask(task, "StartingWindow");
857 }
858
CancelStartingWindow(sptr<IRemoteObject> abilityToken)859 void WindowManagerService::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
860 {
861 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "begin");
862 if (!startingOpen_) {
863 TLOGI(WmsLogTag::WMS_STARTUP_PAGE, "startingWindow not open!");
864 return;
865 }
866 auto task = [this, abilityToken]() {
867 windowController_->CancelStartingWindow(abilityToken);
868 };
869 PostAsyncTask(task, "CancelStartingWindow");
870 }
871
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)872 WMError WindowManagerService::MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId)
873 {
874 if (windowGroupMgr_) {
875 auto task = [this, &missionIds, topMissionId]() {
876 WMError res = windowGroupMgr_->MoveMissionsToForeground(missionIds, topMissionId);
877 // no need to return inner error to caller
878 if (res > WMError::WM_ERROR_NEED_REPORT_BASE) {
879 return res;
880 }
881 return WMError::WM_OK;
882 };
883 return PostSyncTask(task, "MoveMissionsToForeground");
884 }
885 return WMError::WM_ERROR_NULLPTR;
886 }
887
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)888 WMError WindowManagerService::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
889 std::vector<int32_t>& result)
890 {
891 if (windowGroupMgr_) {
892 auto task = [this, &missionIds, &result]() {
893 WMError res = windowGroupMgr_->MoveMissionsToBackground(missionIds, result);
894 // no need to return wms inner error to caller
895 if (res > WMError::WM_ERROR_NEED_REPORT_BASE) {
896 return res;
897 }
898 return WMError::WM_OK;
899 };
900 return PostSyncTask(task, "MoveMissionsToBackground");
901 }
902 return WMError::WM_ERROR_NULLPTR;
903 }
904
905
CheckAnimationPermission(const sptr<WindowProperty> & property) const906 bool WindowManagerService::CheckAnimationPermission(const sptr<WindowProperty>& property) const
907 {
908 WindowType type = property->GetWindowType();
909 // If the animation type is NONE or the window type is WINDOW_TYPE_INPUT_METHOD_FLOAT
910 if (property->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::NONE) ||
911 type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
912 return true;
913 }
914 // If the animation type is DEFAULT and the window type is AppWindow
915 if (property->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::DEFAULT) &&
916 WindowHelper::IsAppWindow(type)) {
917 return true;
918 }
919 // If the animation type is CUSTOM
920 if (Permission::IsSystemCalling() || Permission::IsStartByHdcd()) {
921 WLOGFD("check IsSystemCalling permission success, show with animation calling.");
922 return true;
923 }
924 WLOGFE("check animation permission failed");
925 return false;
926 }
927
CheckSystemWindowPermission(const sptr<WindowProperty> & property) const928 bool WindowManagerService::CheckSystemWindowPermission(const sptr<WindowProperty>& property) const
929 {
930 WindowType type = property->GetWindowType();
931 if (!WindowHelper::IsSystemWindow(type)) {
932 // type is not system
933 return true;
934 }
935 if ((type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || type == WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR)
936 && Permission::IsStartByInputMethod()) {
937 // WINDOW_TYPE_INPUT_METHOD_FLOAT counld be created by input method app
938 WLOGFD("check create permission success, input method app create input method window.");
939 return true;
940 }
941 if (type == WindowType::WINDOW_TYPE_DRAGGING_EFFECT || type == WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW ||
942 type == WindowType::WINDOW_TYPE_TOAST || type == WindowType::WINDOW_TYPE_DIALOG) {
943 // some system types counld be created by normal app
944 return true;
945 }
946 if (type == WindowType::WINDOW_TYPE_FLOAT &&
947 Permission::CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
948 // WINDOW_TYPE_FLOAT counld be created by normal app with the corresponding permission
949 WLOGFD("check create permission success, normal app create float window with request permission.");
950 return true;
951 }
952 if (Permission::IsSystemCalling() || Permission::IsStartByHdcd()) {
953 WLOGFD("check create permission success, create with system calling.");
954 return true;
955 }
956 WLOGFE("check system window permission failed.");
957 return false;
958 }
959
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId,sptr<IRemoteObject> token)960 WMError WindowManagerService::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
961 const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token)
962 {
963 if (!window || property == nullptr || surfaceNode == nullptr || !window->AsObject()) {
964 WLOGFE("window is invalid");
965 return WMError::WM_ERROR_NULLPTR;
966 }
967 if (!CheckSystemWindowPermission(property)) {
968 WLOGFE("create system window permission denied!");
969 return WMError::WM_ERROR_NOT_SYSTEM_APP;
970 }
971 int pid = IPCSkeleton::GetCallingRealPid();
972 int uid = IPCSkeleton::GetCallingUid();
973 property->isSystemCalling_ = Permission::IsSystemCalling();
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
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)1340 WMError WindowManagerService::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
1341 bool isAsyncTask)
1342 {
1343 if (windowProperty == nullptr) {
1344 WLOGFE("windowProperty is nullptr");
1345 return WMError::WM_ERROR_NULLPTR;
1346 }
1347
1348 if ((windowProperty->GetWindowFlags() == static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE) ||
1349 action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) &&
1350 !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1351 WLOGFE("SetForbidSplitMove or SetShowWhenLocked or SetTranform or SetTurnScreenOn permission denied!");
1352 return WMError::WM_ERROR_INVALID_PERMISSION;
1353 }
1354
1355 WindowType type = windowProperty->GetWindowType();
1356 if (type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT ||
1357 type == WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR) {
1358 if (!Permission::IsStartByInputMethod()) {
1359 WLOGI("Keyboard only hide by input method it'self, operation rejected.");
1360 return WMError::WM_ERROR_INVALID_OPERATION;
1361 }
1362 } else if (!accessTokenIdMaps_.isExist(windowProperty->GetWindowId(), IPCSkeleton::GetCallingTokenID()) &&
1363 !Permission::IsSystemCalling()) {
1364 WLOGI("Operation rejected");
1365 return WMError::WM_ERROR_INVALID_OPERATION;
1366 }
1367
1368 if (action == PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE &&
1369 !Permission::CheckCallingPermission("ohos.permission.PRIVACY_WINDOW")) {
1370 WLOGFE("Set privacy mode permission denied!");
1371 return WMError::WM_ERROR_INVALID_PERMISSION;
1372 }
1373
1374 windowProperty->isSystemCalling_ = Permission::IsSystemCalling();
1375 if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) {
1376 auto task = [this, windowProperty, action]() mutable {
1377 windowController_->UpdateProperty(windowProperty, action);
1378 return WMError::WM_OK;
1379 };
1380 return PostSyncTask(task, "UpdateProperty");
1381 }
1382
1383 if (isAsyncTask || action == PropertyChangeAction::ACTION_UPDATE_RECT) {
1384 auto task = [this, windowProperty, action]() mutable {
1385 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1386 WMError res = windowController_->UpdateProperty(windowProperty, action);
1387 if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1388 (IsMoveToOrDragMove(windowProperty->GetWindowSizeChangeReason()))) {
1389 dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1390 }
1391 };
1392 PostAsyncTask(task, "UpdateProperty");
1393 return WMError::WM_OK;
1394 }
1395
1396 auto task = [this, &windowProperty, action]() {
1397 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1398 WMError res = windowController_->UpdateProperty(windowProperty, action);
1399 if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1400 IsMoveToOrDragMove(windowProperty->GetWindowSizeChangeReason())) {
1401 dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1402 }
1403 return res;
1404 };
1405 return PostSyncTask(task, "UpdateProperty");
1406 }
1407
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)1408 WMError WindowManagerService::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
1409 {
1410 auto task = [this, windowId, gravity, percent]() {
1411 WMError res = windowController_->SetWindowGravity(windowId, gravity, percent);
1412 return res;
1413 };
1414 return PostSyncTask(task, "SetWindowGravity");
1415 }
1416
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1417 WMError WindowManagerService::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1418 {
1419 if (!Permission::IsSystemServiceCalling()) {
1420 WLOGFE("get accessibility window info permission denied!");
1421 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1422 }
1423 auto task = [this, &infos]() {
1424 return windowController_->GetAccessibilityWindowInfo(infos);
1425 };
1426 return PostSyncTask(task, "GetAccessibilityWindowInfo");
1427 }
1428
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)1429 WMError WindowManagerService::GetUnreliableWindowInfo(int32_t windowId,
1430 std::vector<sptr<UnreliableWindowInfo>>& infos)
1431 {
1432 if (!Permission::IsSystemServiceCalling()) {
1433 WLOGFE("get unreliable window info permission denied!");
1434 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1435 }
1436 auto task = [this, windowId, &infos]() {
1437 return windowController_->GetUnreliableWindowInfo(windowId, infos);
1438 };
1439 return PostSyncTask(task, "GetUnreliableWindowInfo");
1440 }
1441
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)1442 WMError WindowManagerService::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
1443 {
1444 auto task = [this, &infos]() {
1445 return windowController_->GetVisibilityWindowInfo(infos);
1446 };
1447 return PostSyncTask(task, "GetVisibilityWindowInfo");
1448 }
1449
1450 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)1451 WMError WindowManagerService::RaiseToAppTop(uint32_t windowId)
1452 {
1453 auto task = [this, windowId]() {
1454 return windowController_->RaiseToAppTop(windowId);
1455 };
1456 return PostSyncTask(task, "RaiseToAppTop");
1457 }
1458
GetSnapshot(int32_t windowId)1459 std::shared_ptr<Media::PixelMap> WindowManagerService::GetSnapshot(int32_t windowId)
1460 {
1461 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1462 WLOGFE("permission denied!");
1463 return nullptr;
1464 }
1465 auto task = [this, windowId]() {
1466 return windowController_->GetSnapshot(windowId);
1467 };
1468 return PostSyncTask(task, "GetSnapshot");
1469 }
1470
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1471 void WindowManagerService::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1472 {
1473 auto task = [this, windowId, event]() {
1474 windowController_->DispatchKeyEvent(windowId, event);
1475 };
1476 PostVoidSyncTask(task, "DispatchKeyEvent");
1477 }
1478
NotifyDumpInfoResult(const std::vector<std::string> & info)1479 void WindowManagerService::NotifyDumpInfoResult(const std::vector<std::string>& info)
1480 {
1481 if (windowDumper_) {
1482 windowDumper_->dumpInfoFuture_.SetValue(info);
1483 }
1484 }
1485
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)1486 WMError WindowManagerService::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
1487 std::vector<sptr<RSWindowAnimationTarget>>& targets)
1488 {
1489 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1490 WLOGFE("get window animation targets permission denied!");
1491 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1492 }
1493 auto task = [this, missionIds, &targets]() {
1494 return RemoteAnimation::GetWindowAnimationTargets(missionIds, targets);
1495 };
1496 return PostSyncTask(task, "GetWindowAnimationTargets");
1497 }
1498
GetSystemConfig(SystemConfig & systemConfig)1499 WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig)
1500 {
1501 systemConfig = systemConfig_;
1502 return WMError::WM_OK;
1503 }
1504
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)1505 WMError WindowManagerService::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
1506 {
1507 if (!hotZonesConfig_.isModeChangeHotZoneConfigured_) {
1508 return WMError::WM_DO_NOTHING;
1509 }
1510
1511 return windowController_->GetModeChangeHotZones(displayId, hotZones, hotZonesConfig_);
1512 }
1513
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)1514 void WindowManagerService::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
1515 sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
1516 {
1517 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1518 WLOGFE("minimize windows by launcher permission denied!");
1519 return;
1520 }
1521 auto task = [this, windowIds, isAnimated, &finishCallback]() mutable {
1522 windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
1523 };
1524 PostVoidSyncTask(task, "MinimizeWindowsByLauncher");
1525 }
1526
UpdateAvoidAreaListener(uint32_t windowId,bool haveAvoidAreaListener)1527 WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener)
1528 {
1529 auto task = [this, windowId, haveAvoidAreaListener]() {
1530 sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
1531 if (node == nullptr) {
1532 WLOGFE("get window node failed. win %{public}u", windowId);
1533 return WMError::WM_DO_NOTHING;
1534 }
1535 sptr<WindowNodeContainer> container = windowRoot_->GetWindowNodeContainer(node->GetDisplayId());
1536 if (container == nullptr) {
1537 WLOGFE("get container failed. win %{public}u display %{public}" PRIu64"", windowId, node->GetDisplayId());
1538 return WMError::WM_DO_NOTHING;
1539 }
1540 container->UpdateAvoidAreaListener(node, haveAvoidAreaListener);
1541 return WMError::WM_OK;
1542 };
1543 return PostSyncTask(task, "UpdateAvoidAreaListener");
1544 }
1545
SetAnchorAndScale(int32_t x,int32_t y,float scale)1546 void WindowManagerService::SetAnchorAndScale(int32_t x, int32_t y, float scale)
1547 {
1548 auto task = [this, x, y, scale]() {
1549 windowController_->SetAnchorAndScale(x, y, scale);
1550 };
1551 PostAsyncTask(task, "SetAnchorAndScale");
1552 }
1553
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1554 void WindowManagerService::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1555 {
1556 auto task = [this, deltaX, deltaY]() {
1557 windowController_->SetAnchorOffset(deltaX, deltaY);
1558 };
1559 PostAsyncTask(task, "SetAnchorOffset");
1560 }
1561
OffWindowZoom()1562 void WindowManagerService::OffWindowZoom()
1563 {
1564 auto task = [this]() {
1565 windowController_->OffWindowZoom();
1566 };
1567 PostAsyncTask(task, "OffWindowZoom");
1568 }
1569
UpdateRsTree(uint32_t windowId,bool isAdd)1570 WMError WindowManagerService::UpdateRsTree(uint32_t windowId, bool isAdd)
1571 {
1572 auto task = [this, windowId, isAdd]() {
1573 return windowRoot_->UpdateRsTree(windowId, isAdd);
1574 };
1575 return PostSyncTask(task, "UpdateRsTree");
1576 }
1577
OnScreenshot(DisplayId displayId)1578 void WindowManagerService::OnScreenshot(DisplayId displayId)
1579 {
1580 auto task = [this, displayId]() {
1581 windowController_->OnScreenshot(displayId);
1582 };
1583 PostAsyncTask(task, "OnScreenshot");
1584 }
1585
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)1586 WMError WindowManagerService::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
1587 {
1588 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1589 WLOGFE("bind dialog target permission denied!");
1590 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1591 }
1592 auto task = [this, &windowId, targetToken]() {
1593 return windowController_->BindDialogTarget(windowId, targetToken);
1594 };
1595 return PostSyncTask(task, "BindDialogTarget");
1596 }
1597
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1598 void WindowManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1599 {
1600 auto task = [this, displayId, &hasPrivateWindow]() mutable {
1601 hasPrivateWindow = windowRoot_->HasPrivateWindow(displayId);
1602 };
1603 PostVoidSyncTask(task, "HasPrivateWindow");
1604 WLOGI("called %{public}u", hasPrivateWindow);
1605 }
1606
SetGestureNavigationEnabled(bool enable)1607 WMError WindowManagerService::SetGestureNavigationEnabled(bool enable)
1608 {
1609 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1610 WLOGFE("permission denied!");
1611 return WMError::WM_ERROR_NOT_SYSTEM_APP;
1612 }
1613 auto task = [this, enable]() {
1614 return windowRoot_->SetGestureNavigationEnabled(enable);
1615 };
1616 return PostSyncTask(task, "SetGestureNavigationEnabled");
1617 }
1618
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1619 void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1620 {
1621 WLOGI("called");
1622 WindowManagerService::GetInstance().HasPrivateWindow(displayId, hasPrivateWindow);
1623 }
1624
SetMaximizeMode(MaximizeMode maximizeMode)1625 void WindowManagerService::SetMaximizeMode(MaximizeMode maximizeMode)
1626 {
1627 maximizeMode_ = maximizeMode;
1628 int32_t storageMode = -1;
1629 if (PersistentStorage::HasKey("maximize_state", PersistentStorageType::MAXIMIZE_STATE)) {
1630 PersistentStorage::Get("maximize_state", storageMode, PersistentStorageType::MAXIMIZE_STATE);
1631 PersistentStorage::Delete("maximize_state", PersistentStorageType::MAXIMIZE_STATE);
1632 }
1633 PersistentStorage::Insert("maximize_state", static_cast<int32_t>(maximizeMode),
1634 PersistentStorageType::MAXIMIZE_STATE);
1635 WLOGI("globalMaximizeMode changed from %{public}d to %{public}d", storageMode, static_cast<int32_t>(maximizeMode));
1636 }
1637
GetMaximizeMode()1638 MaximizeMode WindowManagerService::GetMaximizeMode()
1639 {
1640 return maximizeMode_;
1641 }
1642
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)1643 void WindowManagerService::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
1644 {
1645 WLOGFD("Get Focus window info in wms");
1646 windowController_->GetFocusWindowInfo(focusInfo);
1647 }
1648 } // namespace Rosen
1649 } // namespace OHOS
1650