From 8ad6d5b3c06c45038ab75a802f19294ddf6fba99 Mon Sep 17 00:00:00 2001 From: w00574628 Date: Fri, 19 Jan 2024 19:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86SetSessionGravity=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1=E4=B8=8E=E5=B0=86RequestHi?= =?UTF-8?q?deKeyboard=E4=BB=BB=E5=8A=A1=E7=94=B1=E5=87=BA=E5=8F=A3?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wulehui --- .../session/host/include/scene_session.h | 2 +- window_scene/session/host/include/session.h | 5 ++++- .../session/host/src/scene_session.cpp | 21 ++++++++++++++----- window_scene/session/host/src/session.cpp | 18 +++++++++++++++- .../src/scene_session_manager.cpp | 15 ++++--------- wm/src/window_session_impl.cpp | 3 ++- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 9fd097e909..dd4fed98f6 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -144,7 +144,7 @@ public: void NotifyPiPWindowPrepareClose() override; WSError RecoveryPullPiPMainWindow(int32_t persistentId, const Rect& rect) override; void SetScale(float scaleX, float scaleY, float pivotX, float pivotY) override; - void RequestHideKeyboard(); + void RequestHideKeyboard(bool isAppColdStart = false); WSError ProcessPointDownSession(int32_t posX, int32_t posY) override; WSError SendPointEventForMoveDrag(const std::shared_ptr& pointerEvent) override; void NotifyOutsideDownEvent(const std::shared_ptr& pointerEvent); diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 027b3efe4a..7ad8865ebb 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -100,7 +100,8 @@ public: explicit Session(const SessionInfo& info); virtual ~Session() = default; - void SetEventHandler(const std::shared_ptr& handler); + void SetEventHandler(const std::shared_ptr& handler, + const std::shared_ptr& exportHandler = nullptr); WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, @@ -394,6 +395,7 @@ protected: void HandlePointDownDialog(int32_t pointAction); void PostTask(Task&& task, const std::string& name = "sessionTask", int64_t delayTime = 0); + void PostExportTask(Task&& task, const std::string& name = "sessionExportTask", int64_t delayTime = 0); template> Return PostSyncTask(SyncTask&& task, const std::string& name = "sessionTask") { @@ -516,6 +518,7 @@ private: std::vector> lifecycleListeners_; sptr windowEventChannel_; std::shared_ptr handler_; + std::shared_ptr exportHandler_; mutable std::shared_mutex propertyMutex_; sptr property_; diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index a4c1e83fa9..e575bd7f4e 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -2296,13 +2296,24 @@ void SceneSession::SetScale(float scaleX, float scaleY, float pivotX, float pivo } } -void SceneSession::RequestHideKeyboard() +void SceneSession::RequestHideKeyboard(bool isAppColdStart) { #ifdef IMF_ENABLE - WLOGFI("Notify InputMethod framework hide keyboard, id: %{public}d", Session::GetPersistentId()); - if (MiscServices::InputMethodController::GetInstance()) { - MiscServices::InputMethodController::GetInstance()->RequestHideInput(); - } + auto task = [weakThis = wptr(this), isAppColdStart]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("[WMSInput] Session is null, notify inputMethod framework hide keyboard failed!"); + return; + } + WLOGFI("[WMSInput] Notify inputMethod framework hide keyboard start, id: %{public}d," + "isAppColdStart: %{public}d", session->GetPersistentId(), isAppColdStart); + if (MiscServices::InputMethodController::GetInstance()) { + MiscServices::InputMethodController::GetInstance()->RequestHideInput(); + WLOGFI("[WMSInput] Notify inputMethod framework hide keyboard end, id: %{public}d", + session->GetPersistentId()); + } + }; + PostExportTask(task, "RequestHideKeyboard"); #endif } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index c44d345b4d..b19063672d 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -63,9 +63,11 @@ Session::Session(const SessionInfo& info) : sessionInfo_(info) } } -void Session::SetEventHandler(const std::shared_ptr& handler) +void Session::SetEventHandler(const std::shared_ptr& handler, + const std::shared_ptr& exportHandler) { handler_ = handler; + exportHandler_ = exportHandler; } void Session::PostTask(Task&& task, const std::string& name, int64_t delayTime) @@ -81,6 +83,20 @@ void Session::PostTask(Task&& task, const std::string& name, int64_t delayTime) handler_->PostTask(std::move(localTask), "wms:" + name, delayTime, AppExecFwk::EventQueue::Priority::IMMEDIATE); } +void Session::PostExportTask(Task&& task, const std::string& name, int64_t delayTime) +{ + if (!exportHandler_ || exportHandler_->GetEventRunner()->IsCurrentRunnerThread()) { + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "s:%s", name.c_str()); + return task(); + } + auto localTask = [task, name]() { + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "s:%s", name.c_str()); + task(); + }; + exportHandler_->PostTask(std::move(localTask), "wms:" + name, delayTime, + AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + int32_t Session::GetPersistentId() const { return persistentId_; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index bd54812cdb..ad5454703e 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -974,7 +974,7 @@ sptr SceneSessionManager::RequestSceneSession(const SessionInfo& s WLOGFD("[WMSLife] RequestSceneSession, synchronous screenId with displayid %{public}" PRIu64"", sessionInfo.screenId_); } - sceneSession->SetEventHandler(taskScheduler_->GetEventHandler()); + sceneSession->SetEventHandler(taskScheduler_->GetEventHandler(), eventHandler_); if (sessionInfo.isSystem_) { sceneSession->SetCallingPid(IPCSkeleton::GetCallingRealPid()); sceneSession->SetCallingUid(IPCSkeleton::GetCallingUid()); @@ -1255,15 +1255,7 @@ void SceneSessionManager::RequestInputMethodCloseKeyboard(const int32_t persiste return; } if (!sceneSession->IsSessionValid()) { -#ifdef IMF_ENABLE - WLOGFI("[WMSInput] When the app is cold-started, Notify InputMethod framework close keyboard"); - if (MiscServices::InputMethodController::GetInstance()) { - int32_t ret = MiscServices::InputMethodController::GetInstance()->RequestHideInput(); - if (ret != 0) { // 0 - NO_ERROR - WLOGFE("[WMSInput] InputMethod framework close keyboard failed, ret: %{public}d", ret); - } - } -#endif + sceneSession->RequestHideKeyboard(true); } } @@ -5172,7 +5164,8 @@ WSError SceneSessionManager::SetSessionGravity(int32_t persistentId, SessionGrav } return WSError::WS_OK; }; - return taskScheduler_->PostSyncTask(task, "SetSessionGravity" + std::to_string(persistentId)); + taskScheduler_->PostAsyncTask(task, "SetSessionGravity" + std::to_string(persistentId)); + return WSError::WS_OK; } void SceneSessionManager::RelayoutKeyBoard(sptr sceneSession) diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 5c07d515cd..d9579e5c14 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1446,9 +1446,10 @@ static void RequestInputMethodCloseKeyboard(bool isNeedKeyboard, bool keepKeyboa { if (!isNeedKeyboard && !keepKeyboardFlag) { #ifdef IMF_ENABLE - WLOGFI("[WMSInput] Notify InputMethod framework close keyboard"); + WLOGFI("[WMSInput] Notify InputMethod framework close keyboard start."); if (MiscServices::InputMethodController::GetInstance()) { int32_t ret = MiscServices::InputMethodController::GetInstance()->RequestHideInput(); + WLOGFI("[WMSInput] Notify InputMethod framework close keyboard end."); if (ret != 0) { // 0 - NO_ERROR WLOGFE("[WMSInput] InputMethod framework close keyboard failed, ret: %{public}d", ret); } -- Gitee