diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index 75b98c85ec87ac6a44affb877c5c39dace24feff..4331dea48de304c3f07fdc7a03ed7b3dce846a0f 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -55,6 +55,9 @@ Notification::Notification(const Notification &other) isRemoveAllowed_ = other.isRemoveAllowed_; sourceType_ = other.sourceType_; deviceId_ = other.deviceId_; + updateTimerId_ = other.updateTimerId_; + finishTimerId_ = other.finishTimerId_; + archiveTimerId_ = other.archiveTimerId_; } Notification::~Notification() @@ -308,6 +311,26 @@ bool Notification::MarshallingInt64(Parcel &parcel) const return true; } +bool Notification::MarshallingUint64(Parcel &parcel) const +{ + if (!parcel.WriteUint64(updateTimerId_)) { + ANS_LOGE("Can't write update timer id."); + return false; + } + + if (!parcel.WriteUint64(finishTimerId_)) { + ANS_LOGE("Can't write finish timer id."); + return false; + } + + if (!parcel.WriteUint64(archiveTimerId_)) { + ANS_LOGE("Can't write archive timer id."); + return false; + } + + return true; +} + bool Notification::MarshallingParcelable(Parcel &parcel) const { if (!parcel.WriteStrongParcelable(request_)) { @@ -332,6 +355,9 @@ bool Notification::Marshalling(Parcel &parcel) const if (!MarshallingInt64(parcel)) { return false; } + if (!MarshallingUint64(parcel)) { + return false; + } if (!MarshallingParcelable(parcel)) { return false; } @@ -392,6 +418,13 @@ void Notification::ReadFromParcelInt64(Parcel &parcel) parcel.ReadInt64Vector(&vibrationStyle_); } +void Notification::ReadFromParcelUint64(Parcel &parcel) +{ + updateTimerId_ = parcel.ReadUint64(); + finishTimerId_ = parcel.ReadUint64(); + archiveTimerId_ = parcel.ReadUint64(); +} + void Notification::ReadFromParcelParcelable(Parcel &parcel) { // Read request_ @@ -404,6 +437,7 @@ bool Notification::ReadFromParcel(Parcel &parcel) ReadFromParcelString(parcel); ReadFromParcelInt32(parcel); ReadFromParcelInt64(parcel); + ReadFromParcelUint64(parcel); ReadFromParcelParcelable(parcel); return true; @@ -505,7 +539,40 @@ std::string Notification::Dump() const ", postTime = " + std::to_string(postTime_) + ", sound = " + (sound_ == nullptr ? "nullptr" : sound_->ToString()) + ", vibrationStyle = [" + vibrationStyle + "]" + + ", updateTimer = " + std::to_string(updateTimerId_) + + ", finishTimer = " + std::to_string(finishTimerId_) + + ", archiveTimer = " + std::to_string(archiveTimerId_) + " }"; } + +uint64_t Notification::GetUpdateTimer() const +{ + return updateTimerId_; +} + +void Notification::SetUpdateTimer(uint64_t updateTimerId) +{ + updateTimerId_ = updateTimerId; +} + +uint64_t Notification::GetFinishTimer() const +{ + return finishTimerId_; +} + +void Notification::SetFinishTimer(uint64_t finishTimerId) +{ + finishTimerId_ = finishTimerId; +} + +void Notification::SetArchiveTimer(uint64_t archiveTimerId) +{ + archiveTimerId_ = archiveTimerId; +} + +uint64_t Notification::GetArchiveTimer() const +{ + return archiveTimerId_; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_bundle_option.cpp b/frameworks/ans/src/notification_bundle_option.cpp index bf97700770aff07661253eeeca2dcc0741a5df72..b5047f4667b00e82f50117479d0f90af62b4e598 100644 --- a/frameworks/ans/src/notification_bundle_option.cpp +++ b/frameworks/ans/src/notification_bundle_option.cpp @@ -94,5 +94,37 @@ bool NotificationBundleOption::ReadFromParcel(Parcel &parcel) return true; } + +bool NotificationBundleOption::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["uid"] = uid_; + jsonObject["bundleName"] = bundleName_; + return true; +} + +NotificationBundleOption *NotificationBundleOption::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + auto *pBundle = new (std::nothrow) NotificationBundleOption(); + if (pBundle == nullptr) { + ANS_LOGE("Failed to create bundle option instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("uid") != jsonEnd && jsonObject.at("uid").is_number_integer()) { + pBundle->uid_ = jsonObject.at("uid").get(); + } + + if (jsonObject.find("bundleName") != jsonEnd && jsonObject.at("bundleName").is_string()) { + pBundle->bundleName_ = jsonObject.at("bundleName").get(); + } + + return pBundle; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 2e1c717357798a52938bfc4501fc79548c48e418..bd450bedff34e17e6c4c509c50a1e2e3174f6597 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -251,6 +251,12 @@ ErrCode NotificationHelper::GetAllActiveNotifications( return DelayedSingleton::GetInstance()->GetAllActiveNotifications(key, notification); } +ErrCode NotificationHelper::GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request) +{ + return DelayedSingleton::GetInstance()->GetActiveNotificationByFilter(filter, request); +} + ErrCode NotificationHelper::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) { return DelayedSingleton::GetInstance()->IsAllowedNotify(bundleOption, allowed); @@ -386,10 +392,11 @@ ErrCode NotificationHelper::GetDoNotDisturbDate(const int32_t &userId, Notificat return DelayedSingleton::GetInstance()->GetDoNotDisturbDate(userId, doNotDisturbDate); } -ErrCode NotificationHelper::SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode NotificationHelper::SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { - return DelayedSingleton::GetInstance()->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + return DelayedSingleton::GetInstance()->SetEnabledForBundleSlot(bundleOption, + slotType, enabled, isForceControl); } ErrCode NotificationHelper::GetEnabledForBundleSlot( @@ -398,6 +405,11 @@ ErrCode NotificationHelper::GetEnabledForBundleSlot( return DelayedSingleton::GetInstance()->GetEnabledForBundleSlot(bundleOption, slotType, enabled); } +ErrCode NotificationHelper::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + return DelayedSingleton::GetInstance()->GetEnabledForBundleSlotSelf(slotType, enabled); +} + ErrCode NotificationHelper::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) { return DelayedSingleton::GetInstance()->SetSyncNotificationEnabledWithoutApp( @@ -415,9 +427,11 @@ ErrCode NotificationHelper::SetBadgeNumber(int32_t badgeNumber) return DelayedSingleton::GetInstance()->SetBadgeNumber(badgeNumber); } -ErrCode NotificationHelper::RegisterPushCallback(const sptr &pushCallback) +ErrCode NotificationHelper::RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) { - return DelayedSingleton::GetInstance()->RegisterPushCallback(pushCallback); + return DelayedSingleton::GetInstance()->RegisterPushCallback(pushCallback, + notificationCheckRequest); } ErrCode NotificationHelper::UnregisterPushCallback() diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 78da16866e2f56adb83efe2d170faa4e27af9033..edb0173f4d3e008f65f00de1d02c882e72323831 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -15,10 +15,15 @@ #include "notification_request.h" +#include "ans_inner_errors.h" #include "ans_image_util.h" #include "ans_log_wrapper.h" +#include "errors.h" +#include "notification_live_view_content.h" +#include "refbase.h" #include "want_agent_helper.h" #include "want_params_wrapper.h" +#include namespace OHOS { namespace Notification { @@ -45,6 +50,7 @@ const uint32_t NotificationRequest::COLOR_MASK {0xFF000000}; const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY {5}; const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3}; const std::size_t NotificationRequest::MAX_MESSAGE_USERS {1000}; +const std::string NotificationRequest::KEY_PREFIX {"ans_live_view"}; NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId) { @@ -249,6 +255,36 @@ int64_t NotificationRequest::GetAutoDeletedTime() const return autoDeletedTime_; } +void NotificationRequest::SetMaxUpdateTime(int64_t maxUpdateTime) +{ + maxUpdateTime_ = maxUpdateTime; +} + +int64_t NotificationRequest::GetMaxUpdateTime() const +{ + return maxUpdateTime_; +} + +void NotificationRequest::SetMaxFinishTime(int64_t maxFinishTime) +{ + maxFinishTime_ = maxFinishTime; +} + +int64_t NotificationRequest::GetMaxFinishTime() const +{ + return maxFinishTime_; +} + +void NotificationRequest::SetMaxArchiveTime(int64_t maxArchiveTime) +{ + maxArchiveTime_ = maxArchiveTime; +} + +int64_t NotificationRequest::GetMaxArchiveTime() const +{ + return maxArchiveTime_; +} + void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) { littleIcon_ = littleIcon; @@ -678,9 +714,8 @@ std::string NotificationRequest::Dump() ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + ", ownerBundleName = " + ownerBundleName_ + ", ownerUid = " + std::to_string(static_cast(ownerUid_)) + - ", groupName = " + groupName_ + - ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + - ", sortingKey = " + sortingKey_ + + ", groupName = " + groupName_ + ", statusBarText = " + statusBarText_ + ", label = " + label_ + + ", shortcutId = " + shortcutId_ + ", sortingKey = " + sortingKey_ + ", groupAlertType = " + std::to_string(static_cast(groupAlertType_)) + ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) + ", visiblenessType = " + std::to_string(static_cast(visiblenessType_)) + @@ -714,9 +749,10 @@ std::string NotificationRequest::Dump() ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") + ", distributedOptions = " + distributedOptions_.Dump() + ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") + - ", creatorUserId = " + std::to_string(creatorUserId_) + - ", ownerUserId = " + std::to_string(ownerUserId_) + + ", creatorUserId = " + std::to_string(creatorUserId_) + ", ownerUserId = " + std::to_string(ownerUserId_) + ", receiverUserId = " + std::to_string(receiverUserId_) + + ", maxUpdateTime = " + std::to_string(maxUpdateTime_) + + ", maxFinishTime = " + std::to_string(maxFinishTime_) + " }"; } @@ -1544,7 +1580,6 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) this->additionalParams_ = other.additionalParams_; this->littleIcon_ = other.littleIcon_; this->bigIcon_ = other.bigIcon_; - this->overlayIcon_ = other.overlayIcon_; this->notificationContent_ = other.notificationContent_; this->actionButtons_ = other.actionButtons_; @@ -1615,6 +1650,20 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const return true; } +void NotificationRequest::ConvertJsonToNumExt( + NotificationRequest *target, const nlohmann::json &jsonObject) +{ + const auto &jsonEnd = jsonObject.cend(); + + if (jsonObject.find("maxUpdateTime") != jsonEnd && jsonObject.at("maxUpdateTime").is_number_integer()) { + target->maxUpdateTime_ = jsonObject.at("maxUpdateTime").get(); + } + + if (jsonObject.find("maxFinishTime") != jsonEnd && jsonObject.at("maxFinishTime").is_number_integer()) { + target->maxFinishTime_ = jsonObject.at("maxFinishTime").get(); + } +} + void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject) { if (target == nullptr) { @@ -1659,6 +1708,9 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl if (jsonObject.find("badgeNumber") != jsonEnd && jsonObject.at("badgeNumber").is_number_integer()) { target->badgeNumber_ = jsonObject.at("badgeNumber").get(); } + + ConvertJsonToNumExt(target, jsonObject); + } } void NotificationRequest::ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject) @@ -1884,5 +1936,241 @@ bool NotificationRequest::ConvertJsonToNotificationFlags( return true; } + +bool NotificationRequest::IsCommonLiveView() const +{ + return (slotType_ == NotificationConstant::SlotType::LIVE_VIEW) && + (notificationContentType_ == NotificationContent::Type::LIVE_VIEW); +} + +ErrCode NotificationRequest::CheckVersion(const sptr &oldRequest) const +{ + auto content = notificationContent_->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveView = std::static_pointer_cast(oldContent); + + if (oldLiveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) { + return ERR_OK; + } + if (liveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) { + ANS_LOGE("Invalid version, creator bundle name %{public}s, id %{public}d, " + "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(), + GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion()); + return ERR_ANS_EXPIRED_NOTIFICATION; + } + if (oldLiveView->GetVersion() >= liveView->GetVersion()) { + ANS_LOGE("Live view has finished, creator bundle name %{public}s, id %{public}d, " + "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(), + GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion()); + return ERR_ANS_EXPIRED_NOTIFICATION; + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckNotificationRequest(const sptr &oldRequest) const +{ + if (!IsCommonLiveView()) { + return ERR_OK; + } + + using StatusType = NotificationLiveViewContent::LiveViewStatus; + auto content = notificationContent_->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + auto status = liveView->GetLiveViewStatus(); + if (oldRequest == nullptr) { + if (status != StatusType::LIVE_VIEW_CREATE) { + ANS_LOGE("Doesn't exist live view, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_NOTIFICATION_NOT_EXISTS; + } + return ERR_OK; + } + + if (!oldRequest->IsCommonLiveView()) { + ANS_LOGE("Invalid old request param, slot type %{public}d, content type %{public}d.", + oldRequest->GetSlotType(), oldRequest->GetNotificationType()); + return ERR_ANS_INVALID_PARAM; + } + + if (status == StatusType::LIVE_VIEW_CREATE) { + ANS_LOGW("Repeat create live view, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_REPEAT_CREATE; + } + + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveView = std::static_pointer_cast(oldContent); + auto oldStatus = oldLiveView->GetLiveViewStatus(); + if (oldStatus == StatusType::LIVE_VIEW_END) { + ANS_LOGW("Live view has finished, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_END_NOTIFICATION; + } + + return CheckVersion(oldRequest); +} + +void NotificationRequest::FillMissingParameters(const sptr &oldRequest) +{ + if (!IsCommonLiveView() || (oldRequest == nullptr)) { + return; + } + + maxUpdateTime_ = oldRequest->maxUpdateTime_; + maxFinishTime_ = oldRequest->maxFinishTime_; + if (autoDeletedTime_ == NotificationConstant::INVALID_AUTO_DELETE_TIME) { + autoDeletedTime_ = oldRequest->autoDeletedTime_; + } + if (wantAgent_ == nullptr) { + wantAgent_ = oldRequest->wantAgent_; + } + + auto content = notificationContent_->GetNotificationContent(); + auto newLiveViewContent = std::static_pointer_cast(content); + if (newLiveViewContent->GetLiveViewStatus() == + NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE) { + return; + } + auto newExtraInfo = newLiveViewContent->GetExtraInfo(); + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveViewContent = std::static_pointer_cast(oldContent); + auto oldExtraInfo = oldLiveViewContent->GetExtraInfo(); + if (newExtraInfo == nullptr) { + newLiveViewContent->SetExtraInfo(oldExtraInfo); + } else { + auto oldKeySet = oldExtraInfo->KeySet(); + for (const auto &key : oldKeySet) { + if (!newExtraInfo->HasParam(key)) { + newExtraInfo->SetParam(key, oldExtraInfo->GetParam(key)); + } + } + } + + auto newPicture = newLiveViewContent->GetPicture(); + auto oldPicture = oldLiveViewContent->GetPicture(); + for (const auto &pictureRecord : oldPicture) { + if (newPicture.find(pictureRecord.first) != newPicture.end()) { + continue; + } + newPicture[pictureRecord.first] = pictureRecord.second; + } +} + +std::string NotificationRequest::GenerateNotificationRequestKey( + int32_t creatorUserId, int32_t creatorUid, const std::string &label, int32_t notificationId) +{ + const char *keySpliter = "_"; + + std::stringstream stream; + stream << KEY_PREFIX << keySpliter << creatorUserId << keySpliter << + creatorUid << keySpliter<< label << keySpliter << notificationId; + return stream.str(); +} + +std::string NotificationRequest::GetKey() +{ + const char *keySpliter = "_"; + + std::stringstream stream; + stream << KEY_PREFIX << keySpliter << creatorUserId_ << keySpliter << + creatorUid_ << keySpliter << label_ << keySpliter << notificationId_; + return stream.str(); +} + +bool NotificationRequest::CheckImageOverSizeForPixelMap( + const std::shared_ptr &pixelMap, uint32_t maxSize) +{ + if (pixelMap == nullptr) { + return false; + } + + auto size = static_cast(pixelMap->GetByteCount()); + return size > maxSize; +} + +ErrCode NotificationRequest::CheckImageSizeForConverSation(std::shared_ptr &content) +{ + auto conversationalContent = std::static_pointer_cast(content); + auto picture = conversationalContent->GetMessageUser().GetPixelMap(); + if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message user exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto messages = conversationalContent->GetAllConversationalMessages(); + for (auto &msg : messages) { + if (!msg) { + continue; + } + auto img = msg->GetSender().GetPixelMap(); + if (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForPicture(std::shared_ptr &content) +{ + auto pictureContent = std::static_pointer_cast(content); + auto bigPicture = pictureContent->GetBigPicture(); + if (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) { + ANS_LOGE("The size of big picture in PictureContent exceeds limit"); + return ERR_ANS_PICTURE_OVER_SIZE; + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForLiveView(std::shared_ptr &content) +{ + auto liveViewContent = std::static_pointer_cast(content); + auto pictureMap = liveViewContent->GetPicture(); + for (const auto &pixelMapRecord : pictureMap) { + if (pixelMapRecord.second.empty()) { + ANS_LOGE("Picture key exist, but picture content is empty."); + return ERR_ANS_INVALID_PARAM; + } + if (pixelMapRecord.second.size() > MAX_LIVE_VIEW_ICON_NUM) { + ANS_LOGE("Picture key exist, but picture content is empty."); + return ERR_ANS_INVALID_PARAM; + } + for (const auto &pixelMap : pixelMapRecord.second) { + if (CheckImageOverSizeForPixelMap(pixelMap, MAX_ICON_SIZE)) { + ANS_LOGE("The size of big picture in PictureContent exceeds limit."); + return ERR_ANS_ICON_OVER_SIZE; + } + } + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForContent() const +{ + auto content = GetContent(); + if (content == nullptr) { + ANS_LOGE("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto basicContent = GetContent()->GetNotificationContent(); + if (basicContent == nullptr) { + ANS_LOGE("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto contentType = GetNotificationType(); + switch (contentType) { + case NotificationContent::Type::CONVERSATION: + return CheckImageSizeForConverSation(basicContent); + case NotificationContent::Type::PICTURE: + return CheckImageSizeForPicture(basicContent); + case NotificationContent::Type::LIVE_VIEW: + return CheckImageSizeForLiveView(basicContent); + default: + return ERR_OK; + } +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 3bef9e5d45d10402ec0eaeccae3b69e32ff98f0d..a7fea92480174a4ab90ea5cee547e0080113d76c 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -116,6 +116,15 @@ void NotificationSlot::SetType(NotificationConstant::SlotType type) SetEnableVibration(false); SetLevel(LEVEL_LOW); break; + case NotificationConstant::SlotType::LIVE_VIEW: + id_ = "LIVE_VIEW"; + SetName("LIVE_VIEW"); + SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); + SetSound(DEFAULT_NOTIFICATION_SOUND); + SetVibrationStyle(DEFAULT_NOTIFICATION_VIBRATION); + SetLevel(LEVEL_DEFAULT); + SetForceControl(true); + break; case NotificationConstant::SlotType::OTHER: id_ = "OTHER"; SetName("OTHER"); @@ -200,6 +209,16 @@ bool NotificationSlot::GetEnable() const return enabled_; } +void NotificationSlot::SetForceControl(bool isForceControl) +{ + isForceControl_ = isForceControl; +} + +bool NotificationSlot::GetForceControl() const +{ + return isForceControl_; +} + std::string NotificationSlot::Dump() const { return "NotificationSlot{ " diff --git a/frameworks/ans/src/notification_subscriber.cpp b/frameworks/ans/src/notification_subscriber.cpp index 8fc4bd693097a69334db7790770b2f9a7a675bb9..533ead3ae4a0356f3b0144d8dc3504a60e467c91 100644 --- a/frameworks/ans/src/notification_subscriber.cpp +++ b/frameworks/ans/src/notification_subscriber.cpp @@ -67,6 +67,15 @@ void NotificationSubscriber::SubscriberImpl::OnConsumed( std::make_shared(*notification), std::make_shared(*notificationMap)); } +void NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + for (auto notification : notifications) { + OnConsumed(notification, notificationMap); + } +} + void NotificationSubscriber::SubscriberImpl::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { @@ -80,7 +89,6 @@ void NotificationSubscriber::SubscriberImpl::OnCanceled( } } - void NotificationSubscriber::SubscriberImpl::OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) { diff --git a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp index 7139936f3e5fef7d2c501f58c560a7663a6cdd9d..5adbb7e27a13431c9ecea5a79c441c26cda0732d 100644 --- a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp +++ b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp @@ -131,5 +131,23 @@ HWTEST_F(NotificationBundleOptionTest, ReadFromParcel_00001, Function | SmallTes auto rrc = std::make_shared(bundleName, uid); EXPECT_EQ(rrc->ReadFromParcel(parcel), false); } + +/** + * @tc.name: JsonConvert_00001 + * @tc.desc: Test json convert + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationBundleOptionTest, JsonConvert_00001, Function | SmallTest | Level1) +{ + std::string bundleName = "BundleName"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + nlohmann::json jsonObject; + EXPECT_TRUE(rrc->ToJson(jsonObject)); + auto *rrcNew = rrc->FromJson(jsonObject); + EXPECT_EQ(rrcNew->GetBundleName(), rrc->GetBundleName()); + EXPECT_EQ(rrcNew->GetUid(), rrc->GetUid()); } -} \ No newline at end of file +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index 0edf9670f9e8cd38a6492144faba92c44565ad4d..4075e91233783d05c70aea32e9a2abbbc4400ac4 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -982,8 +982,9 @@ HWTEST_F(NotificationHelperTest, SetEnabledForBundleSlot_00001, Function | Small NotificationBundleOption bundleOption; NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; bool enabled = true; + bool isForceControl = false; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ErrCode ret = notificationHelper.SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp index 72362ed60ffb572f8b8a9a0eb5f99e438fd6b1a0..dd5424be9a3ef1c683a8ac7abac095c299ff9368 100644 --- a/frameworks/ans/test/unittest/notification_test.cpp +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -270,12 +270,13 @@ HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1) "inProgress = false, groupOverview = false, isRemoveAllowed = true, progressIndeterminate = false, " "unremovable = false, floatingIcon = false, onlyLocal = false, permitted = true, " "isAgent = false, removalWantAgent = null, maxScreenWantAgent = null, additionalParams = null, " - "littleIcon = null, bigIcon = null, notificationContent = null, " + "littleIcon = null, bigIcon = null, overlayIcon = null, notificationContent = null, " "notificationTemplate = null, actionButtons = empty, messageUsers = empty, " "userInputHistory = empty, distributedOptions = NotificationDistributedOptions" "{ isDistributed = true, devicesSupportDisplay = [], devicesSupportOperate = [] }, " - "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1 }, " - "postTime = 0, sound = nullptr, vibrationStyle = [] }"; + "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1, " + "maxUpdateTime = 0, maxFinishTime = 0 }, postTime = 0, sound = nullptr, vibrationStyle = [], " + "updateTimer = 0, finishTimer = 0, archiveTimer = 0 }"; EXPECT_EQ(rrc->Dump(), ret); } @@ -518,5 +519,34 @@ HWTEST_F(NotificationTest, Marshalling_00003, Function | SmallTest | Level1) EXPECT_EQ(rrc->Marshalling(parcel), true); } + + +/** + * @tc.name: GetUpdateTimer_00001 + * @tc.desc: Test get update timer. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetUpdateTimer_00001, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + auto rrc = std::make_shared(request); + rrc->SetUpdateTimer(1); + EXPECT_EQ(rrc->GetUpdateTimer(), 1); +} + +/** + * @tc.name: GetFinishTimer_00001 + * @tc.desc: Test get finish timer. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetFinishTimer_00001, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + auto rrc = std::make_shared(request); + rrc->SetFinishTimer(1); + EXPECT_EQ(rrc->GetFinishTimer(), 1); } -} \ No newline at end of file +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index 82c4900ac90743f8660d4cfcb972e74d7cdcc9d8..435f1d1d23ecc0424f5c0055e802df55afb11339 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -31,6 +31,7 @@ constexpr uint32_t MAX_ACTIVE_NUM_PERSECOND = 10; constexpr size_t MAX_SLOT_NUM = 5; constexpr uint32_t MAX_ICON_SIZE = 50 * 1024; constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; +constexpr uint32_t MAX_LIVE_VIEW_ICON_NUM = 5; constexpr bool SUPPORT_DO_NOT_DISTRUB = true; constexpr uint32_t SYSTEM_SERVICE_UID = 1000; constexpr uint32_t MAX_CONVERSATIONAL_NUM = 10000; diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index a58d2237f8bbb84b45dd35349a13d56067bf56e1..b8301d2d671a1bb047206b34a4b39ee8ebbe56bb 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -179,6 +179,20 @@ public: virtual ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) = 0; + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param notificationId Indicates the id of the notification to get the extra info by extra info keys. + * @param extraInfoKeys + * @param extraInfo + * @return + */ + virtual ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) = 0; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -642,9 +656,10 @@ public: */ virtual ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) = 0; virtual ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) = 0; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) = 0; virtual ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) = 0; + virtual ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) = 0; /** * @brief Obtains specific datas via specified dump option. @@ -690,7 +705,8 @@ public: * @param pushCallback PushCallBack. * @return Returns register PushCallback result. */ - virtual ErrCode RegisterPushCallback(const sptr &pushCallback) = 0; + virtual ErrCode RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) = 0; /** * @brief Unregister Push Callback. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 5c91814e3cc2cd707ba793f54c8e7ce474c7636d..c45c224c28c15eff0995be8f0edbb614d14bf6d6 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -19,6 +19,7 @@ #include "ans_manager_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_proxy.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -166,6 +167,21 @@ public: ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) override; + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param notificationId Indicates the id of the notification to get the extra info by extra info keys. + * @param label + * @param extraInfoKeys + * @param extraInfo + * @return + */ + ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + const std::vector extraInfoKeys, sptr &request) override; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -629,9 +645,10 @@ public: */ ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; /** * @brief Obtains specific datas via specified dump option. @@ -675,9 +692,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr &pushCallback) override; + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override; /** * @brief Unregister Push Callback. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 4da073244fcfaea5436246f5c71edbe07c0d0d58..98545d6c4263c0fe9f36ed8a1ba0333b43d059ad 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -182,6 +182,10 @@ public: virtual ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) override; + virtual ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) override; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -644,9 +648,10 @@ public: */ virtual ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; virtual ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; virtual ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; + virtual ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; /** * @brief Obtains specific datas via specified dump option. @@ -690,9 +695,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr& pushCallback) override; + ErrCode RegisterPushCallback(const sptr& pushCallback, + const sptr& notificationCheckRequest) override; /** * @brief Unregister Push Callback. @@ -720,6 +727,7 @@ private: ErrCode HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetNotificationAgent(MessageParcel &data, MessageParcel &reply); ErrCode HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply); @@ -773,6 +781,7 @@ private: ErrCode HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply); ErrCode HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); ErrCode HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index fff7608eca9991a3447f356ef56653ef19be30b4..fcad82aee0ba2aec886987e8faffe963d8a8b4b1 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -23,6 +23,7 @@ #include "ans_manager_interface.h" #include "notification_subscriber.h" #include "notification_local_live_view_subscriber.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -468,6 +469,16 @@ public: ErrCode GetAllActiveNotifications( const std::vector key, std::vector> ¬ification); + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * @param filter + * @param extraInfo + * @return + */ + ErrCode GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request); + /** * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies * the current application, no permission is required for calling this method. If bundle specifies another @@ -766,10 +777,11 @@ public: * @param bundleOption Indicates the bundle name and uid of the application. * @param slotType Indicates type of slot. * @param enable the type of slot enabled. + * @param isForceControl Indicates whether the slot is affected by the notification switch. * @return Returns get slot number by bundle result. */ - ErrCode SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled); + ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); /** * Obtains whether the application slot is enabled. @@ -782,6 +794,15 @@ public: ErrCode GetEnabledForBundleSlot( const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); + /** + * Obtains whether the current application slot is enabled. + * + * @param slotType Indicates type of slot. + * @param enable the type of slot enabled to get. + * @return Returns get enabled result. + */ + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + /** * @brief Obtains specific datas via specified dump option. * @@ -824,9 +845,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr &pushCallback); + ErrCode RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest); /** * @brief Unregister Push Callback. @@ -851,24 +874,6 @@ private: */ bool CanPublishMediaContent(const NotificationRequest &request) const; - /** - * @brief Checks whether the picture size exceeds the limit in PixelMap. - * - * @param pixelMap Indicates the specified image. - * @param maxSize Indicates the limit size. - * @return Returns true if the limit size is exceeded; returns false otherwise. - */ - bool CheckImageOverSizeForPixelMap( - const std::shared_ptr &pixelMap, uint32_t maxSize); - - /** - * @brief Checks whether the picture size exceeds the limit in NotificationRequest's content. - * - * @param request Indicates the specified request. - * @return Returns the ErrCode. - */ - ErrCode CheckImageSizeForContent(const NotificationRequest &request); - /** * @brief Checks whether the picture size exceeds the limit. * @@ -885,6 +890,14 @@ private: */ bool IsNonDistributedNotificationType(const NotificationContent::Type &type); + /** + * @brief Checks if the LiveViewContent can be published. + * + * @param request Indicates the specified request. + * @return Returns true if the MediaContent can be published; returns false otherwise. + */ + bool CanPublishLiveViewContent(const NotificationRequest &request) const; + private: std::mutex mutex_; sptr ansManagerProxy_; diff --git a/frameworks/core/include/ans_subscriber_interface.h b/frameworks/core/include/ans_subscriber_interface.h index 91e868f79580e76e3f6bfe1d7abe696e5d43d2b2..5ee72c940b4682798bb89f436720d3768b7f8f95 100644 --- a/frameworks/core/include/ans_subscriber_interface.h +++ b/frameworks/core/include/ans_subscriber_interface.h @@ -56,6 +56,9 @@ public: virtual void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) = 0; + virtual void OnConsumedList( + const std::vector> ¬ifications, const sptr ¬ificationMap) = 0; + /** * @brief The callback function on a notification canceled. * diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h index 7fa46b9f27177cfb3e821f00b93c88b570f476c3..881c4bdb14bf8ae25a4025dce16e2f240cce1e1a 100644 --- a/frameworks/core/include/ans_subscriber_proxy.h +++ b/frameworks/core/include/ans_subscriber_proxy.h @@ -48,6 +48,9 @@ public: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + /** * @brief The callback function on a notification canceled. * diff --git a/frameworks/core/include/ans_subscriber_stub.h b/frameworks/core/include/ans_subscriber_stub.h index 5e03e1e10cd31fa73af6b9c5e86941a7706bd705..b84b5e7a9be88c3ac24d2e06cb3d5501a68a5d0b 100644 --- a/frameworks/core/include/ans_subscriber_stub.h +++ b/frameworks/core/include/ans_subscriber_stub.h @@ -58,6 +58,9 @@ public: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + /** * @brief The callback function on a notification canceled. * @@ -105,6 +108,7 @@ private: ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 78f24ac5deb76ac191d1ecb0961967d5584d4087..c0a5696bb326a4077e1a265dce6e847475253a82 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -43,6 +43,7 @@ namespace Notification { GET_ACTIVE_NOTIFICATION_NUMS, GET_ALL_ACTIVE_NOTIFICATIONS, GET_SPECIAL_ACTIVE_NOTIFICATIONS, + GET_ACTIVE_NOTIFICATION_BY_FILTER, SET_NOTIFICATION_AGENT, GET_NOTIFICATION_AGENT, CAN_PUBLISH_AS_BUNDLE, @@ -99,6 +100,7 @@ namespace Notification { GET_DO_NOT_DISTURB_DATE_BY_USER, SET_ENABLED_FOR_BUNDLE_SLOT, GET_ENABLED_FOR_BUNDLE_SLOT, + GET_ENABLED_FOR_BUNDLE_SLOT_SELF, SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, SET_BADGE_NUMBER, @@ -109,6 +111,7 @@ namespace Notification { ON_DISCONNECTED, ON_CONSUMED, // Obsolete ON_CONSUMED_MAP, + ON_CONSUMED_LIST_MAP, ON_CANCELED_MAP, ON_CANCELED_LIST_MAP, ON_UPDATED, diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 50666b0c84d02e88da7ef09dbc0d4cbc29c0380a..478dd0b01f15b2505d6eb739069df28622be335c 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -44,6 +44,11 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptrIsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[Publish] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; @@ -506,6 +511,67 @@ ErrCode AnsManagerProxy::GetSpecialActiveNotifications( return result; } +ErrCode AnsManagerProxy::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + const std::vector extraInfoKeys, sptr &request) +{ + if (bundleOption == nullptr) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(bundleOption)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write bundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(label)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteStringVector(extraInfoKeys)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail:: write extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: transact ErrCode=%{public}d", result); + return result; + } + + request = reply.ReadParcelable(); + if (request == nullptr) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: read request is nullptr."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::SetNotificationAgent(const std::string &agent) { if (agent.empty()) { @@ -622,6 +688,11 @@ ErrCode AnsManagerProxy::PublishAsBundle( } MessageParcel data; + if (notification->IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[PublishAsBundle] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; @@ -1198,7 +1269,8 @@ ErrCode AnsManagerProxy::SetNotificationsEnabledForAllBundles(const std::string MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE, option, data, reply); + ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE, + option, data, reply); if (result != ERR_OK) { ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: transact ErrCode=%{public}d", result); return ERR_ANS_TRANSACT_FAILED; @@ -2468,8 +2540,8 @@ ErrCode AnsManagerProxy::GetDoNotDisturbDate(const int32_t &userId, sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsManagerProxy::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { if (bundleOption == nullptr) { ANS_LOGE("[SetEnabledForBundleSlot] fail: bundle is empty."); @@ -2497,6 +2569,11 @@ ErrCode AnsManagerProxy::SetEnabledForBundleSlot( return ERR_ANS_PARCELABLE_FAILED; } + if (!data.WriteBool(isForceControl)) { + ANS_LOGE("[SetEnabledForBundleSlot] fail: write isForceControl failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; ErrCode result = InnerTransact(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply); @@ -2558,6 +2635,40 @@ ErrCode AnsManagerProxy::GetEnabledForBundleSlot( return result; } +ErrCode AnsManagerProxy::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(slotType)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail:: write slotType failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadBool(enabled)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read enable failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) { MessageParcel data; @@ -2695,7 +2806,8 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } -ErrCode AnsManagerProxy::RegisterPushCallback(const sptr &pushCallback) +ErrCode AnsManagerProxy::RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) { MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { @@ -2708,6 +2820,11 @@ ErrCode AnsManagerProxy::RegisterPushCallback(const sptr &pushCal return ERR_ANS_PARCELABLE_FAILED; } + if (!data.WriteParcelable(notificationCheckRequest)) { + ANS_LOGE("write notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + MessageParcel reply; MessageOption option = { MessageOption::TF_SYNC }; ErrCode result = InnerTransact(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK, option, data, reply); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 47254fb7ca9a9af59bc8ad0f699761ceac6369e9..b412ab0dfe3013cd1cd5027683fc317e69597dfb 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -75,6 +75,9 @@ const std::map bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector extraInfoKeys; + if (!data.ReadStringVector(&extraInfoKeys)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr request; + ErrCode result = GetActiveNotificationByFilter(bundleOption, notificationId, label, extraInfoKeys, request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(request)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerStub::HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply) { std::string agent; @@ -1694,7 +1740,13 @@ ErrCode AnsManagerStub::HandleSetEnabledForBundleSlot(MessageParcel &data, Messa return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled); + bool isForceControl = false; + if (!data.ReadBool(isForceControl)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1733,6 +1785,30 @@ ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, Messa return ERR_OK; } +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply) +{ + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlotSelf(slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + ErrCode AnsManagerStub::HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) { int32_t userId = SUBSCRIBE_USER_INIT; @@ -1806,7 +1882,13 @@ ErrCode AnsManagerStub::HandleRegisterPushCallback(MessageParcel &data, MessageP return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = RegisterPushCallback(pushCallBack); + sptr notificationCheckRequest = data.ReadParcelable(); + if (notificationCheckRequest == nullptr) { + ANS_LOGE("fail: read notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterPushCallback(pushCallBack, notificationCheckRequest); if (!reply.WriteInt32(result)) { ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1915,6 +1997,14 @@ ErrCode AnsManagerStub::GetSpecialActiveNotifications( return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationByFilter called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::SetNotificationAgent(const std::string &agent) { ANS_LOGE("AnsManagerStub::SetNotificationAgent called!"); @@ -2239,8 +2329,8 @@ ErrCode AnsManagerStub::GetDoNotDisturbDate(const int32_t &userId, sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsManagerStub::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { ANS_LOGE("AnsManagerStub::SetEnabledForBundleSlot called!"); return ERR_INVALID_OPERATION; @@ -2253,6 +2343,11 @@ ErrCode AnsManagerStub::GetEnabledForBundleSlot( return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlotSelf called!"); + return ERR_INVALID_OPERATION; +} ErrCode AnsManagerStub::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) @@ -2279,7 +2374,8 @@ ErrCode AnsManagerStub::SetBadgeNumber(int32_t badgeNumber) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RegisterPushCallback(const sptr& pushCallback) +ErrCode AnsManagerStub::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) { ANS_LOGE("RegisterPushCallback called!"); return ERR_INVALID_OPERATION; diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 38375666213aa5138a5efc1d572848635e78976d..44b3f3f6edcb6844f57c88723d9afc01aedaf4fd 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -143,6 +143,11 @@ ErrCode AnsNotification::PublishNotification(const std::string &label, const Not return ERR_ANS_INVALID_PARAM; } + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + ErrCode checkErr = CheckImageSize(request); if (checkErr != ERR_OK) { ANS_LOGE("The size of one picture exceeds the limit"); @@ -625,6 +630,28 @@ ErrCode AnsNotification::GetAllActiveNotifications( return ansManagerProxy_->GetSpecialActiveNotifications(key, notification); } +ErrCode AnsNotification::GetActiveNotificationByFilter(const LiveViewFilter &filter, + sptr &request) +{ + if (filter.bundle.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("Bundle name %{public}s, uid %{public}d, notification id %{public}d, label %{public}s.", + filter.bundle.GetBundleName().c_str(), filter.bundle.GetUid(), filter.notificationKey.id, + filter.notificationKey.label.c_str()); + + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(filter.bundle)); + return ansManagerProxy_->GetActiveNotificationByFilter(bo, filter.notificationKey.id, filter.notificationKey.label, + filter.extraInfoKeys, request); +} + ErrCode AnsNotification::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) { if (bundleOption.GetBundleName().empty()) { @@ -1050,90 +1077,60 @@ bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) return true; } -bool AnsNotification::CheckImageOverSizeForPixelMap(const std::shared_ptr &pixelMap, uint32_t maxSize) +bool AnsNotification::CanPublishLiveViewContent(const NotificationRequest &request) const { - if (!pixelMap) { - return false; - } - - uint32_t size = static_cast(pixelMap->GetByteCount()); - if (size > maxSize) { + if (!request.IsCommonLiveView()) { return true; } - return false; -} -ErrCode AnsNotification::CheckImageSizeForContent(const NotificationRequest &request) -{ - auto content = request.GetContent(); - if (!content) { - ANS_LOGW("Invalid content in NotificationRequest"); - return ERR_OK; + if (request.GetContent() == nullptr) { + ANS_LOGE("Failed to publish notification with null content."); + return false; } - auto basicContent = request.GetContent()->GetNotificationContent(); - if (!basicContent) { - ANS_LOGW("Invalid content in NotificationRequest"); - return ERR_OK; + auto content = request.GetContent()->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + if (liveView == nullptr) { + ANS_LOGE("Failed to get live view content."); + return false; } - auto contentType = request.GetNotificationType(); - switch (contentType) { - case NotificationContent::Type::CONVERSATION: { - auto conversationalContent = std::static_pointer_cast(basicContent); - - auto picture = conversationalContent->GetMessageUser().GetPixelMap(); - if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) { - ANS_LOGE("The size of picture in ConversationalContent's message user exceeds limit"); - return ERR_ANS_ICON_OVER_SIZE; - } - - auto messages = conversationalContent->GetAllConversationalMessages(); - for (auto &msg : messages) { - if (!msg) { - continue; - } - - auto img = msg->GetSender().GetPixelMap(); - if (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) { - ANS_LOGE("The size of picture in ConversationalContent's message exceeds limit"); - return ERR_ANS_ICON_OVER_SIZE; - } - } - break; - } - case NotificationContent::Type::PICTURE: { - auto pictureContent = std::static_pointer_cast(basicContent); + auto status = liveView->GetLiveViewStatus(); + if (status >= NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT) { + ANS_LOGE("Invalid status %{public}u.", status); + return false; + } - auto bigPicture = pictureContent->GetBigPicture(); - if (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) { - ANS_LOGE("The size of big picture in PictureContent exceeds limit"); - return ERR_ANS_PICTURE_OVER_SIZE; - } - break; - } - default: - break; + auto extraInfo = liveView->GetExtraInfo(); + if ((extraInfo == nullptr) && (status != NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END)) { + ANS_LOGE("Extrainfo is empty."); + return false; } - return ERR_OK; + return true; } ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) { auto littleIcon = request.GetLittleIcon(); - if (CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { ANS_LOGE("The size of little icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } auto bigIcon = request.GetBigIcon(); - if (CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of big icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto overlayIcon = request.GetOverlayIcon(); + if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { ANS_LOGE("The size of big icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } - ErrCode err = CheckImageSizeForContent(request); + ErrCode err = request.CheckImageSizeForContent(); if (err != ERR_OK) { return err; } @@ -1144,7 +1141,7 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) continue; } auto icon = btn->GetIcon(); - if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { ANS_LOGE("The size of icon in ActionButton exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } @@ -1156,7 +1153,7 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) continue; } auto icon = user->GetPixelMap(); - if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { ANS_LOGE("The size of picture in MessageUser exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } @@ -1177,7 +1174,9 @@ ErrCode AnsNotification::IsSupportTemplate(const std::string &templateName, bool bool AnsNotification::IsNonDistributedNotificationType(const NotificationContent::Type &type) { - return ((type == NotificationContent::Type::CONVERSATION) || (type == NotificationContent::Type::PICTURE)); + return ((type == NotificationContent::Type::CONVERSATION) || + (type == NotificationContent::Type::PICTURE) || + (type == NotificationContent::Type::LIVE_VIEW)); } ErrCode AnsNotification::IsAllowedNotify(const int32_t &userId, bool &allowed) @@ -1275,8 +1274,8 @@ ErrCode AnsNotification::GetDoNotDisturbDate(const int32_t &userId, Notification return ret; } -ErrCode AnsNotification::SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsNotification::SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (bundleOption.GetBundleName().empty()) { @@ -1290,7 +1289,7 @@ ErrCode AnsNotification::SetEnabledForBundleSlot( } sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); - return ansManagerProxy_->SetEnabledForBundleSlot(bo, slotType, enabled); + return ansManagerProxy_->SetEnabledForBundleSlot(bo, slotType, enabled, isForceControl); } ErrCode AnsNotification::GetEnabledForBundleSlot( @@ -1310,6 +1309,16 @@ ErrCode AnsNotification::GetEnabledForBundleSlot( return ansManagerProxy_->GetEnabledForBundleSlot(bo, slotType, enabled); } +ErrCode AnsNotification::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetEnabledForBundleSlotSelf fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->GetEnabledForBundleSlotSelf(slotType, enabled); +} + ErrCode AnsNotification::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) { @@ -1361,14 +1370,15 @@ ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) return ansManagerProxy_->SetBadgeNumber(badgeNumber); } -ErrCode AnsNotification::RegisterPushCallback(const sptr& pushCallback) +ErrCode AnsNotification::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) { if (!GetAnsManagerProxy()) { ANS_LOGE("RegisterPushCallback fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - return ansManagerProxy_->RegisterPushCallback(pushCallback); + return ansManagerProxy_->RegisterPushCallback(pushCallback, notificationCheckRequest); } ErrCode AnsNotification::UnregisterPushCallback() diff --git a/frameworks/core/src/ans_subscriber_proxy.cpp b/frameworks/core/src/ans_subscriber_proxy.cpp index 8a7a1e00344e46b4c75c3db91b993cefd4578df2..9073bcb998cd3c2a9d3e1240214783ae779c68df 100644 --- a/frameworks/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_proxy.cpp @@ -96,6 +96,12 @@ void AnsSubscriberProxy::OnConsumed( } MessageParcel data; + if (notification->GetNotificationRequest().IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + ANS_LOGE("[OnConsumed] fail: set max capacity failed."); + return; + } + } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnConsumed] fail: write interface token failed."); return; @@ -127,6 +133,47 @@ void AnsSubscriberProxy::OnConsumed( } } +void AnsSubscriberProxy::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{ + ANS_LOGI("Start consumed list in proxy."); + if (notifications.empty() || notificationMap == nullptr) { + ANS_LOGE("Invalid notification to consumed."); + return; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { + ANS_LOGE("Write interface token failed."); + return; + } + + if (!WriteParcelableVector(notifications, data)) { + ANS_LOGE("Write notifications failed"); + return; + } + + if (!data.WriteBool(notificationMap != nullptr)) { + ANS_LOGE("Write existMap failed"); + return; + } + + if (notificationMap != nullptr) { + if (!data.WriteParcelable(notificationMap)) { + ANS_LOGE("Write notificationMap failed"); + return; + } + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("Transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + void AnsSubscriberProxy::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { @@ -136,6 +183,12 @@ void AnsSubscriberProxy::OnCanceled( } MessageParcel data; + if (notification->GetNotificationRequest().IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + ANS_LOGE("[OnCanceled] fail: set max capacity failed."); + return; + } + } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnCanceled] fail: write interface token failed."); return; diff --git a/frameworks/core/src/ans_subscriber_stub.cpp b/frameworks/core/src/ans_subscriber_stub.cpp index 4648d80cc9bd3130cd0c806bfb32f58286dcad4b..9ea73e10f596428d3ac39d4530a1f8df65c7ada8 100644 --- a/frameworks/core/src/ans_subscriber_stub.cpp +++ b/frameworks/core/src/ans_subscriber_stub.cpp @@ -32,6 +32,8 @@ AnsSubscriberStub::AnsSubscriberStub() std::bind(&AnsSubscriberStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CONSUMED_MAP, std::bind(&AnsSubscriberStub::HandleOnConsumedMap, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP, + std::bind(&AnsSubscriberStub::HandleOnConsumedListMap, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CANCELED_MAP, std::bind(&AnsSubscriberStub::HandleOnCanceledMap, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CANCELED_LIST_MAP, @@ -116,6 +118,35 @@ ErrCode AnsSubscriberStub::HandleOnConsumedMap(MessageParcel &data, MessageParce return ERR_OK; } +ErrCode AnsSubscriberStub::HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGI("Start handle notifications in consumed list."); + + std::vector> notifications; + if (!ReadParcelableVector(notifications, data)) { + ANS_LOGE("read notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool existMap = false; + if (!data.ReadBool(existMap)) { + ANS_LOGE("read existMap failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notificationMap = nullptr; + if (existMap) { + notificationMap = data.ReadParcelable(); + if (notificationMap == nullptr) { + ANS_LOGE("read NotificationSortingMap failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + OnConsumedList(notifications, notificationMap); + return ERR_OK; +} + ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply) { sptr notification = data.ReadParcelable(); @@ -262,6 +293,10 @@ void AnsSubscriberStub::OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) {} +void AnsSubscriberStub::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{} + void AnsSubscriberStub::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) {} diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index c85c8cf9083f615979c28e72b2a6597a09545692..86958bc8dff2601e6929b3947b7574b82a211ea4 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -6561,7 +6561,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0100, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -6581,7 +6582,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0200, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = nullptr; - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); } @@ -6603,7 +6605,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0300, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_OK, result); } @@ -6624,7 +6627,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0400, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false);; EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -6646,7 +6650,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0500, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, + NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index d10275d0fb86b3e2189bac98ceeef6272cda37bc..f03a9102f10c2adffa91d4b219acc375f1cbb89f 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -3158,11 +3158,13 @@ HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot01, Function | SmallTe sptr bundleOption = new NotificationBundleOption(); int32_t type = 4; bool enabled = true; + bool isForceControl = false; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); data.WriteStrongParcelable(bundleOption); data.WriteInt32(type); data.WriteBool(enabled); + data.WriteBool(isForceControl); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)ERR_OK); @@ -4098,8 +4100,9 @@ HWTEST_F(AnsManagerStubTest, SetEnabledForBundleSlot01, Function | SmallTest | L sptr bundleOption = new NotificationBundleOption(); NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; bool enabled = true; + bool isForceControl = false; - ErrCode result = ansManagerStub_->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ErrCode result = ansManagerStub_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); } diff --git a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp index 9aaf4e2e2af75fa5b055531d43e8d73c43bb87a3..cf9e8fe2c2c388ff5ba6fa1089a1780689d9c295 100644 --- a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp @@ -318,8 +318,8 @@ HWTEST_F(AnsNotificationUnitAnnexTest, CheckImageSizeForContent_0100, Function | { NotificationRequest request; request.SetContent(nullptr); - - ErrCode ret = ans_->CheckImageSizeForContent(request); + + ErrCode ret = request.CheckImageSizeForContent(); EXPECT_EQ(ret, ERR_OK); } } // namespace Notification diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index df43fc5f23688bbfce33a81679d755c4f41b8609..7b493ad7f41d88c60d2d783605f80ffe7fe1b147 100755 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -393,7 +393,7 @@ public: } ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override { return ERR_ANS_INVALID_PARAM; } @@ -404,6 +404,11 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) override { @@ -425,7 +430,8 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode RegisterPushCallback(const sptr &pushCallback) override + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override { return ERR_ANS_INVALID_PARAM; } @@ -435,6 +441,13 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, + const int32_t notificationId, const std::string &label, std::vector extraInfoKeys, + const sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) override { @@ -530,7 +543,8 @@ HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0100, Function | Medium EXPECT_NE(ansNotification, nullptr); sptr pushCallback = nullptr; MockGetAnsManagerProxy(false); - ErrCode ret = ansNotification->RegisterPushCallback(pushCallback); + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ErrCode ret = ansNotification->RegisterPushCallback(pushCallback, checkRequest); EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); } @@ -548,7 +562,8 @@ HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0200, Function | Medium sptr pushCallback = nullptr; MockGetAnsManagerProxy(true); ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - ansNotification->RegisterPushCallback(pushCallback); + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ansNotification->RegisterPushCallback(pushCallback, checkRequest); } /* diff --git a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp index c3e07352b6315a5ee0e3c9a810e3e04da15ba76e..6a8486d29d0b715406a825e6e4767211039b2411 100644 --- a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp @@ -689,7 +689,8 @@ HWTEST_F(AnsNotificationUnitTest, SetEnabledForBundleSlot_0100, Function | Mediu bundleOption.SetBundleName(bundleName); NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; bool enabled = true; - ErrCode ret1 = ans_->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + bool isForceControl = false; + ErrCode ret1 = ans_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); ErrCode ret2 = ans_->GetEnabledForBundleSlot(bundleOption, slotType, enabled); EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp index 3952ea93f815c4972ccbd3687f3263d96eb51249..ea83edc890e15da3a4a99d345b8dfa839bd9b803 100644 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "notification_request.h" #include #define private public @@ -154,10 +155,15 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -176,10 +182,15 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -218,14 +229,102 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0700, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0700, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); proxy->OnConsumed(notification, nullptr); } +/* + * @tc.name: OnConsumedList_0100 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + proxy->OnConsumedList(notifications, nullptr); +} + +/* + * @tc.name: OnConsumedList_0200 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); + std::vector> notifications; + notifications.emplace_back(notification); + proxy->OnConsumedList(notifications, nullptr); +} + +/* + * @tc.name: OnConsumedList_0300 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + +/* + * @tc.name: OnConsumedList_0400 + * @tc.desc: 1.Test OnConsumedList function and notifications is not empty + * 2.notificationMap is not nullptr + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); + std::vector> notifications; + notifications.emplace_back(notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + /* * @tc.name: OnCanceled_0400 * @tc.desc: test AnsSubscriberProxy's OnCanceled function @@ -241,7 +340,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -264,7 +365,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -308,7 +411,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0700, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); int32_t deleteReason = 0; proxy->OnCanceled(notification, nullptr, deleteReason); diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn index 79476454fddf6d974c7677f9681900bfb48f618d..fc967ba2c6e7aa0bc28e28a684c5a32713c096c5 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn @@ -19,11 +19,18 @@ module_output_path = "${component_name}/unittest" ohos_unittest("ans_subscriber_stub_test") { module_out_path = module_output_path - include_dirs = [ "${core_path}/include" ] + include_dirs = [ + "${core_path}/include", + "../mock/", + ] sources = [ "ans_subscriber_stub_unit_test.cpp" ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp index 05692edf5a7bdfbd0a37a6b0b9c8d204e9d204c9..03b548d104417a4bf6ead67710972f78e4f51ae2 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp @@ -18,6 +18,7 @@ #define private public #define protected public #include "ans_subscriber_stub.h" +#include "ans_subscriber_proxy.h" #include "ans_inner_errors.h" #include "ans_notification.h" #undef private @@ -26,6 +27,7 @@ #include "message_option.h" #include "message_parcel.h" #include "parcel.h" +#include "mock_i_remote_object.h" using namespace testing; using namespace testing::ext; @@ -239,6 +241,103 @@ HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap04, Function | SmallTest EXPECT_EQ(res, ERR_OK); } +/** +* @tc.name: HandleOnConsumedListMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap04 +* @tc.desc: test HandleOnConsumedListMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.name: HandleOnCanceledMap01 * @tc.desc: test notification failed diff --git a/frameworks/js/napi/src/manager/napi_get_active.cpp b/frameworks/js/napi/src/manager/napi_get_active.cpp index 9efd72f25c295af2a9c7ee7e9549c3fe0e566716..9df4b7d88bf706e361e69048d6e0961048f13678 100644 --- a/frameworks/js/napi/src/manager/napi_get_active.cpp +++ b/frameworks/js/napi/src/manager/napi_get_active.cpp @@ -410,6 +410,8 @@ void AsyncGetLiveViewExecute(napi_env env, void *data) auto asyncLiveViewCallBackInfo = static_cast(data); if (asyncLiveViewCallBackInfo) { + asyncLiveViewCallBackInfo->info.errorCode = NotificationHelper::GetActiveNotificationByFilter( + asyncLiveViewCallBackInfo->filter, asyncLiveViewCallBackInfo->notificationRequest); } } diff --git a/frameworks/js/napi/src/manager/napi_push.cpp b/frameworks/js/napi/src/manager/napi_push.cpp index c329811230e5bcc9d650dbaf71807164bb2a0604..d841af5a671d3b29609216446b07b600828d4ab0 100644 --- a/frameworks/js/napi/src/manager/napi_push.cpp +++ b/frameworks/js/napi/src/manager/napi_push.cpp @@ -106,7 +106,7 @@ napi_value NapiPush::OnRegisterPushCallback(napi_env env, const napi_callback_in } jsPushCallBack_->SetJsPushCallBackObject(argv[INDEX_TWO]); - NotificationHelper::RegisterPushCallback(jsPushCallBack_->AsObject()); + NotificationHelper::RegisterPushCallback(jsPushCallBack_->AsObject(), checkRequest); return undefined; } diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index dc889b8435d0a8c2c5272b1375989c658eb293bb..ac30b4abfaf9816052f4d512203dfc78a38509e9 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -793,7 +793,8 @@ napi_value NapiEnableNotificationSlot(napi_env env, napi_callback_info info) asynccallbackinfo->info.errorCode = NotificationHelper::SetEnabledForBundleSlot( asynccallbackinfo->params.option, asynccallbackinfo->params.outType, - asynccallbackinfo->params.enable); + asynccallbackinfo->params.enable, + asynccallbackinfo->params.isForceControl); } }, [](napi_env env, napi_status status, void *data) { diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 15276b56a2805d8459dda5f2a674cf81a912f299..f6995b077e6cce77255dc9a93f573051a8455d67 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -1324,7 +1324,8 @@ napi_value EnableNotificationSlot(napi_env env, napi_callback_info info) asynccallbackinfo->info.errorCode = NotificationHelper::SetEnabledForBundleSlot( asynccallbackinfo->params.option, asynccallbackinfo->params.outType, - asynccallbackinfo->params.enable); + asynccallbackinfo->params.enable, + asynccallbackinfo->params.isForceControl); } }, [](napi_env env, napi_status status, void *data) { diff --git a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp index e2313a3fec279ec96108a410484667a33dd6f4b1..8441ecd0dffd9b80dddf3c657f3b57d4c4718641 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -226,7 +226,7 @@ private: EXPECT_NE(nullptr, notificationRequest.GetBigIcon()); EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); - EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); + EXPECT_NE(nullptr, notificationRequest.GetOverlayIcon()); std::vector> messageUser = notificationRequest.GetMessageUsers(); for (auto user : messageUser) { if (user != nullptr) { @@ -1536,14 +1536,17 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00100, Func EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::CONTENT_INFORMATION, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, enable)); GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00100::end:" << enable; EXPECT_EQ(enable, false); EXPECT_EQ(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req)); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, true)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::CONTENT_INFORMATION, true, isForceControl)); } /** @@ -1570,16 +1573,19 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00200, Func EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00200::end:" << enable; - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, + NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); EXPECT_EQ(enable, false); EXPECT_EQ((uint32_t)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req)); enable = true; - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, + NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); EXPECT_EQ(enable, true); diff --git a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp index e293563b1b6d44fdc52201766df94369bd449525..6e6741da25d68d633ac6bb5146d0fa2e45311dc0 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -396,8 +396,10 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 EXPECT_EQ(spSlot->GetEnable(), true); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundlename", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); EXPECT_EQ(enable, false); @@ -413,7 +415,8 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 { bool enable = true; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, false)); sleep(SLEEP_TIME); enable = false; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); @@ -434,8 +437,10 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00300, Function | MediumTest | Level1) { bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); enable = true; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); diff --git a/interfaces/inner_api/notification.h b/interfaces/inner_api/notification.h index 4f5908622c1f8ab80f987c6b0a7a3c10910e19fa..6727824018097578d0945c3fd4146547f3b2278c 100644 --- a/interfaces/inner_api/notification.h +++ b/interfaces/inner_api/notification.h @@ -244,6 +244,48 @@ public: */ static Notification *Unmarshalling(Parcel &parcel); + /** + * @brief Obtains the update timer id. + * + * @return Returns the id of the notification update timer. + */ + uint64_t GetUpdateTimer() const; + + /** + * @brief Obtains the update timer id. + * + * @param updateTimerId the id of the notification update timer. + */ + void SetUpdateTimer(uint64_t updateTimerId); + + /** + * @brief Obtains the finish timer id of notification. + * + * @return Returns the id of the notification finish timer. + */ + uint64_t GetFinishTimer() const; + + /** + * @brief Obtains the finish timer id. + * + * @param finishTimerId the id of the notification finish timer. + */ + void SetFinishTimer(uint64_t finishTimerId); + + /** + * @brief Obtains the archive timer id of notification. + * + * @return Returns the id of the notification archive timer. + */ + uint64_t GetArchiveTimer() const; + + /** + * @brief Obtains the archive timer id. + * + * @param archiveTimerId the id of the notification archive timer. + */ + void SetArchiveTimer(uint64_t archiveTimerId); + private: Notification(); void SetEnableSound(const bool &enable); @@ -264,11 +306,13 @@ private: void ReadFromParcelString(Parcel &parcel); void ReadFromParcelInt32(Parcel &parcel); void ReadFromParcelInt64(Parcel &parcel); + void ReadFromParcelUint64(Parcel &parcel); void ReadFromParcelParcelable(Parcel &parcel); bool MarshallingBool(Parcel &parcel) const; bool MarshallingString(Parcel &parcel) const; bool MarshallingInt32(Parcel &parcel) const; bool MarshallingInt64(Parcel &parcel) const; + bool MarshallingUint64(Parcel &parcel) const; bool MarshallingParcelable(Parcel &parcel) const; private: @@ -284,6 +328,9 @@ private: NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL}; sptr request_ {nullptr}; int64_t postTime_ {0}; + uint64_t updateTimerId_ {0}; + uint64_t finishTimerId_ {0}; + uint64_t archiveTimerId_ {0}; std::shared_ptr sound_ {nullptr}; std::vector vibrationStyle_ {}; diff --git a/interfaces/inner_api/notification_bundle_option.h b/interfaces/inner_api/notification_bundle_option.h index 60467a4d3e573182ac2d4d701901a4675e46b359..edc2887102dd0fc86858e84e5120d906760ddc03 100644 --- a/interfaces/inner_api/notification_bundle_option.h +++ b/interfaces/inner_api/notification_bundle_option.h @@ -16,11 +16,12 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H +#include "notification_json_convert.h" #include "parcel.h" namespace OHOS { namespace Notification { -class NotificationBundleOption : public Parcelable { +class NotificationBundleOption : public Parcelable, public NotificationJsonConvertionBase { public: NotificationBundleOption() = default; @@ -85,6 +86,22 @@ public: */ static NotificationBundleOption *Unmarshalling(Parcel &parcel); + /** + * @brief Converts a notification bundle option object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a bundle option object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationBundleOption. + */ + static NotificationBundleOption *FromJson(const nlohmann::json &jsonObject); + private: /** * @brief Read data from a Parcel. diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 564e87bb3a7f55f11a9245fda9d2fc764a04f34b..875c4600f9c7c3d27aae6b168117f21bec28fca6 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -183,6 +183,22 @@ public: */ static const std::string EXTRA_INPUTS_SOURCE; + static const int64_t HOUR_TO_MS = 3600000; + + static const int64_t SECOND_TO_MS = 1000; + + static const int64_t MAX_FINISH_TIME = 8 * HOUR_TO_MS; + + static const int64_t MAX_UPDATE_TIME = 4 * HOUR_TO_MS; + + static const int64_t INVALID_AUTO_DELETE_TIME = -1; + + /* one hour */ + static const int64_t DEFAULT_AUTO_DELETE_TIME = 3600; + + static constexpr uint64_t INVALID_TIMER_ID = 0ULL; + + static constexpr uint64_t NOTIFICATION_MAX_LIVE_VIEW_SIZE = 520ULL * 1024ULL; // rdb constexpr static const char* NOTIFICATION_RDB_NAME = "/notificationdb.db"; constexpr static const char* NOTIFICATION_RDB_TABLE_NAME = "notification_table"; diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index e07cd0d174034d34960000b97dd465f4d5a622ef..2b2a932a01f8c4519062a495074ae11911c7b1f6 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -26,6 +26,7 @@ #include "notification_sorting_map.h" #include "notification_subscriber.h" #include "notification_local_live_view_subscriber.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -471,6 +472,16 @@ public: static ErrCode GetAllActiveNotifications( const std::vector key, std::vector> ¬ification); + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info by filter, you must + * @param filter + * @param extraInfo + * @return + */ + static ErrCode GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request); + /** * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies * the current application, no permission is required for calling this method. If bundle specifies another @@ -732,10 +743,11 @@ public: * @param bundleOption Indicates the bundle name and uid of the application. * @param slotType Indicates type of slot. * @param enabled the type of slot enabled. + * @param isForceControl Indicates whether the slot is affected by the notification switch. * @return Returns get slot number by bundle result. */ - static ErrCode SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled); + static ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); /** * Obtains whether the application slot is enabled. @@ -748,6 +760,15 @@ public: static ErrCode GetEnabledForBundleSlot( const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); + /** + * Obtains whether the current application slot is enabled. + * + * @param slotType Indicates type of slot. + * @param enabled the type of slot enabled to get. + * @return Returns get enabled result. + */ + static ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + /** * @brief Set whether to sync notifications to devices that do not have the app installed. * @@ -778,9 +799,11 @@ public: * @brief Register Push Callback. * * @param pushCallback push appliction's Callback. + * @param notificationCheckRequest Filter conditions for push check. * @return Returns register push callback result. */ - static ErrCode RegisterPushCallback(const sptr& pushCallback); + static ErrCode RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest); /** * @brief Unregister Push Callback. diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index baa5a7b46dcdc38cda5ce3f35cf4788daa341146..c813cd61955e6e27efe973403f5d7e2b7e4af91b 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -19,6 +19,7 @@ #include "ans_const_define.h" #include "message_user.h" #include "notification_action_button.h" +#include "notification_constant.h" #include "notification_content.h" #include "notification_distributed_options.h" #include "notification_flags.h" @@ -425,6 +426,54 @@ public: */ int64_t GetAutoDeletedTime() const; + /** + * @brief Sets the update deadline time before deleting a notification. + * + * @param maxUpdateTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxUpdateTime(int64_t maxUpdateTime); + + /** + * @brief Obtains the time point which a notification must be updated. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxUpdateTime() const; + + /** + * @brief Sets the finish deadline time before deleting a notification. + * + * @param maxFinishTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxFinishTime(int64_t maxUpdateTime); + + /** + * @brief Obtains the time point which a notification must be finished. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxFinishTime() const; + + /** + * @brief Sets the finish deadline time before deleting a notification. + * + * @param maxFinishTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxArchiveTime(int64_t maxArchiveTime); + + /** + * @brief Obtains the time point which a notification must be finished. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxArchiveTime() const; + /** * @brief Sets the little icon of the notification. * @@ -1101,6 +1150,62 @@ public: void SetRemoveAllowed(bool isRemoveAllowed); + bool IsCommonLiveView() const; + + /** + * @brief Checks whether the image size exceeds the limit in content. + * + * @param pixelMap Indicates the image smart pointer. + * @param maxSize The max size of image. + * @return Returns the ErrCode. + */ + static bool CheckImageOverSizeForPixelMap(const std::shared_ptr &pixelMap, uint32_t maxSize); + + /** + * @brief Checks whether the picture size exceeds the limit in content. + * + * @param request Indicates the specified request. + * @return Returns the ErrCode. + */ + ErrCode CheckNotificationRequest(const sptr &oldRequest) const; + + /** + * @brief Fill missing parameters of the current notification request. + * + * @param oldRequest Indicates the old request. + */ + void FillMissingParameters(const sptr &oldRequest); + + /** + * @brief Generate notification request key. + * + * @param creatorUserId Indicates the user id of creator. + * @param creatorUid Indicates the uid of creator. + * @param label Indicates the label of notification request. + * @param notificationId Indicates the ID of notification request, different apps may have same value. + * @return Return the unique key of notification request. + */ + static std::string GenerateNotificationRequestKey(int32_t creatorUserId, + int32_t creatorUid, const std::string &label, int32_t notificationId); + + /** + * @brief Get notification request key. + * + * @return Return the unique key of notification request. + */ + std::string GetKey(); + + /** + * @brief Check the image size in content. + * + * @return Return the check result, ERR_OK: check pass, others: not pass. + */ + ErrCode CheckImageSizeForContent() const; + /** + * Key prefix of notification request + */ + static const std::string KEY_PREFIX; + private: /** * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). @@ -1142,8 +1247,10 @@ private: void CopyOther(const NotificationRequest &other); bool ConvertObjectsToJson(nlohmann::json &jsonObject) const; + ErrCode CheckVersion(const sptr &oldRequest) const; static void ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject); + static void ConvertJsonToNumExt(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToEnum(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToBool(NotificationRequest *target, const nlohmann::json &jsonObject); @@ -1153,6 +1260,9 @@ private: static bool ConvertJsonToNotificationDistributedOptions( NotificationRequest *target, const nlohmann::json &jsonObject); static bool ConvertJsonToNotificationFlags(NotificationRequest *target, const nlohmann::json &jsonObject); + static ErrCode CheckImageSizeForConverSation(std::shared_ptr &content); + static ErrCode CheckImageSizeForPicture(std::shared_ptr &content); + static ErrCode CheckImageSizeForLiveView(std::shared_ptr &content); private: int32_t notificationId_ {0}; @@ -1162,8 +1272,10 @@ private: int32_t progressMax_ {0}; int64_t createTime_ {0}; int64_t deliveryTime_ {0}; - int64_t autoDeletedTime_ {0}; - + int64_t autoDeletedTime_ {NotificationConstant::INVALID_AUTO_DELETE_TIME}; + int64_t maxUpdateTime_ {0}; + int64_t maxFinishTime_ {0}; + int64_t maxArchiveTime_ {0}; pid_t creatorPid_ {0}; int32_t creatorUid_ {0}; int32_t ownerUid_ {0}; diff --git a/interfaces/inner_api/notification_subscriber.h b/interfaces/inner_api/notification_subscriber.h index eec196e3ce36fb05c53793048f94caef3d0c7877..0f2ad926f2507ecf1621ae8b110c6acfce27f0a9 100644 --- a/interfaces/inner_api/notification_subscriber.h +++ b/interfaces/inner_api/notification_subscriber.h @@ -120,6 +120,9 @@ private: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) override; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index eb54f425914f30976bf9120e1e349e4387d9d6ae..6fb39418f86acbcae99a998337274123a2ebc13e 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -658,7 +658,7 @@ public: */ ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; @@ -762,7 +762,8 @@ public: * @param pushCallback PushCallBack. * @return Returns register push Callback result. */ - ErrCode RegisterPushCallback(const sptr& pushCallback) override; + ErrCode RegisterPushCallback(const sptr& pushCallback, + const sptr ¬ificationCheckRequest) override; /** * @brief Unregister Push Callback. diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 93fae9692bdf43f7700aa91c52dd7cc95e337860..bf4aae974444f291bc7f38f955b0b2ea4c815c42 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4333,8 +4333,8 @@ void AdvancedNotificationService::OnBundleDataCleared(const sptrwait(handler); } -ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AdvancedNotificationService::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("slotType: %{public}d, enabled: %{public}d", slotType, enabled); @@ -4872,7 +4872,8 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBack_ = nullptr; } -ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) +ErrCode AdvancedNotificationService::RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) { if (!AccessTokenHelper::IsSystemApp()) { ANS_LOGW("Not system app!"); diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index 8e4daa5bfec177d1afc2ab7d546377466ca5aac9..3741615eb35a5fabb1d7590a6844f5f25d6d0b09 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -996,7 +996,7 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_270000, Function | SmallTest | Level1) bool enabled = false; auto result = advancedNotificationService_->SetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), - NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled); + NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled, false); EXPECT_EQ(result, ERR_ANS_PERMISSION_DENIED); auto result1 = advancedNotificationService_->GetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 9619465dece5782bfa765cadb59bc48d6c4c1a67..7eb1e22b47066c44466843baa8782ee4289670fa 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1543,7 +1543,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, auto result = advancedNotificationService_->SetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), NotificationConstant::SlotType::SOCIAL_COMMUNICATION, - false); + false, false); EXPECT_EQ(result, (int)ERR_OK); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); @@ -2443,7 +2443,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_OK); EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption, - NotificationConstant::SlotType::OTHER, enable), ERR_OK); + NotificationConstant::SlotType::OTHER, enable, false), ERR_OK); EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption, NotificationConstant::SlotType::OTHER, enable), ERR_OK); diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 9b18d001e5316d826b0d2f3e7b716b13b9a4fe46..459bc8e0ef200d42b4c6ecb0d96704d6ed2f97e9 100755 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -1249,7 +1249,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_05 MockVerifyNativeToken(false); MockVerifyCallerPermission(false); AdvancedNotificationService advancedNotificationService; - EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled), + EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false, false), ERR_ANS_NON_SYSTEM_APP); } @@ -1270,7 +1270,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 int32_t notificationId = 0; bundleOption->SetUid(notificationId); AdvancedNotificationService advancedNotificationService; - EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled), + EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false), ERR_ANS_INVALID_BUNDLE); } diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 14960ef708a06f67b332d9c1d6e4a74d09afb4c5..919bdbd4886d7ab028b815668d860b68c5435b6f 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -123,7 +123,7 @@ namespace OHOS { advancedNotificationService.DeleteAllByUser(userId); advancedNotificationService.SetDoNotDisturbDate(date); advancedNotificationService.GetDoNotDisturbDate(date); - advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); advancedNotificationService.GetEnabledForBundleSlot(bundleOption, slotType, enabled); std::vector dumpInfo; advancedNotificationService.ShellDump(stringData, stringData, userId, dumpInfo); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index db837e18f34ad4eb72fc6273f205d0accc05811f..4a0c554a67a47b98791aeb4007a7e19d79afc74d 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -191,7 +191,7 @@ namespace OHOS { ansManagerStub.DeleteAllByUser(userId); ansManagerStub.SetDoNotDisturbDate(date); ansManagerStub.GetDoNotDisturbDate(date); - ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); ansManagerStub.GetEnabledForBundleSlot(bundleOption, slotType, enabled); std::vector dumpInfo; ansManagerStub.ShellDump(stringData, stringData, userId, dumpInfo); diff --git a/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp b/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp index a71c82721631b0863983fb0ec1edd1c654ecd47c..3a18c171451ecf24ef424ea0607e5a0e4bf28131 100644 --- a/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp +++ b/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp @@ -41,7 +41,7 @@ namespace OHOS { uint8_t types = *data % SLOT_TYPE_NUM; Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(types); bool enabled = *data % ENABLE; - Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled); + Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); // test GetEnabledForBundleSlot function Notification::NotificationHelper::GetEnabledForBundleSlot(bundleOption, slotType, enabled); // test SetSyncNotificationEnabledWithoutApp function