From 6326b728f5a371dc072a48081288aedc122a1b8a Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 11:30:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/IAnsManager.idl | 1 + .../core/common/include/ans_const_define.h | 2 + frameworks/core/src/ans_notification.cpp | 4 +- .../ans_manager_proxy_unit_test.cpp | 3 +- .../ans_notification_branch_test.cpp | 2 +- .../unittest/mock/mock_ans_manager_proxy.h | 3 +- interfaces/inner_api/notification_request.h | 1 + services/ans/BUILD.gn | 1 + .../include/advanced_notification_inline.h | 15 ++ .../include/advanced_notification_service.h | 13 +- services/ans/include/notification_record.h | 1 + ...ed_notification_atomic_service_publish.cpp | 182 ++++++++++++++++++ .../advanced_notification_publish.cpp | 14 +- .../advanced_notification_query.cpp | 8 +- .../ans/src/advanced_notification_service.cpp | 23 ++- .../advanced_notification_slot_service.cpp | 4 +- .../ans/src/advanced_notification_utils.cpp | 15 ++ services/ans/test/unittest/BUILD.gn | 1 + ...nced_notification_publish_service_test.cpp | 56 ++++++ .../advanced_notification_service_test.cpp | 5 +- .../advanced_notification_utils_test.cpp | 15 +- .../ansmanagerstub_fuzzer.cpp | 1 + .../ansmanagerstubannex_fuzzer.cpp | 2 + .../ansmanagerstubannexthree_fuzzer.cpp | 3 +- tools/test/mock/mock_ans_manager_stub.h | 2 +- 25 files changed, 338 insertions(+), 39 deletions(-) create mode 100644 services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index 9d447d582..17237deed 100644 --- a/frameworks/ans/IAnsManager.idl +++ b/frameworks/ans/IAnsManager.idl @@ -76,6 +76,7 @@ interface OHOS.Notification.IAnsManager { [in] sptr bundleOption, [in] int notificationId, [in] String label, + [in] int userId, [in] String[] extraInfoKeys, [out] null_sptr request); diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index c8dcc2afd..5acc3c38c 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -57,6 +57,8 @@ constexpr int32_t NOTIFICATION_MIN_COUNT = 0; constexpr int32_t NOTIFICATION_MAX_COUNT = 1024; constexpr int32_t DO_NOT_DISTURB_PROFILE_MIN_ID = 1; constexpr int32_t DO_NOT_DISTURB_PROFILE_MAX_ID = 10; +constexpr int32_t PKG_INSTALL_STATUS_UNKMOWN = -1; +constexpr int32_t PKG_INSTALL_STATUS_UNINSTALL = 0; // Default sound for notification const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 7eda75b94..5929b922e 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1099,8 +1099,8 @@ ErrCode AnsNotification::GetActiveNotificationByFilter(const LiveViewFilter &fil ANS_LOGE("null bundleOption"); return ERR_ANS_INVALID_PARAM; } - return proxy->GetActiveNotificationByFilter(bo, filter.notificationKey.id, filter.notificationKey.label, - filter.extraInfoKeys, request); + return proxy->GetActiveNotificationByFilter(bo, filter.notificationKey.id, + filter.notificationKey.label, filter.userId, filter.extraInfoKeys, request); } ErrCode AnsNotification::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) 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 7d464cec1..42078bbe3 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 @@ -6977,11 +6977,12 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationByFilterTest_0100, Functi int32_t notificationId = 0; std::string label = "label"; std::vector extraInfoKeys; + int32_t userId = -1; NotificationRequest request(1); sptr liveViewRequest = new (std::nothrow) NotificationRequest(request); - int32_t result = proxy->GetActiveNotificationByFilter(bundleOption, notificationId, label, + int32_t result = proxy->GetActiveNotificationByFilter(bundleOption, notificationId, label, userId, extraInfoKeys, liveViewRequest); EXPECT_EQ(ERR_OK, result); } 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 f0a4de4b7..c8db6e43e 100644 --- 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 @@ -582,7 +582,7 @@ public: } ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, - int32_t notificationId, const std::string &label, const std::vector& extraInfoKeys, + int32_t notificationId, const std::string &label, int32_t userId, const std::vector& extraInfoKeys, sptr &request) override { return ERR_ANS_INVALID_PARAM; diff --git a/frameworks/core/test/unittest/mock/mock_ans_manager_proxy.h b/frameworks/core/test/unittest/mock/mock_ans_manager_proxy.h index 9dc390c8e..37e3e113f 100644 --- a/frameworks/core/test/unittest/mock/mock_ans_manager_proxy.h +++ b/frameworks/core/test/unittest/mock/mock_ans_manager_proxy.h @@ -61,10 +61,11 @@ public: MOCK_METHOD2(GetAllNotificationsBySlotType, ErrCode(std::vector>&, int32_t)); MOCK_METHOD2(GetSpecialActiveNotifications, ErrCode(const std::vector&, std::vector>&)); - MOCK_METHOD5(GetActiveNotificationByFilter, ErrCode( + MOCK_METHOD6(GetActiveNotificationByFilter, ErrCode( const sptr&, int32_t, const std::string&, + int32_t, const std::vector&, sptr&)); MOCK_METHOD2(CanPublishAsBundle, ErrCode(const std::string&, bool&)); diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index cc7c290f2..53400e407 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -48,6 +48,7 @@ struct NotificationKey { struct LiveViewFilter { NotificationBundleOption bundle; + int32_t userId {-1}; NotificationKey notificationKey; std::vector extraInfoKeys; }; diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 0120dd0eb..20227e783 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -71,6 +71,7 @@ ohos_source_set("ans_service_sources") { "src/advanced_notification_flow_control_service.cpp", "src/advanced_notification_inline.cpp", "src/advanced_notification_live_view_service.cpp", + "src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp", "src/advanced_notification_manager/advanced_notification_publish.cpp", "src/advanced_notification_manager/advanced_notification_query.cpp", "src/advanced_notification_publish/base_publish_process.cpp", diff --git a/services/ans/include/advanced_notification_inline.h b/services/ans/include/advanced_notification_inline.h index 23972945c..dfd3835a1 100644 --- a/services/ans/include/advanced_notification_inline.h +++ b/services/ans/include/advanced_notification_inline.h @@ -24,6 +24,7 @@ #include "os_account_manager_helper.h" #include "notification_preferences.h" #include "notification_analytics_util.h" +#include "ans_inner_errors.h" namespace OHOS { namespace Notification { @@ -143,6 +144,20 @@ inline void ReportDeleteFailedEventPushByNotification(const sptr & NotificationAnalyticsUtil::ReportDeleteFailedEvent( notification->GetNotificationRequestPoint(), haMetaMessage); } + +inline ErrCode PermissionVerification() +{ + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) || + !AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) { + return ERR_ANS_PERMISSION_DENIED; + } + return ERR_OK; +} } // namespace Notification } // namespace OHOS #endif // NOTIFICATION_ADVANCED_NOTIFICATION_INLINE_H \ No newline at end of file diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 429b9a586..d95176d6e 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -299,7 +299,7 @@ public: ErrCode GetActiveNotificationByFilter( const sptr &bundleOption, int32_t notificationId, const std::string &label, - const std::vector &extraInfoKeys, sptr &request) override; + int32_t userId, const std::vector &extraInfoKeys, sptr &request) override; /** * @brief Checks whether your application has permission to publish notifications by calling @@ -1403,6 +1403,8 @@ public: */ ErrCode SetHashCodeRule(const uint32_t type) override; + ErrCode AtomicServicePublish(const sptr &request); + protected: /** * @brief Query whether there is a agent relationship between the two apps. @@ -1608,7 +1610,7 @@ private: void DoNotDisturbUpdataReminderFlags(const std::shared_ptr &record); ErrCode CheckCommonParams(); std::shared_ptr GetRecordFromNotificationList( - int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName); + int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName, int32_t userId); std::shared_ptr MakeNotificationRecord( const sptr &request, const sptr &bundleOption); ErrCode IsAllowedNotifyForBundle(const sptr &bundleOption, bool &allowed); @@ -1744,6 +1746,13 @@ private: ErrCode CheckNotificationRequestLineWantAgents(const std::shared_ptr &content, bool isAgentController, bool isSystemComp); bool IsReasonClickDelete(const int32_t removeReason); + void CheckRemovalWantAgent(const sptr &request); + bool IsAtomicServiceNotification(const sptr &request); + ErrCode SetCreatorInfoWithAtomicService(const sptr &request); + AnsStatus CheckAndPrepareNotificationInfoWithAtomicService( + const sptr &request, sptr &bundleOption); + AnsStatus ExecutePublishProcess( + const sptr &request, bool isUpdateByOwnerAllowed); private: static sptr instance_; diff --git a/services/ans/include/notification_record.h b/services/ans/include/notification_record.h index d1e78b6e7..8f07abcda 100644 --- a/services/ans/include/notification_record.h +++ b/services/ans/include/notification_record.h @@ -35,6 +35,7 @@ struct NotificationRecord { int32_t finish_status = -1; bool isThirdparty {true}; bool isNeedFlowCtrl {true}; + bool isAtomicService {false}; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::string deviceId; std::string bundleName; diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp new file mode 100644 index 000000000..83a64fb51 --- /dev/null +++ b/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "advanced_notification_service.h" + +#include "accesstoken_kit.h" +#include "access_token_helper.h" +#include "advanced_notification_flow_control_service.h" +#include "advanced_notification_inline.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_status.h" + +#include "hitrace_meter_adapter.h" +#include "notification_analytics_util.h" +#include "os_account_manager.h" +#include "os_account_manager_helper.h" +#include "string_wrapper.h" +#include "hitrace_util.h" + +namespace OHOS { +namespace Notification { + +ErrCode AdvancedNotificationService::AtomicServicePublish(const sptr &request) +{ + ErrCode result = PermissionVerification(); + if (result != ERR_OK) { + return result; + } + + AnsStatus ansStatus = ExecutePublishProcess(request, true); + if (!ansStatus.Ok()) { + ansStatus.AppendSceneBranch(EventSceneId::SCENE_1, EventBranchId::BRANCH_0, "Execute PublishProcess failed"); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, ansStatus.BuildMessage(true)); + return ansStatus.GetErrCode(); + } + + sptr bundleOption; + ansStatus = CheckAndPrepareNotificationInfoWithAtomicService(request, bundleOption); + if (!ansStatus.Ok()) { + ansStatus.AppendSceneBranch(EventSceneId::SCENE_1, EventBranchId::BRANCH_0, + "CheckAndPrepareNotificationInfoWithAtomicService failed"); + NotificationAnalyticsUtil::ReportPublishFailedEvent(request, ansStatus.BuildMessage(true)); + SendPublishHiSysEvent(request, result); + return ansStatus.GetErrCode(); + } + + result = PublishPreparedNotification(request, bundleOption, false); + if (result != ERR_OK) { + SendPublishHiSysEvent(request, result); + return result; + } + return result; +} + +ErrCode AdvancedNotificationService::SetCreatorInfoWithAtomicService(const sptr &request) +{ + // set agentBundle + std::string agentBundleName = ""; + if (!AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID())) { + agentBundleName = GetClientBundleName(); + if (agentBundleName.empty()) { + ANS_LOGE("Failed to GetClientBundleName"); + return ERR_ANS_INVALID_BUNDLE; + } + } + + int32_t uid = IPCSkeleton::GetCallingUid(); + std::shared_ptr agentBundle = + std::make_shared(agentBundleName, uid); + if (agentBundle == nullptr) { + ANS_LOGE("Failed to create agentBundle instance"); + return ERR_ANS_INVALID_BUNDLE; + } + request->SetAgentBundle(agentBundle); + int32_t pid = IPCSkeleton::GetCallingPid(); + request->SetCreatorUid(uid); + request->SetCreatorPid(pid); + int userId = -1; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId); + request->SetCreatorUserId(userId); + request->SetCreatorBundleName(agentBundleName); + return ERR_OK; +} + +AnsStatus AdvancedNotificationService::CheckAndPrepareNotificationInfoWithAtomicService( + const sptr &request, sptr &bundleOption) +{ + ErrCode result = CheckUserIdParams(request->GetReceiverUserId()); + if (result != ERR_OK) { + return AnsStatus(result, "User is invalid"); + } + if (request->GetOwnerUserId() <= SUBSCRIBE_USER_INIT || request->GetOwnerBundleName().empty()) { + return AnsStatus(ERR_ANS_INVALID_PARAM, "OwnerUserId or OwnerBundleName invalid"); + } + CheckRemovalWantAgent(request); + request->SetCreateTime(GetCurrentTime()); + if (request->GetDeliveryTime() <= 0) { + request->SetDeliveryTime(GetCurrentTime()); + } + result = CheckPictureSize(request); + + SetCreatorInfoWithAtomicService(request); + request->SetOwnerUid(0); + + FillActionButtons(request); + + bundleOption = new (std::nothrow) NotificationBundleOption(request->GetOwnerBundleName(), + request->GetOwnerUid()); + if (bundleOption == nullptr) { + return AnsStatus(ERR_ANS_INVALID_BUNDLE, "create bundleOption failed"); + } + SetClassificationWithVoip(request); + request->SetNotDistributed(false); + SetRequestBySlotType(request, bundleOption); + + result = CheckSoundPermission(request, bundleOption->GetBundleName()); + if (result != ERR_OK) { + return AnsStatus(result, "CheckSoundPermission failed"); + } + if (IsNeedPushCheck(request)) { + result = PushCheck(request); + if (result != ERR_OK) { + return AnsStatus(result, "PushCheck failed"); + } + } + return AnsStatus(); +} + +AnsStatus AdvancedNotificationService::ExecutePublishProcess( + const sptr &request, bool isUpdateByOwnerAllowed) +{ + if (!InitPublishProcess()) { + return AnsStatus(ERR_ANS_NO_MEMORY, "InitPublishProcess failed"); + } + + AnsStatus ansStatus = publishProcess_[request->GetSlotType()]->PublishPreWork(request, isUpdateByOwnerAllowed); + if (!ansStatus.Ok()) { + return ansStatus; + } + + ErrCode result = publishProcess_[request->GetSlotType()]->PublishNotificationByApp(request); + if (result != ERR_OK) { + return AnsStatus(result, "PublishNotificationByApp failed"); + } + return AnsStatus(); +} + +bool AdvancedNotificationService::IsAtomicServiceNotification(const sptr &request) +{ + if (!request->IsCommonLiveView() || !request->IsAgentNotification()) { + ANS_LOGD("not commonLiveView or not agent"); + return false; + } + + auto params = request->GetExtendInfo(); + if (params == nullptr) { + ANS_LOGD("extend info is null."); + return false; + } + int32_t installedStatus = params->GetIntParam("autoServiceIntallStatus", PKG_INSTALL_STATUS_UNKMOWN); + if (installedStatus == PKG_INSTALL_STATUS_UNINSTALL) { + ANS_LOGD("AtomicServiceNotification."); + return true; + } + return false; +} +} +} \ No newline at end of file diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp index 10721c10a..fb69b51a4 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp @@ -62,6 +62,10 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt return CollaboratePublish(request); } + if (IsAtomicServiceNotification(request)) { + return AtomicServicePublish(request); + } + if (!InitPublishProcess()) { return ERR_ANS_NO_MEMORY; } @@ -88,15 +92,7 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt if (isSubsystem) { return PublishNotificationBySa(request); } - if (request->GetRemovalWantAgent() != nullptr && request->GetRemovalWantAgent()->GetPendingWant() != nullptr) { - uint32_t operationType = (uint32_t)(request->GetRemovalWantAgent()->GetPendingWant() - ->GetType(request->GetRemovalWantAgent()->GetPendingWant()->GetTarget())); - bool isSystemApp = AccessTokenHelper::IsSystemApp(); - if (!isSubsystem && !isSystemApp && operationType != OPERATION_TYPE_COMMON_EVENT) { - ANS_LOGI("null SetRemovalWantAgent"); - request->SetRemovalWantAgent(nullptr); - } - } + CheckRemovalWantAgent(request); do { result = publishProcess_[request->GetSlotType()]->PublishNotificationByApp(request); if (result != ERR_OK) { diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_query.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_query.cpp index 332a97823..118bb1503 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_query.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_query.cpp @@ -199,10 +199,13 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( ErrCode AdvancedNotificationService::GetActiveNotificationByFilter( const sptr &bundleOption, int32_t notificationId, const std::string &label, - const std::vector &extraInfoKeys, sptr &request) + int32_t userId, const std::vector &extraInfoKeys, sptr &request) { ANS_LOGD("called"); sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr && userId != -1 && !bundleOption->GetBundleName().empty()) { + bundle = new (std::nothrow) NotificationBundleOption(bundleOption->GetBundleName(), 0); + } if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; } @@ -226,7 +229,8 @@ ErrCode AdvancedNotificationService::GetActiveNotificationByFilter( ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { ANS_LOGD("called"); - auto record = GetRecordFromNotificationList(notificationId, bundle->GetUid(), label, bundle->GetBundleName()); + auto record = GetRecordFromNotificationList( + notificationId, bundle->GetUid(), label, bundle->GetBundleName(), userId); if ((record == nullptr) || (!record->request->IsCommonLiveView())) { return; } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 4bdb38e2a..388707e8a 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -699,6 +699,7 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification(const sptrisThirdparty = isThirdparty; + record->isAtomicService = IsAtomicServiceNotification(request); ErrCode result = CheckPublishPreparedNotification(record, isSystemApp); if (result != ERR_OK) { message.ErrorCode(result); @@ -946,8 +947,8 @@ ErrCode AdvancedNotificationService::UpdateSlotAuthInfo(const std::shared_ptrSetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); } } - if (record->request->IsSystemLiveView()) { - ANS_LOGI("System live view no need add slot"); + if (record->request->IsSystemLiveView() || record->isAtomicService) { + ANS_LOGI("System live view or stomicService no need add slot"); return ERR_OK; } std::vector> slots; @@ -1485,13 +1486,14 @@ std::shared_ptr AdvancedNotificationService::GetFromDelayedN } std::shared_ptr AdvancedNotificationService::GetRecordFromNotificationList( - int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName) + int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName, int32_t userId) { for (auto &record : notificationList_) { if ((record->notification->GetLabel() == label) && (record->notification->GetId() == notificationId) && (record->bundleOption->GetUid() == uid) && - (record->bundleOption->GetBundleName() == bundleName)) { + (record->bundleOption->GetBundleName() == bundleName) && + (record->notification->GetRecvUserId() == userId || userId == -1)) { return record; } } @@ -1986,16 +1988,19 @@ ErrCode AdvancedNotificationService::AddRecordToMemory( const std::shared_ptr &record, bool isSystemApp, bool isUpdateByOwner, const bool isAgentController) { - auto result = AssignValidNotificationSlot(record, record->bundleOption); + ErrCode result = ERR_OK; + result = AssignValidNotificationSlot(record, record->bundleOption); if (result != ERR_OK) { ANS_LOGE("Can not assign valid slot!"); return result; } - result = Filter(record); - if (result != ERR_OK) { - ANS_LOGE("Reject by filters: %{public}d", result); - return result; + if (!record->isAtomicService) { + result = Filter(record); + if (result != ERR_OK) { + ANS_LOGE("Reject by filters: %{public}d", result); + return result; + } } if (isSystemApp) { diff --git a/services/ans/src/advanced_notification_slot_service.cpp b/services/ans/src/advanced_notification_slot_service.cpp index 9e25d4d44..8fc7a7361 100644 --- a/services/ans/src/advanced_notification_slot_service.cpp +++ b/services/ans/src/advanced_notification_slot_service.cpp @@ -530,8 +530,8 @@ ErrCode AdvancedNotificationService::AssignValidNotificationSlot(const std::shar } GenerateSlotReminderMode(slot, bundleOption); - if (record->request->IsSystemLiveView()) { - ANS_LOGI("System live view no need add sloty."); + if (record->request->IsSystemLiveView() || record->isAtomicService) { + ANS_LOGI("System live view or atomicService no need add sloty."); result = ERR_OK; } else { std::vector> slots; diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index fdfcc21c3..aa3dda68c 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -88,6 +88,7 @@ constexpr char KEY_TABLE_VERSION[] = "tableVersion"; constexpr char SPLIT_FLAG[] = "-"; constexpr int32_t KEYWORD_SIZE = 4; constexpr int32_t MIN_VERSION = 1; +constexpr int32_t OPERATION_TYPE_COMMON_EVENT = 4; const std::unordered_map HIDUMPER_CMD_MAP = { { "--help", HELP_NOTIFICATION_OPTION }, { "--active", ACTIVE_NOTIFICATION_OPTION }, @@ -2006,5 +2007,19 @@ void AdvancedNotificationService::UpdateCloneBundleInfoFoSilentReminder( } } } + +void AdvancedNotificationService::CheckRemovalWantAgent(const sptr &request) +{ + if (request->GetRemovalWantAgent() != nullptr && request->GetRemovalWantAgent()->GetPendingWant() != nullptr) { + uint32_t operationType = (uint32_t)(request->GetRemovalWantAgent()->GetPendingWant() + ->GetType(request->GetRemovalWantAgent()->GetPendingWant()->GetTarget())); + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + bool isSystemApp = AccessTokenHelper::IsSystemApp(); + if (!isSubsystem && !isSystemApp && operationType != OPERATION_TYPE_COMMON_EVENT) { + ANS_LOGI("null SetRemovalWantAgent"); + request->SetRemovalWantAgent(nullptr); + } + } +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 4b1e38b42..7357af4ad 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1520,6 +1520,7 @@ ohos_unittest("notification_extension_test") { "${services_path}/ans/src/advanced_notification_inline.cpp", "${services_path}/ans/src/advanced_notification_live_view_service.cpp", "${services_path}/ans/src/advanced_notification_manager/advanced_notification_publish.cpp", + "${services_path}/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp", "${services_path}/ans/src/advanced_notification_manager/advanced_notification_query.cpp", "${services_path}/ans/src/advanced_notification_publish/base_publish_process.cpp", "${services_path}/ans/src/advanced_notification_publish/common_notification_publish_process.cpp", diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index 8955aa979..651d3ed5a 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -36,6 +36,8 @@ #include "mock_ipc_skeleton.h" #include "bool_wrapper.h" #include "string_wrapper.h" +#include "want_params.h" +#include "int_wrapper.h" extern void MockIsOsAccountExists(bool exists); extern void MockGetOsAccountLocalIdFromUid(bool mockRet, uint8_t mockCase); @@ -2715,5 +2717,59 @@ HWTEST_F(AnsPublishServiceTest, IsDisableNotification_005, Function | SmallTest ASSERT_TRUE(result); system::SetBoolParameter("persist.edm.notification_disable", defaultPolicy); } + +/* + * @tc.name: AtomicServicePublish_0100 + * @tc.desc: test PublishNotification with common liveView. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsPublishServiceTest, AtomicServicePublish_0100, Function | MediumTest | Level1) +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); + sptr request = new NotificationRequest(1000); + std::shared_ptr liveViewContent = std::make_shared(); + liveViewContent->SetContentType(static_cast(NotificationContent::Type::LIVE_VIEW)); + std::shared_ptr content = std::make_shared(liveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + request->SetIsAgentNotification(true); + request->SetOwnerBundleName("test.com"); + request->SetOwnerUserId(100); + auto extendInfo = std::make_shared(); + extendInfo->SetParam("autoServiceIntallStatus", AAFwk::Integer::Box(0)); + request->SetExtendInfo(extendInfo); + auto params = request->GetExtendInfo(); + int32_t installedStatus = params->GetIntParam("autoServiceIntallStatus", 0); + auto ret = advancedNotificationService_->Publish("", request); + EXPECT_EQ(ret, ERR_OK); +} + +/* + * @tc.name: AtomicServicePublish_0100 + * @tc.desc: test PublishNotification with common liveView. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsPublishServiceTest, AtomicServicePublish_0200, Function | MediumTest | Level1) +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); + sptr request = new NotificationRequest(1000); + std::shared_ptr liveViewContent = std::make_shared(); + liveViewContent->SetContentType(static_cast(NotificationContent::Type::LIVE_VIEW)); + std::shared_ptr content = std::make_shared(liveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + request->SetIsAgentNotification(true); + request->SetOwnerBundleName("test.com"); + request->SetOwnerUserId(-1); + auto extendInfo = std::make_shared(); + extendInfo->SetParam("autoServiceIntallStatus", AAFwk::Integer::Box(0)); + request->SetExtendInfo(extendInfo); + auto ret = advancedNotificationService_->Publish("", request); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 8c9c23018..4f6b14e20 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -3745,8 +3745,9 @@ HWTEST_F(AdvancedNotificationServiceTest, GetActiveNotificationByFilter_0001, Fu int32_t notificationId = 1; std::string label = "GetActiveNotificationByFilter's label"; std::vector extraInfoKeys; + int32_t userId = -1; - ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundleOption, notificationId, label, + ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundleOption, notificationId, label, userId, extraInfoKeys, req), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); GTEST_LOG_(INFO) << "GetActiveNotificationByFilter_0001 test end"; @@ -3999,7 +4000,7 @@ HWTEST_F(AdvancedNotificationServiceTest, GetRecordFromNotificationList_00001, F auto ret = advancedNotificationService_->AssignToNotificationList(record); auto res = advancedNotificationService_->GetRecordFromNotificationList( - 1, SYSTEM_APP_UID, "label", TEST_DEFUALT_BUNDLE); + 1, SYSTEM_APP_UID, "label", TEST_DEFUALT_BUNDLE, -1); EXPECT_NE(res, nullptr); } diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index 0cb0c6e1a..b752ec913 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -205,7 +205,8 @@ HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00001, Function | SmallTest sptr newRequest; auto bundleOption = new NotificationBundleOption("test", 1); int notificationId = 1; - ASSERT_EQ(ans.GetActiveNotificationByFilter(bundleOption, notificationId, label, keys, newRequest), + int32_t userId = -1; + ASSERT_EQ(ans.GetActiveNotificationByFilter(bundleOption, notificationId, label ,userId, keys, newRequest), (int)ERR_ANS_INVALID_PARAM); } @@ -222,8 +223,9 @@ HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00002, Function | SmallTest sptr newRequest; sptr bundle; int notificationId = 1; + int32_t userId = -1; ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter( - bundle, notificationId, label, keys, newRequest), + bundle, notificationId, label, userId, keys, newRequest), (int)ERR_ANS_INVALID_BUNDLE); } @@ -238,6 +240,7 @@ HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00003, Function | SmallTest auto slotType = NotificationConstant::SlotType::LIVE_VIEW; std::string label = "testLabel"; int notificationId = 1; + int32_t userId = -1; sptr oldRequest = new (std::nothrow) NotificationRequest(); oldRequest->SetSlotType(slotType); @@ -264,19 +267,19 @@ HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00003, Function | SmallTest std::vector keys; sptr newRequest; ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle, - notificationId, label, keys, newRequest), (int)ERR_ANS_PERMISSION_DENIED); + notificationId, label, userId, keys, newRequest), (int)ERR_ANS_PERMISSION_DENIED); MockIsVerfyPermisson(true); ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle, - notificationId, label, keys, newRequest), (int)ERR_OK); + notificationId, label, userId, keys, newRequest), (int)ERR_OK); keys.emplace_back("test1"); ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle, - notificationId, label, keys, newRequest), (int)ERR_OK); + notificationId, label, userId, keys, newRequest), (int)ERR_OK); sptr bundle1 = new NotificationBundleOption("test1", 1); ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle1, - notificationId, label, keys, newRequest), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); + notificationId, label, userId, keys, newRequest), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); } /** diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 887a6da93..e390fbd58 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -194,6 +194,7 @@ namespace OHOS { uint32_t slotFlags; service->GetSlotFlagsAsBundle(bundleOption, slotFlags); service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, request); + service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, userId, keys, request); service->GetSlotByBundle(bundleOption, slotType, slot); std::vector bundleOptions; service->GetAllNotificationEnabledBundles(bundleOptions); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index aa17b3ad4..290bfe1f4 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -168,6 +168,8 @@ namespace OHOS { service->GetAllActiveNotifications(notificationsVector); service->GetSpecialActiveNotifications(keys, notificationsVector); service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, notificationRequest); + service->GetActiveNotificationByFilter( + bundleOption, notificationId, stringData, userId, keys, notificationRequest); service->CanPublishAsBundle(stringData, canPublish); service->PublishAsBundle(notificationRequest, stringData); service->PublishAsBundleWithMaxCapacity(notificationRequest, stringData); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index 1ea099a64..624eaafc7 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -170,7 +170,8 @@ namespace OHOS { service->GetActiveNotificationNums(num); service->GetAllActiveNotifications(notificationsVector); service->GetSpecialActiveNotifications(keys, notificationsVector); - service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, notificationRequest); + service->GetActiveNotificationByFilter( + bundleOption, notificationId, stringData, userId, keys, notificationRequest); service->CanPublishAsBundle(stringData, canPublish); service->PublishAsBundle(notificationRequest, stringData); service->PublishAsBundleWithMaxCapacity(notificationRequest, stringData); diff --git a/tools/test/mock/mock_ans_manager_stub.h b/tools/test/mock/mock_ans_manager_stub.h index e32f22365..25db4e395 100644 --- a/tools/test/mock/mock_ans_manager_stub.h +++ b/tools/test/mock/mock_ans_manager_stub.h @@ -531,7 +531,7 @@ public: } ErrCode GetActiveNotificationByFilter(const sptr& bundleOption, - int32_t notificationId, const std::string& label, const std::vector& extraInfoKeys, + int32_t notificationId, const std::string& label, int32_t userId, const std::vector& extraInfoKeys, sptr& request) override { return ERR_ANS_INVALID_PARAM; -- Gitee From 369f3080d916888a3a792c79000e6d597e0da6ef Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 11:44:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/test/unittest/advanced_notification_utils_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index b752ec913..f45dc5759 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -206,7 +206,7 @@ HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00001, Function | SmallTest auto bundleOption = new NotificationBundleOption("test", 1); int notificationId = 1; int32_t userId = -1; - ASSERT_EQ(ans.GetActiveNotificationByFilter(bundleOption, notificationId, label ,userId, keys, newRequest), + ASSERT_EQ(ans.GetActiveNotificationByFilter(bundleOption, notificationId, label, userId, keys, newRequest), (int)ERR_ANS_INVALID_PARAM); } -- Gitee From 3c6824d915e906a80cfc7221ac3d1c152c52b73f Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 14:11:22 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp | 1 - .../ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index e390fbd58..1af0671f7 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -193,7 +193,6 @@ namespace OHOS { service->SetSlotFlagsAsBundle(bundleOption, fuzzData->ConsumeIntegral()); uint32_t slotFlags; service->GetSlotFlagsAsBundle(bundleOption, slotFlags); - service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, request); service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, userId, keys, request); service->GetSlotByBundle(bundleOption, slotType, slot); std::vector bundleOptions; diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index 290bfe1f4..09429c132 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -167,7 +167,6 @@ namespace OHOS { service->GetActiveNotificationNums(num); service->GetAllActiveNotifications(notificationsVector); service->GetSpecialActiveNotifications(keys, notificationsVector); - service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, notificationRequest); service->GetActiveNotificationByFilter( bundleOption, notificationId, stringData, userId, keys, notificationRequest); service->CanPublishAsBundle(stringData, canPublish); -- Gitee From 8610e03b64c8561ba2d9bb3d6251aa68f8d699bd Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 15:24:50 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 21 +++++++++++++++++++ .../core/common/include/ans_const_define.h | 2 -- interfaces/inner_api/notification_request.h | 2 ++ .../include/advanced_notification_service.h | 1 - ...ed_notification_atomic_service_publish.cpp | 19 ----------------- .../advanced_notification_publish.cpp | 2 +- .../ans/src/advanced_notification_service.cpp | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9b3ade1c9..1e8474f3f 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -54,6 +54,8 @@ const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3}; const std::size_t NotificationRequest::MAX_MESSAGE_USERS {1000}; constexpr int32_t MAX_MAP_SIZE = 1000; +constexpr int32_t PKG_INSTALL_STATUS_UNKMOWN = -1; +constexpr int32_t PKG_INSTALL_STATUS_UNINSTALL = 0; NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId) { @@ -3130,5 +3132,24 @@ const std::map NotificationRequest::GetdeviceStatus() { return deviceStatus_; } + +bool AdvancedNotificationService::IsAtomicServiceNotification(const sptr &request) +{ + if (!IsCommonLiveView() || !IsAgentNotification()) { + ANS_LOGD("not commonLiveView or not agent"); + return false; + } + + if (extendInfo_ == nullptr) { + ANS_LOGD("extend info is null."); + return false; + } + int32_t installedStatus = extendInfo_->GetIntParam("autoServiceIntallStatus", PKG_INSTALL_STATUS_UNKMOWN); + if (installedStatus == PKG_INSTALL_STATUS_UNINSTALL) { + ANS_LOGD("AtomicServiceNotification."); + return true; + } + return false; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index 5acc3c38c..c8dcc2afd 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -57,8 +57,6 @@ constexpr int32_t NOTIFICATION_MIN_COUNT = 0; constexpr int32_t NOTIFICATION_MAX_COUNT = 1024; constexpr int32_t DO_NOT_DISTURB_PROFILE_MIN_ID = 1; constexpr int32_t DO_NOT_DISTURB_PROFILE_MAX_ID = 10; -constexpr int32_t PKG_INSTALL_STATUS_UNKMOWN = -1; -constexpr int32_t PKG_INSTALL_STATUS_UNINSTALL = 0; // Default sound for notification const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 53400e407..897ca0e80 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -1496,6 +1496,8 @@ public: static NotificationRequest *CollaborationFromJson(const std::string& basicInfo); + bool IsAtomicServiceNotification(); + private: /** * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index d95176d6e..a0715998b 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1747,7 +1747,6 @@ private: bool isAgentController, bool isSystemComp); bool IsReasonClickDelete(const int32_t removeReason); void CheckRemovalWantAgent(const sptr &request); - bool IsAtomicServiceNotification(const sptr &request); ErrCode SetCreatorInfoWithAtomicService(const sptr &request); AnsStatus CheckAndPrepareNotificationInfoWithAtomicService( const sptr &request, sptr &bundleOption); diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp index 83a64fb51..e0125adbb 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp @@ -159,24 +159,5 @@ AnsStatus AdvancedNotificationService::ExecutePublishProcess( return AnsStatus(); } -bool AdvancedNotificationService::IsAtomicServiceNotification(const sptr &request) -{ - if (!request->IsCommonLiveView() || !request->IsAgentNotification()) { - ANS_LOGD("not commonLiveView or not agent"); - return false; - } - - auto params = request->GetExtendInfo(); - if (params == nullptr) { - ANS_LOGD("extend info is null."); - return false; - } - int32_t installedStatus = params->GetIntParam("autoServiceIntallStatus", PKG_INSTALL_STATUS_UNKMOWN); - if (installedStatus == PKG_INSTALL_STATUS_UNINSTALL) { - ANS_LOGD("AtomicServiceNotification."); - return true; - } - return false; -} } } \ No newline at end of file diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp index fb69b51a4..9b80b5b11 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp @@ -62,7 +62,7 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt return CollaboratePublish(request); } - if (IsAtomicServiceNotification(request)) { + if (request->IsAtomicServiceNotification()) { return AtomicServicePublish(request); } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 388707e8a..97ff7934d 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -699,7 +699,7 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification(const sptrisThirdparty = isThirdparty; - record->isAtomicService = IsAtomicServiceNotification(request); + record->isAtomicService = request->IsAtomicServiceNotification(); ErrCode result = CheckPublishPreparedNotification(record, isSystemApp); if (result != ERR_OK) { message.ErrorCode(result); -- Gitee From 3d673bf087c838492a08f1b801cb3b925fbeef16 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 15:36:47 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 1e8474f3f..7d4d2da42 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -3133,7 +3133,7 @@ const std::map NotificationRequest::GetdeviceStatus() return deviceStatus_; } -bool AdvancedNotificationService::IsAtomicServiceNotification(const sptr &request) +bool NotificationRequest::IsAtomicServiceNotification(const sptr &request) { if (!IsCommonLiveView() || !IsAgentNotification()) { ANS_LOGD("not commonLiveView or not agent"); -- Gitee From 7731f61f9d0ef18c5de6f6f69a9cf951feb738ad Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 5 Jul 2025 15:49:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=85=83=E6=9C=8D=E5=8A=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 7d4d2da42..1ec29aa2f 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -3133,7 +3133,7 @@ const std::map NotificationRequest::GetdeviceStatus() return deviceStatus_; } -bool NotificationRequest::IsAtomicServiceNotification(const sptr &request) +bool NotificationRequest::IsAtomicServiceNotification() { if (!IsCommonLiveView() || !IsAgentNotification()) { ANS_LOGD("not commonLiveView or not agent"); -- Gitee