diff --git a/services/dtbschedmgr/include/mission/distributed_sched_continue_manager.h b/services/dtbschedmgr/include/mission/distributed_sched_continue_manager.h index b36c9ae3..308cf13a 100644 --- a/services/dtbschedmgr/include/mission/distributed_sched_continue_manager.h +++ b/services/dtbschedmgr/include/mission/distributed_sched_continue_manager.h @@ -38,6 +38,12 @@ struct currentMissionInfo { int32_t currentMissionId; bool currentIsContinuable; }; + +struct currentIconInfo { + std::string senderNetworkId; + std::string bundleName; +}; + class DistributedSchedContinueManager { DECLARE_SINGLE_INSTANCE(DistributedSchedContinueManager); @@ -63,7 +69,7 @@ public: int32_t RegisterOffListener(const std::string& type, const sptr& obj); int32_t GetMissionId(const std::string& bundleName, int32_t& missionId); void NotifyDeid(const sptr& obj); - int32_t SetMissionContinueState(const int32_t missionId, const AAFwk::ContinueState &state); + int32_t SetMissionContinueState(const int32_t missionId, const AAFwk::ContinueState& state); private: void AddCancelMissionFocusedTimer(const int32_t missionId); @@ -71,15 +77,17 @@ private: void StartEvent(); int32_t DealFocusedBusiness(const int32_t missionId); int32_t DealUnfocusedBusiness(const int32_t missionId, bool isUnfocused); - int32_t DealUnBroadcastdBusiness(std::string& senderNetworkId, uint32_t accessTokenId, const int32_t state); + int32_t VerifyBroadcastSource(std::string& senderNetworkId, std::string& bundleName, const int32_t state); + int32_t DealOnBroadcastBusiness(std::string& senderNetworkId, uint32_t accessTokenId, const int32_t state); void NotifyRecvBroadcast(const sptr& obj, const std::string& networkId, const std::string& bundleName, const int32_t state); int32_t GetBundleName(const int32_t missionId, std::string& bundleName); bool IsContinue(const int32_t& missionId, const std::string& bundleName); - int32_t DealSetMissionContinueStateBusiness(const int32_t missionId, const AAFwk::ContinueState &state); + int32_t DealSetMissionContinueStateBusiness(const int32_t missionId, const AAFwk::ContinueState& state); int32_t CheckContinueState(const int32_t missionId); private: currentMissionInfo info_ = { INVALID_MISSION_ID, false }; + currentIconInfo iconInfo_; sptr missionFocusedListener_; sptr missionDiedListener_; std::string onType_; @@ -88,6 +96,7 @@ private: std::thread eventThread_; std::condition_variable eventCon_; std::mutex eventMutex_; + std::mutex iconMutex_; std::shared_ptr eventHandler_; }; } // namespace DistributedSchedule diff --git a/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp b/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp index 499af49a..a53391ba 100644 --- a/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp +++ b/services/dtbschedmgr/src/mission/distributed_sched_continue_manager.cpp @@ -146,7 +146,7 @@ void DistributedSchedContinueManager::NotifyDataRecv(std::string& senderNetworkI state = INACTIVE; } auto feedfunc = [this, senderNetworkId, accessTokenId, state]() mutable { - DealUnBroadcastdBusiness(senderNetworkId, accessTokenId, state); + DealOnBroadcastBusiness(senderNetworkId, accessTokenId, state); }; if (eventHandler_ != nullptr) { eventHandler_->PostTask(feedfunc); @@ -364,10 +364,36 @@ int32_t DistributedSchedContinueManager::DealUnfocusedBusiness(const int32_t mis return ERR_OK; } -int32_t DistributedSchedContinueManager::DealUnBroadcastdBusiness(std::string& senderNetworkId, +int32_t DistributedSchedContinueManager::VerifyBroadcastSource(std::string& senderNetworkId, std::string& bundleName, + const int32_t state) +{ + std::lock_guard currentIconLock(iconMutex_); + if (state == ACTIVE) { + iconInfo_.senderNetworkId = senderNetworkId; + iconInfo_.bundleName = bundleName; + } else { + if (senderNetworkId != iconInfo_.senderNetworkId) { + HILOGE("Sender not match, task abort. senderNetworkId: %{public}s, saved NetworkId: %{public}s", + DnetworkAdapter::AnonymizeNetworkId(senderNetworkId).c_str(), + DnetworkAdapter::AnonymizeNetworkId(iconInfo_.senderNetworkId).c_str()); + return INVALID_PARAMETERS_ERR; + } + + if (bundleName != iconInfo_.bundleName) { + HILOGE("BundleName not match, task abort. bundleName: %{public}s, saved bundleName: %{public}s", + bundleName.c_str(), iconInfo_.bundleName.c_str()); + return INVALID_PARAMETERS_ERR; + } + iconInfo_.senderNetworkId = ""; + iconInfo_.bundleName = ""; + } + return ERR_OK; +} + +int32_t DistributedSchedContinueManager::DealOnBroadcastBusiness(std::string& senderNetworkId, uint32_t accessTokenId, const int32_t state) { - HILOGI("DealUnBroadcastdBusiness start, senderNetworkId: %{public}s, accessTokenId: %{public}d, state: %{public}d", + HILOGI("DealOnBroadcastBusiness start, senderNetworkId: %{public}s, accessTokenId: %{public}d, state: %{public}d", DnetworkAdapter::AnonymizeNetworkId(senderNetworkId).c_str(), accessTokenId, state); std::string bundleName; int32_t ret = BundleManagerInternal::GetBundleNameFromDbms(senderNetworkId, accessTokenId, bundleName); @@ -386,6 +412,10 @@ int32_t DistributedSchedContinueManager::DealUnBroadcastdBusiness(std::string& s HILOGE("The bundleType must be app, but it is %{public}d", localBundleInfo.applicationInfo.bundleType); return INVALID_PARAMETERS_ERR; } + ret = VerifyBroadcastSource(senderNetworkId, bundleName, state); + if (ret != ERR_OK) { + return ret; + } std::lock_guard registerOnListenerMapLock(eventMutex_); auto iterItem = registerOnListener_.find(onType_); if (iterItem == registerOnListener_.end()) { @@ -396,7 +426,7 @@ int32_t DistributedSchedContinueManager::DealUnBroadcastdBusiness(std::string& s for (auto iter : objs) { NotifyRecvBroadcast(iter, senderNetworkId, bundleName, state); } - HILOGI("DealUnBroadcastdBusiness end"); + HILOGI("DealOnBroadcastBusiness end"); return ERR_OK; } diff --git a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp index 24440d4b..8f7008fc 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -32,6 +32,8 @@ const std::string BUNDLENAME_01 = "bundleName01"; const std::string BUNDLENAME_02 = "bundleName02"; constexpr int32_t MISSIONID_01 = 1; constexpr int32_t MISSIONID_02 = 2; +constexpr int32_t ACTIVE = 0; +constexpr int32_t INACTIVE = 1; } void DMSContinueManagerTest::SetUpTestCase() @@ -307,22 +309,84 @@ HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3) } /** - * @tc.name: testDealUnBroadcastdBusiness001 - * @tc.desc: test DealUnBroadcastdBusiness. + * @tc.name: testVerifyBroadcastSource001 + * @tc.desc: test testVerifyBroadcastSource001. + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3) +{ + DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource001 start" << std::endl; + + int32_t state = ACTIVE; + std::string networkId = "test networkId"; + std::string bundleName = "test bundleName"; + int32_t ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, ERR_OK); + + state = INACTIVE; + ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.name: testVerifyBroadcastSource002 + * @tc.desc: test testVerifyBroadcastSource002. + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3) +{ + DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource002 start" << std::endl; + + int32_t state = ACTIVE; + std::string networkId = "test networkId"; + std::string bundleName = "test bundleName"; + int32_t ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, ERR_OK); + + state = INACTIVE; + networkId = "invalid networkId"; + ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); +} + +/** + * @tc.name: testVerifyBroadcastSource003 + * @tc.desc: test testVerifyBroadcastSource003. + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3) +{ + DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource003 start" << std::endl; + + int32_t state = ACTIVE; + std::string networkId = "test networkId"; + std::string bundleName = "test bundleName"; + int32_t ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, ERR_OK); + + state = INACTIVE; + bundleName = "invalid bundleName"; + ret = DistributedSchedContinueManager::GetInstance().VerifyBroadcastSource(networkId, bundleName, state); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); +} + +/** + * @tc.name: testDealOnBroadcastBusiness001 + * @tc.desc: test DealOnBroadcastBusiness. * @tc.type: FUNC * @tc.require: I7F8KH */ -HWTEST_F(DMSContinueManagerTest, testDealUnBroadcastdBusiness001, TestSize.Level3) +HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3) { - DTEST_LOG << "DMSContinueManagerTest testDealUnBroadcastdBusiness001 start" << std::endl; + DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 start" << std::endl; /** - * @tc.steps: step1. test DealUnBroadcastdBusiness when senderNetworkId is invalid; + * @tc.steps: step1. test DealOnBroadcastBusiness when senderNetworkId is invalid; */ std::string senderNetworkId = "invalid senderNetworkId"; uint32_t accessTokenId = 0; int32_t state = 0; - int32_t ret = DistributedSchedContinueManager::GetInstance().DealUnBroadcastdBusiness( + int32_t ret = DistributedSchedContinueManager::GetInstance().DealOnBroadcastBusiness( senderNetworkId, accessTokenId, state); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -340,7 +404,7 @@ HWTEST_F(DMSContinueManagerTest, testDealUnBroadcastdBusiness001, TestSize.Level obj = new RemoteOnListenerStubTest(); DistributedSchedContinueManager::GetInstance().NotifyRecvBroadcast(obj, networkId, bundleName, state); - DTEST_LOG << "DMSContinueManagerTest testDealUnBroadcastdBusiness001 end" << std::endl; + DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 end" << std::endl; } /**