diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 3575de6218cca62a2cb8eda88a2ea1407d1f384e..602fed09fa345e8ac998a2ff5e524237bce8a894 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -1690,6 +1690,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. * @@ -3799,20 +3807,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,10 +4050,12 @@ public: /** * @brief Show keyboard window * + * @param callingWindowId the id of calling window. * @param effectOption Keyboard will show with special effect option. * @return WM_OK means window show success, others means failed. */ - virtual WMError ShowKeyboard(KeyboardEffectOption effectOption) + virtual WMError ShowKeyboard(uint32_t callingWindowId, KeyboardEffectOption effectOption + = { KeyboardViewMode::NON_IMMERSIVE_MODE, KeyboardFlowLightMode::NONE, KeyboardGradientMode::NONE, 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 45109c824aed85a7195b8e62219e76a5d453d4ca..c54b7c031b627a2d5300159e014b380065643cdf 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -5430,14 +5430,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); } } @@ -5445,7 +5445,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"); @@ -5456,7 +5456,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 15364944f91ac19ad6dad4e06bb68c92f2f031b5..ad1f26467c3b270d282a922c4d1c5d8b98fd6aea 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 c7133b26e5026a55ee9fa3dc9a6f6e305d3aa493..34455e471444de41adb955e9799026b92c0c12d1 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 fd0fc0ba7da920258c1a4420c20773b4e7b61f78..391d5897ab384e148a394d3f806778457b5d979c 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 303d9ea88973cd8371c103496b49b240c0b99ab1..de086562cdd01fe5782f8bac1b390e9e1916db70 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 d23d13c6b5238819d1919029f5c478200cd96137..84aac433dc65cf031bb2b059c461b071b8dcba71 100644 --- a/window_scene/common/src/session_permission.cpp +++ b/window_scene/common/src/session_permission.cpp @@ -205,6 +205,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 af238015367bbde8348c4c62871e8dad9b800fef..383c1257e0d36926cf1b39a04d92d69f0927d37f 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 { @@ -3190,6 +3192,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; } @@ -7429,6 +7434,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; + } + auto 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 d29f92ad27edf8fcd8e0fdc0213a1a50fad67473..2b51c87b5efce64f5fdcaeb9105020ac42125eab 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 db4969cc9933a8488e20c8ce02e4c6128e91cf22..4144b23b26336ac66449d71ae2cbd01cddaf2cd8 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}, @@ -543,20 +541,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]"); @@ -698,16 +682,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] { @@ -1557,9 +1531,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 e23b26c71536b350c1a0f5d580e1a36fb093d5a6..b6b48123ce5fcd4f5479107f9a57063af9226ca4 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, @@ -295,7 +294,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(); @@ -303,7 +301,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 53bce415961dc7b8581ef313dd01670fae235b39..137bd3aef26e4cc6cafeb27132211d548a317654 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 e5d8b434d18de9a7b586a0d0425f112717de8d8b..b646952b0d152dc9ca1e84199acdce4234f5dd80 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -109,12 +109,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() {} @@ -532,6 +534,7 @@ public: void SetAbilityToken(sptr token); sptr GetAbilityToken() const; WindowMode GetWindowMode() const; + void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); /* * Window ZOrder @@ -979,6 +982,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 75b6f456513cb7be7421bfec0c7dca9956cc9973..c4330371ad9b3d66a1c716f9ed9fd7058013b8a8 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; } @@ -643,9 +642,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 6ffc70102535f3220ba93ea1eee9d406543a590f..1b50993e1adc67f776a18a853511586fa9ec014c 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -3045,6 +3045,7 @@ void Session::UnregisterSessionChangeListeners() sessionRectChangeFunc_ = nullptr; updateSessionLabelAndIconFunc_ = nullptr; onRaiseMainWindowAboveTarget_ = nullptr; + callingSessionIdChangeFunc_ = nullptr; WLOGFD("UnregisterSessionChangeListenser, id: %{public}d", GetPersistentId()); } @@ -3106,7 +3107,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 { @@ -3937,6 +3940,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 b2f57be65acc8da40165ccc40460d803d118b5df..8958f42ce802821f1093ab94e8de4f9a9cb8a8fd 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -137,7 +137,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; @@ -233,7 +232,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; @@ -521,8 +519,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; @@ -1199,7 +1197,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 4b9ffc7271ad8c09fc6d48df46aabe9cd1241be8..ace6f93a19ad11d89d77362f016a6be11eb7d51f 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 @@ -366,11 +366,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 7e97bb0fd9d84065f9c5315399a79176c344812a..2417f67d9daf8b2407923db82a08e219f556b115 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 5d3c2cb9535712d0fea40fa41a46e22dedc15020..be988c0e22c943e25acbb44806423ee07d04db2b 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -2056,7 +2056,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); }; @@ -7801,12 +7800,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"); @@ -14847,22 +14840,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}u", 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}u", 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}u, windowType: %{public}d", + callingWindowId, sceneSession->GetWindowType()); auto callingSession = GetSceneSession(callingWindowId); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "callingsSession is null"); @@ -14872,33 +14864,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"); @@ -14908,10 +14904,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}u, 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 cae8eb38fac14ca0cf0983e4d9bfffb1001e9a3b..1cb1ef13452e643a569f6d6bfbaad7ac008bf840 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 @@ -2637,7 +2637,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; @@ -2647,8 +2647,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(); @@ -2668,7 +2668,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; @@ -2677,8 +2677,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 aab739f17e2ebaf1204c7296904c84dcd9715bb1..d39d30736d07f109335b50d0ff3cfb6c86479ac2 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 @@ -1634,16 +1634,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}u)", callingWindowId); return ERR_INVALID_DATA; } reply.WriteUint32(static_cast(windowStatus)); @@ -1653,16 +1653,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}u)", callingWindowId); return ERR_INVALID_DATA; } reply.WriteInt32(rect.posX_); diff --git a/wm/include/root_scene.h b/wm/include/root_scene.h index a8f995de9ee3ca68e6d6ed95cb1496ae12a82e89..6e132bdc1939dd03745ca39fb48359ef1e5659e7 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 4f511464dd06b7a721398996fa8f857913983e22..de8e2a920ff0ee46a3d6adf4b4b29b75fcfbef41 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -136,8 +136,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 f9a3295f69a8137b63569fad4e2243899c257704..96333ba48d472ed9d5000989c1b2263d4c427f66 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(uint32_t callingWindowId, KeyboardEffectOption effectOption) override; /* * RS Client Multi Instance diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 16a6b36097043d9b1bac3b60f562c063867f314b..de746b43a9f75271e901fd0bd10acdc096c780f5 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -34,7 +34,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(uint32_t callingWindowId, KeyboardEffectOption effectOption) 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 6f578ce4f9a967fc52e116baa234e2c7ec7a200e..37c0875ae3272d9fe14288bad9510779c75fad14 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -439,8 +439,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 29a84543e8c6fb3ed9d9790148847fc401ec09e3..8bca43ec037c9432077bf57904522bd2c2eec986 100644 --- a/wm/src/root_scene.cpp +++ b/wm/src/root_scene.cpp @@ -460,34 +460,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 7af0715572464da15914331f4db715545e4912c6..6088e503e84648b2d6208e9abab663c4c208d9a8 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -1071,22 +1071,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 72ed14ee176f49548a473a884c74ef84f7bd1822..7c65247a3510bd5f58c61cfb8a3678696b17fccd 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(uint32_t callingWindowId, KeyboardEffectOption effectOption) { return Show(); } diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 117d76fb874a8b204641918ec31c1dd321e452ca..6feb64629876059f22b659c7ed24b1c604def79a 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -1673,7 +1673,7 @@ sptr WindowSceneSessionImpl::GetDisplayInfo() const return display->GetDisplayInfo(); } -WMError WindowSceneSessionImpl::ShowKeyboard(KeyboardEffectOption effectOption) +WMError WindowSceneSessionImpl::ShowKeyboard(uint32_t callingWindowId, KeyboardEffectOption effectOption) { TLOGI(WmsLogTag::WMS_KEYBOARD, "Effect option: %{public}s", effectOption.ToString().c_str()); if (effectOption.viewMode_ >= KeyboardViewMode::VIEW_MODE_END) { @@ -5266,10 +5266,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 0a62e589d2cc30f11efbb8515e2c212a03c8090d..ccbffaae3e106f466de7cb433ef9f4009be846d9 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -7364,23 +7364,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 2bdcab5fb9362b1d7745d991046b1f9dc4456129..6015e538933075791543c0aca3e20fa119a3de93 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/wm/test/unittest/window_scene_session_impl_test5.cpp b/wm/test/unittest/window_scene_session_impl_test5.cpp index 31187be9f832604b987c04e39e2b5d07ba167cb9..53cea3bb0964d1f20bbdb18bfb62dc6e39c6a353 100644 --- a/wm/test/unittest/window_scene_session_impl_test5.cpp +++ b/wm/test/unittest/window_scene_session_impl_test5.cpp @@ -688,13 +688,13 @@ HWTEST_F(WindowSceneSessionImplTest5, ShowKeyboard01, TestSize.Level1) effectOption.flowLightMode_ = KeyboardFlowLightMode::BACKGROUND_FLOW_LIGHT; effectOption.gradientMode_ = KeyboardGradientMode::LINEAR_GRADIENT; // normal value - ASSERT_EQ(keyboardWindow->ShowKeyboard(effectOption), WMError::WM_ERROR_INVALID_WINDOW); + ASSERT_EQ(keyboardWindow->ShowKeyboard(1000, effectOption), WMError::WM_ERROR_INVALID_WINDOW); effectOption.viewMode_ = KeyboardViewMode::VIEW_MODE_END; effectOption.flowLightMode_ = KeyboardFlowLightMode::END; effectOption.gradientMode_ = KeyboardGradientMode::END; // exception value - ASSERT_EQ(keyboardWindow->ShowKeyboard(effectOption), WMError::WM_ERROR_INVALID_WINDOW); + ASSERT_EQ(keyboardWindow->ShowKeyboard(1000, effectOption), WMError::WM_ERROR_INVALID_WINDOW); auto lastOption = keyboardWindow->property_->GetKeyboardEffectOption(); ASSERT_EQ(lastOption.viewMode_, KeyboardViewMode::NON_IMMERSIVE_MODE); } diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index 118a6eb5496c0e0ff2d280fbbb264030b31cd87b..b5608a58c6be352aa2dec9f0b3d3bd331c3e5d56 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -871,14 +871,14 @@ HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, TestSize.Level1) option->SetWindowName("GetCallingWindowRect"); sptr window = sptr::MakeSptr(option); Rect rect = { 0, 0, 0, 0 }; - WMError retCode = window->GetCallingWindowRect(rect); + WMError retCode = window->GetCallingWindowRect(1, rect); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->state_ = WindowState::STATE_CREATED; - window->GetCallingWindowRect(rect); + window->GetCallingWindowRect(1, rect); } /** @@ -893,7 +893,7 @@ HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, TestSize.Level1) sptr window = sptr::MakeSptr(option); ASSERT_NE(nullptr, window); WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED; - WMError retCode = window->GetCallingWindowWindowStatus(windowStatus); + WMError retCode = window->GetCallingWindowWindowStatus(1, windowStatus); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; @@ -901,7 +901,7 @@ HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, TestSize.Level1) ASSERT_NE(nullptr, session); window->hostSession_ = session; window->state_ = WindowState::STATE_CREATED; - window->GetCallingWindowWindowStatus(windowStatus); + window->GetCallingWindowWindowStatus(1, windowStatus); } /** diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index b3ae63912f4c152a0b05a7a6cf2d39ff950e7ba1..a1d37df4b46dcfdc09ef5bc4623a4b54b86a58ae 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -260,11 +260,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; }