diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index dceb9c0a9385f59f5b1be9aeb9756085f093a1d2..f4d058f091cc2fa68f090bb931ec3a21f37b12f2 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 1c850e3e13ca1dd504c2089e7c88888270ade07a..9f885091537dd11c34e3b21f27e6cd462d9f2603 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 f617dde2876a3058918747c90ef530503a648d8e..31d1d77f9083d37a93312c368b69c21d11aaebb6 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),