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