/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_WINDOW_MANAGER_SERVICE_H #define OHOS_WINDOW_MANAGER_SERVICE_H #include #include #include #include #include #include #include #include "atomic_map.h" #include "display_change_listener.h" #include "drag_controller.h" #include "event_handler.h" #include "freeze_controller.h" #include "perform_reporter.h" #include "singleton_delegator.h" #include "snapshot_controller.h" #include "struct_multimodal.h" #include "window_common_event.h" #include "window_controller.h" #include "window_dumper.h" #include "window_group_mgr.h" #include "window_manager_config.h" #include "window_root.h" #include "window_system_effect.h" #include "wm_common_inner.h" #include "wm_single_instance.h" #include "zidl/window_manager_stub.h" namespace OHOS { namespace Rosen { class DisplayChangeListener : public IDisplayChangeListener { public: virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type) override; virtual void OnScreenshot(DisplayId displayId) override; }; class WindowInfoQueriedListener : public IWindowInfoQueriedListener { public: virtual void HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override; }; class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub { public: virtual void NotifyWindowTransition( sptr from, sptr to, bool& animaEnabled) override; int32_t GetFocusWindow(sptr& abilityToken) override; virtual void StartingWindow( sptr info, std::shared_ptr pixelMap, uint32_t bgColor) override; virtual void StartingWindow( sptr info, std::shared_ptr pixelMap) override; virtual void CancelStartingWindow(sptr abilityToken) override; virtual void NotifyAnimationAbilityDied(sptr info) override; virtual int32_t MoveMissionsToForeground(const std::vector& missionIds, int32_t topMissionId) override; virtual int32_t MoveMissionsToBackground( const std::vector& missionIds, std::vector& result) override; }; class RSUIDirector; class WindowManagerService : public SystemAbility, public WindowManagerStub { friend class DisplayChangeListener; friend class WindowManagerServiceHandler; DECLARE_SYSTEM_ABILITY(WindowManagerService); WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); public: using Task = std::function; void OnStart() override; void OnStop() override; void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; void SetWindowInputEventConsumer(); int Dump(int fd, const std::vector& args) override; WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId, sptr token) override; WMError AddWindow(sptr& property) override; WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits) override; WMError NotifyWindowTransition(sptr& from, sptr& to, bool isFromClient = false) override; void NotifyAnimationAbilityDied(sptr info); WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override; WMError RequestFocus(uint32_t windowId) override; AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) override; void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr& windowProperty, sptr& moveDragProperty) override; void ProcessPointDown(uint32_t windowId, bool isPointDown) override; void ProcessPointUp(uint32_t windowId) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; WMError MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action, bool isAsyncTask = false) override; WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent) override; WMError GetAccessibilityWindowInfo(std::vector>& infos) override; WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WMError RaiseToAppTop(uint32_t windowId) override; std::shared_ptr GetSnapshot(int32_t windowId) override; WMError SetGestureNavigaionEnabled(bool enable) override; void DispatchKeyEvent(uint32_t windowId, std::shared_ptr event) override; void NotifyDumpInfoResult(const std::vector& info) override; WMError GetWindowAnimationTargets(std::vector missionIds, std::vector>& targets) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError SetWindowAnimationController(const sptr& controller) override; WMError GetSystemConfig(SystemConfig& systemConfig) override; WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override; WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) override; void StartingWindow(sptr info, std::shared_ptr pixelMap, bool isColdStart, uint32_t bkgColor = 0xffffffff); void CancelStartingWindow(sptr abilityToken); WMError MoveMissionsToForeground(const std::vector& missionIds, int32_t topMissionId); WMError MoveMissionsToBackground(const std::vector& missionIds, std::vector& result); void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; WMError UpdateRsTree(uint32_t windowId, bool isAdd) override; void OnScreenshot(DisplayId displayId); void OnAccountSwitched(int accountId); WMError BindDialogTarget(uint32_t& windowId, sptr targetToken) override; void HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); void NotifyWindowClientPointUp(uint32_t windowId, const std::shared_ptr& pointerEvent); void SetAnchorAndScale(int32_t x, int32_t y, float scale) override; void SetAnchorOffset(int32_t deltaX, int32_t deltaY) override; void OffWindowZoom() override; void PostAsyncTask(Task task, const std::string& taskName = "WMSTask", uint32_t delay = 0); void SetMaximizeMode(MaximizeMode maximizeMode) override; MaximizeMode GetMaximizeMode() override; void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; protected: WindowManagerService(); virtual ~WindowManagerService() = default; private: bool Init(); void InitWithAbilityManagerServiceAdded(); void InitWithRanderServiceAdded(); void WindowVisibilityChangeCallback(std::shared_ptr occlusionData); void OnWindowEvent(Event event, const sptr& remoteObject); void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); WMError GetFocusWindowInfo(sptr& abilityToken); bool CheckSystemWindowPermission(const sptr& property) const; bool CheckAnimationPermission(const sptr& property) const; void ConfigureWindowManagerService(); void PostVoidSyncTask(Task task, const std::string& taskName = "WMSTask"); template> Return PostSyncTask(SyncTask&& task, const std::string& taskName = "WMSTask") { Return ret; std::function syncTask([&ret, &task]() {ret = task();}); if (handler_) { handler_->PostSyncTask(syncTask, "wms:" + taskName, AppExecFwk::EventQueue::Priority::IMMEDIATE); } return ret; } void ConfigHotZones(const std::vector& hotZones); void ConfigDecor(const WindowManagerConfig::ConfigItem& decorConfig); void ConfigWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig); void ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig); void ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig); RSAnimationTimingCurve CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig); void CreateKeyboardCurve(const WindowManagerConfig::ConfigItem& config, AnimationConfig::KeyboardAnimation& animateConfig, KeyboardAnimationCurve& sysCurveConfig); void RecordShowTimeEvent(int64_t costTime); void ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig); bool ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out); bool ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig, WindowShadowParameters& outShadow); static inline SingletonDelegator delegator; std::string name_ = "WindowManagerService"; AtomicMap accessTokenIdMaps_; sptr windowRoot_; sptr windowController_; sptr inputWindowMonitor_; sptr snapshotController_; sptr wmsHandler_; sptr dragController_; sptr freezeDisplayController_; sptr windowDumper_; sptr windowGroupMgr_; SystemConfig systemConfig_; ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 }; std::shared_ptr windowCommonEvent_; std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; RSInterfaces& rsInterface_; bool startingOpen_ = true; std::shared_ptr rsUiDirector_; std::shared_ptr windowShowPerformReport_; MaximizeMode maximizeMode_ = MaximizeMode::MODE_RECOVER; }; } // namespace Rosen } // namespace OHOS #endif // OHOS_WINDOW_MANAGER_SERVICE_H