diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 391af8ee66bad938ffe2cf7f0636ea9a934a3baf..3d2cf16ba8a046cad39ca4377ea2c21a571d8e39 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -467,7 +467,7 @@ private: * @param bundleName 包名称 * */ - void NotifyCloneBundleFinish(std::string bundleName, const BackupRestoreScenario sennario); + void HandleCurBundleEndWork(std::string bundleName, const BackupRestoreScenario sennario); /** * @brief SA 备份恢复结束 @@ -602,6 +602,8 @@ private: ErrCode HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup); void StartCurBundleBackupOrRestore(const std::string &bundleName); + + void CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 5cb873aed29797d90ddf24213449cae21c32c206..4f00a34da9572a8bf585cbb5bee5cdd983a0dbe2 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -919,16 +919,20 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { HILOGE("Result report fail, bundleName:%{public}s, ret:%{public}d", callerName.c_str(), ret); - NotifyCloneBundleFinish(callerName, sennario); + HandleCurBundleEndWork(callerName, sennario); + CallOnBundleEndByScenario(callerName, sennario, ret); + OnAllBundlesFinished(BError(BError::Codes::OK)); return ret; } SendEndAppGalleryNotify(callerName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { + HandleCurBundleEndWork(callerName, sennario); session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); - NotifyCloneBundleFinish(callerName, sennario); + OnAllBundlesFinished(BError(BError::Codes::OK)); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + HandleCurBundleEndWork(callerName, sennario); session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); - NotifyCloneBundleFinish(callerName, sennario); + OnAllBundlesFinished(BError(BError::Codes::OK)); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, callerName); } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { @@ -936,12 +940,10 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } return BError(BError::Codes::OK); } catch (const BError &e) { - NotifyCloneBundleFinish(callerName, sennario); + HandleCurBundleEndWork(callerName, sennario); + CallOnBundleEndByScenario(callerName, sennario, e.GetCode()); + OnAllBundlesFinished(BError(BError::Codes::OK)); return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (...) { - NotifyCloneBundleFinish(callerName, sennario); - HILOGE("Unexpected exception"); - return EPERM; } } @@ -967,7 +969,7 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string return SADone(errCode, bundleName); } -void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestoreScenario sennario) +void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestoreScenario sennario) { try { if (sennario != BackupRestoreScenario::FULL_RESTORE && @@ -998,10 +1000,8 @@ void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestor ClearSessionAndSchedInfo(bundleName); } RemoveExtensionMutex(bundleName); - OnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { HILOGE("Unexpected exception"); - ReleaseOnException(); } } diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 4664c5f98dfd2f95912f32b643559f987df0d5ab..63a9538d948bfed520a2be434a7b8e0d58627b30 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -772,4 +772,21 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() return UniqueFd(-EPERM); } } + +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ + if (session_ == nullptr) { + HILOGE("Session is empty, bundleName:%{public}s", bundleName.c_str()); + return; + } + if (scenario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); + } +} } \ No newline at end of file diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index aec7e28e689588032c13cf99dd1d9a3c53559724..309c0bfdb666341f0183ba631442137ecd247901 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -362,4 +362,7 @@ void Service::SetBundleIncDataInfo(const std::vector&, std::ve void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} + +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, + ErrCode errCode) {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index e4e235dcc4813354f48e44b1f8b5a105b6515eaa..84e8abfd12692b5219cc1e70b2f63e2328451f2d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -1234,47 +1234,47 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0200, TestSize.Level1) } /** - * @tc.number: SUB_Service_NotifyCloneBundleFinish_0100 - * @tc.name: SUB_Service_NotifyCloneBundleFinish_0100 - * @tc.desc: 测试 NotifyCloneBundleFinish + * @tc.number: SUB_Service_HandleCurBundleEndWork_0100 + * @tc.name: SUB_Service_HandleCurBundleEndWork_0100 + * @tc.desc: 测试 HandleCurBundleEndWork * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: issueIAKC3I */ -HWTEST_F(ServiceTest, SUB_Service_NotifyCloneBundleFinish_0100, TestSize.Level1) +HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, TestSize.Level1) { - GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NotifyCloneBundleFinish_0100"; + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleCurBundleEndWork_0100"; try { ASSERT_TRUE(service != nullptr); std::string bundleName = BUNDLE_NAME; BackupRestoreScenario senario = BackupRestoreScenario::INCREMENTAL_BACKUP; - service->NotifyCloneBundleFinish(bundleName, senario); + service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); senario = BackupRestoreScenario::FULL_RESTORE; EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); - service->NotifyCloneBundleFinish(bundleName, senario); + service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); - service->NotifyCloneBundleFinish(bundleName, senario); + service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); - service->NotifyCloneBundleFinish(bundleName, senario); + service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by NotifyCloneBundleFinish."; + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleCurBundleEndWork."; } - GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_NotifyCloneBundleFinish_0100"; + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleCurBundleEndWork_0100"; } /** diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 88106fd644bc02dc33a01863eac256ad274850e0..ba99f49ffacdfc48cd91a3c3b3dfb531aa665ac2 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -1507,17 +1507,17 @@ HWTEST_F(ServiceTest, SUB_Service_AppendBundlesRestoreSession_0100, testing::ext } /** - * @tc.number: SUB_Service_NotifyCloneBundleFinish_0100 - * @tc.name: SUB_Service_NotifyCloneBundleFinish_0100 - * @tc.desc: 测试 NotifyCloneBundleFinish 接口 + * @tc.number: SUB_Service_HandleCurBundleEndWork_0100 + * @tc.name: SUB_Service_HandleCurBundleEndWork_0100 + * @tc.desc: 测试 HandleCurBundleEndWork 接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I8ZIMJ */ -HWTEST_F(ServiceTest, SUB_Service_NotifyCloneBundleFinish_0100, testing::ext::TestSize.Level1) +HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NotifyCloneBundleFinish_0100"; + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleCurBundleEndWork_0100"; try { SvcSessionManager::Impl impl_; impl_.clientToken = 1; @@ -1526,12 +1526,12 @@ HWTEST_F(ServiceTest, SUB_Service_NotifyCloneBundleFinish_0100, testing::ext::Te impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; impl_.scenario = IServiceReverse::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); - servicePtr_->NotifyCloneBundleFinish(BUNDLE_NAME, BackupRestoreScenario::FULL_RESTORE); + servicePtr_->HandleCurBundleEndWork(BUNDLE_NAME, BackupRestoreScenario::FULL_RESTORE); } catch (...) { EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by NotifyCloneBundleFinish."; + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleCurBundleEndWork."; } - GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_NotifyCloneBundleFinish_0100"; + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleCurBundleEndWork_0100"; } /**