From 57fdf6c94eff7701512d9042addd01629342dd4b Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Mon, 6 Jun 2022 14:07:07 +0800 Subject: [PATCH] variable type modify Signed-off-by: fangJinliang1 Change-Id: I4577b38bbde0ee8cd3254295ef8c37a6ca0587f2 --- frameworks/ans/src/notification_request.cpp | 10 +++++----- frameworks/js/napi/src/common.cpp | 7 ++++++- interfaces/inner_api/notification_request.h | 6 +++--- .../ans/include/advanced_notification_service.h | 3 +-- services/ans/src/advanced_notification_service.cpp | 13 ++++++++----- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index fab87bf0d..5dff5384a 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -88,12 +88,12 @@ void NotificationRequest::SetUnremovable(bool isUnremovable) unremovable_ = isUnremovable; } -void NotificationRequest::SetBadgeNumber(int32_t number) +void NotificationRequest::SetBadgeNumber(uint32_t number) { badgeNumber_ = number; } -int32_t NotificationRequest::GetBadgeNumber() const +uint32_t NotificationRequest::GetBadgeNumber() const { return badgeNumber_; } @@ -842,7 +842,7 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const return false; } - if (!parcel.WriteInt32(badgeNumber_)) { + if (!parcel.WriteUint32(badgeNumber_)) { ANS_LOGE("Failed to write badge number"); return false; } @@ -1232,7 +1232,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) { notificationId_ = parcel.ReadInt32(); color_ = parcel.ReadUint32(); - badgeNumber_ = parcel.ReadInt32(); + badgeNumber_ = parcel.ReadUint32(); progressValue_ = parcel.ReadInt32(); progressMax_ = parcel.ReadInt32(); createTime_ = parcel.ReadInt64(); @@ -1654,7 +1654,7 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl } if (jsonObject.find("badgeNumber") != jsonEnd) { - target->badgeNumber_ = jsonObject.at("badgeNumber").get(); + target->badgeNumber_ = jsonObject.at("badgeNumber").get(); } } diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 7f5eb237a..176c4c916 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -386,7 +386,7 @@ napi_value Common::SetNotificationRequestByNumber( napi_set_named_property(env, result, "creatorPid", value); // badgeNumber?: number - napi_create_int32(env, request->GetBadgeNumber(), &value); + napi_create_uint32(env, request->GetBadgeNumber(), &value); napi_set_named_property(env, result, "badgeNumber", value); return NapiGetBoolean(env, true); @@ -4204,6 +4204,11 @@ napi_value Common::GetNotificationBadgeNumber( } napi_get_value_int32(env, result, &badgeNumber); + if (badgeNumber < 0) { + ANS_LOGE("Wrong badge number."); + return nullptr; + } + request.SetBadgeNumber(badgeNumber); } diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 4c54274bd..502de66a9 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -201,14 +201,14 @@ public: * * @param number Indicates the number to set. */ - void SetBadgeNumber(int32_t number); + void SetBadgeNumber(uint32_t number); /** * @brief Obtains the number to be displayed for this notification. * * @return Returns the number to be displayed for this notification. */ - int32_t GetBadgeNumber() const; + uint32_t GetBadgeNumber() const; /** * @brief Sets the current notification ID to uniquely identify the notification in the application. @@ -1136,7 +1136,7 @@ private: private: int32_t notificationId_ {0}; uint32_t color_ {NotificationRequest::COLOR_DEFAULT}; - int32_t badgeNumber_ {0}; + uint32_t badgeNumber_ {0}; int32_t progressValue_ {0}; int32_t progressMax_ {0}; int64_t createTime_ {0}; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 855867a7a..87f745fb7 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -808,8 +808,7 @@ private: ErrCode GetHasPoppedDialog(const sptr bundleOption, bool &hasPopped); ErrCode GetAppTargetBundle(const sptr &bundleOption, sptr &targetBundle); - bool PublishSlotChangeCommonEvent( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType); + bool PublishSlotChangeCommonEvent(const sptr &bundleOption); void ReportHasSeenEvent(const int32_t userId, const std::string &bundleName); private: diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 817b4052c..c7903ff54 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1126,6 +1126,11 @@ ErrCode AdvancedNotificationService::UpdateSlots( result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; } })); + + if (result == ERR_OK) { + PublishSlotChangeCommonEvent(bundle); + } + return result; } @@ -3489,7 +3494,7 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( return; } - PublishSlotChangeCommonEvent(bundle, slotType); + PublishSlotChangeCommonEvent(bundle); })); return result; } @@ -3531,17 +3536,15 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlot( return result; } -bool AdvancedNotificationService::PublishSlotChangeCommonEvent( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType) +bool AdvancedNotificationService::PublishSlotChangeCommonEvent(const sptr &bundleOption) { - ANS_LOGD("slotType: %{public}d", slotType); + ANS_LOGD("bundle [%{public}s : %{public}d]", bundleOption->GetBundleName().c_str(), bundleOption->GetUid()); EventFwk::Want want; AppExecFwk::ElementName element; element.SetBundleName(bundleOption->GetBundleName()); want.SetElement(element); want.SetParam(AppExecFwk::Constants::UID, bundleOption->GetUid()); - want.SetParam("SlotType", slotType); want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SLOT_CHANGE); EventFwk::CommonEventData commonData {want}; if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData)) { -- Gitee