diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 040974d2bf45e791e3d2bff0ad578edf95d596f8..4513021ae2d215c03bc5fcb2ae95b777b691f6ff 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 3f4c84960b750d3a08bd2ffe871ea62a2612f2f8..5c9ef0f6814b126b95ca10ed344cc2d2603bba13 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 6df36815e1faf1653875b6f87c92767549b5981f..f48b3a01b756155d9219cf1608ecd31e2674b117 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 */ @@ -1430,15 +1431,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); @@ -1451,51 +1452,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); } } @@ -1506,17 +1515,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"); @@ -1527,12 +1526,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"); @@ -1624,7 +1623,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 849f07ecf4a44f2f7fb61d54bfc9961a8ac6035f..5e89c7a500a3baa65e62fd7e8bcfb3caa4803ea3 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 8210c139780417d2a0e9e1530fddb6608b627253..9d823170f0fb16635e64b7a73e6f21710a50fb1a 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 5ab1644b87c8f632a170c8a50d665da237ac14f8..22dd89a43db28bb7b1ce73c5b104472fa6dc788d 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();