diff --git a/frameworks/ets/ani/ani_common/include/ani_common_util.h b/frameworks/ets/ani/ani_common/include/ani_common_util.h index 50f936f5647f8e4399ee5c890305e0b5bb1ce266..6596fcdb774ec9c8cd48fcaf60731ba6eb83d28d 100644 --- a/frameworks/ets/ani/ani_common/include/ani_common_util.h +++ b/frameworks/ets/ani/ani_common/include/ani_common_util.h @@ -75,6 +75,7 @@ bool GetLongPropertyObject(ani_env *env, ani_object param, const char *name, ani bool GetDoublePropertyValue(ani_env *env, ani_object param, const char *name, double &value); bool GetIntPropertyValue(ani_env *env, ani_object param, const char *name, int32_t &value); bool GetRefProperty(ani_env *env, ani_object param, const char *name, ani_ref &value); +bool GetBooleanPropertyObject(ani_env *env, ani_object param, const char *name, bool &value); bool SetDoublePropertyObject(ani_env *env, ani_object param, const char *name, double value); bool SetDoublePropertyValue(ani_env *env, ani_object param, const char *name, double value); diff --git a/frameworks/ets/ani/ani_common/include/ets_error_utils.h b/frameworks/ets/ani/ani_common/include/ets_error_utils.h index 97ebfc0bf48cb19561e1e85bd47875365616696f..015e88e7febab8a632b797aa4b2d3ddac8143ee6 100644 --- a/frameworks/ets/ani/ani_common/include/ets_error_utils.h +++ b/frameworks/ets/ani/ani_common/include/ets_error_utils.h @@ -35,6 +35,7 @@ public: static void ThrowErrorByNativeErr(ani_env *env, int32_t err); static void ThrowNotSystemAppError(ani_env *env); static void ThrowEtsTransferClassError(ani_env *env); + static void ThrowRuntimeError(ani_env *env, int32_t errCode, const std::string &errMessage = ""); static ani_object CreateError(ani_env *env, const AbilityErrorCode &err); static ani_object CreateError(ani_env *env, ani_int code, const std::string &msg); diff --git a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp index 1a76532c4dbb21f98aac955d545dbd73d57ac239..20bf82347b166569ac3d66c1968151f295ebd9fd 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -1203,6 +1203,29 @@ bool GetRefProperty(ani_env *env, ani_object param, const char *name, ani_ref &v return !isUndefined; } +bool GetBooleanPropertyObject(ani_env *env, ani_object param, const char *name, bool &value) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env"); + return false; + } + + ani_ref obj = nullptr; + ani_status status = ANI_ERROR; + if (!GetRefProperty(env, param, name, obj)) { + TAG_LOGW(AAFwkTag::ANI, "%{public}s : undefined", name); + return false; + } + ani_boolean aniValue = ANI_FALSE; + if ((status = env->Object_CallMethodByName_Boolean( + reinterpret_cast(obj), "unboxed", nullptr, &aniValue)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); + return false; + } + value = aniValue; + return true; +} + bool SetDoublePropertyObject(ani_env *env, ani_object param, const char *name, double value) { if (env == nullptr) { diff --git a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp index f8f48fafc7d17a192a0e71bcbef21d09aafa5cef..de7b9e37f8b6bf0ce17393765171719450aab361 100644 --- a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp @@ -471,12 +471,12 @@ ani_object NativeCreateDisplayContext(ani_env *env, ani_object aniObj, ani_long auto context = GetBaseContext(env, aniObj); if (context == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null context"); - EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + EtsErrorUtil::ThrowRuntimeError(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); return reinterpret_cast(undefRef); } if (displayId < 0) { TAG_LOGE(AAFwkTag::APPKIT, "displayId is invalid, less than 0"); - EtsErrorUtil::ThrowError(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + EtsErrorUtil::ThrowRuntimeError(env, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); return reinterpret_cast(undefRef); } uint64_t validDisplayId = static_cast(displayId); diff --git a/frameworks/ets/ani/ani_common/src/ets_error_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_error_utils.cpp index 0bb8e3f2575904763ccb33157bcab767e46ccd9c..b4beaf864389cd087bb7c43752851dc426248c7e 100644 --- a/frameworks/ets/ani/ani_common/src/ets_error_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_error_utils.cpp @@ -15,6 +15,7 @@ #include "ets_error_utils.h" +#include "ability_runtime_error_util.h" #include "hilog_tag_wrapper.h" namespace OHOS { @@ -57,6 +58,19 @@ void EtsErrorUtil::ThrowError(ani_env *env, const AbilityErrorCode &err) EtsErrorUtil::ThrowError(env, EtsErrorUtil::CreateError(env, static_cast(err), GetErrorMsg(err))); } +void EtsErrorUtil::ThrowRuntimeError(ani_env *env, int32_t errCode, const std::string &errMessage) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env"); + return; + } + std::string eMes = errMessage; + if (eMes.empty()) { + eMes = AbilityRuntimeErrorUtil::GetErrMessage(errCode); + } + EtsErrorUtil::ThrowError(env, EtsErrorUtil::CreateError(env, errCode, eMes)); +} + void EtsErrorUtil::ThrowInvalidCallerError(ani_env *env) { if (env == nullptr) { diff --git a/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp b/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp index 6daaa3dfec2aa819b5c7b81178bbc120dd3afe62..888581c6e9b0d2969ca7f177db064548ca1b9504 100644 --- a/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp +++ b/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp @@ -326,8 +326,8 @@ void EtsAbilityContext::OpenLink(ani_env *env, ani_object aniObj, ani_string ani if ((status = env->Reference_IsUndefined(callbackobj, &isCallbackUndefined)) != ANI_OK) { TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status); } - etsContext->OnOpenLink(env, aniObj, aniLink, myCallbackobj, optionsObj, callbackobj, isOptionsUndefined, - isCallbackUndefined); + etsContext->OnOpenLink(env, aniObj, aniLink, myCallbackobj, optionsObj, callbackobj, !isOptionsUndefined, + !isCallbackUndefined); } bool EtsAbilityContext::IsTerminating(ani_env *env, ani_object aniObj) @@ -751,6 +751,18 @@ void EtsAbilityContext::OnStartServiceExtensionAbility(ani_env *env, ani_object AppExecFwk::AsyncCallback(env, callbackobj, errorObject, nullptr); } +static bool CheckUrl(std::string &urlValue) +{ + if (urlValue.empty()) { + return false; + } + Uri uri = Uri(urlValue); + if (uri.GetScheme().empty() || uri.GetHost().empty()) { + return false; + } + return true; +} + void EtsAbilityContext::OnOpenLink(ani_env *env, ani_object aniObj, ani_string aniLink, ani_object myCallbackobj, ani_object optionsObj, ani_object callbackobj, bool haveOptionsParm, bool haveCallBackParm) { @@ -759,7 +771,7 @@ void EtsAbilityContext::OnOpenLink(ani_env *env, ani_object aniObj, ani_string a AAFwk::OpenLinkOptions openLinkOptions; AAFwk::Want want; want.SetParam(APP_LINKING_ONLY, false); - if (!AppExecFwk::GetStdString(env, aniLink, link)) { + if (!AppExecFwk::GetStdString(env, aniLink, link) || !CheckUrl(link)) { TAG_LOGE(AAFwkTag::CONTEXT, "parse link failed"); aniObject = EtsErrorUtil::CreateInvalidParamError(env, "Parse param link failed, link must be string."); AppExecFwk::AsyncCallback(env, myCallbackobj, aniObject, nullptr); @@ -1160,7 +1172,7 @@ void EtsAbilityContext::UnWrapOpenLinkOptions(ani_env *env, ani_object optionsOb } if ((status = env->Object_GetPropertyByName_Ref(optionsObj, APP_LINKING_ONLY.c_str(), &ParamRef)) == ANI_OK) { bool appLinkingOnly = false; - AppExecFwk::GetFieldBoolByName(env, optionsObj, "appLinkingOnly", appLinkingOnly); + AppExecFwk::GetBooleanPropertyObject(env, optionsObj, "appLinkingOnly", appLinkingOnly); openLinkOptions.SetAppLinkingOnly(appLinkingOnly); want.SetParam(APP_LINKING_ONLY, appLinkingOnly); }