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..ed447d00ce85bc06884d6a5ff47d275c4b57d8ac 100644 --- a/frameworks/ets/ani/ani_common/include/ani_common_util.h +++ b/frameworks/ets/ani/ani_common/include/ani_common_util.h @@ -84,6 +84,7 @@ bool SetStringArrayProperty(ani_env *env, ani_object param, const char *name, co bool SetRefProperty(ani_env *env, ani_object param, const char *name, ani_ref value); bool GetStaticFieldString(ani_env *env, ani_class classObj, const char *fieldName, std::string &value); +bool IsValidProperty(ani_env *env, ani_ref param); } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_ANI_COMMON_UTIL_H 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..a85dffb48c1212e12e42d9032a9c2d531ac10cfb 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -1379,5 +1379,28 @@ bool GetStaticFieldString(ani_env *env, ani_class classObj, const char *fieldNam } return true; } + +bool IsValidProperty(ani_env *env, ani_ref param) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env"); + return false; + } + ani_status status = ANI_ERROR; + ani_boolean isNull = false; + if ((status = env->Reference_IsNullishValue(param, &isNull)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); + return false; + } + ani_boolean isUndefined = false; + if ((status = env->Reference_IsUndefined(param, &isUndefined)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); + return false; + } + if (isUndefined || isNull) { + return false; + } + return true; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp index bbda8657de3734a3b3c6d4039cc6f4a4fdd7c7c0..965c6196e9618d7cd50e60df92e755bc9a08ee55 100644 --- a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp +++ b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp @@ -37,11 +37,11 @@ constexpr const char *CLEANER_CLASS_NAME = "Lapplication/ServiceExtensionContext/Cleaner;"; constexpr const int ANI_ALREADY_BINDED = 8; constexpr const int FAILED_CODE = -1; -constexpr const char *SIGNATURE_ONCONNECT = "LbundleManager/ElementName/ElementName;L@ohos/rpc/rpc/IRemoteObject;:V"; -constexpr const char *SIGNATURE_ONDISCONNECT = "LbundleManager/ElementName/ElementName;:V"; constexpr const char *SIGNATURE_CONNECT_SERVICE_EXTENSION = "L@ohos/app/ability/Want/Want;Lability/connectOptions/ConnectOptions;:J"; constexpr const char *SIGNATURE_DISCONNECT_SERVICE_EXTENSION = "JLutils/AbilityUtils/AsyncCallbackWrapper;:V"; +constexpr int32_t ARGC_ONE = 1; +constexpr int32_t ARGC_TWO = 2; bool BindNativeMethods(ani_env *env, ani_class &cls) { @@ -603,9 +603,25 @@ void ETSServiceExtensionConnection::CallEtsFailed(int32_t errorCode) TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to get env, status: %{public}d", status); return; } - status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onFailed", "I:V", - static_cast(errorCode)); - if (status != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onFailed", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "get onFailed failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "invalid onFailed property"); + return; + } + ani_object errorCodeObj = AppExecFwk::CreateInt(env, errorCode); + if (errorCodeObj == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null errorCodeObj"); + return; + } + ani_ref result; + std::vector argv = { errorCodeObj }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to call onFailed, status: %{public}d", status); } } @@ -658,8 +674,20 @@ void ETSServiceExtensionConnection::OnAbilityConnectDone( return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onConnect", - SIGNATURE_ONCONNECT, refElement, refRemoteObject)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onConnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "get onConnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "invalid onConnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement, refRemoteObject}; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_TWO, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to call onConnect, status: %{public}d", status); } DetachCurrentThread(); @@ -684,8 +712,20 @@ void ETSServiceExtensionConnection::OnAbilityDisconnectDone(const AppExecFwk::El return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onDisconnect", - SIGNATURE_ONDISCONNECT, refElement)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onDisconnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "get onDisconnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "invalid onDisconnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to call onDisconnect, status: %{public}d", status); } DetachCurrentThread(); 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..918a323ca386caaaec26971ec2721f3da12ae497 100644 --- a/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp +++ b/frameworks/ets/ani/ui_ability/src/ets_ability_context.cpp @@ -55,8 +55,6 @@ constexpr const char* CLEANER_CLASS = "Lapplication/UIAbilityContext/Cleaner;"; const std::string APP_LINKING_ONLY = "appLinkingOnly"; constexpr const char* SIGNATURE_OPEN_LINK = "Lstd/core/String;Lutils/AbilityUtils/AsyncCallbackWrapper;" "L@ohos/app/ability/OpenLinkOptions/OpenLinkOptions;Lutils/AbilityUtils/AsyncCallbackWrapper;:V"; -constexpr const char *SIGNATURE_ONCONNECT = "LbundleManager/ElementName/ElementName;L@ohos/rpc/rpc/IRemoteObject;:V"; -constexpr const char *SIGNATURE_ONDISCONNECT = "LbundleManager/ElementName/ElementName;:V"; constexpr const char *SIGNATURE_CONNECT_SERVICE_EXTENSION = "L@ohos/app/ability/Want/Want;Lability/connectOptions/ConnectOptions;:J"; constexpr const char *SIGNATURE_DISCONNECT_SERVICE_EXTENSION = "JLutils/AbilityUtils/AsyncCallbackWrapper;:V"; @@ -66,6 +64,8 @@ const std::string ATOMIC_SERVICE_PREFIX = "com.atomicservice."; constexpr const char *SIGNATURE_START_ABILITY_BY_TYPE = "Lstd/core/String;Lescompat/Record;Lapplication/AbilityStartCallback/AbilityStartCallback;:L@ohos/base/" "BusinessError;"; +constexpr int32_t ARGC_ONE = 1; +constexpr int32_t ARGC_TWO = 2; int64_t RequestCodeFromStringToInt64(const std::string &requestCode) { @@ -1548,9 +1548,25 @@ void ETSAbilityConnection::CallEtsFailed(int32_t errorCode) TAG_LOGE(AAFwkTag::CONTEXT, "Failed to get env, status: %{public}d", status); return; } - status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onFailed", "I:V", - errorCode); - if (status != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onFailed", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::CONTEXT, "get onFailed failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::CONTEXT, "invalid onFailed property"); + return; + } + ani_object errorCodeObj = AppExecFwk::CreateInt(env, errorCode); + if (errorCodeObj == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "null errorCodeObj"); + return; + } + ani_ref result; + std::vector argv = { errorCodeObj }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::CONTEXT, "Failed to call onFailed, status: %{public}d", status); } } @@ -1603,8 +1619,20 @@ void ETSAbilityConnection::OnAbilityConnectDone( return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onConnect", - SIGNATURE_ONCONNECT, refElement, refRemoteObject)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onConnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::CONTEXT, "get onConnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::CONTEXT, "invalid onConnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement, refRemoteObject}; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_TWO, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::CONTEXT, "Failed to call onConnect, status: %{public}d", status); } DetachCurrentThread(); @@ -1628,8 +1656,20 @@ void ETSAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onDisconnect", - SIGNATURE_ONDISCONNECT, refElement)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onDisconnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::CONTEXT, "get onDisconnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::CONTEXT, "invalid onDisconnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::CONTEXT, "Failed to call onDisconnect, status: %{public}d", status); } DetachCurrentThread(); diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp index 59228da3ffe737f5fa53a2b0bd91b69d591589c0..d02e40c9dfa26587efc4ed92da9f2ac46f72795d 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp @@ -36,12 +36,11 @@ static std::map, Ets const char *UI_EXTENSION_CONTEXT_CLASS_NAME = "Lapplication/UIExtensionContext/UIExtensionContext;"; const char *UI_EXTENSION_CONTEXT_CLEANER_CLASS_NAME = "Lapplication/UIExtensionContext/Cleaner;"; constexpr const int FAILED_CODE = -1; -constexpr const char *CONNECT_OPTIONS_CLASS_NAME = "Lability/connectOptions/ConnectOptionsInner;"; -constexpr const char *SIGNATURE_ONCONNECT = "LbundleManager/ElementName/ElementName;L@ohos/rpc/rpc/IRemoteObject;:V"; -constexpr const char *SIGNATURE_ONDISCONNECT = "LbundleManager/ElementName/ElementName;:V"; constexpr const char *SIGNATURE_CONNECT_SERVICE_EXTENSION = "L@ohos/app/ability/Want/Want;Lability/connectOptions/ConnectOptions;:J"; constexpr const char *SIGNATURE_DISCONNECT_SERVICE_EXTENSION = "JLutils/AbilityUtils/AsyncCallbackWrapper;:V"; +constexpr int32_t ARGC_ONE = 1; +constexpr int32_t ARGC_TWO = 2; void EtsUIExtensionContext::TerminateSelfSync(ani_env *env, ani_object obj, ani_object callback) { @@ -721,28 +720,26 @@ void EtsUIExtensionConnection::CallEtsFailed(int32_t errorCode) TAG_LOGE(AAFwkTag::UI_EXT, "null stsConnectionRef_"); return; } - ani_class cls = nullptr; - if ((status = env->FindClass(CONNECT_OPTIONS_CLASS_NAME, &cls)) != ANI_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to find connectOptions calss, status: %{public}d", status); - return; - } - if (cls == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "null class"); + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onFailed", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "get onFailed failed status : %{public}d", status); return; } - ani_method method = nullptr; - if ((status = env->Class_FindMethod(cls, "onFailed", "I:V", &method))) { - TAG_LOGE(AAFwkTag::UI_EXT, "Failed to find onFailed method, status: %{public}d", status); + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::UI_EXT, "invalid onFailed property"); return; } - if (method == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "null method"); + ani_object errorCodeObj = AppExecFwk::CreateInt(env, errorCode); + if (errorCodeObj == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null errorCodeObj"); return; } - status = env->Object_CallMethod_Void( - reinterpret_cast(stsConnectionRef_), method, errorCode); - if (status != ANI_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "Object_CallMethod_Void status: %{public}d", status); + ani_ref result; + std::vector argv = { errorCodeObj }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call onFailed, status: %{public}d", status); } } @@ -785,7 +782,7 @@ void EtsUIExtensionConnection::OnAbilityConnectDone(const AppExecFwk::ElementNam return; } if (remoteObject == nullptr) { - TAG_LOGE(AAFwkTag::CONTEXT, "null remoteObject"); + TAG_LOGE(AAFwkTag::UI_EXT, "null remoteObject"); DetachCurrentThread(); return; } @@ -796,8 +793,20 @@ void EtsUIExtensionConnection::OnAbilityConnectDone(const AppExecFwk::ElementNam return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onConnect", - SIGNATURE_ONCONNECT, refElement, refRemoteObject)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onConnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "get onConnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::UI_EXT, "invalid onConnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement, refRemoteObject}; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_TWO, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call onConnect, status: %{public}d", status); } DetachCurrentThread(); @@ -822,8 +831,20 @@ void EtsUIExtensionConnection::OnAbilityDisconnectDone(const AppExecFwk::Element return; } ani_status status = ANI_ERROR; - if ((status = env->Object_CallMethodByName_Void(reinterpret_cast(stsConnectionRef_), "onDisconnect", - SIGNATURE_ONDISCONNECT, refElement)) != ANI_OK) { + ani_ref funRef; + if ((status = env->Object_GetPropertyByName_Ref(reinterpret_cast(stsConnectionRef_), + "onDisconnect", &funRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "get onDisconnect failed status : %{public}d", status); + return; + } + if (!AppExecFwk::IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::UI_EXT, "invalid onDisconnect property"); + return; + } + ani_ref result; + std::vector argv = { refElement }; + if ((status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ONE, argv.data(), + &result)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "Failed to call onDisconnect, status: %{public}d", status); } DetachCurrentThread(); diff --git a/frameworks/ets/ets/@ohos.application.testRunner.ets b/frameworks/ets/ets/@ohos.application.testRunner.ets index 84c032547f16d29e8caa00658a1a8f8f4e6225c6..5581a2043b6f9c0b1499bb52b2b92ad37213acb7 100644 --- a/frameworks/ets/ets/@ohos.application.testRunner.ets +++ b/frameworks/ets/ets/@ohos.application.testRunner.ets @@ -13,7 +13,10 @@ * limitations under the License. */ +export type OnPrepareFn = () => void; +export type OnRunFn = () => void; + export default interface TestRunner { - onPrepare(): void; - onRun(): void; + onPrepare: OnPrepareFn; + onRun: OnRunFn; } diff --git a/frameworks/ets/ets/ability/connectOptions.ets b/frameworks/ets/ets/ability/connectOptions.ets index f19b251c9670fbfdcd9e44d85d5aa96fc98d05a4..71083a2f8a9e1038ef361cb503bbc5f3a3278e35 100644 --- a/frameworks/ets/ets/ability/connectOptions.ets +++ b/frameworks/ets/ets/ability/connectOptions.ets @@ -16,20 +16,25 @@ import { ElementName } from 'bundleManager.ElementName' import rpc from '@ohos.rpc'; +export type OnConnectFn = (elementName: ElementName, remote: rpc.IRemoteObject) => void; +export type OnDisconnectFn = (elementName: ElementName) => void; +export type OnFailedFn = (code: int) => void; + export interface ConnectOptions { - onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void; - onDisconnect(elementName: ElementName): void; - onFailed(code: int): void; + onConnect: OnConnectFn; + onDisconnect: OnDisconnectFn; + onFailed: OnFailedFn; } class ConnectOptionsInner implements ConnectOptions { - onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void { + onConnect: OnConnectFn = (elementName: ElementName, + remote: rpc.IRemoteObject) => { console.log('onConnect'); } - onDisconnect(elementName: ElementName): void { + onDisconnect: OnDisconnectFn = (elementName: ElementName) => { console.log('onDisconnect'); } - onFailed(code: int): void { + onFailed: OnFailedFn = (code: int) => { console.log('onFailed'); } } diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 314f54e138c2e346b77aa7936d56be2ff24bf80b..d67a976afb234bf28f47911dce9ed4b02fbc9c66 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -693,6 +693,7 @@ ohos_shared_library("test_runner_ani") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:delegator_mgmt", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", ] external_deps = [ diff --git a/frameworks/native/appkit/ability_delegator/runner_runtime/ets_test_runner.cpp b/frameworks/native/appkit/ability_delegator/runner_runtime/ets_test_runner.cpp index 70f26da60968b5cda488dd608f49275bcf4bc44b..8e05cc768e12d5cd2312a8af1fc8bc43df961970 100644 --- a/frameworks/native/appkit/ability_delegator/runner_runtime/ets_test_runner.cpp +++ b/frameworks/native/appkit/ability_delegator/runner_runtime/ets_test_runner.cpp @@ -16,6 +16,7 @@ #include #include "ability_delegator_registry.h" +#include "ani_common_util.h" #include "hilog_tag_wrapper.h" #include "runner_runtime/ets_test_runner.h" @@ -27,6 +28,9 @@ namespace OHOS { namespace RunnerRuntime { +namespace { + constexpr int32_t ARGC_ZERO = 0; +} TestRunner *ETSTestRunner::Create(const std::unique_ptr &runtime, const std::shared_ptr &args, const AppExecFwk::BundleInfo &bundleInfo) @@ -134,17 +138,21 @@ void ETSTestRunner::Prepare() if (env->ResetError() != ANI_OK) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "ResetError failed"); } - ani_method method; + ani_ref funRef; ani_status status = ANI_ERROR; - status = env->Class_FindMethod(etsTestRunnerObj_->aniCls, "onPrepare", ":V", &method); + status = env->Object_GetPropertyByName_Ref(etsTestRunnerObj_->aniObj, "onPrepare", &funRef); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::DELEGATOR, "get onPrepare failed status : %{public}d", status); return; } TAG_LOGI(AAFwkTag::DELEGATOR, "get onPrepare success"); + if (!IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::DELEGATOR, "invalid onPrepare property"); + return; + } - ani_int result; - status = env->Object_CallMethod_Void(etsTestRunnerObj_->aniObj, method, &result); + ani_ref result; + status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ZERO, nullptr, &result); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::DELEGATOR, "Object_CallMethod_Void onPrepare failed status : %{public}d", status); } else { @@ -166,17 +174,21 @@ void ETSTestRunner::Run() if (env->ResetError() != ANI_OK) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "ResetError failed"); } - ani_method method; + ani_ref funRef; ani_status status = ANI_ERROR; - status = env->Class_FindMethod(etsTestRunnerObj_->aniCls, "onRun", ":V", &method); + status = env->Object_GetPropertyByName_Ref(etsTestRunnerObj_->aniObj, "onRun", &funRef); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::DELEGATOR, "get onRun failed status : %{public}d", status); return; } TAG_LOGI(AAFwkTag::DELEGATOR, "get onRun success"); + if (!IsValidProperty(env, funRef)) { + TAG_LOGI(AAFwkTag::DELEGATOR, "invalid onRun property"); + return; + } - ani_int result; - status = env->Object_CallMethod_Void(etsTestRunnerObj_->aniObj, method, &result); + ani_ref result; + status = env->FunctionalObject_Call(reinterpret_cast(funRef), ARGC_ZERO, nullptr, &result); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::DELEGATOR, "Object_CallMethod_Void onRun failed status : %{public}d", status); } else {