From 273b4fef0fae5c5228c2120b7e67fdfbeea8c6e4 Mon Sep 17 00:00:00 2001 From: liaoqingxing Date: Tue, 29 Jul 2025 22:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BE=93=E5=85=A5=E6=B3=95ca?= =?UTF-8?q?llingSessionId=E8=AE=BE=E7=BD=AE=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoqingxing --- interfaces/innerkits/wm/window.h | 23 ++++++--- .../window_runtime/window_napi/js_window.cpp | 8 +-- previewer/include/window.h | 1 + previewer/include/window_impl.h | 1 + previewer/src/window_impl.cpp | 5 ++ .../common/include/session_permission.h | 1 + .../common/src/session_permission.cpp | 14 +++++ .../js_scene_session.cpp | 51 +++++++++++++++++++ .../scene_session_manager/js_scene_session.h | 3 ++ .../js_scene_session_manager.cpp | 29 ----------- .../js_scene_session_manager.h | 3 -- .../session/host/include/keyboard_session.h | 2 +- window_scene/session/host/include/session.h | 6 ++- .../session/host/src/keyboard_session.cpp | 12 ++--- window_scene/session/host/src/session.cpp | 18 ++++++- .../include/scene_session_manager.h | 7 +-- .../zidl/scene_session_manager_interface.h | 4 +- .../zidl/scene_session_manager_proxy.h | 4 +- .../src/scene_session_manager.cpp | 51 ++++++++++--------- .../src/zidl/scene_session_manager_proxy.cpp | 12 ++--- .../src/zidl/scene_session_manager_stub.cpp | 20 ++++---- wm/include/root_scene.h | 1 - wm/include/window_adapter.h | 4 +- wm/include/window_impl.h | 2 +- wm/include/window_scene_session_impl.h | 2 +- wm/include/window_session_impl.h | 4 +- wm/src/root_scene.cpp | 28 ---------- wm/src/window_adapter.cpp | 8 +-- wm/src/window_impl.cpp | 2 +- wm/src/window_scene_session_impl.cpp | 15 ++++-- wm/src/window_session_impl.cpp | 10 ++-- wm/test/unittest/root_scene_test.cpp | 19 ------- .../include/zidl/window_manager_interface.h | 4 +- 33 files changed, 203 insertions(+), 171 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index fe67e9d0fd..2a89dc2b93 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -1689,6 +1689,14 @@ public: */ virtual WMError SetCallingWindow(uint32_t windowId) { return WMError::WM_OK; } + /** + * @brief Change calling window id. + * + * @param callingWindowId Window id. + * @return WM_OK means change success, others means change failed. + */ + virtual WMError ChangeCallingWindowId(uint32_t callingWindowId) { return WMError::WM_OK; } + /** * @brief Set privacy mode of window. * @@ -3798,20 +3806,22 @@ public: /** * @brief get callingWindow windowStatus. + * @param callingWindowId * @param windowStatus - * @return WM_OK means set success, others means set Failed. + * @return WM_OK means get success, others means get Failed. */ - virtual WMError GetCallingWindowWindowStatus(WindowStatus& windowStatus) const + virtual WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) const { return WMError::WM_OK; } /** - * @brief get callingWindow windowStatus + * @brief get callingWindow windowRect + * @param callingWindowId * @param rect. - * @return WM_OK means set success, others means set failed + * @return WM_OK means get success, others means get failed */ - virtual WMError GetCallingWindowRect(Rect& rect) const + virtual WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) const { return WMError::WM_OK; } @@ -4040,9 +4050,10 @@ public: * @brief Show keyboard window * * @param effectOption Keyboard will show with special effect option. + * @param callingWindowId * @return WM_OK means window show success, others means failed. */ - virtual WMError ShowKeyboard(KeyboardEffectOption effectOption) + virtual WMError ShowKeyboard(KeyboardEffectOption effectOption, uint32_t callingWindowId = 0) { return WMError::WM_OK; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 6f236931a8..fffec911e3 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -5320,14 +5320,14 @@ napi_value JsWindow::OnSetCallingWindow(napi_env env, napi_callback_info info) TLOGE(WmsLogTag::WMS_LIFE, "Argc is invalid: %{public}zu", argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } - uint32_t callingWindow = INVALID_WINDOW_ID; + uint32_t callingWindowId = INVALID_WINDOW_ID; if (errCode == WMError::WM_OK) { napi_value nativeVal = argv[0]; if (nativeVal == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to touchable"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_uint32(env, nativeVal, &callingWindow); + napi_get_value_uint32(env, nativeVal, &callingWindowId); } } @@ -5335,7 +5335,7 @@ napi_value JsWindow::OnSetCallingWindow(napi_env env, napi_callback_info info) napi_value lastParam = (argc <= 1) ? nullptr : (GetType(env, argv[1]) == napi_function ? argv[1] : nullptr); napi_value result = nullptr; std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [weakToken, callingWindow, errCode, env, task = napiAsyncTask] { + auto asyncTask = [weakToken, callingWindowId, errCode, env, task = napiAsyncTask] { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); @@ -5346,7 +5346,7 @@ napi_value JsWindow::OnSetCallingWindow(napi_env env, napi_callback_info info) task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "Invalidate params.")); return; } - WMError ret = weakWindow->SetCallingWindow(callingWindow); + WMError ret = weakWindow->SetCallingWindow(callingWindowId); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { diff --git a/previewer/include/window.h b/previewer/include/window.h index 7b159c8425..7e281f9070 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -283,6 +283,7 @@ public: virtual WMError SetBrightness(float brightness) = 0; virtual float GetBrightness() const = 0; virtual WMError SetCallingWindow(uint32_t windowId) = 0; + virtual WMError ChangeCallingWindowId(uint32_t windowId) = 0; virtual WMError SetPrivacyMode(bool isPrivacyMode) = 0; virtual bool IsPrivacyMode() const = 0; virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) = 0; diff --git a/previewer/include/window_impl.h b/previewer/include/window_impl.h index c7133b26e5..34455e4714 100644 --- a/previewer/include/window_impl.h +++ b/previewer/include/window_impl.h @@ -124,6 +124,7 @@ public: virtual WMError SetBrightness(float brightness) override; virtual float GetBrightness() const override; virtual WMError SetCallingWindow(uint32_t windowId) override; + virtual WMError ChangeCallingWindowId(uint32_t windowId) override; virtual WMError SetPrivacyMode(bool isPrivacyMode) override; virtual bool IsPrivacyMode() const override; virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override; diff --git a/previewer/src/window_impl.cpp b/previewer/src/window_impl.cpp index fd0fc0ba7d..391d5897ab 100644 --- a/previewer/src/window_impl.cpp +++ b/previewer/src/window_impl.cpp @@ -645,6 +645,11 @@ WMError WindowImpl::SetCallingWindow(uint32_t windowId) return WMError::WM_OK; } +WMError WindowImpl::ChangeCallingWindowId(uint32_t windowId) +{ + return SetCallingWindow(windowId); +} + WMError WindowImpl::SetPrivacyMode(bool isPrivacyMode) { return WMError::WM_OK; diff --git a/window_scene/common/include/session_permission.h b/window_scene/common/include/session_permission.h index ecb2fefd6a..b372c3edb7 100644 --- a/window_scene/common/include/session_permission.h +++ b/window_scene/common/include/session_permission.h @@ -40,6 +40,7 @@ public: static bool IsShellCall(); static bool IsStartByHdcd(); static bool IsStartedByInputMethod(); + static bool IsKeyboardCallingProcess(int32_t pid); static bool IsSACalling(); static bool VerifyCallingPermission(const std::string& permissionName); static bool VerifyPermissionByCallerToken(const uint32_t callerToken, const std::string& permissionName); diff --git a/window_scene/common/src/session_permission.cpp b/window_scene/common/src/session_permission.cpp index cb8e1923c4..fc09721346 100644 --- a/window_scene/common/src/session_permission.cpp +++ b/window_scene/common/src/session_permission.cpp @@ -206,6 +206,20 @@ bool SessionPermission::IsStartedByInputMethod() #endif // IMF_ENABLE } +bool SessionPermission::IsKeyboardCallingProcess(int32_t pid) +{ +#ifdef IMF_ENABLE + auto imc = MiscServices::InputMethodController::GetInstance(); + if (!imc) { + TLOGE(WmsLogTag::DEFAULT, "InputMethodController is nullptr"); + return false; + } + return imc->IsKeyboardCallingProcess(pid); +#else + return false; +#endif +} + bool SessionPermission::IsSameBundleNameAsCalling(const std::string& bundleName) { if (bundleName == "") { diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 34c14c6064..984d8e60e0 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -112,6 +112,7 @@ const std::string SET_WINDOW_SHADOWS_CB = "setWindowShadows"; const std::string SET_SUB_WINDOW_SOURCE_CB = "setSubWindowSource"; const std::string ANIMATE_TO_CB = "animateToTargetProperty"; const std::string BATCH_PENDING_SCENE_ACTIVE_CB = "batchPendingSceneSessionsActivation"; +const std::string CALLING_WINDOW_ID_CHANGE_CB = "callingWindowIdChange"; constexpr int ARG_COUNT_1 = 1; constexpr int ARG_COUNT_2 = 2; @@ -217,6 +218,7 @@ const std::map ListenerFuncMap { {FLOATING_BALL_UPDATE_CB, ListenerFuncType::FLOATING_BALL_UPDATE_CB}, {FLOATING_BALL_STOP_CB, ListenerFuncType::FLOATING_BALL_STOP_CB}, {FLOATING_BALL_RESTORE_MAIN_WINDOW_CB, ListenerFuncType::FLOATING_BALL_RESTORE_MAIN_WINDOW_CB}, + {CALLING_WINDOW_ID_CHANGE_CB, ListenerFuncType::CALLING_WINDOW_ID_CHANGE_CB}, }; const std::vector g_syncGlobalPositionPermission { @@ -3188,6 +3190,9 @@ void JsSceneSession::ProcessRegisterCallback(ListenerFuncType listenerFuncType) case static_cast(ListenerFuncType::FLOATING_BALL_RESTORE_MAIN_WINDOW_CB): ProcessFloatingBallRestoreMainWindowRegister(); break; + case static_cast(ListenerFuncType::CALLING_WINDOW_ID_CHANGE_CB): + ProcessCallingSessionIdChangeRegister(); + break; default: break; } @@ -7427,6 +7432,52 @@ void JsSceneSession::OnKeyboardStateChange(SessionState state, const KeyboardEff std::to_string(static_cast(state))); } +void JsSceneSession::ProcessCallingSessionIdChangeRegister() +{ + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "session is nullptr, id:%{public}d", persistentId_); + return; + } + session->SetCallingSessionIdSessionListenser([weakThis = wptr(this), where = __func__](uint32_t callingSessionId) { + auto jsSceneSession = weakThis.promote(); + if (!jsSceneSession) { + TLOGNE(WmsLogTag::WMS_KEYBOARD, "%{public}s: jsSceneSession is null", where); + return; + } + jsSceneSession->OnCallingSessionIdChange(callingSessionId); + }); + TLOGD(WmsLogTag::WMS_KEYBOARD, "success"); +} + +void JsSceneSession::OnCallingSessionIdChange(uint32_t callingSessionId) +{ + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGW(WmsLogTag::WMS_KEYBOARD, "session is nullptr, id:%{public}d", persistentId_); + return; + } + auto task = [weakThis = wptr(this), persistentId = persistentId_, callingSessionId, env = env_, where = __func__]() + { + auto jsSceneSession = weakThis.promote(); + if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { + TLOGNE(WmsLogTag::WMS_KEYBOARD, "OnCallingSessionIdChange jsSceneSession id:%{public}d has been destroyed", + persistentId); + return; + } + jsCallBack = jsSceneSession->GetJSCallback(CALLING_WINDOW_ID_CHANGE_CB); + if (!jsCallBack) { + TLOGNE(WmsLogTag::WMS_KEYBOARD, "jsCallBack is nullptr"); + return; + } + napi_value argv[] = { CreateJsValue(env, callingSessionId) }; + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); + TLOGNI(WmsLogTag::WMS_KEYBOARD, "%{public}s: id: %{public}d, newCallingId: %{public}d", + where, persistentId, callingSessionId); + }; + taskScheduler_->PostMainThreadTask(task, "OnCallingSessionIdChange, callingId:" + std::to_string(callingSessionId)); +} + void JsSceneSession::ProcessKeyboardEffectOptionChangeRegister() { auto session = weakSession_.promote(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index d29f92ad27..2b51c87b5e 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -112,6 +112,7 @@ enum class ListenerFuncType : uint32_t { FLOATING_BALL_UPDATE_CB, FLOATING_BALL_STOP_CB, FLOATING_BALL_RESTORE_MAIN_WINDOW_CB, + CALLING_WINDOW_ID_CHANGE_CB, }; class SceneSession; @@ -408,6 +409,7 @@ private: void ProcessWindowMovingRegister(); void ProcessUpdateSessionLabelAndIconRegister(); void ProcessKeyboardStateChangeRegister(); + void ProcessCallingSessionIdChangeRegister(); void ProcessKeyboardEffectOptionChangeRegister(); void ProcessSetHighlightChangeRegister(); void ProcessWindowAnchorInfoChangeRegister(); @@ -508,6 +510,7 @@ private: void NotifySetSubWindowSource(SubWindowSource source); void OnAnimateToTargetProperty(const WindowAnimationProperty& animationProperty, const WindowAnimationOption& animationOption); + void OnCallingSessionIdChange(uint32_t callingSessionId); /* * Window Property diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 8d645c4dbd..6fe240aed5 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -73,7 +73,6 @@ const std::string OUTSIDE_DOWN_EVENT_CB = "outsideDownEvent"; const std::string START_UI_ABILITY_ERROR = "startUIAbilityError"; const std::string ARG_DUMP_HELP = "-h"; const std::string SHIFT_FOCUS_CB = "shiftFocus"; -const std::string CALLING_WINDOW_ID_CHANGE_CB = "callingWindowIdChange"; const std::string CLOSE_TARGET_FLOAT_WINDOW_CB = "closeTargetFloatWindow"; const std::string ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB = "abilityManagerCollaboratorRegistered"; const std::string START_PIP_FAILED_CB = "startPiPFailed"; @@ -96,7 +95,6 @@ const std::map ListenerFunctionTypeMap { {STATUS_BAR_ENABLED_CHANGE_CB, ListenerFunctionType::STATUS_BAR_ENABLED_CHANGE_CB}, {OUTSIDE_DOWN_EVENT_CB, ListenerFunctionType::OUTSIDE_DOWN_EVENT_CB}, {SHIFT_FOCUS_CB, ListenerFunctionType::SHIFT_FOCUS_CB}, - {CALLING_WINDOW_ID_CHANGE_CB, ListenerFunctionType::CALLING_WINDOW_ID_CHANGE_CB}, {START_UI_ABILITY_ERROR, ListenerFunctionType::START_UI_ABILITY_ERROR}, {GESTURE_NAVIGATION_ENABLED_CHANGE_CB, ListenerFunctionType::GESTURE_NAVIGATION_ENABLED_CHANGE_CB}, @@ -539,20 +537,6 @@ void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId display taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId)); } -void JsSceneSessionManager::OnCallingSessionIdChange(uint32_t sessionId) -{ - TLOGD(WmsLogTag::WMS_KEYBOARD, "[NAPI]"); - auto task = [this, sessionId, jsCallBack = GetJSCallback(CALLING_WINDOW_ID_CHANGE_CB), env = env_]() { - if (jsCallBack == nullptr) { - TLOGNE(WmsLogTag::WMS_KEYBOARD, "jsCallBack is nullptr"); - return; - } - napi_value argv[] = { CreateJsValue(env, sessionId) }; - napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); - }; - taskScheduler_->PostMainThreadTask(task, "OnCallingSessionIdChange, sessionId:" + std::to_string(sessionId)); -} - void JsSceneSessionManager::OnAbilityManagerCollaboratorRegistered() { TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]"); @@ -694,16 +678,6 @@ void JsSceneSessionManager::ProcessShiftFocus() SceneSessionManager::GetInstance().SetSCBFocusChangeListener(std::move(scbFocusChangeCallback)); } -void JsSceneSessionManager::ProcessCallingSessionIdChangeRegister() -{ - const char* const where = __func__; - ProcessCallingSessionIdChangeFunc func = [this, where](uint32_t callingSessionId) { - TLOGND(WmsLogTag::WMS_KEYBOARD, "%{public}s called, callingSessionId: %{public}d", where, callingSessionId); - this->OnCallingSessionIdChange(callingSessionId); - }; - SceneSessionManager::GetInstance().SetCallingSessionIdSessionListenser(func); -} - void JsSceneSessionManager::ProcessAbilityManagerCollaboratorRegistered() { auto func = [this] { @@ -1545,9 +1519,6 @@ void JsSceneSessionManager::ProcessRegisterCallback(ListenerFunctionType listene case ListenerFunctionType::SHIFT_FOCUS_CB: ProcessShiftFocus(); break; - case ListenerFunctionType::CALLING_WINDOW_ID_CHANGE_CB: - ProcessCallingSessionIdChangeRegister(); - break; case ListenerFunctionType::START_UI_ABILITY_ERROR: ProcessStartUIAbilityErrorRegister(); break; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index dc45054871..e078527833 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -37,7 +37,6 @@ enum class ListenerFunctionType : uint32_t { STATUS_BAR_ENABLED_CHANGE_CB, OUTSIDE_DOWN_EVENT_CB, SHIFT_FOCUS_CB, - CALLING_WINDOW_ID_CHANGE_CB, START_UI_ABILITY_ERROR, GESTURE_NAVIGATION_ENABLED_CHANGE_CB, CLOSE_TARGET_FLOAT_WINDOW_CB, @@ -292,7 +291,6 @@ private: void OnOutsideDownEvent(int32_t x, int32_t y); void OnStartUIAbilityError(const uint32_t errorCode); void OnShiftFocus(int32_t persistentId, DisplayId displayGroupId); - void OnCallingSessionIdChange(uint32_t callingSessionId); void ProcessCreateSystemSessionRegister(); void ProcessCreateKeyboardSessionRegister(); void ProcessStatusBarEnabledChangeListener(); @@ -300,7 +298,6 @@ private: void ProcessStartUIAbilityErrorRegister(); void ProcessOutsideDownEvent(); void ProcessShiftFocus(); - void ProcessCallingSessionIdChangeRegister(); void ProcessRegisterCallback(ListenerFunctionType listenerFunctionType); bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); void RegisterDumpRootSceneElementInfoListener(); diff --git a/window_scene/session/host/include/keyboard_session.h b/window_scene/session/host/include/keyboard_session.h index 53bce41596..137bd3aef2 100644 --- a/window_scene/session/host/include/keyboard_session.h +++ b/window_scene/session/host/include/keyboard_session.h @@ -93,7 +93,7 @@ private: WSRect GetPanelRect() const; void SetCallingSessionId(uint32_t callingSessionId) override; - void UseFocusIdIfCallingSessionIdInvalid(); + void UseFocusIdIfCallingSessionIdInvalid(uint32_t callingSessionId); void NotifyKeyboardPanelInfoChange(WSRect rect, bool isKeyboardPanelShow); bool CheckIfNeedRaiseCallingSession(sptr callingSession, bool isCallingSessionFloating); WSError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index dece056242..dc25260cec 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -107,12 +107,14 @@ using UpdateTransitionAnimationFunc = std::function& icon)>; using NotifySessionGetTargetOrientationConfigInfoFunc = std::function; -using NotifyKeyboardStateChangeFunc = std::function; +using NotifyKeyboardStateChangeFunc = std::function; using NotifyHighlightChangeFunc = std::function; using NotifySurfaceBoundsChangeFunc = std::function; using HasRequestedVsyncFunc = std::function; using RequestNextVsyncWhenModeChangeFunc = std::function& vsyncCallback)>; using NotifyClearSubSessionFunc = std::function; +using ProcessCallingSessionIdChangeFunc = std::function; class ILifecycleListener { public: virtual void OnActivation() {} @@ -527,6 +529,7 @@ public: void SetAbilityToken(sptr token); sptr GetAbilityToken() const; WindowMode GetWindowMode() const; + void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); /* * Window ZOrder @@ -971,6 +974,7 @@ protected: * Keyboard Window */ NotifyKeyboardStateChangeFunc keyboardStateChangeFunc_; + ProcessCallingSessionIdChangeFunc callingSessionIdChangeFunc_; /* * Window Property diff --git a/window_scene/session/host/src/keyboard_session.cpp b/window_scene/session/host/src/keyboard_session.cpp index c239198a81..9f04c23b29 100644 --- a/window_scene/session/host/src/keyboard_session.cpp +++ b/window_scene/session/host/src/keyboard_session.cpp @@ -102,7 +102,7 @@ WSError KeyboardSession::Show(sptr property) session->NotifySystemKeyboardAvoidChange(SystemKeyboardAvoidChangeReason::KEYBOARD_SHOW); } session->GetSessionProperty()->SetKeyboardEffectOption(property->GetKeyboardEffectOption()); - session->UseFocusIdIfCallingSessionIdInvalid(); + session->UseFocusIdIfCallingSessionIdInvalid(property->GetCallingSessionId()); TLOGNI(WmsLogTag::WMS_KEYBOARD, "Show keyboard session, id: %{public}d, calling id: %{public}d, effectOption: %{public}s", session->GetPersistentId(), session->GetCallingSessionId(), @@ -225,12 +225,11 @@ void KeyboardSession::SetCallingSessionId(uint32_t callingSessionId) } session->GetSessionProperty()->SetCallingSessionId(callingSessionId); - if (session->keyboardCallback_ == nullptr || - session->keyboardCallback_->onCallingSessionIdChange == nullptr) { + if (session->callingSessionIdChangeFunc_ == nullptr) { TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardCallback_, callingSessionId: %{public}d", callingSessionId); return; } - session->keyboardCallback_->onCallingSessionIdChange(callingSessionId); + session->callingSessionIdChangeFunc_(callingSessionId); }, "SetCallingSessionId"); return; } @@ -645,9 +644,10 @@ void KeyboardSession::NotifySessionRectChange(const WSRect& rect, } // Use focused session id when calling session id is invalid. -void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid() +void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid(uint32_t callingSessionId) { - if (GetSceneSession(GetCallingSessionId()) != nullptr) { + if (callingSessionId != INVALID_WINDOW_ID && GetSceneSession(callingSessionId) != nullptr) { + GetSessionProperty()->SetCallingSessionId(callingSessionId); return; } uint32_t focusedSessionId = static_cast(GetFocusedSessionId()); diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 26030f5f94..796581fd4a 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -3011,6 +3011,7 @@ void Session::UnregisterSessionChangeListeners() sessionRectChangeFunc_ = nullptr; updateSessionLabelAndIconFunc_ = nullptr; onRaiseMainWindowAboveTarget_ = nullptr; + callingSessionIdChangeFunc_ = nullptr; WLOGFD("UnregisterSessionChangeListenser, id: %{public}d", GetPersistentId()); } @@ -3067,7 +3068,9 @@ void Session::NotifySessionStateChange(const SessionState& state) static_cast(state), session->GetPersistentId()); if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT && session->keyboardStateChangeFunc_) { - session->keyboardStateChangeFunc_(state, session->GetSessionProperty()->GetKeyboardEffectOption()); + const sptr& property = session->GetSessionProperty(); + session->keyboardStateChangeFunc_( + state, property->GetKeyboardEffectOption(), property->GetCallingSessionId()); } else if (session->sessionStateChangeFunc_) { session->sessionStateChangeFunc_(state); } else { @@ -3893,6 +3896,19 @@ void Session::SetKeyboardStateChangeListener(const NotifyKeyboardStateChangeFunc }, __func__); } +void Session::SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func) +{ + TLOGD(WmsLogTag::DEFAULT, "in"); + PostTask([weakThis = wptr(this), func, where = __func__]() { + auto session = weakThis.promote(); + if (session == nullptr || func == nullptr) { + TLOGNE(WmsLogTag::WMS_KEYBOARD, "%{public}s session or func is null", where); + return; + } + session->callingSessionIdChangeFunc_ = func; + }, __func__); +} + void Session::NotifyOccupiedAreaChangeInfo(sptr info, const std::shared_ptr& rsTransaction, const Rect& callingSessionRect, const std::map& avoidAreas) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index f1442b4d55..616d623b52 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -139,7 +139,6 @@ using CmpFunc = std::function>& lhs, using ProcessStartUIAbilityErrorFunc = std::function; using NotifySCBAfterUpdateFocusFunc = std::function; using NotifyDiffSCBAfterUpdateFocusFunc = std::function; -using ProcessCallingSessionIdChangeFunc = std::function; using FlushWindowInfoTask = std::function; using ProcessVirtualPixelRatioChangeFunc = std::function; using DumpUITreeFunc = std::function; @@ -235,7 +234,6 @@ public: void SetSCBFocusedListener(const NotifySCBAfterUpdateFocusFunc& func); void SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocusFunc& func); void SetSCBFocusChangeListener(const NotifyDiffSCBAfterUpdateFocusFunc&& func); - void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); void SetDumpUITreeFunc(const DumpUITreeFunc& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; @@ -522,8 +520,8 @@ public: void CheckSceneZOrder(); WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override; WSError GetHostGlobalScaledRect(int32_t hostWindowId, Rect& globalScaledRect) override; - WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override; - WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override; + WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) override; + WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) override; WMError GetWindowModeType(WindowModeType& windowModeType) override; WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, int32_t x, int32_t y, std::vector& windowIds) override; @@ -1196,7 +1194,6 @@ private: NotifySCBAfterUpdateFocusFunc notifySCBAfterFocusedFunc_; NotifySCBAfterUpdateFocusFunc notifySCBAfterUnfocusedFunc_; NotifyDiffSCBAfterUpdateFocusFunc notifyDiffSCBAfterUnfocusedFunc_; - ProcessCallingSessionIdChangeFunc callingSessionIdChangeFunc_; ProcessStartUIAbilityErrorFunc startUIAbilityErrorFunc_; DumpRootSceneElementInfoFunc dumpRootSceneFunc_; DumpUITreeFunc dumpUITreeFunc_; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index ca83515b0b..cc0b4b4adb 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -361,11 +361,11 @@ public: { return WSError::WS_OK; } - WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override + WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) override { return WMError::WM_OK; } - WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override + WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) override { return WMError::WM_OK; } diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index 44eb62715a..88aaeabbe0 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -126,8 +126,8 @@ public: WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override; WSError GetHostGlobalScaledRect(int32_t hostWindowId, Rect& globalScaledRect) override; WSError GetFreeMultiWindowEnableState(bool& enable) override; - WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override; - WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override; + WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) override; + WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) override; WMError MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; WMError GetWindowModeType(WindowModeType& windowModeType) override; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 2d2354198f..38653b6ac9 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -2055,7 +2055,6 @@ sptr SceneSessionManager::CreateKeyboa keyboardCb->onGetFocusedSessionId = [this] { return this->GetFocusedSessionId(); }; - keyboardCb->onCallingSessionIdChange = callingSessionIdChangeFunc_; keyboardCb->onSystemKeyboardAvoidChange = [this](DisplayId displayId, SystemKeyboardAvoidChangeReason reason) { this->HandleKeyboardAvoidChange(nullptr, displayId, reason); }; @@ -7876,12 +7875,6 @@ void SceneSessionManager::SetSCBFocusChangeListener(const NotifyDiffSCBAfterUpda notifyDiffSCBAfterUnfocusedFunc_ = std::move(func); } -void SceneSessionManager::SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func) -{ - TLOGD(WmsLogTag::DEFAULT, "in"); - callingSessionIdChangeFunc_ = func; -} - void SceneSessionManager::SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func) { TLOGD(WmsLogTag::DEFAULT, "in"); @@ -14834,22 +14827,21 @@ WindowStatus SceneSessionManager::GetWindowStatus(WindowMode mode, SessionState return windowStatus; } -WMError SceneSessionManager::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) +WMError SceneSessionManager::GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) { if (!SessionPermission::IsStartedByInputMethod()) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed persistentId: %{public}d", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed callingWindowId: %{public}d", callingWindowId); return WMError::WM_ERROR_INVALID_PERMISSION; } - auto sceneSession = GetSceneSession(persistentId); + auto sceneSession = GetSceneSession(callingWindowId); if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, persistentId: %{public}d", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, callingWindowId: %{public}d", callingWindowId); return WMError::WM_ERROR_NULLPTR; } auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusedSessionId = GetFocusedSessionId(displayId); - TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", - persistentId, sceneSession->GetWindowType()); - uint32_t callingWindowId = sceneSession->GetSessionProperty()->GetCallingSessionId(); + TLOGD(WmsLogTag::WMS_KEYBOARD, "callingWindowId: %{public}d, windowType: %{public}d", + callingWindowId, sceneSession->GetWindowType()); auto callingSession = GetSceneSession(callingWindowId); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "callingsSession is null"); @@ -14859,33 +14851,37 @@ WMError SceneSessionManager::GetCallingWindowWindowStatus(int32_t persistentId, return WMError::WM_ERROR_INVALID_WINDOW; } } + int32_t pid = callingSession->GetCallingPid(); + if (!SessionPermission::IsKeyboardCallingProcess(pid)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed callingWindowId: %{public}u", callingWindowId); + return WMError::WM_ERROR_INVALID_PERMISSION; + } if (callingSession->IsSystemSession()) { windowStatus = WindowStatus::WINDOW_STATUS_FULLSCREEN; } else { windowStatus = GetWindowStatus(callingSession->GetWindowMode(), callingSession->GetSessionState(), callingSession->GetSessionProperty()); } - TLOGI(WmsLogTag::WMS_KEYBOARD, "Get WindowStatus persistentId: %{public}d windowstatus: %{public}d", - persistentId, windowStatus); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Get WindowStatus callingWindowId: %{public}d windowstatus: %{public}d", + callingWindowId, windowStatus); return WMError::WM_OK; } -WMError SceneSessionManager::GetCallingWindowRect(int32_t persistentId, Rect& rect) +WMError SceneSessionManager::GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) { if (!SessionPermission::IsStartedByInputMethod()) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed persistentId: %{public}d", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed callingWindowId: %{public}d", callingWindowId); return WMError::WM_ERROR_INVALID_PERMISSION; } - auto sceneSession = GetSceneSession(persistentId); + auto sceneSession = GetSceneSession(callingWindowId); if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, persistentId: %{public}d", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, callingWindowId: %{public}d", callingWindowId); return WMError::WM_ERROR_NULLPTR; } auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusedSessionId = GetFocusedSessionId(displayId); - TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", - persistentId, sceneSession->GetWindowType()); - uint32_t callingWindowId = sceneSession->GetSessionProperty()->GetCallingSessionId(); + TLOGD(WmsLogTag::WMS_KEYBOARD, "callingWindowId: %{public}d, windowType: %{public}d", + callingWindowId, sceneSession->GetWindowType()); auto callingSession = GetSceneSession(callingWindowId); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "callingsSession is null"); @@ -14895,10 +14891,15 @@ WMError SceneSessionManager::GetCallingWindowRect(int32_t persistentId, Rect& re return WMError::WM_ERROR_INVALID_WINDOW; } } + int32_t pid = callingSession->GetCallingPid(); + if (!SessionPermission::IsKeyboardCallingProcess(pid)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "permission is not allowed callingWindowId: %{public}u", callingWindowId); + return WMError::WM_ERROR_INVALID_PERMISSION; + } WSRect sessionRect = callingSession->GetSessionRect(); rect = {sessionRect.posX_, sessionRect.posY_, sessionRect.width_, sessionRect.height_}; - TLOGI(WmsLogTag::WMS_KEYBOARD, "Get Rect persistentId: %{public}d, x: %{public}d, y: %{public}d, " - "height: %{public}u, width: %{public}u", persistentId, rect.posX_, rect.posY_, rect.width_, rect.height_); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Get Rect callingWindowId: %{public}d, x: %{public}d, y: %{public}d, " + "height: %{public}u, width: %{public}u", callingWindowId, rect.posX_, rect.posY_, rect.width_, rect.height_); return WMError::WM_OK; } diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index bd70df0bb4..5d39ca22bd 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -2603,7 +2603,7 @@ WSError SceneSessionManagerProxy::GetFreeMultiWindowEnableState(bool& enable) return static_cast(reply.ReadInt32()); } -WMError SceneSessionManagerProxy::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) +WMError SceneSessionManagerProxy::GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) { MessageParcel data; MessageParcel reply; @@ -2613,8 +2613,8 @@ WMError SceneSessionManagerProxy::GetCallingWindowWindowStatus(int32_t persisten TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); return WMError::WM_ERROR_IPC_FAILED; } - if (!data.WriteInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Write windowId failed"); + if (!data.WriteUint32(callingWindowId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowId failed"); return WMError::WM_ERROR_IPC_FAILED; } sptr remote = Remote(); @@ -2634,7 +2634,7 @@ WMError SceneSessionManagerProxy::GetCallingWindowWindowStatus(int32_t persisten return ret; } -WMError SceneSessionManagerProxy::GetCallingWindowRect(int32_t persistentId, Rect& rect) +WMError SceneSessionManagerProxy::GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) { MessageParcel data; MessageParcel reply; @@ -2643,8 +2643,8 @@ WMError SceneSessionManagerProxy::GetCallingWindowRect(int32_t persistentId, Rec TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); return WMError::WM_ERROR_IPC_FAILED; } - if (!data.WriteInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Write windowId failed"); + if (!data.WriteUint32(callingWindowId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowId failed"); return WMError::WM_ERROR_IPC_FAILED; } sptr remote = Remote(); diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index fe7264d675..2ace48ab85 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -1610,16 +1610,16 @@ int SceneSessionManagerStub::HandleGetFreeMultiWindowEnableState(MessageParcel& int SceneSessionManagerStub::HandleGetCallingWindowWindowStatus(MessageParcel&data, MessageParcel&reply) { TLOGD(WmsLogTag::WMS_KEYBOARD, "In!"); - int32_t persistentId; - if (!data.ReadInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "read persistentId failed"); + uint32_t callingWindowId; + if (!data.ReadUint32(callingWindowId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "read callingWindowId failed"); return ERR_INVALID_DATA; } WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED; - WMError ret = GetCallingWindowWindowStatus(persistentId, windowStatus); + WMError ret = GetCallingWindowWindowStatus(callingWindowId, windowStatus); reply.WriteUint32(static_cast(ret)); if (ret != WMError::WM_OK) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowWindowStatus(%{public}d)", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowWindowStatus(%{public}d)", callingWindowId); return ERR_INVALID_DATA; } reply.WriteUint32(static_cast(windowStatus)); @@ -1629,16 +1629,16 @@ int SceneSessionManagerStub::HandleGetCallingWindowWindowStatus(MessageParcel&da int SceneSessionManagerStub::HandleGetCallingWindowRect(MessageParcel&data, MessageParcel& reply) { TLOGD(WmsLogTag::WMS_KEYBOARD, "In!"); - int32_t persistentId; - if (!data.ReadInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "read persistentId failed"); + uint32_t callingWindowId; + if (!data.ReadUint32(callingWindowId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "read callingWindowId failed"); return ERR_INVALID_DATA; } Rect rect = {0, 0, 0, 0}; - WMError ret = GetCallingWindowRect(persistentId, rect); + WMError ret = GetCallingWindowRect(callingWindowId, rect); reply.WriteInt32(static_cast(ret)); if (ret != WMError::WM_OK) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowRect(%{public}d)", persistentId); + TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowRect(%{public}d)", callingWindowId); return ERR_INVALID_DATA; } reply.WriteInt32(rect.posX_); diff --git a/wm/include/root_scene.h b/wm/include/root_scene.h index a8f995de9e..6e132bdc19 100644 --- a/wm/include/root_scene.h +++ b/wm/include/root_scene.h @@ -88,7 +88,6 @@ public: */ WMError RegisterOccupiedAreaChangeListener(const sptr& listener) override; WMError UnregisterOccupiedAreaChangeListener(const sptr& listener) override; - void NotifyOccupiedAreaChangeForRoot(const sptr& info); /* * watch diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 56ad8d2c97..2fdc77acba 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -135,8 +135,8 @@ public: virtual WMError GetHostWindowRect(int32_t hostWindowId, Rect& rect); virtual WMError GetHostGlobalScaledRect(int32_t hostWindowId, Rect& globalScaledRect); virtual WMError GetFreeMultiWindowEnableState(bool& enable); - virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus); - virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect); + virtual WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus); + virtual WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect); virtual WMError GetWindowModeType(WindowModeType& windowModeType); virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType); virtual WMError SkipSnapshotForAppProcess(int32_t pid, bool skip); diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index f9a3295f69..e67c4d1d7d 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -373,7 +373,7 @@ public: /* * Keyboard */ - WMError ShowKeyboard(KeyboardEffectOption effectOption) override; + WMError ShowKeyboard(KeyboardEffectOption effectOption, uint32_t callingWindowId) override; /* * RS Client Multi Instance diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 9f039e2218..94157a01ea 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -33,7 +33,7 @@ public: bool isModuleAbilityHookEnd = false) override; WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) override; WMError Show(uint32_t reason, bool withAnimation, bool withFocus, bool waitAttach) override; - WMError ShowKeyboard(KeyboardEffectOption effectOption) override; + WMError ShowKeyboard(KeyboardEffectOption effectOption, uint32_t callingWindowId) override; WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits, bool waitDetach) override; WMError Destroy(bool needNotifyServer, bool needClearListener = true, uint32_t reason = 0) override; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index d55936e2a5..ac9c72a795 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -431,8 +431,8 @@ public: const sptr& listener) override; WMError UnregisterExtensionSecureLimitChangeListener( const sptr& listener) override; - virtual WMError GetCallingWindowWindowStatus(WindowStatus& windowStatus) const override; - virtual WMError GetCallingWindowRect(Rect& rect) const override; + virtual WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) const override; + virtual WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) const override; virtual void SetUiDvsyncSwitch(bool dvsyncSwitch) override; virtual void SetTouchEvent(int32_t touchType) override; WMError SetContinueState(int32_t continueState) override; diff --git a/wm/src/root_scene.cpp b/wm/src/root_scene.cpp index ee8a5ec140..252f91d074 100644 --- a/wm/src/root_scene.cpp +++ b/wm/src/root_scene.cpp @@ -465,34 +465,6 @@ WMError RootScene::UnregisterOccupiedAreaChangeListener(const sptr& info) -{ - if (info == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "occupied area info is null"); - return; - } - if (handler_ == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "handler_ is null, notify occupied area for root failed."); - return; - } - TLOGI(WmsLogTag::WMS_KEYBOARD, "occupiedRect: %{public}s, textField PositionY_: %{public}f, Height_: %{public}f", - info->rect_.ToString().c_str(), info->textFieldPositionY_, info->textFieldHeight_); - auto task = [weak = wptr(this), info]() { - auto window = weak.promote(); - if (!window) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "window is null"); - return; - } - std::lock_guard lock(window->occupiedAreaMutex_); - for (const auto& listener : window->occupiedAreaChangeListeners_) { - if (listener != nullptr) { - listener->OnSizeChange(info); - } - } - }; - handler_->PostTask(task, __func__); -} - void RootScene::RegisterNotifyWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeCallback&& callback) { notifyWatchFocusActiveChangeCallback_ = std::move(callback); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 633ea7a8b2..deaee8f15e 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -1044,22 +1044,22 @@ WMError WindowAdapter::GetFreeMultiWindowEnableState(bool& enable) return static_cast(wmsProxy->GetFreeMultiWindowEnableState(enable)); } -WMError WindowAdapter::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) +WMError WindowAdapter::GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) { INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING); - return static_cast(wmsProxy->GetCallingWindowWindowStatus(persistentId, windowStatus)); + return static_cast(wmsProxy->GetCallingWindowWindowStatus(callingWindowId, windowStatus)); } -WMError WindowAdapter::GetCallingWindowRect(int32_t persistentId, Rect& rect) +WMError WindowAdapter::GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) { INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING); - return static_cast(wmsProxy->GetCallingWindowRect(persistentId, rect)); + return static_cast(wmsProxy->GetCallingWindowRect(callingWindowId, rect)); } WMError WindowAdapter::GetWindowModeType(WindowModeType& windowModeType) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 72ed14ee17..1137735474 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1931,7 +1931,7 @@ WMError WindowImpl::Show(uint32_t reason, bool withAnimation, bool withFocus, bo return ret; } -WMError WindowImpl::ShowKeyboard(KeyboardEffectOption effectOption) +WMError WindowImpl::ShowKeyboard(KeyboardEffectOption effectOption, uint32_t callingWindowId) { return Show(); } diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 41f3868a07..73a6954d43 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -1667,7 +1667,7 @@ sptr WindowSceneSessionImpl::GetDisplayInfo() const return display->GetDisplayInfo(); } -WMError WindowSceneSessionImpl::ShowKeyboard(KeyboardEffectOption effectOption) +WMError WindowSceneSessionImpl::ShowKeyboard(KeyboardEffectOption effectOption, uint32_t callingWindowId) { TLOGI(WmsLogTag::WMS_KEYBOARD, "Effect option: %{public}s", effectOption.ToString().c_str()); if (effectOption.viewMode_ >= KeyboardViewMode::VIEW_MODE_END) { @@ -5279,10 +5279,17 @@ WMError WindowSceneSessionImpl::SetCallingWindow(uint32_t callingSessionId) TLOGE(WmsLogTag::WMS_KEYBOARD, "session is invalid!"); return WMError::WM_ERROR_INVALID_WINDOW; } - if (callingSessionId != property_->GetCallingSessionId()) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "from %{public}d to: %{public}d", - property_->GetCallingSessionId(), callingSessionId); + WindowType type = GetType(); + uint32_t curCallingSessionId = property_->GetCallingSessionId(); + // only for the following conditions + if (type != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || callingSessionId == curCallingSessionId || + state_ != WindowState::STATE_SHOWN) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "set calling window id failed, type: %{public}d, newId: %{public}u," + " state: %{public}d", type, callingSessionId, state_); + return WMError::WM_ERROR_INVALID_OPERATION; } + TLOGI(WmsLogTag::WMS_KEYBOARD, "id: %{public}d, curId: %{public}u, newId: %{public}u", + property_->GetPersistentId(), curCallingSessionId, callingSessionId); if (auto hostSession = GetHostSession()) { hostSession->SetCallingSessionId(callingSessionId); } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index b299f1c93a..2a95e91351 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -7257,23 +7257,23 @@ bool WindowSessionImpl::IsHorizontalOrientation(Orientation orientation) const orientation == Orientation::USER_ROTATION_LANDSCAPE_INVERTED; } -WMError WindowSessionImpl::GetCallingWindowWindowStatus(WindowStatus& windowStatus) const +WMError WindowSessionImpl::GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) const { - TLOGD(WmsLogTag::WMS_KEYBOARD, "id: %{public}d", GetPersistentId()); + TLOGD(WmsLogTag::WMS_KEYBOARD, "callingWindowId: %{public}d", callingWindowId); if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::WMS_KEYBOARD, "session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - return SingletonContainer::Get().GetCallingWindowWindowStatus(GetPersistentId(), windowStatus); + return SingletonContainer::Get().GetCallingWindowWindowStatus(callingWindowId, windowStatus); } -WMError WindowSessionImpl::GetCallingWindowRect(Rect& rect) const +WMError WindowSessionImpl::GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) const { if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::WMS_KEYBOARD, "session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - return SingletonContainer::Get().GetCallingWindowRect(GetPersistentId(), rect); + return SingletonContainer::Get().GetCallingWindowRect(callingWindowId, rect); } void WindowSessionImpl::SetUiDvsyncSwitch(bool dvsyncSwitch) diff --git a/wm/test/unittest/root_scene_test.cpp b/wm/test/unittest/root_scene_test.cpp index 86faccfc60..e9ac93bf43 100644 --- a/wm/test/unittest/root_scene_test.cpp +++ b/wm/test/unittest/root_scene_test.cpp @@ -544,25 +544,6 @@ HWTEST_F(RootSceneTest, UnregisterOccupiedAreaChangeListener, TestSize.Level1) ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret); } -/** - * @tc.name: NotifyOccupiedAreaChangeForRoot - * @tc.desc: NotifyOccupiedAreaChangeForRoot Test - * @tc.type: FUNC - */ -HWTEST_F(RootSceneTest, NotifyOccupiedAreaChangeForRoot, TestSize.Level1) -{ - auto rootScene = sptr::MakeSptr(); - sptr listener = sptr::MakeSptr(); - ASSERT_NE(nullptr, listener); - auto ret = rootScene->RegisterOccupiedAreaChangeListener(listener); - ASSERT_EQ(WMError::WM_OK, ret); - sptr info = nullptr; - rootScene->NotifyOccupiedAreaChangeForRoot(info); - info = sptr::MakeSptr(); - ASSERT_NE(nullptr, info); - rootScene->NotifyOccupiedAreaChangeForRoot(info); -} - /** * @tc.name: GetRSNodeByStringIDTest * @tc.desc: For GetRSNodeByStringID Test diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 464112e2c8..956a9406e7 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -256,11 +256,11 @@ public: return WSError::WS_OK; } virtual WSError GetFreeMultiWindowEnableState(bool& enable) { return WSError::WS_OK; } - virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) + virtual WMError GetCallingWindowWindowStatus(uint32_t callingWindowId, WindowStatus& windowStatus) { return WMError::WM_OK; } - virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) + virtual WMError GetCallingWindowRect(uint32_t callingWindowId, Rect& rect) { return WMError::WM_OK; } -- Gitee