diff --git a/frameworks/ans/src/notification_live_view_content.cpp b/frameworks/ans/src/notification_live_view_content.cpp index 9f6f6308500a7b8a17d6b80dee42879961cd6785..ff5d08c1561612f2db3cd97f69eb44d345e052b4 100644 --- a/frameworks/ans/src/notification_live_view_content.cpp +++ b/frameworks/ans/src/notification_live_view_content.cpp @@ -62,6 +62,16 @@ PictureMap NotificationLiveViewContent::GetPicture() const return pictureMap_; } +void NotificationLiveViewContent::SetIsOnlylocalUpdate(const bool &isOnlylocalUpdate) +{ + isOnlylocalUpdate_ = isOnlylocalUpdate; +} + +bool NotificationLiveViewContent::GetIsOnlylocalUpdate() const +{ + return isOnlylocalUpdate_; +} + std::string NotificationLiveViewContent::Dump() { std::string extraStr{"null"}; @@ -212,6 +222,11 @@ bool NotificationLiveViewContent::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteBool(isOnlylocalUpdate_)) { + ANS_LOGE("OnlylocalUpdate is Failed to write."); + return false; + } + return MarshallingPictureMap(parcel); } @@ -261,6 +276,8 @@ bool NotificationLiveViewContent::ReadFromParcel(Parcel &parcel) pictureMap_[key] = pixelMapVec; } + isOnlylocalUpdate_ = parcel.ReadBool(); + return true; } diff --git a/frameworks/ans/test/unittest/notification_live_view_content_test.cpp b/frameworks/ans/test/unittest/notification_live_view_content_test.cpp index 47a25def2b60b82027a3996ba1abcace14be5cea..4a47481314d3aca2b9c9f9ef30f629ac3d00d9b6 100644 --- a/frameworks/ans/test/unittest/notification_live_view_content_test.cpp +++ b/frameworks/ans/test/unittest/notification_live_view_content_test.cpp @@ -89,6 +89,20 @@ HWTEST_F(NotificationLiveViewContentTest, SetPicture_00001, Function | SmallTest EXPECT_EQ(rrc->GetPicture(), pictureMap); } +/** + * @tc.name: SetIsOnlylocalUpdate_00001 + * @tc.desc: Test SetIsOnlylocalUpdate parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLiveViewContentTest, SetIsOnlylocalUpdate_00001, Function | SmallTest | Level1) +{ + bool isOnlyLocalUpdate_ = true; + auto rrc = std::make_shared(); + rrc->SetIsOnlylocalUpdate(isOnlyLocalUpdate_); + EXPECT_EQ(rrc->GetIsOnlylocalUpdate(), isOnlyLocalUpdate_); +} + /** * @tc.name: Dump_00001 * @tc.desc: Test Dump parameters. @@ -153,6 +167,10 @@ HWTEST_F(NotificationLiveViewContentTest, JsonConvert_00001, Function | SmallTes rrc->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE); rrc->SetVersion(NotificationLiveViewContent::MAX_VERSION); + + bool isOnlyLocalUpdate_ = true; + rrc->SetIsOnlylocalUpdate(isOnlyLocalUpdate_); + rrc->SetTitle("title"); rrc->SetText("text"); rrc->SetAdditionalText("addText"); @@ -173,6 +191,7 @@ HWTEST_F(NotificationLiveViewContentTest, JsonConvert_00001, Function | SmallTes EXPECT_EQ(ptr->GetVersion(), NotificationLiveViewContent::MAX_VERSION); EXPECT_NE(ptr->GetExtraInfo(), nullptr); EXPECT_EQ(ptr->GetPicture().size(), 1); + EXPECT_EQ(ptr->GetIsOnlylocalUpdate(), false); delete ptr; } @@ -216,6 +235,10 @@ HWTEST_F(NotificationLiveViewContentTest, MarshallConvert_00001, Function | Smal rrc->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END); uint32_t version = NotificationLiveViewContent::MAX_VERSION - 1; rrc->SetVersion(version); + + bool isOnlyLocalUpdate_ = true; + rrc->SetIsOnlylocalUpdate(isOnlyLocalUpdate_); + rrc->SetTitle("title"); rrc->SetText("text"); rrc->SetAdditionalText("addText"); @@ -232,6 +255,7 @@ HWTEST_F(NotificationLiveViewContentTest, MarshallConvert_00001, Function | Smal EXPECT_EQ(ptr->GetVersion(), version); EXPECT_NE(ptr->GetExtraInfo(), nullptr); EXPECT_EQ(ptr->GetPicture().size(), 2); + EXPECT_EQ(ptr->GetIsOnlylocalUpdate(), false); delete ptr; } diff --git a/interfaces/inner_api/notification_live_view_content.h b/interfaces/inner_api/notification_live_view_content.h index 15ebf8f5caf168183e04a693d924b9302c7fd5b9..4a831d0d3a48dac2b3c6e21db1d16cebd44bcfd4 100644 --- a/interfaces/inner_api/notification_live_view_content.h +++ b/interfaces/inner_api/notification_live_view_content.h @@ -147,6 +147,10 @@ public: PictureMarshallingMap GetPictureMarshallingMap() const; + void SetIsOnlylocalUpdate(const bool &isOnlylocalUpdate); + + bool GetIsOnlylocalUpdate() const; + protected: /** * @brief Read a NotificationLiveViewContent object from a Parcel. @@ -163,6 +167,7 @@ private: std::shared_ptr extraInfo_ {}; PictureMap pictureMap_ {}; PictureMarshallingMap pictureMarshallingMap_ {}; + bool isOnlylocalUpdate_ = false; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 06e18d018fa3b9d067f5df4df3d876bc38f270a0..8e85cd90db612e5bd64942e3d356027755b00778 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1154,6 +1154,8 @@ private: ErrCode GetTargetRecordList(const std::string& bundleName, NotificationConstant::SlotType slotType, NotificationContent::Type contentType, std::vector>& recordList); + ErrCode GetCommonTargetRecordList(const std::string& bundleName,NotificationConstant::SlotType slotType, + NotificationContent::Type contentType,std::vector>& recordList); ErrCode RemoveNotificationFromRecordList(const std::vector>& recordList); void OnSubscriberAdd(const std::shared_ptr &record); void RecoverLiveViewFromDb(); diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index 97f14f90c2978c5dcacf12ff4e42d7fec6991fbd..bdb6bd7b2b04f5541483c56b9009dcaca6a7b309 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -200,6 +200,11 @@ int32_t AdvancedNotificationService::SetNotificationRequestToDb(const Notificati return ERR_OK; } + if (content->GetIsOnlylocalUpdate() && request->IsCommonLiveView()) { + ANS_LOGI("Not saving notification request to db for common live view with isOnlyLocalUpdate set to true."); + return ERR_OK; + } + nlohmann::json jsonObject; if (!NotificationJsonConverter::ConvertToJson(request, jsonObject)) { ANS_LOGE("Convert request to json object failed, bundle name %{public}s, id %{public}d.", diff --git a/services/ans/src/advanced_notification_publish/live_publish_process.cpp b/services/ans/src/advanced_notification_publish/live_publish_process.cpp index a71df2461237e5f9923a4c0a1dc4575661bbb5c2..529ffdec092f1a81744da639c523f9500d8845ea 100644 --- a/services/ans/src/advanced_notification_publish/live_publish_process.cpp +++ b/services/ans/src/advanced_notification_publish/live_publish_process.cpp @@ -88,6 +88,15 @@ bool LivePublishProcess::CheckLocalLiveViewSubscribed(const sptr( + request->GetContent()->GetNotificationContent()); + if (request->GetSlotType() == NotificationConstant::SlotType::LIVE_VIEW && + request->GetNotificationType() == NotificationContent::Type::LIVE_VIEW && + liveViewContent->GetIsOnlylocalUpdate() && + !GetLiveViewSubscribeState(GetClientBundleName())) { + ANS_LOGE("Not subscribe common live view."); + return false; + } return true; } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index cb61d766b094d1cbd12b72c041f261aaa597f5bd..dd764d1b2d94cc19f265cfafabed793a1cc9ec43 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -1044,6 +1044,15 @@ ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotifications(const std } result = RemoveNotificationFromRecordList(recordList); })); + ffrt::task_handle commonHandler = notificationSvrQueue_->submit_h(std::bind([&]() { + if (GetCommonTargetRecordList(bundleName, NotificationConstant::SlotType::LIVE_VIEW, + NotificationContent::Type::LIVE_VIEW, recordList) != ERR_OK) { + ANS_LOGE("Get Common Target record list fail."); + result = ERR_ANS_NOTIFICATION_NOT_EXISTS; + return; + } + result = RemoveNotificationFromRecordList(recordList); + })); notificationSvrQueue_->wait(handler); return result; } @@ -1848,12 +1857,12 @@ ErrCode AdvancedNotificationService::SubscribeLocalLiveView( break; } - bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); - if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { - ANS_LOGE("Client is not a system app or subsystem"); - errCode = ERR_ANS_NON_SYSTEM_APP; - break; - } + // bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + // if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + // ANS_LOGE("Client is not a system app or subsystem"); + // errCode = ERR_ANS_NON_SYSTEM_APP; + // break; + // } errCode = NotificationLocalLiveViewSubscriberManager::GetInstance()->AddLocalLiveViewSubscriber( subscriber, info); diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 5844273db8170d558a44537889d2887898eb8d13..ca15d12932c27346086e42c42a20af6bb726bf01 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -679,6 +679,26 @@ ErrCode AdvancedNotificationService::GetTargetRecordList(const std::string& bund return ERR_OK; } +ErrCode AdvancedNotificationService::GetCommonTargetRecordList(const std::string& bundleName, + NotificationConstant::SlotType slotType, NotificationContent::Type contentType, + std::vector>& recordList) +{ + for (auto& notification : notificationList_) { + auto liveViewContent = std::static_pointer_cast( + notification->request->GetContent()->GetNotificationContent()); + if (notification->request != nullptr && notification->request->GetOwnerBundleName() == bundleName && + notification->request->GetSlotType()== slotType && + notification->request->GetNotificationType() == contentType && + liveViewContent->GetIsOnlylocalUpdate()) { + recordList.emplace_back(notification); + } + } + if (recordList.empty()) { + return ERR_ANS_NOTIFICATION_NOT_EXISTS; + } + return ERR_OK; +} + void AdvancedNotificationService::AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate) { std::chrono::system_clock::time_point now = std::chrono::system_clock::now();