From 3c43fed89990d2e946767d74d25ecf7add0513ac Mon Sep 17 00:00:00 2001 From: baozeyu Date: Thu, 22 Aug 2024 15:02:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_notification.h | 2 +- interfaces/inner_api/notification_helper.h | 2 +- .../ans/include/advanced_notification_service.h | 5 +++-- services/ans/include/notification_preferences.h | 2 +- .../include/notification_preferences_database.h | 2 +- .../advanced_notification_live_view_service.cpp | 17 ++++++++++++----- .../advanced_notification_publish_service.cpp | 1 + .../ans/src/advanced_notification_service.cpp | 3 ++- services/ans/src/notification_preferences.cpp | 6 +++--- .../src/notification_preferences_database.cpp | 9 +++++++-- services/ans/src/system_event_observer.cpp | 11 ++++++++--- 11 files changed, 40 insertions(+), 20 deletions(-) diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 691c08642..1e2b6a64e 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -168,7 +168,7 @@ public: /** * @brief Cancels all the published notifications. - * @note To cancel a specified notification, see CancelNotification(int_32). + * @note To cancel a specified notification, see CancelNotification(int32_t). * * @return Returns cancel all notifications result. */ diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 6838448b2..b1345029b 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -169,7 +169,7 @@ public: /** * @brief Cancels all the published notifications. * - * @note To cancel a specified notification, see CancelNotification(int_32). + * @note To cancel a specified notification, see CancelNotification(int32_t). * @return Returns cancel all notifications result. */ static ErrCode CancelAllNotifications(); diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 864046222..c7b509233 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1100,7 +1100,7 @@ public: /** * @brief Recover LiveView from DB. */ - void RecoverLiveViewFromDb(); + void RecoverLiveViewFromDb(int32_t userId = -1); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED /** @@ -1286,7 +1286,8 @@ private: std::shared_ptr record); static int32_t SetNotificationRequestToDb(const NotificationRequestDb &requestDb); static int32_t GetNotificationRequestFromDb(const std::string &key, NotificationRequestDb &requestDb); - static int32_t GetBatchNotificationRequestsFromDb(std::vector &requests); + static int32_t GetBatchNotificationRequestsFromDb(std::vector &requests, + int32_t userId = -1); static int32_t DeleteNotificationRequestFromDb(const std::string &key, const int32_t userId); void CancelTimer(uint64_t timerId); ErrCode UpdateNotificationTimerInfo(const std::shared_ptr &record); diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 2f75ed6e2..1ffce83c8 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -359,7 +359,7 @@ public: */ bool GetBundleSoundPermission(bool &allPackage, std::set &bundleNames); - void InitSettingFromDisturbDB(); + void InitSettingFromDisturbDB(int32_t userId = -1); void RemoveSettings(int32_t userId); void RemoveAnsBundleDbInfo(const sptr &bundleOption); void RemoveEnabledDbByBundle(const sptr &bundleOption); diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index f4ecb94f3..aafa057b2 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -161,7 +161,7 @@ public: * @param info Indicates notification info. * @return Return true on success, false on failure. */ - bool ParseFromDisturbeDB(NotificationPreferencesInfo &info); + bool ParseFromDisturbeDB(NotificationPreferencesInfo &info, int32_t userId = -1); /** * @brief Delete all data from disturbe DB. diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index e5d7810c0..0f4d0d40e 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -37,12 +37,12 @@ namespace OHOS { namespace Notification { const std::string LOCK_SCREEN_PICTURE_TAG = "lock_screen_picture"; const std::string PROGRESS_VALUE = "progressValue"; -void AdvancedNotificationService::RecoverLiveViewFromDb() +void AdvancedNotificationService::RecoverLiveViewFromDb(int32_t userId) { - ANS_LOGI("Start recover live view from db."); + ANS_LOGI("Start recover live view from db. userId:%{public}d", userId); std::vector requestsdb; - if (GetBatchNotificationRequestsFromDb(requestsdb) != ERR_OK) { + if (GetBatchNotificationRequestsFromDb(requestsdb, userId) != ERR_OK) { ANS_LOGE("Get liveView from db failed."); return; } @@ -290,11 +290,18 @@ int32_t AdvancedNotificationService::GetNotificationRequestFromDb( return ERR_OK; } -int32_t AdvancedNotificationService::GetBatchNotificationRequestsFromDb(std::vector &requests) +int32_t AdvancedNotificationService::GetBatchNotificationRequestsFromDb( + std::vector &requests, int32_t userId) { std::unordered_map dbRecords; std::vector userIds; - int32_t ret = OsAccountManagerHelper::GetInstance().GetAllActiveOsAccount(userIds); + int ret = ERR_OK; + if (userId == -1) { + ret = OsAccountManagerHelper::GetInstance().GetAllActiveOsAccount(userIds); + } else { + userIds.push_back(userId); + } + if (ret != ERR_OK) { ANS_LOGE("Get all os account failed."); return ret; diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index ea8d6c9cc..ebf7a1c5e 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -789,6 +789,7 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string if (!CreateDialogManager()) { return ERROR_INTERNAL_ERROR; } + result = dialogManager_->RequestEnableNotificationDailog(bundleOption, callback, callerToken); if (result == ERR_OK) { result = ERR_ANS_DIALOG_POP_SUCCEEDED; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 5da77206f..b9ca6c3dc 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -301,7 +301,8 @@ AdvancedNotificationService::AdvancedNotificationService() std::bind(&AdvancedNotificationService::OnSubscriberAdd, this, std::placeholders::_1); NotificationSubscriberManager::GetInstance()->RegisterOnSubscriberAddCallback(callback); - std::function recoverFunc = std::bind(&AdvancedNotificationService::RecoverLiveViewFromDb, this); + std::function recoverFunc = std::bind( + &AdvancedNotificationService::RecoverLiveViewFromDb, this, SUBSCRIBE_USER_INIT); notificationSvrQueue_->submit(recoverFunc); ISystemEvent iSystemEvent = { diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 2907cda30..d73ed36ab 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -926,12 +926,12 @@ ErrCode NotificationPreferences::IsSmartReminderEnabled(const std::string &devic return storeDBResult ? ERR_OK : ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } -void NotificationPreferences::InitSettingFromDisturbDB() +void NotificationPreferences::InitSettingFromDisturbDB(int32_t userId) { - ANS_LOGD("%{public}s", __FUNCTION__); + ANS_LOGI("%{public}s userId is %{public}d", __FUNCTION__, userId); std::lock_guard lock(preferenceMutex_); if (preferncesDB_ != nullptr) { - preferncesDB_->ParseFromDisturbeDB(preferencesInfo_); + preferncesDB_->ParseFromDisturbeDB(preferencesInfo_, userId); } } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index e80541632..1b5629041 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -644,7 +644,7 @@ bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( return true; } -bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreferencesInfo &info) +bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreferencesInfo &info, int32_t userId) { ANS_LOGD("%{public}s", __FUNCTION__); if (!CheckRdbStore()) { @@ -652,7 +652,12 @@ bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreference return false; } std::vector activeUserId; - OsAccountManagerHelper::GetInstance().GetAllActiveOsAccount(activeUserId); + if (userId == -1) { + OsAccountManagerHelper::GetInstance().GetAllActiveOsAccount(activeUserId); + } else { + activeUserId.push_back(userId); + } + for (auto iter : activeUserId) { GetDoNotDisturbType(info, iter); GetDoNotDisturbBeginDate(info, iter); diff --git a/services/ans/src/system_event_observer.cpp b/services/ans/src/system_event_observer.cpp index f382a5891..973fb914b 100644 --- a/services/ans/src/system_event_observer.cpp +++ b/services/ans/src/system_event_observer.cpp @@ -92,11 +92,16 @@ void SystemEventObserver::OnReceiveEvent(const EventFwk::CommonEventData &data) } #endif } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { - NotificationPreferences::GetInstance()->InitSettingFromDisturbDB(); - AdvancedNotificationService::GetInstance()->RecoverLiveViewFromDb(); + int32_t userId = data.GetCode(); + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Illegal userId, userId[%{public}d].", userId); + return; + } + NotificationPreferences::GetInstance()->InitSettingFromDisturbDB(userId); + AdvancedNotificationService::GetInstance()->RecoverLiveViewFromDb(userId); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { int32_t userId = data.GetCode(); - if (userId <= DEFAULT_USER_ID) { + if (userId <= SUBSCRIBE_USER_INIT) { ANS_LOGE("Illegal userId, userId[%{public}d].", userId); return; } -- Gitee