diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 75a04c787baff2d5f898602f98843ad9a44edaa4..11478c7223a01a7cde6c960f1630e163cdbee143 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -1638,7 +1638,7 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl } if (jsonObject.find("creatorUid") != jsonEnd) { - target->creatorUid_ = static_cast(jsonObject.at("creatorUid").get()); + target->creatorUid_ = jsonObject.at("creatorUid").get(); } if (jsonObject.find("creatorPid") != jsonEnd) { @@ -1652,6 +1652,10 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl if (jsonObject.find("receiverUserId") != jsonEnd) { target->receiverUserId_ = jsonObject.at("receiverUserId").get(); } + + if (jsonObject.find("badgeNumber") != jsonEnd) { + target->badgeNumber_ = jsonObject.at("badgeNumber").get(); + } } void NotificationRequest::ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject) diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index 518b0dbff6171ccbf82af810f530bbd9371813ce..4dbaf0a03320d24276df9436a3b6a46ce2761ef9 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -365,6 +365,7 @@ private: EXPECT_EQ(0, notificationRequest.GetProgressMax()); EXPECT_EQ(0, notificationRequest.GetProgressValue()); EXPECT_EQ(false, notificationRequest.IsProgressIndeterminate()); + EXPECT_EQ(1, notificationRequest.GetBadgeNumber()); } void CheckCaseFourteenResult(const NotificationRequest& notificationRequest) const @@ -985,6 +986,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00900, Function req.SetFloatingIcon(false); req.SetProgressBar(0, 0, false); req.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); + req.SetBadgeNumber(1); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index b79276d4a9bf841e8cdf33000e9f718ca9239c6f..c6de293cce2d74360b7c8627626ea4dd562a3776 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -1528,6 +1528,17 @@ public: static napi_value SetNotificationFlags( const napi_env &env, const std::shared_ptr &flags, napi_value &result); + /** + * @brief Gets the number of badge of NotificationRequest object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param value Indicates a js object to be converted + * @param request Indicates a NotificationRequest object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationBadgeNumber( + const napi_env &env, const napi_value &value, NotificationRequest &request); + private: static const int32_t ARGS_ONE = 1; static const int32_t ARGS_TWO = 2; diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index e03ebc096316afc059f342f16bfa859925f69f4d..7f5eb237adb3fcd449682790ca2e28ebea57acc2 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -385,6 +385,10 @@ napi_value Common::SetNotificationRequestByNumber( napi_create_int32(env, request->GetCreatorPid(), &value); napi_set_named_property(env, result, "creatorPid", value); + // badgeNumber?: number + napi_create_int32(env, request->GetBadgeNumber(), &value); + napi_set_named_property(env, result, "badgeNumber", value); + return NapiGetBoolean(env, true); } @@ -1440,6 +1444,11 @@ napi_value Common::GetNotificationRequestByNumber( if (GetNotificationBadgeIconStyle(env, value, request) == nullptr) { return nullptr; } + // badgeNumber?: number + if (GetNotificationBadgeNumber(env, value, request) == nullptr) { + return nullptr; + } + return NapiGetNull(env); } @@ -4174,5 +4183,31 @@ napi_value Common::SetNotificationFlags( return NapiGetBoolean(env, true); } + +napi_value Common::GetNotificationBadgeNumber( + const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + int32_t badgeNumber = 0; + + NAPI_CALL(env, napi_has_named_property(env, value, "badgeNumber", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "badgeNumber", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + + napi_get_value_int32(env, result, &badgeNumber); + request.SetBadgeNumber(badgeNumber); + } + + return NapiGetNull(env); +} } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index 9714b0c3ec8f3adf28f79b6a14ce7726de07e236..3d905b1e1551b8c61fe0159fd8d2c26da4453876 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -104,6 +104,9 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) if (ret) { asynccallbackinfo->info.errorCode = NotificationHelper::UnSubscribeNotification(*(asynccallbackinfo->objectInfo)); + if (asynccallbackinfo->info.errorCode != ERR_OK) { + DelDeletingSubscriber(asynccallbackinfo->objectInfo); + } } else { asynccallbackinfo->info.errorCode = ERR_ANS_SUBSCRIBER_IS_DELETING; } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index a23b102a213b5d6f8ccfc5ab1d319775222f590d..1752d2944f5c3d5aa12abd14677de662bcbcb678 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1988,7 +1988,6 @@ ErrCode AdvancedNotificationService::SetRecentNotificationCount(const std::strin { ANS_LOGD("%{public}s arg = %{public}s", __FUNCTION__, arg.c_str()); int32_t count = atoi(arg.c_str()); - if ((count < NOTIFICATION_MIN_COUNT) || (count > NOTIFICATION_MAX_COUNT)) { return ERR_ANS_INVALID_PARAM; } @@ -2505,7 +2504,6 @@ void AdvancedNotificationService::AdjustDateForDndTypeOnce(int64_t &beginDate, i auto newBeginTimePoint = std::chrono::system_clock::from_time_t(todayBeginT); auto newEndTimePoint = std::chrono::system_clock::from_time_t(todayEndT); - if (newBeginTimePoint >= newEndTimePoint) { newEndTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); }