diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 3987646738ecb00080f3cf3692a7aa2e118d8f67..9a206f2aee3960d619e7ae03f1f53235f205f565 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -304,14 +304,14 @@ void StsNotificationLocalLiveViewSubscriber::OnDied() void StsNotificationLocalLiveViewSubscriber::OnResponse(int32_t notificationId, sptr buttonOption) { ANS_LOGD("OnResponse call"); - std::string functionName = "OnResponse"; + std::string functionName = "onResponse"; ani_env *env = GetAniEnv(); if (env == nullptr || stsSubscriber_ == nullptr) { ANS_LOGE("null env or stsSubscriber_"); return; } ani_status status = ANI_OK; - ani_object stsSubscriberObj = reinterpret_cast(stsSubscriber_->aniRef); + ani_object stsSubscriberObj = static_cast(stsSubscriber_->aniRef); ani_ref funRef; ani_boolean isUndefined = ANI_TRUE; status = GetPropertyRef(env, stsSubscriberObj, functionName.c_str(), isUndefined, funRef); @@ -334,6 +334,10 @@ void StsNotificationLocalLiveViewSubscriber::OnResponse(int32_t notificationId, ANS_LOGE("FunctionalObject_Call failed, status: %{public}d", status); return; } + ani_status aniResult = vm_->DetachCurrentThread(); + if (aniResult != ANI_OK) { + ANS_LOGD("OnResponse DetachCurrentThread error. result: %{public}d.", aniResult); + } } void StsNotificationLocalLiveViewSubscriber::SetStsNotificationLocalLiveViewSubscriber( @@ -371,12 +375,18 @@ ani_env* StsNotificationLocalLiveViewSubscriber::GetAniEnv() ANS_LOGE("vm_ is nullptr"); return nullptr; } - ani_env* aniEnv = nullptr; - if (vm_->GetEnv(ANI_VERSION_1, &aniEnv) != ANI_OK) { - ANS_LOGE("get env failed"); - return nullptr; + ani_env* env; + ani_status aniResult = ANI_ERROR; + ani_options aniArgs { 0, nullptr }; + aniResult = vm_->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &env); + if (aniResult != ANI_OK) { + ANS_LOGD("AttachCurrentThread error. result: %{public}d.", aniResult); + if (vm_->GetEnv(ANI_VERSION_1, &env) != ANI_OK) { + ANS_LOGE("get env failed"); + return nullptr; + } } - return aniEnv; + return env; } bool SlotTypeEtsToC(ani_env *env, ani_enum_item enumItem, SlotType &slotType)