diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 65917fbc6acc467f1c398954254c7503ac826995..02884480a0c9b0b0bbf9a7fc68c3401ec28f3ff4 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1046,6 +1046,8 @@ public: virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr &connect, const sptr &callerToken, int32_t accountId, std::string &errMsg, bool isSilent = false) override; + int32_t StartAbilityByCallWithErrMsgInner(const Want &want, sptr connect, + sptr callerToken, int32_t accountId, std::string &errMsg, bool isSilent = false); /** * As abilityRequest is prepared, just execute starting ability procedure. diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 48a6ef40299be3965b3029b30f3ec9aaa1b7e423..4f101629143a71b21556222da17d18ca35726d12 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -8722,6 +8722,18 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr &connect, const sptr &callerToken, int32_t accountId, std::string &errMsg, bool isSilent) +{ + auto ret = StartAbilityByCallWithErrMsgInner(want, connect, callerToken, accountId, errMsg, isSilent); + if (ret != ERR_OK) { + EventInfo eventInfo = BuildEventInfo(want, accountId); + eventInfo.startType = START_ABILITY_TYPE_BY_CALL; + eventHelper_.SendStartAbilityErrorEvent(eventInfo, ret, errMsg); + } + return ret; +} + +int32_t AbilityManagerService::StartAbilityByCallWithErrMsgInner(const Want &want, sptr connect, + sptr callerToken, int32_t accountId, std::string &errMsg, bool isSilent) { if (AppUtils::GetInstance().IsForbidStart()) { TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str()); diff --git a/services/abilitymgr/src/utils/ability_event_util.cpp b/services/abilitymgr/src/utils/ability_event_util.cpp index 2909e3d2f16fecd69d2ecda2434419d253dc7b05..d57fccb2a233e5f34d813a3fc5c12bc831f32c31 100644 --- a/services/abilitymgr/src/utils/ability_event_util.cpp +++ b/services/abilitymgr/src/utils/ability_event_util.cpp @@ -14,6 +14,7 @@ */ #include "ability_event_util.h" +#include "ability_util.h" #include "app_scheduler.h" #include "hilog_tag_wrapper.h" @@ -37,6 +38,13 @@ void AbilityEventUtil::SendStartAbilityErrorEvent(EventInfo &eventInfo, int32_t EventName name = isSystemError ? EventName::START_ABILITY_SYSTEM_ERROR : EventName::START_ABILITY_ERROR; eventInfo.errCode = errCode; eventInfo.errMsg = errMsg; + int32_t callerUid = IPCSkeleton::GetCallingUid(); + std::string callerBundleName; + auto bundleMgr = AbilityUtil::GetBundleManagerHelper(); + if (bundleMgr != nullptr) { + IN_PROCESS_CALL(bundleMgr->GetNameForUid(callerUid, callerBundleName)); + } + eventInfo.callerBundleName = callerBundleName.empty() ? std::to_string(callerUid) : callerBundleName; ffrt::submit([name, eventInfo]() { EventReport::SendAbilityEvent(name, HiSysEventType::FAULT, eventInfo); }, ffrt::task_attr().timeout(FFRT_TASK_TIMEOUT)); diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index 8df05a04a5561cb01c706ca8e031ee60a8da9c6a..3b4b0a3b56763bd36c52b427c399821ecce26e20 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -137,6 +137,11 @@ enum class EventName { USER_DATA_SIZE }; +enum StartAbilityType { + START_ABILITY_TYPE_NORMAL = 0, + START_ABILITY_TYPE_BY_CALL = 1 +}; + class EventReport { public: static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 3c7d231483d65c99248ab504f439bad342129ae7..516178dd81238f7d47777132403df48e9472e57a 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -158,7 +158,8 @@ void EventReport::LogStartErrorEvent(const std::string &name, HiSysEventType typ EVENT_KEY_ABILITY_NAME, eventInfo.abilityName, EVENT_KEY_ERROR_CODE, eventInfo.errCode, EVENT_KEY_ERROR_MESSAGE, eventInfo.errMsg, - EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName); + EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName, + EVENT_KEY_START_TYPE, eventInfo.startType); } void EventReport::LogSystemErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo) diff --git a/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn b/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn index 32a5c85235f14b0dbcf6c5b320b22d1b12f23f62..cb5f4db1448ad0897fbcd6dc99995baa4a82293e 100644 --- a/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("AbilityEventUtilFuzzTest") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:task_handler_wrap", diff --git a/test/unittest/ability_event_util_test/BUILD.gn b/test/unittest/ability_event_util_test/BUILD.gn index cce726809bbcf1dabe88ed674e364a849d24407e..f1b5bc35c7745a024c7f41131450849f71ec0c8f 100644 --- a/test/unittest/ability_event_util_test/BUILD.gn +++ b/test/unittest/ability_event_util_test/BUILD.gn @@ -20,6 +20,7 @@ ohos_unittest("ability_event_util_test") { module_out_path = module_output_path include_dirs = [ + "mock/include", "${ability_runtime_innerkits_path}/ability_manager/include", "${ability_runtime_services_path}/abilitymgr/include/utils", "${ability_runtime_services_path}/abilitymgr/include", @@ -43,6 +44,7 @@ ohos_unittest("ability_event_util_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:task_handler_wrap", diff --git a/test/unittest/ability_event_util_test/ability_event_util_test.cpp b/test/unittest/ability_event_util_test/ability_event_util_test.cpp index d2a5b5d125d799b3e139b71b39e5ecd938b2a6ce..ba4ea18b24e1cf3b30ad92fc861b949834a4ebcb 100644 --- a/test/unittest/ability_event_util_test/ability_event_util_test.cpp +++ b/test/unittest/ability_event_util_test/ability_event_util_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "ability_util.h" #define private public #include "ability_event_util.h" #undef private @@ -29,6 +30,17 @@ using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; namespace OHOS { +namespace AAFwk { +bool AbilityUtil::s_bundleHelperStatus = true; +std::shared_ptr AbilityUtil::GetBundleManagerHelper() +{ + if (s_bundleHelperStatus) { + return DelayedSingleton::GetInstance(); + } + return nullptr; +} +} // namespace AAFwk + namespace AbilityRuntime { class AbilityEventUtilTest : public testing::Test { public: @@ -97,6 +109,26 @@ HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0300, Test TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0300 end"); } +/** + * @tc.name: AbilityEventUtil_SendStartAbilityError_0400 + * @tc.desc: SendKillProcessWithReasonEvent + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0400, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0400 start"); + std::shared_ptr eventUtil = std::make_shared(); + EventInfo eventInfo = {}; + int32_t errCode = 0; + std::string errMsg = "test event"; + AbilityUtil::s_bundleHelperStatus = false; + eventUtil->SendStartAbilityErrorEvent(eventInfo, errCode, errMsg); + EXPECT_EQ(eventInfo.userId, -1); + AbilityUtil::s_bundleHelperStatus = true; + TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0400 end"); +} + /** * @tc.name: AbilityEventUtil_SendKillProcessWithReasonEvent_0100 * @tc.desc: SendKillProcessWithReasonEvent diff --git a/test/unittest/ability_event_util_test/mock/include/ability_util.h b/test/unittest/ability_event_util_test/mock/include/ability_util.h new file mode 100644 index 0000000000000000000000000000000000000000..4fe008d361e84c8255507b75e4166058412dc8da --- /dev/null +++ b/test/unittest/ability_event_util_test/mock/include/ability_util.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H +#define OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H、 + +#include "bundle_mgr_helper.h" +#include "in_process_call_wrapper.h" +#include "ipc_skeleton.h" + +namespace OHOS::AAFwk { +class AbilityUtil { +public: + static bool s_bundleHelperStatus; + static std::shared_ptr GetBundleManagerHelper(); +}; +} // namespace OHOS::AAFwk +#endif // OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H \ No newline at end of file diff --git a/test/unittest/ability_manager_service_mock_test/BUILD.gn b/test/unittest/ability_manager_service_mock_test/BUILD.gn index 97b7c32619cb2c4c456ebae34059ee83e22e5d78..f6324a5c19c46006074aaf31114a495a3a649632 100644 --- a/test/unittest/ability_manager_service_mock_test/BUILD.gn +++ b/test/unittest/ability_manager_service_mock_test/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("ability_manager_service_mock_test") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/insight_intent/insight_intent_utils_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_utils_test/BUILD.gn index 88c0ecdfda1c0fa5af1ea6a04c9241bebd43aca3..80c906c2fbac7d3ae81edcbdd193dafa816852ec 100644 --- a/test/unittest/insight_intent/insight_intent_utils_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_utils_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# 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 @@ -47,6 +47,7 @@ ohos_unittest("insight_intent_utils_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/abilitymgr:wantagent_manager", "${ability_runtime_services_path}/common:app_util",