From d7654a8df522fc630589e73a25bf793ff2114303 Mon Sep 17 00:00:00 2001 From: wufarong Date: Thu, 26 Sep 2024 19:13:30 +0800 Subject: [PATCH] =?UTF-8?q?RecoverLiveViewFromDb=E5=86=85=E9=83=A8?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E6=94=BE=E5=85=A5ffrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong Change-Id: I0f32cdb60cb0130b4085f9e56dd5c9355bf9149c --- frameworks/ans/src/notification_request.cpp | 12 +-- ...dvanced_notification_live_view_service.cpp | 94 ++++++++++--------- .../ans/src/advanced_notification_service.cpp | 4 +- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index dceb9c0a9..f4d058f09 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -1544,7 +1544,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) int32_t slotTypeValue = parcel.ReadInt32(); if (slotTypeValue < 0 || slotTypeValue >= static_cast(NotificationConstant::SlotType::ILLEGAL_TYPE)) { - ANS_LOGE("Invalid slot type value :%d. It should be in [0 , %d).", + ANS_LOGE("Invalid slot type value :%{public}d. It should be in [0 , %{public}d).", slotTypeValue, static_cast(NotificationConstant::SlotType::ILLEGAL_TYPE)); return false; } @@ -1552,7 +1552,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) int32_t groupAlertTypeValue = parcel.ReadInt32(); if (groupAlertTypeValue < 0 || groupAlertTypeValue >= static_cast(NotificationRequest::GroupAlertType::ILLEGAL_TYPE)) { - ANS_LOGE("Invalid groupAlert type value :%d. It should be in [0 , %d).", + ANS_LOGE("Invalid groupAlert type value :%{public}d. It should be in [0 , %{public}d).", groupAlertTypeValue, static_cast(NotificationRequest::GroupAlertType::ILLEGAL_TYPE)); return false; } @@ -1560,26 +1560,26 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) int32_t visiblenessTypeValue = parcel.ReadInt32(); if (visiblenessTypeValue < 0 || visiblenessTypeValue >= static_cast(NotificationConstant::VisiblenessType::ILLEGAL_TYPE)) { - ANS_LOGE("Invalid visibleness type value :%d. It should be in [0 , %d).", + ANS_LOGE("Invalid visibleness type value :%{public}d. It should be in [0 , %{public}d).", visiblenessTypeValue, static_cast(NotificationConstant::VisiblenessType::ILLEGAL_TYPE)); return false; } visiblenessType_ = static_cast(visiblenessTypeValue); int32_t badgeStyleValue = parcel.ReadInt32(); if (badgeStyleValue < 0) { - ANS_LOGE("Invalid badge style value :%d. It should be greater than 0.", badgeStyleValue); + ANS_LOGE("Invalid badge style value :%{public}d. It should be greater than 0.", badgeStyleValue); return false; } if (badgeStyleValue >= static_cast(NotificationRequest::BadgeStyle::ILLEGAL_TYPE)) { badgeStyleValue = static_cast(NotificationRequest::BadgeStyle::NONE); - ANS_LOGE("The badge style value is too large, set it to the default enumeration value: %d.", + ANS_LOGE("The badge style value is too large, set it to the default enumeration value: %{public}d.", static_cast(NotificationRequest::BadgeStyle::NONE)); } badgeStyle_ = static_cast(badgeStyleValue); int32_t notificationContentTypeValue = parcel.ReadInt32(); if (notificationContentTypeValue <= static_cast(NotificationContent::Type::NONE) || notificationContentTypeValue >= static_cast(NotificationContent::Type::ILLEGAL_TYPE)) { - ANS_LOGE("Invalid notification content type value :%d. It should be in (%d , %d)", + ANS_LOGE("Invalid notification content type value :%{public}d. It should be in (%{public}d , %{public}d)", notificationContentTypeValue, static_cast(NotificationContent::Type::NONE), static_cast(NotificationContent::Type::ILLEGAL_TYPE)); return false; diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index 1c850e3e1..9f8850915 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -48,58 +48,64 @@ void AdvancedNotificationService::RecoverLiveViewFromDb(int32_t userId) ANS_LOGE("Get liveView from db failed."); return; } + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("notificationSvrQueue_ is nullptr."); + return; + } + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGI("There are %{public}zu live views to recover.", requestsdb.size()); + for (const auto &requestObj : requestsdb) { + ANS_LOGD("Recover request: %{public}s.", requestObj.request->Dump().c_str()); + if (!IsLiveViewCanRecover(requestObj.request)) { + int32_t userId = requestObj.request->GetReceiverUserId(); + if (DoubleDeleteNotificationFromDb(requestObj.request->GetKey(), + requestObj.request->GetSecureKey(), userId) != ERR_OK) { + ANS_LOGE("Delete notification failed."); + } + continue; + } - for (const auto &requestObj : requestsdb) { - ANS_LOGD("Recover request: %{public}s.", requestObj.request->Dump().c_str()); - if (!IsLiveViewCanRecover(requestObj.request)) { - int32_t userId = requestObj.request->GetReceiverUserId(); - if (DoubleDeleteNotificationFromDb(requestObj.request->GetKey(), - requestObj.request->GetSecureKey(), userId) != ERR_OK) { - ANS_LOGE("Delete notification failed."); + auto record = std::make_shared(); + if (FillNotificationRecord(requestObj, record) != ERR_OK) { + ANS_LOGE("Fill notification record failed."); + continue; } - continue; - } - auto record = std::make_shared(); - if (FillNotificationRecord(requestObj, record) != ERR_OK) { - ANS_LOGE("Fill notification record failed."); - continue; - } + if (Filter(record, true) != ERR_OK) { + ANS_LOGE("Filter record failed."); + continue; + } - if (Filter(record, true) != ERR_OK) { - ANS_LOGE("Filter record failed."); - continue; - } + if (FlowControl(record) != ERR_OK) { + ANS_LOGE("Flow control failed."); + continue; + } - if (FlowControl(record) != ERR_OK) { - ANS_LOGE("Flow control failed."); - continue; - } + // Turn off ringtone and vibration during recovery process + auto notificationFlags = record->request->GetFlags(); + notificationFlags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); + notificationFlags->SetVibrationEnabled(NotificationConstant::FlagStatus::CLOSE); + record->request->SetFlags(notificationFlags); + ANS_LOGI("SetFlags-Recovery, notificationKey = %{public}s flags = %{public}d", + record->request->GetKey().c_str(), notificationFlags->GetReminderFlags()); + if (AssignToNotificationList(record) != ERR_OK) { + ANS_LOGE("Add notification to record list failed."); + continue; + } + UpdateRecentNotification(record->notification, false, 0); - // Turn off ringtone and vibration during recovery process - auto notificationFlags = record->request->GetFlags(); - notificationFlags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); - notificationFlags->SetVibrationEnabled(NotificationConstant::FlagStatus::CLOSE); - record->request->SetFlags(notificationFlags); - ANS_LOGI("SetFlags-Recovery, notificationKey = %{public}s flags = %{public}d", - record->request->GetKey().c_str(), notificationFlags->GetReminderFlags()); - if (AssignToNotificationList(record) != ERR_OK) { - ANS_LOGE("Add notification to record list failed."); - continue; + StartFinishTimer(record, requestObj.request->GetFinishDeadLine(), + NotificationConstant::TRIGGER_EIGHT_HOUR_REASON_DELETE); + StartUpdateTimer(record, requestObj.request->GetUpdateDeadLine(), + NotificationConstant::TRIGGER_FOUR_HOUR_REASON_DELETE); } - UpdateRecentNotification(record->notification, false, 0); - - StartFinishTimer(record, requestObj.request->GetFinishDeadLine(), - NotificationConstant::TRIGGER_EIGHT_HOUR_REASON_DELETE); - StartUpdateTimer(record, requestObj.request->GetUpdateDeadLine(), - NotificationConstant::TRIGGER_FOUR_HOUR_REASON_DELETE); - } - - // publish notifications - for (const auto &subscriber : NotificationSubscriberManager::GetInstance()->GetSubscriberRecords()) { - OnSubscriberAdd(subscriber); - } + // publish notifications + for (const auto &subscriber : NotificationSubscriberManager::GetInstance()->GetSubscriberRecords()) { + OnSubscriberAdd(subscriber); + } + })); + notificationSvrQueue_->wait(handler); ANS_LOGI("End recover live view from db."); } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index f617dde28..31d1d77f9 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -301,9 +301,7 @@ AdvancedNotificationService::AdvancedNotificationService() std::bind(&AdvancedNotificationService::OnSubscriberAdd, this, std::placeholders::_1); NotificationSubscriberManager::GetInstance()->RegisterOnSubscriberAddCallback(callback); - std::function recoverFunc = std::bind( - &AdvancedNotificationService::RecoverLiveViewFromDb, this, SUBSCRIBE_USER_INIT); - notificationSvrQueue_->submit(recoverFunc); + RecoverLiveViewFromDb(); ISystemEvent iSystemEvent = { std::bind(&AdvancedNotificationService::OnBundleRemoved, this, std::placeholders::_1), -- Gitee