1 /*
2  * Copyright (c) 2023 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 #ifndef OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
18 
19 #include <iremote_broker.h>
20 #include <session_info.h>
21 
22 #include "interfaces/include/ws_common.h"
23 #include "common/include/window_session_property.h"
24 #include "session/container/include/zidl/session_stage_interface.h"
25 #include "session/container/include/zidl/window_event_channel_interface.h"
26 
27 namespace OHOS::Accessibility {
28 class AccessibilityEventInfo;
29 }
30 namespace OHOS::Rosen {
31 class RSSurfaceNode;
32 class ISession : public IRemoteBroker {
33 public:
34     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISession");
35 
36     virtual WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
37         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
38         sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr,
39         const std::string& identityToken = "") { return WSError::WS_OK; }
40     virtual WSError Foreground(
41         sptr<WindowSessionProperty> property, bool isFromClient = false, const std::string& identityToken = "") = 0;
42     virtual WSError Background(bool isFromClient = false, const std::string& identityToken = "") = 0;
43     virtual WSError Disconnect(bool isFromClient = false, const std::string& identityToken = "") = 0;
44     virtual WSError Show(sptr<WindowSessionProperty> property) = 0;
45     virtual WSError Hide() = 0;
46     virtual WSError DrawingCompleted() = 0;
47     virtual WSError RemoveStartingWindow() = 0;
48 
49     // scene session
OnSessionEvent(SessionEvent event)50     virtual WSError OnSessionEvent(SessionEvent event) { return WSError::WS_OK; }
51 
52     /**
53      * @brief Receive session event from application.
54      *
55      * This function provides the ability for applications to move window.
56      * This interface will take effect after touch down event.
57      *
58      * @return Returns WSError::WS_OK if called success, otherwise failed.
59      */
SyncSessionEvent(SessionEvent event)60     virtual WSError SyncSessionEvent(SessionEvent event) { return WSError::WS_OK; }
61 
62     /**
63      * @brief Enables or disables system window dragging.
64      *
65      * This function provides the ability for system applications to make system window dragable.
66      *
67      * @return Returns WSError::WS_OK if called success, otherwise failed.
68      * @permission Make sure the caller has system permission.
69      */
SetSystemWindowEnableDrag(bool enableDrag)70     virtual WMError SetSystemWindowEnableDrag(bool enableDrag) { return WMError::WM_OK; }
71 
OnLayoutFullScreenChange(bool isLayoutFullScreen)72     virtual WSError OnLayoutFullScreenChange(bool isLayoutFullScreen) { return WSError::WS_OK; }
73 
74     /**
75      * @brief Callback for processing set default density enabled.
76      *
77      * @param isDefaultDensityEnabled Indicates the {@link bool}
78      * @return Returns WSError::WS_OK if called success, otherwise failed.
79      */
OnDefaultDensityEnabled(bool isDefaultDensityEnabled)80     virtual WSError OnDefaultDensityEnabled(bool isDefaultDensityEnabled) { return WSError::WS_OK; }
81 
82     /**
83      * @brief Callback for processing title and dock hover show changes.
84      *
85      * @param isTitleHoverShown Indicates the {@link bool}
86      * @param isDockHoverShown Indicates the {@link bool}
87      * @return Returns WSError::WS_OK if called success, otherwise failed.
88      */
89     virtual WSError OnTitleAndDockHoverShowChange(bool isTitleHoverShown = true,
90         bool isDockHoverShown = true) { return WSError::WS_OK; }
91 
92     /**
93      * @brief Callback for processing restore main window.
94      *
95      * @return Returns WSError::WS_OK if called success, otherwise failed.
96      */
OnRestoreMainWindow()97     virtual WSError OnRestoreMainWindow() { return WSError::WS_OK; }
98 
RaiseToAppTop()99     virtual WSError RaiseToAppTop() { return WSError::WS_OK; }
100     virtual WSError UpdateSessionRect(
101         const WSRect &rect, const SizeChangeReason reason, bool isGlobal = false, bool isFromMoveToGlobal = false)
102     {
103         return WSError::WS_OK;
104     }
UpdateClientRect(const WSRect & rect)105     virtual WSError UpdateClientRect(const WSRect& rect) { return WSError::WS_OK; }
GetGlobalScaledRect(Rect & globalScaledRect)106     virtual WMError GetGlobalScaledRect(Rect& globalScaledRect) { return WMError::WM_OK; }
OnNeedAvoid(bool status)107     virtual WSError OnNeedAvoid(bool status) { return WSError::WS_OK; }
GetAvoidAreaByType(AvoidAreaType type)108     virtual AvoidArea GetAvoidAreaByType(AvoidAreaType type) { return {}; }
GetAllAvoidAreas(std::map<AvoidAreaType,AvoidArea> & avoidAreas)109     virtual WSError GetAllAvoidAreas(std::map<AvoidAreaType, AvoidArea>& avoidAreas) { return WSError::WS_OK; }
RequestSessionBack(bool needMoveToBackground)110     virtual WSError RequestSessionBack(bool needMoveToBackground) { return WSError::WS_OK; }
MarkProcessed(int32_t eventId)111     virtual WSError MarkProcessed(int32_t eventId) { return WSError::WS_OK; }
SetGlobalMaximizeMode(MaximizeMode mode)112     virtual WSError SetGlobalMaximizeMode(MaximizeMode mode) { return WSError::WS_OK; }
GetGlobalMaximizeMode(MaximizeMode & mode)113     virtual WSError GetGlobalMaximizeMode(MaximizeMode& mode) { return WSError::WS_OK; }
SetAspectRatio(float ratio)114     virtual WSError SetAspectRatio(float ratio) { return WSError::WS_OK; }
UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)115     virtual WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) { return WSError::WS_OK; }
UpdateWindowSceneAfterCustomAnimation(bool isAdd)116     virtual WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) { return WSError::WS_OK; }
RaiseAboveTarget(int32_t subWindowId)117     virtual WSError RaiseAboveTarget(int32_t subWindowId) { return WSError::WS_OK; }
RaiseAppMainWindowToTop()118     virtual WSError RaiseAppMainWindowToTop() { return WSError::WS_OK; }
PendingSessionActivation(const sptr<AAFwk::SessionInfo> abilitySessionInfo)119     virtual WSError PendingSessionActivation(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
120         { return WSError::WS_OK; }
TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)121     virtual WSError TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo) { return WSError::WS_OK; }
SetLandscapeMultiWindow(bool isLandscapeMultiWindow)122     virtual WSError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) { return WSError::WS_OK; }
123     virtual WSError NotifySessionException(
124         const sptr<AAFwk::SessionInfo> abilitySessionInfo, bool needRemoveSession = false) { return WSError::WS_OK; }
125 
126     // extension session
TransferAbilityResult(uint32_t resultCode,const AAFwk::Want & want)127     virtual WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) { return WSError::WS_OK; }
TransferExtensionData(const AAFwk::WantParams & wantParams)128     virtual WSError TransferExtensionData(const AAFwk::WantParams& wantParams) { return WSError::WS_OK; }
TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)129     virtual WSError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
130         int64_t uiExtensionIdLevel)
131     {
132         return WSError::WS_OK;
133     }
NotifyFrameLayoutFinishFromApp(bool notifyListener,const WSRect & rect)134     virtual WSError NotifyFrameLayoutFinishFromApp(bool notifyListener, const WSRect& rect)
135     {
136         return WSError::WS_OK;
137     }
NotifyExtensionDied()138     virtual void NotifyExtensionDied() {}
NotifyExtensionTimeout(int32_t errorCode)139     virtual void NotifyExtensionTimeout(int32_t errorCode) {}
TriggerBindModalUIExtension()140     virtual void TriggerBindModalUIExtension() {}
NotifySyncOn()141     virtual void NotifySyncOn() {}
NotifyAsyncOn()142     virtual void NotifyAsyncOn() {}
NotifyTransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)143     virtual void NotifyTransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
144         int64_t uiExtensionIdLevel) {}
NotifyExtensionEventAsync(uint32_t notifyEvent)145     virtual void NotifyExtensionEventAsync(uint32_t notifyEvent) {}
146 
147     /**
148      * @brief Close pip window while stopPip is called.
149      *
150      * Notify system that pip window is stopping and execute animation.
151      */
NotifyPiPWindowPrepareClose()152     virtual void NotifyPiPWindowPrepareClose() {}
153 
154     /**
155      * @brief Update the required params to system.
156      *
157      * Update the required rect and reason to determine the final size of pip window. Called when start pip,
158      * show pip window, update pip size and pip restore.
159      * Make sure the caller's process is same with the process which created pip window.
160      *
161      * @param rect Indicates the {@link Rect} structure containing required size and position.
162      * @param reason Indicates the {@link SizeChangeReason} reason.
163      * @return Returns WSError::WS_OK if called success, otherwise failed.
164      */
UpdatePiPRect(const Rect & rect,SizeChangeReason reason)165     virtual WSError UpdatePiPRect(const Rect& rect, SizeChangeReason reason) { return WSError::WS_OK; }
166 
167     /**
168      * @brief Update the pip control status to pip control panel.
169      *
170      * Called when the specified component's status needs to be updated.
171      * Make sure the caller's process is same with the process which created pip window.
172      *
173      * @param controlType Indicates the {@link WsPiPControlType} component in pip control panel.
174      * @param status Indicates the {@link WsPiPControlStatus} status of specified component.
175      * @return Returns WSError::WS_OK if called success, otherwise failed.
176      */
UpdatePiPControlStatus(WsPiPControlType controlType,WsPiPControlStatus status)177     virtual WSError UpdatePiPControlStatus(WsPiPControlType controlType, WsPiPControlStatus status)
178     {
179         return WSError::WS_OK;
180     }
181 
182     /**
183      * @brief Update the auto start pip window status.
184      *
185      * @param isAutoStart Indicates the {@link bool}
186      * @param priority Indicates the {@link uint32_t} priority of pip window
187      * @return Returns WSError::WS_OK if called success, otherwise failed.
188      */
SetAutoStartPiP(bool isAutoStart,uint32_t priority)189     virtual WSError SetAutoStartPiP(bool isAutoStart, uint32_t priority) { return WSError::WS_OK; }
190 
ProcessPointDownSession(int32_t posX,int32_t posY)191     virtual WSError ProcessPointDownSession(int32_t posX, int32_t posY) { return WSError::WS_OK; }
SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)192     virtual WSError SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
193     {
194         return WSError::WS_OK;
195     }
IsStartMoving()196     virtual bool IsStartMoving() { return false; }
ChangeSessionVisibilityWithStatusBar(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool visible)197     virtual WSError ChangeSessionVisibilityWithStatusBar(const sptr<AAFwk::SessionInfo> abilitySessionInfo,
198         bool visible) { return WSError::WS_OK; }
UpdateRectChangeListenerRegistered(bool isRegister)199     virtual WSError UpdateRectChangeListenerRegistered(bool isRegister)
200     {
201         return WSError::WS_OK;
202     }
SetCallingSessionId(uint32_t callingSessionId)203     virtual void SetCallingSessionId(uint32_t callingSessionId) {};
SetCustomDecorHeight(int32_t height)204     virtual void SetCustomDecorHeight(int32_t height) {};
UpdateSessionPropertyByAction(const sptr<WindowSessionProperty> & property,WSPropertyChangeAction action)205     virtual WMError UpdateSessionPropertyByAction(const sptr<WindowSessionProperty>& property,
206         WSPropertyChangeAction action) { return WMError::WM_OK; }
GetAppForceLandscapeConfig(AppForceLandscapeConfig & config)207     virtual WMError GetAppForceLandscapeConfig(AppForceLandscapeConfig& config) { return WMError::WM_OK; }
AdjustKeyboardLayout(const KeyboardLayoutParams & params)208     virtual WSError AdjustKeyboardLayout(const KeyboardLayoutParams& params) { return WSError::WS_OK; }
SetDialogSessionBackGestureEnabled(bool isEnabled)209     virtual WSError SetDialogSessionBackGestureEnabled(bool isEnabled) { return WSError::WS_OK; }
NotifyExtensionDetachToDisplay()210     virtual void NotifyExtensionDetachToDisplay() {}
211 
212     /**
213      * @brief Request to get focus or lose focus.
214      *
215      * @param isFocused True means window wants to get focus, false means the opposite.
216      * @return Returns WSError::WS_OK if called success, otherwise failed.
217      */
RequestFocus(bool isFocused)218     virtual WSError RequestFocus(bool isFocused) { return WSError::WS_OK; }
219 
220     /**
221      * @brief Callback for session modal type changes.
222      *
223      * @param subWindowModalType Indicates the {@link SubWindowModalType}
224      * @return Returns WSError::WS_OK if called success, otherwise failed.
225      */
NotifySubModalTypeChange(SubWindowModalType subWindowModalType)226     virtual WSError NotifySubModalTypeChange(SubWindowModalType subWindowModalType) { return WSError::WS_OK; }
227 
228     /**
229      * @brief Callback for main session modal type changes.
230      *
231      * @param isModal Indicates the {@link bool}
232      * @return Returns WSError::WS_OK if called success, otherwise failed.
233      */
NotifyMainModalTypeChange(bool isModal)234     virtual WSError NotifyMainModalTypeChange(bool isModal) { return WSError::WS_OK; }
235 
236     /**
237      * @brief Callback for setting to automatically save the window rect.
238      *
239      * @param enabled Enable the window rect auto-save if true, otherwise means the opposite.
240      * @return Returns WSError::WS_OK if called success, otherwise failed.
241      */
OnSetWindowRectAutoSave(bool enabled)242     virtual WSError OnSetWindowRectAutoSave(bool enabled) { return WSError::WS_OK; }
243 
244     /*
245      *  Gesture Back
246      */
SetGestureBackEnabled(bool isEnabled)247     virtual WMError SetGestureBackEnabled(bool isEnabled) { return WMError::WM_OK; }
248 };
249 } // namespace OHOS::Rosen
250 
251 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
252