From d21fb3c68a13d3cd80ac5b64838160364948be0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=9F=E9=92=B0?= Date: Tue, 15 Oct 2024 11:39:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E6=9C=80=E5=A4=A7=E5=B0=9D=E8=AF=95=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E4=BF=AE=E5=A4=8Dsa=E6=AD=BB=E9=94=81=20?= =?UTF-8?q?=EF=BC=88cherry=20picked=20commit=20from=20Signed-off-by:=20Zshengyu26=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backup_sa/include/module_ipc/service.h | 8 +++ .../src/module_ipc/sa_backup_connection.cpp | 2 + services/backup_sa/src/module_ipc/service.cpp | 67 +++++++++---------- utils/include/b_resources/b_constants.h | 2 +- utils/src/b_json/b_json_clear_data_config.cpp | 12 ++-- .../b_json/b_json_service_disposal_config.cpp | 12 ++-- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 4faae92b9..5f2284330 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -172,6 +172,14 @@ public: */ void DeleteDisConfigFile(); + /** + * @brief 尝试清理处置 + * + * @param bundleName 应用名称 + * + */ + void TryToClearDispose(const BundleName &bundleName); + /** * @brief 结束会话删除session,卸载服务 * diff --git a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp index 3f4c84960..5c9ef0f68 100644 --- a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp @@ -128,9 +128,11 @@ ErrCode SABackupConnection::LoadBackupSAExtInner() [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { HILOGE("Load sa %{public}d timeout", saId_); + lock.unlock(); isConnected_.store(false); return LoadBackupSAExt(); } + lock.unlock(); isConnected_.store(true); callConnected_(move(bundleName_)); return LoadBackupSAExt(); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index f9f8902fe..b636d568b 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -85,6 +85,7 @@ const std::string BACKUPSERVICE_WORK_STATUS_KEY = "persist.backupservice.worksta const std::string BACKUPSERVICE_WORK_STATUS_ON = "true"; const std::string BACKUPSERVICE_WORK_STATUS_OFF = "false"; const std::string BACKUP_PERMISSION = "ohos.permission.BACKUP"; +const int32_t MAX_TRY_CLEAR_DISPOSE_NUM = 3; } // namespace /* Shell/Xts user id equal to 0/1, we need set default 100 */ @@ -1433,15 +1434,15 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (SAUtils::IsSABundleName(bundleName)) { HILOGI("SA does not need to StartRestore"); - return ; + return; } IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario != IServiceReverse::Scenario::RESTORE) { - return ; + return; } if (!disposal_->IfBundleNameInDisposalConfigFile(bundleName)) { HILOGE("WriteDisposalConfigFile Failed"); - return ; + return; } HILOGI("AppendIntoDisposalConfigFile OK, bundleName=%{public}s", bundleName.c_str()); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->StartRestore(bundleName); @@ -1454,51 +1455,59 @@ void Service::SendEndAppGalleryNotify(const BundleName &bundleName) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (SAUtils::IsSABundleName(bundleName)) { HILOGI("SA does not need to EndRestore"); - return ; + return; } IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario != IServiceReverse::Scenario::RESTORE) { - return ; + return; } DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); if (disposeErr != DisposeErr::OK) { HILOGE("Error, disposal will be clear in the end"); - return ; + return; } if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); - return ; + return; } HILOGI("DeleteFromDisposalConfigFile OK, bundleName=%{public}s", bundleName.c_str()); } +void Service::TryToClearDispose(const BundleName &bundleName) +{ + int32_t maxAtt = MAX_TRY_CLEAR_DISPOSE_NUM; + int32_t att = 0; + while (att < maxAtt) { + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); + HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); + if (disposeErr == DisposeErr::OK) { + break; + } + ++ att; + HILOGI("Try to clear dispose, num = %{public}d", att); + } + if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { + HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); + } +} + void Service::SendErrAppGalleryNotify() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario != IServiceReverse::Scenario::RESTORE) { - return ; + return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); if (bundleNameList.empty()) { HILOGI("End, All disposal pasitions have been cleared"); - return ; + return; } for (vector::iterator it = bundleNameList.begin(); it != bundleNameList.end(); ++it) { string bundleName = *it; - DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, - bundleName.c_str()); - if (disposeErr != DisposeErr::OK) { - HILOGE("Error, disposal will be clear in the end"); - return ; - } - if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { - HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); - return ; - } + TryToClearDispose(bundleName); } } @@ -1509,17 +1518,7 @@ void Service::ClearDisposalOnSaStart() if (!bundleNameList.empty()) { for (vector::iterator it = bundleNameList.begin(); it != bundleNameList.end(); ++it) { string bundleName = *it; - DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, - bundleName.c_str()); - if (disposeErr != DisposeErr::OK) { - HILOGE("Error, disposal will be clear in the end"); - return ; - } - if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { - HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); - return ; - } + TryToClearDispose(bundleName); } } HILOGI("SA start, All Errdisposal pasitions have been cleared"); @@ -1530,12 +1529,12 @@ void Service::DeleteDisConfigFile() HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario != IServiceReverse::Scenario::RESTORE) { - return ; + return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); if (!bundleNameList.empty()) { HILOGE("DisposalConfigFile is not empty"); - return ; + return; } if (!disposal_->DeleteConfigFile()) { HILOGE("DeleteConfigFile failed"); @@ -1628,7 +1627,7 @@ std::function Service::GetBackupInfoConnectDied(wptr void Service::ClearResidualBundleData(const std::string &bundleName) { if (session_ == nullptr) { - return ; + return; } auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 849f07ecf..5e89c7a50 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -52,7 +52,7 @@ constexpr int XTS_UID = 1; constexpr int DEFAULT_USER_ID = 100; constexpr int BACKUP_UID = 1089; constexpr int EXTENSION_THREAD_POOL_COUNT = 1; -constexpr int BACKUP_LOADSA_TIMEOUT_MS = 4000; +constexpr int BACKUP_LOADSA_TIMEOUT_MS = 5000; constexpr int DECIMAL_BASE = 10; // 十进制基数 diff --git a/utils/src/b_json/b_json_clear_data_config.cpp b/utils/src/b_json/b_json_clear_data_config.cpp index 8210c1397..9d823170f 100644 --- a/utils/src/b_json/b_json_clear_data_config.cpp +++ b/utils/src/b_json/b_json_clear_data_config.cpp @@ -37,24 +37,24 @@ BJsonClearDataConfig::BJsonClearDataConfig() string filePath = PATH_BUNDLE_BACKUP_HOME + CONFIG_NAME; if (access(filePath.c_str(), F_OK) == 0) { HILOGI("file exist filePath:%{public}s", filePath.c_str()); - return ; + return; } HILOGI("Failed to access filePath :%{public}s", filePath.c_str()); UniqueFd fd(open(filePath.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("Failed to creat filePath :%{public}s", filePath.c_str()); - return ; + return; } cJSON *jsonObjectDis = cJSON_CreateObject(); if (jsonObjectDis == nullptr) { HILOGE("Creat json failed"); - return ; + return; } cJSON *jsonArray = cJSON_CreateArray(); if (jsonArray == nullptr) { HILOGE("Creat json failed"); cJSON_Delete(jsonObjectDis); - return ; + return; } cJSON_AddItemToObject(jsonObjectDis, "ClearDataConfigFile", jsonArray); @@ -62,14 +62,14 @@ BJsonClearDataConfig::BJsonClearDataConfig() if (newStr == nullptr) { HILOGE("cJSON_Print json failed"); cJSON_Delete(jsonObjectDis); - return ; + return; } ofstream outFile(filePath); if (!outFile.is_open()) { HILOGE("open json failed"); cJSON_free(newStr); cJSON_Delete(jsonObjectDis); - return ; + return; } outFile << newStr; outFile.close(); diff --git a/utils/src/b_json/b_json_service_disposal_config.cpp b/utils/src/b_json/b_json_service_disposal_config.cpp index 5ab1644b8..22dd89a43 100644 --- a/utils/src/b_json/b_json_service_disposal_config.cpp +++ b/utils/src/b_json/b_json_service_disposal_config.cpp @@ -34,24 +34,24 @@ BJsonDisposalConfig::BJsonDisposalConfig() string filePath = PATH_BUNDLE_BACKUP_HOME + CONFIG_NAME; if (access(filePath.c_str(), F_OK) == 0) { HILOGI("file exist filePath:%{public}s", filePath.c_str()); - return ; + return; } HILOGI("Failed to access filePath :%{public}s", filePath.c_str()); UniqueFd fd(open(filePath.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("Failed to creat filePath :%{public}s", filePath.c_str()); - return ; + return; } cJSON *jsonObjectDis = cJSON_CreateObject(); if (jsonObjectDis == nullptr) { HILOGE("Creat json failed"); - return ; + return; } cJSON *jsonArray = cJSON_CreateArray(); if (jsonArray == nullptr) { HILOGE("Creat json failed"); cJSON_Delete(jsonObjectDis); - return ; + return; } cJSON_AddItemToObject(jsonObjectDis, "DispoasalConfigFile", jsonArray); @@ -59,14 +59,14 @@ BJsonDisposalConfig::BJsonDisposalConfig() if (newStr == nullptr) { HILOGE("cJSON_Print json failed"); cJSON_Delete(jsonObjectDis); - return ; + return; } ofstream outFile(filePath); if (!outFile.is_open()) { HILOGE("open json failed"); free(newStr); cJSON_Delete(jsonObjectDis); - return ; + return; } outFile << newStr; outFile.close(); -- Gitee From 1f0731ec2d9283b9f77ea870c7987fa19ca84d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=9F=E9=92=B0?= Date: Wed, 23 Oct 2024 07:01:36 +0000 Subject: [PATCH 2/2] update services/backup_sa/src/module_ipc/service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张晟钰 --- services/backup_sa/src/module_ipc/service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b636d568b..d83520554 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1485,7 +1485,7 @@ void Service::TryToClearDispose(const BundleName &bundleName) if (disposeErr == DisposeErr::OK) { break; } - ++ att; + ++att; HILOGI("Try to clear dispose, num = %{public}d", att); } if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { -- Gitee