diff --git a/services/edm/include/admin_manager.h b/services/edm/include/admin_manager.h index 56a7aa178f4b139a1113fcb529c349caa8dd097e..11e82f03e65ccc5112905c80d4e7a9331cd12cbc 100644 --- a/services/edm/include/admin_manager.h +++ b/services/edm/include/admin_manager.h @@ -49,8 +49,8 @@ public: std::vector &permissions, int32_t userId); ErrCode GetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); ErrCode SetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); - ErrCode SaveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId); - ErrCode RemoveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId); + void SaveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId); + void RemoveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId); virtual ~AdminManager(); private: diff --git a/services/edm/src/admin_manager.cpp b/services/edm/src/admin_manager.cpp index 173ff6679a807eceee62219cc3a74a03400af207..66d5ec8058267068b5cc0e1df82f6ff975249174 100644 --- a/services/edm/src/admin_manager.cpp +++ b/services/edm/src/admin_manager.cpp @@ -314,7 +314,7 @@ ErrCode AdminManager::SetEntInfo(const std::string &packageName, EntInfo &entInf return ERR_EDM_UNKNOWN_ADMIN; } -ErrCode AdminManager::SaveSubscribeEvents(const std::vector &events, +void AdminManager::SaveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId) { size_t eventsNumber = admin->adminInfo_.managedEvents_.size(); @@ -328,10 +328,9 @@ ErrCode AdminManager::SaveSubscribeEvents(const std::vector &events, if (admin->adminInfo_.managedEvents_.size() > eventsNumber) { SaveAdmin(userId); } - return ERR_OK; } -ErrCode AdminManager::RemoveSubscribeEvents(const std::vector &events, +void AdminManager::RemoveSubscribeEvents(const std::vector &events, std::shared_ptr &admin, int32_t userId) { size_t eventsNumber = admin->adminInfo_.managedEvents_.size(); @@ -348,7 +347,6 @@ ErrCode AdminManager::RemoveSubscribeEvents(const std::vector &events, if (admin->adminInfo_.managedEvents_.size() < eventsNumber) { SaveAdmin(userId); } - return ERR_OK; } // init void AdminManager::Init() diff --git a/services/edm/src/enterprise_device_mgr_ability.cpp b/services/edm/src/enterprise_device_mgr_ability.cpp index 8e32f2040867f684598291ad10aed53543f4c6b4..8549998e7948bf5722a7a00312777dc38304c59f 100644 --- a/services/edm/src/enterprise_device_mgr_ability.cpp +++ b/services/edm/src/enterprise_device_mgr_ability.cpp @@ -765,11 +765,10 @@ ErrCode EnterpriseDeviceMgrAbility::HandleManagedEvent(const AppExecFwk::Element if (iter != std::end(events)) { return EdmReturnErrCode::MANAGED_EVENTS_INVALID; } - ErrCode code; if (subscribe) { - code = adminMgr_->SaveSubscribeEvents(events, adminItem, userId); + adminMgr_->SaveSubscribeEvents(events, adminItem, userId); } else { - code = adminMgr_->RemoveSubscribeEvents(events, adminItem, userId); + adminMgr_->RemoveSubscribeEvents(events, adminItem, userId); } return ERR_OK; } diff --git a/test/unittest/src/admin_manager_test.cpp b/test/unittest/src/admin_manager_test.cpp index 98ea4431eb85de78ff8a7b241bc58c43ac3d37d0..52ef1a9fd1416d2dadc611984abb61aa6ac65c8c 100644 --- a/test/unittest/src/admin_manager_test.cpp +++ b/test/unittest/src/admin_manager_test.cpp @@ -467,11 +467,11 @@ HWTEST_F(AdminManagerTest, TestSaveSubscribeEvents, TestSize.Level1) entInfo.description = "technology company in wuhan"; std::vector permissions = { "ohos.permission.EDM_TEST_PERMISSION" }; adminMgr_->SetAdminValue(abilityInfo, entInfo, AdminType::NORMAL, permissions, DEFAULT_USER_ID); - ErrCode ret = adminMgr_->SaveSubscribeEvents(events, admin, DEFAULT_USER_ID); - ASSERT_TRUE(ret == ERR_OK); + adminMgr_->SaveSubscribeEvents(events, admin, DEFAULT_USER_ID); + ASSERT_TRUE(admin->adminInfo_.managedEvents_.size() == 1); events.push_back(1); - ret = adminMgr_->SaveSubscribeEvents(events, admin, DEFAULT_USER_ID); - ASSERT_TRUE(ret == ERR_OK); + adminMgr_->SaveSubscribeEvents(events, admin, DEFAULT_USER_ID); + ASSERT_TRUE(admin->adminInfo_.managedEvents_.size() > 1); } /** @@ -492,11 +492,11 @@ HWTEST_F(AdminManagerTest, TestRemoveSubscribeEvents, TestSize.Level1) entInfo.description = "technology company in wuhan"; std::vector permissions = { "ohos.permission.EDM_TEST_PERMISSION" }; adminMgr_->SetAdminValue(abilityInfo, entInfo, AdminType::NORMAL, permissions, DEFAULT_USER_ID); - ErrCode ret = adminMgr_->RemoveSubscribeEvents(events, admin, DEFAULT_USER_ID); - ASSERT_TRUE(ret == ERR_OK); + adminMgr_->RemoveSubscribeEvents(events, admin, DEFAULT_USER_ID); + ASSERT_TRUE(admin->adminInfo_.managedEvents_.size() == 1); events.push_back(0); - ret = adminMgr_->RemoveSubscribeEvents(events, admin, DEFAULT_USER_ID); - ASSERT_TRUE(ret == ERR_OK); + adminMgr_->RemoveSubscribeEvents(events, admin, DEFAULT_USER_ID); + ASSERT_TRUE(admin->adminInfo_.managedEvents_.empty()); } } // namespace TEST } // namespace EDM