From 2606d3608c638e25cdcb6275b93b63284fc0c867 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Fri, 12 Nov 2021 17:13:29 +0000 Subject: [PATCH] Check empty string Signed-off-by: zhaoyuan17 --- frameworks/ans/core/src/ans_notification.cpp | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index 74d77b835..d57d6fc56 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -160,6 +160,11 @@ ErrCode AnsNotification::GetNotificationSlotGroups(std::vector> &slots) { + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -586,6 +611,11 @@ ErrCode AnsNotification::UpdateNotificationSlots( ErrCode AnsNotification::UpdateNotificationSlotGroups( const NotificationBundleOption &bundleOption, const std::vector> &groups) { + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -651,6 +681,11 @@ ErrCode AnsNotification::SetNotificationsEnabledForDefaultBundle(const std::stri ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled) { + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -662,6 +697,11 @@ ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( ErrCode AnsNotification::SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled) { + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -673,6 +713,11 @@ ErrCode AnsNotification::SetShowBadgeEnabledForBundle(const NotificationBundleOp ErrCode AnsNotification::GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled) { + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -712,6 +757,11 @@ ErrCode AnsNotification::GetDisturbMode(NotificationConstant::DisturbMode &distu ErrCode AnsNotification::CancelGroup(const std::string &groupName) { + if (groupName.empty()) { + ANS_LOGE("Invalid group name."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -723,6 +773,11 @@ ErrCode AnsNotification::CancelGroup(const std::string &groupName) ErrCode AnsNotification::RemoveGroupByBundle( const NotificationBundleOption &bundleOption, const std::string &groupName) { + if (bundleOption.GetBundleName().empty() || groupName.empty()) { + ANS_LOGE("Invalid parameter."); + return ERR_ANS_INVALID_PARAM; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; -- Gitee