From 4b03ff1c9a8a945439f4518e752c9b3a3be541cf Mon Sep 17 00:00:00 2001 From: linjunjie Date: Thu, 28 Aug 2025 20:52:10 +0800 Subject: [PATCH] wantAgent close want fd Signed-off-by: linjunjie --- services/abilitymgr/src/ability_manager_stub.cpp | 2 ++ services/abilitymgr/src/pending_want_manager.cpp | 4 ++++ .../want_agent_helper_test/want_agent_helper_test.cpp | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 8a29991ffe3..0428e6b2905 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1982,6 +1982,7 @@ int AbilityManagerStub::SendWantSenderInner(MessageParcel &data, MessageParcel & TAG_LOGE(AAFwkTag::ABILITYMGR, "completedData write fail"); } reply.WriteInt32(result); + senderInfo->want.CloseAllFd(); return NO_ERROR; } @@ -1994,6 +1995,7 @@ int AbilityManagerStub::SendLocalWantSenderInner(MessageParcel &data, MessagePar } int32_t result = SendLocalWantSender(*senderInfo); reply.WriteInt32(result); + senderInfo->want.CloseAllFd(); return NO_ERROR; } diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 608a24e219f..3a6f7eb3a0d 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -145,6 +145,10 @@ void PendingWantManager::MakeWantSenderCanceledLocked(PendingWantRecord &record) TAG_LOGI(AAFwkTag::WANTAGENT, "cancel"); record.SetCanceled(); + auto wantsInfo = record.GetKey()->GetAllWantsInfos(); + for (auto &wantInfo : wantsInfo) { + wantInfo.want.CloseAllFd(); + } for (auto &callback : record.GetCancelCallbacks()) { callback->Send(record.GetKey()->GetRequestCode()); } diff --git a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp index e0c54990229..2ab259e881f 100644 --- a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp @@ -1156,6 +1156,10 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_5500, Function | MediumTest | Leve WantAgentHelper::Cancel(wantAgent, FLAG_ONE_SHOT); type = WantAgentHelper::GetType(wantAgent); EXPECT_EQ(type, WantAgentConstant::OperationType::UNKNOWN_TYPE); + + WantAgentHelper::Cancel(wantAgent); + type = WantAgentHelper::GetType(wantAgent); + EXPECT_EQ(type, WantAgentConstant::OperationType::UNKNOWN_TYPE); } /* -- Gitee