diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 0c078b75a22650d47d30711addc1634b242ade3f..c8bd321cdddc29985a3fd505c5df2c961325f6cd 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(); } @@ -171,7 +173,7 @@ private: void DoUser0Backup(const BJsonEntityExtensionConfig &usrConfig); int User0DoBackup(const BJsonEntityExtensionConfig &usrConfig); - + int DoIncrementalBackup(const std::vector &allFiles, const std::vector &smallFiles, const std::vector &bigFiles); @@ -287,6 +289,8 @@ private: ErrCode GetIncreFileHandleForNormalVersion(const std::string &fileName); void RestoreOneBigFile(const std::string &path, const ExtManageInfo &item, const bool appendTargetPath); int DealIncreRestoreBigAndTarFile(); + std::function ReportOnProcessResultCallback(wptr obj, + BackupRestoreScenario scenario); private: std::shared_mutex lock_; @@ -320,6 +324,8 @@ private: OHOS::ThreadPool onProcessTaskPool_; std::atomic isFirstCallOnProcess_ {false}; std::atomic isExecAppDone_ {false}; + OHOS::ThreadPool reportOnProcessRetPool_; + BackupRestoreScenario curScenario_ { BackupRestoreScenario::FULL_BACKUP }; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index c41b331abf235c3793c27ab3b980cd150f6ad284..6effe0cc54baa7ec8553464a823fdcf1a083d346 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(); @@ -386,6 +402,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 +444,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 +492,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 +538,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 +656,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"); @@ -945,4 +947,48 @@ int BackupExtExtension::User0DoBackup(const BJsonEntityExtensionConfig &usrConfi DoUser0Backup(usrConfig); return ERR_OK; } + +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 23bc9a3c73ee7dcc787a5269e64c9f401b0b9a07..54ff81a8fbdca7bdb298cb5adf4888ebb71cd7b1 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -599,7 +599,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); @@ -685,7 +685,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isCleanService_.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__); @@ -781,7 +781,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isCleanService_.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可能耗时 @@ -818,7 +818,7 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_ == nullptr || isCleanService_.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可能耗时 @@ -1711,7 +1711,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可能耗时 @@ -1937,6 +1937,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN ); } else if (scenario == IServiceReverse::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); + SendEndAppGalleryNotify(callerName); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); } BundleEndRadarReport(callerName, errCode, scenario);