From b5f414037e2f886f4be85de17e85362d8ec56053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 8 Dec 2023 06:15:55 +0000 Subject: [PATCH 1/5] =?UTF-8?q?update=20frameworks/js/napi/include/reminde?= =?UTF-8?q?r/reminder=5Fcommon.h.=20codex=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/js/napi/include/reminder/reminder_common.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 604127a41..dbacbff30 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -160,6 +160,15 @@ private: static void HandleActionButtonTitle(const napi_env &env, const napi_value &actionButton, std::shared_ptr& reminder, const char* str, int32_t buttonType); + + static void GenReminderStringInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder); + + static bool GenReminderIntInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder); + + static void GenReminderBoolInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder); static napi_value ParseInt32Array(const napi_env &env, const napi_value &value, const char* propertyName, std::vector &propertyVal, uint8_t maxLen); -- Gitee From 25d923f1d3ebc15aad45099b6ffee09c23cdcf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 8 Dec 2023 06:54:06 +0000 Subject: [PATCH 2/5] =?UTF-8?q?update=20frameworks/js/napi/src/reminder/re?= =?UTF-8?q?minder=5Fcommon.cpp.=20codex=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../js/napi/src/reminder/reminder_common.cpp | 96 ++++++++++--------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 5592b3b9a..4cccd6993 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -436,6 +436,30 @@ napi_value ReminderCommon::GenReminder( return nullptr; } bool isSysApp = IsSelfSystemApp(reminder); + GenReminderStringInner(env, value, reminder); + if (!GenReminderIntInner(env, value, reminder)) { + return nullptr; + } + GenReminderBoolInner(env, value, reminder); + + // wantAgent + if (!GenWantAgent(env, value, reminder, isSysApp)) { + return nullptr; + } + + // maxScreenWantAgent + GenMaxScreenWantAgent(env, value, reminder); + + // actionButtons + if (!GenActionButtons(env, value, reminder, isSysApp)) { + return nullptr; + } + return NotificationNapi::Common::NapiGetNull(env); +} + +void ReminderCommon::GenReminderStringInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder) +{ char str[NotificationNapi::STR_MAX_SIZE] = {0}; // title @@ -458,13 +482,22 @@ napi_value ReminderCommon::GenReminder( reminder->SetSnoozeContent(std::string(str)); } + // group id + if (GetStringUtf8(env, value, ReminderAgentNapi::GROUP_ID, str, NotificationNapi::STR_MAX_SIZE)) { + reminder->SetGroupId(std::string(str)); + } +} + +bool ReminderCommon::GenReminderIntInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder) +{ // ringDuration int64_t propVal = 0; if (GetInt64(env, value, ReminderAgentNapi::RING_DURATION, propVal)) { if (propVal < 0) { reminder->SetRingDuration(0); } else { - uint64_t ringDuration = static_cast(propVal); + uint16_t ringDuration = static_cast(propVal); reminder->SetRingDuration(ringDuration); } } @@ -474,7 +507,7 @@ napi_value ReminderCommon::GenReminder( if (propVal < 0) { reminder->SetTimeInterval(0); } else { - uint64_t timeInterval = static_cast(propVal); + uint16_t timeInterval = static_cast(propVal); reminder->SetTimeInterval(timeInterval); } } @@ -490,7 +523,7 @@ napi_value ReminderCommon::GenReminder( if (propertyVal < 0) { reminder->SetSnoozeTimes(0); } else { - uint8_t snoozeTimes = propertyVal > UINT8_MAX ? UINT8_MAX : static_cast(propertyVal); + uint8_t snoozeTimes = propertyVal > UINT8_MAX : static_cast(propertyVal); reminder->SetSnoozeTimes(static_cast(snoozeTimes)); } } @@ -499,62 +532,31 @@ napi_value ReminderCommon::GenReminder( int32_t slotType = 0; if (GetInt32(env, value, ReminderAgentNapi::SLOT_TYPE, slotType, false)) { enum NotificationConstant::SlotType actureType = NotificationConstant::SlotType::OTHER; - if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(slotType), actureType)) { - ANSR_LOGW("slot type not support."); - return nullptr; + if (NotificationNapi::SlotTypeJSToc(NotificationNapi::SlotType(slotType), actureType)) { + ANSR_LOGW("slot type not support"); + return false; } reminder->SetSlotType(actureType); } - // snoozeSlotType - int32_t snoozeSlotType = 0; - if (GetInt32(env, value, ReminderAgentNapi::SNOOZE_SLOT_TYPE, snoozeSlotType, false)) { - enum NotificationConstant::SlotType actureSnoozeType = NotificationConstant::SlotType::OTHER; - if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(snoozeSlotType), actureSnoozeType)) { - ANSR_LOGW("snooze slot type not support."); - return nullptr; + // autoDeletedTime + int64_t actoDeletedTime = 0; + if (GetInt64(env, value, ReminderAgentNapi::AUTODELETEDTIME, actoDeletedTime)) { + if (actoDeletedTime > 0) { + reminder->SetActoDeletedTime(actoDeletedTime); } - reminder->SetSnoozeSlotType(actureSnoozeType); } + return true; +} +void ReminderCommon::GenReminderBoolInner( + const napi_env &env, const napi_value &value, std::shared_ptr& reminder) +{ // tapDismissed bool tapDismissed = false; if (GetBool(env, value, ReminderAgentNapi::TAPDISMISSED, tapDismissed)) { reminder->SetTapDismissed(tapDismissed); } - - //autoDeletedTime - int64_t autoDeletedTime = 0; - if (GetInt64(env, value, ReminderAgentNapi::AUTODELETEDTIME, autoDeletedTime)) { - if (autoDeletedTime > 0) { - reminder->SetAutoDeletedTime(autoDeletedTime); - } - } - - // wantAgent - if (!GenWantAgent(env, value, reminder, isSysApp)) { - return nullptr; - } - - // maxScreenWantAgent - GenMaxScreenWantAgent(env, value, reminder); - - // actionButtons - if (!GenActionButtons(env, value, reminder, isSysApp)) { - return nullptr; - } - - // group id - if (GetStringUtf8(env, value, ReminderAgentNapi::GROUP_ID, str, NotificationNapi::STR_MAX_SIZE)) { - reminder->SetGroupId(std::string(str)); - } - - // custom ring uri - if (GetStringUtf8(env, value, ReminderAgentNapi::CUSTOM_RING_URI, str, NotificationNapi::STR_MAX_SIZE)) { - reminder->SetCustomRingUri(std::string(str)); - } - - return NotificationNapi::Common::NapiGetNull(env); } bool ReminderCommon::GetStringUtf8(const napi_env &env, const napi_value &value, -- Gitee From 5f229c0d8e1aaa8131323d4f2f5ca4c6fe056a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 8 Dec 2023 06:59:48 +0000 Subject: [PATCH 3/5] =?UTF-8?q?update=20services/ans/include/reminder=5Fda?= =?UTF-8?q?ta=5Fmanager.h.=20codex=E8=B6=85=E5=A4=A7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/ans/include/reminder_data_manager.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 70e14cd7a..8d8b64b91 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -32,6 +32,7 @@ #include "datashare_predicates.h" #include "datashare_values_bucket.h" #include "app_mgr_interface.h" +#include "time_service_client.h" namespace OHOS { namespace Notification { @@ -503,6 +504,11 @@ private: void StartTimerLocked(const sptr &reminderRequest, TimerType type); void StartTimer(const sptr &reminderRequest, TimerType type); + uint64_t HandleTriggerTimeInner(const sptr &reminderRequest, TimerType type, + const sptr &timer); + uint64_t HandleAlertingTimeInner(const sptr &reminderRequest, TimerType type, + const sptr &timer, time_t now); + /** * @brief Stop the alerting timer and update reminder information. * -- Gitee From 8688583c759b715ad685cf4234da7fb50f68b0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 8 Dec 2023 07:25:11 +0000 Subject: [PATCH 4/5] =?UTF-8?q?update=20services/ans/src/reminder=5Fdata?= =?UTF-8?q?=5Fmanager.cpp.=20codex=E8=B6=85=E5=A4=A7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/ans/src/reminder_data_manager.cpp | 61 +++++++++++++--------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 11418bc39..961e90c82 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()) { + ANSR_LOGW("reminder pageage 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,16 @@ 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 packageName is null or default close reminder, \ + the group id is not set, this reminder can not close by groupId"); 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); UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::CLOSE); StartRecentReminder(); @@ -1599,11 +1595,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGE("Trigger timer has already started."); break; } - SetActiveReminder(reminderRequest); - timerId_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); - triggerTime = reminderRequest->GetTriggerTimeInMilli(); - timer->StartTimer(timerId_, triggerTime); - ANSR_LOGD("Start timing (next triggerTime), timerId=%{public}" PRIu64 "", timerId_); + triggerTime = HandleTriggerTimeInner(reminderRequest, type, time); break; } case TimerType::ALERTING_TIMER: { @@ -1611,12 +1603,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGE("Alerting time out timer has already started."); break; } - triggerTime = ReminderRequest::GetDurationSinceEpochInMilli(now) - + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); - timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); - timer->StartTimer(timerIdAlerting_, triggerTime); - ANSR_LOGD( - "Start timing (alerting time out), timerId=%{public}" PRIu64 "", timerIdAlerting_); + triggerTime = HandleAlertingTimeInner(reminderRequest, type, time, now); break; } default: { @@ -1632,6 +1619,30 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques } } +uint64_t ReminderDataManager::HandleTriggerTimeInner(const sprt &reminderRequest, TimerType type, + const sptr &time) +{ + uint64_t triggerTime = 0; + SetActiveReminder(reminderRequest); + timerId_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); + triggerTime = reminderRequest->GetTriggerTimeInMilli(); + timer->StartTimer(timerId_, triggerTime); + ANSR_LOGD("Start timing (next triggerTime), timerId=%{public}" PRIu64 "", timerId_); + return triggerTime; +} + +uint64_t ReminderDataManager::HandleAlertingTimeInner(const sprt &reminderRequest, TimerType type, + const sptr &time, time_t now) +{ + uint64_t triggerTime = 0; + triggerTime = ReminderRequest::GetDurationSinceEpochInMilli(now) + + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); + timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); + timer->StartTimer(timerIdAlerting_, triggerTime); + ANSR_LOGD("Start timing (alerting time out), timerId=%{public}" PRIu64 "", timerIdAlerting_); + return triggerTime; +} + void ReminderDataManager::StopTimerLocked(TimerType type) { std::lock_guard lock(ReminderDataManager::TIMER_MUTEX); -- Gitee From 74a73d0ea6e2680947493902d903b53d74c21176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 8 Dec 2023 07:40:47 +0000 Subject: [PATCH 5/5] =?UTF-8?q?update=20frameworks/js/napi/src/reminder/re?= =?UTF-8?q?minder=5Fcommon.cpp.=20codex=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/js/napi/src/reminder/reminder_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 4cccd6993..cabdcb545 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -497,7 +497,7 @@ bool ReminderCommon::GenReminderIntInner( if (propVal < 0) { reminder->SetRingDuration(0); } else { - uint16_t ringDuration = static_cast(propVal); + uint64_t ringDuration = static_cast(propVal); reminder->SetRingDuration(ringDuration); } } @@ -507,7 +507,7 @@ bool ReminderCommon::GenReminderIntInner( if (propVal < 0) { reminder->SetTimeInterval(0); } else { - uint16_t timeInterval = static_cast(propVal); + uint64_t timeInterval = static_cast(propVal); reminder->SetTimeInterval(timeInterval); } } -- Gitee