新增任务管理权限

Signed-off-by: liusensen <liusen43@huawei.com>
This commit is contained in:
liusensen 2024-07-15 14:39:04 +08:00
parent 515d14a360
commit 7f7f892f88
3 changed files with 31 additions and 34 deletions

View File

@ -5543,14 +5543,14 @@ WSError SceneSessionManager::IsValidSessionIds(
WSError SceneSessionManager::RegisterSessionListener(const sptr<ISessionListener>& 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<ISessionListener
WSError SceneSessionManager::UnRegisterSessionListener(const sptr<ISessionListener>& 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> sceneSession = GetSceneSession(persistentId);
return ClearSession(sceneSession);
@ -7545,14 +7545,14 @@ WSError SceneSessionManager::ClearSession(sptr<SceneSession> 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<sptr<SceneSession>> sessionVector;
GetAllClearableSessions(sessionVector);
@ -7580,14 +7580,14 @@ void SceneSessionManager::GetAllClearableSessions(std::vector<sptr<SceneSession>
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) {

View File

@ -1607,8 +1607,7 @@ HWTEST_F(SceneSessionManagerTest, ClearMainSessions001, Function | SmallTest | L
ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
std::vector<int32_t> 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<int32_t> 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<int32_t> 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);
}
/**

View File

@ -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);
}
/**