diff --git a/utils/include/perform_reporter.h b/utils/include/perform_reporter.h index 248d22d17a29ca846fd4d3aa8fbeeca7585701bf..d5ccbd619f93df269367af0ac577e69a03f0bc9f 100644 --- a/utils/include/perform_reporter.h +++ b/utils/include/perform_reporter.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "wm_single_instance.h" namespace OHOS { @@ -47,6 +48,33 @@ struct WindowProfileInfo { int32_t windowSceneMode = -1; }; +enum class KeyboardLifeCycleException { + ANIM_SYNC_EXCEPTION, + CREATE_EXCEPTION, +}; + +const std::map KEYBOARD_LIFE_CYCLE_EXCEPTION_MAP = { + {KeyboardLifeCycleException::ANIM_SYNC_EXCEPTION, "ANIM_SYNC_EXCEPTION"}, + {KeyboardLifeCycleException::CREATE_EXCEPTION, "CREATE_EXCEPTION"} +}; + +struct WindowLifeCycleReportInfo { + std::string bundleName; + int32_t windowId; + int32_t windowType; + int32_t windowMode; + int32_t windowFlag; + std::string timeoutStage; + + inline std::string ToString() const + { + std::stringstream ss; + ss << "[bundleName:" << bundleName << ", id:" << windowId << ", type:" << windowType << ", windowMode:" << + windowMode << ", flag:" << windowFlag << "]"; + return ss.str(); + } +}; + class PerformReporter { public: PerformReporter(const std::string& tag, const std::vector& timeSpiltsMs, uint32_t reportInterval = 50); @@ -94,6 +122,9 @@ public: int32_t ReportUIExtensionException(int32_t exceptionType, int32_t pid, int32_t persistentId, const std::string& uiextInfo); int32_t ReportEventDispatchException(int32_t exceptionType, int32_t pid, const std::string& flushInfo); + int32_t ReportKeyboardLifeCycleException(int32_t windowId, KeyboardLifeCycleException subType, + const std::string& msg); + int32_t ReportSpecWindowLifeCycleChange(WindowLifeCycleReportInfo reportInfo); private: void UpdateReportInfo(FullInfoMap& infoMap, const std::string& bundleName, diff --git a/utils/src/perform_reporter.cpp b/utils/src/perform_reporter.cpp index 02a4236dee40f832637433172ac4f68f3e4539f3..7a8661f0f46406750aa422e00132b7bcc2bbfe99 100644 --- a/utils/src/perform_reporter.cpp +++ b/utils/src/perform_reporter.cpp @@ -360,5 +360,39 @@ int32_t WindowInfoReporter::ReportEventDispatchException(int32_t exceptionType, } return ret; } + +int32_t WindowInfoReporter::ReportKeyboardLifeCycleException(int32_t windowId, KeyboardLifeCycleException subType, + const std::string& msg) +{ + std::string eventName = "KEYBOARD_LIFE_CYCLE_EXCEPTION"; + int32_t ret = HiSysEventWrite( + HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, eventName, + HiviewDFX::HiSysEvent::EventType::FAULT, + "WINDOW_ID", windowId, + "SUB_TYPE", KEYBOARD_LIFE_CYCLE_EXCEPTION_MAP.at(subType), + "MSG", msg); + if (ret != 0) { + TLOGE(WmsLogTag::DEFAULT, "write HiSysEvent error, ret: %{public}d", ret); + } + return ret; +} + +int32_t WindowInfoReporter::ReportSpecWindowLifeCycleChange(WindowLifeCycleReportInfo reportInfo) +{ + std::string eventName = "SPEC_WINDOW_LIFE_CYCLE_CHANGE"; + int32_t ret = HiSysEventWrite( + HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, eventName, + HiviewDFX::HiSysEvent::EventType::FAULT, + "BUNDLE_NAME", reportInfo.bundleName, + "WINDOW_ID", reportInfo.windowId, + "WINDOW_TYPE", reportInfo.windowType, + "WINDOW_MODE", reportInfo.windowMode, + "WINDOW_FLAG", reportInfo.windowFlag, + "STAGE", reportInfo.timeoutStage); + if (ret != 0) { + TLOGE(WmsLogTag::DEFAULT, "write HiSysEvent error, ret: %{public}d", ret); + } + return ret; +} } // namespace Rosen } \ No newline at end of file diff --git a/utils/test/unittest/perform_reporter_test.cpp b/utils/test/unittest/perform_reporter_test.cpp index 23dad34dc607cf1d2486ebfc0d99e41432b04153..7d4e1d43d4941b29dd9395b081b5d1bf83dac274 100644 --- a/utils/test/unittest/perform_reporter_test.cpp +++ b/utils/test/unittest/perform_reporter_test.cpp @@ -19,6 +19,7 @@ #include "input_manager.h" #include "perform_reporter.h" #include "window_manager_hilog.h" +#include "wm_common.h" using namespace testing; using namespace testing::ext; @@ -483,6 +484,55 @@ HWTEST_F(PerformReporterTest, ReportWindowProfileInfo017, TestSize.Level1) res = windowInfoReporter.ReportWindowProfileInfo(windowProfileInfo); ASSERT_EQ(res, 0); } + +/** + * @tc.name: ReportWindowProfileInfo018 + * @tc.desc: ReportKeyboardLifeCycleException test + * @tc.type: FUNC + */ +HWTEST_F(PerformReporterTest, ReportKeyboardLifeCycleException18, Function | SmallTest | Level2) +{ + KeyboardLifeCycleException subEventType = KeyboardLifeCycleException::ANIM_SYNC_EXCEPTION; + int32_t windowId = 198; + std::string msg = "ReportKeyboardLifeCycleExceptionTestMSG"; + WindowInfoReporter windowInfoReporter; + int32_t res = windowInfoReporter.ReportKeyboardLifeCycleException(windowId, subEventType, msg); + ASSERT_EQ(res, 0); +} + +/** + * @tc.name: ReportWindowProfileInfo019 + * @tc.desc: ReportKeyboardLifeCycleException test + * @tc.type: FUNC + */ +HWTEST_F(PerformReporterTest, ReportKeyboardLifeCycleException19, Function | SmallTest | Level2) +{ + KeyboardLifeCycleException subEventType = KeyboardLifeCycleException::CREATE_EXCEPTION; + int32_t windowId = 198; + std::string msg = "ReportKeyboardLifeCycleExceptionTestMSG"; + WindowInfoReporter windowInfoReporter; + int32_t res = windowInfoReporter.ReportKeyboardLifeCycleException(windowId, subEventType, msg); + ASSERT_EQ(res, 0); +} + +/** + * @tc.name: ReportWindowProfileInfo018 + * @tc.desc: ReportSpecWindowLifeCycleChange test + * @tc.type: FUNC + */ +HWTEST_F(PerformReporterTest, ReportSpecWindowLifeCycleChange, Function | SmallTest | Level2) +{ + int32_t windowId = 198; + std::string stage = "attach"; + WindowLifeCycleReportInfo reportInfo = { "bundleName", windowId, + static_cast(WindowType::WINDOW_TYPE_APP_SUB_WINDOW), + static_cast(WindowMode::WINDOW_MODE_FULLSCREEN), + static_cast(WindowFlag::WINDOW_FLAG_IS_TEXT_MENU), + stage}; + WindowInfoReporter windowInfoReporter; + int32_t res = windowInfoReporter.ReportSpecWindowLifeCycleChange(reportInfo); + ASSERT_EQ(res, 0); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/session/host/include/keyboard_session.h b/window_scene/session/host/include/keyboard_session.h index c131321d864f4bd7f7d64015e1820c3219f401cc..4eda9112fd64e5f97d552c2e9da178bd59e48765 100644 --- a/window_scene/session/host/include/keyboard_session.h +++ b/window_scene/session/host/include/keyboard_session.h @@ -38,6 +38,8 @@ using OnSystemKeyboardAvoidChangeCallback = std::function; using NotifyOccupiedAreaChangeCallback = std::function& info)>; +const std::string KEYBOARD_ANIM_SYNC_EVENT_NAME { "KeyboardAnimationSyncException" }; + class KeyboardSession : public SystemSession { public: // callback for notify SceneSessionManager @@ -73,6 +75,7 @@ public: void SetKeyboardViewModeChangeListener(const NotifyKeyboarViewModeChangeFunc& func) override; void SetSkipSelfWhenShowOnVirtualScreen(bool isSkip) override; WSError UpdateSizeChangeReason(SizeChangeReason reason) override; + bool GetIsKeyboardSyncTransactionOpen() const { return isKeyboardSyncTransactionOpen_; } void SetSkipEventOnCastPlus(bool isSkip) override; protected: @@ -107,6 +110,7 @@ private: void NotifyRootSceneOccupiedAreaChange(const sptr& info); void SetSurfaceBounds(const WSRect& rect, bool isGlobal, bool needFlush = true) override; bool IsNeedRaiseSubWindow(const sptr& callingSession, const WSRect& callingSessionRect); + void PostKeyboardAnimationSyncTimeoutTask(); sptr keyboardCallback_ = nullptr; bool isKeyboardSyncTransactionOpen_ = false; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 5140997f0834c380ff89e01e0fb76bf9de328e70..6d175654785c2d5de9f7d63fb2936b393f0feced 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -136,6 +136,9 @@ struct DetectTaskInfo { DetectTaskState taskState = DetectTaskState::NO_TASK; }; +const std::string ATTACH_EVENT_NAME { "wms::ReportWindowTimeout_Attach" }; +const std::string DETACH_EVENT_NAME { "wms::ReportWindowTimeout_Detach" }; + class Session : public SessionStub { public: friend class HidumpController; @@ -669,6 +672,11 @@ public: */ void SetBorderUnoccupied(bool borderUnoccupied = false); bool GetBorderUnoccupied() const; + + /* + * Specific Window + */ + void SetWindowAnimationDuration(int32_t duration); protected: class SessionLifeCycleTask : public virtual RefBase { @@ -901,6 +909,8 @@ private: bool ShouldCreateDetectTask(bool isAttach, WindowMode windowMode) const; bool ShouldCreateDetectTaskInRecent(bool newShowRecent, bool oldShowRecent, bool isAttach) const; void CreateDetectStateTask(bool isAttach, WindowMode windowMode); + void PostSpecificSessionLifeCycleTimeoutTask(const std::string& eventName); // only report for specific window + bool IsNeedReportTimeout() const; /* * Window Rotate Animation @@ -1022,6 +1032,11 @@ private: * Window Pattern */ bool borderUnoccupied_ = false; + + /* + * Specific Window + */ + int32_t windowAnimationDuration_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/keyboard_session.cpp b/window_scene/session/host/src/keyboard_session.cpp index 93df3adff11a2d3f47791e899f53b26112dc658c..cf0fdaac5ecec217ed38dd802aeba43df2d77cd9 100644 --- a/window_scene/session/host/src/keyboard_session.cpp +++ b/window_scene/session/host/src/keyboard_session.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "perform_reporter.h" #include "session/host/include/keyboard_session.h" #include @@ -634,6 +635,7 @@ void KeyboardSession::OpenKeyboardSyncTransaction() if (transactionController) { transactionController->OpenSyncTransaction(session->GetEventHandler()); } + session->PostKeyboardAnimationSyncTimeoutTask(); return WSError::WS_OK; }; PostSyncTask(task); @@ -668,6 +670,11 @@ void KeyboardSession::CloseKeyboardSyncTransaction(uint32_t callingId, const WSR return WSError::WS_OK; } session->isKeyboardSyncTransactionOpen_ = false; + auto handler = session->GetEventHandler(); + if (handler) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Keyboard anim_sync event cancelled"); + handler->RemoveTask(KEYBOARD_ANIM_SYNC_EVENT_NAME); + } auto transactionController = RSSyncTransactionController::GetInstance(); if (transactionController) { transactionController->CloseSyncTransaction(session->GetEventHandler()); @@ -886,6 +893,34 @@ void KeyboardSession::SetSkipSelfWhenShowOnVirtualScreen(bool isSkip) }, __func__); } +void KeyboardSession::PostKeyboardAnimationSyncTimeoutTask() +{ + // anim_sync_exception + int32_t const THRESHOLD = 1000; + auto task = [weakThis = wptr(this)]() { + auto session = weakThis.promote(); + if (!session) { + TLOGNE(WmsLogTag::WMS_KEYBOARD, "keyboard session is null"); + return; + } + if (!session->GetIsKeyboardSyncTransactionOpen()) { + TLOGND(WmsLogTag::WMS_KEYBOARD, "closed anim_sync in time"); + return; + } + std::string msg("close anim_sync timeout"); + WindowInfoReporter::GetInstance().ReportKeyboardLifeCycleException( + session->GetPersistentId(), + KeyboardLifeCycleException::ANIM_SYNC_EXCEPTION, + msg); + }; + auto handler = GetEventHandler(); + if (!handler) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "handler is null"); + return; + } + handler->PostTask(task, KEYBOARD_ANIM_SYNC_EVENT_NAME, THRESHOLD); +} + void KeyboardSession::SetSkipEventOnCastPlus(bool isSkip) { PostTask([weakThis = wptr(this), isSkip, where = __func__]() { diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index ea17eb0129c3ebbd59b3d0ee6ef160272dad88ab..d5a3d0fb60786c2ba1cc827d8d3aa155308c5afb 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1346,10 +1346,10 @@ WSError Session::Foreground(sptr property, bool isFromCli SetActive(true); } isStarting_ = false; - NotifyForeground(); isTerminating_ = false; + PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME); return WSError::WS_OK; } @@ -1422,6 +1422,7 @@ WSError Session::Background(bool isFromClient, const std::string& identityToken) UpdateSessionState(SessionState::STATE_BACKGROUND); SetIsPendingToBackgroundState(false); NotifyBackground(); + PostSpecificSessionLifeCycleTimeoutTask(DETACH_EVENT_NAME); return WSError::WS_OK; } @@ -1637,6 +1638,9 @@ void Session::SetIsActivatedAfterScreenLocked(bool isActivatedAfterScreenLocked) void Session::SetAttachState(bool isAttach, WindowMode windowMode) { isAttach_ = isAttach; + if (handler_ && IsNeedReportTimeout()) { + handler_->RemoveTask(isAttach_ ? ATTACH_EVENT_NAME : DETACH_EVENT_NAME); + } PostTask([weakThis = wptr(this), isAttach]() { auto session = weakThis.promote(); if (session == nullptr) { @@ -4155,4 +4159,60 @@ bool Session::GetBorderUnoccupied() const { return borderUnoccupied_; } + +void Session::SetWindowAnimationDuration(int32_t duration) +{ + windowAnimationDuration_ = duration; +} + +bool Session::IsNeedReportTimeout() const +{ + WindowType type = GetWindowType(); + return WindowHelper::IsSubWindow(type) || (WindowHelper::IsAboveSystemWindow(type) && + type != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT && type != WindowType::WINDOW_TYPE_PANEL); +} + +void Session::PostSpecificSessionLifeCycleTimeoutTask(const std::string& eventName) +{ + const int32_t THRESHOLD = 20; + if (!IsNeedReportTimeout()) { + TLOGD(WmsLogTag::DEFAULT, "not specific window"); + return; + } + // if configured animation, don't report + if (windowAnimationDuration_) { + TLOGD(WmsLogTag::DEFAULT, "window configured animation, don't report"); + return; + } + if (!handler_) { + TLOGE(WmsLogTag::DEFAULT, "handler is null"); + return; + } + handler_->RemoveTask(eventName == ATTACH_EVENT_NAME ? + DETACH_EVENT_NAME : ATTACH_EVENT_NAME); + auto task = [weakThis = wptr(this), eventName, where = __func__]() { + auto session = weakThis.promote(); + if (!session) { + TLOGNI(WmsLogTag::DEFAULT, "%{public}s, session is null.", where); + return; + } + bool isAttach = session->GetAttachState(); + if ((isAttach && eventName == ATTACH_EVENT_NAME) || + (!isAttach && eventName == DETACH_EVENT_NAME)) { + TLOGND(WmsLogTag::DEFAULT, "%{public}s, detached or attached in time", where); + return; + } + WindowLifeCycleReportInfo reportInfo { + session->GetSessionInfo().bundleName_, + static_cast(session->GetPersistentId()), + static_cast(session->GetWindowType()), + static_cast(session->GetWindowMode()), + static_cast(session->GetSessionProperty()->GetWindowFlags()), + eventName + }; + TLOGNI(WmsLogTag::DEFAULT, "%{public}s report msg: %{public}s", where, reportInfo.ToString().c_str()); + WindowInfoReporter::GetInstance().ReportSpecWindowLifeCycleChange(reportInfo); + }; + PostTask(task, eventName, THRESHOLD); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 3a846d6194dca4aa7616fbff3b2d5e82548829e8..eed8b8395795a900f377f9506784790b1b84d6e6 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -465,6 +465,7 @@ public: void RegisterNotifyRootSceneOccupiedAreaChangeFunc(NotifyRootSceneOccupiedAreaChangeFunc&& func); void GetKeyboardOccupiedAreaWithRotation( int32_t persistentId, Rotation rotation, std::vector>& avoidAreas); + void ReportKeyboardCreateException(sptr& keyboardSession); /* * UIExtension diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 9f55789efa749b2d219b1081e7428d3c82c66252..c0fc7d5da7b2fa7f6048b4f261a1cf9d7220823c 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -2104,6 +2104,7 @@ void SceneSessionManager::CreateKeyboardPanelSession(sptr keyboard if (panelSession == nullptr) { if (panelVec.size() >= 2) { // 2 is max number of keyboard panel, one input method and one system keyboard TLOGE(WmsLogTag::WMS_KEYBOARD, "Error size of keyboardPanel, size: %{public}zu", panelVec.size()); + ReportKeyboardCreateException(keyboardSession); return; } std::string panelName = keyboardSession->IsSystemKeyboard() ? "SCBSystemKeyboardPanel" : "SCBKeyboardPanel"; @@ -2153,6 +2154,7 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se TLOGE(WmsLogTag::WMS_LIFE, "Invalid window type"); } if (sceneSession != nullptr) { + sceneSession->SetWindowAnimationDuration(appWindowSceneConfig_.windowAnimation_.duration_); sceneSession->SetSessionInfoPersistentId(sceneSession->GetPersistentId()); sceneSession->isKeyboardPanelEnabled_ = isKeyboardPanelEnabled_; sceneSession->RegisterForceSplitListener([this](const std::string& bundleName) { @@ -14614,6 +14616,31 @@ void SceneSessionManager::RegisterHookSceneSessionActivationFunc(const sptr& keyboardSession) { + std::string msg = "UITYPE:" + std::to_string(static_cast(systemConfig_.windowUIType_)) + ",PanelId:["; + for (const auto& session : GetSceneSessionVectorByType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL)) { + if (!session) { + TLOGW(WmsLogTag::DEFAULT, "session nullptr"); + continue; + } + msg += "PanelId:" + std::to_string(session->GetPersistentId()) + ","; + msg += "screenId:" + std::to_string(session->GetScreenId()) + ","; + } + msg += "],"; + for (const auto& session : GetSceneSessionVectorByType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT)) { + if (!session) { + TLOGW(WmsLogTag::DEFAULT, "session nullptr"); + continue; + } + msg += "keyboardId:" + std::to_string(session->GetPersistentId()) + ","; + msg += "screenId:" + std::to_string(session->GetScreenId()) + ","; + } + WindowInfoReporter::GetInstance().ReportKeyboardLifeCycleException( + keyboardSession->GetPersistentId(), + KeyboardLifeCycleException::CREATE_EXCEPTION, + msg); +} + void SceneSessionManager::RegisterSceneSessionDestructCallback(NotifySceneSessionDestructFunc&& func) { onSceneSessionDestruct_ = std::move(func); diff --git a/window_scene/test/unittest/session_test4.cpp b/window_scene/test/unittest/session_test4.cpp index e176b092b480a36e3800fe6481428e366778c9f5..f90a33fed96e391647b4179cb58799f49ee00b12 100644 --- a/window_scene/test/unittest/session_test4.cpp +++ b/window_scene/test/unittest/session_test4.cpp @@ -40,7 +40,14 @@ namespace { const std::string UNDEFINED = "undefined"; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSessionTest4"}; } - +namespace { +std::string g_logMsg; +void SessionTest4LogCallBack( + const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg) +{ + g_logMsg = msg; +} +} class WindowSessionTest4 : public testing::Test { public: static void SetUpTestCase(); @@ -1118,6 +1125,167 @@ HWTEST_F(WindowSessionTest4, SafelySetWant01, TestSize.Level1) ASSERT_NE(nullptr, sessionInfo.want); EXPECT_EQ(sessionInfo.SafelyGetWant().GetBundle(), "SafelySetWantTest"); } + +/** + * @tc.name: IsNeedReportTimeout + * @tc.desc: Case of non-specific window + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, IsNeedReportTimeout_NonSpecific_Window, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "IsNeedReportTimeout_NonSpecific_Window"; + sessionInfo.bundleName_ = "IsNeedReportTimeout_NonSpecific_Window"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, property->GetWindowType()); + + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType()); + EXPECT_EQ(false, session->IsNeedReportTimeout()); + + property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, property->GetWindowType()); + + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, session->GetWindowType()); + EXPECT_EQ(false, session->IsNeedReportTimeout()); +} + +/** + * @tc.name: IsNeedReportTimeout + * @tc.desc: Case of specific window + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, IsNeedReportTimeout_specific_window, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "IsNeedReportTimeout_specific_window"; + sessionInfo.bundleName_ = "IsNeedReportTimeout_specific_window"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType()); + + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType()); + EXPECT_EQ(true, session->IsNeedReportTimeout()); +} + +/** + * @tc.name: PostSpecificSessionLifeCycleTimeoutTask + * @tc.desc: Test Case about non specific window + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, ReportWindowTimeout_NonSpecificWindow, TestSize.Level1) +{ + LOG_SetCallback(SessionTest4LogCallBack); + g_logMsg.clear(); + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "ReportWindowTimeout_NonSpecificWindow"; + sessionInfo.bundleName_ = "ReportWindowTimeout_NonSpecificWindow"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, property->GetWindowType()); + EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, session->GetWindowType()); + session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME); + EXPECT_EQ(false, session->IsNeedReportTimeout()); +} + +/** + * @tc.name: PostSpecificSessionLifeCycleTimeoutTask + * @tc.desc: Test Case about non specific window + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, ReportWindowTimeout_SpecificWindow, TestSize.Level1) +{ + LOG_SetCallback(SessionTest4LogCallBack); + g_logMsg.clear(); + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "ReportWindowTimeout_SpecificWindow"; + sessionInfo.bundleName_ = "ReportWindowTimeout_SpecificWindow"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType()); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType()); + session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME); + EXPECT_TRUE(g_logMsg.find("not specific window") == std::string::npos); +} + +/** + * @tc.name: PostSpecificSessionLifeCycleTimeoutTask + * @tc.desc: Test Case about handler is not nullptr + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, ReportWindowTimeout_Handler_NOT_NULL, TestSize.Level1) +{ + LOG_SetCallback(SessionTest4LogCallBack); + g_logMsg.clear(); + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "ReportWindowTimeout_Handler_NOT_NULL"; + sessionInfo.bundleName_ = "ReportWindowTimeout_Handler_NOT_NULL"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType()); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType()); + session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME); + + sptr sceneSessionManager = sptr::MakeSptr(); + session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(), + sceneSessionManager->eventHandler_); + EXPECT_TRUE(g_logMsg.find("not specific window") == std::string::npos); + EXPECT_TRUE(g_logMsg.find("handler is null") == std::string::npos); +} + +/** + * @tc.name: PostSpecificSessionLifeCycleTimeoutTask + * @tc.desc: Test Case about window animation duration + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest4, ReportWindowTimeout_WindowAnimationDuration, TestSize.Level1) +{ + LOG_SetCallback(SessionTest4LogCallBack); + g_logMsg.clear(); + SessionInfo sessionInfo; + sessionInfo.abilityName_ = "ReportWindowTimeout_WindowAnimationDuration"; + sessionInfo.bundleName_ = "ReportWindowTimeout_WindowAnimationDuration"; + + sptr session = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->isSystemCalling_ = true; + property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + session->SetSessionProperty(property); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType()); + EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType()); + session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME); + sptr sceneSessionManager = sptr::MakeSptr(); + session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(), + sceneSessionManager->eventHandler_); + EXPECT_TRUE(g_logMsg.find("handler is null") == std::string::npos); + + session->SetWindowAnimationDuration(true); + EXPECT_EQ(true, session->IsNeedReportTimeout()); + + session->SetWindowAnimationDuration(false); + EXPECT_TRUE(g_logMsg.find("window configured animation") == std::string::npos); +} } } // namespace Rosen } // namespace OHOS