diff --git a/frameworks/ets/ani/src/sts_notification_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index a6defe8fb569bacd711b92b2290d2d1b2cde7a73..36330b500046c5f472ab97cf565620f8e0d3d999 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -447,20 +447,25 @@ bool WarpNotificationLocalLiveViewButton( bool getCapsuleByIcon(ani_env *env, ani_object obj, std::shared_ptr &pixelMap) { - ani_boolean isUndefined = ANI_TRUE; - pixelMap = nullptr; + ani_boolean isUndefined = ANI_FALSE; ani_ref tempRef = nullptr; ani_status status = GetPropertyRef(env, obj, "icon", isUndefined, tempRef); if (status != ANI_OK) { ANS_LOGE("icon GetPropertyRef failed"); return false; } + if (isUndefined == ANI_TRUE) { + return true; + } if (tempRef == nullptr) { - ANS_LOGE("PixelMap is null"); + ANS_LOGE("tempRef is null"); return false; } pixelMap = GetPixelMapFromEnvSp(env, static_cast(tempRef)); - + if (pixelMap == nullptr) { + ANS_LOGE("PixelMap is null"); + return false; + } return true; } @@ -540,14 +545,16 @@ bool UnWarpNotificationCapsule(ani_env *env, ani_object obj, NotificationCapsule } capsule.SetTime(static_cast(time)); std::shared_ptr pixelMap = nullptr; - if (!getCapsuleByIcon(env, obj, pixelMap) || pixelMap == nullptr) { + if (!getCapsuleByIcon(env, obj, pixelMap)) { ANS_LOGE("get icon failed"); return false; } - capsule.SetIcon(pixelMap); + if (pixelMap != nullptr) { + capsule.SetIcon(pixelMap); + } std::vector iconButtons = {}; if (!getCapsuleByButtons(env, obj, iconButtons)) { - ANS_LOGE("get capsuleButtons failed"); + ANS_LOGE("get capsuleButtons failed"); return false; } capsule.SetCapsuleButton(iconButtons);