diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 2c7fd0df83c7e24c2f5224a63c3edfe19eeb79ef..5c7a69bbbbdb9100858e6e0b9187f3e11860a430 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(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 > (UINT64_MAX / MILLI_SECONDS)) { ANSR_LOGW("setRingDuration, replace to set (1s), for the given is out of legal range"); ringDurationInMilli_ = MILLI_SECONDS; } else { @@ -823,7 +823,7 @@ bool ReminderRequest::UpdateNextReminder() return false; } -void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra) +void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string &extra) { switch (type) { case UpdateNotificationType::COMMON: { @@ -1351,7 +1351,7 @@ void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) notificationRequest_->SetWantAgent(wantAgent); } -void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string function) +void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string &function) { uint8_t oldState = state_; if (deSet) { 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..59759a6997bec365c9d354b059d9952fbca257f8 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(std::string &wantAgentInfo, const uint8_t &type); /** * @brief Sets action button. @@ -557,7 +557,7 @@ public: * @param type Indicates the update type. * @param extra Indicates the extra content. */ - void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); + void UpdateNotificationRequest(UpdateNotificationType type, std::string &extra); static int GetActualTime(const TimeTransferType &type, int cTime); static int GetCTime(const TimeTransferType &type, int actualTime); @@ -678,7 +678,7 @@ private: bool InitNotificationRequest(); void InitServerObj(); void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); - void SetState(bool deSet, const uint8_t newState, std::string function); + void SetState(bool deSet, const uint8_t newState, std::string &function); void SetWantAgent(AppExecFwk::ElementName &element); std::vector StringSplit(std::string source, const std::string &split) const; void UpdateActionButtons(const bool &setSnooze); 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 723dba78a4e25bb6b188e20272f036875033387f..ca69e0d5dd97e0010fbd33d689e581b7b2f5840e 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. @@ -247,14 +247,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); /** @@ -264,7 +256,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 @@ -287,7 +279,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 538c554a5e4fa8c89e46557c871cb75ef9b4d69a..c971d5df84cdfc4fdd103aa1b3fb9e46f7904fe9 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; @@ -375,7 +375,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(); @@ -769,24 +769,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) { @@ -801,7 +783,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(); @@ -893,7 +875,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 36215051b34dbbf8ff9b3a79e251b40dc3e264f7..e369d0c2af20cfa2050c0fe4e34f81b1a111ee7a 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) {