From 2c8110aea4ff5798068bd05fa9bf12f6e388073f Mon Sep 17 00:00:00 2001 From: wufarong1 Date: Sat, 24 Aug 2024 17:03:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?iconsResource=E8=BE=93=E5=85=A5=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E4=B8=8Estoi=E5=BC=82=E5=B8=B8=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong1 Change-Id: I5104c1da30acaaca587a149e3549220f12820c41 --- .../notification_local_live_view_button.cpp | 12 +++++- frameworks/ans/src/notification_request.cpp | 37 ++++++++++++++++--- interfaces/inner_api/notification_constant.h | 8 +++- interfaces/inner_api/notification_content.h | 7 +++- interfaces/inner_api/notification_request.h | 14 ++++++- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/frameworks/ans/src/notification_local_live_view_button.cpp b/frameworks/ans/src/notification_local_live_view_button.cpp index 81d163d51..de055a1b9 100644 --- a/frameworks/ans/src/notification_local_live_view_button.cpp +++ b/frameworks/ans/src/notification_local_live_view_button.cpp @@ -16,6 +16,7 @@ #include "notification_local_live_view_button.h" #include +#include #include // for basic_string, operator+, basic_string<>... #include // for shared_ptr, shared_ptr<>::element_type #include @@ -257,10 +258,19 @@ bool NotificationLocalLiveViewButton::ReadFromParcel(Parcel &parcel) ANS_LOGE("Failed to read button names"); return false; } + if (iconsResource.size(); resource->bundleName = iconsResource[RESOURCE_BUNDLENAME_INDEX]; resource->moduleName = iconsResource[RESOURCE_MODULENAME_INDEX]; - resource->id = std::stoi(iconsResource[RESOURCE_ID_INDEX]); + try { + resource->id = std::stoi(iconsResource[RESOURCE_ID_INDEX]); + } catch (...) { + ANS_LOGE(AAFwkTag::APPKIT, "stoi(%(public)s) failed", iconsResource[RESOURCE_ID_INDEX].c_str()); + return false; + } buttonIconsResource_.emplace_back(resource); } diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 90ce75934..af3b873c1 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -24,6 +24,7 @@ #include "refbase.h" #include "want_agent_helper.h" #include "want_params_wrapper.h" +#include #include namespace OHOS { @@ -1502,11 +1503,37 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) return false; } - slotType_ = static_cast(parcel.ReadInt32()); - groupAlertType_ = static_cast(parcel.ReadInt32()); - visiblenessType_ = static_cast(parcel.ReadInt32()); - badgeStyle_ = static_cast(parcel.ReadInt32()); - notificationContentType_ = static_cast(parcel.ReadInt32()); + int32_t slotTypeValue = parcel.ReadInt32(); + if (slotTypeValue < 0 || slotTypeValue >= NotificationConstant::SlotType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", slotTypeValue); + return false; + } + slotType_ = static_cast(slotTypeValue); + int32_t groupAlertTypeValue = parcel.ReadInt32(); + if (groupAlertTypeValue < 0 || groupAlertTypeValue >= NotificationRequest::GroupAlertType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", groupAlertTypeValue); + return false; + } + groupAlertType_ = static_cast(groupAlertTypeValue); + int32_t visiblenessTypeValue = parcel.ReadInt32(); + if (visiblenessTypeValue < 0 || visiblenessTypeValue >= NotificationConstant::VisiblenessType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", visiblenessTypeValue); + return false; + } + visiblenessType_ = static_cast(visiblenessTypeValue); + int32_t badgeStyleValue = parcel.ReadInt32(); + if (badgeStyleValue < 0 || badgeStyleValue >= NotificationRequest::BadgeStyle.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", badgeStyleValue); + return false; + } + badgeStyle_ = static_cast(badgeStyleValue); + int32_t notificationContentTypeValue = parcel.ReadInt32(); + if (notificationContentTypeValue <= NotificationContent::Type.NONE || + notificationContentTypeValue >= NotificationContent::Type.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", otificationContentTypeValue); + return false; + } + notificationContentType_ = static_cast(notificationContentTypeValue); showDeliveryTime_ = parcel.ReadBool(); tapDismissed_ = parcel.ReadBool(); diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index d01c1afea..573fdaa40 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -65,6 +65,7 @@ public: LIVE_VIEW, // the notification type is live view CUSTOMER_SERVICE, // the notification type is customer service EMERGENCY_INFORMATION, // the notification type is emergency information + ILLEGAL_TYPE, // invalid type,it is used as the upper limit of the enumerated value }; enum ReminderFlag { @@ -93,7 +94,12 @@ public: /** * notifications are not displayed on the lock screen. */ - SECRET + SECRET, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; enum class DoNotDisturbType { diff --git a/interfaces/inner_api/notification_content.h b/interfaces/inner_api/notification_content.h index 3d68945a8..836c0e80d 100644 --- a/interfaces/inner_api/notification_content.h +++ b/interfaces/inner_api/notification_content.h @@ -75,7 +75,12 @@ public: * Indicates notifications that include a live view. * Such notifications are created using NotificationLiveViewContent. */ - LIVE_VIEW + LIVE_VIEW, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; /** diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 541f85294..b04f96855 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -64,7 +64,12 @@ public: /** * displayed as a small icon. */ - LITTLE + LITTLE, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; enum class GroupAlertType { @@ -82,7 +87,12 @@ public: * the overview notification has sound or vibration but child notifications are muted (no sound or vibration) * in a group if sound or vibration is enabled for the associated NotificationSlot objects. */ - OVERVIEW + OVERVIEW, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; /** -- Gitee From ffe5157c2e9e5ebaf4dc342f3de4e31908abfd44 Mon Sep 17 00:00:00 2001 From: wufarong1 Date: Mon, 26 Aug 2024 20:41:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ANS=E5=91=8A=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong1 Change-Id: I006096ab2f6c1d04dde5422393345ea9dedf710c --- frameworks/ans/src/notification_local_live_view_button.cpp | 1 + frameworks/ans/src/notification_request.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/ans/src/notification_local_live_view_button.cpp b/frameworks/ans/src/notification_local_live_view_button.cpp index de055a1b9..ae93977ac 100644 --- a/frameworks/ans/src/notification_local_live_view_button.cpp +++ b/frameworks/ans/src/notification_local_live_view_button.cpp @@ -173,6 +173,7 @@ NotificationLocalLiveViewButton *NotificationLocalLiveViewButton::FromJson(const auto pIcon = AnsImageUtil::UnPackImage(iconObj.get()); if (pIcon == nullptr) { ANS_LOGE("Failed to parse button icon"); + delete button; return nullptr; } button->buttonIcons_.emplace_back(pIcon); diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index af3b873c1..b3b5db337 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2282,7 +2282,7 @@ bool NotificationRequest::ConvertJsonToNotificationDistributedOptions( target->distributedOptions_ = *pOpt; } } - + delete pOpt; return true; } -- Gitee