From d9e06ac26455bb87707f49a0315f12de2786aadf Mon Sep 17 00:00:00 2001 From: huaqingsimeng Date: Tue, 19 Dec 2023 21:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=9C=8D=E5=8A=A1=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=81=A2=E5=A4=8D=E5=BA=94=E7=94=A8=EF=BC=8C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../src/b_session_restore_async.cpp | 104 ++++----------- .../backup_sa/include/module_ipc/service.h | 8 +- .../include/module_ipc/svc_session_manager.h | 7 + .../include/module_sched/sched_scheduler.h | 12 ++ services/backup_sa/src/module_ipc/service.cpp | 18 +++ .../src/module_ipc/svc_session_manager.cpp | 26 +++- .../src/module_sched/sched_scheduler.cpp | 26 ++++ .../b_session_restore_async_mock.cpp | 6 - tests/mock/module_ipc/service_mock.cpp | 2 + .../module_ipc/svc_session_manager_mock.cpp | 2 + .../module_sched/sched_scheduler_mock.cpp | 4 + .../b_session_restore_async_test.cpp | 120 ------------------ .../src/tools_op_restore_async.cpp | 27 +++- 13 files changed, 143 insertions(+), 219 deletions(-) diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index c25212f5d..a0a38653c 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -47,6 +47,24 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); + ServiceProxy::InvaildInstance(); + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + HILOGI("Failed to get backup service"); + return nullptr; + } + BSessionRestore::Callbacks callbacksTmp {.onFileReady = callbacks.onFileReady, + .onBundleStarted = callbacks.onBundleStarted, + .onBundleFinished = callbacks.onBundleFinished, + .onAllBundlesFinished = callbacks.onAllBundlesFinished, + .onBackupServiceDied = callbacks.onBackupServiceDied}; + int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); + if (res != 0) { + HILOGE("Failed to Restore because of %{public}d", res); + return nullptr; + } + + restore->RegisterBackupServiceDied(callbacks.onBackupServiceDied); return restore; } catch (const exception &e) { HILOGE("Failed to Restore because of %{public}s", e.what()); @@ -78,18 +96,12 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - { - std::unique_lock lock(mutex_); - workList_.push({move(remoteCap), move(bundlesToRestore), restoreType, userId}); - } - - if (isAppend_.exchange(true)) { - return ERR_OK; - } else { - PopBundleInfo(); + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return ERR_OK; + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); } void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) @@ -107,76 +119,4 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); } - -void BSessionRestoreAsync::OnBackupServiceDied() -{ - HILOGE("Backup service died"); - if (callbacks_.onBackupServiceDied) { - callbacks_.onBackupServiceDied(); - } - deathRecipient_ = nullptr; - ServiceProxy::InvaildInstance(); - PopBundleInfo(); -} - -void BSessionRestoreAsync::PopBundleInfo() -{ - HILOGE("Start"); - AppendBundleInfo info; - isAppend_.store(true); - { - std::unique_lock lock(mutex_); - if (workList_.empty()) { - isAppend_.store(false); - return; - } - info = move(workList_.front()); - workList_.pop(); - } - AppendBundlesImpl(move(info)); -} - -void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) -{ - HILOGD("Start"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); - if (proxy == nullptr) { - return OnBundleStarted(BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(), - info.bundlesToRestore); - } - auto onBackupServiceDied = bind(&BSessionRestoreAsync::OnBackupServiceDied, shared_from_this()); - RegisterBackupServiceDied(onBackupServiceDied); - - BSessionRestore::Callbacks callbacksTmp {.onFileReady = callbacks_.onFileReady, - .onBundleStarted = callbacks_.onBundleStarted, - .onBundleFinished = callbacks_.onBundleFinished, - .onAllBundlesFinished = callbacks_.onAllBundlesFinished, - .onBackupServiceDied = onBackupServiceDied}; - int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); - if (res != 0) { - HILOGE("Failed to Init Restore because of %{public}d", res); - BError(BError::Codes::SDK_BROKEN_IPC, "Failed to int restore session").GetCode(); - return OnBundleStarted(res, info.bundlesToRestore); - } - for (auto &bundleName : info.bundlesToRestore) { - HILOGD("Append bundleName: %{public}s", bundleName.c_str()); - } - res = - proxy->AppendBundlesRestoreSession(move(info.remoteCap), info.bundlesToRestore, info.restoreType, info.userId); - if (res != 0) { - HILOGE("Failed to Restore because of %{public}d", res); - BError(BError::Codes::SDK_BROKEN_IPC, "Failed to append bundles").GetCode(); - return OnBundleStarted(res, info.bundlesToRestore); - } -} - -void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) -{ - for (auto &bundleName : bundlesToRestore) { - if (callbacks_.onBundleStarted) { - callbacks_.onBundleStarted(errCode, bundleName); - } - } -} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index ba9538812..2a2e639bc 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -97,7 +97,13 @@ public: * */ void SendAppGalleryNotify(const std::string &bundleName); - + + /** + * @brief 结束会话删除session,卸载服务 + * + */ + void SessionDeactive(); + public: explicit Service(int32_t saID, bool runOnCreate = false) : SystemAbility(saID, runOnCreate) { 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 0c530e3cc..ff45a9c2f 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -76,6 +76,7 @@ public: [RESTORE] Support for multiple users, incoming during restore process. */ int32_t userId {100}; + RestoreTypeEnum restoreDataType {RESTORE_DATA_WAIT_SEND}; }; public: @@ -405,6 +406,12 @@ public: */ void DecreaseSessionCnt(); + /** + * @brief clear session data + * + */ + void ClearSessionData(); + private: /** * @brief 获取backup extension ability diff --git a/services/backup_sa/include/module_sched/sched_scheduler.h b/services/backup_sa/include/module_sched/sched_scheduler.h index 30415c6c1..507c4caee 100644 --- a/services/backup_sa/include/module_sched/sched_scheduler.h +++ b/services/backup_sa/include/module_sched/sched_scheduler.h @@ -68,6 +68,18 @@ public: */ void TryUnloadServiceTimer(bool force = false); + /** + * @brief clear scheduler data + * + */ + void ClearSchedulerData(); + + /** + * @brief unload service + * + */ + void TryUnloadService(); + void StartTimer() { extTime_.Setup(); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index aedb23277..cddd07075 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -826,4 +826,22 @@ void Service::SendAppGalleryNotify(const BundleName &bundleName) bundleName.c_str()); } } + +void Service::SessionDeactive() +{ + try { + HILOGI("Begin"); + // 结束定时器 + sched_->ClearSchedulerData(); + // 清除缓存数据 + session_->ClearSessionData(); + // 清除session + session_->Deactive(nullptr, true); + // 卸载服务 + sched_->TryUnloadService(); + } catch (...) { + HILOGI("Unexpected exception"); + return; + } +} } // namespace OHOS::FileManagement::Backup 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 f6b89f44a..4f78c7e0d 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -269,7 +269,7 @@ void SvcSessionManager::InitClient(Impl &newImpl) HILOGW("It's curious that the backup sa dies before the backup client"); return; } - (void)revPtrStrong->StopAll(obj); + (void)revPtrStrong->SessionDeactive(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); @@ -427,9 +427,7 @@ bool SvcSessionManager::IsOnAllBundlesFinished() if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - auto iter = find_if(impl_.backupExtNameMap.begin(), impl_.backupExtNameMap.end(), - [](const auto &it) { return it.second.isBundleFinished == false; }); - bool isAllBundlesFinished = (iter == impl_.backupExtNameMap.end() && impl_.isAppendFinish); + bool isAllBundlesFinished = !impl_.backupExtNameMap.size(); if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isAllBundlesFinished = (isAllBundlesFinished && isAllBundlesRestored); @@ -502,6 +500,9 @@ bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) bool SvcSessionManager::NeedToUnloadService() { unique_lock lock(lock_); + if (impl_.restoreDataType == RestoreTypeEnum::RESTORE_DATA_READDY) { + return false; + } bool isNeedToUnloadService = (!impl_.backupExtNameMap.size() && (sessionCnt_.load() <= 0)); if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); @@ -520,6 +521,7 @@ void SvcSessionManager::SetBundleRestoreType(const std::string &bundleName, Rest auto it = GetBackupExtNameMap(bundleName); it->second.restoreType = restoreType; + impl_.restoreDataType = restoreType; } RestoreTypeEnum SvcSessionManager::GetBundleRestoreType(const std::string &bundleName) @@ -658,4 +660,20 @@ void SvcSessionManager::DecreaseSessionCnt() HILOGE("Invalid sessionCount."); } } + +void SvcSessionManager::ClearSessionData() +{ + unique_lock lock(lock_); + for (auto it = impl_.backupExtNameMap.begin(); it != impl_.backupExtNameMap.end();) { + // clear timer + extBundleTimer.Unregister(it->second.extTimerId); + // disconnect extension + if (it->second.schedAction == BConstants::ServiceSchedAction::RUNNING) { + it->second.backUpConnection->DisconnectBackupExtAbility(); + } + // clear data + it->second.schedAction = BConstants::ServiceSchedAction::FINISH; + } + impl_.backupExtNameMap.clear(); +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 658fe501f..3453bbdd4 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -210,6 +210,32 @@ void SchedScheduler::TryUnloadServiceTimer(bool force) tryUnload(); } +void SchedScheduler::TryUnloadService() +{ + HILOGI("Unload system ability"); + sptr saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + HILOGE("UnloadSA, GetSystemAbilityManager is null."); + return; + } + int32_t result = saManager->UnloadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID); + if (result != ERR_OK) { + HILOGE("UnloadSA, UnloadSystemAbility result: %{public}d", result); + return; + } +} + +void SchedScheduler::ClearSchedulerData() +{ + unique_lock lock(lock_); + for (auto &bundleTime : bundleTimeVec_) { + auto &[bName, iTime] = bundleTime; + extTime_.Unregister(iTime); + } + bundleTimeVec_.clear(); + threadPool_.Stop(); +} + void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) { if (!resultCode) { diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp index 76ddbb901..4068bd936 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -96,11 +96,5 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, void BSessionRestoreAsync::OnBackupServiceDied() {} -void BSessionRestoreAsync::PopBundleInfo() {} - -void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) {} - -void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) {} - void BSessionRestoreAsync::RegisterBackupServiceDied(function functor) {} } // namespace OHOS::FileManagement::Backup \ 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 372961277..898c0f835 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -127,4 +127,6 @@ void Service::OnAllBundlesFinished(ErrCode errCode) {} void Service::OnStartSched() {} void Service::SendAppGalleryNotify(const BundleName &bundleName) {} + +void Service::SessionDeactive() {} } // 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 604c4e743..012ff4682 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -325,4 +325,6 @@ void SvcSessionManager::SetBackupExtName(const string &bundleName, const string void SvcSessionManager::IncreaseSessionCnt() {} void SvcSessionManager::DecreaseSessionCnt() {} + +void SvcSessionManager::ClearSessionData() {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_sched/sched_scheduler_mock.cpp b/tests/mock/module_sched/sched_scheduler_mock.cpp index b44f94ebd..264efd809 100644 --- a/tests/mock/module_sched/sched_scheduler_mock.cpp +++ b/tests/mock/module_sched/sched_scheduler_mock.cpp @@ -34,5 +34,9 @@ void SchedScheduler::InstallingState(const string &bundleName) {} void SchedScheduler::TryUnloadServiceTimer(bool force) {} +void SchedScheduler::TryUnloadService() {} + +void SchedScheduler::ClearSchedulerData() {} + void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) {} }; // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index 5b2b2377f..e9badac6b 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -250,124 +250,4 @@ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0600, test } GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0600"; } - -/** - * @tc.number: SUB_backup_b_session_restore_async_0700 - * @tc.name: SUB_backup_b_session_restore_async_0700 - * @tc.desc: 测试OnBackupServiceDied接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7L7A6 - */ -HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0700, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0700"; - try { - GTEST_LOG_(INFO) << "GetInstance is true"; - SetMockGetInstance(true); - GTEST_LOG_(INFO) << "callbacks_.onBackupServiceDied is nullptr"; - callbacks_.onBackupServiceDied = nullptr; - restorePtr_->OnBackupServiceDied(); - GTEST_LOG_(INFO) << "callbacks_.onBackupServiceDied is not nullptr"; - Init(); - restorePtr_->OnBackupServiceDied(); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by OnBackupServiceDied."; - } - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0700"; -} - -/** - * @tc.number: SUB_backup_b_session_restore_async_0800 - * @tc.name: SUB_backup_b_session_restore_async_0800 - * @tc.desc: 测试PopBundleInfo接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7L7A6 - */ -HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0800, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0800"; - try { - GTEST_LOG_(INFO) << "GetInstance is true"; - SetMockGetInstance(true); - GTEST_LOG_(INFO) << "LoadSystemAbility is true"; - SetMockLoadSystemAbility(true); - vector bundleNames; - restorePtr_->workList_.push({UniqueFd(-1), bundleNames, RESTORE_DATA_WAIT_SEND, -1}); - restorePtr_->PopBundleInfo(); - EXPECT_TRUE(restorePtr_->workList_.empty()); - restorePtr_->PopBundleInfo(); - EXPECT_TRUE(restorePtr_->workList_.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by PopBundleInfo."; - } - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0800"; -} - -/** - * @tc.number: SUB_backup_b_session_restore_async_0900 - * @tc.name: SUB_backup_b_session_restore_async_0900 - * @tc.desc: 测试AppendBundlesImpl接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7L7A6 - */ -HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0900, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0900"; - try { - vector bundleNames; - BSessionRestoreAsync::AppendBundleInfo info; - info.remoteCap = UniqueFd(-1); - info.bundlesToRestore = bundleNames; - info.restoreType = TypeRestoreTypeEnum::RESTORE_DATA_WAIT_SEND; - info.userId = -1; - GTEST_LOG_(INFO) << "GetInstance is false"; - SetMockGetInstance(false); - restorePtr_->AppendBundlesImpl(move(info)); - GTEST_LOG_(INFO) << "GetInstance is true"; - SetMockGetInstance(true); - restorePtr_->AppendBundlesImpl(move(info)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by AppendBundlesImpl."; - } - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0900"; -} - -/** - * @tc.number: SUB_backup_b_session_restore_async_1000 - * @tc.name: SUB_backup_b_session_restore_async_1000 - * @tc.desc: 测试OnBundleStarted接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7L7A6 - */ -HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_1000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_1000"; - try { - vector bundleNames; - GTEST_LOG_(INFO) << "GetInstance is true"; - SetMockGetInstance(true); - GTEST_LOG_(INFO) << "onBundleStarted is nullptr"; - callbacks_.onBundleStarted = nullptr; - restorePtr_->OnBundleStarted(0x1000, bundleNames); - GTEST_LOG_(INFO) << "onBundleStarted is func ptr"; - Init(); - restorePtr_->OnBundleStarted(0x1000, bundleNames); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by OnBundleStarted."; - } - GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_1000"; -} - } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 79c3a16ee..146ae8f83 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -50,6 +50,9 @@ public: if (flag == true) { ready_ = true; cv_.notify_all(); + } else if (cnt_ == 0) { + ready_ = true; + cv_.notify_all(); } } @@ -59,12 +62,24 @@ public: cv_.wait(lk, [&] { return ready_; }); } + void UpdateBundleFinishedCount() + { + lock_guard lk(lock_); + cnt_--; + } + + void SetBundleFinishedCount(uint32_t cnt) + { + cnt_ = cnt; + } + shared_ptr session_ = {}; private: mutable condition_variable cv_; mutex lock_; bool ready_ = false; + uint32_t cnt_ {0}; }; static string GenHelpMsg() @@ -111,7 +126,8 @@ static void OnBundleStarted(shared_ptr ctx, ErrCode err, const Bun { printf("BundleStarted errCode = %d, BundleName = %s\n", err, name.c_str()); if (err != 0) { - ctx->TryNotify(true); + ctx->UpdateBundleFinishedCount(); + ctx->TryNotify(); } } @@ -119,16 +135,15 @@ static void OnBundleFinished(shared_ptr ctx, ErrCode err, const Bu { printf("BundleFinished errCode = %d, BundleName = %s\n", err, name.c_str()); if (err != 0) { - ctx->TryNotify(true); + ctx->UpdateBundleFinishedCount(); + ctx->TryNotify(); } } static void OnAllBundlesFinished(shared_ptr ctx, ErrCode err) { printf("all bundles finished end\n"); - if (err != 0) { - ctx->TryNotify(true); - } + ctx->TryNotify(true); } static void OnBackupServiceDied(shared_ptr ctx) @@ -267,7 +282,7 @@ static int32_t InitArg(const string &pathCapFile, FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return -EPERM; } - + ctx->SetBundleFinishedCount(bundleNames.size()); return AppendBundles(ctx, pathCapFile, bundleNames, type, userId); } -- Gitee