diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index e6f76234fbf113526101fbd97f400d4c781e38cc..41e141584e976d304aaee93ad2aaee2a235989a7 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -23,6 +23,7 @@ import { NotificationLongTextContent } from 'notification.notificationContent'; import { NotificationMultiLineContent } from 'notification.notificationContent'; import { NotificationPictureContent } from 'notification.notificationContent'; import { NotificationSystemLiveViewContent } from 'notification.notificationContent'; +import { NotificationContent } from 'notification.notificationContent'; import { NotificationTemplate } from 'notification.notificationTemplate'; import { DistributedOptions } from 'notification.notificationRequest'; import { NotificationLiveViewContent } from 'notification.notificationContent'; @@ -553,6 +554,33 @@ export default namespace notificationManager { } return true; } + function checkContentType(content: NotificationContent): boolean + { + let contentType = content.notificationContentType; + if (contentType !== undefined) { + let type:ContentType = contentType as ContentType; + if (type == ContentType.NOTIFICATION_CONTENT_BASIC_TEXT + && content.normal == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_LONG_TEXT + && content.longText == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_PICTURE + && content.picture == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_MULTILINE + && content.multiLine == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW + && content.systemLiveView == undefined) { + return false; + } else if (type == ContentType.NOTIFICATION_CONTENT_LIVE_VIEW + && content.liveView == undefined) { + return false; + } + } + return true; + } function isInvalidParameter(request: NotificationRequest): BusinessError { let error: BusinessError = successCallbackError @@ -564,6 +592,12 @@ export default namespace notificationManager { error = errorParamInvalid return error; } + if (request.content?.notificationContentType == undefined) { + return errorParamInvalid; + } + if (!checkContentType(request.content)) { + return errorParamInvalid; + } if (request.content?.normal !== undefined && !isInvalidContent(request.content.normal)) { return errorParamInvalid; }