diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index d1ee442ca3..d93b18c609 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5543,14 +5543,14 @@ WSError SceneSessionManager::IsValidSessionIds( WSError SceneSessionManager::RegisterSessionListener(const sptr& listener) { WLOGFI("Enter"); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this, &listener]() { WSError ret = WSError::WS_DO_NOTHING; if (listenerController_ != nullptr) { @@ -5571,14 +5571,14 @@ WSError SceneSessionManager::RegisterSessionListener(const sptr& listener) { WLOGFI("Enter"); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this, &listener]() { if (listenerController_ != nullptr) { listenerController_->DelSessionListener(listener); @@ -7511,14 +7511,14 @@ void SceneSessionManager::OnScreenshot(DisplayId displayId) WSError SceneSessionManager::ClearSession(int32_t persistentId) { WLOGFI("id: %{public}d", persistentId); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this, persistentId]() { sptr sceneSession = GetSceneSession(persistentId); return ClearSession(sceneSession); @@ -7545,14 +7545,14 @@ WSError SceneSessionManager::ClearSession(sptr sceneSession) WSError SceneSessionManager::ClearAllSessions() { WLOGFI("Enter"); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this]() { std::vector> sessionVector; GetAllClearableSessions(sessionVector); @@ -7580,14 +7580,14 @@ void SceneSessionManager::GetAllClearableSessions(std::vector WSError SceneSessionManager::LockSession(int32_t sessionId) { WLOGFI("id: %{public}d", sessionId); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this, sessionId]() { auto sceneSession = GetSceneSession(sessionId); if (sceneSession == nullptr) { @@ -7603,14 +7603,14 @@ WSError SceneSessionManager::LockSession(int32_t sessionId) WSError SceneSessionManager::UnlockSession(int32_t sessionId) { WLOGFI("id: %{public}d", sessionId); - if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { - TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { WLOGFE("The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } + if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { + TLOGW(WmsLogTag::WMS_LIFE, "The caller has not permission granted"); + return WSError::WS_ERROR_INVALID_PERMISSION; + } auto task = [this, sessionId]() { auto sceneSession = GetSceneSession(sessionId); if (sceneSession == nullptr) { diff --git a/window_scene/test/unittest/scene_session_manager_test.cpp b/window_scene/test/unittest/scene_session_manager_test.cpp index b262b75095..86cfa80362 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -1607,8 +1607,7 @@ HWTEST_F(SceneSessionManagerTest, ClearMainSessions001, Function | SmallTest | L ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); std::vector persistentIds = {sceneSession->GetPersistentId()}; auto result = ssm_->ClearMainSessions(persistentIds, clearFailedIds); - EXPECT_EQ(result, WMError::WM_OK); - EXPECT_EQ(clearFailedIds.size(), 0); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); } /** @@ -1636,8 +1635,7 @@ HWTEST_F(SceneSessionManagerTest, ClearMainSessions002, Function | SmallTest | L ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2}); std::vector persistentIds = {sceneSession1->GetPersistentId(), sceneSession2->GetPersistentId()}; auto result = ssm_->ClearMainSessions(persistentIds, clearFailedIds); - EXPECT_EQ(result, WMError::WM_OK); - EXPECT_EQ(clearFailedIds.size(), 1); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); } /** @@ -1658,8 +1656,7 @@ HWTEST_F(SceneSessionManagerTest, ClearMainSessions003, Function | SmallTest | L ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); std::vector persistentIds = {sceneSession->GetPersistentId(), invalidPersistentId}; auto result = ssm_->ClearMainSessions(persistentIds, clearFailedIds); - EXPECT_EQ(result, WMError::WM_OK); - EXPECT_EQ(clearFailedIds.size(), 1); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); } /** diff --git a/wm/test/unittest/window_manager_lite_test.cpp b/wm/test/unittest/window_manager_lite_test.cpp index 07d53b346e..b24b20b6f8 100644 --- a/wm/test/unittest/window_manager_lite_test.cpp +++ b/wm/test/unittest/window_manager_lite_test.cpp @@ -377,7 +377,7 @@ HWTEST_F(WindowManagerLiteTest, ClearMainSessions001, Function | SmallTest | Lev EXPECT_CALL(m->Mock(), ClearMainSessions(_)).Times(0).WillOnce(Return(WMError::WM_OK)); auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds); - ASSERT_EQ(WMError::WM_OK, errorCode); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, errorCode); } /** @@ -393,7 +393,7 @@ HWTEST_F(WindowManagerLiteTest, ClearMainSessions002, Function | SmallTest | Lev EXPECT_CALL(m->Mock(), ClearMainSessions(_)).Times(1).WillOnce(Return(WMError::WM_OK)); auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds); - ASSERT_EQ(WMError::WM_OK, errorCode); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, errorCode); } /** @@ -409,7 +409,7 @@ HWTEST_F(WindowManagerLiteTest, ClearMainSessions003, Function | SmallTest | Lev EXPECT_CALL(m->Mock(), ClearMainSessions(_, _)).Times(0).WillOnce(Return(WMError::WM_OK)); auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds, clearFailedIds); - ASSERT_EQ(WMError::WM_OK, errorCode); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, errorCode); } /** @@ -425,7 +425,7 @@ HWTEST_F(WindowManagerLiteTest, ClearMainSessions004, Function | SmallTest | Lev EXPECT_CALL(m->Mock(), ClearMainSessions(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds, clearFailedIds); - ASSERT_EQ(WMError::WM_OK, errorCode); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, errorCode); } /**