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 0a56c748513c9030350af6527355518a8dbd8ec5..f984240d6851267c97a8cd1796b0f464c360aa25 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 7581238718d2b8698dbb516e0a4a9d843e397bd3..2cb78a59fe0f1b95c8122cd80672d3f45491146c 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 960a3fad191dfa15636b4ff8c2c605c73ee815af..41192d5917e4db52d8677ebf95961d467c474817 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"); }