diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 214621187167d87a059366b82214d5385cabd44b..793736a5e653cb70b06f4c6824586692c8c7122b 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -568,7 +568,7 @@ private: ErrCode ProcessAsanDirectory(InnerBundleInfo &info) const; ErrCode CleanAsanDirectory(InnerBundleInfo &info) const; void AddAppProvisionInfo(const std::string &bundleName, - const Security::Verify::ProvisionInfo &provisionInfo) const; + const Security::Verify::ProvisionInfo &provisionInfo, const InstallParam &installParam) const; ErrCode UninstallHspBundle(std::string &uninstallDir, const std::string &bundleName); ErrCode UninstallHspVersion(std::string &uninstallDir, int32_t versionCode, InnerBundleInfo &info); ErrCode CheckProxyDatas(const std::unordered_map &newInfos); diff --git a/services/bundlemgr/include/shared/inner_shared_bundle_installer.h b/services/bundlemgr/include/shared/inner_shared_bundle_installer.h index 6c4710a3cddaedac8ff7e9d1ef0e828a2da49627..2780c3ddd19bc990c01120f68880ee7beb497868 100644 --- a/services/bundlemgr/include/shared/inner_shared_bundle_installer.h +++ b/services/bundlemgr/include/shared/inner_shared_bundle_installer.h @@ -89,6 +89,7 @@ private: void GetInstallEventInfo(EventInfo &eventInfo) const; void AddAppProvisionInfo(const std::string &bundleName, const Security::Verify::ProvisionInfo &provisionInfo) const; + void SaveInstallParamInfo(const std::string &bundleName, const InstallParam &installParam) const; // the real path or the parent directory of hsp files to be installed. std::string sharedBundlePath_; diff --git a/services/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp b/services/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp index 8da2b6779d8f696b089940eb2ab6ee8b1e925de8..c01b9bde352f1df0bff469850566409ce01012c8 100644 --- a/services/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp +++ b/services/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp @@ -38,6 +38,7 @@ const std::string VALIDITY_NOT_BEFORE = "VALIDITY_NOT_BEFORE"; const std::string VALIDITY_NOT_AFTER = "VALIDITY_NOT_AFTER"; const std::string SPECIFIED_DISTRIBUTED_TYPE = "SPECIFIED_DISTRIBUTED_TYPE"; const std::string ADDITIONAL_INFO = "ADDITIONAL_INFO"; +const std::string DEFAULT_VALUE = ""; const int32_t INDEX_BUNDLE_NAME = 0; const int32_t INDEX_VERSION_CODE = 1; const int32_t INDEX_VERSION_NAME = 2; @@ -97,6 +98,8 @@ bool AppProvisionInfoManagerRdb::AddAppProvisionInfo(const std::string &bundleNa valuesBucket.PutString(ISSUER, appProvisionInfo.issuer); valuesBucket.PutLong(VALIDITY_NOT_BEFORE, appProvisionInfo.validity.notBefore); valuesBucket.PutLong(VALIDITY_NOT_AFTER, appProvisionInfo.validity.notAfter); + valuesBucket.PutString(SPECIFIED_DISTRIBUTED_TYPE, DEFAULT_VALUE); + valuesBucket.PutString(ADDITIONAL_INFO, DEFAULT_VALUE); return rdbDataManager_->InsertData(valuesBucket); } diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 8478338679f64428ea1ff93de5962cf824cf90b7..5dcbc994fc5907180c08fe83be8514868b133c0f 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -884,7 +884,7 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector #endif OnSingletonChange(installParam.noSkipsKill); GetInstallEventInfo(newInfos, sysEventInfo_); - AddAppProvisionInfo(bundleName_, hapVerifyResults[0].GetProvisionInfo()); + AddAppProvisionInfo(bundleName_, hapVerifyResults[0].GetProvisionInfo(), installParam); sync(); return result; } @@ -3376,13 +3376,26 @@ ErrCode BaseBundleInstaller::CleanAsanDirectory(InnerBundleInfo &info) const } void BaseBundleInstaller::AddAppProvisionInfo(const std::string &bundleName, - const Security::Verify::ProvisionInfo &provisionInfo) const + const Security::Verify::ProvisionInfo &provisionInfo, + const InstallParam &installParam) const { AppProvisionInfo appProvisionInfo = bundleInstallChecker_->ConvertToAppProvisionInfo(provisionInfo); if (!DelayedSingleton::GetInstance()->AddAppProvisionInfo( bundleName, appProvisionInfo)) { APP_LOGW("bundleName: %{public}s add appProvisionInfo failed.", bundleName.c_str()); } + if (!installParam.specifiedDistributionType.empty()) { + if (!DelayedSingleton::GetInstance()->SetSpecifiedDistributionType( + bundleName, installParam.specifiedDistributionType)) { + APP_LOGW("bundleName: %{public}s SetSpecifiedDistributionType failed.", bundleName.c_str()); + } + } + if (!installParam.additionalInfo.empty()) { + if (!DelayedSingleton::GetInstance()->SetAdditionalInfo( + bundleName, installParam.additionalInfo)) { + APP_LOGW("bundleName: %{public}s SetAdditionalInfo failed.", bundleName.c_str()); + } + } } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 7495c1a80db03517f0e8983ef228ae5cece8129b..e1e7e18760e69726b42db87e7b99933db7b4500f 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -4479,9 +4479,11 @@ ErrCode BundleDataMgr::GetAppProvisionInfo(const std::string &bundleName, int32_ if (infoItem == bundleInfos_.end()) { return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } - int32_t responseUserId = infoItem->second.GetResponseUserId(userId); - if (responseUserId == Constants::INVALID_USERID) { - return ERR_BUNDLE_MANAGER_INVALID_USER_ID; + if (infoItem->second.GetApplicationBundleType() != BundleType::SHARED) { + int32_t responseUserId = infoItem->second.GetResponseUserId(userId); + if (responseUserId == Constants::INVALID_USERID) { + return ERR_BUNDLE_MANAGER_INVALID_USER_ID; + } } if (!DelayedSingleton::GetInstance()->GetAppProvisionInfo(bundleName, appProvisionInfo)) { APP_LOGE("bundleName:%{public}s GetAppProvisionInfo failed.", bundleName.c_str()); @@ -4699,11 +4701,13 @@ ErrCode BundleDataMgr::GetSpecifiedDistributionType( APP_LOGE("bundleName: %{public}s does not exist", bundleName.c_str()); return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } - int32_t userId = AccountHelper::GetCurrentActiveUserId(); - int32_t responseUserId = infoItem->second.GetResponseUserId(userId); - if (responseUserId == Constants::INVALID_USERID) { - APP_LOGE("bundleName: %{public}s does not exist in current userId", bundleName.c_str()); - return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + if (infoItem->second.GetApplicationBundleType() != BundleType::SHARED) { + int32_t userId = AccountHelper::GetCurrentActiveUserId(); + int32_t responseUserId = infoItem->second.GetResponseUserId(userId); + if (responseUserId == Constants::INVALID_USERID) { + APP_LOGE("bundleName: %{public}s does not exist in current userId", bundleName.c_str()); + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + } } if (!DelayedSingleton::GetInstance()->GetSpecifiedDistributionType(bundleName, specifiedDistributionType)) { @@ -4723,11 +4727,13 @@ ErrCode BundleDataMgr::GetAdditionalInfo( APP_LOGE("bundleName: %{public}s does not exist", bundleName.c_str()); return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } - int32_t userId = AccountHelper::GetCurrentActiveUserId(); - int32_t responseUserId = infoItem->second.GetResponseUserId(userId); - if (responseUserId == Constants::INVALID_USERID) { - APP_LOGE("bundleName: %{public}s does not exist in current userId", bundleName.c_str()); - return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + if (infoItem->second.GetApplicationBundleType() != BundleType::SHARED) { + int32_t userId = AccountHelper::GetCurrentActiveUserId(); + int32_t responseUserId = infoItem->second.GetResponseUserId(userId); + if (responseUserId == Constants::INVALID_USERID) { + APP_LOGE("bundleName: %{public}s does not exist in current userId", bundleName.c_str()); + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + } } if (!DelayedSingleton::GetInstance()->GetAdditionalInfo(bundleName, additionalInfo)) { diff --git a/services/bundlemgr/src/shared/inner_shared_bundle_installer.cpp b/services/bundlemgr/src/shared/inner_shared_bundle_installer.cpp index 2c674e374befcdfa8998de2cde0ac243ad61afc5..546034f2a3786f475a8f81c9e2fb411b7b935303 100644 --- a/services/bundlemgr/src/shared/inner_shared_bundle_installer.cpp +++ b/services/bundlemgr/src/shared/inner_shared_bundle_installer.cpp @@ -100,6 +100,9 @@ ErrCode InnerSharedBundleInstaller::Install(const InstallParam &installParam) result = SaveBundleInfoToStorage(); CHECK_RESULT(result, "save bundle info to storage failed %{public}d"); + // save specifiedDistributionType and additionalInfo + SaveInstallParamInfo(bundleName_, installParam); + APP_LOGD("install shared bundle successfully: %{public}s", bundleName_.c_str()); return result; } @@ -395,5 +398,22 @@ void InnerSharedBundleInstaller::AddAppProvisionInfo(const std::string &bundleNa APP_LOGW("bundleName: %{public}s add appProvisionInfo failed.", bundleName.c_str()); } } + +void InnerSharedBundleInstaller::SaveInstallParamInfo( + const std::string &bundleName, const InstallParam &installParam) const +{ + if (!installParam.specifiedDistributionType.empty()) { + if (!DelayedSingleton::GetInstance()->SetSpecifiedDistributionType( + bundleName, installParam.specifiedDistributionType)) { + APP_LOGW("bundleName: %{public}s SetSpecifiedDistributionType failed.", bundleName.c_str()); + } + } + if (!installParam.additionalInfo.empty()) { + if (!DelayedSingleton::GetInstance()->SetAdditionalInfo( + bundleName, installParam.additionalInfo)) { + APP_LOGW("bundleName: %{public}s SetAdditionalInfo failed.", bundleName.c_str()); + } + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp index 0745bd17709e6d88a91edfa21259ebc2b572af45..39b220ee4d37e0fbac0b202084619d0f6f0ec99d 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp @@ -30,6 +30,7 @@ #include "bundle_permission_mgr.h" #include "bundle_verify_mgr.h" #include "inner_bundle_info.h" +#include "inner_shared_bundle_installer.h" #include "installd/installd_service.h" #include "installd_client.h" #include "mock_status_receiver.h" @@ -412,7 +413,8 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0001, Function | Sma BaseBundleInstaller baseBundleInstaller; Security::Verify::ProvisionInfo appProvisionInfo; std::string bundleName = ""; - baseBundleInstaller.AddAppProvisionInfo(bundleName, appProvisionInfo); + InstallParam installParam; + baseBundleInstaller.AddAppProvisionInfo(bundleName, appProvisionInfo, installParam); AppProvisionInfo newProvisionInfo; bool ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(bundleName, newProvisionInfo); @@ -421,14 +423,36 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0001, Function | Sma /** * @tc.number: AddAppProvisionInfo_0002 - * @tc.name: test the start function of AddAppProvisionInfo and DeleteAppProvisionInfo + * @tc.name: test the start function of AddAppProvisionInfo * @tc.desc: 1. BaseBundleInstaller */ HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0002, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; Security::Verify::ProvisionInfo appProvisionInfo; - baseBundleInstaller.AddAppProvisionInfo(BUNDLE_NAME, appProvisionInfo); + std::string bundleName = ""; + InstallParam installParam; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + baseBundleInstaller.AddAppProvisionInfo(bundleName, appProvisionInfo, installParam); + AppProvisionInfo newProvisionInfo; + bool ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(bundleName, + newProvisionInfo); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: AddAppProvisionInfo_0003 + * @tc.name: test the start function of AddAppProvisionInfo and DeleteAppProvisionInfo + * @tc.desc: 1. BaseBundleInstaller +*/ +HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0003, Function | SmallTest | Level0) +{ + BaseBundleInstaller baseBundleInstaller; + Security::Verify::ProvisionInfo appProvisionInfo; + InstallParam installParam; + installParam.specifiedDistributionType = "specifiedDistributionType"; + baseBundleInstaller.AddAppProvisionInfo(BUNDLE_NAME, appProvisionInfo, installParam); AppProvisionInfo newProvisionInfo; bool ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(BUNDLE_NAME, newProvisionInfo); @@ -437,6 +461,40 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0002, Function | Sma EXPECT_TRUE(ret); } +/** + * @tc.number: AddAppProvisionInfo_0004 + * @tc.name: test the start function of AddAppProvisionInfo + * @tc.desc: 1. BaseBundleInstaller +*/ +HWTEST_F(BmsBundleAppProvisionInfoTest, AddAppProvisionInfo_0004, Function | SmallTest | Level0) +{ + BaseBundleInstaller baseBundleInstaller; + Security::Verify::ProvisionInfo appProvisionInfo; + InstallParam installParam; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + baseBundleInstaller.AddAppProvisionInfo(BUNDLE_NAME, appProvisionInfo, installParam); + AppProvisionInfo newProvisionInfo; + bool ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(BUNDLE_NAME, + newProvisionInfo); + EXPECT_TRUE(ret); + + std::string specifiedDistributionType; + ret = DelayedSingleton::GetInstance()->GetSpecifiedDistributionType(BUNDLE_NAME, + specifiedDistributionType); + EXPECT_TRUE(ret); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + + std::string additionalInfo; + ret = DelayedSingleton::GetInstance()->GetAdditionalInfo(BUNDLE_NAME, + additionalInfo); + EXPECT_TRUE(ret); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + + ret = DelayedSingleton::GetInstance()->DeleteAppProvisionInfo(BUNDLE_NAME); + EXPECT_TRUE(ret); +} + /** * @tc.number: SetSpecifiedDistributionType_0001 * @tc.name: test the start function of SetSpecifiedDistributionType @@ -544,7 +602,7 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, GetAdditionalInfo_0001, Function | Small } /** - * @tc.number: GGetAdditionalInfo_0002 + * @tc.number: GetAdditionalInfo_0002 * @tc.name: test the start function of GetAdditionalInfo */ HWTEST_F(BmsBundleAppProvisionInfoTest, GetAdditionalInfo_0002, Function | SmallTest | Level0) @@ -554,4 +612,68 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, GetAdditionalInfo_0002, Function | Small additionalInfo); EXPECT_FALSE(ret); } + +/** + * @tc.number: SaveInstallParamInfo_0001 + * @tc.name: test the start function of SaveInstallParamInfo +*/ +HWTEST_F(BmsBundleAppProvisionInfoTest, SaveInstallParamInfo_0001, Function | SmallTest | Level0) +{ + InnerSharedBundleInstaller installer(HAP_FILE_PATH1); + InstallParam installParam; + installer.SaveInstallParamInfo(BUNDLE_NAME, installParam); + std::string specifiedDistributionType; + bool ret = DelayedSingleton::GetInstance()->GetSpecifiedDistributionType(BUNDLE_NAME, + specifiedDistributionType); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: SaveInstallParamInfo_0002 + * @tc.name: test the start function of SaveInstallParamInfo +*/ +HWTEST_F(BmsBundleAppProvisionInfoTest, SaveInstallParamInfo_0002, Function | SmallTest | Level0) +{ + InnerSharedBundleInstaller installer(HAP_FILE_PATH1); + InstallParam installParam; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + installer.SaveInstallParamInfo(BUNDLE_NAME, installParam); + std::string specifiedDistributionType; + bool ret = DelayedSingleton::GetInstance()->GetSpecifiedDistributionType(BUNDLE_NAME, + specifiedDistributionType); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: SaveInstallParamInfo_0003 + * @tc.name: test the start function of SaveInstallParamInfo +*/ +HWTEST_F(BmsBundleAppProvisionInfoTest, SaveInstallParamInfo_0003, Function | SmallTest | Level0) +{ + AppProvisionInfo appProvisionInfo; + bool ret = DelayedSingleton::GetInstance()->AddAppProvisionInfo(BUNDLE_NAME, + appProvisionInfo); + EXPECT_TRUE(ret); + InnerSharedBundleInstaller installer(HAP_FILE_PATH1); + InstallParam installParam; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + installer.SaveInstallParamInfo(BUNDLE_NAME, installParam); + + std::string specifiedDistributionType; + ret = DelayedSingleton::GetInstance()->GetSpecifiedDistributionType(BUNDLE_NAME, + specifiedDistributionType); + EXPECT_TRUE(ret); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + + std::string additionalInfo; + ret = DelayedSingleton::GetInstance()->GetAdditionalInfo(BUNDLE_NAME, + additionalInfo); + EXPECT_TRUE(ret); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + + ret = DelayedSingleton::GetInstance()->DeleteAppProvisionInfo(BUNDLE_NAME); + EXPECT_TRUE(ret); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_hsp_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_hsp_test.cpp index 8077861c4595399dd75b001e69941dcbad345be1..e99b8abcc4ebc64e1a5198d26b462b60c0930b13 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_hsp_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_hsp_test.cpp @@ -63,6 +63,7 @@ public: void SetUp(); void TearDown(); ErrCode InstallBundle(const std::string &bundlePath) const; + ErrCode InstallBundle(const std::string &bundlePath, const InstallParam &installParam) const; ErrCode UpdateBundle(const std::string &bundlePath) const; ErrCode UnInstallBundle(const std::string &bundleName) const; const std::shared_ptr GetBundleDataMgr() const; @@ -118,6 +119,26 @@ ErrCode BmsBundleHspTest::InstallBundle(const std::string &bundlePath) const return receiver->GetResultCode(); } +ErrCode BmsBundleHspTest::InstallBundle(const std::string &bundlePath, const InstallParam &installParam) const +{ + if (!bundleMgrService_) { + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + auto installer = bundleMgrService_->GetBundleInstaller(); + if (!installer) { + EXPECT_FALSE(true) << "the installer is nullptr"; + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + sptr receiver = new (std::nothrow) MockStatusReceiver(); + if (!receiver) { + EXPECT_FALSE(true) << "the receiver is nullptr"; + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + bool result = installer->Install(bundlePath, installParam, receiver); + EXPECT_TRUE(result); + return receiver->GetResultCode(); +} + ErrCode BmsBundleHspTest::UpdateBundle(const std::string &bundlePath) const { if (!bundleMgrService_) { @@ -287,4 +308,38 @@ HWTEST_F(BmsBundleHspTest, BmsBundleHspTest_0700, Function | SmallTest | Level0) ErrCode installResult = InstallBundle(MODULE_D_FILE_PATH + HSP_NAME_D); EXPECT_NE(installResult, ERR_OK); } + +/** + * @tc.number: BmsBundleHspTest_0800 + * @tc.name: BmsBundleHspTest + * @tc.desc: test install, GetSpecifiedDistributionType and GetAdditionalInfo + */ +HWTEST_F(BmsBundleHspTest, BmsBundleHspTest_0800, Function | SmallTest | Level0) +{ + InstallParam installParam; + installParam.userId = USERID; + installParam.installFlag = InstallFlag::NORMAL; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + ErrCode installResult = InstallBundle(MODULE_FILE_PATH + HSP_NAME_C, installParam); + EXPECT_EQ(installResult, ERR_OK); + + auto dataMgr = GetBundleDataMgr(); + if (!dataMgr) { + EXPECT_NE(dataMgr, nullptr); + } else { + std::string specifiedDistributionType; + auto ret = dataMgr->GetSpecifiedDistributionType(BUNDLE_NAME, specifiedDistributionType); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + + std::string additionalInfo; + ret = dataMgr->GetAdditionalInfo(BUNDLE_NAME, additionalInfo); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_shared_library_install_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_shared_library_install_test.cpp index eb2026330ed487a3fdbdf83e9228980bc85683d1..b2c3eda2eacf3715327dda90d00786c3bed93546 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_shared_library_install_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_hsp_test/bms_bundle_shared_library_install_test.cpp @@ -65,8 +65,11 @@ public: void StartBundleService(); ErrCode InstallBundle(const std::vector &bundleFilePaths, const std::vector &sharedBundlePaths) const; + ErrCode InstallBundle(const std::vector &bundleFilePaths, + const InstallParam &installParam) const; ErrCode UnInstallBundle(const std::string &bundleName) const; ErrCode UninstallSharedBundle(const std::string &bundleName) const; + const std::shared_ptr GetBundleDataMgr() const; private: std::shared_ptr installdService_; std::shared_ptr bundleMgrService_; @@ -111,6 +114,11 @@ void BmsBundleSharedLibraryInstallTest::StartBundleService() } } +const std::shared_ptr BmsBundleSharedLibraryInstallTest::GetBundleDataMgr() const +{ + return bundleMgrService_->GetDataMgr(); +} + ErrCode BmsBundleSharedLibraryInstallTest::InstallBundle(const std::vector &bundleFilePaths, const std::vector &sharedBundlePaths) const { @@ -137,6 +145,28 @@ ErrCode BmsBundleSharedLibraryInstallTest::InstallBundle(const std::vectorGetResultCode(); } +ErrCode BmsBundleSharedLibraryInstallTest::InstallBundle(const std::vector &bundleFilePaths, + const InstallParam &installParam) const +{ + if (!bundleMgrService_) { + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + auto installer = bundleMgrService_->GetBundleInstaller(); + if (!installer) { + EXPECT_FALSE(true) << "the installer is nullptr"; + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + sptr receiver = new (std::nothrow) MockStatusReceiver(); + if (!receiver) { + EXPECT_FALSE(true) << "the receiver is nullptr"; + return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; + } + + bool result = installer->Install(bundleFilePaths, installParam, receiver); + EXPECT_TRUE(result); + return receiver->GetResultCode(); +} + ErrCode BmsBundleSharedLibraryInstallTest::UnInstallBundle(const std::string &bundleName) const { if (!bundleMgrService_) { @@ -511,5 +541,42 @@ HWTEST_F(BmsBundleSharedLibraryInstallTest, BmsBundleSharedLibraryInstallDepende ErrCode installResult = InstallBundle(bundleFilePaths, sharedBundlePaths); EXPECT_EQ(installResult, ERR_APPEXECFWK_INSTALL_DEPENDENT_MODULE_NOT_EXIST); } + +/** + * @tc.number: GetSpecifiedDistributionType_0010 + * @tc.name: BmsBundleSharedLibraryInstall + * @tc.desc: test install, install hsp + */ +HWTEST_F(BmsBundleSharedLibraryInstallTest, GetSpecifiedDistributionType_0010, Function | SmallTest | Level0) +{ + std::vector bundleFilePaths{}; + std::vector sharedBundlePaths{MODULE_FILE_PATH + LIBA_V10001}; + InstallParam installParam; + installParam.userId = USERID; + installParam.installFlag = InstallFlag::NORMAL; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + installParam.sharedBundleDirPaths = sharedBundlePaths; + ErrCode installResult = InstallBundle(bundleFilePaths, installParam); + EXPECT_EQ(installResult, ERR_OK); + + auto dataMgr = GetBundleDataMgr(); + if (!dataMgr) { + EXPECT_NE(dataMgr, nullptr); + } else { + std::string specifiedDistributionType; + auto ret = dataMgr->GetSpecifiedDistributionType(SHARED_BUNDLE_NAME_A, specifiedDistributionType); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + + std::string additionalInfo; + ret = dataMgr->GetAdditionalInfo(SHARED_BUNDLE_NAME_A, additionalInfo); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + } + + ErrCode unInstallResult = UninstallSharedBundle(SHARED_BUNDLE_NAME_A); + EXPECT_EQ(unInstallResult, ERR_OK); +} } } \ No newline at end of file diff --git a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp index e23f882e893550267ee9cd5a0fa982c3edbb5bf7..df6af86a11a695ee6772af52374ad78094abcb6b 100644 --- a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp +++ b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp @@ -227,6 +227,8 @@ public: void TearDown(); static void Install( const std::string &bundleFilePath, const InstallFlag installFlag, std::vector &resvec); + static void Install( + const std::string &bundleFilePath, const InstallParam &installParam, std::vector &resvec); static void Uninstall(const std::string &bundleName, std::vector &resvec); static void HapUninstall( const std::string &bundleName, const std::string &modulePackage, std::vector &resvec); @@ -280,6 +282,21 @@ void ActsBmsKitSystemTest::Install( resvec.push_back(statusReceiver->GetResultMsg()); } +void ActsBmsKitSystemTest::Install( + const std::string &bundleFilePath, const InstallParam &installParam, std::vector &resvec) +{ + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + APP_LOGE("get bundle installer failed."); + resvec.push_back(ERROR_INSTALL_FAILED); + return; + } + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); + EXPECT_NE(statusReceiver, nullptr); + installerProxy->Install(bundleFilePath, installParam, statusReceiver); + resvec.push_back(statusReceiver->GetResultMsg()); +} + void ActsBmsKitSystemTest::Uninstall(const std::string &bundleName, std::vector &resvec) { sptr installerProxy = GetInstallerProxy(); @@ -7948,5 +7965,94 @@ HWTEST_F(ActsBmsKitSystemTest, GetAdditionalInfo_0002, Function | SmallTest | Le std::cout << "END GetAdditionalInfo_0002" << std::endl; } + +/** + * @tc.number: GetAdditionalInfo_0003 + * @tc.name: test GetAdditionalInfo proxy + * @tc.desc: 1.system run normally + * 2.SetAdditionalInfo and SetSpecifiedDistributionType + */ +HWTEST_F(ActsBmsKitSystemTest, GetAdditionalInfo_0003, Function | SmallTest | Level1) +{ + std::vector resvec; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; + std::string appName = BASE_BUNDLE_NAME + "1"; + InstallParam installParam; + installParam.userId = USERID; + installParam.installFlag = InstallFlag::NORMAL; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + Install(bundleFilePath, installParam, resvec); + CommonTool commonTool; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + APP_LOGE("bundle mgr proxy is nullptr."); + EXPECT_EQ(bundleMgrProxy, nullptr); + } else { + std::string additionalInfo; + ErrCode ret = bundleMgrProxy->GetAdditionalInfo(appName, additionalInfo); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + std::string specifiedDistributionType; + ret = bundleMgrProxy->GetSpecifiedDistributionType(appName, specifiedDistributionType); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + } + resvec.clear(); + Uninstall(appName, resvec); + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; +} + +/** + * @tc.number: GetAdditionalInfo_0004 + * @tc.name: test GetAdditionalInfo proxy + * @tc.desc: 1.system run normally + * 2.2.SetAdditionalInfo and SetSpecifiedDistributionType + */ +HWTEST_F(ActsBmsKitSystemTest, GetAdditionalInfo_0004, Function | SmallTest | Level1) +{ + std::vector resvec; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; + std::string appName = BASE_BUNDLE_NAME + "1"; + InstallParam installParam; + installParam.userId = USERID; + installParam.installFlag = InstallFlag::NORMAL; + installParam.specifiedDistributionType = "specifiedDistributionType"; + installParam.additionalInfo = "additionalInfo"; + Install(bundleFilePath, installParam, resvec); + CommonTool commonTool; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + + // update hap + installParam.installFlag = InstallFlag::REPLACE_EXISTING; + installParam.additionalInfo = "modify additionalInfo"; + resvec.clear(); + Install(bundleFilePath, installParam, resvec); + installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + APP_LOGE("bundle mgr proxy is nullptr."); + EXPECT_EQ(bundleMgrProxy, nullptr); + } else { + std::string additionalInfo; + ErrCode ret = bundleMgrProxy->GetAdditionalInfo(appName, additionalInfo); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.additionalInfo, additionalInfo); + std::string specifiedDistributionType; + ret = bundleMgrProxy->GetSpecifiedDistributionType(appName, specifiedDistributionType); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(installParam.specifiedDistributionType, specifiedDistributionType); + } + resvec.clear(); + Uninstall(appName, resvec); + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file