From 560a62ca80bb942592a79f7c529330c2508a3a1e Mon Sep 17 00:00:00 2001 From: liwang <965027894@qq.com> Date: Fri, 29 Aug 2025 14:12:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=8C=96=E5=90=8E=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=A4=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liwang <965027894@qq.com> --- .../ani/src/manager/ani_local_live_view.cpp | 14 +++++++--- frameworks/ets/ani/src/manager/ani_on.cpp | 28 +++++++++++++++---- frameworks/ets/ani/src/sts_disturb_mode.cpp | 2 +- frameworks/ets/ani/src/sts_subscribe.cpp | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) 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 975e50ca1..c75197a40 100644 --- a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp +++ b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp @@ -54,11 +54,17 @@ void AniTriggerSystemLiveView( void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj) { ANS_LOGD("AniSubscribeSystemLiveView call"); - NotificationSts::StsNotificationLocalLiveViewSubscriber *localLiveViewSubscriber - = new (std::nothrow)NotificationSts::StsNotificationLocalLiveViewSubscriber(); + std::shared_ptr localLiveViewSubscriber + = std::make_shared(); + if (localLiveViewSubscriber == nullptr) { + OHOS::NotificationSts::ThrowError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + ANS_LOGE("AniSubscribeSystemLiveView localLiveViewSubscriber ERROR_INTERNAL_ERROR"); + return; + } localLiveViewSubscriber->SetStsNotificationLocalLiveViewSubscriber(env, subscriberObj); - int returncode - = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification(*localLiveViewSubscriber, false); + int returncode = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification( + (*localLiveViewSubscriber.get()), 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/manager/ani_on.cpp b/frameworks/ets/ani/src/manager/ani_on.cpp index 8bbab66b1..04d361e16 100644 --- a/frameworks/ets/ani/src/manager/ani_on.cpp +++ b/frameworks/ets/ani/src/manager/ani_on.cpp @@ -38,6 +38,25 @@ bool CheckCallerIsSystemApp() return true; } +int32_t getNotificationCheckRequestParam(ani_env *env, ani_object checkRequestObj, + sptr &checkRequest) +{ + checkRequest = new (std::nothrow) NotificationCheckRequest(); + if (checkRequest == nullptr) { + ANS_LOGE("new NotificationCheckRequest fail"); + int32_t errCode = OHOS::Notification::ERROR_INTERNAL_ERROR; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (!OHOS::NotificationSts::UnWarpNotificationCheckRequest(env, checkRequestObj, checkRequest)) { + ANS_LOGE("InvalidParam 'checkRequest'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + return ERR_OK; +} + ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkRequestObj) { ANS_LOGD("enter"); @@ -54,11 +73,10 @@ ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkR ANS_LOGI("Old function param, don't need register."); return ERR_OK; } - sptr checkRequest = new NotificationCheckRequest(); - if (!OHOS::NotificationSts::UnWarpNotificationCheckRequest(env, checkRequestObj, checkRequest)) { - ANS_LOGE("InvalidParam 'checkRequest'"); - int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; - OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + sptr checkRequest = nullptr; + int32_t errCode = getNotificationCheckRequestParam(env, checkRequestObj, checkRequest); + if (errCode != ERR_OK || checkRequest == nullptr) { + ANS_LOGE("getNotificationCheckRequestParam fail, errCode:%{public}d", errCode); return errCode; } if (!CheckCallerIsSystemApp()) { diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index 0f836672d..050f223ce 100644 --- a/frameworks/ets/ani/src/sts_disturb_mode.cpp +++ b/frameworks/ets/ani/src/sts_disturb_mode.cpp @@ -79,7 +79,7 @@ bool UnwrapArrayDoNotDisturbProfile(ani_env *env, ani_object arrayObj, return false; } sptr profile = new (std::nothrow)NotificationDoNotDisturbProfile(); - if (!UnwrapDoNotDisturbProfile(env, static_cast(optionRef), profile)) { + if (profile == nullptr || !UnwrapDoNotDisturbProfile(env, static_cast(optionRef), profile)) { ANS_LOGE("Get profile failed, index: %{public}d", i); return false; } diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 524ed688f..4f1ec7077 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -830,7 +830,7 @@ sptr GetOperationInfoForDistributeOperation( { std::string hashCodeStd; sptr info = new (std::nothrow) StsNotificationOperationInfo(); - if (ANI_OK != GetStringByAniString(env, hashcode, hashCodeStd)) { + if (info == nullptr || ANI_OK != GetStringByAniString(env, hashcode, hashCodeStd)) { ANS_LOGD("hashCode is valid"); return nullptr; } -- Gitee