From 491f7577181effd0e9c994313054328ad17f0e73 Mon Sep 17 00:00:00 2001 From: hubijie Date: Thu, 19 Jun 2025 16:30:53 +0800 Subject: [PATCH] =?UTF-8?q?PC=E5=8E=BB=E9=99=A4=E5=90=AF=E5=8A=A8=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E9=85=8D=E5=90=88AMS=E5=AE=8C=E6=88=90=E7=94=9F?= =?UTF-8?q?=E5=91=BD=E5=91=A8=E6=9C=9F=E8=B0=83=E5=BA=A6=20Signed-off-by:?= =?UTF-8?q?=20hubijie=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/include/window_session_property.h | 5 + window_scene/interfaces/include/ws_common.h | 9 ++ .../session/host/include/scene_session.h | 5 + .../session/host/src/scene_session.cpp | 26 ++++- .../session/host/src/zidl/session_proxy.cpp | 4 + .../session/host/src/zidl/session_stub.cpp | 4 + .../include/scene_session_manager.h | 2 + .../zidl/session_router_stack_listener.h | 11 ++- .../src/scene_session_manager.cpp | 54 ++++++++++- .../unittest/scene_session_lifecycle_test.cpp | 81 ++++++++++++++++ .../unittest/scene_session_manager_test12.cpp | 96 +++++++++++++++++++ .../unittest/scene_session_manager_test6.cpp | 24 +++++ 12 files changed, 315 insertions(+), 6 deletions(-) diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 7ef23c6b83..e3e5e78743 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -879,6 +879,11 @@ struct SystemSessionConfig : public Parcelable { { return windowUIType_ == WindowUIType::PAD_WINDOW; } + + bool IsPcOrPcMode() const + { + return IsPcWindow() || (IsPadWindow() && IsFreeMultiWindowMode()); + } }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/interfaces/include/ws_common.h b/window_scene/interfaces/include/ws_common.h index 9a6de15add..3925fd899e 100644 --- a/window_scene/interfaces/include/ws_common.h +++ b/window_scene/interfaces/include/ws_common.h @@ -351,6 +351,12 @@ struct WindowSizeLimits { } }; +enum class StartWindowType : uint32_t { + DEFAULT = 0, + RETAIN_AND_INVISIBLE, + REMOVE_NODE_INVISIBLE, +}; + struct SessionInfo { std::string bundleName_ = ""; std::string moduleName_ = ""; @@ -413,6 +419,8 @@ struct SessionInfo { bool disableDelegator = false; bool reuseDelegatorWindow = false; bool isAbilityHook_ = false; + StartWindowType startWindowType_ = StartWindowType::DEFAULT; + bool isSetStartWindowType_ = false; /* * Keyboard @@ -720,6 +728,7 @@ struct StartingWindowInfo { std::string brandingPath_; std::string backgroundImagePath_; std::string backgroundImageFit_; + std::string startWindowType_; }; struct StartingWindowPageDrawInfo { diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 7d316d8384..59afc3b1c3 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -130,6 +130,7 @@ using NotifyWindowAnchorInfoChangeFunc = std::function(int32_t sessionId)>; using NotifySetParentSessionFunc = std::function; using NotifyUpdateFlagFunc = std::function; +using GetStartWindowTypeFunc = std::function; using NotifyRotationChangeFunc = std::function; using NotifyHookSceneSessionActivationFunc = std::function& session, bool isNewWant)>; using NotifySceneSessionDestructFunc = std::function; @@ -618,6 +619,7 @@ public: void SetIsUserRequestedExit(bool isUserRequestedExit); void SetGetAllAppUseControlMapFunc(GetAllAppUseControlMapFunc&& callback); void UpdateLifecyclePausedInner(); + void CalculatedStartWindowType(SessionInfo& sessionInfo, bool hideStartWindow); void SendPointerEventToUI(std::shared_ptr pointerEvent); bool SendKeyEventToUI(std::shared_ptr keyEvent, bool isPreImeEvent = false); @@ -650,6 +652,7 @@ public: WSError UpdateRectChangeListenerRegistered(bool isRegister) override; WMError NotifyDisableDelegatorChange() override; virtual void SetRecentSessionState(RecentSessionInfo& info, const SessionState& state) {} + void RegisterGetStartWindowConfigFunc(GetStartWindowTypeFunc&& func); /* * Window Decor @@ -1051,6 +1054,8 @@ private: NotifySceneSessionDestructFunc notifySceneSessionDestructFunc_; bool CheckIdentityTokenIfMatched(const std::string& identityToken); bool CheckPidIfMatched(); + GetStartWindowTypeFunc getStartWindowConfigFunc_; + StartWindowType startWindowType_; // session lifecycle funcs WSError ForegroundTask(const sptr& property); diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 97aa85e7f8..3332133ec7 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -91,6 +91,7 @@ constexpr uint32_t ROTATION_DEGREE = 90; constexpr int32_t HALF_VALUE = 2; const int32_t ROTATE_POLICY_WINDOW = 0; const int32_t ROTATE_POLICY_SCREEN = 1; +const std::string OPTIONAL_SHOW = "OPTIONAL_SHOW"; // startWindowType can be changed by startAbility option. bool CheckIfRectElementIsTooLarge(const WSRect& rect) { @@ -5302,22 +5303,43 @@ static SessionInfo MakeSessionInfoDuringPendingActivation(const sptr(WindowMode::WINDOW_MODE_FULLSCREEN)) { info.fullScreenStart_ = true; } + session->CalculatedStartWindowType(info, abilitySessionInfo->hideStartWindow); TLOGI(WmsLogTag::WMS_LIFE, "bundleName:%{public}s, moduleName:%{public}s, abilityName:%{public}s, " "appIndex:%{public}d, affinity:%{public}s. callState:%{public}d, want persistentId:%{public}d, " "uiAbilityId:%{public}" PRIu64 ", windowMode:%{public}d, callerId:%{public}d, " "needClearInNotShowRecent:%{public}u, appInstanceKey: %{public}s, isFromIcon:%{public}d, " "supportedWindowModes.size:%{public}zu, requestId:%{public}d, " "maxWindowWidth:%{public}d, minWindowWidth:%{public}d, maxWindowHeight:%{public}d, minWindowHeight:%{public}d, " - "reuseDelegatorWindow:%{public}d", + "reuseDelegatorWindow:%{public}d, startWindowType:%{public}d", info.bundleName_.c_str(), info.moduleName_.c_str(), info.abilityName_.c_str(), info.appIndex_, info.sessionAffinity.c_str(), info.callState_, info.persistentId_, info.uiAbilityId_, info.windowMode, info.callerPersistentId_, info.needClearInNotShowRecent_, info.appInstanceKey_.c_str(), info.isFromIcon_, info.supportedWindowModes.size(), info.requestId, info.windowSizeLimits.maxWindowWidth, info.windowSizeLimits.minWindowWidth, - info.windowSizeLimits.maxWindowHeight, info.windowSizeLimits.minWindowHeight, info.reuseDelegatorWindow); + info.windowSizeLimits.maxWindowHeight, info.windowSizeLimits.minWindowHeight, + info.reuseDelegatorWindow, info.startWindowType_); return info; } +void SceneSession::CalculatedStartWindowType(SessionInfo& info, bool hideStartWindow) +{ + if (getStartWindowConfigFunc_ == nullptr || GetSessionInfo().bundleName_ != info.bundleName_) { + TLOGI(WmsLogTag::WMS_LIFE, "only same app in pc or pcMode."); + return; + } + std::string startWindowType; + getStartWindowConfigFunc_(info, startWindowType); + if (startWindowType == OPTIONAL_SHOW) { + info.startWindowType_ = hideStartWindow ? StartWindowType::RETAIN_AND_INVISIBLE : StartWindowType::DEFAULT; + info.isSetStartWindowType_ = true; + } +} + +void SceneSession::RegisterGetStartWindowConfigFunc(GetStartWindowTypeFunc&& func) +{ + getStartWindowConfigFunc_ = std::move(func); +} + WSError SceneSession::PendingSessionActivation(const sptr abilitySessionInfo) { if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index c8d1d5b478..2cf0c632cc 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -531,6 +531,10 @@ WSError SessionProxy::PendingSessionActivation(sptr abilityS TLOGE(WmsLogTag::WMS_LIFE, "Write reuseDelegatorWindow failed."); return WSError::WS_ERROR_IPC_FAILED; } + if (!data.WriteBool(abilitySessionInfo->hideStartWindow)) { + TLOGE(WmsLogTag::WMS_LIFE, "Write hideStartWindow failed."); + return WSError::WS_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 2d333971ab..6f99e684ad 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -793,6 +793,10 @@ int SessionStub::HandlePendingSessionActivation(MessageParcel& data, MessageParc TLOGE(WmsLogTag::WMS_LIFE, "Read reuseDelegatorWindow failed."); return ERR_INVALID_DATA; } + if (!data.ReadBool(abilitySessionInfo->hideStartWindow)) { + TLOGE(WmsLogTag::WMS_LIFE, "Read hideStartWindow failed."); + return ERR_INVALID_DATA; + } WSError errCode = PendingSessionActivation(abilitySessionInfo); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 33d4123d16..fa99fc73da 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -721,6 +721,7 @@ public: WMError UpdateKioskAppList(const std::vector& kioskAppList); WMError EnterKioskMode(const sptr& token); WMError ExitKioskMode(); + void RegisterGetStartWindowConfigCallback(const sptr& sceneSession); void RegisterUpdateKioskAppListCallback(UpdateKioskAppListFunc&& func); void RegisterKioskModeChangeCallback(KioskModeChangeFunc&& func); @@ -845,6 +846,7 @@ private: const uint32_t& windowStateChangeReason, bool& isColdStart); sptr GetHookedSessionByModuleName(const SessionInfo& sessionInfo); void RegisterHookSceneSessionActivationFunc(const sptr& sceneSession); + void SetSessionInfoStartWindowType(const sptr& sceneSession); void RegisterSceneSessionDestructNotifyManagerFunc(const sptr& sceneSession); void UpdateAbilityHookState(sptr& sceneSession, bool isAbilityHook); diff --git a/window_scene/session_manager/include/zidl/session_router_stack_listener.h b/window_scene/session_manager/include/zidl/session_router_stack_listener.h index 73eeae5d26..0ed2e419f5 100644 --- a/window_scene/session_manager/include/zidl/session_router_stack_listener.h +++ b/window_scene/session_manager/include/zidl/session_router_stack_listener.h @@ -19,6 +19,8 @@ #include #include +#include "wm_common.h" + namespace OHOS::Rosen { class RouterStackInfo : public Parcelable { @@ -31,7 +33,8 @@ public: bool Marshalling(Parcel &parcel) const { - return parcel.WriteInt32(winId_) && parcel.WriteString(routerStackInfo_); + return parcel.WriteInt32(winId_) && parcel.WriteString(routerStackInfo_) && + parcel.WriteInt32(static_cast(errCode_)); } static RouterStackInfo *Unmarshalling(Parcel &parcel) @@ -40,8 +43,11 @@ public: if (routerStackInfo == nullptr) { return nullptr; } + int32_t errCode = 0; bool res = - parcel.ReadInt32(routerStackInfo->winId_) && parcel.ReadString(routerStackInfo->routerStackInfo_); + parcel.ReadInt32(routerStackInfo->winId_) && parcel.ReadString(routerStackInfo->routerStackInfo_) + && parcel.ReadInt32(errCode); + routerStackInfo->errCode_ = static_cast(errCode); if (!res) { delete routerStackInfo; return nullptr; @@ -51,6 +57,7 @@ public: int32_t winId_{0}; std::string routerStackInfo_; + WMError errCode_ = WMError::WM_OK; }; class ISessionRouterStackListener : public IRemoteBroker { diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 98caec536c..3a63b7ea95 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -166,6 +166,12 @@ const std::map STRING_TO_DISP {"follow_desktop", OHOS::AppExecFwk::DisplayOrientation::FOLLOW_DESKTOP}, }; +const std::map CONVERT_STRING_TO_START_WINDOW_TYPE_MAP = { + {"REQUIRED_SHOW", StartWindowType::DEFAULT}, + {"REQUIRED_HIDE", StartWindowType::RETAIN_AND_INVISIBLE}, + {"OPTIONAL_SHOW", StartWindowType::DEFAULT}, +}; + const std::unordered_set LAYOUT_INFO_WHITELIST = { "SCBSmartDock", "SCBExtScreenDock", @@ -2599,6 +2605,9 @@ void SceneSessionManager::InitSceneSession(sptr& sceneSession, con RegisterSessionExceptionFunc(sceneSession); RegisterVisibilityChangedDetectFunc(sceneSession); RegisterSaveSnapshotFunc(sceneSession); + if (systemConfig_.IsPcOrPcMode()) { + RegisterGetStartWindowConfigCallback(sceneSession); + } if (systemConfig_.windowUIType_ == WindowUIType::PAD_WINDOW) { RegisterRemoveSnapshotFunc(sceneSession); } @@ -3442,6 +3451,7 @@ WSError SceneSessionManager::RequestSceneSessionDestructionInner(sptrResetSessionInfoResultCode(); + sceneSession->EditSessionInfo().isSetStartWindowType_ = false; } NotifySessionForCallback(sceneSession, needRemoveSession); // Clear js cb map if needed. @@ -5332,12 +5342,45 @@ void SceneSessionManager::FillSessionInfo(sptr& sceneSession) } else if (abilityInfo->applicationInfo.codePath == std::to_string(CollaboratorType::OTHERS_TYPE)) { sceneSession->SetCollaboratorType(CollaboratorType::OTHERS_TYPE); } + SetSessionInfoStartWindowType(sceneSession); TLOGI(WmsLogTag::WMS_MAIN, "bundleName:%{public}s removeMissionAfterTerminate:%{public}d " "excludeFromMissions:%{public}d label:%{public}s iconPath:%{public}s collaboratorType:%{public}s.", abilityInfo->bundleName.c_str(), abilityInfo->removeMissionAfterTerminate, abilityInfo->excludeFromMissions, abilityInfo->label.c_str(), abilityInfo->iconPath.c_str(), abilityInfo->applicationInfo.codePath.c_str()); } +void SceneSessionManager::SetSessionInfoStartWindowType(const sptr& sceneSession) +{ + if (systemConfig_.IsPcOrPcMode() && !sceneSession->GetSessionInfo().isSetStartWindowType_) { + StartingWindowInfo startingWindowInfo; + GetStartupPage(sceneSession->GetSessionInfo(), startingWindowInfo); + TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d, startWindowType from rdb:%{public}s", + sceneSession->GetPersistentId(), startingWindowInfo.startWindowType_.c_str()); + if (CONVERT_STRING_TO_START_WINDOW_TYPE_MAP.count(startingWindowInfo.startWindowType_) > 0) { + sceneSession->EditSessionInfo().startWindowType_ = + CONVERT_STRING_TO_START_WINDOW_TYPE_MAP.at(startingWindowInfo.startWindowType_); + } + TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d, startWindowType:%{public}d", + sceneSession->GetPersistentId(), sceneSession->GetSessionInfo().startWindowType_); + } +} + +void SceneSessionManager::RegisterGetStartWindowConfigCallback(const sptr& sceneSession) +{ + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "session is nullptr"); + return; + } + sceneSession->RegisterGetStartWindowConfigFunc([this](const SessionInfo& sessionInfo, std::string& startWindowType) { + StartingWindowInfo startingWindowInfo; + GetStartupPage(sessionInfo, startingWindowInfo); + startWindowType = startingWindowInfo.startWindowType_; + TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d, startWindowType:%{public}s", + sessionInfo.persistentId_, startWindowType.c_str()); + }); +} + + std::shared_ptr SceneSessionManager::QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName, const std::string& abilityName, const std::string& moduleName) { @@ -15864,14 +15907,21 @@ WMError SceneSessionManager::GetRouterStackInfo(int32_t persistentId, TLOGE(WmsLogTag::WMS_LIFE, "Session with persistentId %{public}d not found", persistentId); return WMError::WM_ERROR_NULLPTR; } - auto task = [this, session, listener, where = __func__] { + auto task = [this, weakSceneSession = wptr(session), listener, where = __func__] { + sptr session = weakSceneSession.promote(); + if (session == nullptr) { + TLOGNE(WmsLogTag::WMS_LIFE, "session is nullptr"); + return; + } std::string routerStack; auto ret = session->GetRouterStackInfo(routerStack); + sptr routerStackInfo = sptr::MakeSptr(session->GetPersistentId(), routerStack); if (ret != WMError::WM_OK) { TLOGNE(WmsLogTag::WMS_LIFE, "failed, persistentId %{public}d", session->GetPersistentId()); + routerStackInfo->errCode_ = ret; + listener->SendRouterStackInfo(routerStackInfo); return; } - sptr routerStackInfo = sptr::MakeSptr(session->GetPersistentId(), routerStack); listener->SendRouterStackInfo(routerStackInfo); }; ffrtQueueHelper_->SubmitTask(task); diff --git a/window_scene/test/unittest/scene_session_lifecycle_test.cpp b/window_scene/test/unittest/scene_session_lifecycle_test.cpp index 86238d1baa..7c6ef314ac 100644 --- a/window_scene/test/unittest/scene_session_lifecycle_test.cpp +++ b/window_scene/test/unittest/scene_session_lifecycle_test.cpp @@ -1093,6 +1093,87 @@ HWTEST_F(SceneSessionLifecycleTest, NotifySessionBackground, TestSize.Level0) sceneSession->NotifySessionBackground(reason, withAnimation, isFromInnerkits); ASSERT_EQ(ret, 1); } + +/** + * @tc.name: CalculatedStartWindowType01 + * @tc.desc: CalculatedStartWindowType when getStartWindowConfigFunc_ is null. + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, CalculatedStartWindowType01, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "CalculatedStartWindowType01"; + info.bundleName_ = "CalculatedStartWindowType01"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + SessionInfo info2; + + sceneSession->CalculatedStartWindowType(info2, false); + EXPECT_EQ(info2.startWindowType_, StartWindowType::DEFAULT); +} + +/** + * @tc.name: CalculatedStartWindowType02 + * @tc.desc: CalculatedStartWindowType when hideStartWindow is true + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, CalculatedStartWindowType02, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "CalculatedStartWindowType02"; + info.bundleName_ = "CalculatedStartWindowType02"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->getStartWindowConfigFunc_ = [](SessionInfo sessionInfo, std::string& startWindowType) { + startWindowType = "OPTIONAL_SHOW"; + }; + SessionInfo info2; + + sceneSession->CalculatedStartWindowType(info2, true); + EXPECT_EQ(info2.startWindowType_, StartWindowType::RETAIN_AND_INVISIBLE); +} + +/** + * @tc.name: CalculatedStartWindowType03 + * @tc.desc: CalculatedStartWindowType when hideStartWindow is false + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, CalculatedStartWindowType03, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "CalculatedStartWindowType03"; + info.bundleName_ = "CalculatedStartWindowType03"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->getStartWindowConfigFunc_ = [](SessionInfo sessionInfo, std::string& startWindowType) { + startWindowType = "OPTIONAL_SHOW"; + }; + SessionInfo info2; + + sceneSession->CalculatedStartWindowType(info2, false); + EXPECT_EQ(info2.startWindowType_, StartWindowType::DEFAULT); +} + +/** + * @tc.name: CalculatedStartWindowType04 + * @tc.desc: CalculatedStartWindowType when startWindowType is not optional + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, CalculatedStartWindowType04, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "CalculatedStartWindowType04"; + info.bundleName_ = "CalculatedStartWindowType04"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->getStartWindowConfigFunc_ = [](SessionInfo sessionInfo, std::string& startWindowType) { + startWindowType = "REQUIRED_HIDE"; + }; + SessionInfo info2; + + sceneSession->CalculatedStartWindowType(info2, false); + EXPECT_EQ(info2.startWindowType_, StartWindowType::DEFAULT); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index 7538b057e4..580f8db695 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -192,6 +192,14 @@ void SceneSessionManagerTest12::ConstructKeyboardCallingWindowTestData(const Key } namespace { + +std::string g_logMsg; +void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) +{ + g_logMsg = msg; +} + /** * @tc.name: GetResourceManager * @tc.desc: GetResourceManager @@ -2346,6 +2354,94 @@ HWTEST_F(SceneSessionManagerTest12, RemoveInstanceKey_OK, TestSize.Level1) auto result = ssm_->RemoveInstanceKey(bundleName, instanceKey); EXPECT_EQ(result, WMError::WM_OK); } + +/** + * @tc.name: SetSessionInfoStartWindowType01 + * @tc.desc: test function : SetSessionInfoStartWindowType + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType01, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "SetSessionInfoStartWindowType01"; + info.bundleName_ = "SetSessionInfoStartWindowType01"; + info.isSetStartWindowType_ = false; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + auto oldUIType = ssm_->systemConfig_.windowUIType_; + ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + + ssm_->SetSessionInfoStartWindowType(sceneSession); + + EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT); + ssm_->systemConfig_.windowUIType_ = oldUIType; +} + +/** + * @tc.name: SetSessionInfoStartWindowType02 + * @tc.desc: test function : SetSessionInfoStartWindowType + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType02, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "SetSessionInfoStartWindowType02"; + info.bundleName_ = "SetSessionInfoStartWindowType02"; + info.isSetStartWindowType_ = false; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + auto oldUIType = ssm_->systemConfig_.windowUIType_; + ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + + ssm_->SetSessionInfoStartWindowType(sceneSession); + + EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT); + ssm_->systemConfig_.windowUIType_ = oldUIType; +} + +/** + * @tc.name: SetSessionInfoStartWindowType03 + * @tc.desc: test function : SetSessionInfoStartWindowType + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType03, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "SetSessionInfoStartWindowType03"; + info.bundleName_ = "SetSessionInfoStartWindowType03"; + info.isSetStartWindowType_ = true; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + auto oldUIType = ssm_->systemConfig_.windowUIType_; + ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + + ssm_->SetSessionInfoStartWindowType(sceneSession); + + EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT); + ssm_->systemConfig_.windowUIType_ = oldUIType; +} + +/** + * @tc.name: RegisterGetStartWindowConfigCallback + * @tc.desc: test function : RegisterGetStartWindowConfigCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterGetStartWindowConfigCallback, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "RegisterGetStartWindowConfigCallback"; + info.bundleName_ = "RegisterGetStartWindowConfigCallback"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + + ssm_->RegisterGetStartWindowConfigCallback(sceneSession); + + EXPECT_NE(sceneSession->getStartWindowConfigFunc_, nullptr); + + g_logMsg.clear(); + ssm_->RegisterGetStartWindowConfigCallback(nullptr); + EXPECT_TRUE(g_logMsg.find("session is nullptr") != std::string::npos); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/scene_session_manager_test6.cpp b/window_scene/test/unittest/scene_session_manager_test6.cpp index 136f3fbd14..53995a937c 100644 --- a/window_scene/test/unittest/scene_session_manager_test6.cpp +++ b/window_scene/test/unittest/scene_session_manager_test6.cpp @@ -1086,6 +1086,30 @@ HWTEST_F(SceneSessionManagerTest6, InitSceneSession01, TestSize.Level1) ASSERT_EQ(100, sceneSession->GetSessionInfo().screenId_); } +/** + * @tc.name: InitSceneSession02 + * @tc.desc: InitSceneSession02:in pc or pcmode + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest6, InitSceneSession02, TestSize.Level1) +{ + ASSERT_NE(nullptr, ssm_); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "InitSceneSession02"; + sessionInfo.abilityName_ = "InitSceneSession02"; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + auto oldUIType = ssm_->systemConfig_.windowUIType_; + ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + + ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr); + EXPECT_NE(sceneSession->getStartWindowConfigFunc_, nullptr); + + sceneSession->getStartWindowConfigFunc_ = nullptr; + ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + EXPECT_EQ(sceneSession->getStartWindowConfigFunc_, nullptr); + ssm_->systemConfig_.windowUIType_ = oldUIType; +} + /** * @tc.name: CheckAndNotifyWaterMarkChangedResult * @tc.desc: CheckAndNotifyWaterMarkChangedResult -- Gitee