diff --git a/services/dtbschedmgr/include/continue/dsched_continue.h b/services/dtbschedmgr/include/continue/dsched_continue.h index dfb5ecd1..ecf687db 100644 --- a/services/dtbschedmgr/include/continue/dsched_continue.h +++ b/services/dtbschedmgr/include/continue/dsched_continue.h @@ -154,6 +154,9 @@ private: int32_t ExecuteContinueReply(); int32_t ExecuteContinueSend(std::shared_ptr data); int32_t ExecuteContinueData(std::shared_ptr cmd); + int32_t UpdateElementInfo(std::shared_ptr cmd); + void FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType, + std::vector &dmsAbilityInfos, std::vector &result); int32_t ExecuteNotifyComplete(int32_t result); int32_t ExecuteContinueEnd(int32_t result); int32_t ExecuteContinueError(int32_t result); @@ -165,9 +168,6 @@ private: uint32_t accessToken); int32_t OnContinueDataCmd(std::shared_ptr cmd); int32_t OnNotifyComplete(int32_t missionId, bool isSuccess); - int32_t UpdateElementInfo(std::shared_ptr cmd); - void FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType, - std::vector &dmsAbilityInfos, std::vector &result); void ContinueTypeFormat(std::string &continueType); int32_t OnContinueEndCmd(std::shared_ptr cmd); int32_t OnContinueEnd(int32_t result); diff --git a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h index 242c9970..124fcf77 100644 --- a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h +++ b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h @@ -105,7 +105,7 @@ private: const int32_t state, const int32_t retry = 0); void NotifyRecvBroadcast(const sptr& obj, const currentIconInfo& continueInfo, const int32_t state); bool IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, const std::string &srcAbilityName, - const std::string &srcContinueType, bool isSameBundle); + const std::string &srcContinueType); std::string ContinueTypeFormat(const std::string &continueType); void FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName, const std::string& continueType); diff --git a/services/dtbschedmgr/src/continue/dsched_continue.cpp b/services/dtbschedmgr/src/continue/dsched_continue.cpp index ab0996a6..78bb97df 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue.cpp @@ -421,82 +421,7 @@ int32_t DSchedContinue::OnNotifyComplete(int32_t missionId, bool isSuccess) return ERR_OK; } -int32_t DSchedContinue::UpdateElementInfo(std::shared_ptr cmd) -{ - std::string srcModuleName = cmd->want_.GetModuleName(); - if (srcModuleName.empty()) { - HILOGD("UpdateElementInfo srcModuleName from element is empty"); - srcModuleName = cmd->want_.GetStringParam(OHOS::AAFwk::Want::PARAM_MODULE_NAME); - } - std::string srcContinueType = cmd->continueType_; - ContinueTypeFormat(srcContinueType); - HILOGD("UpdateElementInfo srcModuleName: %{public}s; srcContinueType:%{public}s", srcModuleName.c_str(), - srcContinueType.c_str()); - DmsBundleInfo distributedBundleInfo; - std::string localDeviceId; - if (!GetLocalDeviceId(localDeviceId) || !DmsBmStorage::GetInstance()->GetDistributedBundleInfo( - localDeviceId, cmd->dstBundleName_, distributedBundleInfo)) { - HILOGE("UpdateElementInfo can not found bundle info for bundle name: %{public}s", - cmd->dstBundleName_.c_str()); - return CAN_NOT_FOUND_MODULE_ERR; - } - std::vector dmsAbilityInfos = distributedBundleInfo.dmsAbilityInfos; - std::vector result; - FindSinkContinueAbilityInfo(srcModuleName, srcContinueType, dmsAbilityInfos, result); - if (result.empty()) { - HILOGE("UpdateElementInfo can not found bundle info for bundle name: %{public}s", - cmd->dstBundleName_.c_str()); - return CAN_NOT_FOUND_MODULE_ERR; - } - auto element = cmd->want_.GetElement(); - DmsAbilityInfo finalAbility = result[0]; - HILOGD("UpdateElementInfo final sink ability detail info: " - "bundleName: %{public}s; abilityName: %{public}s; moduleName: %{public}s", - cmd->dstBundleName_.c_str(), finalAbility.abilityName.c_str(), finalAbility.moduleName.c_str()); - cmd->want_.SetElementName(element.GetDeviceID(), cmd->dstBundleName_, finalAbility.abilityName, - finalAbility.moduleName); - return ERR_OK; -} - -void DSchedContinue::FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType, - std::vector &dmsAbilityInfos, std::vector &result) -{ - bool sameAbilityGot = false; - bool hasSameModule = false; - for (const auto &abilityInfoElement: dmsAbilityInfos) { - std::vector continueTypes = abilityInfoElement.continueType; - for (std::string &continueTypeElement: continueTypes) { - ContinueTypeFormat(continueTypeElement); - HILOGD("UpdateElementInfo check sink continue ability, current: " - "continueType: %{public}s; abilityName: %{public}s; moduleName: %{public}s", - continueTypeElement.c_str(), abilityInfoElement.abilityName.c_str(), - abilityInfoElement.moduleName.c_str()); - if (continueTypeElement != srcContinueType) { - continue; - } - if (continueTypeElement == abilityInfoElement.abilityName && - srcModuleName == abilityInfoElement.moduleName) { - sameAbilityGot = true; - result.clear(); - result.push_back(abilityInfoElement); - break; - } else if (continueTypeElement != abilityInfoElement.abilityName && - srcModuleName == abilityInfoElement.moduleName) { - hasSameModule = true; - result.clear(); - result.push_back(abilityInfoElement); - break; - } else if (continueTypeElement != abilityInfoElement.abilityName) { - result.push_back(abilityInfoElement); - break; - } - } - if (sameAbilityGot || hasSameModule) { - break; - } - } -} void DSchedContinue::ContinueTypeFormat(std::string &continueType) { @@ -1055,6 +980,75 @@ int32_t DSchedContinue::ExecuteContinueData(std::shared_ptr cmd) +{ + std::string srcModuleName = cmd->want_.GetModuleName(); + if (srcModuleName.empty()) { + HILOGD("UpdateElementInfo srcModuleName from element is empty"); + srcModuleName = cmd->want_.GetStringParam(OHOS::AAFwk::Want::PARAM_MODULE_NAME); + } + std::string srcContinueType = cmd->continueType_; + ContinueTypeFormat(srcContinueType); + HILOGD("UpdateElementInfo srcModuleName: %{public}s; srcContinueType:%{public}s", srcModuleName.c_str(), + srcContinueType.c_str()); + DmsBundleInfo distributedBundleInfo; + std::string localDeviceId; + if (!GetLocalDeviceId(localDeviceId) || !DmsBmStorage::GetInstance()->GetDistributedBundleInfo( + localDeviceId, cmd->dstBundleName_, distributedBundleInfo)) { + HILOGE("UpdateElementInfo can not found bundle info for bundle name: %{public}s", + cmd->dstBundleName_.c_str()); + return CAN_NOT_FOUND_MODULE_ERR; + } + + std::vector dmsAbilityInfos = distributedBundleInfo.dmsAbilityInfos; + std::vector result; + FindSinkContinueAbilityInfo(srcModuleName, srcContinueType, dmsAbilityInfos, result); + if (result.empty()) { + HILOGE("UpdateElementInfo can not found bundle info for bundle name: %{public}s", + cmd->dstBundleName_.c_str()); + return CAN_NOT_FOUND_MODULE_ERR; + } + auto element = cmd->want_.GetElement(); + DmsAbilityInfo finalAbility = result[0]; + HILOGD("UpdateElementInfo final sink ability detail info: " + "bundleName: %{public}s; abilityName: %{public}s; moduleName: %{public}s", + cmd->dstBundleName_.c_str(), finalAbility.abilityName.c_str(), finalAbility.moduleName.c_str()); + cmd->want_.SetElementName(element.GetDeviceID(), cmd->dstBundleName_, finalAbility.abilityName, + finalAbility.moduleName); + return ERR_OK; +} + +void DSchedContinue::FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType, + std::vector &dmsAbilityInfos, std::vector &result) +{ + bool sameModuleGot = false; + for (const auto &abilityInfoElement: dmsAbilityInfos) { + std::vector continueTypes = abilityInfoElement.continueType; + for (std::string &continueTypeElement: continueTypes) { + ContinueTypeFormat(continueTypeElement); + HILOGD("UpdateElementInfo check sink continue ability, current: " + "continueType: %{public}s; abilityName: %{public}s; moduleName: %{public}s", + continueTypeElement.c_str(), abilityInfoElement.abilityName.c_str(), + abilityInfoElement.moduleName.c_str()); + if (continueTypeElement != srcContinueType) { + continue; + } + if (srcModuleName == abilityInfoElement.moduleName) { + sameModuleGot = true; + result.clear(); + result.push_back(abilityInfoElement); + break; + } else { + result.push_back(abilityInfoElement); + break; + } + } + if (sameModuleGot) { + break; + } + } +} + int32_t DSchedContinue::UpdateWantForContinueType(OHOS::AAFwk::Want& want) { std::string srcAbilityName = want.GetElement().GetAbilityName(); diff --git a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp index 35539618..fe3dc065 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp @@ -360,7 +360,7 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet } bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, - const std::string &srcAbilityName, const std::string &srcContinueType, bool isSameBundle) + const std::string &srcAbilityName, const std::string &srcContinueType) { std::string formatSrcContinueType = ContinueTypeFormat(srcContinueType); for (auto &abilityInfo: bundleInfo.abilityInfos) { @@ -369,16 +369,12 @@ bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundl } for (const auto &continueTypeItem: abilityInfo.continueType) { HILOGI("IsBundleContinuable check: srcAbilityName:%{public}s; srcContinueType:%{public}s;" - " sinkAbilityName:%{public}s; sinkContinueType:%{public}s; isSameBundle: %{public}d", + " sinkAbilityName:%{public}s; sinkContinueType:%{public}s; ", srcAbilityName.c_str(), srcContinueType.c_str(), abilityInfo.name.c_str(), - continueTypeItem.c_str(), isSameBundle); + continueTypeItem.c_str()); if (continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType) { return true; } - if ((srcContinueType == srcAbilityName || abilityInfo.name == continueTypeItem) - && isSameBundle && abilityInfo.name == srcAbilityName) { - return true; - } } } return false; 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 fbf6dad4..dbcd4de2 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -1197,7 +1197,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 start" << std::endl; std::string srcAbilityName = "abilityName"; std::string srcContinueType = "continueType"; - bool isSameBundle = true; AppExecFwk::BundleInfo localBundleInfo; std::vector abilityInfos; @@ -1215,14 +1214,9 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1) DTEST_LOG << "GetRecvMgr failed." << std::endl; return; } - bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); + bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType); EXPECT_EQ(ret, false); - isSameBundle = false; - ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); - EXPECT_EQ(ret, false); DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 end" << std::endl; } @@ -1236,7 +1230,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 start" << std::endl; std::string srcAbilityName = "abilityName"; std::string srcContinueType = "continueType"; - bool isSameBundle = true; AppExecFwk::BundleInfo localBundleInfo; std::vector abilityInfos; @@ -1254,13 +1247,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1) DTEST_LOG << "GetRecvMgr failed." << std::endl; return; } - bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); - EXPECT_EQ(ret, true); - - isSameBundle = false; - ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); + bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType); EXPECT_EQ(ret, true); DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl; } @@ -1277,7 +1264,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1) std::string sinkAbilityName = "sinkAbilityName"; std::string srcContinueType = "srcContinueType"; std::string sinkContinueType = "sinkContinueType"; - bool isSameBundle = false; AppExecFwk::BundleInfo localBundleInfo; std::vector abilityInfos; @@ -1295,8 +1281,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1) DTEST_LOG << "GetRecvMgr failed." << std::endl; return; } - bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); + bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType); EXPECT_EQ(ret, false); DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl; } @@ -1313,7 +1298,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1) std::string sinkAbilityName = "sinkAbilityName"; std::string srcContinueType = srcAbilityName; std::string sinkContinueType = "sinkContinueType"; - bool isSameBundle = true; AppExecFwk::BundleInfo localBundleInfo; std::vector abilityInfos; @@ -1331,8 +1315,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1) DTEST_LOG << "GetRecvMgr failed." << std::endl; return; } - bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); + bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType); EXPECT_EQ(ret, false); DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 end" << std::endl; } @@ -1349,7 +1332,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1) std::string sinkAbilityName = "sinkAbilityName"; std::string srcContinueType = srcAbilityName; std::string sinkContinueType = "sinkContinueType"; - bool isSameBundle = true; AppExecFwk::BundleInfo localBundleInfo; std::vector abilityInfos; @@ -1367,8 +1349,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1) DTEST_LOG << "GetRecvMgr failed." << std::endl; return; } - bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, - srcContinueType, isSameBundle); + bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType); EXPECT_EQ(ret, true); DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl; }