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