diff --git a/agent_runtime_framework/services/agentmgr/BUILD.gn b/agent_runtime_framework/services/agentmgr/BUILD.gn index 4433f4af17..8ea919fa5d 100644 --- a/agent_runtime_framework/services/agentmgr/BUILD.gn +++ b/agent_runtime_framework/services/agentmgr/BUILD.gn @@ -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", ] diff --git a/agent_runtime_framework/services/agentmgr/src/agent_bundle_event_callback.cpp b/agent_runtime_framework/services/agentmgr/src/agent_bundle_event_callback.cpp index c61b7e12dd..9ce27645fb 100644 --- a/agent_runtime_framework/services/agentmgr/src/agent_bundle_event_callback.cpp +++ b/agent_runtime_framework/services/agentmgr/src/agent_bundle_event_callback.cpp @@ -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 \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/BUILD.gn b/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/BUILD.gn index 50e6597467..c9c07502ac 100644 --- a/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/BUILD.gn @@ -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" ] -} \ No newline at end of file +} diff --git a/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/agent_bundle_event_callback_test.cpp b/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/agent_bundle_event_callback_test.cpp index 0085f29820..440f6d3d1e 100644 --- a/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/agent_bundle_event_callback_test.cpp +++ b/test/unittest/agent_runtime_framework/agent_bundle_event_callback_test/agent_bundle_event_callback_test.cpp @@ -16,6 +16,7 @@ #include #include #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 diff --git a/test/unittest/agent_runtime_framework/agent_manager_service_test/BUILD.gn b/test/unittest/agent_runtime_framework/agent_manager_service_test/BUILD.gn index 88fd16df33..ffe9246e33 100644 --- a/test/unittest/agent_runtime_framework/agent_manager_service_test/BUILD.gn +++ b/test/unittest/agent_runtime_framework/agent_manager_service_test/BUILD.gn @@ -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",