From 8a5826cbca8d67d478d4e5e14a01ebf8a6add5d4 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Tue, 2 Apr 2024 19:35:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=80=82=E9=85=8DExtensi?= =?UTF-8?q?onAbilityName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: libuyan <1014734367@qq.com> --- .../include/module_external/bms_adapter.h | 2 ++ .../include/module_ipc/svc_session_manager.h | 2 +- .../src/module_external/bms_adapter.cpp | 23 +++++++++++++++++++ services/backup_sa/src/module_ipc/service.cpp | 3 ++- .../src/module_ipc/svc_session_manager.cpp | 4 ++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index 9903ec498..5f7dd2846 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 12c647180..e27bf402d 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 bb12e6627..a66069566 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 0844f9e8d..449a20132 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 34c3b55b1..04769ec31 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -404,14 +404,14 @@ 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; -- Gitee From 1f8e42d2825cddce52b54dad40477da90471d098 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Tue, 2 Apr 2024 19:51:36 +0800 Subject: [PATCH 2/4] add ut Signed-off-by: libuyan <1014734367@qq.com> --- tests/mock/module_external/bms_adapter_mock.cpp | 5 +++++ tests/mock/module_ipc/svc_session_manager_mock.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/mock/module_external/bms_adapter_mock.cpp b/tests/mock/module_external/bms_adapter_mock.cpp index afff66e3e..8d412f2a7 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 69f45fd8d..8c4cae1f2 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 {}; -- Gitee From 6efe9cb8fe27bf793f3a0c943f15cd6d772cf698 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Tue, 2 Apr 2024 20:04:12 +0800 Subject: [PATCH 3/4] add target Signed-off-by: libuyan <1014734367@qq.com> --- services/backup_sa/src/module_ipc/svc_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 04769ec31..c56d99093 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -414,7 +414,7 @@ void SvcSessionManager::CreateBackupConnection(BundleName &bundleName, string ex 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)); } -- Gitee From 3368718f5d4844df038718fbc97c50b8c36d7b30 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Wed, 3 Apr 2024 17:36:12 +0800 Subject: [PATCH 4/4] add target Signed-off-by: libuyan <1014734367@qq.com> --- tests/unittests/backup_api/backup_impl/service_reverse_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e07040799..47aae9a7e 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 (...) { -- Gitee