From 3b1f18e12aec3a646e3a60f0c861a3b56d1deffd Mon Sep 17 00:00:00 2001 From: guxiang Date: Thu, 11 Sep 2025 21:52:01 +0800 Subject: [PATCH] =?UTF-8?q?distributedOperation=E5=A2=9E=E5=8A=A0=E8=BF=90?= =?UTF-8?q?=E7=BB=B4=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guxiang --- frameworks/ans/src/notification_flags.cpp | 2 +- .../test/unittest/notification_flags_test.cpp | 3 ++ interfaces/inner_api/notification_flags.h | 1 + .../include/advanced_notification_service.h | 2 + .../ans/include/notification_analytics_util.h | 1 + ...tification_distributed_manager_service.cpp | 46 +++++++++++-------- ...ation_distributed_manager_service_test.cpp | 23 ++++++++++ ...stributed_unlock_listener_oper_service.cpp | 2 +- .../test/unittest/mock/mock_request_box.h | 2 +- 9 files changed, 61 insertions(+), 21 deletions(-) diff --git a/frameworks/ans/src/notification_flags.cpp b/frameworks/ans/src/notification_flags.cpp index 36ccdb9f5..e2fbf85bf 100644 --- a/frameworks/ans/src/notification_flags.cpp +++ b/frameworks/ans/src/notification_flags.cpp @@ -256,7 +256,7 @@ bool NotificationFlags::ReadFromParcel(Parcel &parcel) bool NotificationFlags::GetReminderFlagsByString( const std::string &strReminderFlags, std::shared_ptr &reminderFlags) { - if (strReminderFlags.size() <= SOUND_ENABLED_SEQ) { + if (strReminderFlags.size() != REMINDER_FLAG_SIZE) { ANS_LOGE("GetReminderFlagsByString failed as Invalid reminderFlags size"); return false; } diff --git a/frameworks/ans/test/unittest/notification_flags_test.cpp b/frameworks/ans/test/unittest/notification_flags_test.cpp index eace184c6..721f063f2 100644 --- a/frameworks/ans/test/unittest/notification_flags_test.cpp +++ b/frameworks/ans/test/unittest/notification_flags_test.cpp @@ -201,6 +201,9 @@ HWTEST_F(NotificationFlagsTest, GetReminderFlagsByString_00001, Function | Small res = flag.GetReminderFlagsByString("444444", flagSptr); ASSERT_FALSE(res); + + res = flag.GetReminderFlagsByString("1111111", flagSptr); + ASSERT_FALSE(res); } /** diff --git a/interfaces/inner_api/notification_flags.h b/interfaces/inner_api/notification_flags.h index 3c35da8f1..7e1c8bf92 100644 --- a/interfaces/inner_api/notification_flags.h +++ b/interfaces/inner_api/notification_flags.h @@ -175,6 +175,7 @@ private: static constexpr char CHAR_REMIND_DISABLE = '0'; static constexpr char CHAR_REMIND_ENABLE = '1'; static constexpr char CHAR_FLAG_STATUS_CLOSE = '2'; + static constexpr int32_t REMINDER_FLAG_SIZE = 6; static constexpr int32_t SOUND_ENABLED_SEQ = 5; static constexpr int32_t LOCK_SCREEN_VISIBLENESS_ENABLED_SEQ = 4; static constexpr int32_t BANNER_ENABLED_SEQ = 3; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index ed0e690f2..5ba5c6d71 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1819,6 +1819,8 @@ private: ErrCode UpdateNotificationSwitchState( const sptr &bundleOption, const AppExecFwk::BundleInfo &bundleInfo); + ErrCode DistributeOperationInner(const sptr& operationInfo); + private: static sptr instance_; static ffrt::mutex instanceMutex_; diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index 8801f9a78..53ecfefe0 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -82,6 +82,7 @@ enum EventBranchId { BRANCH_18 = 18, BRANCH_19 = 19, BRANCH_20 = 20, + BRANCH_21 = 21, }; class OperationalMeta { diff --git a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp index 4d7186d79..267113b9b 100644 --- a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp +++ b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp @@ -375,43 +375,53 @@ ErrCode AdvancedNotificationService::DistributeOperation(const sptrGetOperationType(); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_8, EventBranchId::BRANCH_21); + message.Message("key:" + operationInfo->GetHashCode(), false); if (operationType == OperationType::DISTRIBUTE_OPERATION_REPLY) { operationInfo->SetEventId(std::to_string(GetCurrentTime())); std::string key = operationInfo->GetHashCode() + operationInfo->GetEventId(); DistributedOperationService::GetInstance().AddOperation(key, callback); + } else if (operationType == OperationType::DISTRIBUTE_OPERATION_JUMP_BY_TYPE) { + message.Append(", type:" + std::to_string(operationInfo->GetJumpType()) + + ", index: " + std::to_string(operationInfo->GetBtnIndex())); } ANS_LOGI("DistributeOperation trigger hashcode %{public}s.", operationInfo->GetHashCode().c_str()); ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - std::string hashCode = operationInfo->GetHashCode(); - for (auto record : notificationList_) { - if (record->notification->GetKey() != hashCode) { - continue; - } - if (record->notification->GetNotificationRequestPoint() == nullptr) { - continue; - } - auto request = record->notification->GetNotificationRequestPoint(); - if (!request->GetDistributedCollaborate()) { - ANS_LOGI("Not collaborate hashcode %{public}s.", hashCode.c_str()); - continue; - } - result = NotificationSubscriberManager::GetInstance()->DistributeOperation(operationInfo, request); - return; - } - ANS_LOGI("DistributeOperation not exist hashcode."); - result = ERR_ANS_INVALID_PARAM; + result = DistributeOperationInner(operationInfo); })); notificationSvrQueue_->wait(handler); if (result != ERR_OK && operationType == OperationType::DISTRIBUTE_OPERATION_REPLY) { std::string key = operationInfo->GetHashCode() + operationInfo->GetEventId(); DistributedOperationService::GetInstance().RemoveOperationResponse(key); } + NotificationAnalyticsUtil::ReportModifyEvent(message.ErrorCode(result)); return result; #else return ERR_ANS_INVALID_PARAM; #endif } +ErrCode AdvancedNotificationService::DistributeOperationInner(const sptr& operationInfo) +{ + std::string hashCode = operationInfo->GetHashCode(); + for (auto record : notificationList_) { + if (record->notification->GetKey() != hashCode) { + continue; + } + if (record->notification->GetNotificationRequestPoint() == nullptr) { + continue; + } + auto request = record->notification->GetNotificationRequestPoint(); + if (!request->GetDistributedCollaborate()) { + ANS_LOGI("Not collaborate hashcode %{public}s.", hashCode.c_str()); + continue; + } + return NotificationSubscriberManager::GetInstance()->DistributeOperation(operationInfo, request); + } + ANS_LOGI("DistributeOperation not exist hashcode."); + return ERR_ANS_INVALID_PARAM; +} + ErrCode AdvancedNotificationService::ReplyDistributeOperation(const std::string& hashCode, const int32_t result) { #ifdef ALL_SCENARIO_COLLABORATION diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp index b300581ae..6195d0eec 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp @@ -341,6 +341,29 @@ HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_600, Functi ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.name: DistributeOperation_700 + * @tc.desc: Test DistributeOperation ERR_OK with OperationType JUMP_BY_TYPE. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_700, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + sptr bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + sptr request = new (std::nothrow) NotificationRequest(); + request->SetDistributedCollaborate(true); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + advancedNotificationService_->DeleteAll(); + advancedNotificationService_->AddToNotificationList(record); + sptr operationInfo = new (std::nothrow) NotificationOperationInfo(); + operationInfo->SetHashCode(record->notification->GetKey()); + operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_JUMP_BY_TYPE); + sptr callback = nullptr; + auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback); + ASSERT_EQ(ret, (int)ERR_OK); +} + /** * @tc.name: SetTargetDeviceStatus_100 * @tc.desc: Test SetTargetDeviceStatus when caller is not subsystem or system app. diff --git a/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp b/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp index d1ed95c2a..a72371bd4 100644 --- a/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp +++ b/services/distributed/src/soft_bus/distributed_unlock_listener_oper_service.cpp @@ -199,7 +199,7 @@ void UnlockListenerOperService::TriggerLiveViewNotification( bool UnlockListenerOperService::TriggerAncoNotification(const sptr& notificationRequest, const std::string& hashCode, const int32_t deviceType, const NotificationConstant::SlotType& slotType) { - bool triggerWantInner; + bool triggerWantInner = false; if (DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->DistributedAncoNotificationClick( notificationRequest, triggerWantInner) != ERR_OK) { return triggerWantInner; diff --git a/services/distributed/test/unittest/mock/mock_request_box.h b/services/distributed/test/unittest/mock/mock_request_box.h index dba315085..c87ece8a3 100644 --- a/services/distributed/test/unittest/mock/mock_request_box.h +++ b/services/distributed/test/unittest/mock/mock_request_box.h @@ -58,7 +58,7 @@ public: bool GetActionButtonsTitle(std::vector& buttonsTitle) const; bool GetNotificationBasicInfo(std::string& basicInfo) const; - static int32_t MAX_LINES_NUM = 7; + static const int32_t MAX_LINES_NUM = 7; }; } // namespace Notification } // namespace OHOS -- Gitee