From 9aa9f15b493886d6cf835c54ff341257d7c75154 Mon Sep 17 00:00:00 2001 From: mubaoyu Date: Fri, 17 Nov 2023 14:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=87=8D=E5=90=AF=E5=90=8Egr?= =?UTF-8?q?oupId=E5=8A=9F=E8=83=BD=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mubaoyu --- frameworks/ans/src/reminder_request.cpp | 4 ++-- services/ans/src/reminder_data_manager.cpp | 23 +++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index f66e845f7..702597127 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -1109,6 +1109,7 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); // write bool @@ -1121,7 +1122,6 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const WRITE_INT32_RETURN_FALSE_LOG(parcel, reminderId_, "reminderId"); WRITE_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); WRITE_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); WRITE_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); WRITE_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); @@ -1205,6 +1205,7 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); READ_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); + READ_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); READ_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); READ_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); @@ -1219,7 +1220,6 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); - READ_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); READ_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); READ_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); READ_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index b321471ee..a8badf685 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -181,12 +181,12 @@ void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageNa bool ReminderDataManager::IsMatchedForGroupIdAndPkgName(const sptr &reminder, const std::string &packageName, const std::string &groupId) const { - sptr notification = reminder->GetNotificationRequest(); - if (notification == nullptr) { - ANSR_LOGW("IsMatchedForGroupIdAndPkgName not find the notification"); + std::string packageNameTemp = reminder->GetBundleName(); + if (packageNameTemp.empty()) { + ANS_LOGW("reminder package name is null!"); return false; } - if (notification->GetCreatorBundleName() == packageName && reminder->GetGroupId() == groupId) { + if (packageNameTemp == packageName && reminder->GetGroupId() == groupId) { return true; } return false; @@ -500,20 +500,15 @@ void ReminderDataManager::CloseReminder(const OHOS::EventFwk::Want &want, bool c ANSR_LOGW("Invalid reminder id: %{public}d", reminderId); return; } - sptr notificationRequest = reminder->GetNotificationRequest(); - if (notificationRequest == nullptr) { - ANSR_LOGW("notificationRequest is not find, this reminder can`t close by groupId"); + std::string packageName = reminder->GetBundleName(); + std::string groupId = reminder->GetGroupId(); + if (packageName.empty() || groupId.empty()) { + ANSR_LOGW("reminder package name is null or the group id is not set, this reminder can not close by group id!"); CloseReminder(reminder, cancelNotification); StartRecentReminder(); CheckNeedNotifyStatus(reminder, ReminderRequest::ActionButtonType::CLOSE); - return; - } - std::string bundleName = notificationRequest->GetCreatorBundleName(); - std::string groupId = reminder->GetGroupId(); - if (!groupId.empty()) { - ANSR_LOGD("close reminder, the group id is set."); - CloseRemindersByGroupId(reminderId, bundleName, groupId); } + CloseRemindersByGroupId(reminderId, packageName, groupId); CloseReminder(reminder, cancelNotification); StartRecentReminder(); CheckNeedNotifyStatus(reminder, ReminderRequest::ActionButtonType::CLOSE); -- Gitee