diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 5b84215f351c2fa934344eaf6345da8393931891..ab33536585fc3e14156e7b07a1e03202ac5b5321 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -31,8 +31,8 @@ #include "b_file_info.h" #include "b_resources/b_constants.h" -#include "i_service_reverse.h" #include "i_service.h" +#include "i_service_reverse.h" #include "module_ipc/svc_backup_connection.h" #include "svc_death_recipient.h" #include "timer.h" @@ -225,11 +225,18 @@ public: */ bool GetSchedBundleName(std::string &bundleName); + /** + * @brief Set the Backup Ext Name object + * + * @param bundleName 应用名称 + * @param backupExtName extension name + */ + void SetBackupExtName(const std::string &bundleName, const std::string &backupExtName); + /** * @brief 获取backup extension name * * @param bundleName 应用名称 - * @return std::string * @return std::string extension name */ std::string GetBackupExtName(const std::string &bundleName); @@ -312,7 +319,7 @@ public: */ bool NeedToUnloadService(); -/** + /** * @brief Set the bundle restore type object * * @param bundleName @@ -374,7 +381,7 @@ public: * @param bundleName 应用名称 * @return */ - void BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback& callback); + void BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback &callback); /** * @brief 取消/暂停应用扩展能力定时器 diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 116dd770756c445c364327b521da047212fb73e4..8f85c320c0524e1303b5d06aa34ea73102aa5ddc 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -259,6 +259,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, session_->SetBundleVersionCode(bundleInfo.name, bundleInfo.versionCode); session_->SetBundleVersionName(bundleInfo.name, bundleInfo.versionName); session_->SetBundleDataSize(bundleInfo.name, bundleInfo.spaceOccupied); + session_->SetBackupExtName(bundleInfo.name, bundleInfo.extensionName); } } for (auto info : restoreInfos) { @@ -268,8 +269,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, session_->RemoveExtInfo(info.name); } } - Start(); - Finish(); OnStartSched(); return BError(BError::Codes::OK); } @@ -282,13 +281,12 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName session_->AppendBundles(bundleNames); for (auto info : backupInfos) { session_->SetBundleDataSize(info.name, info.spaceOccupied); + session_->SetBackupExtName(info.name, info.extensionName); if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_REFUSED_ACT), info.name); session_->RemoveExtInfo(info.name); } } - Start(); - Finish(); OnStartSched(); return BError(BError::Codes::OK); } @@ -434,6 +432,7 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) AAFwk::Want want; string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ + HILOGD("backupExtName: %{public}s, bundleName: %{public}s", backupExtName.data(), bundleName.data()); string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ uint32_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index 75712fb5f365eec3e465a8c84ebd9a2d5c1e95fa..9c9d3390d4660d0f944bff5008d6fdf54397cf1a 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -28,8 +28,6 @@ #include "b_json/b_json_entity_ext_manage.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" -#include "module_external/bms_adapter.h" -#include "module_external/sms_adapter.h" #include "module_ipc/service.h" namespace OHOS::FileManagement::Backup { @@ -360,6 +358,18 @@ void SvcSessionManager::SetServiceSchedAction(const string &bundleName, BConstan } } +void SvcSessionManager::SetBackupExtName(const string &bundleName, const string &backupExtName) +{ + HILOGI("Begin"); + unique_lock lock(lock_); + if (!impl_.clientToken) { + throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + } + + auto it = GetBackupExtNameMap(bundleName); + it->second.backupExtName = backupExtName; +} + string SvcSessionManager::GetBackupExtName(const string &bundleName) { HILOGI("Begin"); @@ -367,19 +377,9 @@ string SvcSessionManager::GetBackupExtName(const string &bundleName) if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - string name = bundleName; - VerifyBundleName(name); - auto bundleInfos = BundleMgrAdapter::GetBundleInfos({bundleName}, impl_.userId); - for (auto &&bundleInfo : bundleInfos) { - if (!bundleInfo.allToBackup || bundleInfo.extensionName.empty()) { - throw BError(BError::Codes::SA_INVAL_ARG, - string(bundleInfo.name).append(" is not allow to backup or extension name is empty")); - } - if (bundleInfo.name == bundleName) { - return bundleInfo.extensionName; - } - } - throw BError(BError::Codes::SA_INVAL_ARG, "Could not find the extension name"); + + auto it = GetBackupExtNameMap(bundleName); + return it->second.backupExtName; } void SvcSessionManager::AppendBundles(const vector &bundleNames) @@ -396,6 +396,8 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) info.backUpConnection = GetBackupExtAbility(bundleName); impl_.backupExtNameMap.insert(make_pair(bundleName, info)); } + impl_.isBackupStart = true; + impl_.isAppendFinish = true; } void SvcSessionManager::Start() @@ -460,7 +462,7 @@ void SvcSessionManager::SetInstallState(const string &bundleName, const string & string SvcSessionManager::GetInstallState(const string &bundleName) { HILOGI("Begin"); - unique_lock lock(lock_); + shared_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } @@ -484,7 +486,7 @@ void SvcSessionManager::SetNeedToInstall(const std::string &bundleName, bool nee bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) { HILOGI("Begin"); - unique_lock lock(lock_); + shared_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } @@ -515,7 +517,7 @@ void SvcSessionManager::SetBundleRestoreType(const std::string &bundleName, Rest RestoreTypeEnum SvcSessionManager::GetBundleRestoreType(const std::string &bundleName) { - unique_lock lock(lock_); + shared_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } @@ -537,7 +539,7 @@ void SvcSessionManager::SetBundleVersionCode(const std::string &bundleName, uint uint32_t SvcSessionManager::GetBundleVersionCode(const std::string &bundleName) { - unique_lock lock(lock_); + shared_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } @@ -559,7 +561,7 @@ void SvcSessionManager::SetBundleVersionName(const std::string &bundleName, std: std::string SvcSessionManager::GetBundleVersionName(const std::string &bundleName) { - unique_lock lock(lock_); + shared_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } @@ -634,5 +636,4 @@ void SvcSessionManager::BundleExtTimerStop(const std::string &bundleName) extBundleTimer.Unregister(it->second.extTimerId); } } - -} // namespace OHOS::FileManagement::Backup- +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 07e6a5832c4f471fb398101f52bc21fc11558ac8..45dd0126ef941a2eb505d0a9289dbb0a82fa293d 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -320,4 +320,5 @@ void SvcSessionManager::BundleExtTimerStart ( void SvcSessionManager::BundleExtTimerStop(const std::string &bundleName) {} +void SvcSessionManager::SetBackupExtName(const string &bundleName, const string &backupExtName) {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index a393297fc86353832f9958438212307f41b05001..f3e04a938d306c096027e4aa00ad52e23a66080f 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -339,6 +339,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0100, tes { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBackupExtName_0100"; try { + sessionManagerPtr_->SetBackupExtName(BUNDLE_NAME, BUNDLE_NAME); string extName = sessionManagerPtr_->GetBackupExtName(BUNDLE_NAME); EXPECT_EQ(extName, BUNDLE_NAME); } catch (...) {