/* * Copyright (c) 2023 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_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H #define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H #include #include #include #include "agent_death_recipient.h" #include "common/include/task_scheduler.h" #include "future.h" #include "interfaces/include/ws_common.h" #include "mission_snapshot.h" #include "session_listener_controller.h" #include "scene_session_converter.h" #include "scb_session_handler.h" #include "session/host/include/root_scene_session.h" #include "session_manager/include/zidl/scene_session_manager_stub.h" #include "wm_single_instance.h" #include "window_scene_config.h" #include "display_info.h" #include "display_change_listener.h" namespace OHOS::AAFwk { class SessionInfo; } // namespace OHOS::AAFwk namespace OHOS::AppExecFwk { class IBundleMgr; struct AbilityInfo; } // namespace OHOS::AppExecFwk namespace OHOS::Global::Resource { class ResourceManager; } // namespace OHOS::Global::Resource namespace OHOS::Rosen { namespace AncoConsts { constexpr const char* ANCO_MISSION_ID = "ohos.anco.param.missionId"; constexpr const char* ANCO_SESSION_ID = "ohos.anco.param.sessionId"; } class SceneSession; class AccessibilityWindowInfo; using NotifyCreateSpecificSessionFunc = std::function& session)>; using ProcessGestureNavigationEnabledChangeFunc = std::function; using ProcessOutsideDownEventFunc = std::function; using NotifySetFocusSessionFunc = std::function& session)>; using DumpRootSceneElementInfoFunc = std::function& params, std::vector& infos)>; using WindowFocusChangedFunc = std::function; 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 SceneSessionManager : public SceneSessionManagerStub { WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager) public: sptr RequestSceneSession(const SessionInfo& sessionInfo, sptr property = nullptr); std::future RequestSceneSessionActivation(const sptr& sceneSession, bool isNewActive); WSError RequestSceneSessionBackground(const sptr& sceneSession, const bool isDelegator = false); WSError RequestSceneSessionDestruction( const sptr& sceneSession, const bool needRemoveSession = true); WSError RequestSceneSessionByCall(const sptr& sceneSession); void StartAbilityBySpecified(const SessionInfo& sessionInfo); void SetRootSceneContext(AbilityRuntime::Context* context); sptr GetRootSceneSession(); sptr GetSceneSession(int32_t persistentId); sptr GetSceneSessionByName(const std::string& bundleName, const std::string& moduleName, const std::string& abilityName); WSError CreateAndConnectSpecificSession(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, sptr property, int32_t& persistentId, sptr& session, sptr token = nullptr); WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId); WMError UpdateProperty(sptr& property, WSPropertyChangeAction action); void SetCreateSpecificSessionListener(const NotifyCreateSpecificSessionFunc& func); void SetGestureNavigationEnabledChangeListener(const ProcessGestureNavigationEnabledChangeFunc& func); void SetOutsideDownEventListener(const ProcessOutsideDownEventFunc& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; WSError ProcessBackEvent(); WSError BindDialogTarget(uint64_t persistentId, sptr targetToken); void GetStartPage(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor); WMError SetGestureNavigaionEnabled(bool enable); WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent); WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent); WSError SetFocusedSession(int32_t persistentId); int32_t GetFocusedSession() const; WSError GetAllSessionDumpInfo(std::string& info); WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector& params, const std::string& strId); WSError GetSessionDumpInfo(const std::vector& params, std::string& info); WSError UpdateFocus(int32_t persistentId, bool isFocused); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SwitchUser(int32_t oldUserId, int32_t newUserId, std::string &fileDir); int32_t GetCurrentUserId() const; void StartWindowInfoReportLoop(); void GetFocusWindowInfo(FocusChangeInfo& focusInfo); void NotifyCompleteFirstFrameDrawing(int32_t persistentId); void NotifySessionMovedToFront(int32_t persistentId); WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); WSError SetSessionLabel(const sptr &token, const std::string &label); WSError SetSessionIcon(const sptr &token, const std::shared_ptr &icon); WSError IsValidSessionIds(const std::vector &sessionIds, std::vector &results); WSError RegisterSessionListener(const sptr sessionListener); void UnregisterSessionListener(); void HandleTurnScreenOn(const sptr& sceneSession); void HandleKeepScreenOn(const sptr& sceneSession, bool requireLock); void InitWithRenderServiceAdded(); WSError PendingSessionToForeground(const sptr &token); WSError PendingSessionToBackgroundForDelegator(const sptr &token); WSError GetFocusSessionToken(sptr &token); WSError RegisterSessionListener(const sptr& listener); WSError UnRegisterSessionListener(const sptr& listener); WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, std::vector& sessionInfos); WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo); WSError GetAllAbilityInfos(const AAFwk::Want &want, int32_t userId, std::vector &abilityInfos); WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate); WSError TerminateSessionNew(const sptr info, bool needStartCaller); WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, std::shared_ptr& snapshot, bool isLowResolution); WSError SetSessionContinueState(const sptr &token, const ContinueState& continueState); WSError ClearSession(int32_t persistentId); WSError ClearAllSessions(); void UpdatePrivateStateAndNotify(bool isAddingPrivateSession); void InitPersistentStorage(); std::string GetSessionSnapshotFilePath(int32_t persistentId); void OnOutsideDownEvent(int32_t x, int32_t y); void NotifySessionTouchOutside(int32_t action, int32_t x, int32_t y); WMError GetAccessibilityWindowInfo(std::vector>& infos); WSError SetWindowFlags(const sptr& sceneSession, uint32_t flags); void SetWaterMarkSessionCount(int32_t count); int32_t GetWaterMarkSessionCount() const; void NotifyOccupiedAreaChangeInfo(const sptr callingSession, const WSRect& rect, const WSRect& occupiedArea); void OnScreenshot(DisplayId displayId); void NotifyDumpInfoResult(const std::vector& info); void SetDumpRootSceneElementInfoListener(const DumpRootSceneElementInfoFunc& func); RunnableFuture> dumpInfoFuture_; void RegisterWindowFocusChanged(const WindowFocusChangedFunc& func); WSError RegisterIAbilityManagerCollaborator(int32_t type, const sptr &impl); WSError UnregisterIAbilityManagerCollaborator(int32_t type); protected: SceneSessionManager(); virtual ~SceneSessionManager() = default; private: void Init(); void InitPrepareTerminateConfig(); void LoadWindowSceneXml(); void ConfigWindowSceneXml(); void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig); void ConfigKeyboardAnimation(const WindowSceneConfig::ConfigItem& animationConfig); bool ConfigAppWindowCornerRadius(const WindowSceneConfig::ConfigItem& item, float& out); bool ConfigAppWindowShadow(const WindowSceneConfig::ConfigItem& shadowConfig, WindowShadowConfig& outShadow); void ConfigDecor(const WindowSceneConfig::ConfigItem& decorConfig); void ConfigWindowAnimation(const WindowSceneConfig::ConfigItem& windowAnimationConfig); void ConfigStartingWindowAnimation(const WindowSceneConfig::ConfigItem& startingWindowConfig); void ConfigWindowSizeLimits(); void ConfigMainWindowSizeLimits(const WindowSceneConfig::ConfigItem& mainWindowSizeConifg); void ConfigSubWindowSizeLimits(const WindowSceneConfig::ConfigItem& subWindowSizeConifg); sptr CreateSpecificSessionCallback(); void FillSessionInfo(SessionInfo& sessionInfo); std::shared_ptr QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName, const std::string& abilityName, const std::string& moduleName); void RelayoutKeyBoard(sptr sceneSession); void RestoreCallingSessionSizeIfNeed(); void ResizeSoftInputCallingSessionIfNeed(const sptr& sceneSession); sptr SetAbilitySessionInfo(const sptr& scnSession); WSError DestroyDialogWithMainWindow(const sptr& scnSession); sptr FindMainWindowWithToken(sptr targetToken); WSError UpdateParentSession(const sptr& sceneSession, sptr property); void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing); void UpdateFocusableProperty(int32_t persistentId); std::vector> GetSceneSessionVectorByType(WindowType type); bool UpdateSessionAvoidAreaIfNeed(const int32_t& persistentId, const AvoidArea& avoidArea, AvoidAreaType avoidAreaType); bool UpdateAvoidArea(const int32_t& persistentId); sptr GetBundleManager(); std::shared_ptr CreateResourceManager( const AppExecFwk::AbilityInfo& abilityInfo); void GetStartPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, std::string& path, uint32_t& bgColor); std::string CreateCurve( const WindowSceneConfig::ConfigItem& curveConfig, const std::string& nodeName = "keyboardAnimation"); bool CheckIsRemote(const std::string& deviceId); bool GetLocalDeviceId(std::string& localDeviceId); std::string AnonymizeDeviceId(const std::string& deviceId); int GetRemoteSessionInfos(const std::string& deviceId, int32_t numMax, std::vector &sessionInfos); int GetRemoteSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo); WSError SetBrightness(const sptr& sceneSession, float brightness); WSError UpdateBrightness(int32_t persistentId); void SetDisplayBrightness(float brightness); float GetDisplayBrightness() const; WMError HandleUpdateProperty(const sptr& property, WSPropertyChangeAction action, const sptr& sceneSession); void NotifyWindowInfoChange(int32_t persistentId, WindowUpdateType type); bool FillWindowInfo(std::vector>& infos, const sptr& sceneSession); std::vector> GetWindowVisibilityChangeInfo( std::shared_ptr occlusionData); void WindowVisibilityChangeCallback(std::shared_ptr occlusiontionData); sptr SelectSesssionFromMap(const uint64_t& surfaceId); void WindowDestroyNotifyVisibility(const sptr& sceneSession); void RegisterInputMethodShownFunc(const sptr& sceneSession); void OnInputMethodShown(const int32_t& persistentId); void RegisterInputMethodHideFunc(const sptr& sceneSession); void RegisterSessionExceptionFunc(const sptr& sceneSession); bool IsSessionVisible(const sptr& session); void DumpSessionInfo(const sptr& session, std::ostringstream& oss); void DumpAllAppSessionInfo(std::ostringstream& oss); void DumpSessionElementInfo(const sptr& session, const std::vector& params, std::string& dumpInfo); void AddClientDeathRecipient(const sptr& sessionStage, const sptr& sceneSession); void DestroySpecificSession(const sptr& remoteObject); void CleanUserMap(); WMError UpdatePropertyDragEnabled(const sptr& property, const sptr& sceneSession); WMError UpdatePropertyRaiseEnabled(const sptr& property, const sptr& sceneSession); WSError DestroyAndDisconnectSpecificSessionInner(sptr sceneSession); sptr rootSceneSession_; std::shared_ptr rootSceneContext_; std::shared_mutex sceneSessionMapMutex_; std::map> sceneSessionMap_; sptr scbSessionHandler_; std::shared_ptr listenerController_; std::map, int32_t> remoteObjectMap_; std::set> avoidAreaListenerSessionSet_; std::map> lastUpdatedAvoidArea_; NotifyCreateSpecificSessionFunc createSpecificSessionFunc_; ProcessGestureNavigationEnabledChangeFunc gestureNavigationEnabledChangeFunc_; ProcessOutsideDownEventFunc outsideDownEventFunc_; DumpRootSceneElementInfoFunc dumpRootSceneFunc_; AppWindowSceneConfig appWindowSceneConfig_; SystemSessionConfig systemConfig_; int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isPrepareTerminateEnable_ {false}; WSRect callingWindowRestoringRect_ = {0, 0, 0, 0}; int32_t currentUserId_; std::shared_ptr taskScheduler_; sptr bundleMgr_; std::shared_ptr eventLoop_; std::shared_ptr eventHandler_; bool isReportTaskStart_ = false; std::shared_ptr lastOcclusionData_ = std::make_shared(); RSInterfaces& rsInterface_; void RegisterSessionStateChangeNotifyManagerFunc(sptr& sceneSession); void OnSessionStateChange(int32_t persistentId, const SessionState& state); sptr sessionListener_; sptr FindSessionByToken(const sptr &token); void CheckAndNotifyWaterMarkChangedResult(bool isAddingWaterMark); WSError NotifyWaterMarkFlagChangedResult(bool hasWaterMark); int32_t waterMarkSessionCount_ { 0 }; void ProcessPreload(const AppExecFwk::AbilityInfo& abilityInfo) const; WindowFocusChangedFunc windowFocusChangedFunc_; sptr callingSession_ = nullptr; sptr windowDeath_ = new AgentDeathRecipient( std::bind(&SceneSessionManager::DestroySpecificSession, this, std::placeholders::_1)); WSError ClearSession(sptr sceneSession); bool IsSessionClearable(sptr scnSession); void GetAllClearableSessions(std::vector>& sessionVector); int GetRemoteSessionSnapshotInfo(const std::string& deviceId, int32_t sessionId, AAFwk::MissionSnapshot& sessionSnapshot); const int32_t BROKER_UID = 5528; const int32_t BROKER_RESERVE_UID = 5005; std::shared_mutex collaboratorMapLock_; std::unordered_map> collaboratorMap_; bool CheckCollaboratorType(int32_t type); void QueryAbilityInfoFromBMS(const int32_t uId, const SessionInfo& sessionInfo, AppExecFwk::AbilityInfo& abilityInfo); void NotifyStartAbility(int32_t collaboratorType, const SessionInfo& sessionInfo); void NotifySessionCreate(const sptr sceneSession, SessionInfo& sessionInfo); void NotifyLoadAbility(int32_t collaboratorType, sptr abilitySessionInfo, std::shared_ptr abilityInfo); void NotifyUpdateSessionInfo(const sptr sceneSession); void NotifyClearSession(int32_t collaboratorType, int32_t persistentId); void NotifyMoveSessionToForeground(int32_t collaboratorType, int32_t persistendId); void PreHandleCollaborator(sptr sceneSession); }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H