From d86175329006747d884afb905b7b103580d50789 Mon Sep 17 00:00:00 2001 From: derek Date: Mon, 7 Mar 2022 22:49:53 +0800 Subject: [PATCH 1/3] fix codex Signed-off-by: derek --- frameworks/ans/core/BUILD.gn | 2 +- frameworks/ans/core/src/ans_manager_proxy.cpp | 2 +- frameworks/ans/native/BUILD.gn | 2 +- frameworks/ans/native/src/reminder_helper.cpp | 6 +-- .../ans/native/src/reminder_request.cpp | 49 +++++++++++------ .../ans/native/src/reminder_request_alarm.cpp | 12 +++-- .../native/src/reminder_request_calendar.cpp | 34 ++++++------ .../ans/native/src/reminder_request_timer.cpp | 21 +++++--- .../unittest/reminder_request_alarm_test.cpp | 2 +- .../reminder_request_calendar_test.cpp | 2 +- .../test/unittest/reminder_request_test.cpp | 2 +- .../unittest/reminder_request_timer_test.cpp | 2 +- frameworks/ans/test/moduletest/config.json | 13 ++++- .../ans/native/include/reminder_helper.h | 4 +- .../ans/native/include/reminder_request.h | 11 ++-- .../native/include/reminder_request_alarm.h | 2 +- .../include/reminder_request_calendar.h | 14 ++++- .../native/include/reminder_request_timer.h | 8 +-- .../ans/include/reminder/reminder_common.h | 2 +- .../napi/ans/src/reminder/native_module.cpp | 4 +- .../kits/napi/ans/src/reminder/publish.cpp | 24 ++++----- .../napi/ans/src/reminder/reminder_common.cpp | 22 ++++---- services/ans/include/reminder_data_manager.h | 16 +++--- services/ans/include/reminder_event_manager.h | 2 +- services/ans/include/reminder_timer_info.h | 2 +- .../ans/src/advanced_notification_service.cpp | 24 +++++++-- services/ans/src/reminder_data_manager.cpp | 54 +++++++++++-------- services/ans/src/reminder_event_manager.cpp | 5 +- services/ans/src/reminder_timer_info.cpp | 6 +-- 29 files changed, 217 insertions(+), 132 deletions(-) diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index fdca50b6d..8c1172118 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index 000af8c28..1199f44fd 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -2302,7 +2302,7 @@ ErrCode AnsManagerProxy::GetValidReminders(std::vector> &r ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); return ERR_ANS_PARCELABLE_FAILED; } - ANSR_LOGD("[GetValidReminders] count=%{public}u", count); + ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); reminders.clear(); result = ReadReminders(count, reply, reminders); if (result != ERR_OK) { diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index a0aa9d6cc..059c83526 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 5e518b771..524d479dc 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,13 +13,13 @@ * limitations under the License. */ +#include "reminder_helper.h" + #include "ans_log_wrapper.h" #include "ans_notification.h" #include "notification_helper.h" #include "singleton.h" -#include "reminder_helper.h" - namespace OHOS { namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 8c71b7f82..c2b15f2a6 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -13,18 +13,23 @@ * limitations under the License. */ +#include "reminder_request.h" + #include "ans_log_wrapper.h" #include "bundle_mgr_interface.h" #include "if_system_ability_manager.h" +#include "ipc_skeleton.h" #include "iservice_registry.h" #include "os_account_manager.h" #include "system_ability_definition.h" #include "want_agent_helper.h" -#include "reminder_request.h" - namespace OHOS { namespace Notification { +namespace { +const int BASE_YEAR = 1900; +} + int32_t ReminderRequest::GLOBAL_ID = 0; const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; const uint16_t ReminderRequest::INVALID_U16_VALUE = 0; @@ -45,7 +50,6 @@ const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.no const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; -const int ReminderRequest::BASE_YEAR = 1900; ReminderRequest::ReminderRequest() { @@ -710,12 +714,12 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write action button size"); return false; } - for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { - if (!parcel.WriteUint8(static_cast(it->first))) { + for (auto button : actionButtonMap_) { + if (!parcel.WriteUint8(static_cast(button.first))) { ANSR_LOGE("Failed to write action button type"); return false; } - if (!parcel.WriteString(static_cast(it->second.title))) { + if (!parcel.WriteString(static_cast(button.second.title))) { ANSR_LOGE("Failed to write action button title"); return false; } @@ -725,12 +729,15 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) { - auto objptr = new ReminderRequest(); - if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { + auto objptr = new (std::nothrow) ReminderRequest(); + if (objptr == nullptr) { + ANSR_LOGE("Failed to create reminder due to no memory."); + return objptr; + } + if (!objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } - return objptr; } @@ -978,9 +985,9 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) int requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { + for (auto button : actionButtonMap_) { auto want = std::make_shared(); - auto type = it->first; + auto type = button.first; if (type == ActionButtonType::CLOSE) { want->SetAction(REMINDER_EVENT_CLOSE_ALERT); ANSR_LOGD("Add action button, type is close"); @@ -997,7 +1004,7 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) want->SetParam(PARAM_REMINDER_ID, reminderId_); std::vector> wants; wants.push_back(want); - auto title = static_cast(it->second.title); + auto title = static_cast(button.second.title); AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo( requestCode, AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, @@ -1005,8 +1012,12 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) wants, nullptr ); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); std::shared_ptr buttonWantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); + IPCSkeleton::SetCallingIdentity(identity); + std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, title, buttonWantAgent); notificationRequest_->AddActionButton(actionButton); @@ -1030,8 +1041,12 @@ void ReminderRequest::AddRemovalWantAgent() wants, nullptr ); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); std::shared_ptr wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); + IPCSkeleton::SetCallingIdentity(identity); + notificationRequest_->SetRemovalWantAgent(wantAgent); } @@ -1052,7 +1067,10 @@ std::shared_ptr ReminderRequest::CreateWan wants, nullptr ); - return AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); + IPCSkeleton::SetCallingIdentity(identity); + return wantAgent; } void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) @@ -1073,7 +1091,7 @@ void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string f if (deSet) { state_ |= newState; } else { - state_ &= ~newState; + state_ &= static_cast(~newState); } ANSR_LOGI("Switch the reminder(reminderId=%{public}d) state, from %{public}s to %{public}s, called by %{public}s", reminderId_, GetState(oldState).c_str(), GetState(state_).c_str(), function.c_str()); @@ -1121,7 +1139,7 @@ void ReminderRequest::UpdateNotificationCommon() { time_t now; (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS); + notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); notificationRequest_->SetLabel(NOTIFICATION_LABEL); notificationRequest_->SetShowDeliveryTime(true); notificationRequest_->SetTapDismissed(true); @@ -1153,6 +1171,7 @@ void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) // snooze the reminder by manual extendContent = GetShowTime(triggerTimeInMilli_) + snoozeContent_ == "" ? "" : (" (" + snoozeContent_ + ")"); + notificationRequest_->SetTapDismissed(false); } else { // the reminder is expired now, when timeInterval is 0 extendContent = GetShowTime(reminderTimeInMilli_) + diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index f5a549729..8d9963226 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "ans_log_wrapper.h" - #include "reminder_request_alarm.h" +#include "ans_log_wrapper.h" + namespace OHOS { namespace Notification { const uint8_t ReminderRequestAlarm::DAYS_PER_WEEK = 7; @@ -269,7 +269,11 @@ ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New alarm"); auto objptr = new (std::nothrow) ReminderRequestAlarm(); - if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { + if (objptr == nullptr) { + ANSR_LOGE("Failed to create reminder alarm due to no memory."); + return objptr; + } + if (!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 0809af129..58c260f5e 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "ans_log_wrapper.h" - #include "reminder_request_calendar.h" +#include "ans_log_wrapper.h" + namespace OHOS { namespace Notification { const uint8_t ReminderRequestCalendar::MAX_MONTHS_OF_YEAR = 12; @@ -29,9 +29,9 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays) : ReminderRequest(ReminderRequest::ReminderType::CALENDAR) { - // 1. record the infomation which designated by user at first time. - firstDesignateYear_ = GetActualTime(TimeTransferType::YEAR, dateTime.tm_year); - firstDesignateMonth_ = GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon); + // 1. record the information which designated by user at first time. + firstDesignateYear_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); + firstDesignateMonth_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); firstDesignateDay_ = dateTime.tm_mday; SetRepeatMonths(repeatMonths); SetRepeatDaysOfMonth(repeatDays); @@ -39,8 +39,8 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, // 2. get the latest valid trigger time. InitDateTime(dateTime); - hour_ = dateTime_.tm_hour; - minute_ = dateTime_.tm_min; + hour_ = static_cast(dateTime_.tm_hour); + minute_ = static_cast(dateTime_.tm_min); uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) { time_t target = static_cast(nextTriggerTime / MILLI_SECONDS); @@ -51,9 +51,9 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, "Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); } - // 2. set the time infomation (used to transfer to proxy service) which is decided to trigger firstly. - year_ = GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year); - month_ = GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon); + // 2. set the time information (used to transfer to proxy service) which is decided to trigger firstly. + year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); + month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); day_ = dateTime_.tm_mday; second_ = 0; SetTriggerTimeInMilli(nextTriggerTime); @@ -191,7 +191,7 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTimeAsRepeatReminder(const tm &n } if ((triggerTimeInMilli = GetTimeInstantMilli(setYear, setMonth, setDay, hour_, minute_, second_)) != INVALID_LONG_LONG_VALUE) { - ANSR_LOGD("Next calendar time:%{public}u/%{public}u/%{public}u %{public}u:%{public}u:%{public}u", + ANSR_LOGD("Next calendar time:%{public}hu/%{public}hhu/%{public}hhu %{public}hhu:%{public}hhu:%{public}hhu", setYear, setMonth, setDay, hour_, minute_, second_); } return triggerTimeInMilli; @@ -284,7 +284,7 @@ void ReminderRequestCalendar::SetMonth(const uint8_t &month, const bool &isSet) void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeatMonths) { if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) { - ANSR_LOGW("The length of repeat months array should not larger than %{public}u", MAX_MONTHS_OF_YEAR); + ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR); throw std::invalid_argument( "The length of repeat months array should not larger than " + std::to_string(MAX_MONTHS_OF_YEAR)); } @@ -297,7 +297,7 @@ void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeat void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeateDays) { if (repeateDays.size() > MAX_DAYS_OF_MONTH) { - ANSR_LOGW("The length of repeat days array should not larger than %{public}u", MAX_DAYS_OF_MONTH); + ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH); throw std::invalid_argument( "The length of repeat days array should not larger than " + std::to_string(MAX_DAYS_OF_MONTH)); } @@ -439,7 +439,11 @@ ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New calendar"); auto objptr = new ReminderRequestCalendar(); - if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { + if (objptr == nullptr) { + ANS_LOGE("Failed to create reminder calendar due to no memory."); + return objptr; + } + if (!objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } diff --git a/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index d0fd4337b..cac422619 100644 --- a/frameworks/ans/native/src/reminder_request_timer.cpp +++ b/frameworks/ans/native/src/reminder_request_timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,14 +13,14 @@ * limitations under the License. */ +#include "reminder_request_timer.h" + #include #include #include "ans_log_wrapper.h" #include "time_service_client.h" -#include "reminder_request_timer.h" - namespace OHOS { namespace Notification { ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) @@ -33,7 +33,12 @@ ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) ReminderRequest::SetTriggerTimeInMilli( ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS); sptr timer = MiscServices::TimeServiceClient::GetInstance(); - firstRealTimeInMilliSeconds_ = timer->GetBootTimeMs(); + int64_t bootTimeMs = timer->GetBootTimeMs(); + if (bootTimeMs >= 0) { + firstRealTimeInMilliSeconds_ = static_cast(bootTimeMs); + } else { + ANSR_LOGW("Get boot time error."); + } } ReminderRequestTimer::ReminderRequestTimer(const ReminderRequestTimer &other) : ReminderRequest(other) @@ -113,8 +118,12 @@ bool ReminderRequestTimer::Marshalling(Parcel &parcel) const ReminderRequestTimer *ReminderRequestTimer::Unmarshalling(Parcel &parcel) { - auto objptr = new ReminderRequestTimer(); - if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { + auto objptr = new (std::nothrow) ReminderRequestTimer(); + if (objptr == nullptr) { + ANSR_LOGE("Failed to create reminder timer due to no memory."); + return objptr; + } + if (!objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } diff --git a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp index d658d162c..a9b7ff527 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp index f7bc5ed5c..ff9b3415d 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp index 14f13c79b..b92b95288 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp index 852fbb84e..36cc697b7 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/ans/test/moduletest/config.json b/frameworks/ans/test/moduletest/config.json index 7d3bb1663..46e2a9f39 100644 --- a/frameworks/ans/test/moduletest/config.json +++ b/frameworks/ans/test/moduletest/config.json @@ -13,6 +13,18 @@ }, "deviceConfig": {}, "module": { + "reqPermissions": [ + { + "name": "ohos.permission.PUBLISH_AGENT_REMINDER", + "reason": "SYSTEM_GRANT", + "usedScene": { + "ability": [ + ".FormAbility" + ], + "when": "inuse" + } + } + ], "package": "com.example.myapplication", "name": ".MyApplication", "deviceType": [ @@ -58,4 +70,3 @@ ] } } - \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_helper.h b/interfaces/innerkits/ans/native/include/reminder_helper.h index 0d7f34d88..639b2be8c 100644 --- a/interfaces/innerkits/ans/native/include/reminder_helper.h +++ b/interfaces/innerkits/ans/native/include/reminder_helper.h @@ -53,7 +53,7 @@ public: /** * Cancels a specified reminder. * - * @param reminderId Indicates the ID of the reminder instace to cancel. + * @param reminderId Indicates the ID of the reminder instance to cancel. * @return Returns cancel reminder result. */ static ErrCode CancelReminder(const int32_t reminderId); @@ -69,7 +69,7 @@ public: * Obtains all valid reminder notifications set by the current application, namely, the reminders that will * still be triggered later. If a reminder will never be triggered again, it is not considered a valid reminder. * - * @param[out] validReminders Indicates an initial vector to recieve the result. + * @param[out] validReminders Indicates an initial vector to receive the result. * @return Returns an array list containing all valid reminder notifications set by the current application. */ static ErrCode GetValidReminders(std::vector> &validReminders); diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 14fb032d6..8fc78a071 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,6 +19,7 @@ #include #include +#include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" @@ -52,7 +53,7 @@ public: */ enum class ActionButtonType : uint8_t { /** - * @brief Indicates that this action button is used to close reminder's notfication. + * @brief Indicates that this action button is used to close reminder's notification. * It always works well, whether the application is running at the time. * */ @@ -343,7 +344,7 @@ public: * * 1) Updates the trigger time to the next one. * 2) Updates the notification content for "Snooze". - * 3) Switchs the state from "Showing[, Alerting]" to "Snooze". + * 3) Switches the state from "Showing[, Alerting]" to "Snooze". */ bool OnSnooze(); @@ -432,7 +433,7 @@ public: /** * @brief Sets the ringing or vibration duration for this reminder, in seconds. * - * @param ringDurationInSeconds Indicates the duration. The defautl is 1 second. + * @param ringDurationInSeconds Indicates the duration. The default is 1 second. * @return Current reminder self. */ ReminderRequest& SetRingDuration(const uint64_t ringDurationInSeconds); @@ -514,7 +515,7 @@ public: virtual bool UpdateNextReminder(); /** - * @brief Update notification attibutes. + * @brief Update notification attributes. * * Some attributes need to be updated after the reminder published or before the notification publish. * For example, action button should not init until the reminder is published successfully, as the reminder id is diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 07239f1ea..6c943699e 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index b675abed7..638b881aa 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -164,7 +164,17 @@ private: static const uint8_t DECEMBER; static const uint8_t DEFAULT_SNOOZE_TIMES; - tm dateTime_; + tm dateTime_ = { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 0, + .tm_year = 0, + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = -1 + }; uint16_t firstDesignateYear_ {1}; uint8_t firstDesignateMonth_ {1}; uint8_t firstDesignateDay_ {1}; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 9fc2362f2..19c279d33 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,7 +31,7 @@ public: * * @param countDownTimeInSeconds Indicates the duration after which this timer reminder will be triggered. */ - ReminderRequestTimer(uint64_t countDownTimeInSeconds); + explicit ReminderRequestTimer(uint64_t countDownTimeInSeconds); /** * @brief Copy construct from an exist reminder. @@ -69,8 +69,8 @@ private: void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; void UpdateTimeInfo(const std::string description); uint64_t countDownTimeInSeconds_ {0}; - uint64_t firstRealTimeInMilliSeconds_ {-1}; - uint64_t whenToChangeSysTime_ {-1}; + uint64_t firstRealTimeInMilliSeconds_ {0}; + uint64_t whenToChangeSysTime_ {0}; }; } // namespace Reminder } // namespace OHOS diff --git a/interfaces/kits/napi/ans/include/reminder/reminder_common.h b/interfaces/kits/napi/ans/include/reminder/reminder_common.h index 63b1d0f79..3a6821603 100644 --- a/interfaces/kits/napi/ans/include/reminder/reminder_common.h +++ b/interfaces/kits/napi/ans/include/reminder/reminder_common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/napi/ans/src/reminder/native_module.cpp b/interfaces/kits/napi/ans/src/reminder/native_module.cpp index f4fe3650b..23ce01695 100644 --- a/interfaces/kits/napi/ans/src/reminder/native_module.cpp +++ b/interfaces/kits/napi/ans/src/reminder/native_module.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ +#include "reminder/native_module.h" + #include "napi/native_api.h" #include "napi/native_node_api.h" #include "reminder/publish.h" #include "slot.h" -#include "reminder/native_module.h" - namespace OHOS { namespace ReminderAgentNapi { EXTERN_C_START diff --git a/interfaces/kits/napi/ans/src/reminder/publish.cpp b/interfaces/kits/napi/ans/src/reminder/publish.cpp index d0033726d..242a7d66c 100644 --- a/interfaces/kits/napi/ans/src/reminder/publish.cpp +++ b/interfaces/kits/napi/ans/src/reminder/publish.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,14 +13,14 @@ * limitations under the License. */ +#include "reminder/publish.h" + #include "ans_log_wrapper.h" #include "common.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" -#include "reminder/publish.h" - namespace OHOS { namespace ReminderAgentNapi { static const int32_t PUBLISH_PARAM_LEN = 2; @@ -314,29 +314,29 @@ void ParseReminderCalendar(const napi_env &env, ReminderRequest &reminder, napi_ { // dateTime napi_value value = nullptr; - ReminderRequestCalendar& calender = (ReminderRequestCalendar&)reminder; + ReminderRequestCalendar& calendar = (ReminderRequestCalendar&)reminder; napi_value dateTime = nullptr; napi_create_object(env, &dateTime); napi_set_named_property(env, result, CALENDAR_DATE_TIME, dateTime); - napi_create_uint32(env, static_cast(calender.GetYear()), &value); + napi_create_uint32(env, static_cast(calendar.GetYear()), &value); napi_set_named_property(env, dateTime, CALENDAR_YEAR, value); - napi_create_uint32(env, static_cast(calender.GetMonth()), &value); + napi_create_uint32(env, static_cast(calendar.GetMonth()), &value); napi_set_named_property(env, dateTime, CALENDAR_MONTH, value); - napi_create_uint32(env, static_cast(calender.GetDay()), &value); + napi_create_uint32(env, static_cast(calendar.GetDay()), &value); napi_set_named_property(env, dateTime, CALENDAR_DAY, value); - napi_create_uint32(env, static_cast(calender.GetHour()), &value); + napi_create_uint32(env, static_cast(calendar.GetHour()), &value); napi_set_named_property(env, dateTime, CALENDAR_HOUR, value); - napi_create_uint32(env, static_cast(calender.GetMinute()), &value); + napi_create_uint32(env, static_cast(calendar.GetMinute()), &value); napi_set_named_property(env, dateTime, CALENDAR_MINUTE, value); - napi_create_uint32(env, static_cast(calender.GetSecond()), &value); + napi_create_uint32(env, static_cast(calendar.GetSecond()), &value); napi_set_named_property(env, dateTime, CALENDAR_SECOND, value); // repeatMonths napi_create_array(env, &value); napi_set_named_property(env, result, CALENDAR_REPEAT_MONTHS, value); int count = 0; - for (auto month : calender.GetRepeatMonths()) { + for (auto month : calendar.GetRepeatMonths()) { napi_value napiDay = nullptr; napi_create_int32(env, month, &napiDay); napi_set_element(env, value, count, napiDay); @@ -347,7 +347,7 @@ void ParseReminderCalendar(const napi_env &env, ReminderRequest &reminder, napi_ napi_create_array(env, &value); napi_set_named_property(env, result, CALENDAR_REPEAT_DAYS, value); count = 0; - for (auto day : calender.GetRepeatDays()) { + for (auto day : calendar.GetRepeatDays()) { napi_value napiDay = nullptr; napi_create_int32(env, day, &napiDay); napi_set_element(env, value, count, napiDay); diff --git a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index 0d53108ad..27f82b503 100644 --- a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp +++ b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,14 +13,14 @@ * limitations under the License. */ +#include "reminder/reminder_common.h" + #include "ans_log_wrapper.h" #include "common.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" -#include "reminder/reminder_common.h" - namespace OHOS { namespace ReminderAgentNapi { using namespace OHOS::Notification; @@ -222,7 +222,7 @@ napi_value ReminderCommon::GenReminder( if (propertyVal < 0) { reminder->SetSnoozeTimes(0); } else { - uint8_t snoozeTimes = propertyVal > UINT8_MAX ? UINT8_MAX : propertyVal; + uint8_t snoozeTimes = propertyVal > UINT8_MAX ? UINT8_MAX : static_cast(propertyVal); reminder->SetSnoozeTimes(static_cast(snoozeTimes)); } } @@ -402,7 +402,7 @@ napi_value ReminderCommon::CreateReminderCalendar( { napi_value dateTimeObj = nullptr; if (!GetObject(env, value, ReminderAgentNapi::CALENDAR_DATE_TIME, dateTimeObj)) { - ANSR_LOGW("Create calender reminder fail: dateTime must be setted."); + ANSR_LOGW("Create calendar reminder fail: dateTime must be setted."); return nullptr; } @@ -454,30 +454,30 @@ bool ReminderCommon::CheckCalendarParams(const int32_t &year, const int32_t &mon const int32_t &hour, const int32_t &min) { if (year < 0 || year > UINT16_MAX) { - ANSR_LOGW("Create calender reminder fail: designated %{public}s must between [0, %{public}u]", + ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [0, %{public}d]", ReminderAgentNapi::CALENDAR_YEAR, UINT16_MAX); return false; } if (month < 1 || month > ReminderRequestCalendar::MAX_MONTHS_OF_YEAR) { - ANSR_LOGW("Create calender reminder fail: designated %{public}s must between [1, %{public}u]", + ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [1, %{public}hhu]", ReminderAgentNapi::CALENDAR_MONTH, ReminderRequestCalendar::MAX_MONTHS_OF_YEAR); return false; } uint8_t maxDaysOfMonth = ReminderRequestCalendar::GetDaysOfMonth(static_cast(year), month); if (day < 1 || day > maxDaysOfMonth) { - ANSR_LOGW("Create calender reminder fail: designated %{public}s must between [1, %{public}u]", + ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [1, %{public}hhu]", ReminderAgentNapi::CALENDAR_DAY, maxDaysOfMonth); return false; } uint8_t maxHour = 23; if (hour < 0 || hour > maxHour) { - ANSR_LOGW("Create calender reminder fail: designated %{public}s must between [0, %{public}u]", + ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [0, %{public}hhu]", ReminderAgentNapi::CALENDAR_HOUR, maxHour); return false; } uint8_t maxMinute = 59; if (min < 0 || min > maxMinute) { - ANSR_LOGW("Create calender reminder fail: designated %{public}s must between [0, %{public}u]", + ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [0, %{public}hhu]", ReminderAgentNapi::CALENDAR_MINUTE, maxMinute); return false; } @@ -501,7 +501,7 @@ napi_value ReminderCommon::ParseInt32Array(const napi_env &env, const napi_value uint32_t length = 0; napi_get_array_length(env, result, &length); if (length > maxLen) { - ANSR_LOGW("The max length of array of %{public}s is %{public}d.", propertyName, maxLen); + ANSR_LOGW("The max length of array of %{public}s is %{public}hhu.", propertyName, maxLen); return nullptr; } napi_valuetype valuetype = napi_undefined; diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index b1d22285a..15ea95104 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -129,6 +129,11 @@ public: */ void SnoozeReminder(const OHOS::EventFwk::Want &want); + /** + * Starts the recent reminder timing. + */ + void StartRecentReminder(); + /** * @brief Terminate the alerting reminder. * @@ -321,11 +326,6 @@ private: void SnoozeReminderImpl(sptr &reminder); - /** - * Starts the recent reminder timing. - */ - void StartRecentReminder(); - /** * Starts timing actually. * @@ -386,7 +386,7 @@ private: static std::shared_ptr REMINDER_DATA_MANAGER; /** - * Used for multi-thread syncronise. + * Used for multi-thread synchronise. */ static std::mutex MUTEX; static std::mutex SHOW_MUTEX; @@ -446,7 +446,7 @@ private: * Indicates the total count of reminders in system. */ int16_t totalCount_ {0}; - AdvancedNotificationService *advancedNotificationService_; + sptr advancedNotificationService_ = nullptr; }; } // namespace OHOS } // namespace Nofitifcation diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 35f46ba0e..0fb8b6556 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/include/reminder_timer_info.h b/services/ans/include/reminder_timer_info.h index b3e66b42d..ee8c22640 100644 --- a/services/ans/include/reminder_timer_info.h +++ b/services/ans/include/reminder_timer_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index f97370ac8..3bebba308 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1722,7 +1722,11 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ANSR_LOGW("PrepareNotificationInfo fail"); return result; } - ReminderDataManager::GetInstance()->PublishReminder(reminder, bundleOption); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + rdm->PublishReminder(reminder, bundleOption); return ERR_OK; } @@ -1734,7 +1738,11 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } - ReminderDataManager::GetInstance()->CancelReminder(reminderId, bundleOption); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + rdm->CancelReminder(reminderId, bundleOption); return ERR_OK; } @@ -1748,7 +1756,11 @@ ErrCode AdvancedNotificationService::CancelAllReminders() } int userId = -1; AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); - ReminderDataManager::GetInstance()->CancelAllReminders(bundleOption, userId); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + rdm->CancelAllReminders(bundleOption, userId); return ERR_OK; } @@ -1761,7 +1773,11 @@ ErrCode AdvancedNotificationService::GetValidReminders(std::vectorGetValidReminders(bundleOption, reminders); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + rdm->GetValidReminders(bundleOption, reminders); ANSR_LOGD("Valid reminders size=%{public}zu", reminders.size()); return ERR_OK; } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 52adfccde..f55aa3e5b 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,16 +13,17 @@ * limitations under the License. */ +#include "reminder_data_manager.h" + #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" +#include "ipc_skeleton.h" #include "notification_slot.h" #include "reminder_event_manager.h" #include "time_service_client.h" #include "singleton.h" -#include "reminder_data_manager.h" - namespace OHOS { namespace Notification { const int16_t ReminderDataManager::MAX_NUM_REMINDER_LIMIT_SYSTEM = 2000; @@ -225,15 +226,22 @@ void ReminderDataManager::OnProcessDiedLocked(const sptr ReminderDataManager::CreateTimerInfo(TimerType type) const { auto sharedTimerInfo = std::make_shared(); - sharedTimerInfo->SetType(sharedTimerInfo->TIMER_TYPE_WAKEUP|sharedTimerInfo->TIMER_TYPE_EXACT); + if (sharedTimerInfo->TIMER_TYPE_WAKEUP > UINT8_MAX || sharedTimerInfo->TIMER_TYPE_EXACT > UINT8_MAX) { + ANSR_LOGE("Failed to set timer type."); + return nullptr; + } + uint8_t timerTypeWakeup = static_cast(sharedTimerInfo->TIMER_TYPE_WAKEUP); + uint8_t timerTypeExact = static_cast(sharedTimerInfo->TIMER_TYPE_EXACT); + int timerType = static_cast(timerTypeWakeup | timerTypeExact); + sharedTimerInfo->SetType(timerType); sharedTimerInfo->SetRepeat(false); sharedTimerInfo->SetInterval(0); int requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - auto want = std::make_shared(); + auto want = std::make_shared(); switch (type) { case (TimerType::TRIGGER_TIMER): { want->SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); @@ -261,8 +269,12 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp wants, nullptr ); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); std::shared_ptr wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, 0); + IPCSkeleton::SetCallingIdentity(identity); + sharedTimerInfo->SetWantAgent(wantAgent); return sharedTimerInfo; } @@ -390,14 +402,14 @@ void ReminderDataManager::TerminateAlerting(const uint16_t waitInSecond, const s void ReminderDataManager::TerminateAlerting(const sptr &reminder, const std::string &reason) { - ANSR_LOGI("Terminate the alerting reminder, %{public}s, called by %{public}s", - reminder->Dump().c_str(), reason.c_str()); - StopAlertingReminder(reminder); - if (reminder == nullptr) { ANSR_LOGE("TerminateAlerting illegal."); return; } + ANSR_LOGI("Terminate the alerting reminder, %{public}s, called by %{public}s", + reminder->Dump().c_str(), reason.c_str()); + StopAlertingReminder(reminder); + if (!reminder->OnTerminate()) { return; } @@ -531,17 +543,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co reminder->OnShow(false, isSysTimeChanged, false); return; } - if (isNeedToPlaySound) { // todo if shouldAlert - PlaySoundAndVibration(reminder); // play sound and vibration - reminder->OnShow(true, isSysTimeChanged, true); - if (needScheduleTimeout) { - StartTimer(reminder, TimerType::ALERTING_TIMER); - } else { - TerminateAlerting(1, reminder); - } - } else { - reminder->OnShow(false, isSysTimeChanged, true); - } + reminder->OnShow(isNeedToPlaySound, isSysTimeChanged, true); AddToShowedReminders(reminder); UpdateNotification(reminder); // this should be called after OnShow ANSR_LOGD("publish notification.(reminderId=%{public}d)", reminder->GetReminderId()); @@ -550,6 +552,14 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co reminder->OnShowFail(); RemoveFromShowedReminders(reminder); } else { + if (isNeedToPlaySound) { + PlaySoundAndVibration(reminder); // play sound and vibration + if (needScheduleTimeout) { + StartTimer(reminder, TimerType::ALERTING_TIMER); + } else { + TerminateAlerting(1, reminder); + } + } HandleSameNotificationIdShowing(reminder); } if (isNeedToStartNext) { @@ -1044,13 +1054,13 @@ void ReminderDataManager::ResetStates(TimerType type) { switch (type) { case TimerType::TRIGGER_TIMER: { - ANSR_LOGD("ResetStates(activeReminder)"); + ANSR_LOGD("ResetStates(activeReminderId, timerId(next triggerTime))"); timerId_ = 0; activeReminderId_ = -1; break; } case TimerType::ALERTING_TIMER: { - ANSR_LOGD("ResetStates(alertingReminder)"); + ANSR_LOGD("ResetStates(alertingReminderId, timeId(alerting time out))"); timerIdAlerting_ = 0; alertingReminderId_ = -1; break; diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 852d43672..0f53dfe3a 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "reminder_event_manager.h" + #include "ans_log_wrapper.h" #include "appmgr/app_mgr_constants.h" #include "bundle_constants.h" @@ -21,7 +23,6 @@ #include "common_event_support.h" #include "ipc_skeleton.h" -#include "reminder_event_manager.h" using namespace OHOS::EventFwk; namespace OHOS { diff --git a/services/ans/src/reminder_timer_info.cpp b/services/ans/src/reminder_timer_info.cpp index 939bb0685..fbfd1ab72 100644 --- a/services/ans/src/reminder_timer_info.cpp +++ b/services/ans/src/reminder_timer_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,12 +13,12 @@ * limitations under the License. */ +#include "reminder_timer_info.h" + #include "ans_log_wrapper.h" #include "common_event_manager.h" #include "reminder_request.h" -#include "reminder_timer_info.h" - using namespace OHOS::EventFwk; namespace OHOS { namespace Notification { -- Gitee From 01e47300280be722e4b4941ab707bbe5d196ba99 Mon Sep 17 00:00:00 2001 From: derek Date: Mon, 7 Mar 2022 23:00:13 +0800 Subject: [PATCH 2/3] fix codex Signed-off-by: derek --- services/ans/include/reminder_data_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 15ea95104..dfd68eca7 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -446,7 +446,7 @@ private: * Indicates the total count of reminders in system. */ int16_t totalCount_ {0}; - sptr advancedNotificationService_ = nullptr; + AdvancedNotificationService *advancedNotificationService_ = nullptr; }; } // namespace OHOS } // namespace Nofitifcation -- Gitee From 4a0e2e55854788946c141c99d9864f8d3ad58b7d Mon Sep 17 00:00:00 2001 From: derek Date: Tue, 8 Mar 2022 09:15:19 +0800 Subject: [PATCH 3/3] fix codex Signed-off-by: derek --- interfaces/innerkits/ans/native/include/reminder_request.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 8fc78a071..36c16a871 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -573,7 +573,7 @@ protected: { return INVALID_LONG_LONG_VALUE; } - static const int BASE_YEAR; + private: void AddActionButtons(const bool includeSnooze); -- Gitee