diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 381d0bb5db61d5808adde21dbfa8374ef2aba3a9..a1d134f8dbcad17ca8b5f85383d092925b0d1166 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -574,7 +574,7 @@ std::vector ReminderRequest::StringSplit(std::string source, const return result; } -void ReminderRequest::RecoverWantAgent(std::string wantAgentInfo, const uint8_t &type) +void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type) { std::vector info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT); uint8_t minLen = 2; @@ -585,10 +585,10 @@ void ReminderRequest::RecoverWantAgent(std::string wantAgentInfo, const uint8_t ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str()); switch (type) { case 0: { - auto wantAgentInfo = std::make_shared(); - wantAgentInfo->pkgName = info.at(0); - wantAgentInfo->abilityName = info.at(1); - SetWantAgentInfo(wantAgentInfo); + auto wai = std::make_shared(); + wai->pkgName = info.at(0); + wai->abilityName = info.at(1); + SetWantAgentInfo(wai); break; } case 1: { @@ -645,7 +645,7 @@ ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTime ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) { - if ((timeIntervalInSeconds < 0) || (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS))) { + if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); timeIntervalInMilli_ = 0; } else { @@ -744,7 +744,7 @@ void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) { - if ((ringDurationInSeconds <= 0) || (ringDurationInSeconds > (UINT64_MAX / MILLI_SECONDS))) { + if ((ringDurationInSeconds == 0) || (ringDurationInSeconds > (UINT64_MAX / MILLI_SECONDS))) { ANSR_LOGW("setRingDuration, replace to set (1s), for the given is out of legal range"); ringDurationInMilli_ = MILLI_SECONDS; } else { diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 1bb778ea66742414abee0324b6e0bff14a37fffb..e8776359a1d388ecf77362d3b2bcc3d199f0cd26 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -55,11 +55,11 @@ ReminderRequestAlarm::ReminderRequestAlarm(const ReminderRequestAlarm &other) : void ReminderRequestAlarm::CheckParamValid() const { - if ((hour_ >= HOURS_PER_DAY) || (hour_ < 0)) { + if (hour_ >= HOURS_PER_DAY) { ANSR_LOGE("setted hour is not between [0, 24)"); throw std::invalid_argument("setted hour is not between [0, 24)"); } - if (minute_ < 0 || minute_ >= MINUTES_PER_HOUR) { + if (minute_ >= MINUTES_PER_HOUR) { ANSR_LOGE("setted minute is not between [0, 60)"); throw std::invalid_argument("setted minute is not between [0, 60)"); } diff --git a/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index cac42261980e32d4966be8ff836c2370982fb2a8..7dea553614810becf52425a6d64d769422308973 100644 --- a/frameworks/ans/native/src/reminder_request_timer.cpp +++ b/frameworks/ans/native/src/reminder_request_timer.cpp @@ -85,7 +85,7 @@ void ReminderRequestTimer::CheckParamsValid(const uint64_t countDownTimeInSecond } } -void ReminderRequestTimer::UpdateTimeInfo(const std::string description) +void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) { if (IsExpired()) { return; diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 798913b6a582a95a44c45f2c865a8cb2862a4563..cc6455989b536c87441782487f8df9231dc86d03 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -410,7 +410,7 @@ public: */ virtual void RecoverFromDb(const std::shared_ptr &resultSet); void RecoverActionButton(const std::shared_ptr &resultSet); - void RecoverWantAgent(std::string wantAgentInfo, const uint8_t &type); + void RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type); /** * @brief Sets action button. diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 673bf2885e2e76b7c7f9e4514d1c5a784ce34b48..0b703709c65d414a3ce7862bad9e6fe97202a5b2 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -75,7 +75,7 @@ protected: private: ReminderRequestTimer() {}; void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; - void UpdateTimeInfo(const std::string description); + void UpdateTimeInfo(const std::string &description); uint64_t countDownTimeInSeconds_ {0}; uint64_t firstRealTimeInMilliSeconds_ {0}; uint64_t whenToChangeSysTime_ {0}; diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 168891ff2ee08e1189d1472553c38fb4c3dd1037..bd69270eb4970ed0e6d2dc4458e34accd3595fc1 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -77,7 +77,7 @@ public: */ static std::shared_ptr GetInstance(); static std::shared_ptr InitInstance( - sptr &advancedNotificationService); + const sptr &advancedNotificationService); /** * Obtains all the valid reminders (which are not expired) relative to the bundle option. @@ -110,7 +110,7 @@ public: * @param reminder Indicates the reminder. * @param bundleOption Indicates bundle option the reminder belongs to. */ - void PublishReminder(sptr &reminder, sptr &bundleOption); + void PublishReminder(const sptr &reminder, const sptr &bundleOption); /** * @brief Refresh all reminders when date/time or timeZone of device changed by user. @@ -248,14 +248,6 @@ private: */ sptr GetRecentReminderLocked(); - /** - * Obtains all the reminders of the target bundle name. - * - * @param bundleName Indicates the bundle name. - * @return all the reminders of the target bundle name. - */ - std::vector> GetSameBundleRemindersLocked(std::string &bundleName); - void HandleImmediatelyShow(std::vector> &showImmediately, bool isSysTimeChanged); /** @@ -265,7 +257,7 @@ private: * @param reminder Indicates the target reminder. * @return sptr Returns the target reminder if it is need to show immediately, otherwise nullptr. */ - sptr HandleRefreshReminder(uint8_t &type, sptr &reminder); + sptr HandleRefreshReminder(const uint8_t &type, sptr &reminder); /** * @brief Handles all the reminders that have the same notification id and belong to same application @@ -288,7 +280,7 @@ private: * @return true if the two reminders belong to the same application. */ bool IsBelongToSameApp( - const sptr reminder, const std::string otherPkgName, const int otherUserId); + const sptr reminder, const std::string &otherPkgName, const int otherUserId); void LoadReminderFromDb(); diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 50aacfd848faaa36aa0b5d0abbe3620b86cf521a..09c731643bb18daba6a555759302e84d448bdae6 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -26,7 +26,7 @@ namespace OHOS { namespace Notification { class ReminderEventManager { public: - ReminderEventManager(std::shared_ptr &reminderDataManager); + explicit ReminderEventManager(std::shared_ptr &reminderDataManager); virtual ~ReminderEventManager() {}; ReminderEventManager(ReminderEventManager &other) = delete; ReminderEventManager& operator = (const ReminderEventManager &other) = delete; @@ -42,8 +42,8 @@ public: private: sptr GetBundleOption(const OHOS::EventFwk::Want &want) const; - void HandlePackageRemove(OHOS::EventFwk::Want &want) const; - void HandleProcessDied(OHOS::EventFwk::Want &want) const; + void HandlePackageRemove(const EventFwk::Want &want) const; + void HandleProcessDied(const EventFwk::Want &want) const; std::shared_ptr reminderDataManager_ = nullptr; }; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index d178dea5412954f26c8accc74a9a868e1f3bdbfd..b08745ff58c7a326c6a1b256eddc23216febb95a 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -36,8 +36,8 @@ std::mutex ReminderDataManager::SHOW_MUTEX; std::mutex ReminderDataManager::ALERT_MUTEX; std::mutex ReminderDataManager::TIMER_MUTEX; -void ReminderDataManager::PublishReminder(sptr &reminder, - sptr &bundleOption) +void ReminderDataManager::PublishReminder(const sptr &reminder, + const sptr &bundleOption) { if (CheckReminderLimitExceededLocked(bundleOption->GetBundleName())) { return; @@ -376,7 +376,7 @@ std::shared_ptr ReminderDataManager::GetInstance() } std::shared_ptr ReminderDataManager::InitInstance( - sptr &advancedNotificationService) + const sptr &advancedNotificationService) { if (REMINDER_DATA_MANAGER == nullptr) { REMINDER_DATA_MANAGER = std::make_shared(); @@ -773,24 +773,6 @@ sptr ReminderDataManager::GetRecentReminderLocked() return nullptr; } -std::vector> ReminderDataManager::GetSameBundleRemindersLocked(std::string &bundleName) -{ - std::lock_guard lock(ReminderDataManager::MUTEX); - std::vector> reminders; - for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { - sptr bundleOption = FindNotificationBundleOption((*it)->GetReminderId()); - if (bundleOption == nullptr) { - ANSR_LOGW("GetSameBundleRemindersLocked get notificationBundleOption(reminderId=%{public}d) fail", - (*it)->GetReminderId()); - continue; - } - if (bundleName == bundleOption->GetBundleName()) { - reminders.push_back((*it)); - } - } - return reminders; -} - void ReminderDataManager::HandleImmediatelyShow( std::vector> &showImmediately, bool isSysTimeChanged) { @@ -805,7 +787,7 @@ void ReminderDataManager::HandleImmediatelyShow( } } -sptr ReminderDataManager::HandleRefreshReminder(uint8_t &type, sptr &reminder) +sptr ReminderDataManager::HandleRefreshReminder(const uint8_t &type, sptr &reminder) { reminder->SetReminderTimeInMilli(ReminderRequest::INVALID_LONG_LONG_VALUE); uint64_t triggerTimeBefore = reminder->GetTriggerTimeInMilli(); @@ -897,7 +879,7 @@ bool ReminderDataManager::IsReminderAgentReady() const } bool ReminderDataManager::IsBelongToSameApp( - const sptr reminder, const std::string otherPkgName, const int otherUserId) + const sptr reminder, const std::string &otherPkgName, const int otherUserId) { ANSR_LOGD("otherUserId=%{public}d, (currently, userId not support)", otherUserId); int32_t reminderId = reminder->GetReminderId(); diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 75909939478a24e56050f2e5f2ff318351adbbd3..747a9a788277bec542230e2defe84f75af1b43fc 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -129,7 +129,7 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw } } -void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(OHOS::EventFwk::Want &want) const +void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(const EventFwk::Want &want) const { OHOS::AppExecFwk::ElementName ele = want.GetElement(); std::string bundleName = ele.GetBundleName(); @@ -142,7 +142,7 @@ void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(OHOS::Ev reminderDataManager_->CancelAllReminders(bundleOption, userId); } -void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(OHOS::EventFwk::Want &want) const +void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(const EventFwk::Want &want) const { sptr bundleOption = GetBundleOption(want); if (bundleOption == nullptr) {