diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 604127a41e003305b0e5c95b820f3bcac2d8589d..dbacbff3083744aa60776941bcfd92214389b444 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); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 5592b3b9a1882cf2b47fdc303cc1ce33a2c6c4a8..cabdcb5451b0a11de9a817b349dee28af5618e04 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,6 +482,15 @@ 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)) { @@ -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, diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 70e14cd7a9fd7b13cf43508c0a4b3181b0c446f4..8d8b64b91713beb15d9a6ee73c48a424f3390935 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. * diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 11418bc39a3592fcf2cde64f2d3cb34de1eb386f..961e90c82274cf0176a5ae9dec610c3f9cfb0ab3 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);