!1745 add module name to 'want' in sdk

Merge pull request !1745 from zhoujun62/fix_bug
This commit is contained in:
openharmony_ci 2022-05-19 02:56:50 +00:00 committed by Gitee
commit 940cf6b2b9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 23 additions and 17 deletions

View File

@ -100,7 +100,6 @@ bool ElementName::ReadFromParcel(Parcel &parcel)
bundleName_ = Str16ToStr8(parcel.ReadString16());
abilityName_ = Str16ToStr8(parcel.ReadString16());
deviceId_ = Str16ToStr8(parcel.ReadString16());
moduleName_ = Str16ToStr8(parcel.ReadString16());
return true;
}
@ -120,7 +119,6 @@ bool ElementName::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(abilityName_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName_));
return true;
}
} // namespace AppExecFwk

View File

@ -251,7 +251,6 @@ bool Operation::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(action_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, entities_);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, flags_);
@ -298,9 +297,6 @@ bool Operation::ReadFromParcel(Parcel &parcel)
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
deviceId_ = Str16ToStr8(readString16);
readString16.clear();
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
moduleName_ = Str16ToStr8(readString16);
readString16.clear();
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, &entities_);
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, flags_);

View File

@ -72,6 +72,8 @@ const std::string Want::PARAM_RESV_CALLER_TOKEN("ohos.aafwk.param.callerToken");
const std::string Want::PARAM_RESV_CALLER_UID("ohos.aafwk.param.callerUid");
const std::string Want::PARAM_RESV_CALLER_PID("ohos.aafwk.param.callerPid");
const std::string Want::PARAM_MODULE_NAME("moduleName");
/**
* @description:Default construcotr of Want class, which is used to initialzie flags and URI.
* @param None
@ -1382,9 +1384,6 @@ void Want::ToUriStringInner(std::string &uriString) const
if (operation_.GetAbilityName().length() > 0) {
uriString += "ability=" + Encode(operation_.GetAbilityName()) + ";";
}
if (operation_.GetModuleName().length() > 0) {
uriString += "moduleName=" + Encode(operation_.GetModuleName()) + ";";
}
if (operation_.GetFlags() != 0) {
uriString += "flag=";
char buf[HEX_STRING_BUF_LEN] {0};
@ -1701,6 +1700,8 @@ bool Want::ReadFromParcel(Parcel &parcel)
parameters_ = *params;
delete params;
params = nullptr;
std::string moduleName = GetStringParam(PARAM_MODULE_NAME);
SetModuleName(moduleName);
} else {
return false;
}
@ -1760,8 +1761,6 @@ bool Want::ParseUriInternal(const std::string &content, ElementName &element, Wa
element.SetBundleName(value);
} else if (prop == "ability") {
element.SetAbilityName(value);
} else if (prop == "moduleName") {
element.SetModuleName(value);
} else if (prop == "package") {
want.SetBundle(Decode(value));
} else if (prop.length() > TYPE_TAG_SIZE) {
@ -1769,6 +1768,8 @@ bool Want::ParseUriInternal(const std::string &content, ElementName &element, Wa
if (!Want::CheckAndSetParameters(want, key, prop, value)) {
return false;
}
std::string moduleName = want.GetStringParam(PARAM_MODULE_NAME);
want.SetModuleName(moduleName);
}
return true;
@ -1956,7 +1957,6 @@ nlohmann::json Want::ToJson() const
{"deviceId", operation_.GetDeviceId()},
{"bundleName", operation_.GetBundleName()},
{"abilityName", operation_.GetAbilityName()},
{"moduleName", operation_.GetModuleName()},
{"uri", GetUriString()},
{"type", GetType()},
{"flags", GetFlags()},
@ -1974,7 +1974,6 @@ bool Want::ReadFromJson(nlohmann::json &wantJson)
if ((wantJson.find("deviceId") == jsonObjectEnd)
|| (wantJson.find("bundleName") == jsonObjectEnd)
|| (wantJson.find("abilityName") == jsonObjectEnd)
|| (wantJson.find("moduleName") == jsonObjectEnd)
|| (wantJson.find("uri") == jsonObjectEnd)
|| (wantJson.find("type") == jsonObjectEnd)
|| (wantJson.find("flags") == jsonObjectEnd)
@ -1988,8 +1987,7 @@ bool Want::ReadFromJson(nlohmann::json &wantJson)
std::string deviceId = wantJson.at("deviceId").get<std::string>();
std::string bundleName = wantJson.at("bundleName").get<std::string>();
std::string abilityName = wantJson.at("abilityName").get<std::string>();
std::string moduleName = wantJson.at("moduleName").get<std::string>();
SetElementName(deviceId, bundleName, abilityName, moduleName);
SetElementName(deviceId, bundleName, abilityName);
std::string uri = wantJson.at("uri").get<std::string>();
SetUri(uri);
@ -2006,6 +2004,9 @@ bool Want::ReadFromJson(nlohmann::json &wantJson)
std::string parametersString = wantJson.at("parameters").get<std::string>();
WantParams parameters = WantParamWrapper::ParseWantParams(parametersString);
SetParams(parameters);
std::string moduleName = GetStringParam(PARAM_MODULE_NAME);
SetModuleName(moduleName);
if (wantJson.at("entities").is_null()) {
ABILITYBASE_LOGI("entities is null");
} else {

View File

@ -816,6 +816,9 @@ public:
static const std::string PARAM_RESV_CALLER_UID;
static const std::string PARAM_RESV_CALLER_PID;
// module name string
static const std::string PARAM_MODULE_NAME;
private:
WantParams parameters_;
Operation operation_;

View File

@ -74,6 +74,10 @@ napi_value WrapElementName(napi_env env, const ElementName &elementName)
NAPI_CALL(env, napi_create_string_utf8(env, elementName.GetAbilityName().c_str(), NAPI_AUTO_LENGTH, &jsValue));
NAPI_CALL(env, napi_set_named_property(env, jsObject, "abilityName", jsValue));
jsValue = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, elementName.GetModuleName().c_str(), NAPI_AUTO_LENGTH, &jsValue));
NAPI_CALL(env, napi_set_named_property(env, jsObject, "moduleName", jsValue));
return jsObject;
}
@ -1040,6 +1044,10 @@ napi_value WrapWant(napi_env env, const Want &want)
jsValue = GetPropertyValueByPropertyName(env, jsElementName, "abilityName", napi_string);
SetPropertyValueByPropertyName(env, jsObject, "abilityName", jsValue);
jsValue = nullptr;
jsValue = GetPropertyValueByPropertyName(env, jsElementName, "moduleName", napi_string);
SetPropertyValueByPropertyName(env, jsObject, "moduleName", jsValue);
jsValue = nullptr;
jsValue = WrapStringToJS(env, want.GetUriString());
SetPropertyValueByPropertyName(env, jsObject, "uri", jsValue);
@ -1106,8 +1114,8 @@ bool UnwrapWant(napi_env env, napi_value param, Want &want)
ElementName natElementName;
UnwrapElementName(env, param, natElementName);
want.SetElementName(natElementName.GetDeviceID(), natElementName.GetBundleName(), natElementName.GetAbilityName(),
natElementName.GetModuleName());
want.SetElementName(natElementName.GetDeviceID(), natElementName.GetBundleName(),
natElementName.GetAbilityName(), natElementName.GetModuleName());
natValueString = "";
if (UnwrapStringByPropertyName(env, param, "type", natValueString)) {