接续拦截优化

Signed-off-by: MisterE <smart_e@126.com>
This commit is contained in:
openharmony_ci 2024-10-24 08:50:55 +00:00 committed by MisterE
commit 487e6ec292
10 changed files with 69 additions and 39 deletions

View File

@ -142,7 +142,7 @@ private:
int32_t PostStartTask(const OHOS::AAFwk::WantParams& wantParams);
int32_t PostReplyTask(std::shared_ptr<DSchedContinueReplyCmd> cmd);
int32_t PostCotinueAbilityTask(uint32_t appVersion);
int32_t PostCotinueAbilityTask(int32_t appVersion);
int32_t PostContinueSendTask(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t status,
uint32_t accessToken);
int32_t PostContinueDataTask(std::shared_ptr<DSchedContinueDataCmd> cmd);
@ -150,7 +150,7 @@ private:
int32_t PostContinueEndTask(int32_t result);
int32_t ExecuteContinueReq(std::shared_ptr<DistributedWantParams> wantParams);
int32_t ExecuteContinueAbility(uint32_t appVersion);
int32_t ExecuteContinueAbility(int32_t appVersion);
int32_t ExecuteContinueReply();
int32_t ExecuteContinueSend(std::shared_ptr<ContinueAbilityData> data);
int32_t ExecuteContinueData(std::shared_ptr<DSchedContinueDataCmd> cmd);
@ -159,7 +159,7 @@ private:
int32_t ExecuteContinueError(int32_t result);
int32_t OnContinueMission(const OHOS::AAFwk::WantParams& wantParams);
int32_t OnStartCmd(uint32_t appVersion);
int32_t OnStartCmd(int32_t appVersion);
int32_t OnReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd);
int32_t OnStartContinuation(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t status,
uint32_t accessToken);
@ -182,7 +182,7 @@ private:
const AccountInfo& accountInfo);
int32_t CheckStartPermission(std::shared_ptr<DSchedContinueDataCmd> cmd);
int32_t PackEndCmd(std::shared_ptr<DSchedContinueEndCmd> cmd, int32_t result);
int32_t PackReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd, int32_t replyCmd, uint32_t appVersion,
int32_t PackReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd, int32_t replyCmd, int32_t appVersion,
int32_t result, const std::string reason);
int32_t SendCommand(std::shared_ptr<DSchedContinueCmdBase> cmd);

View File

@ -78,7 +78,7 @@ public:
public:
int32_t direction_ = 0;
uint32_t appVersion_ = 0;
int32_t appVersion_ = 0;
DistributedWantParams wantParams_;
};
@ -112,7 +112,7 @@ public:
public:
int32_t replyCmd_ = 0;
uint32_t appVersion_ = 0;
int32_t appVersion_ = 0;
int32_t result_ = 0;
std::string reason_;
};

View File

@ -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, std::string &srcAbilityName,
std::string &srcContinueType, bool &isSameBundle);
std::string ContinueTypeFormat(std::string &continueType);
private:
currentIconInfo iconInfo_;
sptr<DistributedMissionDiedListener> missionDiedListener_;

View File

@ -264,13 +264,13 @@ int32_t DSchedContinue::PostStartTask(const OHOS::AAFwk::WantParams& wantParams)
return ERR_OK;
}
int32_t DSchedContinue::OnStartCmd(uint32_t appVersion)
int32_t DSchedContinue::OnStartCmd(int32_t appVersion)
{
HILOGI("called");
return PostCotinueAbilityTask(appVersion);
}
int32_t DSchedContinue::PostCotinueAbilityTask(uint32_t appVersion)
int32_t DSchedContinue::PostCotinueAbilityTask(int32_t appVersion)
{
DSchedContinueEventType eventType = DSHCED_CONTINUE_ABILITY_EVENT;
HILOGI("PostCotinueAbilityTask %{public}d, continueInfo %{public}s", eventType,
@ -279,7 +279,7 @@ int32_t DSchedContinue::PostCotinueAbilityTask(uint32_t appVersion)
HILOGE("PostCotinueAbilityTask eventHandler is nullptr");
return INVALID_PARAMETERS_ERR;
}
auto data = std::make_shared<uint32_t>(appVersion);
auto data = std::make_shared<int32_t>(appVersion);
auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, data, 0);
if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) {
HILOGE("PostCotinueAbilityTask eventHandler send event type %{public}d fail", eventType);
@ -652,15 +652,15 @@ int32_t DSchedContinue::PackStartCmd(std::shared_ptr<DSchedContinueStartCmd>& cm
HILOGE("pack start cmd failed, the bundle is not installed on local device.");
return ret;
}
cmd->appVersion_ = localBundleInfo.versionCode;
cmd->appVersion_ = static_cast<int32_t>(localBundleInfo.versionCode);
}
cmd->wantParams_ = *wantParams;
return ERR_OK;
}
int32_t DSchedContinue::ExecuteContinueAbility(uint32_t appVersion)
int32_t DSchedContinue::ExecuteContinueAbility(int32_t appVersion)
{
HILOGI("ExecuteContinueAbility start, appVersion: %{public}u", appVersion);
HILOGI("ExecuteContinueAbility start, appVersion: %{public}d", appVersion);
DmsRadar::GetInstance().SaveDataDmsContinue("ContinueAbility", ERR_OK);
int32_t result = GetMissionIdByBundleName();
@ -1071,7 +1071,7 @@ int32_t DSchedContinue::ExecuteNotifyComplete(int32_t result)
return ERR_OK;
}
int32_t DSchedContinue::PackReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd, int32_t replyCmd, uint32_t appVersion,
int32_t DSchedContinue::PackReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd, int32_t replyCmd, int32_t appVersion,
int32_t result, const std::string reason)
{
if (cmd == nullptr) {

View File

@ -177,12 +177,11 @@ int32_t DSchedContinueStartCmd::Unmarshal(const std::string &jsonStr)
direction_ = direction->valueint;
cJSON *appVersion = cJSON_GetObjectItemCaseSensitive(rootValue, "AppVersion");
if (appVersion == nullptr || !cJSON_IsNumber(appVersion) || appVersion->valueint < 0 ||
appVersion->valueint > UINT32_MAX) {
if (appVersion == nullptr || !cJSON_IsNumber(appVersion)) {
cJSON_Delete(rootValue);
return INVALID_PARAMETERS_ERR;
}
appVersion_ = static_cast<uint32_t>(appVersion->valueint);
appVersion_ = appVersion->valueint;
cJSON *wantParams = cJSON_GetObjectItemCaseSensitive(rootValue, "WantParams");
if (wantParams == nullptr || !cJSON_IsString(wantParams) || (wantParams->valuestring == nullptr)) {
@ -654,10 +653,10 @@ int32_t DSchedContinueReplyCmd::Unmarshal(const std::string &jsonStr)
}
const char *numKeys[] = {
"ReplyCmd", "Result"
"ReplyCmd", "AppVersion", "Result"
};
int32_t *numValues[] = {
&replyCmd_, &result_
&replyCmd_, &appVersion_, &result_
};
int32_t numLength = sizeof(numKeys) / sizeof(numKeys[0]);
for (int32_t i = 0; i < numLength; i++) {
@ -669,14 +668,6 @@ int32_t DSchedContinueReplyCmd::Unmarshal(const std::string &jsonStr)
*numValues[i] = item->valueint;
}
cJSON *appVersion = cJSON_GetObjectItemCaseSensitive(rootValue, "AppVersion");
if (appVersion == nullptr || !cJSON_IsNumber(appVersion) || appVersion->valueint < 0 ||
appVersion->valueint > UINT32_MAX) {
cJSON_Delete(rootValue);
return INVALID_PARAMETERS_ERR;
}
appVersion_ = static_cast<uint32_t>(appVersion->valueint);
cJSON *reason = cJSON_GetObjectItemCaseSensitive(rootValue, "Reason");
if (reason == nullptr || !cJSON_IsString(reason) || (reason->valuestring == nullptr)) {
cJSON_Delete(rootValue);

View File

@ -86,7 +86,7 @@ int32_t DSchedContinueSourceStartState::DoContinueAbilityTask(std::shared_ptr<DS
HILOGE("dContinue or event is null");
return INVALID_PARAMETERS_ERR;
}
auto syncContinueData = event->GetSharedObject<uint32_t>();
auto syncContinueData = event->GetSharedObject<int32_t>();
int32_t ret = dContinue->ExecuteContinueAbility(*syncContinueData);
if (ret != ERR_OK) {
HILOGE("DSchedContinueSourceStartState ExecuteContinueAbility failed, ret: %{public}d", ret);

View File

@ -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,8 @@ 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 ? true : false;
if (!IsBundleContinuable(localBundleInfo, abilityInfo.abilityName, continueType, isSameBundle)) {
HILOGE("Bundle %{public}s is not continuable", finalBundleName.c_str());
return INVALID_PARAMETERS_ERR;
}
@ -363,14 +367,40 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
return ERR_OK;
}
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo)
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, std::string &srcAbilityName,
std::string &srcContinueType, bool &isSameBundle)
{
std::string formatSrcContinueType = ContinueTypeFormat(srcContinueType);
bool continuable = false;
bool isSameAbility = false;
for (auto abilityInfo : bundleInfo.abilityInfos) {
if (abilityInfo.continuable) {
return true;
if (!abilityInfo.continuable) {
continue;
}
continuable = true;
isSameAbility = false;
for(const auto &continueTypeItem: abilityInfo.continueType){
if((srcContinueType == srcAbilityName || abilityInfo.name == continueTypeItem)
&& abilityInfo.name == srcAbilityName){
isSameAbility = true;
}
if(continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType){
return true;
}
}
}
return false;
return continuable && isSameBundle && isSameAbility;
}
std::string DMSContinueRecvMgr::ContinueTypeFormat(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,

View File

@ -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");

View File

@ -107,7 +107,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_002_1, TestSize.Level0)
int32_t subType = CONTINUE_PULL;
int32_t direction = CONTINUE_SINK;
sptr<IRemoteObject> callback = nullptr;
uint32_t appVersion = 0;
int32_t appVersion = 0;
auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, "");
auto conti = std::make_shared<DSchedContinue>(subType, direction, callback, info);
@ -411,7 +411,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0010_1, TestSize.Level0)
auto conti = std::make_shared<DSchedContinue>(subType, direction, callback, info);
conti->Init();
uint32_t appVersion = 0;
int32_t appVersion = 0;
int32_t ret = conti->ExecuteContinueAbility(appVersion);
EXPECT_NE(ret, ERR_OK);
DTEST_LOG << "DSchedContinueTest DSchedContinueTest_0010_1 end ret:" << ret << std::endl;
@ -649,7 +649,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0019_1, TestSize.Level0)
auto cmd = std::make_shared<DSchedContinueReplyCmd>();
int32_t replyCmd = 0;
uint32_t appVersion = 0;
int32_t appVersion = 0;
int32_t result = 0;
int32_t ret = conti->PackReplyCmd(cmd, replyCmd, appVersion, result, "");

View File

@ -1287,6 +1287,7 @@ HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotChanged001, TestSize.Le
{
DTEST_LOG << "testNotifyMissionSnapshotChanged001 begin" << std::endl;
DistributedSchedMissionManager::GetInstance().Init();
EXPECT_CALL(*mockDmsAdapter, GetLocalMissionSnapshotInfo(_, _, _)).WillOnce(Return(true));
DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotChanged(1);
EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionChangeHandler_, nullptr);
DTEST_LOG << "testNotifyMissionSnapshotChanged001 end" << std::endl;
@ -2310,6 +2311,7 @@ HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote002, TestSize.Lev
DistributedSchedMissionManager::GetInstance().missonChangeListener_ = new DistributedMissionChangeListener();
DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = true;
EXPECT_CALL(*mockDmsAdapter, GetLocalMissionSnapshotInfo(_, _, _)).WillOnce(Return(true));
auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
EXPECT_EQ(ret, ERR_NONE);
DTEST_LOG << "testStartSyncMissionsFromRemote002 end" << std::endl;