diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index a3ed873fe0e05f28696ecf8d5e655703d29c41ba..7ea867de96a4110ecf7a8e259d0b7c76b253a13c 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -160,6 +160,11 @@ public: { return stsSubscriber_; } + + static StsNotificationLocalLiveViewSubscriber *GetSelfSubscriber() + { + return new (std::nothrow) StsNotificationLocalLiveViewSubscriber(); + } private: ani_env* GetAniEnv(); private: diff --git a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp index 1717201299b0ac832d787b5781d12a72ec48fce5..a677c8be485fb2f93a42bdcd44a418fd512eed5b 100644 --- a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp +++ b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp @@ -54,8 +54,8 @@ void AniTriggerSystemLiveView( void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj) { ANS_LOGD("AniSubscribeSystemLiveView call"); - std::shared_ptr localLiveViewSubscriber - = std::make_shared(); + NotificationSts::StsNotificationLocalLiveViewSubscriber *localLiveViewSubscriber = + NotificationSts::StsNotificationLocalLiveViewSubscriber::GetSelfSubscriber(); if (localLiveViewSubscriber == nullptr) { OHOS::NotificationSts::ThrowError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); @@ -64,7 +64,7 @@ void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj) } localLiveViewSubscriber->SetStsNotificationLocalLiveViewSubscriber(env, subscriberObj); int returncode = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification( - (*localLiveViewSubscriber.get()), false); + *localLiveViewSubscriber, false); if (returncode != ERR_OK) { int externalCode = NotificationSts::GetExternalCode(returncode); OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 496c1f8baa7bbc4bb6ee6ae1ae35308b5210ac6e..b1324424ef1aa80d894ec77b3b09d92285371452 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -334,7 +334,9 @@ void StsNotificationLocalLiveViewSubscriber::OnConnected() {} void StsNotificationLocalLiveViewSubscriber::OnDisconnected() -{} +{ + delete this; +} void StsNotificationLocalLiveViewSubscriber::OnDied() {}