From 979e5c9722d764ae0a71071cabc70a394a1f0432 Mon Sep 17 00:00:00 2001 From: "yang.yang" Date: Thu, 11 Sep 2025 21:29:17 +0800 Subject: [PATCH] add app_startup_error report Signed-off-by: yang.yang Change-Id: Iff3441ba13c45b81b3a310e51c51fd8499e98dd7 --- .../ability_runtime/app/js_ability_stage.cpp | 14 +++++++++- .../appkit/app_startup/startup_manager.cpp | 11 ++++++++ hisysevent.yaml | 9 ++++++ .../appkit/app_startup/startup_manager.h | 5 ++++ services/common/include/event_report.h | 2 ++ services/common/src/event_report.cpp | 22 ++++++++++++++- .../startup_manager_test.cpp | 28 +++++++++++++++++++ 7 files changed, 89 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp index e1361c061fd..37da1c5afcc 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp @@ -16,6 +16,7 @@ #include "js_ability_stage.h" #include "ability_delegator_registry.h" +#include "event_report.h" #include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "js_ability_stage_context.h" @@ -716,7 +717,18 @@ int32_t JsAbilityStage::RunAutoStartupTaskInner(const std::function &cal return result; } auto runAutoStartupCallback = std::make_shared( - [callback](const std::shared_ptr &) { + [callback, moduleName](const std::shared_ptr &stResult) { + if (stResult && stResult->GetResultCode() == ERR_STARTUP_TIMEOUT) { + AAFwk::EventInfo eventInfo; + eventInfo.errCode = stResult->GetResultCode(); + eventInfo.errMsg = stResult->GetResultMessage(); + eventInfo.bundleName = DelayedSingleton::GetInstance()->GetBundleName(); + eventInfo.appIndex = DelayedSingleton::GetInstance()->GetAppIndex(); + eventInfo.moduleName = moduleName; + eventInfo.userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; + AAFwk::EventReport::SendAppStartupErrorEvent( + AAFwk::EventName::APP_STARTUP_ERROR, HiSysEventType::FAULT, eventInfo); + } TAG_LOGI(AAFwkTag::APPKIT, "OnCompletedCallback"); callback(); }); diff --git a/frameworks/native/appkit/app_startup/startup_manager.cpp b/frameworks/native/appkit/app_startup/startup_manager.cpp index dc64dff7e9e..89745a62fee 100644 --- a/frameworks/native/appkit/app_startup/startup_manager.cpp +++ b/frameworks/native/appkit/app_startup/startup_manager.cpp @@ -97,6 +97,7 @@ int32_t StartupManager::PreloadAppHintStartup(const AppExecFwk::BundleInfo& bund return ERR_OK; } bundleName_ = bundleInfo.name; + appIndex_ = bundleInfo.applicationInfo.appIndex; moduleStartupConfigInfos_.emplace_back(preloadHapModuleInfo.name, preloadHapModuleInfo.appStartup, preloadHapModuleInfo.hapPath, preloadHapModuleInfo.moduleType, preloadHapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE); @@ -591,6 +592,16 @@ bool StartupManager::EnableLazyLoadingAppStartupTasks() const return enableLazyLoadingAppStartupTasks_; } +const std::string &StartupManager::GetBundleName() const +{ + return bundleName_; +} + +int StartupManager::GetAppIndex() const +{ + return appIndex_; +} + void StartupManager::PreloadAppHintStartupTask(std::shared_ptr startupTaskData) { std::map> preloadAppHintTasks; diff --git a/hisysevent.yaml b/hisysevent.yaml index 5fdb732767b..bbb3db951e4 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -393,6 +393,15 @@ APP_STARTUP_TYPE: START_TYPE: {type: INT32, desc: 'type of start, cold or hot'} START_REASON: {type: INT32, desc: start reason} +APP_STARTUP_ERROR: + __BASE: {type: FAULT, level: CRITICAL, tag: app, desc: app startup error} + BUNDLE_NAME: {type: STRING, desc: bundle name} + ERROR_CODE: {type: INT32, desc: error code} + MODULE_NAME: {type: STRING, desc: module name} + USER_ID: {type: INT32, desc: userId} + APP_INDEX: {type: INT32, desc: app index} + ERROR_MESSAGE: {type: STRING, desc: error message} + PROCESS_START: __BASE: {type: BEHAVIOR, level: MINOR, tag: app, desc: application process startup event reporting} STARTUP_TIME: {type: INT64, desc: process start time} diff --git a/interfaces/kits/native/appkit/app_startup/startup_manager.h b/interfaces/kits/native/appkit/app_startup/startup_manager.h index e4532b1b0ce..655280a6847 100644 --- a/interfaces/kits/native/appkit/app_startup/startup_manager.h +++ b/interfaces/kits/native/appkit/app_startup/startup_manager.h @@ -101,10 +101,15 @@ public: bool EnableLazyLoadingAppStartupTasks() const; + const std::string &GetBundleName() const; + + int32_t GetAppIndex() const; + private: // read only after initialization std::vector moduleStartupConfigInfos_; std::string bundleName_; + int32_t appIndex_; std::mutex appStartupConfigInitializationMutex_; std::atomic isAppStartupConfigInited_ = false; diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index 8df05a04a55..d20827fe99d 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -88,6 +88,7 @@ enum class EventName { EXECUTE_INSIGHT_INTENT_ERROR, STARTUP_TASK_ERROR, START_ABILITY_SYSTEM_ERROR, + APP_STARTUP_ERROR, // ability behavior event START_ABILITY, @@ -160,6 +161,7 @@ public: static void SendLaunchFrameworkEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); static void SendReportDataPartitionUsageEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); + static void SendAppStartupErrorEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); private: static std::string ConvertEventName(const EventName &eventName); diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 3c7d231483d..548594b01ad 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -866,6 +866,26 @@ void EventReport::SendReportDataPartitionUsageEvent(const EventName &eventName, EVENT_FILE_OR_FOLDER_SIZE, eventInfo.fileOfFolderSize); } +void EventReport::SendAppStartupErrorEvent(const EventName &eventName, HiSysEventType type, + const EventInfo &eventInfo) +{ + std::string name = ConvertEventName(eventName); + if (name == INVALID_EVENT_NAME) { + TAG_LOGE(AAFwkTag::DEFAULT, "invalid eventName"); + return; + } + HiSysEventWrite( + HiSysEvent::Domain::AAFWK, + name, + type, + EVENT_KEY_USERID, eventInfo.userId, + EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName, + EVENT_KEY_MODULE_NAME, eventInfo.moduleName, + EVENT_KEY_ERROR_CODE, eventInfo.errCode, + EVENT_KEY_APP_INDEX, eventInfo.appIndex, + EVENT_KEY_ERROR_MESSAGE, eventInfo.errMsg); +} + std::string EventReport::ConvertEventName(const EventName &eventName) { const char* eventNames[] = { @@ -873,7 +893,7 @@ std::string EventReport::ConvertEventName(const EventName &eventName) "START_ABILITY_ERROR", "TERMINATE_ABILITY_ERROR", "START_EXTENSION_ERROR", "STOP_EXTENSION_ERROR", "CONNECT_SERVICE_ERROR", "DISCONNECT_SERVICE_ERROR", "UI_EXTENSION_ERROR", "UI_SERVICE_EXTENSION_ERROR", "EXECUTE_INSIGHT_INTENT_ERROR", - "STARTUP_TASK_ERROR", "START_ABILITY_SYSTEM_ERROR", + "STARTUP_TASK_ERROR", "START_ABILITY_SYSTEM_ERROR", "APP_STARTUP_ERROR", // ability behavior event "START_ABILITY", "TERMINATE_ABILITY", "CLOSE_ABILITY", diff --git a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp index c95dc202908..0e58f0f4f7b 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp @@ -1448,6 +1448,34 @@ HWTEST_F(StartupManagerTest, EnableLazyLoadingAppStartupTasks_001, Function | Me GTEST_LOG_(INFO) << "EnableLazyLoadingAppStartupTasks_001 end"; } +/** + * @tc.name: GetBundleName_001 + * @tc.desc: test GetBundleName + * @tc.type: FUNC + */ +HWTEST_F(StartupManagerTest, GetBundleName_001, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "GetBundleName_001 start"; + std::shared_ptr startupManager = DelayedSingleton::GetInstance(); + ASSERT_NE(startupManager, nullptr); + EXPECT_EQ(startupManager->GetBundleName(), startupManager->bundleName_); + GTEST_LOG_(INFO) << "GetBundleName_001 end"; +} + +/** + * @tc.name: GetAppIndex_001 + * @tc.desc: test GetAppIndex + * @tc.type: FUNC + */ +HWTEST_F(StartupManagerTest, GetAppIndex_001, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppIndex_001 start"; + std::shared_ptr startupManager = DelayedSingleton::GetInstance(); + ASSERT_NE(startupManager, nullptr); + EXPECT_EQ(startupManager->GetAppIndex(), startupManager->appIndex_); + GTEST_LOG_(INFO) << "GetAppIndex_001 end"; +} + /** * @tc.name: SetSchedulerPhase_0100 * @tc.desc: test SetSchedulerPhase -- Gitee