diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index cd6780fbd1a36f621712bd7d798503ad7c3ff8e6..5aa81eb1ce3c6e3eaa7571c25fec2c14969a0666 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -1643,7 +1643,7 @@ WSError SessionStageProxy::NotifyWindowAttachStateChange(bool isAttach) { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER); if (!data.WriteInterfaceToken(GetDescriptor())) { TLOGE(WmsLogTag::WMS_SUB, "WriteInterfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index c0e6621fde3e050544914c8fea89dbba3b9f71d6..76f83c687d0cde99ceb8ad4ee10b1aa4f7c1d303 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -657,6 +657,11 @@ public: WSError SetWindowCornerRadius(float cornerRadius) override; void SetPrivacyModeChangeNotifyFunc(NotifyPrivacyModeChangeFunc&& func); + /* + * Window Pattern + */ + void NotifyWindowAttachStateListenerRegistered(bool registered) override; + protected: void NotifyIsCustomAnimationPlaying(bool isPlaying); void SetMoveDragCallback(); diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index ad18d4db0a88997bb8907f6b8816ee5cd9e83806..caf751ef9b74d0ebdcc89c0a2b1e614918c593df 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -540,6 +540,7 @@ public: void SetAttachState(bool isAttach, WindowMode windowMode = WindowMode::WINDOW_MODE_UNDEFINED); bool GetAttachState() const; void RegisterDetachCallback(const sptr& callback); + void SetNeedNotifyAttachState(bool needNotify); SystemSessionConfig GetSystemConfig() const; void RectCheckProcess(); @@ -957,6 +958,7 @@ private: */ Task saveSnapshotCallback_ = []() {}; Task removeSnapshotCallback_ = []() {}; + std::atomic needNotifyAttachState_ = { false }; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index 208f760508181542ea2b63b28ae0a2b733d697b5..4aa350eb9873b5480c18c0b0112e052117788137 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -379,6 +379,13 @@ public: virtual WSError StartMovingWithCoordinate(int32_t offsetX, int32_t offsetY, int32_t pointerPosX, int32_t pointerPosY) { return WSError::WS_OK; } virtual WSError GetCrossAxisState(CrossAxisState& state) { return WSError::WS_OK; }; + + /** + * @brief Notify the window attach state listener is registered or not. + * + * @param registered true means register success. + */ + virtual void NotifyWindowAttachStateListenerRegistered(bool registered) { } }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_ipc_interface_code.h b/window_scene/session/host/include/zidl/session_ipc_interface_code.h index 2a94d45926659adc3bf126834b28ee174031f3c0..79bfb112c27055ae9751b780dd6bf9317023456e 100644 --- a/window_scene/session/host/include/zidl/session_ipc_interface_code.h +++ b/window_scene/session/host/include/zidl/session_ipc_interface_code.h @@ -104,6 +104,9 @@ enum class SessionInterfaceCode { TRANS_ID_UPDATE_PIP_RECT, TRANS_ID_UPDATE_PIP_CONTROL_STATUS, TRANS_ID_SET_AUTOSTART_PIP, + + // Window Pattern + TRANS_ID_NOTIFY_WINDOW_ATTACH_STATE_LISTENER_REGISTERED, }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index a43a631346cb8b334bb9e38cf0b2008d1da48123..7424f0175d335e072ef10b694177f03d69788206 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -145,6 +145,11 @@ public: int32_t pointerPosX, int32_t pointerPosY) override; WSError OnContainerModalEvent(const std::string& eventName, const std::string& eventValue) override; + /* + * Window Pattern + */ + void NotifyWindowAttachStateListenerRegistered(bool registered) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index 7a65c6cdde561ce44c0f9443ea77fcdd13d0423e..1ee034031b0e4a165a7538c1089f122edfd94bef 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -109,6 +109,9 @@ private: int HandleUpdatePiPControlStatus(MessageParcel& data, MessageParcel& reply); int HandleSetAutoStartPiP(MessageParcel& data, MessageParcel& reply); + // Window Pattern + int HandleNotifyWindowAttachStateListenerRegistered(MessageParcel& data, MessageParcel& reply); + // PC Window int HandleSetWindowRectAutoSave(MessageParcel& data, MessageParcel& reply); int HandleSetSupportedWindowModes(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index bcc899ddd01c5cc3e2d918531e03350fca61000d..0dccca35afd52c189e13486c9a8ade08c95ea69e 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -6864,4 +6864,9 @@ void SceneSession::SetSidebarMaskColorModifier(bool needBlur) maskColorValue_->Set(Rosen::RSColor::FromArgbInt(snapshotMaskColor_)); } } + +void SceneSession::NotifyWindowAttachStateListenerRegistered(bool registered) +{ + SetNeedNotifyAttachState(registered); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index ef6a441528c0d0eda8815a01c13b41b7289a8072..d11238825f739477b05f0bacf1dfefa15cf72f2a 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1579,7 +1579,7 @@ void Session::SetAttachState(bool isAttach, WindowMode windowMode) TLOGND(WmsLogTag::WMS_LIFE, "session is null"); return; } - if (session->sessionStage_) { + if (session->needNotifyAttachState_.load() && session->sessionStage_) { session->sessionStage_->NotifyWindowAttachStateChange(isAttach); } TLOGND(WmsLogTag::WMS_LIFE, "isAttach:%{public}d persistentId:%{public}d", isAttach, @@ -1593,6 +1593,11 @@ void Session::SetAttachState(bool isAttach, WindowMode windowMode) CreateDetectStateTask(isAttach, windowMode); } +void Session::SetNeedNotifyAttachState(bool needNotify) +{ + needNotifyAttachState_.store(needNotify); +} + void Session::CreateDetectStateTask(bool isAttach, WindowMode windowMode) { if (!IsSupportDetectWindow(isAttach)) { diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index 0896fdcdd9c42a63693a56da401c8421a4b32107..fc203cd44904d0a9b1e721db98009572efbbf062 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -2508,4 +2508,29 @@ WSError SessionProxy::OnContainerModalEvent(const std::string& eventName, const } return WSError::WS_OK; } + +void SessionProxy::NotifyWindowAttachStateListenerRegistered(bool registered) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed"); + return; + } + if (!data.WriteBool(registered)) { + TLOGE(WmsLogTag::WMS_MAIN, "Write enable failed"); + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_MAIN, "remote is null"); + return; + } + if (remote->SendRequest( + static_cast(SessionInterfaceCode::TRANS_ID_NOTIFY_WINDOW_ATTACH_STATE_LISTENER_REGISTERED), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed"); + } +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 8a772fdbd8d2fad7b15aaa392bfd27d9e2520440..77ca1968b18469cc7eed7c50b31c5fd5efa5f901 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -246,6 +246,8 @@ int SessionStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, Messag return HandleGetCrossAxisState(data, reply); case static_cast(SessionInterfaceCode::TRANS_ID_CONTAINER_MODAL_EVENT): return HandleContainerModalEvent(data, reply); + case static_cast(SessionInterfaceCode::TRANS_ID_NOTIFY_WINDOW_ATTACH_STATE_LISTENER_REGISTERED): + return HandleNotifyWindowAttachStateListenerRegistered(data, reply); default: WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -1541,4 +1543,16 @@ int SessionStub::HandleContainerModalEvent(MessageParcel& data, MessageParcel& r OnContainerModalEvent(eventName, eventValue); return ERR_NONE; } + +int SessionStub::HandleNotifyWindowAttachStateListenerRegistered(MessageParcel& data, MessageParcel& reply) +{ + bool registered = false; + if (!data.ReadBool(registered)) { + TLOGE(WmsLogTag::WMS_PATTERN, "read registered failed"); + return ERR_INVALID_DATA; + } + TLOGD(WmsLogTag::WMS_PATTERN, "registered: %{public}d", registered); + NotifyWindowAttachStateListenerRegistered(registered); + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index fa9e183d2c8742f0236c492fa5c233f4c954fad0..ede12aa3b0821994e40998bf5d4ccca48a5aabfa 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -4683,13 +4683,16 @@ WMError WindowSceneSessionImpl::RegisterKeyboardPanelInfoChangeListener( WMError WindowSceneSessionImpl::RegisterWindowAttachStateChangeListener( const sptr& listener) { - std::lock_guard lockListener(windowAttachStateChangeListenerMutex_); if (listener == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "id: %{public}d, listener is null", GetPersistentId()); return WMError::WM_ERROR_NULLPTR; } + std::lock_guard lockListener(windowAttachStateChangeListenerMutex_); windowAttachStateChangeListener_ = listener; TLOGD(WmsLogTag::WMS_SUB, "id: %{public}d listener registered", GetPersistentId()); + auto hostSession = GetHostSession(); + CHECK_HOST_SESSION_RETURN_ERROR_IF_NULL(hostSession, WMError::WM_ERROR_NULLPTR); + hostSession->NotifyWindowAttachStateListenerRegistered(true); return WMError::WM_OK; } @@ -4697,13 +4700,17 @@ WMError WindowSceneSessionImpl::UnregisterWindowAttachStateChangeListener() { std::lock_guard lockListener(windowAttachStateChangeListenerMutex_); windowAttachStateChangeListener_ = nullptr; - TLOGI(WmsLogTag::WMS_SUB, "id: %{public}d", GetPersistentId()); + TLOGD(WmsLogTag::WMS_SUB, "id: %{public}d listener unregistered", GetPersistentId()); + auto hostSession = GetHostSession(); + CHECK_HOST_SESSION_RETURN_ERROR_IF_NULL(hostSession, WMError::WM_ERROR_NULLPTR); + hostSession->NotifyWindowAttachStateListenerRegistered(false); return WMError::WM_OK; } WSError WindowSceneSessionImpl::NotifyWindowAttachStateChange(bool isAttach) { TLOGD(WmsLogTag::WMS_SUB, "id: %{public}d", GetPersistentId()); + std::lock_guard lockListener(windowAttachStateChangeListenerMutex_); if (!windowAttachStateChangeListener_) { TLOGW(WmsLogTag::WMS_SUB, "listener is null"); return WSError::WS_ERROR_NULLPTR;