bugfix: AgentBundleEvent ignore appClone events

Co-Authored-By: Agent

Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
yangxuguang-huawei
2026-03-21 09:15:20 +08:00
parent 160a3e3ff1
commit 230232e978
5 changed files with 59 additions and 4 deletions
@@ -26,6 +26,7 @@ ohos_shared_library("agentmgr") {
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
"${ability_runtime_path}/utils/global/constant",
"${ability_runtime_services_path}/common/include",
"${agent_runtime_framework_path}/interfaces/kits/native/agent_extension/connection/include",
]
@@ -16,10 +16,14 @@
#include "agent_bundle_event_callback.h"
#include "agent_card_mgr.h"
#include "global_constant.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AgentRuntime {
namespace {
constexpr const char* APP_INDEX = "appIndex";
}
void AgentBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData)
{
@@ -29,6 +33,7 @@ void AgentBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData ev
std::string bundleName = want.GetElement().GetBundleName();
int32_t userId = want.GetIntParam("userId", 0);
int32_t uid = want.GetIntParam("uid", 0);
int32_t appIndex = want.GetIntParam(APP_INDEX, 0);
// verify data
if (action.empty()) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "OnReceiveEvent failed, empty action");
@@ -40,8 +45,15 @@ void AgentBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData ev
return;
}
TAG_LOGI(AAFwkTag::SER_ROUTER, "bundleName:%{public}s, action:%{public}s, userId:%{public}d, uid:%{public}d",
bundleName.c_str(), action.c_str(), userId, uid);
TAG_LOGI(AAFwkTag::SER_ROUTER,
"bundleName:%{public}s, action:%{public}s, userId:%{public}d, uid:%{public}d, appIndex:%{public}d",
bundleName.c_str(), action.c_str(), userId, uid, appIndex);
if (appIndex > 0 && appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGI(AAFwkTag::SER_ROUTER, "ignore clone bundle event, bundleName:%{public}s, appIndex:%{public}d",
bundleName.c_str(), appIndex);
return;
}
if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) {
AgentCardMgr::GetInstance().HandleBundleInstall(bundleName, userId);
@@ -59,4 +71,4 @@ void AgentBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData ev
}
}
} // namespace AgentRuntime
} // namespace OHOS
} // namespace OHOS
@@ -32,6 +32,7 @@ ohos_unittest("agent_bundle_event_callback_test") {
include_dirs = [
"mock/include",
"${ability_runtime_services_path}/common/include",
"${ability_runtime_path}/utils/global/constant",
"${agent_runtime_framework_path}/interfaces/inner_api/include",
"${agent_runtime_framework_path}/services/agentmgr/include",
]
@@ -61,4 +62,4 @@ ohos_unittest("agent_bundle_event_callback_test") {
group("unittest") {
testonly = true
deps = [ ":agent_bundle_event_callback_test" ]
}
}
@@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "agent_bundle_event_callback.h"
#include "global_constant.h"
#include "want.h"
using namespace OHOS;
@@ -131,5 +132,44 @@ HWTEST_F(AgentBundleEventCallbackTest, OnReceiveEventTest_004, TestSize.Level1)
bundleEventCallback.OnReceiveEvent(eventData);
EXPECT_EQ(eventData.GetWant().GetAction(), "ohos.intent.action.UNKNOWN");
}
/**
* @tc.name: OnReceiveEventTest_005
* @tc.desc: Verify clone app package event is ignored.
* @tc.type: FUNC
* @tc.require: AR000H1N32
*/
HWTEST_F(AgentBundleEventCallbackTest, OnReceiveEventTest_005, TestSize.Level1)
{
AgentBundleEventCallback bundleEventCallback;
EventFwk::CommonEventData eventData;
Want want;
want.SetBundle("test");
want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
want.SetParam("appIndex", 1);
eventData.SetWant(want);
bundleEventCallback.OnReceiveEvent(eventData);
EXPECT_EQ(eventData.GetWant().GetIntParam("appIndex", 0), 1);
}
/**
* @tc.name: OnReceiveEventTest_006
* @tc.desc: Verify sandbox app package event still reaches normal flow.
* @tc.type: FUNC
* @tc.require: AR000H1N32
*/
HWTEST_F(AgentBundleEventCallbackTest, OnReceiveEventTest_006, TestSize.Level1)
{
AgentBundleEventCallback bundleEventCallback;
EventFwk::CommonEventData eventData;
Want want;
want.SetBundle("test");
want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
want.SetParam("appIndex", AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX + 1);
eventData.SetWant(want);
bundleEventCallback.OnReceiveEvent(eventData);
EXPECT_EQ(eventData.GetWant().GetIntParam("appIndex", 0),
AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX + 1);
}
} // namespace AgentRuntime
} // namespace OHOS
@@ -43,6 +43,7 @@ ohos_unittest("agent_manager_service_test") {
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/utils/global/constant",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/common/include",
"${agent_runtime_framework_path}/interfaces/inner_api/include",