From 00ea1a66a532f3e060f27cddfb4b374ad31ee217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Sat, 19 Aug 2023 17:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9D=E8=B5=96=E8=A7=A3=E8=80=A6&&=E5=A4=8F?= =?UTF-8?q?=E4=BB=A4=E6=97=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- frameworks/ans/src/reminder_request_alarm.cpp | 24 +++++++++++++++---- interfaces/inner_api/reminder_request_alarm.h | 2 ++ notification.gni | 6 +++++ services/ans/BUILD.gn | 6 ++++- services/ans/include/reminder_data_manager.h | 6 +++-- services/ans/src/reminder_data_manager.cpp | 4 ++++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp index 70e43634c..1357fc683 100644 --- a/frameworks/ans/src/reminder_request_alarm.cpp +++ b/frameworks/ans/src/reminder_request_alarm.cpp @@ -140,19 +140,35 @@ uint64_t ReminderRequestAlarm::GetNextTriggerTime(bool forceToGetNext) const } else { nextTriggerTime = target + nextDayInterval * HOURS_PER_DAY * SECONDS_PER_HOUR; } + time_t triggerTime = GetTriggerTimeWithDST(now, nextTriggerTime); struct tm test; - (void)localtime_r(&nextTriggerTime, &test); + (void)localtime_r(&triggerTime, &test); ANSR_LOGI("NextTriggerTime: year=%{public}d, mon=%{public}d, day=%{public}d, hour=%{public}d, " "min=%{public}d, sec=%{public}d, week=%{public}d, nextTriggerTime=%{public}lld", GetActualTime(TimeTransferType::YEAR, test.tm_year), GetActualTime(TimeTransferType::MONTH, test.tm_mon), test.tm_mday, test.tm_hour, test.tm_min, test.tm_sec, - GetActualTime(TimeTransferType::WEEK, test.tm_wday), (long long)nextTriggerTime); + GetActualTime(TimeTransferType::WEEK, test.tm_wday), (long long)triggerTime); - if (static_cast(nextTriggerTime) <= 0) { + if (static_cast(triggerTime) <= 0) { return 0; } - return ReminderRequest::GetDurationSinceEpochInMilli(nextTriggerTime); + return ReminderRequest::GetDurationSinceEpochInMilli(triggerTime); +} + +time_t ReminderRequestAlarm::GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const +{ + time_t triggerTime = nextTriggerTime; + struct tm nowLocal; + struct tm nextLocal; + (void)localtime_r(&now, &nowLocal); + (void)localtime_r(&nextTriggerTime, &nextLocal); + if (nowLocal.tm_isdst == 0 && nextLocal.tm_isdst > 0) { + triggerTime -= SECONDS_PER_HOUR; + } else if (nowLocal.tm_isdst > 0 && nextLocal.tm_isdst == 0) { + triggerTime += SECONDS_PER_HOUR; + } + return triggerTime; } int8_t ReminderRequestAlarm::GetNextAlarm(const time_t now, const time_t target) const diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index 837fdcbb4..e95a5ec2a 100644 --- a/interfaces/inner_api/reminder_request_alarm.h +++ b/interfaces/inner_api/reminder_request_alarm.h @@ -150,6 +150,8 @@ private: */ int8_t GetNextAlarm(const time_t now, const time_t target) const; + time_t GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const; + static const uint8_t DAYS_PER_WEEK; static const uint8_t MONDAY; static const uint8_t SUNDAY; diff --git a/notification.gni b/notification.gni index 543d27490..97f92da33 100644 --- a/notification.gni +++ b/notification.gni @@ -50,6 +50,7 @@ declare_args() { device_usage = true hisysevent_usage = true standby_enable = true + player_framework = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_usage_statistics)) { @@ -66,5 +67,10 @@ declare_args() { standby_enable = false } + if (defined(global_parts_info) && + !defined(global_parts_info.multimedia_player_framework)) { + player_framework = false + } + print("hisysevent_usage = " + "$hisysevent_usage") } diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index ade0cd52f..b7fc20094 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -83,7 +83,6 @@ ohos_shared_library("libans") { "image_framework:image_native", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", - "player_framework:media_client", "relational_store:native_rdb", "time_service:time_client", ] @@ -104,6 +103,11 @@ ohos_shared_library("libans") { defines += [ "DEVICE_STANDBY_ENABLE" ] } + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + subsystem_name = "${subsystem_name}" part_name = "${component_name}" } diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 6e079ddde..9a5cf9aee 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -21,7 +21,9 @@ #include "advanced_notification_service.h" #include "ans_inner_errors.h" +#ifdef PLAYER_FRAMEWORK_ENABLE #include "player.h" +#endif #include "reminder_request.h" #include "reminder_store.h" #include "reminder_timer_info.h" @@ -504,9 +506,9 @@ private: */ int32_t alertingReminderId_ = -1; sptr alertingReminder_ = nullptr; - +#ifdef PLAYER_FRAMEWORK_ENABLE std::shared_ptr soundPlayer_ = nullptr; - +#endif /** * Indicates the total count of reminders in system. */ diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 5a0b410a0..3ebfc4784 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1166,6 +1166,7 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem TerminateAlerting(alertingReminder_, "PlaySoundAndVibration"); } ANSR_LOGD("Play sound and vibration, reminderId=%{public}d", reminder->GetReminderId()); +#ifdef PLAYER_FRAMEWORK_ENABLE if (soundPlayer_ == nullptr) { soundPlayer_ = Media::PlayerFactory::CreatePlayer(); if (soundPlayer_ == nullptr) { @@ -1180,6 +1181,7 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem soundPlayer_->SetLooping(true); soundPlayer_->PrepareAsync(); soundPlayer_->Play(); +#endif SetAlertingReminder(reminder); } @@ -1224,6 +1226,7 @@ void ReminderDataManager::StopSoundAndVibration(const sptr &rem return; } ANSR_LOGD("Stop sound and vibration, reminderId=%{public}d", reminder->GetReminderId()); +#ifdef PLAYER_FRAMEWORK_ENABLE if (soundPlayer_ == nullptr) { ANSR_LOGW("Sound player is null"); } else { @@ -1231,6 +1234,7 @@ void ReminderDataManager::StopSoundAndVibration(const sptr &rem soundPlayer_->Release(); soundPlayer_ = nullptr; } +#endif sptr nullReminder = nullptr; SetAlertingReminder(nullReminder); } -- Gitee