diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index fa554b4f5bb61a1979733617e52f3da699cb0d12..390d3966a6662e99f29cbe22798278980326762b 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1276,6 +1276,7 @@ private: ErrCode SetRequestBundleInfo(const sptr &request, int32_t uid, std::string &bundle); ErrCode PrePublishNotificationBySa(const sptr &request, int32_t uid, std::string &bundle); + ErrCode PrePublishRequest(const sptr &request); ErrCode PublishNotificationBySa(const sptr &request); bool IsNeedPushCheck(const sptr &request); void FillExtraInfoToJson(const sptr &request, @@ -1381,7 +1382,7 @@ private: ErrCode RemoveAllNotificationsInner(const sptr &bundleOption, int32_t reason); void RemoveNotificationList(const std::shared_ptr &record); void StartFinishTimerForUpdate(const std::shared_ptr &record, uint64_t process); - ErrCode CheckSystemLiveView(const sptr &request, const std::string &key); + ErrCode CheckLongTermLiveView(const sptr &request, const std::string &key); void ExcuteCancelGroupCancel(const sptr& bundleOption, const std::string &groupName, const int32_t reason); ErrCode ExcuteCancelAll(const sptr& bundleOption, const int32_t reason); diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index a8675583cddd0bbab265e0e2646ea3f474fbea89..ffe14f2c80a9fb46b3bd8eb9170eba6ea66cd604 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -169,6 +169,88 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt return result; } +ErrCode AdvancedNotificationService::PublishNotificationForIndirectProxy(const sptr &request) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("%{public}s", __FUNCTION__); + + if (!request) { + ANSR_LOGE("ReminderRequest object is nullptr"); + return ERR_ANS_INVALID_PARAM; + } + ErrCode result = PrePublishRequest(request); + if (result != ERR_OK) { + return result; + } + auto tokenCaller = IPCSkeleton::GetCallingTokenID(); + bool isAgentController = AccessTokenHelper::VerifyCallerPermission(tokenCaller, + OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER); + // SA not support sound + if (!request->GetSound().empty()) { + request->SetSound(""); + } + std::string bundle = request->GetCreatorBundleName(); + int32_t uid = request->GetCreatorUid(); + std::shared_ptr record = std::make_shared(); + record->request = request; + record->isThirdparty = false; + record->bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); + record->bundleOption->SetInstanceKey(request->GetCreatorInstanceKey()); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); + if (record->bundleOption == nullptr || bundleOption == nullptr) { + ANS_LOGE("Failed to create bundleOption"); + return ERR_ANS_NO_MEMORY; + } + record->notification = new (std::nothrow) Notification(request); + if (record->notification == nullptr) { + ANS_LOGE("Failed to create notification"); + return ERR_ANS_NO_MEMORY; + } + + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + SetRequestBySlotType(record->request, bundleOption); + + auto ipcUid = IPCSkeleton::GetCallingUid(); + ffrt::task_handle handler = notificationSvrQueue_->submit_h([&]() { + if (AssignValidNotificationSlot(record, bundleOption) != ERR_OK) { + ANS_LOGE("Can not assign valid slot!"); + } + + ChangeNotificationByControlFlags(record, isAgentController); + if (IsSaCreateSystemLiveViewAsBundle(record, ipcUid) && + (std::static_pointer_cast( + record->request->GetContent()->GetNotificationContent())->GetType() == TYPE_CODE_DOWNLOAD)) { + result = SaPublishSystemLiveViewAsBundle(record); + if (result == ERR_OK) { + SendLiveViewUploadHiSysEvent(record, UploadStatus::CREATE); + } + return; + } + + if (AssignToNotificationList(record) != ERR_OK) { + ANS_LOGE("Failed to assign notification list"); + return; + } + + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); + }); + notificationSvrQueue_->wait(handler); + if (result != ERR_OK) { + return result; + } + + if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { + StartAutoDelete(record, + record->request->GetAutoDeletedTime(), NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + } + return ERR_OK; +} + bool AdvancedNotificationService::InitPublishProcess() { if (publishProcess_.size() > 0) { diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index d43bf75671b36048f638ed57734eb8eeb91eeae2..90848a55f59410c8d2a7bc438b3ad5d24cc52108 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2138,13 +2138,9 @@ ErrCode AdvancedNotificationService::CheckSoundPermission(const sptr &request, +ErrCode AdvancedNotificationService::CheckLongTermLiveView(const sptr &request, const std::string &key) { - if (!request->IsSystemLiveView()) { - return ERR_OK; - } - // live view, not update std::shared_ptr additionalData = request->GetAdditionalData(); if (additionalData && additionalData->HasParam("SYSTEM_UPDATE_ONLY")) { @@ -2155,7 +2151,7 @@ ErrCode AdvancedNotificationService::CheckSystemLiveView(const sptrrequest, record->notification->GetKey()) != ERR_OK) { + if (!remove && CheckLongTermLiveView(record->request, record->notification->GetKey()) != ERR_OK) { return ERR_ANS_INVALID_PARAM; } diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index c3f5f318e20d84c02734a0d51a051975a7ae35d6..d42d8c3d6efaf901dd5206cacc9034f214b80520 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1690,6 +1690,55 @@ ErrCode AdvancedNotificationService::PrePublishNotificationBySa(const sptr &request) +{ + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_9, EventBranchId::BRANCH_0); + if (!InitPublishProcess()) { + return ERR_ANS_NO_MEMORY; + } + ErrCode result = publishProcess_[request->GetSlotType()]->PublishPreWork(request, false); + if (result != ERR_OK) { + message.BranchId(EventBranchId::BRANCH_0).ErrorCode(result).Message("publish prework failed", true); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); + return result; + } + result = CheckUserIdParams(request->GetReceiverUserId()); + if (result != ERR_OK) { + message.BranchId(EventBranchId::BRANCH_1).ErrorCode(result).Message("User is invalid", true); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); + return result; + } + + if (request->GetCreatorUid() <= 0) { + message.BranchId(EventBranchId::BRANCH_2).ErrorCode(ERR_ANS_INVALID_UID) + .Message("createUid failed" + std::to_string(request->GetCreatorUid()), true); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); + return ERR_ANS_INVALID_UID; + } + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager == nullptr) { + ANS_LOGE("failed to get bundleManager!"); + return ERR_ANS_INVALID_BUNDLE; + } + request->SetCreatorPid(IPCSkeleton::GetCallingPid()); + int32_t userId = SUBSCRIBE_USER_INIT; + if (request->GetCreatorUserId() == SUBSCRIBE_USER_INIT) { + OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(request->GetCreatorUid(), userId); + request->SetCreatorUserId(userId); + } + + if (request->GetDeliveryTime() <= 0) { + request->SetDeliveryTime(GetCurrentTime()); + } + result = CheckPictureSize(request); + if (result != ERR_OK) { + message.ErrorCode(result).Message("Failed to check picture size", true); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); + return result; + } + return ERR_OK; +} + uint64_t AdvancedNotificationService::StartAutoDelete(const std::shared_ptr &record, int64_t deleteTimePoint, int32_t reason) {