IssueNo: #I589JF:parse moduleName

Description: parse moduleName
Sig:SIG_ApplicaitonFramework
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: wangtiantian <wangtiantian19@huawei.com>
This commit is contained in:
wangtiantian 2022-05-19 15:55:45 +08:00
parent d19f015f43
commit ade45d0378
2 changed files with 51 additions and 51 deletions

View File

@ -183,6 +183,26 @@ static void ConvertRemoteAbilityInfos(
}
}
static bool ParseModuleName(napi_env env, std::string &moduleName, napi_value args)
{
napi_status status;
napi_valuetype valueType;
napi_value prop = nullptr;
bool hasKey = false;
napi_has_named_property(env, args, "moduleName", &hasKey);
if (hasKey) {
status = napi_get_named_property(env, args, "moduleName", &prop);
napi_typeof(env, prop, &valueType);
if ((status == napi_ok) && (valueType == napi_string)) {
moduleName = GetStringFromNAPI(env, prop);
} else {
APP_LOGE("begin to parse ElementName moduleName failed");
return false;
}
}
return true;
}
static bool ParseElementName(napi_env env, OHOS::AppExecFwk::ElementName &elementName, napi_value args)
{
APP_LOGD("begin to parse ElementName");
@ -212,17 +232,6 @@ static bool ParseElementName(napi_env env, OHOS::AppExecFwk::ElementName &elemen
return false;
}
prop = nullptr;
status = napi_get_named_property(env, args, "moduleName", &prop);
napi_typeof(env, prop, &valueType);
if (status == napi_ok && valueType == napi_string) {
std::string moduleName = GetStringFromNAPI(env, prop);
if (moduleName.empty()) {
APP_LOGE("err ElementName moduleName is empty");
return false;
}
elementName.SetModuleName(moduleName);
}
prop = nullptr;
status = napi_get_named_property(env, args, "abilityName", &prop);
napi_typeof(env, prop, &valueType);
if (status == napi_ok && valueType == napi_string) {
@ -231,6 +240,11 @@ static bool ParseElementName(napi_env env, OHOS::AppExecFwk::ElementName &elemen
APP_LOGE("begin to parse ElementName abilityName failed");
return false;
}
std::string moduleName;
if (!ParseModuleName(env, moduleName, args)) {
return false;
}
elementName.SetModuleName(moduleName);
APP_LOGD("parse ElementName end");
return true;
}

View File

@ -1402,14 +1402,7 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
APP_LOGE("args not object type");
return false;
}
std::string wantBundleName;
std::string wantModuleName;
std::string wantAbilityName;
std::string wantDeviceId;
std::string wantType;
int32_t wantFlags = 0;
std::string wantAction;
std::string wantUri;
std::vector<std::string> wantEntities;
std::string elementUri;
std::string elementDeviceId;
@ -1419,30 +1412,23 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
napi_value prop = nullptr;
napi_get_named_property(env, args, "bundleName", &prop);
wantBundleName = GetStringFromNAPI(env, prop);
std::string wantBundleName = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "moduleName", &prop);
napi_typeof(env, prop, &valueType);
if (valueType == napi_string) {
wantModuleName = GetStringFromNAPI(env, prop);
if (wantModuleName.empty()) {
APP_LOGE("error moduleName is empty!");
return false;
}
}
std::string wantModuleName = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "abilityName", &prop);
wantAbilityName = GetStringFromNAPI(env, prop);
std::string wantAbilityName = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "deviceId", &prop);
wantDeviceId = GetStringFromNAPI(env, prop);
std::string wantDeviceId = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "type", &prop);
wantType = GetStringFromNAPI(env, prop);
std::string wantType = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "flags", &prop);
@ -1453,11 +1439,11 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
prop = nullptr;
napi_get_named_property(env, args, "action", &prop);
wantAction = GetStringFromNAPI(env, prop);
std::string wantAction = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "uri", &prop);
wantUri = GetStringFromNAPI(env, prop);
std::string wantUri = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, args, "entities", &prop);
@ -1472,7 +1458,6 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
napi_typeof(env, elementProp, &valueType);
if (valueType == napi_object) {
APP_LOGD("begin to parse want elementName");
prop = nullptr;
napi_get_named_property(env, elementProp, "deviceId", &prop);
elementDeviceId = GetStringFromNAPI(env, prop);
@ -1483,33 +1468,34 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
prop = nullptr;
napi_status status = napi_get_named_property(env, elementProp, "bundleName", &prop);
if (status != napi_ok) {
APP_LOGE("elementName bundleName incorrect!");
return false;
}
napi_typeof(env, prop, &valueType);
if (valueType != napi_string) {
APP_LOGE("elementName bundleName type mismatch!");
if ((status != napi_ok) || (valueType != napi_string)) {
APP_LOGE("elementName bundleName incorrect!");
return false;
}
elementBundleName = GetStringFromNAPI(env, prop);
prop = nullptr;
napi_get_named_property(env, elementProp, "moduleName", &prop);
elementModuleName = GetStringFromNAPI(env, prop);
prop = nullptr;
status = napi_get_named_property(env, elementProp, "abilityName", &prop);
if (status != napi_ok) {
napi_typeof(env, prop, &valueType);
if ((status != napi_ok) || (valueType != napi_string)) {
APP_LOGE("elementName abilityName incorrect!");
return false;
}
napi_typeof(env, prop, &valueType);
if (valueType != napi_string) {
APP_LOGE("elementName abilityName type mismatch!");
return false;
}
elementAbilityName = GetStringFromNAPI(env, prop);
prop = nullptr;
bool hasKey = false;
napi_has_named_property(env, elementProp, "moduleName", &hasKey);
if (hasKey) {
status = napi_get_named_property(env, elementProp, "moduleName", &prop);
napi_typeof(env, prop, &valueType);
if ((status != napi_ok) || (valueType != napi_string)) {
APP_LOGE("elementName moduleName incorrect!");
return false;
}
elementModuleName = GetStringFromNAPI(env, prop);
}
}
if (elementBundleName.empty()) {
elementBundleName = wantBundleName;
@ -1526,8 +1512,8 @@ static bool ParseWant(napi_env env, Want &want, napi_value args)
if (elementUri.empty()) {
elementUri = wantUri;
}
APP_LOGD("bundleName:%{public}s, abilityName:%{public}s",
elementBundleName.c_str(), elementAbilityName.c_str());
APP_LOGD("bundleName:%{public}s, moduleName: %{public}s, abilityName:%{public}s",
elementBundleName.c_str(), elementModuleName.c_str(), elementAbilityName.c_str());
APP_LOGD("action:%{public}s, uri:%{private}s, type:%{public}s, flags:%{public}d",
wantAction.c_str(), elementUri.c_str(), wantType.c_str(), wantFlags);
want.SetAction(wantAction);