From b4b190fabb1fcc7f96919d58ce50330775a714b9 Mon Sep 17 00:00:00 2001 From: linan24 Date: Fri, 15 Aug 2025 12:26:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E8=93=9D=E5=8C=BA=E8=BD=AF=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: linan24 --- .../native/backup_ext/include/ext_extension.h | 2 +- .../native/backup_ext/include/untar_file.h | 2 +- .../native/backup_ext/src/ext_extension.cpp | 54 +++++-------------- .../backup_ext/src/sub_ext_extension.cpp | 4 +- utils/include/b_filesystem/b_dir.h | 17 ------ utils/src/b_filesystem/b_dir.cpp | 27 ---------- 6 files changed, 17 insertions(+), 89 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index ac4246976..d210b9c47 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -336,7 +336,7 @@ private: void RestoreBigFiles(bool appendTargetPath); void FillEndFileInfos(const std::string &path, const unordered_map &result); void RestoreBigFileAfter(const string &filePath, const struct stat &sta); - int DealIncreUnPacketResult(const off_t tarFileSize, const std::string &tarFileName, + void DealIncreUnPacketResult(const off_t tarFileSize, const std::string &tarFileName, const std::tuple &result); ErrCode StartOnProcessTaskThread(wptr obj, BackupRestoreScenario scenario); diff --git a/frameworks/native/backup_ext/include/untar_file.h b/frameworks/native/backup_ext/include/untar_file.h index 49eb36e26..ed05bae6c 100644 --- a/frameworks/native/backup_ext/include/untar_file.h +++ b/frameworks/native/backup_ext/include/untar_file.h @@ -18,7 +18,6 @@ #include "tar_file.h" #include "b_json/b_report_entity.h" -#include "b_filesystem/b_dir.h" namespace OHOS::FileManagement::Backup { struct FileStatInfo { @@ -31,6 +30,7 @@ struct FileStatInfo { }; using ErrFileInfo = std::map>; +using EndFileInfo = std::map; const int FIRST_PARAM = 0; const int SECOND_PARAM = 1; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 7845876e7..65c10b663 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -924,10 +924,6 @@ int BackupExtExtension::DoRestore(const string &fileName, const off_t fileSize) endFileInfos_.merge(fileInfos); errFileInfos_.merge(errInfos); } - if (BDir::CheckAndRmSoftLink(tarName) || BDir::CheckAndRmSoftLink(fileInfos)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } if (ret != 0) { HILOGE("Failed to untar file = %{public}s, err = %{public}d", tarName.c_str(), ret); return ret; @@ -955,25 +951,23 @@ void BackupExtExtension::GetTarIncludes(const string &tarName, unordered_map &result) { + if (!isDebug_) { + return; + } int err = std::get(result); - EndFileInfo tmpEndInfo = std::get(result); if (!isRpValid_) { if (err != ERR_OK) { endFileInfos_[tarFileName] = tarFileSize; errFileInfos_[tarFileName] = {err}; } + EndFileInfo tmpEndInfo = std::get(result); endFileInfos_.merge(tmpEndInfo); } - if (BDir::CheckAndRmSoftLink(tmpEndInfo)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } ErrFileInfo tmpErrInfo = std::get(result); errFileInfos_.merge(tmpErrInfo); - return ERR_OK; } int BackupExtExtension::DoIncrementalRestore() @@ -1001,9 +995,9 @@ int BackupExtExtension::DoIncrementalRestore() string tarName = path + item; // 当用户指定fullBackupOnly字段或指定版本的恢复,解压目录当前在/backup/restore - if (!BDir::IsFilePathValid(tarName) || BDir::CheckAndRmSoftLink(tarName)) { + if (!BDir::IsFilePathValid(tarName)) { HILOGE("Check incre tarfile path : %{public}s err, path is forbidden", GetAnonyPath(tarName).c_str()); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); + return ERR_INVALID_VALUE; } unordered_map result; GetTarIncludes(tarName, result); @@ -1016,9 +1010,7 @@ int BackupExtExtension::DoIncrementalRestore() std::tuple unPacketRes = UntarFile::GetInstance().IncrementalUnPacket(tarName, path, result); err = std::get(unPacketRes); - if (int tmpErr = DealIncreUnPacketResult(tarFileSize, item, unPacketRes); tmpErr != ERR_OK) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } + DealIncreUnPacketResult(tarFileSize, item, unPacketRes); HILOGI("Application recovered successfully, package path is %{public}s", tarName.c_str()); DeleteBackupIncrementalTars(tarName); } @@ -1096,13 +1088,6 @@ void BackupExtExtension::RestoreBigFilesForSpecialCloneCloud(const ExtManageInfo if (!BDir::IsFilePathValid(fileName)) { HILOGE("Check big special file path : %{public}s err, path is forbidden", GetAnonyPath(fileName).c_str()); errFileInfos_[fileName].emplace_back(DEFAULT_INVAL_VALUE); - if (!RemoveFile(fileName)) { - HILOGE("Failed to delete the backup bigFile %{public}s", GetAnonyPath(fileName).c_str()); - } - return; - } - if (BDir::CheckAndRmSoftLink(fileName)) { - HILOGE("File soft links are forbidden"); return; } if (chmod(fileName.c_str(), sta.st_mode) != 0) { @@ -1141,10 +1126,6 @@ ErrCode BackupExtExtension::RestoreTarForSpecialCloneCloud(const ExtManageInfo & HILOGE("Check spec tarfile hash path : %{public}s err, path is forbidden", GetAnonyPath(tarName).c_str()); return ERR_INVALID_VALUE; } - if (BDir::CheckAndRmSoftLink(tarName)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } if (!BDir::IsFilePathValid(untarPath)) { HILOGE("Check spec tarfile path : %{public}s err, path is forbidden", GetAnonyPath(untarPath).c_str()); return ERR_INVALID_VALUE; @@ -1155,18 +1136,18 @@ ErrCode BackupExtExtension::RestoreTarForSpecialCloneCloud(const ExtManageInfo & } auto [err, fileInfos, errInfos] = UntarFile::GetInstance().UnPacket(tarName, untarPath); if (isDebug_) { + if (err != 0) { + endFileInfos_[tarName] = item.sta.st_size; + errFileInfos_[tarName] = { err }; + } endFileInfos_.merge(fileInfos); errFileInfos_.merge(errInfos); } - if (BDir::CheckAndRmSoftLink(fileInfos)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } - DeleteBackupIncrementalTars(tarName); if (err != ERR_OK) { HILOGE("Failed to untar file = %{public}s, err = %{public}d", tarName.c_str(), err); return err; } + DeleteBackupIncrementalTars(tarName); return ERR_OK; } @@ -1380,10 +1361,6 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, HILOGE("Check big file path : %{public}s err, path is forbidden", GetAnonyPath(filePath).c_str()); return; } - if (BDir::CheckAndRmSoftLink(fileName)) { - HILOGE("File soft links are forbidden"); - return; - } if (isDebug_) { endFileInfos_[filePath] = item.sta.st_size; } @@ -1396,10 +1373,7 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, HILOGE("failed to move the file. err = %{public}d", errno); return; } - if (BDir::CheckAndRmSoftLink(filePath)) { - HILOGE("File soft links are forbidden"); - return; - } + RestoreBigFileAfter(filePath, item.sta); } diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index ff18af6c1..cb1bd5b5c 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1516,9 +1516,7 @@ ErrCode BackupExtExtension::CloudSpecialRestore(string tarName, string untarPath auto unPacketRes = UntarFile::GetInstance().IncrementalUnPacket(tarName, untarPath, result); ErrCode err = ERR_OK; err = std::get(unPacketRes); - if (int tmpErr = DealIncreUnPacketResult(tarFileSize, tarName, unPacketRes); tmpErr != ERR_OK) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } + DealIncreUnPacketResult(tarFileSize, tarName, unPacketRes); HILOGI("Application recovered successfully, package path is %{public}s", tarName.c_str()); DeleteBackupIncrementalTars(tarName); return err; diff --git a/utils/include/b_filesystem/b_dir.h b/utils/include/b_filesystem/b_dir.h index c4d89d1c8..bb5b12e04 100644 --- a/utils/include/b_filesystem/b_dir.h +++ b/utils/include/b_filesystem/b_dir.h @@ -32,7 +32,6 @@ #include "errors.h" namespace OHOS::FileManagement::Backup { -using EndFileInfo = std::map; class BDir { public: /** @@ -103,22 +102,6 @@ public: */ static bool IsFilePathValid(const std::string &filePath); - /** - * @brief 核实文件是否存在软链接并删除 - * - * @param filePath 待核实的路径 - * @return 是否存在软连接 - */ - static bool CheckAndRmSoftLink(const std::string &filePath); - - /** - * @brief 核实文件是否存在软链接并删除 - * - * @param filePaths 待核实的路径集合 - * @return 是否存在软连接 - */ - static bool CheckAndRmSoftLink(const EndFileInfo &filePaths); - /** * @brief 判断目录列表是否包含路径 */ diff --git a/utils/src/b_filesystem/b_dir.cpp b/utils/src/b_filesystem/b_dir.cpp index a725c3f09..7e89517c7 100644 --- a/utils/src/b_filesystem/b_dir.cpp +++ b/utils/src/b_filesystem/b_dir.cpp @@ -532,33 +532,6 @@ bool BDir::IsFilePathValid(const std::string &filePath) return AppFileService::SandboxHelper::IsValidPath(filePath); } -bool BDir::CheckAndRmSoftLink(const std::string &filePath) -{ - if (std::filesystem::is_symlink(filePath)) { - HILOGE("Soft link is not allowed, path = %{public}s", GetAnonyPath(filePath).c_str()); - if (unlink(filePath.c_str()) < 0) { - HILOGE("Failed to unlink the backup file : %{public}s", GetAnonyPath(filePath).c_str()); - } - return true; - } - return false; -} - -bool BDir::CheckAndRmSoftLink(const EndFileInfo &filePaths) -{ - bool isSoftLink = false; - for (const auto &it : filePaths) { - if (std::filesystem::is_symlink(it.first)) { - HILOGE("Soft link is not allowed, path = %{public}s", GetAnonyPath(it.first).c_str()); - isSoftLink = true; - if (unlink(it.first.c_str()) < 0) { - HILOGE("Failed to unlink the backup file : %{public}s", GetAnonyPath(it.first).c_str()); - } - } - } - return isSoftLink; -} - bool BDir::IsDirsMatch(const vector &excludePaths, const string &path) { if (path.empty()) { -- Gitee From 408086b5370f54258d26afe8fb5aa2b044d3dbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Fri, 15 Aug 2025 15:28:09 +0800 Subject: [PATCH 2/6] blue only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- .../native/backup_ext/src/ext_extension.cpp | 10 +- .../backup_ext/src/sub_ext_extension.cpp | 4 +- .../kits/ndk/fileshare/src/oh_file_share.cpp | 2 +- services/backup_sa/src/module_ipc/service.cpp | 3 +- .../src/module_ipc/service_incremental.cpp | 5 +- .../backup_sa/src/module_ipc/sub_service.cpp | 23 - .../module_ipc/svc_restore_deps_manager.cpp | 2 +- .../backup_ext/include/ext_backup_js_mock.h | 3 - tests/mock/module_ipc/service_mock.cpp | 4 +- tests/unittests/backup_sa/BUILD.gn | 1 - .../backup_sa/module_client/BUILD.gn | 86 ---- .../module_client/service_client_test.cpp | 405 ------------------ .../module_external/bms_adapter_test.cpp | 1 - tests/unittests/backup_sa/module_ipc/BUILD.gn | 3 + .../module_ipc/service_other_test.cpp | 5 +- .../module_ipc/service_stub_test.cpp | 6 +- .../backup_sa/module_ipc/service_test.cpp | 6 +- .../backup_sa/module_ipc/sub_service_test.cpp | 3 +- .../b_utils/scan_file_singleton_test.cpp | 24 +- utils/include/b_radar/radar_const.h | 2 +- utils/include/b_utils/scan_file_singleton.h | 4 +- 21 files changed, 43 insertions(+), 559 deletions(-) delete mode 100644 tests/unittests/backup_sa/module_client/BUILD.gn delete mode 100644 tests/unittests/backup_sa/module_client/service_client_test.cpp diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 7845876e7..13608ef7c 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -854,7 +854,7 @@ tuple BackupExtExtension::CalculateDataSize(const B // 扫描文件计算数据量 tie(bigFileInfo, smallFiles) = GetFileInfos(includes, excludes); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); appStatistic_->smallFileCount_ = smallFiles.size(); appStatistic_->bigFileCount_ = bigFileInfo.size(); for (const auto &item : bigFileInfo) { @@ -1039,11 +1039,11 @@ void BackupExtExtension::AsyncTaskBackup(const string config) ptr->CalculateDataSizeTask(config); } catch (const BError &e) { HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); ptr->AppDone(e.GetCode()); } catch (...) { HILOGE("Failed to restore the ext bundle"); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } }; @@ -1066,11 +1066,11 @@ void BackupExtExtension::AsyncTaskBackup(const string config) ptr->DoBackUpTask(config); } catch (const BError &e) { HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); ptr->AppDone(e.GetCode()); } catch (...) { HILOGE("Failed to restore the ext bundle"); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } ptr->DoClear(); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index ff18af6c1..27ccb5dfb 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1592,7 +1592,7 @@ void BackupExtExtension::DoBackUpTask(const string &config) int ret = 0; TarMap fileBackupedInfo; - while (!ScanFileSingleton::GetInstance().GetCompeletedFlag()) { + while (!ScanFileSingleton::GetInstance().GetCompletedFlag()) { ScanFileSingleton::GetInstance().WaitForFiles(); std::map incFiles = ScanFileSingleton::GetInstance().GetAllBigFiles(); if (incFiles.empty()) { @@ -1615,7 +1615,7 @@ void BackupExtExtension::DoBackUpTask(const string &config) ret = DoBackup(bigFileInfo, fileBackupedInfo, smallFiles, includeSize, excludeSize); DoBackupEnd(); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); AppDone(ret); HILOGI("backup app done %{public}d", ret); } diff --git a/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp b/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp index 019f6a598..21449436c 100644 --- a/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp +++ b/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp @@ -94,7 +94,7 @@ static bool ConvertPolicyErrorResult(const std::deque &remote) .activeTime = TimeUtils::GetCurrentTime(), }); if (ret == ERR_OK) { + HILOGE("Success to init a new restore session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -523,6 +524,7 @@ ErrCode Service::InitBackupSession(const sptr &remote) .activeTime = TimeUtils::GetCurrentTime(), }); if (ret == ERR_OK) { + HILOGE("Success to init a new backup session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -977,7 +979,6 @@ ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRe { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - UpdateHandleCnt(errCode); try { ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 60a1838e3..60530df5f 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -348,10 +348,10 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot } totalStatistic_->Report("InitIncrementalBackupSession", MODULE_INIT, errCode); if (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) { - HILOGE("Active restore session error, Already have a session"); + HILOGE("Active incremental backup error, Already have a session"); return errCode; } - HILOGE("Active restore session error"); + HILOGE("Active backup session error"); StopAll(nullptr, true); return errCode; } @@ -759,6 +759,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGE("GetIncrementalFileHandle error, session is empty"); if (session_ == nullptr) { HILOGE("GetIncrementalFileHandle error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 57f6e9eb5..0875d71e7 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -1064,29 +1064,6 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() } } -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) -{ - if (session_ == nullptr) { - HILOGE("Session is empty, bundleName:%{public}s", bundleName.c_str()); - return; - } - HILOGI("Begin"); - try { - if (scenario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); - } - } catch (const BError &e) { - HILOGE("Call onBundleFinished error, client is died"); - return; - } -} - ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { diff --git a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp index 681821422..10932eb32 100644 --- a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp @@ -33,7 +33,7 @@ vector SvcRestoreDepsManager::GetRestoreBundleNames(const vector, int32_t)); MOCK_METHOD((std::function &argv)>), ParseReleaseInfo, ()); - MOCK_METHOD(ErrCode, GetBackupCompatibilityInfo, (std::function, std::string)); - MOCK_METHOD(ErrCode, GetRestoreCompatibilityInfo, (std::function, std::string)); - MOCK_METHOD((std::function &argv)>), ParseCompatibilityInfo, ()); public: MOCK_METHOD(bool, GetProfileFromAbility, (const OHOS::AppExecFwk::AbilityInfo&, const std::string&, std::vector&), (const)); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index c07e58304..735762b18 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -387,14 +387,14 @@ void Service::CreateDirIfNotExist(const std::string &path) { } -void Service::StartRunningTimer(const std::string &bundleName) {} - std::vector Service::GetSupportBackupBundleNames(vector&, bool, const vector&) { return {}; } +void Service::StartRunningTimer(const std::string &bundleName) {} + void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} diff --git a/tests/unittests/backup_sa/BUILD.gn b/tests/unittests/backup_sa/BUILD.gn index b552944b3..5351c84bd 100644 --- a/tests/unittests/backup_sa/BUILD.gn +++ b/tests/unittests/backup_sa/BUILD.gn @@ -19,7 +19,6 @@ group("backup_sa_test") { deps = [ "module_app_gallery:app_gallery_test", - "module_client:service_client_test", "module_external:adapter_test", "module_ipc:backup_sa_ipc_test", "session:session_test", diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn deleted file mode 100644 index 47a26fff8..000000000 --- a/tests/unittests/backup_sa/module_client/BUILD.gn +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("//foundation/filemanagement/app_file_service/app_file_service.gni") -import("//foundation/filemanagement/app_file_service/backup.gni") - -ohos_unittest("service_client_test") { - module_out_path = path_module_out_tests - - include_dirs = [ - "${path_backup}/frameworks/native/backup_kit_inner/include", - "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/services/backup_sa/include", - "${path_backup}/services/backup_sa/include/module_notify", - "${path_backup}/utils/include", - "${path_backup}/utils/src", - "${path_backup}/tests/mock/utils_mock/include", - ".", - ] - - sources = [ - "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", - "service_client_test.cpp", - ] - - deps = [ - "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/services/backup_sa:backup_sa_ipc_stub", - "${path_backup}/utils:backup_utils", - ] - - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD200000", - "private = public", - "protected = public", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_connect_callback_stub", - "ability_runtime:ability_manager", - "access_token:libaccesstoken_sdk", - "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "googletest:gmock_main", - "googletest:gtest_main", - "hilog:libhilog", - "hitrace:hitrace_meter", - "ipc:ipc_core", - "jsoncpp:jsoncpp", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "storage_service:storage_manager_sa_proxy", - ] - - use_exceptions = true -} - -group("backup_sa_service_client_test") { - testonly = true - deps = [ ":service_client_test" ] -} diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp deleted file mode 100644 index ce840db00..000000000 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include - -#include "b_error/b_error.h" -#include "service_client.h" -#include "service_reverse.h" -#include "b_session_restore.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -class ServiceClientTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(); - void SetUp() override {}; - void TearDown() override {}; - -public: - static inline sptr proxy = nullptr; -}; - -void ServiceClientTest::SetUpTestCase() -{ - GTEST_LOG_(INFO) << "begin SetUpTestCase"; - proxy = ServiceClient::GetInstance(); - if (proxy == nullptr) { - GTEST_LOG_(INFO) << "Failed to get ServiceClient instance"; - } -} - -void ServiceClientTest::TearDownTestCase() -{ - if (proxy != nullptr) { - ServiceClient::InvaildInstance(); - proxy = nullptr; - } - ServiceClient::InvaildInstance(); -} - -/** - * @tc.number: SUB_service_client_test_0100 - * @tc.name: SUB_service_client_test_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9KPRL - */ -HWTEST_F(ServiceClientTest, SUB_service_client_test_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0100"; - EXPECT_NE(proxy, nullptr); - ServiceClient::InvaildInstance(); - proxy=ServiceClient::serviceProxy_; - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0100"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0200"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode ret = proxy->Start(); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->Finish(); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->Release(); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0200"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0300"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - int32_t result = -1; - bundleName = "test"; - proxy->CancelForResult(bundleName, result); - EXPECT_EQ(result, 0); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0400, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0400"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode err = -1; - ErrCode ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 0; - ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 1; - ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0400"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0500, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0500"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode err = -1; - ErrCode ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 0; - ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 1; - ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0500"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0600"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - int fd = -1; - ErrCode ret = proxy->GetLocalCapabilities(fd); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - fd = -2; - ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0700, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0700"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - ErrCode ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - fileName = ""; - ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = "test"; - fileName = "test"; - ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0700"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0800"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - bool booleanValue = false; - ErrCode ret = proxy->GetBackupInfo(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_BEF)); - EXPECT_EQ(bundleName, ""); - EXPECT_EQ(fileName, ""); - booleanValue = true; - ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; - ret = proxy->StartFwkTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StartFwkTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; - ret = proxy->StopExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StopExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bool isExt = true; - bundleName = ""; - ret = proxy->UpdateTimer(bundleName, 0, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_EQ(isExt, false); - bundleName = "test"; - ret = proxy->UpdateTimer(bundleName, 10, isExt); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(isExt, false); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0900"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string stringVal = ""; - ErrCode ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = "test"; - ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - int64_t val = -1; - ret = proxy->RefreshDataSize(val); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - val = 1; - ret = proxy->RefreshDataSize(val); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize.Level1) -{ - std::string bundleName = ""; - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1000"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - BFileInfo *fileInfo = nullptr; - BFileInfo bf {bundleName, "", 0}; - fileInfo = &bf; - ErrCode ret = proxy->PublishFile(*fileInfo); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->PublishIncrementalFile(*fileInfo); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1100"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - int fd = 0; - int32_t restoreType = -1; - int32_t userid = -1; - std::vector bundleNames; - std::vector detailInfos; - std::vector bundlesToBackup; - ErrCode ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleNames.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - detailInfos.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - restoreType = 1; - userid = 1; - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1200"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - sptr srptr = nullptr; - ErrCode ret = proxy->InitRestoreSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->InitBackupSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - std::string errMsg = ""; - std::string result = "err"; - proxy->InitRestoreSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - proxy->InitBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - proxy->InitIncrementalBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - BSessionRestore::Callbacks callback; - srptr = sptr(new ServiceReverse(callback)); - ret = proxy->InitRestoreSession(srptr); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy->InitBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - - proxy->InitRestoreSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - proxy->InitBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - proxy->InitIncrementalBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1300"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1400, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1400"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - bool isExt = true; - bundleName = ""; - ErrCode ret = proxy->UpdateSendRate(bundleName, 0, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - bundleName = "test"; - ret = proxy->UpdateSendRate(bundleName, 10, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - bundleName = ""; - ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - bundleName = "test"; - ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - fileName = ""; - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - fileName = "name"; - ret = proxy->AppFileReady(fileName, -1, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - fileName = ""; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - bundleName = "test"; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1400"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp b/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp index a8967a828..58d25582d 100644 --- a/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp +++ b/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp @@ -69,7 +69,6 @@ public: MOCK_METHOD(int32_t, GetExtensionRunningSaList, (const std::string&, (std::vector>&))); MOCK_METHOD(int32_t, GetRunningSaExtensionInfoList, (const std::string&, (std::vector&))); MOCK_METHOD(int32_t, GetCommonEventExtraDataIdlist, (int32_t, (std::vector&), const std::string&)); - MOCK_METHOD((sptr), GetLocalAbilityManagerProxy, (int32_t)); }; class BundleMgrMock : public IRemoteStub { diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index bc4f9bd3b..afeed10d2 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -61,6 +61,7 @@ ohos_unittest("module_ipc_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false @@ -139,6 +140,7 @@ ohos_unittest("backup_service_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false @@ -348,6 +350,7 @@ ohos_unittest("backup_service_scheduler_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index c99367281..a1253d5ea 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -1244,7 +1244,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); + EXPECT_CALL(*skeleton, GetCallingUid()).WillRepeatedly(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, PublishFile(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); @@ -1317,6 +1317,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0200, TestSize.Level1) auto ret = service->AppDone(errCode); EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); @@ -1547,7 +1548,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppendBundlesClearSession_0000, TestSize.Level info.name = "bundleNames"; info.appIndex = 0; bundleInfos.push_back(info); - EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); + EXPECT_CALL(*session, GetSessionUserId()).WillRepeatedly(Return(0)); EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); EXPECT_CALL(*session, IsOnOnStartSched()).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index db4f1931e..160351ddf 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -56,10 +56,8 @@ public: MOCK_METHOD3(ServiceResultReport, ErrCode(const string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode)); MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); - MOCK_METHOD5( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, - RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD5(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId)); MOCK_METHOD4( AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index d47502656..f51d1fc6f 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -888,8 +888,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) BackupExtInfo extInfo {}; auto callDied = [](const string &&bundleName, bool isCleanCalled) {}; auto callConnected = [](const string &&bundleName) {}; - string bundleNameIndexInfo = "123456789"; - extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); + extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, BUNDLE_NAME)); extInfo.backUpConnection->backupProxy_ = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; @@ -2051,8 +2050,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le BackupExtInfo extInfo {}; auto callDied = [](const string &&bundleName, bool isCleanCalled) {}; auto callConnected = [](const string &&bundleName) {}; - string bundleNameIndexInfo = "123456789"; - extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); + extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, BUNDLE_NAME)); impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index cb6051d3f..4d11a9489 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -2306,12 +2306,13 @@ HWTEST_F(ServiceTest, SUB_Service_GetCompatibilityInfo_0200, testing::ext::TestS res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::RESTORE)); + EXPECT_CALL(*svcProxy, HandleGetCompatibilityInfo(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*svcProxy, HandleGetCompatibilityInfo(_, _, _)) .WillOnce(Return(BError(BError::Codes::OK).GetCode())); res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); diff --git a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp index c759c1f44..c8f3f4fe0 100644 --- a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp +++ b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp @@ -76,28 +76,28 @@ HWTEST_F(ScanFileSingletonTest, scan_file_singleton_GetAllBigfiles_0100, testing /** * @brief 测试设置和获取完成标志 - * @tc.number: SUB_scan_file_singleton_SetGetCompeletedFlag_0100 - * @tc.name: scan_file_singleton_SetGetCompeletedFlag_0100 - * @tc.desc: 测试ScanFileSingleton的SetCompeletedFlag和GetCompeletedFlag方法是否能正确设置和获取完成标志 + * @tc.number: SUB_scan_file_singleton_SetGetCompletedFlag_0100 + * @tc.name: scan_file_singleton_SetGetCompletedFlag_0100 + * @tc.desc: 测试ScanFileSingleton的SetCompletedFlag和GetCompletedFlag方法是否能正确设置和获取完成标志 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(ScanFileSingletonTest, scan_file_singleton_SetGetCompeletedFlag_0100, testing::ext::TestSize.Level1) +HWTEST_F(ScanFileSingletonTest, scan_file_singleton_SetGetCompletedFlag_0100, testing::ext::TestSize.Level1) { auto& instance = ScanFileSingleton::GetInstance(); - instance.SetCompeletedFlag(true); - EXPECT_TRUE(instance.GetCompeletedFlag()) << "The completed flag should be true."; + instance.SetCompletedFlag(true); + EXPECT_TRUE(instance.GetCompletedFlag()) << "The completed flag should be true."; - instance.SetCompeletedFlag(false); - EXPECT_FALSE(instance.GetCompeletedFlag()) << "The completed flag should be false."; + instance.SetCompletedFlag(false); + EXPECT_FALSE(instance.GetCompletedFlag()) << "The completed flag should be false."; } /** * @brief 测试添加和获取小文件信息 * @tc.number: SUB_scan_file_singleton_GetAllSmallFiles_0100 * @tc.name: scan_file_singleton_GetAllSmallFiles_0100 - * @tc.desc: 测试ScanFileSingleton的GetAllBigfiles方法是否能正确添加和获取小文件信息 + * @tc.desc: 测试ScanFileSingleton的GetAllSmallfiles方法是否能正确添加和获取小文件信息 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -107,10 +107,10 @@ HWTEST_F(ScanFileSingletonTest, scan_file_singleton_GetAllSmallFiles_0100, testi auto& instance = ScanFileSingleton::GetInstance(); instance.AddSmallFile("/path/to/small_file.txt", 512); - auto allSmallFiels = instance.GetAllSmallFiles(); + auto allSmallFiles = instance.GetAllSmallFiles(); - EXPECT_EQ(allSmallFiels.size(), 1) << "There should be one small file in queue."; - EXPECT_EQ(allSmallFiels["/path/to/small_file.txt"], 512) << "The file size should be 512 bytes."; + EXPECT_EQ(allSmallFiles.size(), 1) << "There should be one small file in queue."; + EXPECT_EQ(allSmallFiles["/path/to/small_file.txt"], 512) << "The file size should be 512 bytes."; } /** diff --git a/utils/include/b_radar/radar_const.h b/utils/include/b_radar/radar_const.h index 6ebf347da..cd9ae364b 100644 --- a/utils/include/b_radar/radar_const.h +++ b/utils/include/b_radar/radar_const.h @@ -107,7 +107,7 @@ struct RadarError { error_ = TransferErrCode(code); } - int16_t TransferErrCode(int32_t code) + uint16_t TransferErrCode(int32_t code) { if (code == 0) { return 0; diff --git a/utils/include/b_utils/scan_file_singleton.h b/utils/include/b_utils/scan_file_singleton.h index a3174279b..2316c7056 100644 --- a/utils/include/b_utils/scan_file_singleton.h +++ b/utils/include/b_utils/scan_file_singleton.h @@ -33,9 +33,9 @@ public: std::map GetAllBigFiles(); - bool GetCompeletedFlag(); + bool GetCompletedFlag(); - void SetCompeletedFlag(bool value); + void SetCompletedFlag(bool value); std::map GetAllSmallFiles(); -- Gitee From c3a33d60bfecb678d08e5842a6cbfb12d17b8384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Fri, 15 Aug 2025 15:34:09 +0800 Subject: [PATCH 3/6] blue only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- .../backup_sa/src/module_ipc/sub_service.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 0875d71e7..f676a797c 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -878,6 +878,30 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName return BError(BError::Codes::OK); } +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ + if (session_ == nullptr) { + HILOGE("Session is empty, bundleName:%{public}s", bundleName.c_str()); + return; + } + HILOGI("Begin"); + try { + if (scenario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); + } + } catch (const BError &e) { + HILOGE("Call onBundleFinished error, client is died"); + return; + } +} + + std::string Service::GetCallerName() { std::string callerName; -- Gitee From 128fee55f6f2010da1275adf179389e81358ff14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Fri, 15 Aug 2025 15:59:53 +0800 Subject: [PATCH 4/6] clean code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- utils/src/b_utils/scan_file_singleton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/src/b_utils/scan_file_singleton.cpp b/utils/src/b_utils/scan_file_singleton.cpp index 8761a4cc3..37455d4fb 100644 --- a/utils/src/b_utils/scan_file_singleton.cpp +++ b/utils/src/b_utils/scan_file_singleton.cpp @@ -52,13 +52,13 @@ std::map ScanFileSingleton::GetAllBigFiles() return fileMap; } -bool ScanFileSingleton::GetCompeletedFlag() +bool ScanFileSingleton::GetCompletedFlag() { std::lock_guard lock(mutexLock_); return isCalculateCompleted_; } -void ScanFileSingleton::SetCompeletedFlag(bool value) +void ScanFileSingleton::SetCompletedFlag(bool value) { std::lock_guard lock(mutexLock_); isCalculateCompleted_ = value; -- Gitee From 205ab338734630a85bfac3189c056c403b770b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Mon, 18 Aug 2025 14:11:34 +0800 Subject: [PATCH 5/6] clean code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- frameworks/native/backup_ext/src/sub_ext_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 27ccb5dfb..95a271f18 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -152,7 +152,7 @@ void BackupExtExtension::SetClearDataFlag(bool isClearData) string BackupExtExtension::GetBundlePath() { - if (BFile::EndsWith(bundleName_, BConstants::BUNDLE_FILE_MANAGER) && bundleName_.size() == BConstants::FM_LEN) { + if (bundleName_ == BConstants::BUNDLE_FILE_MANAGER) { return string(BConstants::PATH_FILEMANAGE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); } else if (bundleName_ == BConstants::BUNDLE_MEDIAL_DATA) { return string(BConstants::PATH_MEDIALDATA_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); -- Gitee From 06badeb540b3b1bd73923ac42fdaf221210074a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Tue, 19 Aug 2025 12:04:02 +0800 Subject: [PATCH 6/6] clean code 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_incremental.cpp | 3 ++- services/backup_sa/src/module_ipc/sub_service.cpp | 1 - tests/unittests/backup_sa/module_ipc/sub_service_test.cpp | 1 - .../backup_utils/b_utils/scan_file_singleton_test.cpp | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 60530df5f..1b478b103 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -340,6 +340,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot .callerName = GetCallerName(), .activeTime = TimeUtils::GetCurrentTime()}); if (errCode == ERR_OK) { + HILOGE("Success to init a new incremental backup session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -759,7 +760,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { - HILOGE("GetIncrementalFileHandle error, session is empty"); + HILOGI("Begin get incrementalFileHandle"); if (session_ == nullptr) { HILOGE("GetIncrementalFileHandle error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 9431a8d81..a71006c6e 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -902,7 +902,6 @@ void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRes } } - std::string Service::GetCallerName() { std::string callerName; diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index 4d11a9489..3a3888e59 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -2306,7 +2306,6 @@ HWTEST_F(ServiceTest, SUB_Service_GetCompatibilityInfo_0200, testing::ext::TestS res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*svcProxy, HandleGetCompatibilityInfo(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); diff --git a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp index c8f3f4fe0..bbd05eb03 100644 --- a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp +++ b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp @@ -97,7 +97,7 @@ HWTEST_F(ScanFileSingletonTest, scan_file_singleton_SetGetCompletedFlag_0100, te * @brief 测试添加和获取小文件信息 * @tc.number: SUB_scan_file_singleton_GetAllSmallFiles_0100 * @tc.name: scan_file_singleton_GetAllSmallFiles_0100 - * @tc.desc: 测试ScanFileSingleton的GetAllSmallfiles方法是否能正确添加和获取小文件信息 + * @tc.desc: 测试ScanFileSingleton的GetAllSmallFiles方法是否能正确添加和获取小文件信息 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 -- Gitee