diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index fab87bf0d033f13d765fc172ab2bebd5e93cbe71..5dff5384a701b2d4a07badb040ae62cccb3c84c4 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 7f5eb237adb3fcd449682790ca2e28ebea57acc2..176c4c916f76e742ce5e029102e3f6a9f0ccfe81 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 4c54274bdcb477a32be76e2d3f5f8ff1188dfae7..502de66a9d577591f7b479b93ef314340fa6d23f 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 855867a7aaa32f9a667a1d1067654244ce3818ca..87f745fb76c99e5c0575b73205feb45efa1eff06 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 817b4052c573c97716728054ef8fd6e6321026d4..c7903ff54704c81f170b82195da51ef6ef358e52 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)) {