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