diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 666d1731534fd87738912ec58d0666081bfb5533..e2dfa7df73369ae1982357190c5a91a61efb8388 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -193,6 +193,21 @@ public: virtual void OnWindowStyleUpdate(WindowStyleType styleType) = 0; }; +/** + * @class IKeyboardCallingWindowDisplayChangeListener + * + * @brief Observe the display change of keyboard callingWindow. + */ +class IKeyboardCallingWindowDisplayChangeListener : virtual public RefBase { +public: + /** + * @brief Notify caller when calling window display changed. + * + * @param callingWindowInfo The information about the calling window. + */ + virtual void OnCallingWindowDisplayChanged(CallingWindowInfo callingWindowInfo) = 0; +}; + /** * @class IWindowPidVisibilityChangedListener * @@ -920,6 +935,30 @@ public: */ WMError UnregisterWindowStyleChangedListener(const sptr& listener); + /** + * @brief Register keyboard calling window display change listener. + * + * @param listener IKeyboardCallingWindowDisplayChangeListener + * @return WM_OK means register success, others means unregister failed. + */ + WMError RegisterCallingWindowDisplayChangeListener( + const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + + /** + * @brief Unregister keyboard calling window display change listener. + * + * @param listener IKeyboardCallingWindowDisplayChangeListener + * @return WM_OK means unregister success, others means unregister failed. + */ + WMError UnregisterCallingWindowDisplayChangeListener( + const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + /** * @brief Skip Snapshot for app process. * @@ -1054,6 +1093,7 @@ private: void NotifyGestureNavigationEnabledResult(bool enable) const; void UpdateVisibleWindowNum(const std::vector& visibleWindowNumInfo); WMError NotifyWindowStyleChange(WindowStyleType type); + WMError NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo); void NotifyWindowPidVisibilityChanged(const sptr& info) const; }; } // namespace Rosen diff --git a/interfaces/innerkits/wm/window_manager_lite.h b/interfaces/innerkits/wm/window_manager_lite.h index 14c7c6b40e5fc8be6c985dc98274400ba2edcedc..839a009586d38e04b5ce4f58c3f48111e3f68a7c 100644 --- a/interfaces/innerkits/wm/window_manager_lite.h +++ b/interfaces/innerkits/wm/window_manager_lite.h @@ -154,6 +154,14 @@ public: */ WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo); + /** + * @brief Get keyboard calling window info. + * + * @param callingWindowInfo calling window info + * @return WM_OK means get success, others means get failed. + */ + WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo); + /** * @brief Get all main window info. * @@ -222,6 +230,24 @@ public: */ WMError UnregisterWindowStyleChangedListener(const sptr& listener); + /** + * @brief Register keyboard calling window display change listener. + * + * @param listener IKeyboardCallingWindowDisplayChangeListener + * @return WM_OK means register success, others means unregister failed. + */ + WMError RegisterCallingWindowDisplayChangeListener( + const sptr& listener); + + /** + * @brief Unregister keyboard calling window display change listener. + * + * @param listener IKeyboardCallingWindowDisplayChangeListener + * @return WM_OK means unregister success, others means unregister failed. + */ + WMError UnregisterCallingWindowDisplayChangeListener( + const sptr& listener); + /** * @brief Get window style type. * @@ -325,6 +351,7 @@ private: WMError NotifyWindowStyleChange(WindowStyleType type); void NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type) const; + WMError NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo); }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 23b7885550a9ea8cc45dee2eab07b6caf594f7c6..c24ce1108fc5bd8ffa76bcb16d0c3ca0120606aa 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -939,6 +939,40 @@ struct KeyboardPanelInfo : public Parcelable { } }; +/** + * @struct CallingWindowInfo + * + * @brief Info of keyboard calling window + */ +struct CallingWindowInfo : public Parcelable { + int32_t windowId_ = 0; + int32_t callingPid_ = -1; + DisplayId displayId_ = 0; + int32_t userId_ = 0; + + CallingWindowInfo() {} + CallingWindowInfo(int32_t windowId, int32_t callingPid, DisplayId displayId, int32_t userId) + : windowId_(windowId), callingPid_(callingPid), displayId_(displayId), userId_(userId) {} + + bool Marshalling(Parcel& parcel) const + { + return parcel.WriteInt32(windowId_) && parcel.WriteInt32(callingPid_) && + parcel.WriteUint64(displayId_) && parcel.WriteInt32(userId_); + } + + static CallingWindowInfo* Unmarshalling(Parcel& parcel) + { + CallingWindowInfo* callingWindowInfo = new CallingWindowInfo(); + bool res = parcel.ReadInt32(callingWindowInfo->windowId_) && parcel.ReadInt32(callingWindowInfo->callingPid_) && + parcel.ReadUint64(callingWindowInfo->displayId_) && parcel.ReadInt32(callingWindowInfo->userId_); + if (!res) { + delete callingWindowInfo; + return nullptr; + } + return callingWindowInfo; + } +}; + /** * @brief Enumerates avoid area type. */ diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index c17491dd4755c7612f5f58945680946d2625f6fc..00e09dbdeaa3848e448961320ba5d57dad3d71dc 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -609,6 +609,7 @@ public: int32_t StartUIAbilityBySCB(sptr& abilitySessionInfo); int32_t StartUIAbilityBySCB(sptr& sceneSessions); WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo); + WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo); WMError GetAllMainWindowInfos(std::vector& infos) const; WMError ClearMainSessions(const std::vector& persistentIds, std::vector& clearFailedIds); WMError TerminateSessionByPersistentId(int32_t persistentId); diff --git a/window_scene/session_manager/include/scene_session_manager_lite.h b/window_scene/session_manager/include/scene_session_manager_lite.h index 0344a2b55aed0e3c54625bd8c54be8092125a953..2729d586a3f98a3ef4821654796f928e0127bd41 100644 --- a/window_scene/session_manager/include/scene_session_manager_lite.h +++ b/window_scene/session_manager/include/scene_session_manager_lite.h @@ -83,6 +83,7 @@ public: WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock) override; WMError HasFloatingWindowForeground(const sptr& abilityToken, bool& hasOrNot) override; + WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) override; }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/session_manager_agent_controller.h b/window_scene/session_manager/include/session_manager_agent_controller.h index 0e4a06a87eab31108d885df6bd171e16d4593cf1..8fdbf542931f98989198038a9a8f2f266e3855b2 100644 --- a/window_scene/session_manager/include/session_manager_agent_controller.h +++ b/window_scene/session_manager/include/session_manager_agent_controller.h @@ -47,6 +47,7 @@ public: void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing); void NotifyGestureNavigationEnabledResult(bool enable); void NotifyWindowStyleChange(WindowStyleType type); + void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo); void NotifyWindowPidVisibilityChanged(const sptr& info); void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground); diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h index fc488ac4e2198d1ab0ca9c478afc8d4e74c58550..e87b77490b4c53cb271894b5c9967350590e2270 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h @@ -86,6 +86,7 @@ public: TRANS_ID_MINIMIZE_MAIN_SESSION, TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO, TRANS_ID_HAS_FLOAT_FOREGROUND, + TRANS_ID_GET_CALLING_WINDOW_INFO, }; /* diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h index 117a325f0c8d45e0af6df459b39788d2f9bce709..fecc8177c423c78410938cba2f386dcc9007ed44 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h @@ -73,6 +73,7 @@ public: WMError GetVisibilityWindowInfo(std::vector>& infos) override; WMError GetWindowModeType(WindowModeType& windowModeType) override; WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) override; + WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) override; WMError GetAllMainWindowInfos(std::vector& infos) override; WMError ClearMainSessions(const std::vector& persistentIds, std::vector& clearFailedIds) override; WSError RaiseWindowToTop(int32_t persistentId) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h index be33ba7416199997ef96e92f557b02357df66480..3fc7d34602e5fcaf0f8f7ab9b1e25a4cd2832453 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h @@ -63,6 +63,7 @@ private: int HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply); int HandleGetWindowModeType(MessageParcel& data, MessageParcel& reply); int HandleGetMainWinodowInfo(MessageParcel& data, MessageParcel& reply); + int HandleGetCallingWindowInfo(MessageParcel& data, MessageParcel& reply); int HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply); int HandleClearMainSessions(MessageParcel& data, MessageParcel& reply); int HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index e7339c99fa51d3c200e1edba8227f8586bdbf34b..95fb8eb10c48bcf63eabf9ecb9c563ddf992eae1 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -10373,6 +10373,20 @@ WSError SceneSessionManager::UpdateSessionDisplayId(int32_t persistentId, uint64 NotifySessionUpdate(sceneSession->GetSessionInfo(), ActionType::MOVE_DISPLAY, fromScreenId); sceneSession->NotifyDisplayMove(fromScreenId, screenId); sceneSession->UpdateDensity(); + + const auto& keyboardSessionVec = GetSceneSessionVectorByType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + for (const auto& keyboardSession : keyboardSessionVec) { + if (keyboardSession) { + TLOGD(WmsLogTag::WMS_KEYBOARD, "isSystemKeyboard: %{public}d, callingSessionId: %{public}d", + keyboardSession->IsSystemKeyboard(), keyboardSession->GetCallingSessionId()); + } + if (keyboardSession && !keyboardSession->IsSystemKeyboard() && + static_cast(keyboardSession->GetCallingSessionId()) == persistentId) { + CallingWindowInfo callingWindowInfo(persistentId, sceneSession->GetCallingPid(), screenId, GetUserIdByUid(getuid())); + SessionManagerAgentController::GetInstance().NotifyCallingWindowDisplayChanged(callingWindowInfo); + break; + } + } return WSError::WS_OK; } @@ -12140,6 +12154,26 @@ WMError SceneSessionManager::GetMainWindowInfos(int32_t topNum, std::vector
GetCallingPid(); + callingWindowInfo.displayId_ = sceneSession->GetSessionProperty()->GetDisplayId(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "callingWindow id: %{public}d,pid: %{public}d,displayId: %{public}" PRIu64" , curUserId: %{public}d", + callingWindowInfo.windowId_, callingWindowInfo.callingPid_, callingWindowInfo.displayId_, curUserId); + return WMError::WM_OK; +} + WMError SceneSessionManager::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, int32_t x, int32_t y, std::vector& windowIds) { diff --git a/window_scene/session_manager/src/scene_session_manager_lite.cpp b/window_scene/session_manager/src/scene_session_manager_lite.cpp index e97ed30f31370b3c41fc711fbc054d6a98de02eb..9c0ba6faa562e3b3ad4c6e0a633d49baa2263798 100644 --- a/window_scene/session_manager/src/scene_session_manager_lite.cpp +++ b/window_scene/session_manager/src/scene_session_manager_lite.cpp @@ -217,6 +217,11 @@ WMError SceneSessionManagerLite::GetMainWindowInfos(int32_t topNum, std::vector< return SceneSessionManager::GetInstance().GetMainWindowInfos(topNum, topNInfo); } +WMError SceneSessionManagerLite::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) +{ + return SceneSessionManager::GetInstance().GetCallingWindowInfo(callingWindowInfo); +} + WMError SceneSessionManagerLite::GetAllMainWindowInfos(std::vector& infos) { return SceneSessionManager::GetInstance().GetAllMainWindowInfos(infos); diff --git a/window_scene/session_manager/src/session_manager_agent_controller.cpp b/window_scene/session_manager/src/session_manager_agent_controller.cpp index 1ef677777be51265f126b3a773a77d6b2fb41203..e721a20f94179ed64bf987e2cb301af3d8433b22 100644 --- a/window_scene/session_manager/src/session_manager_agent_controller.cpp +++ b/window_scene/session_manager/src/session_manager_agent_controller.cpp @@ -228,6 +228,19 @@ void SessionManagerAgentController::NotifyWindowStyleChange(WindowStyleType type } } +void SessionManagerAgentController::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + TLOGD(WmsLogTag::WMS_KEYBOARD, + "notify userId: %{public}d, displayId: %{public}d, persistentId: %{public}d", + callingWindowInfo.userId_, static_cast(callingWindowInfo.displayId_), callingWindowInfo.windowId_); + for (const auto& agent : smAgentContainer_.GetAgentsByType( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY)) { + if (agent != nullptr) { + agent->NotifyCallingWindowDisplayChanged(callingWindowInfo); + } + } +} + void SessionManagerAgentController::NotifyWindowPidVisibilityChanged( const sptr& info) { diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 803b001c11935dd97ff3e18611654330bb123702..fa58dbfe39b897d226027d43562aedf9a81cc40e 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -1048,6 +1048,40 @@ WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::ve return static_cast(reply.ReadInt32()); } +WMError SceneSessionManagerLiteProxy::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(callingWindowInfo.windowId_) || !data.WriteInt32(callingWindowInfo.userId_)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "persistentId and userId write failed, id: %{public}d, userId: %{public}d", + callingWindowInfo.windowId_, callingWindowInfo.userId_); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(SceneSessionManagerLiteMessage::TRANS_ID_GET_CALLING_WINDOW_INFO), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + auto ret = static_cast(reply.ReadInt32()); + if (ret == WMError::WM_OK) { + callingWindowInfo.windowId_ = reply.ReadInt32(); + callingWindowInfo.callingPid_ = reply.ReadInt32(); + callingWindowInfo.displayId_ = reply.ReadUint64(); + callingWindowInfo.userId_ = reply.ReadInt32(); + } + return ret; +} + WSError SceneSessionManagerLiteProxy::RegisterIAbilityManagerCollaborator(int32_t type, const sptr& impl) { diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp index 92ff36763dfeb27dd08959092778700f1f32dd9f..a2ee20b9a69e1b2aee9ec4cd87659aba3679ef26 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp @@ -135,6 +135,8 @@ int SceneSessionManagerLiteStub::ProcessRemoteRequest(uint32_t code, MessageParc return HandleHasFloatingWindowForeground(data, reply); case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO): return HandleLockSessionByAbilityInfo(data, reply); + case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_GET_CALLING_WINDOW_INFO): + return HandleGetCallingWindowInfo(data, reply); default: WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -696,6 +698,31 @@ int SceneSessionManagerLiteStub::HandleGetMainWinodowInfo(MessageParcel& data, M return ERR_NONE; } +int SceneSessionManagerLiteStub::HandleGetCallingWindowInfo(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_KEYBOARD, "In"); + int32_t persistentId; + int32_t userId; + if (!data.ReadInt32(persistentId) || !data.ReadInt32(userId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Read persistentId and userId failed."); + return ERR_INVALID_DATA; + } + CallingWindowInfo callingWindowInfo; + callingWindowInfo.windowId_ = persistentId; + callingWindowInfo.userId_ = userId; + WMError ret = GetCallingWindowInfo(callingWindowInfo); + if (ret != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "id: %{public}d, failed to get calling window info", persistentId); + return ERR_INVALID_DATA; + } + reply.WriteInt32(static_cast(ret)); + reply.WriteInt32(callingWindowInfo.windowId_); + reply.WriteInt32(callingWindowInfo.callingPid_); + reply.WriteUint64(callingWindowInfo.displayId_); + reply.WriteInt32(callingWindowInfo.userId_); + return ERR_NONE; +} + int SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply) { std::vector infos; diff --git a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp index 4721c84e56bf27d592b1da86e1b42898449ab65e..1628c47a770f9d69a7afca3793c574c46d95f82b 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp @@ -146,6 +146,10 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub { infos.push_back(mainWindowInfo); return WMError::WM_OK; } + WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) override + { + return WMError::WM_OK; + } WMError ClearMainSessions(const std::vector& persistentIds, std::vector& clearFailedIds) override { diff --git a/wm/include/window_adapter_lite.h b/wm/include/window_adapter_lite.h index 85e052f600e5e557eee4290e92ff1f2fb7abb95e..6fbfcd2fa4f0b56b2540ad1fc1ce815e89310db4 100644 --- a/wm/include/window_adapter_lite.h +++ b/wm/include/window_adapter_lite.h @@ -47,6 +47,7 @@ public: virtual WMError GetWindowModeType(WindowModeType& windowModeType); virtual WMError RaiseWindowToTop(int32_t persistentId); virtual WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo); + virtual WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo); WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); virtual WMError GetAllMainWindowInfos(std::vector& infos); virtual WMError ClearMainSessions(const std::vector& persistentIds); diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h index 8b21346c8b6c28a8e971a89eff5fc5a4585d2f56..5f8a3a5cb70f370a33928a23756ad7e4ed18ba9e 100644 --- a/wm/include/window_manager_agent.h +++ b/wm/include/window_manager_agent.h @@ -40,9 +40,10 @@ public: void NotifyGestureNavigationEnabledResult(bool enable) override; void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) override {}; void NotifyWindowStyleChange(WindowStyleType type) override; + void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) override {}; void NotifyWindowPidVisibilityChanged(const sptr& info) override; void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) override {} }; } // namespace Rosen } // namespace OHOS -#endif // OHOS_WINDOW_MANAGER_AGENT_H +#endif // OHOS_WINDOW_MANAGER_AGENT_H \ No newline at end of file diff --git a/wm/include/window_manager_agent_lite.h b/wm/include/window_manager_agent_lite.h index 37a7fab7696103823a5ad7793a63669c0bc473c6..baa4a98447d2dce5216376e5be75ea8fe828f268 100644 --- a/wm/include/window_manager_agent_lite.h +++ b/wm/include/window_manager_agent_lite.h @@ -40,6 +40,7 @@ public: void NotifyGestureNavigationEnabledResult(bool enable) override {}; void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) override; void NotifyWindowStyleChange(WindowStyleType type) override; + void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) override; void NotifyWindowPidVisibilityChanged(const sptr& info) override {}; void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) override; }; diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h index ed46d948432052af9728dbbfe4d7e81b1f84e6c7..cbedaa767c7e1c04fb86d7259d99f0cd7059ceac 100644 --- a/wm/include/zidl/window_manager_agent_interface.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -37,6 +37,7 @@ enum class WindowManagerAgentType : uint32_t { WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY, WINDOW_MANAGER_AGENT_TYPE_PIP, + WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, WINDOW_MANAGER_AGENT_TYPE_END, }; @@ -59,6 +60,7 @@ public: TRANS_ID_UPDATE_WINDOW_STYLE_TYPE, TRANS_ID_NOTIFY_WINDOW_PID_VISIBILITY, TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED, + TRANS_ID_NOTIFY_CALLING_DISPLAY_CHANGE, }; virtual void UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) = 0; @@ -75,6 +77,7 @@ public: virtual void NotifyGestureNavigationEnabledResult(bool enable) = 0; virtual void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) = 0; virtual void NotifyWindowStyleChange(WindowStyleType type) = 0; + virtual void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) = 0; virtual void NotifyWindowPidVisibilityChanged(const sptr& info) = 0; virtual void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) = 0; }; diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h index 20885b62a6234133568c20ee2c4e19109c064378..1116d1527e4be4e52170e1fb298617fdf477671c 100644 --- a/wm/include/zidl/window_manager_agent_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -41,6 +41,7 @@ public: void NotifyGestureNavigationEnabledResult(bool enable) override; void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) override; void NotifyWindowStyleChange(WindowStyleType type) override; + void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) override; void NotifyWindowPidVisibilityChanged(const sptr& info) override; void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) override; diff --git a/wm/src/window_adapter_lite.cpp b/wm/src/window_adapter_lite.cpp index 5c8574417062069ad0b582a501b256e6dd5a5a40..b1f6b90fcaf2e629d3f49cc2cd4e3f03918cb8c5 100644 --- a/wm/src/window_adapter_lite.cpp +++ b/wm/src/window_adapter_lite.cpp @@ -229,6 +229,16 @@ WMError WindowAdapterLite::GetMainWindowInfos(int32_t topNum, std::vectorGetMainWindowInfos(topNum, topNInfo); } +WMError WindowAdapterLite::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + TLOGD(WmsLogTag::WMS_KEYBOARD, "get calling window info"); + + auto wmsProxy = GetWindowManagerServiceProxy(); + CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); + return wmsProxy->GetCallingWindowInfo(callingWindowInfo); +} + WMError WindowAdapterLite::GetAllMainWindowInfos(std::vector& infos) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index fec4c9740bb295ae9dfb2b80f25229e96cdade38..68cc5c67d7493dd988236f9dc1889226eeafddca 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -97,6 +97,8 @@ public: std::vector>> displayInfoChangedListeners_; std::vector> windowPidVisibilityListeners_; sptr windowPidVisibilityListenerAgent_; + std::vector> callingDisplayChangedListeners_; + sptr callingDisplayListenerAgent_; }; void WindowManager::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId) @@ -1232,6 +1234,11 @@ WMError WindowManager::NotifyWindowStyleChange(WindowStyleType type) return WMError::WM_OK; } +WMError NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; +} + WMError WindowManager::RegisterDrawingContentChangedListener(const sptr& listener) { if (listener == nullptr) { diff --git a/wm/src/window_manager_agent_lite.cpp b/wm/src/window_manager_agent_lite.cpp index df0825c8261072903b18945e137ef354474b73e7..1afd779885e3bcbfe932b67063060d12ae434ac8 100644 --- a/wm/src/window_manager_agent_lite.cpp +++ b/wm/src/window_manager_agent_lite.cpp @@ -52,6 +52,11 @@ void WindowManagerAgentLite::NotifyWindowStyleChange(WindowStyleType type) SingletonContainer::Get().NotifyWindowStyleChange(type); } +void WindowManagerAgentLite::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + SingletonContainer::Get().NotifyCallingWindowDisplayChanged(callingWindowInfo); +} + void WindowManagerAgentLite::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) { SingletonContainer::Get().UpdatePiPWindowStateChanged(bundleName, isForeground); diff --git a/wm/src/window_manager_lite.cpp b/wm/src/window_manager_lite.cpp index 2a0274eccb263047fe1bcd032655e6f290ac210a..4e00fa5df9382343e90e47c835ce539d4f0c86ec 100644 --- a/wm/src/window_manager_lite.cpp +++ b/wm/src/window_manager_lite.cpp @@ -49,6 +49,7 @@ public: void NotifyWMSConnected(int32_t userId, int32_t screenId); void NotifyWMSDisconnected(int32_t userId, int32_t screenId); void NotifyWindowStyleChange(WindowStyleType type); + void NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo); void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground); void NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type); @@ -73,6 +74,8 @@ public: sptr windowStyleListenerAgent_; std::vector> pipStateChangedListeners_; sptr pipStateChangedListenerAgent_; + std::vector> callingDisplayChangedListeners_; + sptr callingDisplayListenerAgent_; }; void WindowManagerLite::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId) @@ -258,6 +261,28 @@ void WindowManagerLite::Impl::NotifyWindowStyleChange(WindowStyleType type) } } +void WindowManagerLite::Impl::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + std::vector> displayChangeListeners; + { + std::lock_guard lock(mutex_); + displayChangeListeners = callingDisplayChangedListeners_; + } + + TLOGI(WmsLogTag::WMS_KEYBOARD, "notify userId: %{public}d, displayId: %{public}" PRIu64 + " ,persistentId: %{public}d, num: %{public}" PRIu32" ", + callingWindowInfo.userId_, callingWindowInfo.displayId_, + callingWindowInfo.windowId_, static_cast(callingDisplayChangedListeners_.size())); + + for (const auto& listener : callingDisplayChangedListeners_) { + if (!listener) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "listener is nullptr"); + continue; + } + listener->OnCallingWindowDisplayChanged(callingWindowInfo); + } +} + void WindowManagerLite::Impl::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) { std::vector> pipStateChangedListeners; @@ -645,6 +670,11 @@ WMError WindowManagerLite::GetMainWindowInfos(int32_t topNum, std::vector().GetMainWindowInfos(topNum, topNInfo); } +WMError WindowManagerLite::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) +{ + return SingletonContainer::Get().GetCallingWindowInfo(callingWindowInfo); +} + WMError WindowManagerLite::RegisterWMSConnectionChangedListener(const sptr& listener) { int32_t clientUserId = GetUserIdByUid(getuid()); @@ -725,6 +755,12 @@ WMError WindowManagerLite::NotifyWindowStyleChange(WindowStyleType type) return WMError::WM_OK; } +WMError WindowManagerLite::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + pImpl_->NotifyCallingWindowDisplayChanged(callingWindowInfo); + return WMError::WM_OK; +} + WMError WindowManagerLite::RegisterWindowStyleChangedListener(const sptr& listener) { TLOGI(WmsLogTag::WMS_MAIN, "start register windowStyleChangedListener"); @@ -787,6 +823,73 @@ WMError WindowManagerLite::UnregisterWindowStyleChangedListener(const sptr& listener) +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "start register callingDisplayChangeListener"); + if (listener == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "listener could not be null"); + return WMError::WM_ERROR_NULLPTR; + } + { + std::lock_guard lock(pImpl_->mutex_); + if (pImpl_->callingDisplayListenerAgent_ == nullptr) { + pImpl_->callingDisplayListenerAgent_ = new WindowManagerAgentLite(); + } + auto iter = std::find(pImpl_->callingDisplayChangedListeners_.begin(), + pImpl_->callingDisplayChangedListeners_.end(), listener); + if (iter != pImpl_->callingDisplayChangedListeners_.end()) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "listener is already registered"); + return WMError::WM_OK; + } + pImpl_->callingDisplayChangedListeners_.emplace_back(listener); + } + WMError ret = WMError::WM_OK; + ret = SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); + if (ret != WMError::WM_OK) { + TLOGW(WmsLogTag::WMS_KEYBOARD, "Register agent failed!"); + std::lock_guard lock(pImpl_->mutex_); + pImpl_->callingDisplayListenerAgent_ = nullptr; + auto iter = std::find(pImpl_->callingDisplayChangedListeners_.begin(), + pImpl_->callingDisplayChangedListeners_.end(), listener); + if (iter != pImpl_->callingDisplayChangedListeners_.end()) { + pImpl_->callingDisplayChangedListeners_.erase(iter); + } + } + return ret; +} + +WMError WindowManagerLite::UnregisterCallingWindowDisplayChangeListener( + const sptr& listener) +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "start unRegister callingDisplayChangeListener"); + if (listener == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "listener could not be null"); + return WMError::WM_ERROR_NULLPTR; + } + { + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->callingDisplayChangedListeners_.begin(), + pImpl_->callingDisplayChangedListeners_.end(), listener); + if (iter == pImpl_->callingDisplayChangedListeners_.end()) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "could not find this listener"); + return WMError::WM_OK; + } + pImpl_->callingDisplayChangedListeners_.erase(iter); + } + WMError ret = WMError::WM_OK; + if (pImpl_->callingDisplayChangedListeners_.empty() && pImpl_->callingDisplayListenerAgent_ != nullptr) { + ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); + if (ret == WMError::WM_OK) { + std::lock_guard lock(pImpl_->mutex_); + pImpl_->callingDisplayListenerAgent_ = nullptr; + } + } + return ret; +} + WindowStyleType WindowManagerLite::GetWindowStyleType() { WindowStyleType styleType; diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp index cdacca9865d419192b6b700e20e2a3c6c00747a3..b1f6d88a19f5a3a75ef6e48a3936dc993beaf446 100644 --- a/wm/src/zidl/window_manager_agent_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -381,6 +381,31 @@ void WindowManagerAgentProxy::NotifyWindowStyleChange(WindowStyleType type) } } +void WindowManagerAgentProxy::NotifyCallingWindowDisplayChanged(const CallingWindowInfo& callingWindowInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); + return; + } + if (!data.WriteParcelable(&callingWindowInfo)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowInfo failed"); + return; + } + + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null"); + return; + } + if (remote->SendRequest(static_cast(WindowManagerAgentMsg::TRANS_ID_NOTIFY_CALLING_DISPLAY_CHANGE), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest calling display info change failed"); + } +} + void WindowManagerAgentProxy::NotifyWindowPidVisibilityChanged(const sptr& info) { MessageParcel data; diff --git a/wm/src/zidl/window_manager_agent_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp index 39bea2a1dcdfac854efe8643312d267895ffb553..f44435f62618f25d6e76e9522fae2c7814f828c9 100644 --- a/wm/src/zidl/window_manager_agent_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -192,6 +192,15 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, UpdatePiPWindowStateChanged(bundleName, isForeground); break; } + case WindowManagerAgentMsg::TRANS_ID_NOTIFY_CALLING_DISPLAY_CHANGE: { + sptr callingWindowInfo = data.ReadParcelable(); + if (callingWindowInfo == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "callingWindowInfo is nullptr!"); + return ERR_INVALID_VALUE; + } + NotifyCallingWindowDisplayChanged(*callingWindowInfo); + break; + } default: WLOGFW("unknown transaction code %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/wmserver/include/zidl/window_manager_lite_interface.h b/wmserver/include/zidl/window_manager_lite_interface.h index a88866d40149fa0c78f86aa21c625953de529bf8..a375b867a45a8229699c8a4dcac857e68e4f58f5 100644 --- a/wmserver/include/zidl/window_manager_lite_interface.h +++ b/wmserver/include/zidl/window_manager_lite_interface.h @@ -44,6 +44,7 @@ public: AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid) = 0; virtual WMError GetWindowModeType(WindowModeType& windowModeType) { return WMError::WM_OK; } virtual WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) = 0; + virtual WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) = 0; virtual WMError GetAllMainWindowInfos(std::vector& infos) = 0; virtual WMError ClearMainSessions(const std::vector& persistentIds, std::vector& clearFailedIds) = 0;