1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_WINDOW_ADAPTER_H 17e0dac50fSopenharmony_ci#define OHOS_WINDOW_ADAPTER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <refbase.h> 20e0dac50fSopenharmony_ci#include <zidl/window_manager_agent_interface.h> 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_ci#include "common/include/window_session_property.h" 23e0dac50fSopenharmony_ci#include "window.h" 24e0dac50fSopenharmony_ci#include "zidl/window_interface.h" 25e0dac50fSopenharmony_ci#include "singleton_delegator.h" 26e0dac50fSopenharmony_ci#include "window_property.h" 27e0dac50fSopenharmony_ci#include "wm_single_instance.h" 28e0dac50fSopenharmony_ci#include "zidl/window_manager_interface.h" 29e0dac50fSopenharmony_ci 30e0dac50fSopenharmony_cinamespace OHOS { 31e0dac50fSopenharmony_cinamespace Rosen { 32e0dac50fSopenharmony_ciclass WMSDeathRecipient : public IRemoteObject::DeathRecipient { 33e0dac50fSopenharmony_cipublic: 34e0dac50fSopenharmony_ci virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 35e0dac50fSopenharmony_ci}; 36e0dac50fSopenharmony_ci 37e0dac50fSopenharmony_ciclass WindowAdapter { 38e0dac50fSopenharmony_ciWM_DECLARE_SINGLE_INSTANCE(WindowAdapter); 39e0dac50fSopenharmony_cipublic: 40e0dac50fSopenharmony_ci using SessionRecoverCallbackFunc = std::function<WMError()>; 41e0dac50fSopenharmony_ci using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>; 42e0dac50fSopenharmony_ci virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty, 43e0dac50fSopenharmony_ci std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId, const sptr<IRemoteObject>& token); 44e0dac50fSopenharmony_ci virtual WMError AddWindow(sptr<WindowProperty>& windowProperty); 45e0dac50fSopenharmony_ci virtual WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits); 46e0dac50fSopenharmony_ci virtual WMError DestroyWindow(uint32_t windowId); 47e0dac50fSopenharmony_ci virtual WMError RequestFocus(uint32_t windowId); 48e0dac50fSopenharmony_ci virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect); 49e0dac50fSopenharmony_ci virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); 50e0dac50fSopenharmony_ci virtual WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId); 51e0dac50fSopenharmony_ci virtual void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty, 52e0dac50fSopenharmony_ci sptr<MoveDragProperty>& moveDragProperty); 53e0dac50fSopenharmony_ci virtual void ProcessPointDown(uint32_t windowId, bool isPointDown = true); 54e0dac50fSopenharmony_ci virtual void ProcessPointUp(uint32_t windowId); 55e0dac50fSopenharmony_ci virtual WMError MinimizeAllAppWindows(DisplayId displayId); 56e0dac50fSopenharmony_ci virtual WMError ToggleShownStateForAllAppWindows(); 57e0dac50fSopenharmony_ci virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); 58e0dac50fSopenharmony_ci virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action); 59e0dac50fSopenharmony_ci virtual WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent); 60e0dac50fSopenharmony_ci virtual WMError GetSystemConfig(SystemConfig& systemConfig); 61e0dac50fSopenharmony_ci virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones); 62e0dac50fSopenharmony_ci virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd); 63e0dac50fSopenharmony_ci virtual WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken); 64e0dac50fSopenharmony_ci virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type, 65e0dac50fSopenharmony_ci const sptr<IWindowManagerAgent>& windowManagerAgent); 66e0dac50fSopenharmony_ci virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, 67e0dac50fSopenharmony_ci const sptr<IWindowManagerAgent>& windowManagerAgent); 68e0dac50fSopenharmony_ci virtual WMError CheckWindowId(int32_t windowId, int32_t& pid); 69e0dac50fSopenharmony_ci 70e0dac50fSopenharmony_ci virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller); 71e0dac50fSopenharmony_ci virtual WMError NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to); 72e0dac50fSopenharmony_ci virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener); 73e0dac50fSopenharmony_ci virtual void ClearWindowAdapter(); 74e0dac50fSopenharmony_ci 75e0dac50fSopenharmony_ci virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos); 76e0dac50fSopenharmony_ci virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos); 77e0dac50fSopenharmony_ci virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos); 78e0dac50fSopenharmony_ci virtual void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated, 79e0dac50fSopenharmony_ci sptr<RSIWindowAnimationFinishedCallback>& finishCallback); 80e0dac50fSopenharmony_ci virtual void SetAnchorAndScale(int32_t x, int32_t y, float scale); 81e0dac50fSopenharmony_ci virtual void SetAnchorOffset(int32_t deltaX, int32_t deltaY); 82e0dac50fSopenharmony_ci virtual void OffWindowZoom(); 83e0dac50fSopenharmony_ci virtual WMError RaiseToAppTop(uint32_t windowId); 84e0dac50fSopenharmony_ci virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId); 85e0dac50fSopenharmony_ci virtual WMError SetGestureNavigationEnabled(bool enable); 86e0dac50fSopenharmony_ci virtual void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event); 87e0dac50fSopenharmony_ci virtual void NotifyDumpInfoResult(const std::vector<std::string>& info); 88e0dac50fSopenharmony_ci virtual WMError DumpSessionAll(std::vector<std::string>& infos); 89e0dac50fSopenharmony_ci virtual WMError DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos); 90e0dac50fSopenharmony_ci virtual WMError GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj); 91e0dac50fSopenharmony_ci virtual WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds, 92e0dac50fSopenharmony_ci std::vector<sptr<RSWindowAnimationTarget>>& targets); 93e0dac50fSopenharmony_ci virtual void SetMaximizeMode(MaximizeMode maximizeMode); 94e0dac50fSopenharmony_ci virtual MaximizeMode GetMaximizeMode(); 95e0dac50fSopenharmony_ci virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); 96e0dac50fSopenharmony_ci virtual WMError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); 97e0dac50fSopenharmony_ci virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); 98e0dac50fSopenharmony_ci virtual WMError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible); 99e0dac50fSopenharmony_ci virtual WMError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener); 100e0dac50fSopenharmony_ci virtual WMError RaiseWindowToTop(int32_t persistentId); 101e0dac50fSopenharmony_ci virtual WMError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId); 102e0dac50fSopenharmony_ci virtual void CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 103e0dac50fSopenharmony_ci const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 104e0dac50fSopenharmony_ci sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, 105e0dac50fSopenharmony_ci SystemSessionConfig& systemConfig, sptr<IRemoteObject> token = nullptr); 106e0dac50fSopenharmony_ci virtual void RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 107e0dac50fSopenharmony_ci const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 108e0dac50fSopenharmony_ci sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr); 109e0dac50fSopenharmony_ci virtual WMError DestroyAndDisconnectSpecificSession(const int32_t persistentId); 110e0dac50fSopenharmony_ci virtual WMError DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId, 111e0dac50fSopenharmony_ci const sptr<IRemoteObject>& callback); 112e0dac50fSopenharmony_ci virtual WMError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage, 113e0dac50fSopenharmony_ci const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 114e0dac50fSopenharmony_ci sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token = nullptr); 115e0dac50fSopenharmony_ci WMError GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap); 116e0dac50fSopenharmony_ci void RegisterSessionRecoverCallbackFunc(int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc); 117e0dac50fSopenharmony_ci void UnregisterSessionRecoverCallbackFunc(int32_t persistentId); 118e0dac50fSopenharmony_ci WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); 119e0dac50fSopenharmony_ci virtual WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); 120e0dac50fSopenharmony_ci virtual WMError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken); 121e0dac50fSopenharmony_ci virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused); 122e0dac50fSopenharmony_ci virtual void AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage, 123e0dac50fSopenharmony_ci const sptr<IRemoteObject>& token, uint64_t surfaceNodeId); 124e0dac50fSopenharmony_ci virtual void RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage, 125e0dac50fSopenharmony_ci const sptr<IRemoteObject>& token); 126e0dac50fSopenharmony_ci virtual void UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect); 127e0dac50fSopenharmony_ci virtual void ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY); 128e0dac50fSopenharmony_ci virtual WMError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide); 129e0dac50fSopenharmony_ci virtual WMError UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags, 130e0dac50fSopenharmony_ci uint32_t extWindowActions); 131e0dac50fSopenharmony_ci virtual WMError GetHostWindowRect(int32_t hostWindowId, Rect& rect); 132e0dac50fSopenharmony_ci virtual WMError GetFreeMultiWindowEnableState(bool& enable); 133e0dac50fSopenharmony_ci virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus); 134e0dac50fSopenharmony_ci virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect); 135e0dac50fSopenharmony_ci virtual WMError GetWindowModeType(WindowModeType& windowModeType); 136e0dac50fSopenharmony_ci virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType); 137e0dac50fSopenharmony_ci virtual WMError SkipSnapshotForAppProcess(int32_t pid, bool skip); 138e0dac50fSopenharmony_ci virtual WMError SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled); 139e0dac50fSopenharmony_ci virtual WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, 140e0dac50fSopenharmony_ci int32_t x, int32_t y, std::vector<int32_t>& windowIds); 141e0dac50fSopenharmony_ci virtual WMError ReleaseForegroundSessionScreenLock(); 142e0dac50fSopenharmony_ci WMError GetDisplayIdByPersistentId(int32_t persistentId, int32_t& displayId); 143e0dac50fSopenharmony_ci 144e0dac50fSopenharmony_ci /* 145e0dac50fSopenharmony_ci * PC Window 146e0dac50fSopenharmony_ci */ 147e0dac50fSopenharmony_ci virtual WMError IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode); 148e0dac50fSopenharmony_ci 149e0dac50fSopenharmony_ciprivate: 150e0dac50fSopenharmony_ci static inline SingletonDelegator<WindowAdapter> delegator; 151e0dac50fSopenharmony_ci void ReregisterWindowManagerAgent(); 152e0dac50fSopenharmony_ci void OnUserSwitch(); 153e0dac50fSopenharmony_ci bool InitWMSProxy(); 154e0dac50fSopenharmony_ci bool InitSSMProxy(); 155e0dac50fSopenharmony_ci 156e0dac50fSopenharmony_ci void WindowManagerAndSessionRecover(); 157e0dac50fSopenharmony_ci 158e0dac50fSopenharmony_ci sptr<IWindowManager> GetWindowManagerServiceProxy() const; 159e0dac50fSopenharmony_ci 160e0dac50fSopenharmony_ci mutable std::mutex mutex_; 161e0dac50fSopenharmony_ci sptr<IWindowManager> windowManagerServiceProxy_ = nullptr; 162e0dac50fSopenharmony_ci sptr<WMSDeathRecipient> wmsDeath_ = nullptr; 163e0dac50fSopenharmony_ci bool isProxyValid_ = false; 164e0dac50fSopenharmony_ci bool recoverInitialized_ = false; 165e0dac50fSopenharmony_ci bool isRegisteredUserSwitchListener_ = false; 166e0dac50fSopenharmony_ci std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap_; 167e0dac50fSopenharmony_ci std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerAgentMap_; 168e0dac50fSopenharmony_ci // above guarded by mutex_ 169e0dac50fSopenharmony_ci}; 170e0dac50fSopenharmony_ci} // namespace Rosen 171e0dac50fSopenharmony_ci} // namespace OHOS 172e0dac50fSopenharmony_ci#endif // OHOS_WINDOW_ADAPTER_H 173