From ebf49591e5bbfb409662dc40acde85c109e56f99 Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Sat, 4 Jan 2025 11:00:45 +0800 Subject: [PATCH] resultReport after clear Signed-off-by: yaoruozi1@huawei.com --- .../backup_sa/include/module_ipc/service.h | 4 +++- services/backup_sa/src/module_ipc/service.cpp | 22 +++++++++---------- .../backup_sa/src/module_ipc/sub_service.cpp | 17 ++++++++++++++ tests/mock/module_ipc/service_mock.cpp | 3 +++ .../module_ipc/service_other_test.cpp | 22 +++++++++---------- .../backup_sa/module_ipc/service_test.cpp | 16 +++++++------- 6 files changed, 53 insertions(+), 31 deletions(-) diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index a9ed6ca5c..6bf84e63b 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -466,7 +466,7 @@ private: * @param bundleName 包名称 * */ - void NotifyCloneBundleFinish(std::string bundleName, const BackupRestoreScenario sennario); + void HandleCurBundleEndWork(std::string bundleName, const BackupRestoreScenario sennario); /** * @brief SA 备份恢复结束 @@ -601,6 +601,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 f49a37103..a9a83f900 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 e6d88a92c..34acc9f43 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -722,4 +722,21 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er StopAll(nullptr, true); return ret; } + +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 6218bb137..d9a6a54f6 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -357,4 +357,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 e4e235dcc..84e8abfd1 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 f334db579..88a1546c3 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -1506,17 +1506,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; @@ -1525,12 +1525,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"; } /** -- Gitee