diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index 9903ec49819016f24a4487f1a1fc747c60782d9c..5f7dd28468a4a550cf3ce413257127cb6570bb32 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -63,6 +63,8 @@ public: const std::vector &incrementalDataList, int32_t userId); static std::vector GetBundleInfosForIncremental(int32_t userId); + + static std::string GetExtName(string bundleName, int32_t userId); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_BUNDLE_MGR_ADAPTER_H 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 12c647180475236369ef15aa6ad3773214468aaa..e27bf402d9949543a24f1670a28ba079141e7aff 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -258,7 +258,7 @@ public: * * @param bundleName 应用名称 */ - void CreateBackupConnection(BundleName &bundleName); + void CreateBackupConnection(BundleName &bundleName, std::string extName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index bb12e66279ecce2169ca27b6e854ec6167469c5f..a660695662727261a6e862e9e4a388643318e6c9 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -336,4 +336,27 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement } return BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, userId); } + +string BundleMgrAdapter::GetExtName(string bundleName, int32_t userId) +{ + vector installedBundles; + auto bms = GetBundleManager(); + if (!bms->GetBundleInfos(AppExecFwk::GET_BUNDLE_WITH_EXTENSION_INFO, installedBundles, userId)) { + throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle infos"); + } + for (auto const &installedBundle : installedBundles) { + if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || + installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { + HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); + continue; + } + for (auto ext : installedBundle.extensionInfos) { + if (ext.bundleName != bundleName) { + continue; + } + return ext.name; + } + } + return "BackupExtensionAbility"; +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 0844f9e8da124b177d1bc7723f4eb71992a300a2..449a2013291f1ee8ee4acca8911ec8bef59b6bf0 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -938,7 +938,8 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) try { HILOGI("Service::GetBackupInfo begin."); session_->IncreaseSessionCnt(); - session_->CreateBackupConnection(bundleName); + std::string extName = BundleMgrAdapter::GetExtName(bundleName, session_->GetSessionUserId()); + session_->CreateBackupConnection(bundleName, extName); auto backupConnection = session_->GetExtConnection(bundleName); auto callConnDone = [ptr {wptr(this)}](const string &&bundleName) { HILOGI("callConnDone begin."); 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 34c3b55b1ed62a5a8b6eef26bbed23824246a0f8..c56d99093b29fb7259091282c0e8d96d59c95dc8 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -404,17 +404,17 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) impl_.isAppendFinish = true; } -void SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +void SvcSessionManager::CreateBackupConnection(BundleName &bundleName, string extName) { HILOGI("SvcSessionManager::CreateBackupConnection begin."); unique_lock lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - HILOGD("bundleName: %{public}s", bundleName.c_str()); + HILOGD("bundleName: %{public}s, extName: %{public}s", bundleName.c_str(), extName.c_str()); BackupExtInfo info {}; info.backUpConnection = GetBackupExtAbility(bundleName); - info.backupExtName = bundleName; + info.backupExtName = extName; impl_.backupExtNameMap.insert(make_pair(bundleName, info)); } diff --git a/tests/mock/module_external/bms_adapter_mock.cpp b/tests/mock/module_external/bms_adapter_mock.cpp index afff66e3ee8222dfd7c395189bc63a8ffc2ff2a6..8d412f2a713a50517bbdc72ba0dde76a8bf65380 100644 --- a/tests/mock/module_external/bms_adapter_mock.cpp +++ b/tests/mock/module_external/bms_adapter_mock.cpp @@ -65,4 +65,9 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement BJsonEntityCaps::BundleInfo {"com.example.app2backup", {}, {}, 0, true, "com.example.app2backup"}); return bundleInfos; } + +string BundleMgrAdapter::GetExtName(string bundleName, int32_t userId) +{ + return "BackupExtensionAbility"; +} } // 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 69f45fd8d48593662c47251ea56a842d1fd8d85f..8c4cae1f2fe96fde92b149da77665207e4973eb3 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -202,7 +202,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } -void SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +void SvcSessionManager::CreateBackupConnection(BundleName &bundleName, string extName) { GTEST_LOG_(INFO) << "CreateBackupConnection"; BackupExtInfo info {}; diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index e070407997b717922fe221327815835aaa633e06..47aae9a7ebeb12e365412029eaba21e94eb355da 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -1222,7 +1222,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverse::Scenario::RESTORE); std::string resultReport = "result_report"; service_->RestoreOnResultReport(resultReport); } catch (...) {