diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 9fd097e909704705ff5219bb49427966f3c8606d..dd4fed98f6f1841b435befcb7627712ff12c1bca 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 027b3efe4a940acafd869e8cacadb93401fda9e6..7ad8865ebb868e389c39b98ce4f7ff3f4319fd16 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 a4c1e83fa9cf29c73efa1363d1cc3c1339c11e0a..e575bd7f4e789d8fb1ebf0095f31213807c06bfe 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 c44d345b4d047a22f3c8d7d3a33faf56c3f7f327..b19063672d32aeba78906c798e435dd668ea96fc 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 bd54812cdbf44cb5571abd57046b1bc29147e3c5..ad5454703ec1e31542542375c6abf6ae00d6e5f5 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 5c07d515cd4f015fdbec9cc522b999446f8f6a5c..d9579e5c140b4cd5d6c3e15fe9f4a598339b6b13 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); }