• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(
__anon12a2a74b0202(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     }
__anon12a2a74b0302() 87     handler_->PostTask([]() { MemoryGuard cacheGuard; }, AppExecFwk::EventQueue::Priority::IMMEDIATE);
88     // init RSUIDirector, it will handle animation callback
89     rsUiDirector_ = RSUIDirector::Create();
__anon12a2a74b0402(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     return PostSyncTask([this, windowId]() {
929         WLOGI("[WMS] Remove: %{public}u", windowId);
930         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:RemoveWindow(%u)", windowId);
931         WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
932         WMError res = windowController_->RecoverInputEventToClient(windowId);
933         if (res != WMError::WM_OK) {
934             return res;
935         }
936         return windowController_->RemoveWindowNode(windowId);
937     });
938 }
939 
DestroyWindow(uint32_t windowId,bool onlySelf)940 WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf)
941 {
942     if (!accessTokenIdMaps_.isExistAndRemove(windowId, IPCSkeleton::GetCallingTokenID())) {
943         WLOGI("Operation rejected");
944         return WMError::WM_ERROR_INVALID_OPERATION;
945     }
946     return PostSyncTask([this, windowId, onlySelf]() {
947         auto node = windowRoot_->GetWindowNode(windowId);
948         if (node == nullptr) {
949             return WMError::WM_ERROR_NULLPTR;
950         }
951         node->stateMachine_.SetDestroyTaskParam(onlySelf);
952         auto func = [this, windowId]() {
953             WLOGI("[WMS] Destroy: %{public}u", windowId);
954             HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:DestroyWindow(%u)", windowId);
955             WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
956             windowGroupMgr_->OnWindowDestroyed(windowId);
957             auto node = windowRoot_->GetWindowNode(windowId);
958             if (node == nullptr) {
959                 return WMError::WM_OK;
960             }
961             if (node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
962                 dragController_->FinishDrag(windowId);
963             }
964             return windowController_->DestroyWindow(windowId, node->stateMachine_.GetDestroyTaskParam());
965         };
966         if (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
967             node->stateMachine_.IsRemoteAnimationPlaying()) {
968             WLOGI("SetDestroyTask id:%{public}u", node->GetWindowId());
969             node->stateMachine_.SetDestroyTask(func);
970             return WMError::WM_OK;
971         }
972         WLOGI("DestroyWindow windowId: %{public}u, name:%{public}s state: %{public}u",
973             node->GetWindowId(), node->GetWindowName().c_str(),
974             static_cast<uint32_t>(node->stateMachine_.GetCurrentState()));
975         return func();
976     });
977 }
978 
RequestFocus(uint32_t windowId)979 WMError WindowManagerService::RequestFocus(uint32_t windowId)
980 {
981     return PostSyncTask([this, windowId]() {
982         WLOGI("[WMS] RequestFocus: %{public}u", windowId);
983         return windowController_->RequestFocus(windowId);
984     });
985 }
986 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType avoidAreaType)987 AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType)
988 {
989     return PostSyncTask([this, windowId, avoidAreaType]() {
990         WLOGI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId,
991             static_cast<uint32_t>(avoidAreaType));
992         return windowController_->GetAvoidAreaByType(windowId, avoidAreaType);
993     });
994 }
995 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)996 WMError WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type,
997     const sptr<IWindowManagerAgent>& windowManagerAgent)
998 {
999     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1000         WLOGFE("register windowManager agent permission denied!");
1001         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1002     }
1003     if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
1004         WLOGFE("windowManagerAgent is null");
1005         return WMError::WM_ERROR_NULLPTR;
1006     }
1007     return PostSyncTask([this, &windowManagerAgent, type]() {
1008         WMError ret = WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type);
1009         if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR) { // if system bar, notify once
1010             windowController_->NotifySystemBarTints();
1011         }
1012         return ret;
1013     });
1014 }
1015 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)1016 WMError WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type,
1017     const sptr<IWindowManagerAgent>& windowManagerAgent)
1018 {
1019     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1020         WLOGFE("unregister windowManager agent permission denied!");
1021         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1022     }
1023     if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
1024         WLOGFE("windowManagerAgent is null");
1025         return WMError::WM_ERROR_NULLPTR;
1026     }
1027     return PostSyncTask([this, &windowManagerAgent, type]() {
1028         return WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type);
1029     });
1030 }
1031 
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)1032 WMError WindowManagerService::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
1033 {
1034     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1035         WLOGFE("set window animation controller permission denied!");
1036         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1037     }
1038     if (controller == nullptr) {
1039         WLOGFE("RSWindowAnimation: Failed to set window animation controller, controller is null!");
1040         return WMError::WM_ERROR_NULLPTR;
1041     }
1042 
1043     sptr<AgentDeathRecipient> deathRecipient = new AgentDeathRecipient(
1044         [this](sptr<IRemoteObject>& remoteObject) {
1045             PostVoidSyncTask([&remoteObject]() {
1046                 RemoteAnimation::OnRemoteDie(remoteObject);
1047             });
1048         }
1049     );
1050     controller->AsObject()->AddDeathRecipient(deathRecipient);
1051     RemoteAnimation::SetWindowControllerAndRoot(windowController_, windowRoot_);
1052     RemoteAnimation::SetMainTaskHandler(handler_);
1053     return PostSyncTask([this, &controller]() {
1054         WMError ret = windowController_->SetWindowAnimationController(controller);
1055         RemoteAnimation::SetAnimationFirst(system::GetParameter("persist.window.af.enabled", "1") == "1");
1056         return ret;
1057     });
1058 }
1059 
OnWindowEvent(Event event,const sptr<IRemoteObject> & remoteObject)1060 void WindowManagerService::OnWindowEvent(Event event, const sptr<IRemoteObject>& remoteObject)
1061 {
1062     if (event == Event::REMOTE_DIED) {
1063         PostVoidSyncTask([this, &remoteObject]() {
1064             uint32_t windowId = windowRoot_->GetWindowIdByObject(remoteObject);
1065             auto node = windowRoot_->GetWindowNode(windowId);
1066             if (node == nullptr) {
1067                 WLOGFD("window node is nullptr, REMOTE_DIED no need to destroy");
1068                 return;
1069             }
1070             WLOGI("window %{public}u received REMOTE_DIED", windowId);
1071             node->stateMachine_.SetDestroyTaskParam(true);
1072             auto func = [this, windowId]() {
1073                 auto node = windowRoot_->GetWindowNode(windowId);
1074                 if (node == nullptr) {
1075                     WLOGFD("window node is nullptr");
1076                     return;
1077                 }
1078                 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
1079                     dragController_->FinishDrag(windowId);
1080                 }
1081                 WindowInnerManager::GetInstance().NotifyWindowRemovedOrDestroyed(windowId);
1082                 windowGroupMgr_->OnWindowDestroyed(windowId);
1083                 windowController_->DestroyWindow(windowId, node->stateMachine_.GetDestroyTaskParam());
1084             };
1085 
1086             if (node->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1087                 RemoteAnimation::OnRemoteDie(remoteObject);
1088             }
1089             if (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
1090                 node->stateMachine_.IsRemoteAnimationPlaying()) {
1091                 WLOGI("set destroy task windowId:%{public}u", node->GetWindowId());
1092                 node->stateMachine_.SetDestroyTask(func);
1093                 handler_->PostTask(func, "destroyTimeOutTask", 6000); // 6000 is time out 6s
1094                 return;
1095             }
1096             func();
1097         });
1098     }
1099 }
1100 
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)1101 void WindowManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
1102     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
1103 {
1104     HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:NotifyDisplayStateChange(%u)", type);
1105     DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId();
1106     if (type == DisplayStateChangeType::FREEZE) {
1107         freezeDisplayController_->FreezeDisplay(displayId);
1108     } else if (type == DisplayStateChangeType::UNFREEZE) {
1109         freezeDisplayController_->UnfreezeDisplay(displayId);
1110         /*
1111          * Set 'InnerInputManager Listener' to MMI, ensure that the listener
1112          * for move/drag won't be replaced by freeze-display-window
1113          */
1114         WindowInnerManager::GetInstance().SetInputEventConsumer();
1115     } else {
1116         PostAsyncTask([this, defaultDisplayId, displayInfo, displayInfoMap, type]() mutable {
1117             windowController_->NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1118             windowGroupMgr_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1119         });
1120     }
1121 }
1122 
OnDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)1123 void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
1124     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
1125 {
1126     WindowManagerService::GetInstance().NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
1127 }
1128 
OnScreenshot(DisplayId displayId)1129 void DisplayChangeListener::OnScreenshot(DisplayId displayId)
1130 {
1131     WindowManagerService::GetInstance().OnScreenshot(displayId);
1132 }
1133 
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)1134 void WindowManagerService::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
1135     sptr<MoveDragProperty>& moveDragProperty)
1136 {
1137     if (windowProperty == nullptr || moveDragProperty == nullptr) {
1138         WLOGFE("windowProperty or moveDragProperty is invalid");
1139         return;
1140     }
1141 
1142     PostAsyncTask([this, windowId, windowProperty, moveDragProperty]() mutable {
1143         if (moveDragProperty->startDragFlag_ || moveDragProperty->startMoveFlag_) {
1144             bool res = WindowInnerManager::GetInstance().NotifyServerReadyToMoveOrDrag(windowId,
1145                 windowProperty, moveDragProperty);
1146             if (!res) {
1147                 WLOGFE("invalid operation");
1148                 return;
1149             }
1150             windowController_->InterceptInputEventToServer(windowId);
1151         }
1152         windowController_->NotifyServerReadyToMoveOrDrag(windowId, moveDragProperty);
1153     });
1154 }
1155 
ProcessPointDown(uint32_t windowId,bool isPointDown)1156 void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isPointDown)
1157 {
1158     PostAsyncTask([this, windowId, isPointDown]() {
1159         windowController_->ProcessPointDown(windowId, isPointDown);
1160     });
1161 }
1162 
ProcessPointUp(uint32_t windowId)1163 void WindowManagerService::ProcessPointUp(uint32_t windowId)
1164 {
1165     PostAsyncTask([this, windowId]() {
1166         WindowInnerManager::GetInstance().NotifyWindowEndUpMovingOrDragging(windowId);
1167         windowController_->RecoverInputEventToClient(windowId);
1168         windowController_->ProcessPointUp(windowId);
1169     });
1170 }
1171 
NotifyWindowClientPointUp(uint32_t windowId,const std::shared_ptr<MMI::PointerEvent> & pointerEvent)1172 void WindowManagerService::NotifyWindowClientPointUp(uint32_t windowId,
1173     const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
1174 {
1175     PostAsyncTask([this, windowId, pointerEvent]() mutable {
1176         windowController_->NotifyWindowClientPointUp(windowId, pointerEvent);
1177     });
1178 }
1179 
MinimizeAllAppWindows(DisplayId displayId)1180 WMError WindowManagerService::MinimizeAllAppWindows(DisplayId displayId)
1181 {
1182     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1183         WLOGFE("minimize all appWindows permission denied!");
1184         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1185     }
1186     PostAsyncTask([this, displayId]() {
1187         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:MinimizeAllAppWindows(%" PRIu64")", displayId);
1188         WLOGI("displayId %{public}" PRIu64"", displayId);
1189         windowController_->MinimizeAllAppWindows(displayId);
1190     });
1191     return WMError::WM_OK;
1192 }
1193 
ToggleShownStateForAllAppWindows()1194 WMError WindowManagerService::ToggleShownStateForAllAppWindows()
1195 {
1196     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1197         WLOGFE("toggle shown state for all appwindows permission denied!");
1198         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1199     }
1200     PostAsyncTask([this]() {
1201         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:ToggleShownStateForAllAppWindows");
1202         return windowController_->ToggleShownStateForAllAppWindows();
1203     });
1204     return WMError::WM_OK;
1205 }
1206 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)1207 WMError WindowManagerService::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
1208 {
1209     return PostSyncTask([this, &topWinId, mainWinId]() {
1210         return windowController_->GetTopWindowId(mainWinId, topWinId);
1211     });
1212 }
1213 
SetWindowLayoutMode(WindowLayoutMode mode)1214 WMError WindowManagerService::SetWindowLayoutMode(WindowLayoutMode mode)
1215 {
1216     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1217         WLOGFE("set window layout mode permission denied!");
1218         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1219     }
1220     return PostSyncTask([this, mode]() {
1221         WLOGI("layoutMode: %{public}u", mode);
1222         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:SetWindowLayoutMode");
1223         return windowController_->SetWindowLayoutMode(mode);
1224     });
1225 }
1226 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)1227 WMError WindowManagerService::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
1228     bool isAsyncTask)
1229 {
1230     if (windowProperty == nullptr) {
1231         WLOGFE("windowProperty is nullptr");
1232         return WMError::WM_ERROR_NULLPTR;
1233     }
1234     if ((windowProperty->GetWindowFlags() == static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE) ||
1235         action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) &&
1236         !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1237         WLOGFE("SetForbidSplitMove or SetShowWhenLocked or SetTranform or SetTurnScreenOn permission denied!");
1238         return WMError::WM_ERROR_INVALID_PERMISSION;
1239     }
1240     windowProperty->isSystemCalling_ = Permission::IsSystemCalling();
1241     if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) {
1242         return PostSyncTask([this, windowProperty, action]() mutable {
1243             windowController_->UpdateProperty(windowProperty, action);
1244             return WMError::WM_OK;
1245         });
1246     }
1247 
1248     if (isAsyncTask || action == PropertyChangeAction::ACTION_UPDATE_RECT) {
1249         PostAsyncTask([this, windowProperty, action]() mutable {
1250             HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1251             WMError res = windowController_->UpdateProperty(windowProperty, action);
1252             if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1253                 windowProperty->GetWindowSizeChangeReason() == WindowSizeChangeReason::MOVE) {
1254                 dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1255             }
1256         });
1257         return WMError::WM_OK;
1258     }
1259 
1260     return PostSyncTask([this, &windowProperty, action]() {
1261         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty");
1262         WMError res = windowController_->UpdateProperty(windowProperty, action);
1263         if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK &&
1264             windowProperty->GetWindowSizeChangeReason() == WindowSizeChangeReason::MOVE) {
1265             dragController_->UpdateDragInfo(windowProperty->GetWindowId());
1266         }
1267         return res;
1268     });
1269 }
1270 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)1271 WMError WindowManagerService::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
1272 {
1273     return PostSyncTask([this, windowId, gravity, percent]() {
1274         WMError res = windowController_->SetWindowGravity(windowId, gravity, percent);
1275         return res;
1276     });
1277 }
1278 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1279 WMError WindowManagerService::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1280 {
1281     if (!Permission::IsSystemServiceCalling()) {
1282         WLOGFE("get accessibility window info permission denied!");
1283         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1284     }
1285     return PostSyncTask([this, &infos]() {
1286         return windowController_->GetAccessibilityWindowInfo(infos);
1287     });
1288 }
1289 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)1290 WMError WindowManagerService::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
1291 {
1292     return PostSyncTask([this, &infos]() {
1293         return windowController_->GetVisibilityWindowInfo(infos);
1294     });
1295 }
1296 
RaiseToAppTop(uint32_t windowId)1297 WmErrorCode WindowManagerService::RaiseToAppTop(uint32_t windowId)
1298 {
1299     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1300         WLOGFE("window raise to app top permission denied!");
1301         return WmErrorCode::WM_ERROR_NOT_SYSTEM_APP;
1302     }
1303     return PostSyncTask([this, windowId]() {
1304         return windowController_->RaiseToAppTop(windowId);
1305     });
1306 }
1307 
GetSnapshot(int32_t windowId)1308 std::shared_ptr<Media::PixelMap> WindowManagerService::GetSnapshot(int32_t windowId)
1309 {
1310     return nullptr;
1311 }
1312 
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1313 void WindowManagerService::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1314 {
1315     PostVoidSyncTask([this, windowId, event]() {
1316         windowController_->DispatchKeyEvent(windowId, event);
1317     });
1318 }
1319 
NotifyDumpInfoResult(const std::vector<std::string> & info)1320 void WindowManagerService::NotifyDumpInfoResult(const std::vector<std::string>& info)
1321 {
1322     if (windowDumper_) {
1323         windowDumper_->dumpInfoFuture_.SetValue(info);
1324     }
1325 }
1326 
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)1327 WMError WindowManagerService::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
1328     std::vector<sptr<RSWindowAnimationTarget>>& targets)
1329 {
1330     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1331         WLOGFE("get window animation targets permission denied!");
1332         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1333     }
1334     return PostSyncTask([this, missionIds, &targets]() {
1335         return RemoteAnimation::GetWindowAnimationTargets(missionIds, targets);
1336     });
1337 }
1338 
GetSystemConfig(SystemConfig & systemConfig)1339 WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig)
1340 {
1341     systemConfig = systemConfig_;
1342     return WMError::WM_OK;
1343 }
1344 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)1345 WMError WindowManagerService::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
1346 {
1347     if (!hotZonesConfig_.isModeChangeHotZoneConfigured_) {
1348         return WMError::WM_DO_NOTHING;
1349     }
1350 
1351     return windowController_->GetModeChangeHotZones(displayId, hotZones, hotZonesConfig_);
1352 }
1353 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)1354 void WindowManagerService::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
1355     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
1356 {
1357     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1358         WLOGFE("minimize windows by launcher permission denied!");
1359         return;
1360     }
1361     PostVoidSyncTask([this, windowIds, isAnimated, &finishCallback]() mutable {
1362         windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
1363     });
1364 }
1365 
UpdateAvoidAreaListener(uint32_t windowId,bool haveAvoidAreaListener)1366 WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener)
1367 {
1368     return PostSyncTask([this, windowId, haveAvoidAreaListener]() {
1369         sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
1370         if (node == nullptr) {
1371             WLOGFE("get window node failed. win %{public}u", windowId);
1372             return WMError::WM_DO_NOTHING;
1373         }
1374         sptr<WindowNodeContainer> container = windowRoot_->GetWindowNodeContainer(node->GetDisplayId());
1375         if (container == nullptr) {
1376             WLOGFE("get container failed. win %{public}u display %{public}" PRIu64"", windowId, node->GetDisplayId());
1377             return WMError::WM_DO_NOTHING;
1378         }
1379         container->UpdateAvoidAreaListener(node, haveAvoidAreaListener);
1380         return WMError::WM_OK;
1381     });
1382 }
1383 
SetAnchorAndScale(int32_t x,int32_t y,float scale)1384 void WindowManagerService::SetAnchorAndScale(int32_t x, int32_t y, float scale)
1385 {
1386     PostAsyncTask([this, x, y, scale]() {
1387         windowController_->SetAnchorAndScale(x, y, scale);
1388     });
1389 }
1390 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1391 void WindowManagerService::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1392 {
1393     PostAsyncTask([this, deltaX, deltaY]() {
1394         windowController_->SetAnchorOffset(deltaX, deltaY);
1395     });
1396 }
1397 
OffWindowZoom()1398 void WindowManagerService::OffWindowZoom()
1399 {
1400     PostAsyncTask([this]() {
1401         windowController_->OffWindowZoom();
1402     });
1403 }
1404 
UpdateRsTree(uint32_t windowId,bool isAdd)1405 WMError WindowManagerService::UpdateRsTree(uint32_t windowId, bool isAdd)
1406 {
1407     return PostSyncTask([this, windowId, isAdd]() {
1408         return windowRoot_->UpdateRsTree(windowId, isAdd);
1409     });
1410 }
1411 
OnScreenshot(DisplayId displayId)1412 void WindowManagerService::OnScreenshot(DisplayId displayId)
1413 {
1414     PostAsyncTask([this, displayId]() {
1415         windowController_->OnScreenshot(displayId);
1416     });
1417 }
1418 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)1419 WMError WindowManagerService::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
1420 {
1421     if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
1422         WLOGFE("bind dialog target permission denied!");
1423         return WMError::WM_ERROR_NOT_SYSTEM_APP;
1424     }
1425     return PostSyncTask([this, &windowId, targetToken]() {
1426         return windowController_->BindDialogTarget(windowId, targetToken);
1427     });
1428 }
1429 
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1430 void WindowManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1431 {
1432     PostVoidSyncTask([this, displayId, &hasPrivateWindow]() mutable {
1433         hasPrivateWindow = windowRoot_->HasPrivateWindow(displayId);
1434     });
1435     WLOGI("called %{public}u", hasPrivateWindow);
1436 }
1437 
SetGestureNavigaionEnabled(bool enable)1438 WMError WindowManagerService::SetGestureNavigaionEnabled(bool enable)
1439 {
1440     return PostSyncTask([this, enable]() {
1441         return windowRoot_->SetGestureNavigaionEnabled(enable);
1442     });
1443 }
1444 
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1445 void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1446 {
1447     WLOGI("called");
1448     WindowManagerService::GetInstance().HasPrivateWindow(displayId, hasPrivateWindow);
1449 }
1450 
SetMaximizeMode(MaximizeMode maximizeMode)1451 void WindowManagerService::SetMaximizeMode(MaximizeMode maximizeMode)
1452 {
1453     maximizeMode_ = maximizeMode;
1454     int32_t storageMode = -1;
1455     if (PersistentStorage::HasKey("maximize_state", PersistentStorageType::MAXIMIZE_STATE)) {
1456         PersistentStorage::Get("maximize_state", storageMode, PersistentStorageType::MAXIMIZE_STATE);
1457         PersistentStorage::Delete("maximize_state", PersistentStorageType::MAXIMIZE_STATE);
1458     }
1459     PersistentStorage::Insert("maximize_state", static_cast<int32_t>(maximizeMode),
1460         PersistentStorageType::MAXIMIZE_STATE);
1461     WLOGI("globalMaximizeMode changed from %{public}d to %{public}d", storageMode, static_cast<int32_t>(maximizeMode));
1462 }
1463 
GetMaximizeMode()1464 MaximizeMode WindowManagerService::GetMaximizeMode()
1465 {
1466     return maximizeMode_;
1467 }
1468 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)1469 void WindowManagerService::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
1470 {
1471     WLOGFD("Get Focus window info in wms");
1472     windowController_->GetFocusWindowInfo(focusInfo);
1473 }
1474 } // namespace Rosen
1475 } // namespace OHOS
1476