From d9e9409f6ff0ebc5709057f782ee05a4567bd6c9 Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Wed, 6 Nov 2024 11:58:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DonProcess=E8=B0=83?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../native/backup_ext/include/ext_extension.h | 5 + .../backup_ext/src/sub_ext_extension.cpp | 92 ++++++++++++------- services/backup_sa/src/module_ipc/service.cpp | 10 +- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index e18a11f0b..59ccc52f2 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -70,6 +70,7 @@ public: bundleName_ = bundleName; threadPool_.Start(BConstants::EXTENSION_THREAD_POOL_COUNT); onProcessTaskPool_.Start(BConstants::EXTENSION_THREAD_POOL_COUNT); + reportOnProcessRetPool_.Start(BConstants::EXTENSION_THREAD_POOL_COUNT); SetStagingPathProperties(); } ~BackupExtExtension() @@ -77,6 +78,7 @@ public: onProcessTimeoutTimer_.Shutdown(); threadPool_.Stop(); onProcessTaskPool_.Stop(); + reportOnProcessRetPool_.Stop(); if (callJsOnProcessThread_.joinable()) { callJsOnProcessThread_.join(); } @@ -291,6 +293,8 @@ private: sptr proxy); ErrCode IncrementalAllFileReady(const TarMap &pkgInfo, const vector &srcFiles, sptr proxy); + std::function ReportOnProcessResultCallback(wptr obj, + BackupRestoreScenario scenario); private: std::shared_mutex lock_; @@ -324,6 +328,7 @@ private: OHOS::ThreadPool onProcessTaskPool_; std::atomic isFirstCallOnProcess_ {false}; std::atomic isExecAppDone_ {false}; + OHOS::ThreadPool reportOnProcessRetPool_; BackupRestoreScenario curScenario_ { BackupRestoreScenario::FULL_BACKUP }; }; diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index cc0711792..4156f50d4 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -386,6 +386,10 @@ std::function BackupExtExtension::OnBackupCall HILOGE("Extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } extensionPtr->FinishOnProcessTask(); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); @@ -424,6 +428,10 @@ std::function BackupExtExtension::OnBackupExCa HILOGE("Extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (errCode == ERR_OK) { if (backupExRetInfo.size()) { @@ -468,6 +476,10 @@ std::function BackupExtExtension::IncOnBackupC HILOGE("Current extension execute call backup error, extPtr is empty"); return; } + if (extPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); extPtr->FinishOnProcessTask(); if (errCode == ERR_OK) { @@ -510,6 +522,10 @@ std::function BackupExtExtension::IncOnBackupE HILOGE("Extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (errCode == ERR_OK) { if (backupExRetInfo.size()) { @@ -624,37 +640,7 @@ void BackupExtExtension::SyncCallJsOnProcessTask(wptr obj, B HILOGE("Current extension execute finished"); return; } - auto callBack = [obj, scenario](ErrCode errCode, const std::string processInfo) { - auto extPtr = obj.promote(); - if (extPtr == nullptr) { - HILOGE("Async call js onPreocess callback failed, exPtr is empty"); - return; - } - if (extPtr->onProcessTimeout_.load()) { - HILOGE("The result of invoking onProcess is timeout."); - extPtr->onProcessTimeout_.store(false); - return; - } - extPtr->CloseOnProcessTimeOutTimer(); - extPtr->isFirstCallOnProcess_.store(false); - extPtr->onProcessTimeout_.store(false); - if (extPtr->onProcessTimeoutCnt_.load() > 0) { - extPtr->onProcessTimeoutCnt_ = 0; - HILOGI("onProcess execute success, reset onProcessTimeoutCnt"); - } - if (processInfo.size() == 0) { - HILOGE("Current extension has no js method named onProcess."); - std::unique_lock lock(extPtr->onProcessLock_); - extPtr->isFirstCallOnProcess_.store(false); - extPtr->stopCallJsOnProcess_.store(true); - extPtr->execOnProcessCon_.notify_one(); - lock.unlock(); - return; - } - std::string processInfoJsonStr; - BJsonUtil::BuildOnProcessRetInfo(processInfoJsonStr, processInfo); - extPtr->ReportAppProcessInfo(processInfoJsonStr, scenario); - }; + auto callBack = ReportOnProcessResultCallback(obj, scenario); auto extenionPtr = obj.promote(); if (extenionPtr == nullptr) { HILOGE("Async call js onProcess failed, extenionPtr is empty"); @@ -1196,4 +1182,48 @@ int BackupExtExtension::DoIncrementalBackup(const vector smallFiles.size(), allFiles.size()); return err; } + +std::function BackupExtExtension::ReportOnProcessResultCallback( + wptr obj, BackupRestoreScenario scenario) +{ + return [obj, scenario](ErrCode errCode, const std::string processInfo) { + auto extPtr = obj.promote(); + if (extPtr == nullptr) { + HILOGE("Async call js onPreocess callback failed, exPtr is empty"); + return; + } + if (extPtr->onProcessTimeout_.load()) { + HILOGE("The result of invoking onProcess is timeout."); + extPtr->onProcessTimeout_.store(false); + return; + } + extPtr->CloseOnProcessTimeOutTimer(); + extPtr->isFirstCallOnProcess_.store(false); + extPtr->onProcessTimeout_.store(false); + if (extPtr->onProcessTimeoutCnt_.load() > 0) { + extPtr->onProcessTimeoutCnt_ = 0; + HILOGI("onProcess execute success, reset onProcessTimeoutCnt"); + } + if (processInfo.size() == 0) { + HILOGE("Current extension has no js method named onProcess."); + std::unique_lock lock(extPtr->onProcessLock_); + extPtr->isFirstCallOnProcess_.store(false); + extPtr->stopCallJsOnProcess_.store(true); + extPtr->execOnProcessCon_.notify_one(); + lock.unlock(); + return; + } + std::string processInfoJsonStr; + BJsonUtil::BuildOnProcessRetInfo(processInfoJsonStr, processInfo); + auto task = [obj, scenario, processInfoJsonStr]() { + auto reportExtPtr = obj.promote(); + if (reportExtPtr == nullptr) { + HILOGE("Report onProcess Result error, reportExtPtr is empty"); + return; + } + reportExtPtr->ReportAppProcessInfo(processInfoJsonStr, scenario); + }; + extPtr->reportOnProcessRetPool_.AddTask([task]() { task(); }); + }; +} } // 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 cc1f9e671..757867dbd 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -613,7 +613,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); @@ -698,7 +698,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Init Incremental backup session error, session is empty"); + HILOGE("AppendBundles restore session error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); @@ -793,7 +793,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Init Incremental backup session error, session is empty"); + HILOGE("AppendBundles backup session error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 @@ -830,7 +830,7 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Init Incremental backup session error, session is empty"); + HILOGE("AppendBundles backup session with infos error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 @@ -1728,7 +1728,7 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (bundleNames.empty() || session_ == nullptr) { - HILOGE("Init Incremental backup session error, session is empty"); + HILOGE("AppendBundles clear session error, session is empty"); return EPERM; } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 -- Gitee From 500669122fdd5725739a2a13f839ceb6ac574707 Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Wed, 13 Nov 2024 10:51:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../native/backup_ext/src/sub_ext_extension.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 4156f50d4..1b983404f 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -206,6 +206,10 @@ std::function BackupExtExtension::OnRestoreCallback( HILOGE("Ext extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } HILOGI("Current bundle will execute app done"); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); @@ -242,6 +246,10 @@ std::function BackupExtExtension::OnRestoreExCallbac HILOGE("Extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } if (errCode == ERR_OK && !restoreRetInfo.empty()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); if (spendTime >= BConstants::MAX_TIME_COST) { @@ -302,6 +310,10 @@ std::function BackupExtExtension::IncreOnRestoreExCa HILOGE("Extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } if (errCode == ERR_OK && !restoreRetInfo.empty()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); if (spendTime >= BConstants::MAX_TIME_COST) { @@ -341,6 +353,10 @@ std::function BackupExtExtension::IncreOnRestoreCall HILOGE("Ext extension handle have been released"); return; } + if (extensionPtr->isExecAppDone_.load()) { + HILOGE("Appdone has been executed for the current application"); + return; + } HILOGI("Current bundle will execute app done"); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); -- Gitee