From 76148af1d574dedfff52845ba32d4ad62f38c3b3 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 12 Feb 2025 15:13:26 +0800 Subject: [PATCH] fix bug Signed-off-by: gaojiaqi --- .../include/reminder_bundle_manager_helper.h | 141 +++++++++--------- .../include/reminder_calendar_share_table.h | 4 +- .../include/reminder_config_change_observer.h | 54 +++---- .../src/reminder_datashare_helper.cpp | 35 ++--- 4 files changed, 110 insertions(+), 124 deletions(-) diff --git a/services/reminder/include/reminder_bundle_manager_helper.h b/services/reminder/include/reminder_bundle_manager_helper.h index 9763f19e8..7d004085b 100644 --- a/services/reminder/include/reminder_bundle_manager_helper.h +++ b/services/reminder/include/reminder_bundle_manager_helper.h @@ -13,73 +13,74 @@ * limitations under the License. */ -#ifndef NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H -#define NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H - -#include -#include -#include - -#include "bundle_mgr_interface.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "refbase.h" -#include "remote_death_recipient.h" -#include "singleton.h" - -namespace OHOS { -namespace Notification { -class ReminderBundleManagerHelper : public DelayedSingleton { -public: - /** - * @brief Obtains the bundle name base on the specified uid. - * - * @param uid Indicates the specified uid. - * @return Returns the bundle name. - */ - std::string GetBundleNameByUid(int32_t uid); - - /** - * @brief Obtains the default uid. - * - * @param bundle Indicates the bundle name. - * @param userId Indicates the user id. - * @return Returns the uid. - */ - int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); - - /** - * @brief Obtains bundle info by bundle name. - * - * @param bundleName Indicates the bundle name. - * @param flag Indicates the bundle flag. - * @param bundleInfo Indicates the bundle info. - * @param userId Indicates the user id. - * @return Returns the check result. - */ - bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, - int32_t userId, AppExecFwk::BundleInfo &bundleInfo); - - /** - * @brief Obtains the app index by uid. - * @param uid Indicates uid. - * @return Returns the query result if succeed, retrun 0(main index) otherwise. - */ - int32_t GetAppIndexByUid(const int32_t uid); - -private: - void Connect(); - void Disconnect(); - - void OnRemoteDied(const wptr &object); - -private: - sptr bundleMgr_ = nullptr; - std::mutex connectionMutex_; - sptr deathRecipient_ = nullptr; - - DECLARE_DELAYED_SINGLETON(ReminderBundleManagerHelper) -}; -} // namespace Notification -} // namespace OHOS -#endif // NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H + #ifndef NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H + #define NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H + + #include + #include + #include + + #include "bundle_mgr_interface.h" + #include "ipc_skeleton.h" + #include "iremote_object.h" + #include "refbase.h" + #include "remote_death_recipient.h" + #include "singleton.h" + + namespace OHOS { + namespace Notification { + class ReminderBundleManagerHelper : public DelayedSingleton { + public: + /** + * @brief Obtains the bundle name base on the specified uid. + * + * @param uid Indicates the specified uid. + * @return Returns the bundle name. + */ + std::string GetBundleNameByUid(int32_t uid); + + /** + * @brief Obtains the default uid. + * + * @param bundle Indicates the bundle name. + * @param userId Indicates the user id. + * @return Returns the uid. + */ + int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); + + /** + * @brief Obtains bundle info by bundle name. + * + * @param bundleName Indicates the bundle name. + * @param flag Indicates the bundle flag. + * @param bundleInfo Indicates the bundle info. + * @param userId Indicates the user id. + * @return Returns the check result. + */ + bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, + int32_t userId, AppExecFwk::BundleInfo &bundleInfo); + + /** + * @brief Obtains the app index by uid. + * @param uid Indicates uid. + * @return Returns the query result if succeed, retrun 0(main index) otherwise. + */ + int32_t GetAppIndexByUid(const int32_t uid); + + private: + void Connect(); + void Disconnect(); + + void OnRemoteDied(const wptr &object); + + private: + sptr bundleMgr_ = nullptr; + std::mutex connectionMutex_; + sptr deathRecipient_ = nullptr; + + DECLARE_DELAYED_SINGLETON(ReminderBundleManagerHelper) + }; + } // namespace Notification + } // namespace OHOS + #endif // NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H + \ No newline at end of file diff --git a/services/reminder/include/reminder_calendar_share_table.h b/services/reminder/include/reminder_calendar_share_table.h index 4ac40cc83..33c7dc3f3 100644 --- a/services/reminder/include/reminder_calendar_share_table.h +++ b/services/reminder/include/reminder_calendar_share_table.h @@ -23,23 +23,21 @@ class ReminderCalendarShareTable { public: static constexpr const char* ID = "_id"; static constexpr const char* EVENT_ID = "event_id"; - static constexpr const char* BEGIN = "begin"; static constexpr const char* END = "end"; static constexpr const char* ALARM_TIME = "alarmTime"; static constexpr const char* STATE = "state"; - static constexpr const char* MINUTES = "minutes"; static constexpr const char* TITLE = "title"; static constexpr const char* CONTENT = "content"; static constexpr const char* WANT_AGENT = "wantAgent"; static constexpr const char* BUTTONS = "buttons"; static constexpr const char* SLOT_TYPE = "slotType"; static constexpr const char* KEEP_HEADSUP = "keepHeadsUp"; + static constexpr const char* IDENTIFIER = "identifier"; static constexpr const char* PROXY = "datashareproxy://com.ohos.calendardata/CalendarAlerts"; static constexpr const char* NAME = "com.ohos.calendar"; static constexpr const char* DATA_NAME = "com.ohos.calendardata"; static constexpr const char* ENTRY = "ReminderCallbackExtAbility"; - static constexpr const char* IDENTIFIER = "identifier"; static constexpr const char* PARAM_CALLBACK_TYPE = "CallbackType"; diff --git a/services/reminder/include/reminder_config_change_observer.h b/services/reminder/include/reminder_config_change_observer.h index 982b7ddb1..31b33f70f 100644 --- a/services/reminder/include/reminder_config_change_observer.h +++ b/services/reminder/include/reminder_config_change_observer.h @@ -13,30 +13,30 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H - -#include "configuration_observer_stub.h" - -namespace OHOS { -namespace Notification { - -/** - * @brief Listening system language change, when the system language changes, - * notify ReminderDataManager. -*/ -class ReminderConfigChangeObserver final : public AppExecFwk::ConfigurationObserverStub { -public: - ReminderConfigChangeObserver() = default; - ~ReminderConfigChangeObserver() = default; - -public: - void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; - -private: - std::string languageInfo_; -}; -} // namespace Notification -} // namespace OHOS - -#endif \ No newline at end of file + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H + + #include "configuration_observer_stub.h" + + namespace OHOS { + namespace Notification { + + /** + * @brief Listening system language change, when the system language changes, + * notify ReminderDataManager. + */ + class ReminderConfigChangeObserver final : public AppExecFwk::ConfigurationObserverStub { + public: + ReminderConfigChangeObserver() = default; + ~ReminderConfigChangeObserver() = default; + + public: + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; + + private: + std::string languageInfo_; + }; + } // namespace Notification + } // namespace OHOS + + #endif \ No newline at end of file diff --git a/services/reminder/src/reminder_datashare_helper.cpp b/services/reminder/src/reminder_datashare_helper.cpp index cd1862609..a08dd9a0b 100644 --- a/services/reminder/src/reminder_datashare_helper.cpp +++ b/services/reminder/src/reminder_datashare_helper.cpp @@ -31,7 +31,6 @@ namespace { constexpr int64_t DURATION_PRELOAD_TIME = 10 * 60 * 60 * 1000; // 10h, millisecond constexpr int64_t DURATION_DELAY_TASK = 1 * 1000 * 1000; // 1s, microsecond constexpr int64_t CYCLE_DATASHARE_TASK = 1; // 1s -constexpr int64_t DURATION_ONE_MINUTE = 60 * 1000; // 1min, millisecond constexpr int64_t DURATION_ONE_SECOND = 1000; // 1s, millisecond } @@ -129,9 +128,9 @@ bool ReminderDataShareHelper::Query(std::map> predicates.EndWrap(); predicates.Or(); predicates.BeginWrap(); - predicates.GreaterThanOrEqualTo(ReminderCalendarShareTable::BEGIN, timestamp); + predicates.GreaterThanOrEqualTo(ReminderCalendarShareTable::ALARM_TIME, timestamp); predicates.And(); - predicates.LessThanOrEqualTo(ReminderCalendarShareTable::BEGIN, targetTimestamp); + predicates.LessThanOrEqualTo(ReminderCalendarShareTable::ALARM_TIME, targetTimestamp); predicates.EndWrap(); predicates.EndWrap(); auto resultSet = helper->Query(uri, predicates, columns); @@ -344,21 +343,15 @@ sptr ReminderDataShareHelper::CreateReminder( reminder->DeserializeWantAgent(strValue, 0); GetRdbValue(result, ReminderCalendarShareTable::IDENTIFIER, strValue); reminder->SetIdentifier(strValue); - uint64_t minutes = 0; - GetRdbValue(result, ReminderCalendarShareTable::MINUTES, minutes); - minutes = minutes * DURATION_ONE_MINUTE; uint64_t endDateTime = 0; GetRdbValue(result, ReminderCalendarShareTable::END, endDateTime); reminder->SetAutoDeletedTime(endDateTime); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - uint64_t dateTime = 0; - GetRdbValue(result, ReminderCalendarShareTable::BEGIN, dateTime); - dateTime -= minutes; - calendar->SetDateTime(dateTime); + calendar->SetDateTime(triggerTime); calendar->SetEndDateTime(endDateTime); - time_t now = static_cast(dateTime / DURATION_ONE_SECOND); + time_t now = static_cast(triggerTime / DURATION_ONE_SECOND); struct tm nowTime; (void)localtime_r(&now, &nowTime); calendar->SetFirstDesignateYear(static_cast(ReminderRequest::GetActualTime( @@ -376,12 +369,13 @@ std::map> ReminderDataShareHelper::CreateRemi for (auto& values : info.valueBuckets_) { sptr reminder = sptr::MakeSptr(); InitNormalInfo(reminder); - InitBaseInfo(values, reminder); - uint64_t minutes = 0; - auto iter = values.find(ReminderCalendarShareTable::MINUTES); + uint64_t triggerTime = 0; + auto iter = values.find(ReminderCalendarShareTable::ALARM_TIME); if (iter != values.end()) { - minutes = static_cast(std::get(iter->second)) * DURATION_ONE_MINUTE; + triggerTime = static_cast(std::get(iter->second)); + reminder->SetTriggerTimeInMilli(triggerTime); } + InitBaseInfo(values, reminder); uint64_t endDateTime = 0; iter = values.find(ReminderCalendarShareTable::END); if (iter != values.end()) { @@ -390,10 +384,7 @@ std::map> ReminderDataShareHelper::CreateRemi } ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - iter = values.find(ReminderCalendarShareTable::BEGIN); - if (iter != values.end()) { - calendar->SetDateTime(static_cast(std::get(iter->second)) - minutes); - } + calendar->SetDateTime(triggerTime); calendar->SetEndDateTime(endDateTime); time_t now = static_cast(calendar->GetDateTime() / DURATION_ONE_SECOND); @@ -425,11 +416,7 @@ void ReminderDataShareHelper::InitNormalInfo(sptr& reminder) void ReminderDataShareHelper::InitBaseInfo(const DataShare::DataShareObserver::ChangeInfo::VBucket& info, sptr& reminder) { - auto iter = info.find(ReminderCalendarShareTable::ALARM_TIME); - if (iter != info.end()) { - reminder->SetTriggerTimeInMilli(static_cast(std::get(iter->second))); - } - iter = info.find(ReminderCalendarShareTable::ID); + auto iter = info.find(ReminderCalendarShareTable::ID); if (iter != info.end()) { reminder->SetReminderId(static_cast(std::get(iter->second))); } -- Gitee