diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 8ed30ff621484f0083c8d9ef15d1ab26ad931518..5514bdd79d977621e520a958d59444fb5722a3eb 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/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 1cc0d3cde015fc95ada8be32362f8b3aa26e5d57..58e5a028c81195d3a72a006245e47bf1e84b81b8 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -2480,6 +2480,11 @@ struct KeyboardEffectOption : public Parcelable { KeyboardGradientMode gradientMode_ = KeyboardGradientMode::NONE; uint32_t blurHeight_ = 0; + KeyboardEffectOption() {} + KeyboardEffectOption(KeyboardViewMode viewMode, KeyboardFlowLightMode flowLightMode, + KeyboardGradientMode gradientMode, uint32_t blurHeight) + : viewMode_(viewMode), flowLightMode_(flowLightMode), gradientMode_(gradientMode), blurHeight_(blurHeight) {} + virtual bool Marshalling(Parcel& parcel) const override { return (parcel.WriteUint32(static_cast(viewMode_)) && 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 2fb9479bde113d9eaa96cbc01f47232c88285fef..8c0ee15fd188feb02e9b160d2a1e23acd9b285e5 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 8d23c8ea8b53d6e1e2d6e9bcd9641a3ff7376238..f2a9ee63cf3b97bf81ebfe71a6e0b2b52b817ddc 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/test/systemtest/wms/window_input_method_test.cpp b/test/systemtest/wms/window_input_method_test.cpp index 80cbfb76b109da789d36169d7f773a1bf9085842..3913f2890ce1e9f4b5773d46d01a6a2f34ac8cb2 100644 --- a/test/systemtest/wms/window_input_method_test.cpp +++ b/test/systemtest/wms/window_input_method_test.cpp @@ -77,11 +77,14 @@ HWTEST_F(WindowInputMethodTest, ShowKeyboard01, TestSize.Level1) .parentId = INVALID_WINDOW_ID, }; const sptr& fullWindow = Utils::CreateTestWindow(windowInfo); - ASSERT_NE(nullptr, fullWindow); + if (fullWindow == nullptr) { + return; + } + uint32_t callingWindowId = 3; KeyboardEffectOption effectOption; if (!SceneBoardJudgement::IsSceneBoardEnabled()) { sleep(TEST_SLEEP_SECOND); - ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(effectOption)); + ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(callingWindowId, effectOption)); sleep(TEST_SLEEP_SECOND); ASSERT_EQ(WMError::WM_OK, fullWindow->ChangeKeyboardEffectOption(effectOption)); sleep(TEST_SLEEP_SECOND); @@ -89,7 +92,7 @@ HWTEST_F(WindowInputMethodTest, ShowKeyboard01, TestSize.Level1) return; } effectOption.viewMode_ = KeyboardViewMode::DARK_IMMERSIVE_MODE; - ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(effectOption)); + ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(callingWindowId, effectOption)); sleep(TEST_SLEEP_SECOND); effectOption.viewMode_ = KeyboardViewMode::LIGHT_IMMERSIVE_MODE; 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..b5630b1e2143c5119813665f621d8b5f5712efcc 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_SESSION_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_SESSION_ID_CHANGE_CB, ListenerFuncType::CALLING_SESSION_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_SESSION_ID_CHANGE_CB): + ProcessCallingSessionIdChangeRegister(); + break; default: break; } @@ -7388,25 +7393,27 @@ void JsSceneSession::ProcessKeyboardStateChangeRegister() return; } session->SetKeyboardStateChangeListener( - [weakThis = wptr(this), where = __func__](SessionState state, const KeyboardEffectOption& effectOption) { + [weakThis = wptr(this), where = __func__]( + SessionState state, const KeyboardEffectOption& effectOption, uint32_t callingSessionId) { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession) { TLOGNE(WmsLogTag::WMS_KEYBOARD, "%{public}s: jsSceneSession is null", where); return; } - jsSceneSession->OnKeyboardStateChange(state, effectOption); + jsSceneSession->OnKeyboardStateChange(state, effectOption, callingSessionId); }); TLOGD(WmsLogTag::WMS_KEYBOARD, "success"); } -void JsSceneSession::OnKeyboardStateChange(SessionState state, const KeyboardEffectOption& effectOption) +void JsSceneSession::OnKeyboardStateChange(SessionState state, const KeyboardEffectOption& effectOption, + const 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_, state, env = env_, effectOption, + auto task = [weakThis = wptr(this), persistentId = persistentId_, state, env = env_, effectOption, callingSessionId, where = __func__] { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { @@ -7421,14 +7428,61 @@ void JsSceneSession::OnKeyboardStateChange(SessionState state, const KeyboardEff } napi_value jsKeyboardStateObj = CreateJsValue(env, state); napi_value jsKeyboardEffectOptionObj = ConvertKeyboardEffectOptionToJsValue(env, effectOption); - napi_value argv[] = { jsKeyboardStateObj, jsKeyboardEffectOptionObj }; + napi_value jsKeyboardCallingIdObj = CreateJsValue(env, callingSessionId); + napi_value argv[] = { jsKeyboardStateObj, jsKeyboardEffectOptionObj, jsKeyboardCallingIdObj }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); - TLOGNI(WmsLogTag::WMS_KEYBOARD, "%{public}s: id: %{public}d, state: %{public}d", where, persistentId, state); + TLOGNI(WmsLogTag::WMS_KEYBOARD, "%{public}s: id: %{public}d, state: %{public}d, callingSessionId: %{public}u", + where, persistentId, state, callingSessionId); }; taskScheduler_->PostMainThreadTask(task, "OnKeyboardStateChange, state:" + 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_SESSION_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..20a2f47ecef0da67fe9e11164b46c694f0617bab 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_SESSION_ID_CHANGE_CB, }; class SceneSession; @@ -408,6 +409,7 @@ private: void ProcessWindowMovingRegister(); void ProcessUpdateSessionLabelAndIconRegister(); void ProcessKeyboardStateChangeRegister(); + void ProcessCallingSessionIdChangeRegister(); void ProcessKeyboardEffectOptionChangeRegister(); void ProcessSetHighlightChangeRegister(); void ProcessWindowAnchorInfoChangeRegister(); @@ -495,7 +497,8 @@ private: void OnUpdateAppUseControl(ControlAppType type, bool isNeedControl, bool isControlRecentOnly); void OnWindowMoving(DisplayId displayId, int32_t pointerX, int32_t pointerY); void UpdateSessionLabelAndIcon(const std::string& label, const std::shared_ptr& icon); - void OnKeyboardStateChange(SessionState state, const KeyboardEffectOption& effectOption); + void OnKeyboardStateChange(SessionState state, const KeyboardEffectOption& effectOption, + const uint32_t callingSessionId); void OnKeyboardEffectOptionChange(const KeyboardEffectOption& effectOption); void NotifyHighlightChange(bool isHighlight); void NotifyWindowAnchorInfoChange(const WindowAnchorInfo& windowAnchorInfo); @@ -508,6 +511,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 be06d1d20e2e9c0be85223fc5470550a4945d331..0c869341c203f3702f759585500231a040cb7562 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}, @@ -545,20 +543,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]"); @@ -700,16 +684,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] { @@ -1559,9 +1533,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 bf82225a4bbc5d46603ddcfee8d1d16e6c8541ab..3a94df0b872ec851bd5d17582d2c378d4ea3db00 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, @@ -296,7 +295,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(); @@ -304,7 +302,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 a4fa5209e1a897455da29cde5457656277645731..a2dda3c08284b15e34ceae0c45673f2617b4e7b1 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() {} @@ -533,6 +535,7 @@ public: void SetAbilityToken(sptr token); sptr GetAbilityToken() const; WindowMode GetWindowMode() const; + void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); /* * Window ZOrder @@ -980,6 +983,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..b017c0db1412851b2dbcc6e6021c9190ec501a70 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()); @@ -654,9 +654,6 @@ void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid() } else { TLOGI(WmsLogTag::WMS_KEYBOARD, "Using focusedSession id: %{public}d", focusedSessionId); GetSessionProperty()->SetCallingSessionId(focusedSessionId); - if (keyboardCallback_ != nullptr && keyboardCallback_->onCallingSessionIdChange != nullptr) { - keyboardCallback_->onCallingSessionIdChange(focusedSessionId); - } } } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 4f5f1ab92cc7aa156dcbca2dd8f7cc406cb46460..030aa002f4011d7ccfc2c80c7c6adff60f14c093 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -3050,6 +3050,7 @@ void Session::UnregisterSessionChangeListeners() sessionRectChangeFunc_ = nullptr; updateSessionLabelAndIconFunc_ = nullptr; onRaiseMainWindowAboveTarget_ = nullptr; + callingSessionIdChangeFunc_ = nullptr; WLOGFD("UnregisterSessionChangeListenser, id: %{public}d", GetPersistentId()); } @@ -3111,7 +3112,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 { @@ -3945,6 +3948,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 a0eb4dd69f39ec2db5cb790fcc2b6b95cb3d8ee4..90dbc57c9818066af271f76c2d6bec6b5052f8fc 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; @@ -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); void SetFindScenePanelRsNodeByZOrderFunc(FindScenePanelRsNodeByZOrderFunc&& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; @@ -524,8 +522,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; @@ -1206,7 +1204,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 95fc5f2edc745481753f3a06edf3c9595aab6bd6..2e0a2940be04f3a72a68cbe75e9a4a3abb94412a 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -2069,7 +2069,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); }; @@ -7832,12 +7831,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"); @@ -14896,22 +14889,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"); @@ -14921,33 +14913,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}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"); @@ -14957,10 +14953,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/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 669999a745961134772d158f1abb6711727a3180..06e409d1b7ac1a22d7a59c757f745b47c700886e 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -598,8 +598,6 @@ HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, TestSize.Level1) ssm_->SetShiftFocusListener(fun); ssm_->SetSCBFocusedListener(func); ssm_->SetSCBUnfocusedListener(func); - ProcessCallingSessionIdChangeFunc func1; - ssm_->SetCallingSessionIdSessionListenser(func1); ProcessStartUIAbilityErrorFunc func2; ssm_->SetStartUIAbilityErrorListener(func2); ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession1, false, reason); diff --git a/window_scene/test/unittest/session_permission_test.cpp b/window_scene/test/unittest/session_permission_test.cpp index 0c8f1fdb9f860ac2dea65b27edf57397a1b28156..a599288a54fc9b2baa26f7b0d6a956c2909cf769 100644 --- a/window_scene/test/unittest/session_permission_test.cpp +++ b/window_scene/test/unittest/session_permission_test.cpp @@ -178,6 +178,17 @@ HWTEST_F(SessionPermissionTest, IsStartedByInputMethod, TestSize.Level1) ASSERT_EQ(false, result); } +/** + * @tc.name: IsKeyboardCallingProcess + * @tc.desc: test function : IsKeyboardCallingProcess + * @tc.type: FUNC + */ +HWTEST_F(SessionPermissionTest, IsKeyboardCallingProcess, TestSize.Level1) +{ + bool result = SessionPermission::IsKeyboardCallingProcess(1); + ASSERT_EQ(false, result); +} + /** * @tc.name: IsStartedByUIExtension * @tc.desc: test function : IsStartedByUIExtension diff --git a/window_scene/test/unittest/session_test4.cpp b/window_scene/test/unittest/session_test4.cpp index eb6e1063de3a577e9f98e95eb746950d0f1df1e1..e2915e2ccf4f248f13ca8d6ec744b9c1fee5b58d 100644 --- a/window_scene/test/unittest/session_test4.cpp +++ b/window_scene/test/unittest/session_test4.cpp @@ -774,6 +774,20 @@ HWTEST_F(WindowSessionTest4, NotifySessionInfoLockedStateChange, TestSize.Level1 WLOGFI("NotifySessionInfoLockedStateChange end!"); } +/** + * @tc.name: SetCallingSessionIdSessionListenser + * @tc.desc: SetCallingSessionIdSessionListenser Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, SetCallingSessionIdSessionListenser, TestSize.Level1) +{ + WLOGFI("SetCallingSessionIdSessionListenser begin!"); + ASSERT_NE(session_, nullptr); + ProcessCallingSessionIdChangeFunc func1; + session_->SetCallingSessionIdSessionListenser(func1); + WLOGFI("SetCallingSessionIdSessionListenser end!"); +} + /** * @tc.name: GetMainSession * @tc.desc: GetMainSession Test diff --git a/window_scene/test/unittest/window_keyboard/keyboard_session_test.cpp b/window_scene/test/unittest/window_keyboard/keyboard_session_test.cpp index 59b7d0ca434d086aaf76ca1793faaddb043a1ee9..0681633306e1745bc53d75caa5f1052f526d9270 100644 --- a/window_scene/test/unittest/window_keyboard/keyboard_session_test.cpp +++ b/window_scene/test/unittest/window_keyboard/keyboard_session_test.cpp @@ -382,7 +382,8 @@ HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid, TestSize.Leve SessionInfo info; info.abilityName_ = "UseFocusIdIfCallingSessionIdInvalid"; info.bundleName_ = "UseFocusIdIfCallingSessionIdInvalid"; - sptr specificCb = sptr::MakeSptr(); + sptr specificCb = + sptr::MakeSptr(); EXPECT_NE(specificCb, nullptr); sptr keyboardCb = sptr::MakeSptr(); @@ -397,7 +398,7 @@ HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid, TestSize.Leve EXPECT_NE(id, 0); keyboardSession->GetSessionProperty()->SetCallingSessionId(id); - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); + keyboardSession->UseFocusIdIfCallingSessionIdInvalid(id); } /** diff --git a/window_scene/test/unittest/window_keyboard/keyboard_session_test3.cpp b/window_scene/test/unittest/window_keyboard/keyboard_session_test3.cpp index 57589fee3e697848a40b0da0bf2b330be1b63fc6..be19950781193bd554ef7f2fa26acfe2425df15c 100644 --- a/window_scene/test/unittest/window_keyboard/keyboard_session_test3.cpp +++ b/window_scene/test/unittest/window_keyboard/keyboard_session_test3.cpp @@ -181,8 +181,8 @@ HWTEST_F(KeyboardSessionTest3, GetSessionScreenName01, TestSize.Level1) */ HWTEST_F(KeyboardSessionTest3, UseFocusIdIfCallingSessionIdInvalid01, TestSize.Level1) { - auto keyboardSession = - GetKeyboardSession("UseFocusIdIfCallingSessionIdInvalid01", "UseFocusIdIfCallingSessionIdInvalid01"); + auto keyboardSession = GetKeyboardSession("UseFocusIdIfCallingSessionIdInvalid01", + "UseFocusIdIfCallingSessionIdInvalid01"); ASSERT_NE(keyboardSession, nullptr); sptr keyboardCallback = sptr::MakeSptr(); @@ -200,55 +200,17 @@ HWTEST_F(KeyboardSessionTest3, UseFocusIdIfCallingSessionIdInvalid01, TestSize.L }; keyboardSession->GetSessionProperty()->SetCallingSessionId(100); - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); + keyboardSession->UseFocusIdIfCallingSessionIdInvalid(100); auto resultId = keyboardSession->GetCallingSessionId(); ASSERT_EQ(resultId, 100); - keyboardSession->GetSessionProperty()->SetCallingSessionId(101); - keyboardSession->keyboardCallback_->onGetFocusedSessionId = []() -> int32_t { return 100; }; - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); - resultId = keyboardSession->GetCallingSessionId(); - ASSERT_EQ(resultId, 100); -} - -/** - * @tc.name: UseFocusIdIfCallingSessionIdInvalid02 - * @tc.desc: test function: UseFocusIdIfCallingSessionIdInvalid - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionTest3, UseFocusIdIfCallingSessionIdInvalid02, TestSize.Level1) -{ - auto keyboardSession = GetKeyboardSession("UseFocusIdIfCallingSessionIdInvalid02", - "UseFocusIdIfCallingSessionIdInvalid02"); - sptr keyboardCallback = - new (std::nothrow) KeyboardSession::KeyboardSessionCallback(); - keyboardSession->keyboardCallback_ = keyboardCallback; - sptr sceneSession = GetSceneSession("TestSceneSession", "TestSceneSession"); - sceneSession->persistentId_ = 100; - keyboardSession->keyboardCallback_->onGetSceneSession = - [sceneSession](uint32_t callingSessionId)->sptr { - if (sceneSession->persistentId_ != callingSessionId) { - return nullptr; - } - return sceneSession; - }; - - keyboardSession->GetSessionProperty()->SetCallingSessionId(100); - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); - auto resultId = keyboardSession->GetCallingSessionId(); - EXPECT_EQ(resultId, 100); - keyboardSession->GetSessionProperty()->SetCallingSessionId(101); keyboardSession->keyboardCallback_->onGetFocusedSessionId = []()->int32_t { return 100; }; - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); + keyboardSession->UseFocusIdIfCallingSessionIdInvalid(100); resultId = keyboardSession->GetCallingSessionId(); - EXPECT_EQ(resultId, 100); - keyboardSession->keyboardCallback_->onCallingSessionIdChange = nullptr; - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); - keyboardSession->keyboardCallback_->onCallingSessionIdChange = [](int32_t callingSessionid) {}; - keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); + ASSERT_EQ(resultId, 100); } /** 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 d9282b801fb1b5b7da0298e0f0a30ff5792a8fb1..a8c578aba097be070203b4db98069af1c6810693 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; @@ -122,7 +122,8 @@ public: WMError SetTouchHotAreas(const std::vector& rects) override; WMError SetKeyboardTouchHotAreas(const KeyboardTouchHotAreas& hotAreas) override; virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override; - virtual WMError SetCallingWindow(uint32_t callingSessionId) override; + WMError SetCallingWindow(uint32_t callingSessionId) override; + WMError ChangeCallingWindowId(uint32_t callingWindowId) override; WMError ChangeKeyboardEffectOption(KeyboardEffectOption effectOption) override; virtual bool IsTransparent() const override; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 7672f2d3c8928bac64271f9d7073b5b9c5855a76..933fd183bb4e0e3c8a5f36585c631b3fb93016cf 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 c958e4bc61f39c869b551b159f49b2954378a895..e744cd8314c085fb9eef1cad2b435d484d5ef41c 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -1645,7 +1645,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) { @@ -1664,6 +1664,7 @@ WMError WindowSceneSessionImpl::ShowKeyboard(KeyboardEffectOption effectOption) effectOption.gradientMode_ = KeyboardGradientMode::NONE; } property_->SetKeyboardEffectOption(effectOption); + property_->SetCallingSessionId(callingWindowId); return Show(); } @@ -5238,10 +5239,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); } @@ -5249,6 +5257,11 @@ WMError WindowSceneSessionImpl::SetCallingWindow(uint32_t callingSessionId) return WMError::WM_OK; } +WMError WindowSceneSessionImpl::ChangeCallingWindowId(uint32_t callingWindowId) +{ + return SetCallingWindow(callingWindowId); +} + WMError WindowSceneSessionImpl::ChangeKeyboardEffectOption(KeyboardEffectOption effectOption) { TLOGI(WmsLogTag::WMS_KEYBOARD, "effect option: %{public}s", diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index cb70519a15dc86d87bcaf53cda4446a9d2e19e56..a53b7a52c1bb274f55f89106ed35dbd3d36aaca3 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -7360,23 +7360,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_test3.cpp b/wm/test/unittest/window_scene_session_impl_test3.cpp index e2d17fc949491923a5457924920a1b71222c5683..23465525413eb0f9dd7496aefa158f226dfee779 100644 --- a/wm/test/unittest/window_scene_session_impl_test3.cpp +++ b/wm/test/unittest/window_scene_session_impl_test3.cpp @@ -505,6 +505,33 @@ HWTEST_F(WindowSceneSessionImplTest3, SetCallingWindow, TestSize.Level1) EXPECT_EQ(0, windowSceneSessionImpl->property_->callingSessionId_); } +/** + * @tc.name: SetCallingWindow01 + * @tc.desc: SetCallingWindow01 + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest3, SetCallingWindow01, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("SetCallingWindow01"); + sptr windowSceneSessionImpl = sptr::MakeSptr(option); + + windowSceneSessionImpl->hostSession_ = nullptr; + auto ret = windowSceneSessionImpl->SetCallingWindow(0); + EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); + + SessionInfo sessionInfo = { "CreateTestBundle0", "CreateTestModule0", "CreateTestAbility0" }; + sptr session = sptr::MakeSptr(sessionInfo); + windowSceneSessionImpl->hostSession_ = session; + windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + windowSceneSessionImpl->property_->SetPersistentId(1); + windowSceneSessionImpl->property_->SetParentPersistentId(2); + windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; + ret = windowSceneSessionImpl->SetCallingWindow(10); + EXPECT_EQ(WMError::WM_OK, ret); + EXPECT_EQ(10, windowSceneSessionImpl->property_->callingSessionId_); +} + /** * @tc.name: RaiseToAppTop * @tc.desc: RaiseToAppTop diff --git a/wm/test/unittest/window_scene_session_impl_test5.cpp b/wm/test/unittest/window_scene_session_impl_test5.cpp index 9a5a1021c01ef40f7de1feceff05c75e8674d34e..ecd1c8d13895cb9de3cb8ff75f1c0fcbf66e91ad 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 5fc2c8c435d31f587b96194c93cc7edfd7b522a1..d43277b24924adaf984f8a53178b641712936c0a 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; }