From 26176abe4b34092f5141aad1d23ac839fbb1fa0b Mon Sep 17 00:00:00 2001 From: Nathan Yang Date: Wed, 13 Aug 2025 16:55:33 +0800 Subject: [PATCH] bugfix: add preload phase check Signed-off-by: Nathan Yang --- .../ability_manager/include/ability_manager_errors.h | 2 +- services/abilitymgr/src/preload_manager_service.cpp | 7 ++++--- .../preload_manager_service_test.cpp | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 0a56c748513..f984240d685 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -986,7 +986,7 @@ enum { /** * Result (2097388) for app not configured preload phase. */ - ERR_APP_PRELOAD_PHASE_UNSET = 2097388, + ERR_INVALID_APP_PRELOAD_PHASE = 2097388, ERR_DO_CLOSURE_CALLBACK_FAILED = 2097397, diff --git a/services/abilitymgr/src/preload_manager_service.cpp b/services/abilitymgr/src/preload_manager_service.cpp index 7581238718d..2cb78a59fe0 100644 --- a/services/abilitymgr/src/preload_manager_service.cpp +++ b/services/abilitymgr/src/preload_manager_service.cpp @@ -75,9 +75,10 @@ int32_t PreloadManagerService::PreloadApplication(const std::string &bundleName, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, abilityInfo)), RESOLVE_ABILITY_ERR, "failed to get abilityInfo"); AppExecFwk::AppPreloadPhase appPreloadPhase = abilityInfo.applicationInfo.appPreloadPhase; - if (appPreloadPhase == AppExecFwk::AppPreloadPhase::DEFAULT) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "preload phase not set"); - return ERR_APP_PRELOAD_PHASE_UNSET; + if (appPreloadPhase <= AppExecFwk::AppPreloadPhase::DEFAULT || + appPreloadPhase > AppExecFwk::AppPreloadPhase::WINDOW_STAGE_CREATED) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid preload phase:%{public}d", static_cast(appPreloadPhase)); + return ERR_INVALID_APP_PRELOAD_PHASE; } if (appPreloadPhase <= AppExecFwk::AppPreloadPhase::ABILITY_STAGE_CREATED) { TAG_LOGI(AAFwkTag::ABILITYMGR, "preload to phase:%{public}d", static_cast(appPreloadPhase)); diff --git a/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp b/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp index 960a3fad191..41192d5917e 100644 --- a/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp +++ b/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp @@ -309,7 +309,11 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_010, TestSize.Level1) int32_t userId = -1; int32_t appIndex = 0; auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); - EXPECT_EQ(result, ERR_APP_PRELOAD_PHASE_UNSET); + EXPECT_EQ(result, ERR_INVALID_APP_PRELOAD_PHASE); + + MyStatus::GetInstance().queryAbilityInfo_.applicationInfo.appPreloadPhase = AppExecFwk::AppPreloadPhase(100); + result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); + EXPECT_EQ(result, ERR_INVALID_APP_PRELOAD_PHASE); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_010 end"); } -- Gitee