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 4d87bac9f829486166758296cfddcb0387acaf2a..0a56c748513c9030350af6527355518a8dbd8ec5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -978,17 +978,22 @@ enum { */ ERR_PROCESS_START_INVALID_PID = 2097386, + /** + * Result (2097387) for not expected caller native name. + */ + ERR_NOT_EXPECTED_NATIVE_CALLER_NAME = 2097387, + + /** + * Result (2097388) for app not configured preload phase. + */ + ERR_APP_PRELOAD_PHASE_UNSET = 2097388, + ERR_DO_CLOSURE_CALLBACK_FAILED = 2097397, ERR_DMS_START_REMOTE_FAILED = 2097398, ERR_PRELOAD_APP_DATA_ABILITIES_FAILED = 2097399, - /** - * Result (2097387) for not expected caller native name. - */ - ERR_NOT_EXPECTED_NATIVE_CALLER_NAME = 2097387, - /** * Native error(3000000) for target bundle not exist. */ diff --git a/services/abilitymgr/src/preload_manager_service.cpp b/services/abilitymgr/src/preload_manager_service.cpp index e99cccf0dc2ba932ea7d1ba2a5053070cf79548c..7581238718d2b8698dbb516e0a4a9d843e397bd3 100644 --- a/services/abilitymgr/src/preload_manager_service.cpp +++ b/services/abilitymgr/src/preload_manager_service.cpp @@ -75,6 +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::ABILITY_STAGE_CREATED) { TAG_LOGI(AAFwkTag::ABILITYMGR, "preload to phase:%{public}d", static_cast(appPreloadPhase)); AppExecFwk::PreloadPhase preloadPhase = 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 2e384d5643d06aec089618462df8d47dab3fb86d..960a3fad191dfa15636b4ff8c2c605c73ee815af 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 @@ -52,18 +52,16 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_001 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = false; std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, ERR_CAPABILITY_NOT_SUPPORT); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; appIndex = -1; - result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, ERR_CAPABILITY_NOT_SUPPORT); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_001 end"); @@ -80,14 +78,12 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_002, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_002 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = false; std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, ERR_PERMISSION_DENIED); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_002 end"); @@ -104,15 +100,13 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_003, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_003 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = false; std::string bundleName = "bundleName"; int32_t userId = 102; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, ERR_CROSS_USER); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_003 end"); @@ -129,8 +123,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_004, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_004 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -138,12 +130,12 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_004, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, -1); MyStatus::GetInstance().retCheckPreloadAppRecordExist_ = ERR_OK; MyStatus::GetInstance().isPreloadApplicationRecordExist_ = true; - result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, ERR_PRELOAD_APP_RECORD_ALREADY_EXIST); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_004 end"); @@ -160,8 +152,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_005, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_005 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -171,7 +161,7 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_005, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, INNER_ERR); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_005 end"); @@ -188,8 +178,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_006, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_006 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -200,7 +188,7 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_006, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, -1); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_006 end"); @@ -217,8 +205,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_007, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_007 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -230,7 +216,7 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_007, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_007 end"); @@ -247,8 +233,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_008, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_008 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -263,7 +247,7 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_008, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, 100); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_008 end"); @@ -280,8 +264,6 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_009, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_009 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; MyStatus::GetInstance().isMultiUserConcurrency_ = true; @@ -296,10 +278,40 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_009, TestSize.Level1) std::string bundleName = "bundleName"; int32_t userId = -1; int32_t appIndex = 0; - auto result = abilityMs_->PreloadApplication(bundleName, userId, appIndex); + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); EXPECT_EQ(result, 100); TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_009 end"); } + +/* + * Feature: PreloadManagerService + * Name: PreloadApplication_010 + * Function: PreloadApplication + * SubFunction: NA + * FunctionPoints: PreloadManagerService PreloadApplication + */ +HWTEST_F(PreloadManagerServiceTest, PreloadApplication_010, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_010 start"); + + MyStatus::GetInstance().isPreloadApplicationEnabled_ = true; + MyStatus::GetInstance().retVerifyPreloadApplicationPermission_ = true; + MyStatus::GetInstance().isMultiUserConcurrency_ = true; + MyStatus::GetInstance().retCheckPreloadAppRecordExist_ = ERR_OK; + MyStatus::GetInstance().isPreloadApplicationRecordExist_ = false; + MyStatus::GetInstance().bundleMgrHelper_ = DelayedSingleton::GetInstance(); + MyStatus::GetInstance().retGetLaunchWantForBundle_ = 0; + MyStatus::GetInstance().retQueryAbilityInfo_ = true; + MyStatus::GetInstance().queryAbilityInfo_.applicationInfo.appPreloadPhase = + AppExecFwk::AppPreloadPhase::DEFAULT; + std::string bundleName = "bundleName"; + int32_t userId = -1; + int32_t appIndex = 0; + auto result = PreloadManagerService::GetInstance().PreloadApplication(bundleName, userId, appIndex); + EXPECT_EQ(result, ERR_APP_PRELOAD_PHASE_UNSET); + + TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_010 end"); +} } // namespace AAFwk } // namespace OHOS