diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 3197916aec4e4f7c1608785cb4759518bdf28f8e..39fe3105db9e4289f0e28c590c0e1fc8497bd39b 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -29,7 +29,6 @@ namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) { ANSR_LOGI("PublishReminder start"); - 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 2984b3143b4d01f4d7b4a22c9844bbad7ffa2cc9..06dc80e8652330cd5f6ce93a5598604ad9a598c3 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 @@ -1101,6 +1121,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 +1137,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) diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 2c0de6b23f3ab63f6925b6b1916eac72e34f86a4..67ee01eae407a0e6521d66b4acba8c8bea2ede85 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); @@ -151,7 +152,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 +274,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 df2a62a70b916060e68cc49a9bbcb46432b8e747..b74a4a4d60d9dbab2841cacab840982994ff16dc 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,12 +154,18 @@ 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 (now <= target) { - triggerTimeInMilli = static_cast(target) * MILLI_SECONDS; - ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); + 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()); } return triggerTimeInMilli; @@ -206,12 +215,16 @@ 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 < 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; + return ReminderRequest::GetDurationSinceEpochInMilli(target); } void ReminderRequestCalendar::InitDateTime() @@ -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/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index 4fc99ed1697bd1c8997ae1e76f725ae963eaac35..d0fd4337b2432cc0974cfcb9d5103ad071705014 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/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp index 7788b8fc78700801aa4bf6b9473e32b3811a655d..14f13c79bfc96216cac3edd1dcb9eb97519b546d 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 1b29bd76e39df871077f7fcc0d7f35d75b809817..8f759bb5aeaa397729cee4bc6144c64c3aa3802d 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 = { diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 8e320cda6eb4b3e877d199d79e0dd13b8575654b..14fb032d6ff2f0af0445dfee2cc70254c92418b0 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/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index 8c7d091ba166e7ef7d2abc6e7a4ef8b431b7bdd2..83ba3aba1535b91a2254f5b4fe2d09696e2fbf89 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); } diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 889058add1aa198dd02ee0ff0efa6561461d9495..b1d22285a35a000f2fea65ea06991d547efeb1d0 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 1fb4bd01d505e29e3876fbf02ee733622fc203e6..52adfccde3323e4a36e343f52e2db06b76e26392 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() @@ -703,7 +704,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; @@ -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); } @@ -982,7 +983,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,14 +1000,14 @@ 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)); } } void ReminderDataManager::StopTimerLocked(TimerType type) { - std::lock_guard lock(ReminderDataManager::MUTEX); + std::lock_guard lock(ReminderDataManager::TIMER_MUTEX); StopTimer(type); } diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index f4f75ad54477296cbb38a21b0301079da73f71d2..b864de2080181f15a6a93af6ba57338f2544bf87 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(