异moduleName可接续

Signed-off-by: MisterE <smart_e@126.com>
This commit is contained in:
MisterE 2024-11-21 14:11:46 +08:00
parent bdcc54abc3
commit 0a72ac8ec9
5 changed files with 81 additions and 110 deletions

View File

@ -154,6 +154,9 @@ private:
int32_t ExecuteContinueReply(); int32_t ExecuteContinueReply();
int32_t ExecuteContinueSend(std::shared_ptr<ContinueAbilityData> data); int32_t ExecuteContinueSend(std::shared_ptr<ContinueAbilityData> data);
int32_t ExecuteContinueData(std::shared_ptr<DSchedContinueDataCmd> cmd); int32_t ExecuteContinueData(std::shared_ptr<DSchedContinueDataCmd> cmd);
int32_t UpdateElementInfo(std::shared_ptr<DSchedContinueDataCmd> cmd);
void FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType,
std::vector<DmsAbilityInfo> &dmsAbilityInfos, std::vector<DmsAbilityInfo> &result);
int32_t ExecuteNotifyComplete(int32_t result); int32_t ExecuteNotifyComplete(int32_t result);
int32_t ExecuteContinueEnd(int32_t result); int32_t ExecuteContinueEnd(int32_t result);
int32_t ExecuteContinueError(int32_t result); int32_t ExecuteContinueError(int32_t result);
@ -165,9 +168,6 @@ private:
uint32_t accessToken); uint32_t accessToken);
int32_t OnContinueDataCmd(std::shared_ptr<DSchedContinueDataCmd> cmd); int32_t OnContinueDataCmd(std::shared_ptr<DSchedContinueDataCmd> cmd);
int32_t OnNotifyComplete(int32_t missionId, bool isSuccess); int32_t OnNotifyComplete(int32_t missionId, bool isSuccess);
int32_t UpdateElementInfo(std::shared_ptr<DSchedContinueDataCmd> cmd);
void FindSinkContinueAbilityInfo(const std::string &srcModuleName, const std::string &srcContinueType,
std::vector<DmsAbilityInfo> &dmsAbilityInfos, std::vector<DmsAbilityInfo> &result);
void ContinueTypeFormat(std::string &continueType); void ContinueTypeFormat(std::string &continueType);
int32_t OnContinueEndCmd(std::shared_ptr<DSchedContinueEndCmd> cmd); int32_t OnContinueEndCmd(std::shared_ptr<DSchedContinueEndCmd> cmd);
int32_t OnContinueEnd(int32_t result); int32_t OnContinueEnd(int32_t result);

View File

@ -105,7 +105,7 @@ private:
const int32_t state, const int32_t retry = 0); const int32_t state, const int32_t retry = 0);
void NotifyRecvBroadcast(const sptr<IRemoteObject>& obj, const currentIconInfo& continueInfo, const int32_t state); void NotifyRecvBroadcast(const sptr<IRemoteObject>& obj, const currentIconInfo& continueInfo, const int32_t state);
bool IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, const std::string &srcAbilityName, 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); std::string ContinueTypeFormat(const std::string &continueType);
void FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName, void FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName,
const std::string& continueType); const std::string& continueType);

View File

@ -421,82 +421,7 @@ int32_t DSchedContinue::OnNotifyComplete(int32_t missionId, bool isSuccess)
return ERR_OK; return ERR_OK;
} }
int32_t DSchedContinue::UpdateElementInfo(std::shared_ptr<DSchedContinueDataCmd> 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<DmsAbilityInfo> dmsAbilityInfos = distributedBundleInfo.dmsAbilityInfos;
std::vector<DmsAbilityInfo> 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<DmsAbilityInfo> &dmsAbilityInfos, std::vector<DmsAbilityInfo> &result)
{
bool sameAbilityGot = false;
bool hasSameModule = false;
for (const auto &abilityInfoElement: dmsAbilityInfos) {
std::vector<std::string> 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) void DSchedContinue::ContinueTypeFormat(std::string &continueType)
{ {
@ -1055,6 +980,75 @@ int32_t DSchedContinue::ExecuteContinueData(std::shared_ptr<DSchedContinueDataCm
return ret; return ret;
} }
int32_t DSchedContinue::UpdateElementInfo(std::shared_ptr<DSchedContinueDataCmd> 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<DmsAbilityInfo> dmsAbilityInfos = distributedBundleInfo.dmsAbilityInfos;
std::vector<DmsAbilityInfo> 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<DmsAbilityInfo> &dmsAbilityInfos, std::vector<DmsAbilityInfo> &result)
{
bool sameModuleGot = false;
for (const auto &abilityInfoElement: dmsAbilityInfos) {
std::vector<std::string> 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) int32_t DSchedContinue::UpdateWantForContinueType(OHOS::AAFwk::Want& want)
{ {
std::string srcAbilityName = want.GetElement().GetAbilityName(); std::string srcAbilityName = want.GetElement().GetAbilityName();

View File

@ -360,7 +360,7 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
} }
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, 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); std::string formatSrcContinueType = ContinueTypeFormat(srcContinueType);
for (auto &abilityInfo: bundleInfo.abilityInfos) { for (auto &abilityInfo: bundleInfo.abilityInfos) {
@ -369,16 +369,12 @@ bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundl
} }
for (const auto &continueTypeItem: abilityInfo.continueType) { for (const auto &continueTypeItem: abilityInfo.continueType) {
HILOGI("IsBundleContinuable check: srcAbilityName:%{public}s; srcContinueType:%{public}s;" 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(), srcAbilityName.c_str(), srcContinueType.c_str(), abilityInfo.name.c_str(),
continueTypeItem.c_str(), isSameBundle); continueTypeItem.c_str());
if (continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType) { if (continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType) {
return true; return true;
} }
if ((srcContinueType == srcAbilityName || abilityInfo.name == continueTypeItem)
&& isSameBundle && abilityInfo.name == srcAbilityName) {
return true;
}
} }
} }
return false; return false;

View File

@ -1197,7 +1197,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 start" << std::endl; DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 start" << std::endl;
std::string srcAbilityName = "abilityName"; std::string srcAbilityName = "abilityName";
std::string srcContinueType = "continueType"; std::string srcContinueType = "continueType";
bool isSameBundle = true;
AppExecFwk::BundleInfo localBundleInfo; AppExecFwk::BundleInfo localBundleInfo;
std::vector<AppExecFwk::AbilityInfo> abilityInfos; std::vector<AppExecFwk::AbilityInfo> abilityInfos;
@ -1215,14 +1214,9 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1)
DTEST_LOG << "GetRecvMgr failed." << std::endl; DTEST_LOG << "GetRecvMgr failed." << std::endl;
return; return;
} }
bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType);
srcContinueType, isSameBundle);
EXPECT_EQ(ret, false); 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; 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; DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 start" << std::endl;
std::string srcAbilityName = "abilityName"; std::string srcAbilityName = "abilityName";
std::string srcContinueType = "continueType"; std::string srcContinueType = "continueType";
bool isSameBundle = true;
AppExecFwk::BundleInfo localBundleInfo; AppExecFwk::BundleInfo localBundleInfo;
std::vector<AppExecFwk::AbilityInfo> abilityInfos; std::vector<AppExecFwk::AbilityInfo> abilityInfos;
@ -1254,13 +1247,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1)
DTEST_LOG << "GetRecvMgr failed." << std::endl; DTEST_LOG << "GetRecvMgr failed." << std::endl;
return; return;
} }
bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType);
srcContinueType, isSameBundle);
EXPECT_EQ(ret, true);
isSameBundle = false;
ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName,
srcContinueType, isSameBundle);
EXPECT_EQ(ret, true); EXPECT_EQ(ret, true);
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl; 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 sinkAbilityName = "sinkAbilityName";
std::string srcContinueType = "srcContinueType"; std::string srcContinueType = "srcContinueType";
std::string sinkContinueType = "sinkContinueType"; std::string sinkContinueType = "sinkContinueType";
bool isSameBundle = false;
AppExecFwk::BundleInfo localBundleInfo; AppExecFwk::BundleInfo localBundleInfo;
std::vector<AppExecFwk::AbilityInfo> abilityInfos; std::vector<AppExecFwk::AbilityInfo> abilityInfos;
@ -1295,8 +1281,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1)
DTEST_LOG << "GetRecvMgr failed." << std::endl; DTEST_LOG << "GetRecvMgr failed." << std::endl;
return; return;
} }
bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType);
srcContinueType, isSameBundle);
EXPECT_EQ(ret, false); EXPECT_EQ(ret, false);
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl; 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 sinkAbilityName = "sinkAbilityName";
std::string srcContinueType = srcAbilityName; std::string srcContinueType = srcAbilityName;
std::string sinkContinueType = "sinkContinueType"; std::string sinkContinueType = "sinkContinueType";
bool isSameBundle = true;
AppExecFwk::BundleInfo localBundleInfo; AppExecFwk::BundleInfo localBundleInfo;
std::vector<AppExecFwk::AbilityInfo> abilityInfos; std::vector<AppExecFwk::AbilityInfo> abilityInfos;
@ -1331,8 +1315,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1)
DTEST_LOG << "GetRecvMgr failed." << std::endl; DTEST_LOG << "GetRecvMgr failed." << std::endl;
return; return;
} }
bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType);
srcContinueType, isSameBundle);
EXPECT_EQ(ret, false); EXPECT_EQ(ret, false);
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 end" << std::endl; 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 sinkAbilityName = "sinkAbilityName";
std::string srcContinueType = srcAbilityName; std::string srcContinueType = srcAbilityName;
std::string sinkContinueType = "sinkContinueType"; std::string sinkContinueType = "sinkContinueType";
bool isSameBundle = true;
AppExecFwk::BundleInfo localBundleInfo; AppExecFwk::BundleInfo localBundleInfo;
std::vector<AppExecFwk::AbilityInfo> abilityInfos; std::vector<AppExecFwk::AbilityInfo> abilityInfos;
@ -1367,8 +1349,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1)
DTEST_LOG << "GetRecvMgr failed." << std::endl; DTEST_LOG << "GetRecvMgr failed." << std::endl;
return; return;
} }
bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType);
srcContinueType, isSameBundle);
EXPECT_EQ(ret, true); EXPECT_EQ(ret, true);
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl; DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl;
} }