diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index fdca50b6dcef7a63f0c9e2ecbc7ee8d1b73bbace..8c11721180255b1925c3c4962f9acd5d38a62784 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 000af8c28c72701d84bbbe4629a744e71ab8f8e5..1199f44fdce03d4cdadb4fee7e8af168ca6f5cdf 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 a0aa9d6ccf3c7a5039278afb806ca60395040791..059c83526b4f2a84e812e25fc2deb2539450e4a3 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 5e518b7714e744a67d37dcf9a3c7414c6dff13d8..524d479dcf6be3889181f0fa0cc5ca4f6842aa4f 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 8c71b7f82560abea9e70fe49f1820d167f11aa48..c2b15f2a61c8ae2a02c8e15e010787328c534294 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 f5a549729d310340397863571d3a25fe0fd3fc29..8d996322653eedd38635e138ce30884cedce4a67 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 0809af1294726c2a50f9e02e688d28fdf0fc4970..58c260f5e45be70e4c2654d2fcb9433e6118ac54 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 d0fd4337b2432cc0974cfcb9d5103ad071705014..cac42261980e32d4966be8ff836c2370982fb2a8 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 d658d162c17953ac065308dc2d28117d07eab81a..a9b7ff527d5dfad08fa6e6f2205079abf360229f 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 f7bc5ed5cb3f750452100c1b20dfeaaddeff48a4..ff9b3415d359f66fbf11c33a7b28a9625ce4b0fa 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 14f13c79bfc96216cac3edd1dcb9eb97519b546d..b92b95288588d8b9e42174490dd13c462f57acb5 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 852fbb84eb3c575668039f834d654362a0f6c267..36cc697b70e47f8e0a9d0a4fa7046bc4fb3f30e0 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 7d3bb1663873510fc00c1203273ad743dfbb2f43..46e2a9f391b523655bdfbb7b2a6d525dcd79dff1 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 0d7f34d8880c0a3ee6fec2c2810703f5256b6473..639b2be8ccd48ccbcc3ae9ed05e37c39776380dd 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 14fb032d6ff2f0af0445dfee2cc70254c92418b0..36c16a871a6bab767e1ec83975f6b173fb2cc6f5 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 @@ -572,7 +573,7 @@ protected: { return INVALID_LONG_LONG_VALUE; } - static const int BASE_YEAR; + private: void AddActionButtons(const bool includeSnooze); diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 07239f1ea3b9cb57afcee7db461a6fc0d04969cf..6c943699e1e955f729674b46850ec1479b3385da 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 b675abed73f24e01371abcb93f46880451c2d2f4..638b881aa53f75f8345a1e025bead32a19e213c8 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 9fc2362f2effe12f4758313624e55562c48318cd..19c279d332a647df0cf33c7a5a9a54f5c172d303 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 63b1d0f796e16be16994fb08cf4814b07b22c48d..3a6821603fb0016e40788bd8411c5c79d6d8c775 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 f4fe3650ba080b8ce115245cd6fed1f18e68a762..23ce01695e03cc84ed5ee988cd7fe53d6411ef3e 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 d0033726d9be2716863a4a3b6c001397d170ca1a..242a7d66c6bcac9204a23f0ef1e2683be2802444 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 0d53108ad92bc9f1a5768ac341eeac1a354a128a..27f82b503edbf4c5270a00583223e097deeb97a5 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 b1d22285a35a000f2fea65ea06991d547efeb1d0..dfd68eca7e85e7afc11fa7871efd4ba322070f7b 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_; + AdvancedNotificationService *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 35f46ba0ec2d26137aba6d19eed2ae3078bdbd8e..0fb8b6556f6f97f82fdad6a8839c7c9faae76cd3 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 b3e66b42d7087a5a2de9f6f4795030750cf5b57b..ee8c22640cd5905c25f727cc1884b1e3d231c15f 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 f97370ac8be6f6bfd809cd02c57d8b7b0af20a23..3bebba308262d0682c9f3bb2a6bb9bf9b2ece81e 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 52adfccde3323e4a36e343f52e2db06b76e26392..f55aa3e5b717b0084de928ddcade8aa8dd521196 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 852d4367258df06f8dd7c30e1755739d574b08f2..0f53dfe3a3f9115db64e6c0374fce30317a5021a 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 939bb06856faef7782d3a5a09519be9d4510d8cc..fbfd1ab728810f03e7926456ad30124323c814f4 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 {