diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index 9d447d582c361eed1b4873874e148ba75bba559c..17237deedb575acfb88659f12034b705728ae23f 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/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9b3ade1c92b8b886dba42c97634802137063f903..1ec29aa2fd71c9f528a3cb286623c068d3014bff 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 NotificationRequest::IsAtomicServiceNotification() +{ + 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/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 7eda75b949752bcac22c14d879b76054d24e8786..5929b922eee13d2ec19b5c49e5c8002e5812e11b 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 7d464cec1f2e2b7f5fc8ef22034cf2c164f32558..42078bbe30d43a0f294bd23111ee66a9fbbc2f2a 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 f0a4de4b7f8dfa3bc8bafd110e3cc94538580017..c8db6e43e74297d3d7dd8684ae4eb828a09c2531 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 9dc390c8ea62963f5b85ef5c48a79649025c6d48..37e3e113fedb187d35116609d3844895547f52ca 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 cc7c290f298c969202b28b2fb28fcc1f10a47b52..897ca0e80463fdcc8c9a08cfc2e0586b3e2cfa04 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; }; @@ -1495,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/BUILD.gn b/services/ans/BUILD.gn index 0120dd0eb217237008144b5d9d80705c448ba313..20227e7838679800f8f39b2b6afa670679e9176c 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 23972945c11240062f86daf38cf468fb43254e48..dfd3835a1aebdb4126b09dcfcf2e02d2e8be9ca0 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 429b9a58671eda78bfad8f8933484de96db4d083..a0715998b651fc378d6b08f43d7b30415710b7e8 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,12 @@ private: ErrCode CheckNotificationRequestLineWantAgents(const std::shared_ptr &content, bool isAgentController, bool isSystemComp); bool IsReasonClickDelete(const int32_t removeReason); + void CheckRemovalWantAgent(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 d1e78b6e7d26427f3597b1b9d88d7abee7d9742c..8f07abcdad4dc9bed9a07eb86c82f29c424e4ead 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 0000000000000000000000000000000000000000..e0125adbbb3d4b29a209e19e1bb3801a62383b98 --- /dev/null +++ b/services/ans/src/advanced_notification_manager/advanced_notification_atomic_service_publish.cpp @@ -0,0 +1,163 @@ +/* + * 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(); +} + +} +} \ 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 10721c10a52b97d470d3ea787066e4ddf953d127..9b80b5b1130449f33e534dfaccfa31611ccd1109 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 (request->IsAtomicServiceNotification()) { + 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 332a978237350fd53d5b49c2aa5f415d5cba98fa..118bb15038fb93005e2adb03c55d620992a0ed76 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 4bdb38e2a771e5d17ba31448b167a5ba684e0394..97ff7934dbd8dd470a44ca6a8972ab85a552f0e5 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 = request->IsAtomicServiceNotification(); 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 9e25d4d4452643dd5e48232ec10827df6f0c8b5c..8fc7a7361b186bd221c6a128bcea2d3d2d02efb3 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 fdfcc21c30a5de86d00a75a69be1b6cf08a54c4a..aa3dda68c436a5d2f70303249d19664d5d0b0ce4 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 4b1e38b42b06b560a2ba6a08698cd6228af10c73..7357af4ad6e7c712ce23f6939916ff961c91b54a 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 8955aa9791814b0a7a880ee24724dc17b6c6c6a0..651d3ed5a0893dec3189b2f06dc8d1c170b26239 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 8c9c23018e3d699a07e006babafd0f0e29e390b6..4f6b14e20aa94a3f086eb20c5ee6ac6a78eb110d 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 0cb0c6e1aee1f070be19c9bde7e79168d6a85d1b..f45dc5759308b60fa99eabe73d51e7afce86bf51 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 887a6da932e9a52ff27a4fd498132496fdc06bcf..1af0671f71acc87aa962d7cd3fe496cab28c85f0 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -193,7 +193,7 @@ 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; service->GetAllNotificationEnabledBundles(bundleOptions); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index aa17b3ad4902ec6964a28fe544b6b43ddf6e4536..09429c132c8f767bf119a368efdb3434f01bf764 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -167,7 +167,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/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index 1ea099a647fa400b866ceb625d73f7c7a3841be4..624eaafc70d414406298faa851795cb444fcbe80 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 e32f22365407e47a162e2f4f03acb7d68b5ede99..25db4e39521003c3145efa3f0210b1b3b1ed2df1 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;