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 9885a5dfb07f512f78615dd82fd9fe77aaf0d4d2..411b107b25b02586b3c4a69d891a06b355f9ce3c 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 321065c7784be328d6caba890c910bbd44f2a58b..9614e2dbb6fcbf5d9f2ea3a0c54a5ba28b09d510 100755 --- 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::ThrowErrorWithInvalidParam(env); + return errCode; + } + if (!OHOS::NotificationSts::UnWarpNotificationCheckRequest(env, checkRequestObj, checkRequest)) { + ANS_LOGE("InvalidParam 'checkRequest'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowErrorWithInvalidParam(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::ThrowErrorWithInvalidParam(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 1cc2f7c285f947b872331c17355a377d1f02140e..40037ccc4cd24688a177a79c99de48ef50dd8966 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 06733616419ff0227d31d7c7f987c676140c839d..dd3db2ae187f9ee76c529f18fd789494826ad7f4 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -787,7 +787,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; }