diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index a65829d9afc78dcea4c51ff850e41f3c4d1b3604..6d71765fd28c2a242b21d7dd0cae368ad3e1ab5e 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1163,7 +1163,7 @@ void BackupExtExtension::FillEndFileInfos(const std::string &path, for (const auto &it : result) { std::string filePath = it.first; if (!filePath.empty() && filePath.size() <= PATH_MAX) { - endFileInfos_[filePath] = it.second.size; + endFileInfos_[path + filePath] = it.second.size; } else { HILOGE("FileName : %{public}s error", GetAnonyPath(filePath).c_str()); } diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 65a45b0c1e89ca6aa21202ff3d92dd3489c9f61c..413d103e4399767ecbcd7266f14dca22a295ecb8 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -239,7 +239,7 @@ public: * @param ptr 当前对象 * @param bundleName 应用名称 */ - void DoTimeout(wptr ptr, std::string bundleName); + void DoTimeout(std::string bundleName); /** * @brief 清理残留数据 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 ca28a7fdaf9bd7db591865acad35cf170b1c45ef..2e4f5a59361c73453b670a56531213781c0d0450 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -71,6 +71,7 @@ struct BackupExtInfo { int32_t appendNum {1}; bool isClearData {true}; bool isInPublishFile {false}; + bool isOnProcessNormal {false}; }; class Service; @@ -510,6 +511,22 @@ public: void SetPublishFlag(const std::string &bundleName); + /** + * @brief 设置 bundleName 对应的标志位 + * + * @param bundleName 应用名称 + * @return + */ + bool SetOnProcessFlag(const BundleName &bundleName, bool isOnProcessNormal); + + /** + * @brief 获取 bundleName 对应的标志位 + * + * @param bundleName 应用名称 + * @return + */ + bool GetOnProcessFlag(const BundleName &bundleName); + private: /** * @brief 获取backup extension ability @@ -551,7 +568,6 @@ private: * @return */ uint32_t CalAppProcessTime(const std::string &bundleName); - public: /** * @brief Construct a new Svc Session object diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 9c4bc77df33f06decb9c348efedbe2a68843c380..ca18ae1e32bcf61509bcccd50336387d7753375e 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -2014,7 +2014,11 @@ ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupResto { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + return BError(BError::Codes::SA_INVAL_ARG); + } string bundleName = VerifyCallerAndGetCallerName(); + session_->SetOnProcessFlag(bundleName, true); if (sennario == BackupRestoreScenario::FULL_RESTORE) { session_->GetServiceReverseProxy()->RestoreOnProcessInfo(bundleName, processInfo); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { @@ -2043,7 +2047,7 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu return; } try { - DoTimeout(thisPtr, bundleName); + thisPtr->DoTimeout(bundleName); } catch (...) { HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); thisPtr->ClearSessionAndSchedInfo(bundleName); @@ -2052,19 +2056,19 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu }; } -void Service::DoTimeout(wptr ptr, std::string bundleName) +void Service::DoTimeout(std::string bundleName) { - auto thisPtr = ptr.promote(); - if (!thisPtr) { - HILOGE("ServicePtr is nullptr."); + if (session_ == nullptr) { + HILOGE("SessionPtr is nullptr."); return; } - auto sessionPtr = thisPtr->session_; - if (sessionPtr == nullptr) { - HILOGE("SessionPtr is nullptr."); + if (isInRelease_.load() && session_->GetOnProcessFlag(bundleName)) { + HILOGI("DoTimeout invalid, extension is onProcess, no need to stop extension"); + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); return; } - IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + IServiceReverse::Scenario scenario = session_->GetScenario(); int32_t errCode = BError(BError::Codes::EXT_ABILITY_TIMEOUT).GetCode(); if (scenario == IServiceReverse::Scenario::BACKUP) { AppRadar::Info info(bundleName, "", "on backup timeout"); @@ -2077,7 +2081,7 @@ void Service::DoTimeout(wptr ptr, std::string bundleName) } try { if (SAUtils::IsSABundleName(bundleName)) { - auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); + auto sessionConnection = session_->GetSAExtConnection(bundleName); shared_ptr saConnection = sessionConnection.lock(); if (saConnection == nullptr) { HILOGE("lock sa connection ptr is nullptr"); @@ -2085,17 +2089,17 @@ void Service::DoTimeout(wptr ptr, std::string bundleName) } saConnection->DisconnectBackupSAExt(); } else { - auto sessionConnection = sessionPtr->GetExtConnection(bundleName); + auto sessionConnection = session_->GetExtConnection(bundleName); sessionConnection->DisconnectBackupExtAbility(); } - sessionPtr->StopFwkTimer(bundleName); - sessionPtr->StopExtTimer(bundleName); - thisPtr->ClearSessionAndSchedInfo(bundleName); - thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); } catch (...) { HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - thisPtr->ClearSessionAndSchedInfo(bundleName); - thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); } } 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 d802512bb32b93d1c8be4bfe7626056cf7164df9..a08b6c701f052766a58b29ab412e3ff0ec356028 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -1005,4 +1005,27 @@ void SvcSessionManager::SetPublishFlag(const std::string &bundleName) it->second.isInPublishFile = true; HILOGE("Set PublishFile success, bundleName = %{public}s", bundleName.c_str()); } + +bool SvcSessionManager::SetOnProcessFlag(const BundleName &bundleName, bool isOnProcessNormal) +{ + unique_lock lock(lock_); + if (!impl_.clientToken) { + HILOGE("Set on process flag err, No caller token was specified"); + return false; + } + auto it = GetBackupExtNameMap(bundleName); + it->second.isOnProcessNormal = isOnProcessNormal; + return true; +} + +bool SvcSessionManager::GetOnProcessFlag(const BundleName &bundleName) +{ + unique_lock lock(lock_); + if (!impl_.clientToken) { + HILOGE("Get on process flag err, No caller token was specified"); + return false; + } + auto it = GetBackupExtNameMap(bundleName); + return it->second.isOnProcessNormal; +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/include/svc_session_manager_mock.h b/tests/mock/module_ipc/include/svc_session_manager_mock.h index 680c2bea6989d0dbb59d934573b808c8f805a771..ae332d29ec76c2a0a0ba9717c5d08bd802a30d9f 100644 --- a/tests/mock/module_ipc/include/svc_session_manager_mock.h +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -58,6 +58,8 @@ public: virtual ErrCode ClearSessionData() = 0; virtual int GetSessionCnt() = 0; virtual SvcSessionManager::Impl GetImpl() = 0; + virtual bool SetOnProcessFlag(const BundleName &bundleName, bool isOnProcessNormal) = 0; + virtual bool GetOnProcessFlag(const BundleName &bundleName) = 0; public: BSvcSessionManager() = default; virtual ~BSvcSessionManager() = default; @@ -102,6 +104,8 @@ public: MOCK_METHOD(ErrCode, ClearSessionData, ()); MOCK_METHOD(int, GetSessionCnt, ()); MOCK_METHOD(SvcSessionManager::Impl, GetImpl, ()); + MOCK_METHOD(bool, SetOnProcessFlag, (const BundleName &bundleName, bool isOnProcessNormal)); + MOCK_METHOD(bool, GetOnProcessFlag, (const BundleName &bundleName)); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H diff --git a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp index c6eca0e78d0644685e4d19b28ab6e01258783d24..d457e836c7c6a0c5bc4511fd74c31e9746372d6f 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -253,4 +253,14 @@ SvcSessionManager::Impl SvcSessionManager::GetImpl() { return BSvcSessionManager::sessionManager->GetImpl(); } + +bool SvcSessionManager::SetOnProcessFlag(const BundleName &bundleName, bool isOnProcessNormal) +{ + return return BSvcSessionManager::sessionManager->SetOnProcessFlag(bundleName, isOnProcessNormal); +} + +bool SvcSessionManager::GetOnProcessFlag(const BundleName &bundleName) +{ + return return BSvcSessionManager::sessionManager->GetOnProcessFlag(bundleName); +} } // 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 0c1665b82af8650fc5c0e0065e904927b9665b85..cad15b3e21546a1abe97c27b2fb01b46a0a8c3f4 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -441,4 +441,14 @@ bool SvcSessionManager::CleanAndCheckIfNeedWait(ErrCode &ret, std::vector &bundleNameList) = 0; virtual void SetPublishFlag(const std::string &bundleName) = 0; + virtual bool SetOnProcessFlag(const BundleName &bundleName, bool isOnProcessNormal) = 0; + virtual bool GetOnProcessFlag(const BundleName &bundleName) = 0; public: static inline std::shared_ptr session = nullptr; }; @@ -155,6 +157,8 @@ public: MOCK_METHOD(int64_t, GetLastIncrementalTime, (const std::string &)); MOCK_METHOD(bool, CleanAndCheckIfNeedWait, (ErrCode &, std::vector &)); MOCK_METHOD(void, SetPublishFlag, (const std::string &)); + MOCK_METHOD(bool, SetOnProcessFlag, (const BundleName &bundleName, bool isOnProcessNormal)); + MOCK_METHOD(bool, GetOnProcessFlag, (const BundleName &bundleName)); }; } // namespace OHOS::FileManagement::Backup