From 0734affb94b6e621ebbbd567e1aa1cfe173c14e5 Mon Sep 17 00:00:00 2001 From: derek Date: Tue, 22 Feb 2022 11:14:57 +0800 Subject: [PATCH 1/9] set flag to make systemUI not play sound and vibrate Signed-off-by: derek Change-Id: Icabf6a3cc1e847c045f663890799ad82443b16e3 --- frameworks/ans/native/src/reminder_request.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 2984b3143..d523b9a31 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -1101,6 +1101,9 @@ bool ReminderRequest::UpdateNextReminder(const bool &force) void ReminderRequest::UpdateNotificationCommon() { + time_t now; + (void)time(&now); // unit is seconds. + notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS); notificationRequest_->SetLabel(NOTIFICATION_LABEL); notificationRequest_->SetShowDeliveryTime(true); notificationRequest_->SetTapDismissed(true); @@ -1114,9 +1117,10 @@ void ReminderRequest::UpdateNotificationCommon() || reminderType_ == ReminderRequest::ReminderType::ALARM) { notificationRequest_->SetUnremovable(true); } - time_t now; - (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS); + auto flags = std::make_shared(); + flags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); + flags->SetVibrationEnabled(NotificationConstant::FlagStatus::CLOSE); + notificationRequest_->SetFlags(flags); } void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) -- Gitee From 7bd3e6afb8d467802c74c1d4d2151d35d8423048 Mon Sep 17 00:00:00 2001 From: derek Date: Tue, 22 Feb 2022 20:37:31 +0800 Subject: [PATCH 2/9] 1.fix app can not recieve event on wgr 2.fix calendar can not set on wgr Signed-off-by: derek Change-Id: I05b39a8d422f0cbc60e2d7476f78332bbe50d310 --- .../ans/native/src/reminder_request_calendar.cpp | 15 +++++++++++---- services/ans/src/reminder_event_manager.cpp | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index df2a62a70..877514919 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -152,11 +152,11 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTime() const tarTime.tm_min = minute_; tarTime.tm_sec = 0; + ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); if (!(repeatMonth_ > 0 && repeatDay_ > 0)) { const time_t target = mktime(&tarTime); if (now <= target) { triggerTimeInMilli = static_cast(target) * MILLI_SECONDS; - ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); } return triggerTimeInMilli; @@ -207,11 +207,18 @@ uint64_t ReminderRequestCalendar::GetTimeInstantMilli( tar.tm_min = minute; tar.tm_sec = second; const time_t target = mktime(&tar); - if (target < 0) { - ANSR_LOGW("GetTImeInstantMilli less than 0."); + if (target == -1) { + ANSR_LOGW("mktime return error."); return INVALID_LONG_LONG_VALUE; } - return static_cast(target) * MILLI_SECONDS; + auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target); + auto tarDuration = std::chrono::duration_cast(tarEndTimePoint.time_since_epoch()); + int64_t tarDate = tarDuration.count(); + if (tarDate < 0) { + ANSR_LOGW("tarDuration is less than 0."); + return INVALID_LONG_LONG_VALUE; + } + return static_cast(tarDate); } void ReminderRequestCalendar::InitDateTime() diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index f4f75ad54..b864de208 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -15,10 +15,11 @@ #include "ans_log_wrapper.h" #include "appmgr/app_mgr_constants.h" +#include "bundle_constants.h" #include "bundle_mgr_interface.h" #include "common_event_manager.h" #include "common_event_support.h" -#include "bundle_constants.h" +#include "ipc_skeleton.h" #include "reminder_event_manager.h" @@ -44,11 +45,14 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); CommonEventSubscribeInfo subscriberInfo(matchingSkills); auto subscriber = std::make_shared(subscriberInfo, reminderDataManager); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); if (CommonEventManager::SubscribeCommonEvent(subscriber)) { ANSR_LOGD("SubscribeCommonEvent ok"); } else { ANSR_LOGD("SubscribeCommonEvent fail"); } + IPCSkeleton::SetCallingIdentity(identity); } ReminderEventManager::ReminderEventSubscriber::ReminderEventSubscriber( -- Gitee From dbfd12ea66158332ca831b3d4a8ab16a9113cf39 Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 15:25:13 +0800 Subject: [PATCH 3/9] 1.add permission check 2.fix time_t static_cast issue 3.fix codex Signed-off-by: derek Change-Id: I608f7687cd116c592837c21c03d52a59c76fbba6 --- frameworks/ans/native/src/reminder_helper.cpp | 4 ++- .../ans/native/src/reminder_request.cpp | 34 +++++++++++++++---- .../ans/native/src/reminder_request_alarm.cpp | 4 +-- .../native/src/reminder_request_calendar.cpp | 11 ++---- .../ans/native/src/reminder_request_timer.cpp | 4 +-- .../ans/native/include/reminder_request.h | 3 +- services/ans/src/reminder_data_manager.cpp | 6 ++-- 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 3197916ae..a5c0e6777 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -29,7 +29,9 @@ namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) { ANSR_LOGI("PublishReminder start"); - + if (!CheckPermission()) { + return ERR_PERMISSION_DENIED; + } NotificationSlot slot(reminder.GetSlotType()); NotificationHelper::AddNotificationSlot(slot); return DelayedSingleton::GetInstance()->PublishReminder(reminder); diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index d523b9a31..06dc80e86 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -261,11 +261,11 @@ bool ReminderRequest::HandleTimeZoneChange( ANSR_LOGE("Get now time error"); return false; } - if (newZoneTriggerTime <= (static_cast(now))) { + if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) { snoozeTimesDynamic_ = 0; showImmediately = true; } else { - SetTriggerTimeInMilli(newZoneTriggerTime * MILLI_SECONDS); + SetTriggerTimeInMilli(newZoneTriggerTime); showImmediately = false; } } @@ -367,7 +367,8 @@ bool ReminderRequest::OnTimeZoneChange() struct tm *oriTime = gmtime(&oldZoneTriggerTime); time_t newZoneTriggerTime = mktime(oriTime); uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); - return HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, nextTriggerTime); + return HandleTimeZoneChange( + triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime); } ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( @@ -849,16 +850,23 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) info.title = title; actionButtonMap_.insert(std::pair(type, info)); } - InitNotificationRequest(); + if (!InitNotificationRequest()) { + return false; + } return true; } -void ReminderRequest::InitNotificationRequest() +bool ReminderRequest::InitNotificationRequest() { ANSR_LOGI("Init notification"); - notificationRequest_ = new NotificationRequest(notificationId_); + notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + if (notificationRequest_ == nullptr) { + ANSR_LOGE("Failed to create notification."); + return false; + } displayContent_ = content_; AddActionButtons(true); + return true; } bool ReminderRequest::IsAlerting() const @@ -866,6 +874,18 @@ bool ReminderRequest::IsAlerting() const return (state_ & REMINDER_STATUS_ALERTING) != 0; } +uint64_t ReminderRequest::GetDurationSinceEpochInMilli(const time_t target) +{ + auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target); + auto tarDuration = std::chrono::duration_cast(tarEndTimePoint.time_since_epoch()); + int64_t tarDate = tarDuration.count(); + if (tarDate < 0) { + ANSR_LOGW("tarDuration is less than 0."); + return INVALID_LONG_LONG_VALUE; + } + return static_cast(tarDate); +} + std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const { return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS); @@ -879,7 +899,7 @@ uint64_t ReminderRequest::GetNowInstantMilli() const ANSR_LOGE("Get now time error"); return 0; } - return static_cast(now) * MILLI_SECONDS; + return GetDurationSinceEpochInMilli(now); } std::string ReminderRequest::GetShowTime(const uint64_t showTime) const diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 2c0de6b23..8bfde145b 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -151,7 +151,7 @@ uint64_t ReminderRequestAlarm::GetNextTriggerTime(bool forceToGetNext) const if (static_cast(nextTriggerTime) <= 0) { return 0; } - return static_cast(nextTriggerTime) * ReminderRequest::MILLI_SECONDS; + return ReminderRequest::GetDurationSinceEpochInMilli(nextTriggerTime); } int8_t ReminderRequestAlarm::GetNextAlarm(const time_t now, const time_t target) const @@ -273,7 +273,7 @@ bool ReminderRequestAlarm::Marshalling(Parcel &parcel) const ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New alarm"); - auto objptr = new ReminderRequestAlarm(); + auto objptr = new (std::nothrow) ReminderRequestAlarm(); if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 877514919..1662c758e 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -156,7 +156,7 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTime() const if (!(repeatMonth_ > 0 && repeatDay_ > 0)) { const time_t target = mktime(&tarTime); if (now <= target) { - triggerTimeInMilli = static_cast(target) * MILLI_SECONDS; + triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target); ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); } return triggerTimeInMilli; @@ -211,14 +211,7 @@ uint64_t ReminderRequestCalendar::GetTimeInstantMilli( ANSR_LOGW("mktime return error."); return INVALID_LONG_LONG_VALUE; } - auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target); - auto tarDuration = std::chrono::duration_cast(tarEndTimePoint.time_since_epoch()); - int64_t tarDate = tarDuration.count(); - if (tarDate < 0) { - ANSR_LOGW("tarDuration is less than 0."); - return INVALID_LONG_LONG_VALUE; - } - return static_cast(tarDate); + return ReminderRequest::GetDurationSinceEpochInMilli(target); } void ReminderRequestCalendar::InitDateTime() diff --git a/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index 4fc99ed16..d0fd4337b 100644 --- a/frameworks/ans/native/src/reminder_request_timer.cpp +++ b/frameworks/ans/native/src/reminder_request_timer.cpp @@ -31,7 +31,7 @@ ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) time_t now; // unit is seconds. (void)time(&now); ReminderRequest::SetTriggerTimeInMilli( - (static_cast(now) + countDownTimeInSeconds_) * ReminderRequest::MILLI_SECONDS); + ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS); sptr timer = MiscServices::TimeServiceClient::GetInstance(); firstRealTimeInMilliSeconds_ = timer->GetBootTimeMs(); } @@ -88,7 +88,7 @@ void ReminderRequestTimer::UpdateTimeInfo(const std::string description) ANSR_LOGD("%{public}s, update countdown time trigger time", description.c_str()); time_t now; (void)time(&now); // unit is seconds. - whenToChangeSysTime_ = static_cast(now) * MILLI_SECONDS; + whenToChangeSysTime_ = ReminderRequest::GetDurationSinceEpochInMilli(now); sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootTime = timer->GetBootTimeMs(); SetTriggerTimeInMilli(whenToChangeSysTime_ + (countDownTimeInSeconds_ * MILLI_SECONDS - diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 8e320cda6..14fb032d6 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -560,6 +560,7 @@ public: static const std::string PARAM_REMINDER_ID; static int GetActualTime(const TimeTransferType &type, int cTime); static int GetCTime(const TimeTransferType &type, int actualTime); + static uint64_t GetDurationSinceEpochInMilli(const time_t target); static int32_t GetUid(const int &userId, const std::string &bundleName); static int GetUserId(const int &uid); @@ -583,7 +584,7 @@ private: std::string GetState(const uint8_t state) const; bool HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime); bool HandleTimeZoneChange(uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime); - void InitNotificationRequest(); + bool InitNotificationRequest(); void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); void SetState(bool deSet, const uint8_t newState, std::string function); void SetWantAgent(AppExecFwk::ElementName &element); diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 1fb4bd01d..47c7cbac8 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -703,7 +703,7 @@ sptr ReminderDataManager::GetRecentReminderLocked() time_t now; (void)time(&now); // unit is seconds. if (now < 0 - || static_cast(now) * ReminderRequest::MILLI_SECONDS > (*it)->GetTriggerTimeInMilli()) { + || ReminderRequest::GetDurationSinceEpochInMilli(now) > (*it)->GetTriggerTimeInMilli()) { ANSR_LOGE("Get recent reminder while the trigger time is overdue."); it++; continue; @@ -982,7 +982,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGE("Alerting time out timer has already started."); break; } - triggerTime = static_cast(now) * ReminderRequest::MILLI_SECONDS + triggerTime = ReminderRequest::GetDurationSinceEpochInMilli(now) + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type)); timer->StartTimer(timerIdAlerting_, triggerTime); @@ -999,7 +999,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGW("Start timer fail"); } else { ANSR_LOGD("Timing info: now:(%{public}llu), tar:(%{public}llu)", - (unsigned long long)(static_cast(now) * ReminderRequest::MILLI_SECONDS), + (unsigned long long)(ReminderRequest::GetDurationSinceEpochInMilli(now)), (unsigned long long)(triggerTime)); } } -- Gitee From 4930936f6500fd725903004f5120f188923e672c Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 15:51:28 +0800 Subject: [PATCH 4/9] rm permission check Signed-off-by: derek Change-Id: I0c8b6a3919a71694e9a1bbfd434648025efe1f68 --- frameworks/ans/native/src/reminder_helper.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index a5c0e6777..39fe3105d 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -29,9 +29,6 @@ namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) { ANSR_LOGI("PublishReminder start"); - if (!CheckPermission()) { - return ERR_PERMISSION_DENIED; - } NotificationSlot slot(reminder.GetSlotType()); NotificationHelper::AddNotificationSlot(slot); return DelayedSingleton::GetInstance()->PublishReminder(reminder); -- Gitee From 64518610a37536093a37245728c52e43d1b3329d Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 18:14:23 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix=20wgr=20calendar=20set=20error(?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD=E5=A4=8F=E4=BB=A4=E6=97=B6?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: derek Change-Id: I46ef23f1ee069256fc99861639ab3b6a489df1bc --- .../ans/native/src/reminder_request_alarm.cpp | 1 + .../ans/native/src/reminder_request_calendar.cpp | 15 +++++++++++++++ .../napi/ans/src/reminder/reminder_common.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 8bfde145b..67ee01eae 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -122,6 +122,7 @@ uint64_t ReminderRequestAlarm::GetNextTriggerTime(bool forceToGetNext) const tar.tm_hour = hour_; tar.tm_min = minute_; tar.tm_sec = 0; + tar.tm_isdst = -1; const time_t target = mktime(&tar); int8_t nextDayInterval = GetNextAlarm(now, target); diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 1662c758e..ef4d799df 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -113,6 +113,7 @@ uint8_t ReminderRequestCalendar::GetNextDay( setTime.tm_hour = target.tm_hour; setTime.tm_min = target.tm_min; setTime.tm_sec = target.tm_sec; + setTime.tm_isdst = -1; struct tm nowTime; nowTime.tm_year = now.tm_year; @@ -121,6 +122,8 @@ uint8_t ReminderRequestCalendar::GetNextDay( nowTime.tm_hour = now.tm_hour; nowTime.tm_min = now.tm_min; nowTime.tm_sec = now.tm_sec; + nowTime.tm_isdst = -1; + if (mktime(&nowTime) >= mktime(&setTime)) { continue; } else { @@ -151,10 +154,16 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTime() const tarTime.tm_hour = hour_; tarTime.tm_min = minute_; tarTime.tm_sec = 0; + tarTime.tm_isdst = -1; ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); if (!(repeatMonth_ > 0 && repeatDay_ > 0)) { + ANSR_LOGD("tarTime: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", + tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec); const time_t target = mktime(&tarTime); + if (target == -1) { + ANSR_LOGW("mktime return error."); + } if (now <= target) { triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target); ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); @@ -206,6 +215,10 @@ uint64_t ReminderRequestCalendar::GetTimeInstantMilli( tar.tm_hour = hour; tar.tm_min = minute; tar.tm_sec = second; + tar.tm_isdst = -1; + + ANSR_LOGD("tar: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", + tar.tm_year, tar.tm_mon, tar.tm_mday, tar.tm_hour, tar.tm_min, tar.tm_sec); const time_t target = mktime(&tar); if (target == -1) { ANSR_LOGW("mktime return error."); @@ -222,6 +235,7 @@ void ReminderRequestCalendar::InitDateTime() dateTime_.tm_hour = hour_; dateTime_.tm_min = minute_; dateTime_.tm_sec = second_; + dateTime_.tm_isdst = -1; } void ReminderRequestCalendar::InitDateTime(const tm &dateTime) @@ -232,6 +246,7 @@ void ReminderRequestCalendar::InitDateTime(const tm &dateTime) dateTime_.tm_hour = dateTime.tm_hour; dateTime_.tm_min = dateTime.tm_min; dateTime_.tm_sec = dateTime.tm_sec; + dateTime_.tm_isdst = -1; } bool ReminderRequestCalendar::IsRepeatReminder() const diff --git a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index 8c7d091ba..83ba3aba1 100644 --- a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp +++ b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp @@ -446,6 +446,7 @@ napi_value ReminderCommon::CreateReminderCalendar( dateTime.tm_hour = propertyHourVal; dateTime.tm_min = propertyMinteVal; dateTime.tm_sec = 0; + dateTime.tm_isdst = -1; reminder = std::make_shared(dateTime, repeatMonths, repeatDays); return NotificationNapi::Common::NapiGetNull(env); } -- Gitee From fd96085c306d4d40db3a3f143a0a8a2309c3e98b Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 18:27:13 +0800 Subject: [PATCH 6/9] fix codecheck Signed-off-by: derek Change-Id: I5a4bfd5e3fc73ad3cb774fe0a308cfabe39b0c8d --- frameworks/ans/native/src/reminder_request_calendar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index ef4d799df..6639245cc 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -159,7 +159,7 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTime() const ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); if (!(repeatMonth_ > 0 && repeatDay_ > 0)) { ANSR_LOGD("tarTime: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", - tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec); + tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec); const time_t target = mktime(&tarTime); if (target == -1) { ANSR_LOGW("mktime return error."); -- Gitee From 2908e64c50b7d2a57e4d38e541afdd6e8695682c Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 21:33:28 +0800 Subject: [PATCH 7/9] fix lock error Signed-off-by: derek Change-Id: Iba64d6e92b032f47062f2282f2ab6d6eec74b053 --- services/ans/include/reminder_data_manager.h | 1 + services/ans/src/reminder_data_manager.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 889058add..b1d22285a 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -391,6 +391,7 @@ private: static std::mutex MUTEX; static std::mutex SHOW_MUTEX; static std::mutex ALERT_MUTEX; + static std::mutex TIMER_MUTEX; /** * Max number of reminders limit for the whole system. diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 47c7cbac8..52adfccde 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -33,6 +33,7 @@ std::shared_ptr ReminderDataManager::REMINDER_DATA_MANAGER std::mutex ReminderDataManager::MUTEX; std::mutex ReminderDataManager::SHOW_MUTEX; std::mutex ReminderDataManager::ALERT_MUTEX; +std::mutex ReminderDataManager::TIMER_MUTEX; void ReminderDataManager::PublishReminder(sptr &reminder, sptr &bundleOption) @@ -322,6 +323,7 @@ void ReminderDataManager::CloseReminder(const OHOS::EventFwk::Want &want, bool c return; } CloseReminder(reminder, cancelNotification); + StartRecentReminder(); } void ReminderDataManager::CloseReminder(const sptr &reminder, bool cancelNotification) @@ -341,7 +343,6 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b if (cancelNotification) { CancelNotification(reminder); } - StartRecentReminder(); } std::shared_ptr ReminderDataManager::GetInstance() @@ -950,7 +951,7 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) void ReminderDataManager::StartTimerLocked(const sptr &reminderRequest, TimerType type) { - std::lock_guard lock(ReminderDataManager::MUTEX); + std::lock_guard lock(ReminderDataManager::TIMER_MUTEX); StartTimer(reminderRequest, type); } @@ -1006,7 +1007,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques void ReminderDataManager::StopTimerLocked(TimerType type) { - std::lock_guard lock(ReminderDataManager::MUTEX); + std::lock_guard lock(ReminderDataManager::TIMER_MUTEX); StopTimer(type); } -- Gitee From fce0fe91da36dacb65b3e266b03edbdbcb4fbe2d Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 23 Feb 2022 22:25:59 +0800 Subject: [PATCH 8/9] calendar fix overDual judge from now <= target to now < target Signed-off-by: derek Change-Id: I472a5cf4f1562b9b343da0a2d646e8cf31c77b48 --- frameworks/ans/native/src/reminder_request_calendar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 6639245cc..b74a4a4d6 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -164,7 +164,7 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTime() const if (target == -1) { ANSR_LOGW("mktime return error."); } - if (now <= target) { + if (now < target) { triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target); ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); } -- Gitee From 9ca60742236bc9edfcedaaafff0edd4304048c8a Mon Sep 17 00:00:00 2001 From: derek Date: Thu, 24 Feb 2022 16:26:44 +0800 Subject: [PATCH 9/9] update test case desc Signed-off-by: derek Change-Id: Icba7fe258f4948c74ab124a9ca23540e640da89d --- .../test/unittest/reminder_request_test.cpp | 42 +++++++++---------- .../ans/test/moduletest/ReminderHelperTest.js | 12 +++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp index 7788b8fc7..14f13c79b 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp @@ -41,7 +41,7 @@ const uint8_t ReminderRequestTest::REMINDER_STATUS_SHOWING = 4; * @tc.name: CanRemove_00100 * @tc.desc: When reminder init, CanRemove should return true. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) { @@ -53,7 +53,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) * @tc.name: CanRemove_00200 * @tc.desc: When reminder is shown, CanRemove should return false. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) { @@ -66,7 +66,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) * @tc.name: CanRemove_00300 * @tc.desc: When reminder close, CanRemove should return true. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) { @@ -80,7 +80,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) * @tc.name: CanRemove_00400 * @tc.desc: When reminder is covered as same notification id, CanRemove should return true. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) { @@ -95,7 +95,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) * @tc.name: StateCheck_00100 * @tc.desc: When reminder init, state should be 0. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) { @@ -107,7 +107,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) * @tc.name: StateCheck_00200 * @tc.desc: When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) { @@ -120,7 +120,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) * @tc.name: StateCheck_00300 * @tc.desc: When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) { @@ -133,7 +133,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) * @tc.name: StateCheck_00400 * @tc.desc: When reminder is covered as same notification id, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) { @@ -146,7 +146,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) * @tc.name: StateCheck_00500 * @tc.desc: When reminder is shown with param true,true, state REMINDER_STATUS_SHOWING should be set. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) { @@ -159,7 +159,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) * @tc.name: StateCheck_00600 * @tc.desc: When reminder is shown with param false,true, state REMINDER_STATUS_SHOWING should be set. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) { @@ -172,7 +172,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) * @tc.name: StateCheck_00700 * @tc.desc: When reminder is shown with param true,false, state REMINDER_STATUS_SHOWING should not change. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) { @@ -186,7 +186,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) * @tc.name: StateCheck_00800 * @tc.desc: When reminder is shown with param false,false, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) { @@ -200,7 +200,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) * @tc.name: initReminderId_00100 * @tc.desc: When reminder create successfully, system should assign unique id to reminder. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level1) { @@ -216,7 +216,7 @@ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level * @tc.name: setContent_00100 * @tc.desc: Test SetContent with normal parameters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) { @@ -230,7 +230,7 @@ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) * @tc.name: setContent_00200 * @tc.desc: Test SetContent parameters with special characters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) { @@ -244,7 +244,7 @@ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) * @tc.name: setExpiredContent_00100 * @tc.desc: Test SetExpiredContent with normal parameters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U + * @tc.require: SR000GGTRD AR000GH8EF AR000GNF1U AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Level1) { @@ -258,7 +258,7 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Le * @tc.name: setExpiredContent_00200 * @tc.desc: Test SetExpiredContent with special characters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U + * @tc.require: SR000GGTRD AR000GH8EF AR000GNF1U AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Level1) { @@ -272,7 +272,7 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Le * @tc.name: setTitle_00100 * @tc.desc: Test SetTitle with normal parameters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) { @@ -286,7 +286,7 @@ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) * @tc.name: setTitle_00200 * @tc.desc: Test SetTitle with special characters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) { @@ -300,7 +300,7 @@ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) * @tc.name: setNotificationId_00100 * @tc.desc: Test SetNotificationId parameters. * @tc.type: FUNC - * @tc.require: SR000GGGTRD AR000GH8EF + * @tc.require: SR000GGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Level1) { @@ -314,7 +314,7 @@ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Le * @tc.name: setSnoozeTimes_00100 * @tc.desc: Test SetSnoozeTimes parameters. * @tc.type: FUNC - * @tc.require: AR000GNF1T + * @tc.require: AR000GNF1T AR000GH8E7 */ HWTEST_F(ReminderRequestTest, setSnoozeTimes_00100, Function | SmallTest | Level1) { diff --git a/frameworks/ans/test/moduletest/ReminderHelperTest.js b/frameworks/ans/test/moduletest/ReminderHelperTest.js index 1b29bd76e..8f759bb5a 100644 --- a/frameworks/ans/test/moduletest/ReminderHelperTest.js +++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js @@ -52,7 +52,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper001 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH + * @tc.require: SR000GGTRB AR000GH8EH AR000GH8E9 AR00GH8EH */ it("testReminderHelper001", 0, async function (done) { let timer = { @@ -82,7 +82,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper002 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH + * @tc.require: SR000GGTRB AR000GH8EH AR000GH8E9 AR00GH8EH */ it("testReminderHelper002", 0, async function (done) { let timer = { @@ -205,7 +205,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper008 * @tc.desc: test cancelAllReminders can cancel all exist reminders * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8EA + * @tc.require: SR000GGTRB AR000GH8EA AR000GH8EF AR000GH8EI */ it("testReminderHelper008", 0, async function (done) { let timer = { @@ -373,7 +373,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper013 * @tc.desc: test getValidReminders, verify all the information is correct. * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8EB + * @tc.require: SR000GGTRB AR000GH8EB AR000GH8EF */ it("testReminderHelper013", 0, async function (done) { var alarm = { @@ -567,7 +567,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper022 * @tc.desc: test publishReminder a normal alarm. * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH AR000GH8EE */ it("testReminderHelper022", 0, async function (done) { let alarm = { @@ -855,7 +855,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper027 * @tc.desc: test publishReminder (max number limit of each application) * @tc.type: FUNC - * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH + * @tc.require: SR000GGTRE AR000GH8E9 AR00GH8EH */ it("testReminderHelper027", 0, async function (done) { let timer = { -- Gitee