From 65ac7815c4018b79bd138d256f4c5286c33da818 Mon Sep 17 00:00:00 2001 From: wangh Date: Sun, 15 Oct 2023 19:32:38 +0800 Subject: [PATCH] [wms] add interactive type for window stage event Signed-off-by: wangh --- .../window_napi/js_window_utils.cpp | 4 ++++ test/common/mock/mock_IWindow.h | 1 + wm/include/window_agent.h | 2 ++ wm/include/window_impl.h | 11 +++++++++ wm/include/zidl/window_interface.h | 2 ++ wm/include/zidl/window_proxy.h | 2 ++ wm/src/window_agent.cpp | 10 ++++++++ wm/src/window_impl.cpp | 13 ++++++++++ wm/src/zidl/window_proxy.cpp | 21 ++++++++++++++++ wm/src/zidl/window_stub.cpp | 5 ++++ wmserver/src/window_root.cpp | 24 +++++++++++++++++++ .../unittest/avoid_area_controller_test.cpp | 1 + wmserver/test/unittest/window_node_test.cpp | 1 + 13 files changed, 97 insertions(+) diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index a314c16d52..eac8b1b09b 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -233,6 +233,10 @@ napi_value WindowStageEventTypeInit(napi_env env) static_cast(LifeCycleEventType::INACTIVE))); napi_set_named_property(env, objValue, "HIDDEN", CreateJsValue(env, static_cast(LifeCycleEventType::BACKGROUND))); + napi_set_named_property(env, objValue, "RESUMED", CreateJsValue(env, + static_cast(LifeCycleEventType::RESUMED))); + napi_set_named_property(env, objValue, "PAUSED", CreateJsValue(env, + static_cast(LifeCycleEventType::PAUSED))); return objValue; } diff --git a/test/common/mock/mock_IWindow.h b/test/common/mock/mock_IWindow.h index 9e71f725e8..6ca5f432d9 100644 --- a/test/common/mock/mock_IWindow.h +++ b/test/common/mock/mock_IWindow.h @@ -53,6 +53,7 @@ public: MOCK_METHOD2(UpdateZoomTransform, WMError(const Transform& trans, bool isDisplayZoomOn)); MOCK_METHOD1(RestoreSplitWindowMode, WMError(uint32_t mode)); MOCK_METHOD1(ConsumeKeyEvent, void(std::shared_ptr event)); + MOCK_METHOD1(NotifyForegroundInteractiveStatus, void(bool interactive)); sptr AsObject() override { return nullptr; diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 5712c474c0..e34e9848cc 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -52,6 +52,8 @@ public: WMError UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn) override; WMError RestoreSplitWindowMode(uint32_t mode) override; void ConsumeKeyEvent(std::shared_ptr event) override; + void NotifyForegroundInteractiveStatus(bool interactive) override; + private: sptr window_; }; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 5a37682e05..394a2e4621 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -261,6 +261,7 @@ public: void NotifyBackground(); void UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn); void PerformBack() override; + void NotifyForegroundInteractiveStatus(bool interactive); virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; @@ -454,6 +455,16 @@ private: CALL_UI_CONTENT(UnFocus); } } + inline void NotifyAfterResumed() + { + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterResumed, lifecycleListeners); + } + inline void NotifyAfterPaused() + { + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterPaused, lifecycleListeners); + } inline void NotifyBeforeDestroy(std::string windowName) { std::lock_guard lock(mutex_); diff --git a/wm/include/zidl/window_interface.h b/wm/include/zidl/window_interface.h index f413807bed..6719eb75ab 100644 --- a/wm/include/zidl/window_interface.h +++ b/wm/include/zidl/window_interface.h @@ -52,6 +52,7 @@ public: TRANS_ID_UPDATE_ZOOM_TRANSFORM, TRANS_ID_RESTORE_SPLIT_WINDOW_MODE, TRANS_ID_CONSUME_KEY_EVENT, + TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS, }; virtual WMError UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason, @@ -79,6 +80,7 @@ public: virtual void ConsumeKeyEvent(std::shared_ptr event) = 0; virtual WMError UpdateOccupiedAreaAndRect(const sptr& info, const Rect& rect, const std::shared_ptr& rsTransaction = nullptr) = 0; + virtual void NotifyForegroundInteractiveStatus(bool interactive) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_proxy.h b/wm/include/zidl/window_proxy.h index 09fc535907..b2b81aca06 100644 --- a/wm/include/zidl/window_proxy.h +++ b/wm/include/zidl/window_proxy.h @@ -54,6 +54,8 @@ public: WMError UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn) override; WMError RestoreSplitWindowMode(uint32_t mode) override; void ConsumeKeyEvent(std::shared_ptr event) override; + void NotifyForegroundInteractiveStatus(bool interactive) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index f6421f0b92..93185dcef2 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -255,5 +255,15 @@ void WindowAgent::ConsumeKeyEvent(std::shared_ptr event) } window_->ConsumeKeyEvent(event); } + +void WindowAgent::NotifyForegroundInteractiveStatus(bool interactive) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->NotifyForegroundInteractiveStatus(interactive); +} + } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 8da8ecc604..e25f7380e9 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -3244,6 +3244,19 @@ void WindowImpl::NotifyBackground() NotifyAfterBackground(); } +void WindowImpl::NotifyForegroundInteractiveStatus(bool interactive) +{ + WLOGFI("NotifyForegroundInteractiveStatus %{public}d", interactive); + if (!IsWindowValid() || state_ != WindowState::STATE_SHOWN) { + return; + } + if (interactive) { + NotifyAfterResumed(); + } else { + NotifyAfterPaused(); + } +} + void WindowImpl::TransformSurfaceNode(const Transform& trans) { if (surfaceNode_ == nullptr) { diff --git a/wm/src/zidl/window_proxy.cpp b/wm/src/zidl/window_proxy.cpp index 984e97e3a3..7fdabdf026 100644 --- a/wm/src/zidl/window_proxy.cpp +++ b/wm/src/zidl/window_proxy.cpp @@ -548,6 +548,27 @@ void WindowProxy::ConsumeKeyEvent(std::shared_ptr event) return; } } + +void WindowProxy::NotifyForegroundInteractiveStatus(bool interactive) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteBool(interactive)) { + WLOGFE("Write Focus failed"); + return; + } + + if (Remote()->SendRequest(static_cast(WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} + } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_stub.cpp b/wm/src/zidl/window_stub.cpp index eadf28944f..b1ed03aaf4 100644 --- a/wm/src/zidl/window_stub.cpp +++ b/wm/src/zidl/window_stub.cpp @@ -200,6 +200,11 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce ConsumeKeyEvent(event); break; } + case WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS: { + bool interactive = data.ReadBool(); + NotifyForegroundInteractiveStatus(interactive); + break; + } default: WLOGFW("unknown transaction code %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 0c7dc2c7c1..9c7a51b90c 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -571,6 +571,18 @@ WMError WindowRoot::PostProcessAddWindowNode(sptr& node, sptrSetDisplayOrientationFromWindow(node, true); } } + + if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + for (auto& winNode : windowNodes) { + if (winNode && WindowHelper::IsMainWindow(winNode->GetWindowType()) && + winNode->isVisible_ && winNode->GetWindowToken()) { + winNode->GetWindowToken()->NotifyForegroundInteractiveStatus(false); + } + } + } + return WMError::WM_OK; } @@ -780,6 +792,18 @@ WMError WindowRoot::RemoveWindowNode(uint32_t windowId, bool fromAnimation) } HandleKeepScreenOn(windowId, false); } + + if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + for (auto& winNode : windowNodes) { + if (winNode && WindowHelper::IsMainWindow(winNode->GetWindowType()) && + winNode->isVisible_ && winNode->GetWindowToken()) { + winNode->GetWindowToken()->NotifyForegroundInteractiveStatus(true); + } + } + } + return res; } diff --git a/wmserver/test/unittest/avoid_area_controller_test.cpp b/wmserver/test/unittest/avoid_area_controller_test.cpp index 385e0e78a6..3d928abc6b 100644 --- a/wmserver/test/unittest/avoid_area_controller_test.cpp +++ b/wmserver/test/unittest/avoid_area_controller_test.cpp @@ -158,6 +158,7 @@ public: return nullptr; } void ConsumeKeyEvent(std::shared_ptr event) override {} + void NotifyForegroundInteractiveStatus(bool interactive) override {} }; void AvoidAreaControllerTest::SetUpTestCase() diff --git a/wmserver/test/unittest/window_node_test.cpp b/wmserver/test/unittest/window_node_test.cpp index 0b00d86d04..27dee58625 100644 --- a/wmserver/test/unittest/window_node_test.cpp +++ b/wmserver/test/unittest/window_node_test.cpp @@ -144,6 +144,7 @@ public: return nullptr; }; void ConsumeKeyEvent(std::shared_ptr event) override {} + void NotifyForegroundInteractiveStatus(bool interactive) override {} }; sptr CreateWindowProperty(uint32_t windowId, const std::string& windowName) -- Gitee