mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 00:20:44 +00:00
commit
5a9a1096c9
@ -101,11 +101,13 @@ private:
|
||||
void PostOnBroadcastBusiness(const std::string& senderNetworkId, uint16_t bundleNameId, uint8_t continueTypeId,
|
||||
const int32_t state, const int32_t delay = 0, const int32_t retry = 0);
|
||||
void FindContinueType(const DmsBundleInfo &distributedBundleInfo, uint8_t &continueTypeId,
|
||||
std::string &continueType);
|
||||
std::string &continueType, DmsAbilityInfo &abilityInfo);
|
||||
int32_t DealOnBroadcastBusiness(const std::string& senderNetworkId, uint16_t bundleNameId, uint8_t continueTypeId,
|
||||
const int32_t state, const int32_t retry = 0);
|
||||
void NotifyRecvBroadcast(const sptr<IRemoteObject>& obj, const currentIconInfo& continueInfo, const int32_t state);
|
||||
bool IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo);
|
||||
bool IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, const std::string &srcAbilityName,
|
||||
const std::string &srcContinueType, bool isSameBundle);
|
||||
std::string ContinueTypeFormat(const std::string &continueType);
|
||||
private:
|
||||
currentIconInfo iconInfo_;
|
||||
sptr<DistributedMissionDiedListener> missionDiedListener_;
|
||||
|
@ -46,6 +46,7 @@ constexpr int32_t DBMS_RETRY_DELAY = 2000;
|
||||
const std::string TAG = "DMSContinueRecvMgr";
|
||||
const std::string DBMS_RETRY_TASK = "retry_on_boradcast_task";
|
||||
const std::u16string DESCRIPTOR = u"ohos.aafwk.RemoteOnListener";
|
||||
const std::string QUICK_START_CONFIGURATION = "_ContinueQuickStart";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(DMSContinueRecvMgr);
|
||||
@ -293,13 +294,14 @@ bool DMSContinueRecvMgr::GetFinalBundleName(DmsBundleInfo &distributedBundleInfo
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::FindContinueType(const DmsBundleInfo &distributedBundleInfo,
|
||||
uint8_t &continueTypeId, std::string &continueType)
|
||||
uint8_t &continueTypeId, std::string &continueType, DmsAbilityInfo &abilityInfo)
|
||||
{
|
||||
uint32_t pos = 0;
|
||||
for (auto dmsAbilityInfo: distributedBundleInfo.dmsAbilityInfos) {
|
||||
for (auto continueTypeElement: dmsAbilityInfo.continueType) {
|
||||
if (pos == continueTypeId) {
|
||||
continueType = continueTypeElement;
|
||||
abilityInfo = dmsAbilityInfo;
|
||||
return;
|
||||
}
|
||||
++pos;
|
||||
@ -327,7 +329,8 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
|
||||
std::string finalBundleName;
|
||||
AppExecFwk::BundleInfo localBundleInfo;
|
||||
std::string continueType;
|
||||
FindContinueType(distributedBundleInfo, continueTypeId, continueType);
|
||||
DmsAbilityInfo abilityInfo;
|
||||
FindContinueType(distributedBundleInfo, continueTypeId, continueType, abilityInfo);
|
||||
if (!GetFinalBundleName(distributedBundleInfo, finalBundleName, localBundleInfo, continueType)) {
|
||||
HILOGE("The app is not installed on the local device.");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
@ -338,7 +341,9 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
|
||||
HILOGE("The bundleType must be app, but it is %{public}d", localBundleInfo.applicationInfo.bundleType);
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
if (!IsBundleContinuable(localBundleInfo)) {
|
||||
bool isSameBundle = (bundleName == finalBundleName);
|
||||
if (state == ACTIVE
|
||||
&& !IsBundleContinuable(localBundleInfo, abilityInfo.abilityName, continueType, isSameBundle)) {
|
||||
HILOGE("Bundle %{public}s is not continuable", finalBundleName.c_str());
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
@ -356,23 +361,48 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter,
|
||||
currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType),
|
||||
state);
|
||||
currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType), state);
|
||||
}
|
||||
HILOGI("DealOnBroadcastBusiness end");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo)
|
||||
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo,
|
||||
const std::string &srcAbilityName, const std::string &srcContinueType, bool isSameBundle)
|
||||
{
|
||||
for (auto abilityInfo : bundleInfo.abilityInfos) {
|
||||
if (abilityInfo.continuable) {
|
||||
return true;
|
||||
std::string formatSrcContinueType = ContinueTypeFormat(srcContinueType);
|
||||
for (auto &abilityInfo: bundleInfo.abilityInfos) {
|
||||
if (!abilityInfo.continuable) {
|
||||
continue;
|
||||
}
|
||||
for (const auto &continueTypeItem: abilityInfo.continueType) {
|
||||
HILOGI("IsBundleContinuable check: srcAbilityName:%{public}s; srcContinueType:%{public}s;"
|
||||
" sinkAbilityName:%{public}s; sinkContinueType:%{public}s; isSameBundle: %{public}d",
|
||||
srcAbilityName.c_str(), srcContinueType.c_str(), abilityInfo.name.c_str(),
|
||||
continueTypeItem.c_str(), isSameBundle);
|
||||
if (continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType) {
|
||||
return true;
|
||||
}
|
||||
if ((srcContinueType == srcAbilityName || abilityInfo.name == continueTypeItem)
|
||||
&& isSameBundle && abilityInfo.name == srcAbilityName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string DMSContinueRecvMgr::ContinueTypeFormat(const std::string &continueType)
|
||||
{
|
||||
std::string suffix = QUICK_START_CONFIGURATION;
|
||||
if (suffix.length() <= continueType.length() &&
|
||||
continueType.rfind(suffix) == (continueType.length() - suffix.length())) {
|
||||
return continueType.substr(0, continueType.rfind(QUICK_START_CONFIGURATION));
|
||||
} else {
|
||||
return continueType + QUICK_START_CONFIGURATION;
|
||||
}
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::NotifyRecvBroadcast(const sptr<IRemoteObject>& obj,
|
||||
const currentIconInfo& continueInfo, const int32_t state)
|
||||
{
|
||||
|
@ -406,6 +406,11 @@ int32_t DMSContinueSendMgr::DealUnfocusedBusiness(const int32_t missionId, Unfoc
|
||||
}
|
||||
uint16_t bundleNameId = 0;
|
||||
uint8_t continueTypeId = 0;
|
||||
ret = BundleManagerInternal::GetContinueTypeId(bundleName, abilityName, continueTypeId);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Get focused contineTypeId failed, contineTypeId: %{public}u, ret: %{public}d", continueTypeId, ret);
|
||||
return ret;
|
||||
}
|
||||
ret = GetAccessTokenIdSendEvent(bundleName, reason, bundleNameId, continueTypeId);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("GetAccessTokenIdSendEvent failed");
|
||||
|
@ -970,6 +970,167 @@ HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1)
|
||||
DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIsBundleContinuable_001
|
||||
* @tc.desc: all continuable = false => res = false
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
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<AppExecFwk::AbilityInfo> abilityInfos;
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::vector<std::string> continueTypes;
|
||||
continueTypes.push_back(srcContinueType);
|
||||
abilityInfo.continueType = continueTypes;
|
||||
abilityInfo.continuable = false;
|
||||
abilityInfo.name = srcAbilityName;
|
||||
abilityInfos.push_back(abilityInfo);
|
||||
|
||||
localBundleInfo.abilityInfos = abilityInfos;
|
||||
bool ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, false);
|
||||
|
||||
isSameBundle = false;
|
||||
ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIsBundleContinuable_002
|
||||
* @tc.desc: continuable = true; same continueType => res = true
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
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<AppExecFwk::AbilityInfo> abilityInfos;
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::vector<std::string> continueTypes;
|
||||
continueTypes.push_back(srcContinueType + "_ContinueQuickStart");
|
||||
abilityInfo.continueType = continueTypes;
|
||||
abilityInfo.continuable = true;
|
||||
abilityInfo.name = srcAbilityName;
|
||||
abilityInfos.push_back(abilityInfo);
|
||||
|
||||
localBundleInfo.abilityInfos = abilityInfos;
|
||||
bool ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, true);
|
||||
|
||||
isSameBundle = false;
|
||||
ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, true);
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIsBundleContinuable_003
|
||||
* @tc.desc: continuable = true; diff continueType; diff BundleName => res = false;
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_003 start" << std::endl;
|
||||
std::string srcAbilityName = "srcAbilityName";
|
||||
std::string sinkAbilityName = "sinkAbilityName";
|
||||
std::string srcContinueType = "srcContinueType";
|
||||
std::string sinkContinueType = "sinkContinueType";
|
||||
bool isSameBundle = false;
|
||||
|
||||
AppExecFwk::BundleInfo localBundleInfo;
|
||||
std::vector<AppExecFwk::AbilityInfo> abilityInfos;
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::vector<std::string> continueTypes;
|
||||
continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
|
||||
abilityInfo.continueType = continueTypes;
|
||||
abilityInfo.continuable = true;
|
||||
abilityInfo.name = sinkAbilityName;
|
||||
abilityInfos.push_back(abilityInfo);
|
||||
|
||||
localBundleInfo.abilityInfos = abilityInfos;
|
||||
bool ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIsBundleContinuable_004
|
||||
* @tc.desc: continuable = true; diff continueType; same BundleName => res = false;
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 start" << std::endl;
|
||||
std::string srcAbilityName = "srcAbilityName";
|
||||
std::string sinkAbilityName = "sinkAbilityName";
|
||||
std::string srcContinueType = srcAbilityName;
|
||||
std::string sinkContinueType = "sinkContinueType";
|
||||
bool isSameBundle = true;
|
||||
|
||||
AppExecFwk::BundleInfo localBundleInfo;
|
||||
std::vector<AppExecFwk::AbilityInfo> abilityInfos;
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::vector<std::string> continueTypes;
|
||||
continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
|
||||
abilityInfo.continueType = continueTypes;
|
||||
abilityInfo.continuable = true;
|
||||
abilityInfo.name = sinkAbilityName;
|
||||
abilityInfos.push_back(abilityInfo);
|
||||
|
||||
localBundleInfo.abilityInfos = abilityInfos;
|
||||
bool ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIsBundleContinuable_005
|
||||
* @tc.desc: continuable = true; no src continueType; same BundleName => res = false;
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 start" << std::endl;
|
||||
std::string srcAbilityName = "srcAbilityName";
|
||||
std::string sinkAbilityName = "sinkAbilityName";
|
||||
std::string srcContinueType = srcAbilityName;
|
||||
std::string sinkContinueType = "sinkContinueType";
|
||||
bool isSameBundle = true;
|
||||
|
||||
AppExecFwk::BundleInfo localBundleInfo;
|
||||
std::vector<AppExecFwk::AbilityInfo> abilityInfos;
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::vector<std::string> continueTypes;
|
||||
continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
|
||||
abilityInfo.continueType = continueTypes;
|
||||
abilityInfo.continuable = true;
|
||||
abilityInfo.name = srcAbilityName;
|
||||
abilityInfos.push_back(abilityInfo);
|
||||
|
||||
localBundleInfo.abilityInfos = abilityInfos;
|
||||
bool ret = DMSContinueRecvMgr::GetInstance().IsBundleContinuable(localBundleInfo, srcAbilityName,
|
||||
srcContinueType, isSameBundle);
|
||||
EXPECT_EQ(ret, true);
|
||||
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetBundleNameByScreenOffInfo_001
|
||||
* @tc.desc: test GetBundleNameByScreenOffInfo
|
||||
|
Loading…
Reference in New Issue
Block a user