!1164 回退:使用distributedWant代替want进行传输

Merge pull request !1164 from zhx/master
This commit is contained in:
openharmony_ci 2024-11-08 09:07:21 +00:00 committed by Gitee
commit dc0fb8d657
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 14 additions and 57 deletions

View File

@ -91,7 +91,6 @@ private:
int32_t MarshalCallerInfo(std::string &jsonStr);
int32_t MarshalAccountInfo(std::string &jsonStr);
int32_t UnmarshalParcel(const std::string &jsonStr);
int32_t UnmarshalWantStr(const std::string &jsonStr);
int32_t UnmarshalCallerInfo(const std::string &jsonStr);
int32_t UnmarshalCallerInfoExtra(const std::string &jsonStr);
int32_t UnmarshalAccountInfo(const std::string &jsonStr);

View File

@ -18,7 +18,6 @@
#include "cJSON.h"
#include "parcel.h"
#include "distributedWant/distributed_want.h"
#include "distributed_sched_utils.h"
#include "dms_constant.h"
#include "dtbschedmgr_log.h"
@ -221,9 +220,8 @@ int32_t DSchedContinueDataCmd::Marshal(std::string &jsonStr)
cJSON_AddStringToObject(rootValue, "BaseCmd", baseJsonStr.c_str());
DistributedWant dtbWant(want_);
Parcel wantParcel;
if (!dtbWant.Marshalling(wantParcel)) {
if (!want_.Marshalling(wantParcel)) {
cJSON_Delete(rootValue);
return INVALID_PARAMETERS_ERR;
}
@ -420,11 +418,20 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr)
HILOGE("Want term is null or not string.");
return INVALID_PARAMETERS_ERR;
}
if (UnmarshalWantStr(wantStr->valuestring) != ERR_OK) {
Parcel wantParcel;
int32_t ret = Base64StrToParcel(wantStr->valuestring, wantParcel);
if (ret != ERR_OK) {
cJSON_Delete(rootValue);
HILOGE("UnmarshalWantStr failed!");
HILOGE("Want parcel Base64Str unmarshal fail, ret %{public}d.", ret);
return INVALID_PARAMETERS_ERR;
};
}
auto wantPtr = AAFwk::Want::Unmarshalling(wantParcel);
if (wantPtr == nullptr) {
cJSON_Delete(rootValue);
HILOGE("AAFwk Want unmarshalling fail, check return null.");
return INVALID_PARAMETERS_ERR;
}
want_ = *wantPtr;
cJSON *abilityInfoStr = cJSON_GetObjectItemCaseSensitive(rootValue, "AbilityInfo");
if (abilityInfoStr == nullptr || !cJSON_IsString(abilityInfoStr) || (abilityInfoStr->valuestring == nullptr)) {
@ -433,7 +440,7 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr)
return INVALID_PARAMETERS_ERR;
}
Parcel abilityParcel;
int32_t ret = Base64StrToParcel(abilityInfoStr->valuestring, abilityParcel);
ret = Base64StrToParcel(abilityInfoStr->valuestring, abilityParcel);
if (ret != ERR_OK) {
cJSON_Delete(rootValue);
HILOGE("AbilityInfo parcel Base64Str unmarshal fail, ret %{public}d.", ret);
@ -451,31 +458,6 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr)
return ERR_OK;
}
int32_t DSchedContinueDataCmd::UnmarshalWantStr(const std::string &jsonStr)
{
Parcel wantParcel;
int32_t ret = Base64StrToParcel(jsonStr, wantParcel);
if (ret != ERR_OK) {
HILOGE("Want parcel Base64Str unmarshal fail, ret %{public}d.", ret);
return INVALID_PARAMETERS_ERR;
}
auto dtbWantPtr = DistributedWant::Unmarshalling(wantParcel);
if (dtbWantPtr == nullptr) {
HILOGE("Distributed want unmarshalling fail, check return null.");
return INVALID_PARAMETERS_ERR;
}
DistributedWant dtbWant = *dtbWantPtr;
auto wantPtr = dtbWant.ToWant();
if (wantPtr == nullptr) {
HILOGE("Convert distributedWant to want failed.");
return INVALID_PARAMETERS_ERR;
}
want_ = *wantPtr;
return ERR_OK;
}
int32_t DSchedContinueDataCmd::UnmarshalCallerInfo(const std::string &jsonStr)
{
cJSON *rootValue = cJSON_Parse(jsonStr.c_str());

View File

@ -15,8 +15,6 @@
#include "dsched_continue_event_test.h"
#include "distributedWant/distributed_want.h"
#include "distributed_sched_utils.h"
#include "dsched_continue_event.h"
#include "dtbschedmgr_log.h"
#include "test_log.h"
@ -218,27 +216,5 @@ HWTEST_F(DSchedContinueEventTest, DSchedContinueEventTest_005_1, TestSize.Level0
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DSchedContinueEventTest DSchedContinueEventTest_005_1 end ret:" << ret << std::endl;
}
/**
* @tc.name: DSchedContinueEventTest_006_1
* @tc.desc: Test UnmarshalWantStr
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinueEventTest, DSchedContinueEventTest_006_1, TestSize.Level0)
{
DTEST_LOG << "DSchedContinueEventTest DSchedContinueEventTest_006_1 begin" << std::endl;
DistributedWant dtbWant;
Parcel wantParcel;
ASSERT_EQ(dtbWant.Marshalling(wantParcel), true);
std::string wantStr = ParcelToBase64Str(wantParcel);
DSchedContinueDataCmd cmd;
int32_t ret = cmd.UnmarshalWantStr(wantStr);
EXPECT_EQ(ret, ERR_OK);
ret = cmd.UnmarshalWantStr("");
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DSchedContinueEventTest DSchedContinueEventTest_006_1 end ret:" << ret << std::endl;
}
}
}