From cbdf65e529f60d4275b99bddf8978f2d377503ae Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 27 Feb 2025 21:36:28 +0800 Subject: [PATCH 01/21] complete service ipc. Signed-off-by: BrainL Change-Id: I0991cc4d9add5f8760df3fcdc858771d04ad09d5 --- bundle.json | 6 +- frameworks/native/backup_ext/BUILD.gn | 1 + .../native/backup_ext/include/ext_extension.h | 5 +- .../native/backup_ext/src/ext_backup.cpp | 5 +- .../native/backup_ext/src/ext_extension.cpp | 75 +- .../backup_ext/src/sub_ext_extension.cpp | 17 +- .../include/service_reverse_stub.h | 4 +- .../backup_kit_inner/src/b_file_info.cpp | 4 +- .../src/b_incremental_backup_session.cpp | 38 +- .../src/b_incremental_data.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 61 +- .../b_incremental_session_restore_async.cpp | 41 +- .../backup_kit_inner/src/b_session_backup.cpp | 40 +- .../src/b_session_restore.cpp | 54 +- .../src/b_session_restore_async.cpp | 39 +- .../backup_kit_inner/src/service_client.cpp | 144 ++ .../src/service_incremental_proxy.cpp | 417 ----- .../backup_kit_inner/src/service_proxy.cpp | 839 ---------- .../native/backup_kit_inner/BUILD.gn | 10 +- .../backup_kit_inner/impl/b_file_info.h | 32 +- .../impl/b_incremental_data.h | 36 +- .../b_incremental_session_restore_async.h | 5 +- .../impl/b_session_restore_async.h | 5 +- .../backup_kit_inner/impl/backup_file_info.h | 44 + .../impl/backup_incremental_data.h | 47 + .../native/backup_kit_inner/impl/i_service.h | 104 -- .../impl/i_service_ipc_interface_code.h | 64 - ...i_service_reverse.h => iservice_reverse.h} | 2 +- .../backup_kit_inner/impl/service_client.h | 58 + .../backup_kit_inner/impl/service_common.h | 29 + .../backup_kit_inner/impl/service_proxy.h | 112 -- interfaces/kits/js/BUILD.gn | 1 + .../kits/js/backup/prop_n_operation.cpp | 37 +- services/backup_sa/BUILD.gn | 132 +- services/backup_sa/ExtensionType.idl | 22 + services/backup_sa/IService.idl | 72 + services/backup_sa/ServiceType.idl | 23 + .../backup_sa/include/module_ipc/service.h | 116 +- .../module_ipc/service_reverse_proxy.h | 4 +- .../include/module_ipc/service_stub.h | 85 - .../module_ipc/svc_restore_deps_manager.h | 5 +- .../include/module_ipc/svc_session_manager.h | 7 +- services/backup_sa/src/module_ipc/service.cpp | 183 ++- .../src/module_ipc/service_incremental.cpp | 70 +- .../backup_sa/src/module_ipc/service_stub.cpp | 858 ---------- .../backup_sa/src/module_ipc/sub_service.cpp | 33 +- .../src/module_ipc/svc_session_manager.cpp | 2 +- test/fuzztest/backupext_fuzzer/BUILD.gn | 1 + test/fuzztest/backupsa_fuzzer/BUILD.gn | 1 + test/fuzztest/backupsaanother_fuzzer/BUILD.gn | 1 + .../backupsaanother_fuzzer.cpp | 22 +- test/fuzztest/backupsaappend_fuzzer/BUILD.gn | 1 + .../backupsaappend_fuzzer.cpp | 18 +- .../backupservicestub_fuzzer/BUILD.gn | 1 + .../backupservicestub_fuzzer.cpp | 567 ------- .../backupservicestubbranch_fuzzer/BUILD.gn | 1 + .../backupservicestubbranch_fuzzer.cpp | 863 +--------- .../backupservicestubbranch_fuzzer/service.h | 87 - test/fuzztest/servicereverse_fuzzer/BUILD.gn | 2 + .../svcrestoredepsmanager_fuzzer/BUILD.gn | 1 + .../backup_kit_inner/service_client_mock.cpp | 80 + .../backup_kit_inner/service_proxy_mock.cpp | 114 +- .../include/service_reverse_proxy_mock.h | 4 +- .../include/svc_session_manager_mock.h | 4 +- tests/mock/module_ipc/service_mock.cpp | 158 +- tests/mock/module_ipc/service_stub_mock.cpp | 877 +++++----- .../mock/module_ipc/src/service_stub_mock.cpp | 394 +++-- .../src/svc_session_manager_mock.cpp | 2 +- .../module_ipc/svc_session_manager_mock.cpp | 2 +- .../svc_session_manager_throw_mock.cpp | 2 +- .../svc_session_manager_throw_mock.h | 4 +- tests/moduletests/backup_kit_inner/BUILD.gn | 2 + .../unittests/backup_api/backup_impl/BUILD.gn | 3 +- .../backup_impl/include/i_service_mock.h | 4 +- .../include/service_reverse_mock.h | 4 +- .../backup_impl/service_proxy_test.cpp | 1444 ----------------- .../backup_impl/service_reverse_stub_test.cpp | 4 +- tests/unittests/backup_ext/BUILD.gn | 13 +- tests/unittests/backup_sa/module_ipc/BUILD.gn | 15 +- .../module_ipc/service_incremental_test.cpp | 93 +- .../module_ipc/service_other_test.cpp | 36 +- .../module_ipc/service_stub_test.cpp | 6 +- .../backup_sa/module_ipc/service_test.cpp | 18 +- .../module_ipc/service_throw_test.cpp | 75 +- tests/unittests/backup_sa/session/BUILD.gn | 19 +- .../session/b_incremental_session_test.cpp | 139 +- .../backup_sa/session/service_client_mock.cpp | 51 + .../backup_sa/session/service_client_mock.h | 34 + .../backup_sa/session/service_proxy_mock.cpp | 146 +- .../backup_sa/session/service_proxy_mock.h | 59 +- tests/unittests/backup_tools/BUILD.gn | 4 + tools/backup_tool/src/tools_op_backup.cpp | 9 +- tools/backup_tool/src/tools_op_check_sa.cpp | 6 +- .../src/tools_op_incremental_backup.cpp | 12 +- utils/BUILD.gn | 6 +- utils/include/b_radar/b_radar.h | 4 +- utils/src/b_radar/b_radar.cpp | 4 +- 97 files changed, 2591 insertions(+), 6816 deletions(-) create mode 100644 frameworks/native/backup_kit_inner/src/service_client.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_proxy.cpp create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h rename interfaces/inner_api/native/backup_kit_inner/impl/{i_service_reverse.h => iservice_reverse.h} (98%) create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_client.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_common.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h create mode 100644 services/backup_sa/ExtensionType.idl create mode 100644 services/backup_sa/IService.idl create mode 100644 services/backup_sa/ServiceType.idl delete mode 100644 services/backup_sa/include/module_ipc/service_stub.h delete mode 100644 services/backup_sa/src/module_ipc/service_stub.cpp delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h create mode 100644 tests/mock/backup_kit_inner/service_client_mock.cpp delete mode 100644 tests/unittests/backup_api/backup_impl/service_proxy_test.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/bundle.json b/bundle.json index d81e5f73a..002d60fc6 100644 --- a/bundle.json +++ b/bundle.json @@ -143,12 +143,10 @@ "impl/b_session_restore.h", "impl/b_session_restore_async.h", "impl/b_file_info.h", - "impl/service_proxy.h", + "impl/service_client.h", "impl/b_session_backup.h", - "impl/i_service_ipc_interface_code.h", "impl/i_service_reverse_ipc_interface_code.h", - "impl/i_service.h", - "impl/i_service_reverse.h" + "impl/iservice_reverse.h" ] } }, diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index ec60d87cd..e1140901c 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("backup_extension_ability_native") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index db933dad2..2cc7e5a5a 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -30,7 +30,8 @@ #include "b_radar/b_radar.h" #include "ext_backup_js.h" #include "ext_extension_stub.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "tar_file.h" #include "thread_pool.h" #include "timer.h" diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index e75dcf5f8..fc37b3296 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -34,7 +34,8 @@ #include "ext_backup_js.h" #include "ext_extension.h" #include "filemgmt_libhilog.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 1119285af..1a9e4f089 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -53,9 +53,9 @@ #include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "iservice.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" namespace OHOS::FileManagement::Backup { @@ -400,7 +400,7 @@ tuple BackupExtExtension::GetIncrementalFileHandle( } VerifyCaller(); if (BDir::CheckFilePathInvalid(fileName)) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_IPC, string("Failed to AGetInstance")); } @@ -459,10 +459,10 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) cache.SetExtManage(pkgInfo); cachedEntity.Persist(); close(cachedEntity.GetFd().Release()); - + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); ErrCode ret = - proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)), - ERR_OK); + proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + ERR_OK); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully"); } else { @@ -500,8 +500,8 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro WaitToSendFd(startTime, fdNum); int32_t errCode = ERR_OK; string filePath = std::get<0>(item.second); - UniqueFd fd(open(filePath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(filePath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(filePath).c_str(), errno); errCode = errno; @@ -513,7 +513,7 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro continue; } } - ret = proxy->AppFileReady(item.first, std::move(fd), errCode); + ret = proxy->AppFileReady(item.first, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully, package name is %{public}s", item.first.c_str()); } else { @@ -685,15 +685,15 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string tarPath = path + tarName; int32_t errCode = ERR_OK; - UniqueFd fd(open(tarPath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(tarPath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("TarFileReady open file failed, file name is %{public}s, err = %{public}d", tarName.c_str(), errno); errCode = errno; AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", "TarFileReady", "tarFile", tarPath}; HiAudit::GetInstance(false).Write(auditLog); } - int ret = proxy->AppFileReady(tarName, std::move(fd), errCode); + int ret = proxy->AppFileReady(tarName, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("TarFileReady: AppFileReady success for %{public}s", tarName.c_str()); // 删除文件 @@ -776,7 +776,7 @@ int BackupExtExtension::DoBackup(TarMap &bigFileInfo, map &small return EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -841,9 +841,9 @@ bool BackupExtExtension::RefreshDataSize(int64_t totalSize) HILOGI("no backup datasize, don't need to refresh"); return true; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("start RefreshDatasize by ipc"); @@ -1709,9 +1709,9 @@ void BackupExtExtension::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("AppDone Begin."); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1724,8 +1724,8 @@ void BackupExtExtension::AppDone(ErrCode errCode) void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("restoreRetInfo is %{public}s", restoreRetInfo.c_str()); auto ret = proxy->ServiceResultReport(restoreRetInfo, scenario, errCode); if (ret != ERR_OK) { @@ -1735,8 +1735,8 @@ void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, void BackupExtExtension::StartExtTimer(bool &isExtStart) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start ext timer by ipc."); auto ret = proxy->StartExtTimer(isExtStart); if (ret != ERR_OK) { @@ -1747,8 +1747,8 @@ void BackupExtExtension::StartExtTimer(bool &isExtStart) void BackupExtExtension::StartFwkTimer(bool &isFwkStart) { HILOGI("Do backup, start fwk timer begin."); - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start fwk timer by ipc."); auto ret = proxy->StartFwkTimer(isFwkStart); if (ret != ERR_OK) { @@ -1761,9 +1761,9 @@ bool BackupExtExtension::StopExtTimer() { HILOGI("StopExtTimer start"); bool isExtStop; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("StopExtTimer by ipc"); @@ -1961,7 +1961,8 @@ static void WriteFile(const string &filename, const vector &srcFiles, sptr proxy) + const vector &srcFiles, + sptr proxy) { string tarFile = bigFileInfo.begin()->first; string manageFile = GetReportFileName(tarFile); @@ -1969,8 +1970,9 @@ ErrCode BackupExtExtension::IncrementalTarFileReady(const TarMap &bigFileInfo, WriteFile(file, srcFiles); string tarName = string(INDEX_FILE_INCREMENTAL_BACKUP).append(tarFile); - ErrCode ret = proxy->AppIncrementalFileReady(tarFile, UniqueFd(open(tarName.data(), O_RDONLY)), - UniqueFd(open(file.data(), O_RDONLY)), ERR_OK); + int fd = open(tarName.data(), O_RDONLY); + int manifestFd = open(file.data(), O_RDONLY); + ErrCode ret = proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalTarFileReady: The application is packaged successfully"); // 删除文件 @@ -2000,8 +2002,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, auto [path, sta, isBeforeTar] = item.second; int32_t errCode = ERR_OK; WaitToSendFd(startTime, fdNum); - UniqueFd fd(open(path.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(path.data(), O_RDONLY); + if (fdval < 0) { HILOGE("IncrementalBigFileReady open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(path).c_str(), errno); errCode = errno; @@ -2019,7 +2021,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, } string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); WriteFile(file, bigInfo); - ret = proxy->AppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY)), errCode); + int manifestFdval = open(file.data(), O_RDONLY); + ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); if (SUCCEEDED(ret)) { HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", item.first.c_str()); @@ -2051,11 +2054,11 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append("all")); WriteFile(file, srcFiles); - UniqueFd fd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)); - UniqueFd manifestFd(open(file.data(), O_RDONLY)); + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); + int manifestFdval = open(file.data(), O_RDONLY); ErrCode ret = - proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), std::move(fd), std::move(manifestFd), - ERR_OK); + proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + manifestFdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalAllFileReady successfully"); RemoveFile(file); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 24e2a9c11..a84f219a2 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -51,9 +51,8 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" #include "b_anony/b_anony.h" @@ -483,7 +482,7 @@ std::function BackupExtExtension::IncOnBackupC HILOGI("Begin get IncOnBackupCallback"); return [obj](ErrCode errCode, std::string errMsg) { HILOGI("App onbackup end"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -525,7 +524,7 @@ std::function BackupExtExtension::IncOnBackupE { HILOGI("Begin get HandleIncBackupEx callback"); return [obj](ErrCode errCode, const std::string backupExRetInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -575,7 +574,7 @@ std::function BackupExtExtension::IncOnBackupE void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Report app process error, proxy is empty"); return; @@ -739,9 +738,9 @@ void BackupExtExtension::CloseOnProcessTimeOutTimer() void BackupExtExtension::AppIncrementalDone(ErrCode errCode) { HILOGI("Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1173,7 +1172,7 @@ int BackupExtExtension::DoIncrementalBackup(const vector if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { throw BError(errno); } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h index 53a4964aa..c981c206f 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" namespace OHOS::FileManagement::Backup { diff --git a/frameworks/native/backup_kit_inner/src/b_file_info.cpp b/frameworks/native/backup_kit_inner/src/b_file_info.cpp index e068da158..c01b287eb 100644 --- a/frameworks/native/backup_kit_inner/src/b_file_info.cpp +++ b/frameworks/native/backup_kit_inner/src/b_file_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_file_info.h" +#include "backup_file_info.h" #include "filemgmt_libhilog.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index 97de333ab..c78a25e5e 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalBackupSession::~BIncrementalBackupSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -76,13 +76,13 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitIncrementalBackupSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +101,7 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks void BIncrementalBackupSession::RegisterBackupServiceDied(function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +111,7 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -122,12 +122,14 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct UniqueFd BIncrementalBackupSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -138,7 +140,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -153,7 +155,7 @@ ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector< ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -174,12 +176,12 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, std::vector infos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + int32_t res = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { @@ -194,7 +196,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -205,7 +207,7 @@ ErrCode BIncrementalBackupSession::Release() ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp index 571805e51..a0a5b1037 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "filemgmt_libhilog.h" #include "message_parcel.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 97468695a..b09e2ce64 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalRestoreSession::~BIncrementalRestoreSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -75,15 +75,15 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { errMsg = "Failed to get backup service"; errCode = BError(BError::Codes::SDK_BROKEN_IPC); HILOGE("Init IncrementalRestoreSession failed, %{public}s", errMsg.c_str()); return nullptr; } - errCode = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitRestoreSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", errCode); AppRadar::Info info ("", "", "create restore session failed"); @@ -104,12 +104,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -119,7 +121,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -128,16 +130,17 @@ ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalRestoreSession::PublishSAFile(BFileInfo fileInfo, UniqueFd fd) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->PublishSAIncrementalFile(fileInfo, move(fd)); + int fdValue = fd.Get(); + return proxy->PublishSAIncrementalFile(fileInfo, fdValue); } ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -147,11 +150,12 @@ ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, cons ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -159,19 +163,23 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -179,14 +187,15 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -207,7 +216,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -217,7 +226,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 170a50db6..fa1eb7624 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -19,7 +19,7 @@ #include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -31,7 +31,7 @@ BIncrementalSessionRestoreAsync::~BIncrementalSessionRestoreAsync() HILOGE("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -47,8 +47,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return nullptr; @@ -79,7 +79,7 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -88,7 +88,7 @@ ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -102,12 +102,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(fdCode, bundlesToRestore, detailInfos, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -115,7 +117,8 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } @@ -125,11 +128,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionData(fdCode, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -137,14 +143,15 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BIncrementalSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -154,7 +161,7 @@ ErrCode BIncrementalSessionRestoreAsync::Release() void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -171,7 +178,7 @@ void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function BSessionBackup::Init(Callbacks callbacks) try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -76,13 +76,13 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitBackupSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +101,7 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, void BSessionBackup::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +111,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -121,7 +121,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) ErrCode BSessionBackup::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -132,12 +132,14 @@ ErrCode BSessionBackup::Start() UniqueFd BSessionBackup::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -148,7 +150,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -163,7 +165,7 @@ ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -183,7 +185,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -203,7 +205,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector ErrCode BSessionBackup::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -213,7 +215,7 @@ ErrCode BSessionBackup::Finish() ErrCode BSessionBackup::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -224,7 +226,7 @@ ErrCode BSessionBackup::Release() ErrCode BSessionBackup::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 21fbc125f..ab86d5ab0 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BSessionRestore::~BSessionRestore() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) try { HILOGI("Init RestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -72,12 +72,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) UniqueFd BSessionRestore::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -87,7 +89,7 @@ UniqueFd BSessionRestore::GetLocalCapabilities() ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -96,7 +98,7 @@ ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestore::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -106,7 +108,7 @@ ErrCode BSessionRestore::Start() ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -114,14 +116,17 @@ ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &f return proxy->GetFileHandle(bundleName, fileName); } -ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -129,18 +134,20 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -148,14 +155,15 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -165,7 +173,7 @@ ErrCode BSessionRestore::Finish() ErrCode BSessionRestore::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -175,7 +183,7 @@ ErrCode BSessionRestore::Release() void BSessionRestore::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -186,7 +194,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -196,7 +204,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) ErrCode BSessionRestore::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index a60c56462..f3f5276bd 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -20,8 +20,9 @@ #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" +#include "service_common.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -32,7 +33,7 @@ BSessionRestoreAsync::~BSessionRestoreAsync() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -48,8 +49,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -80,7 +81,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -89,7 +90,7 @@ ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -103,12 +104,14 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -126,12 +129,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -139,14 +145,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -156,7 +163,7 @@ ErrCode BSessionRestoreAsync::Release() void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -173,7 +180,7 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct ErrCode BSessionRestoreAsync::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp new file mode 100644 index 000000000..6efa0661f --- /dev/null +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022-2025 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 "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + unique_lock getInstanceLock(getInstanceMutex_); + unique_lock lock(proxyMutex_); + if (serviceProxy_ != nullptr) { + return serviceProxy_; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOGE("Get an empty samgr"); + return nullptr; + } + sptr loadCallback = sptr(new ServiceProxyLoadCallback()); + if (loadCallback == nullptr) { + HILOGE("loadCallback is nullptr."); + return nullptr; + } + int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); + if (ret != ERR_OK) { + HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", + FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); + return nullptr; + } + + auto waitStatus = + loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), + [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); + if (!waitStatus) { + HILOGE("Load backup sa timeout"); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceClient::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + BError(BError::Codes::SA_INVAL_ARG).GetCode()); + return nullptr; + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Invalid Instance"); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Load backup sa success, systemAbilityId: %{public}d, remoteObject result:%{public}s", systemAbilityId, + (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + unique_lock lock(proxyMutex_); + serviceProxy_ = iface_cast(remoteObject); + if (serviceProxy_ == nullptr) { + HILOGE("serviceProxy_ is nullptr"); + return; + } + auto remoteObj = serviceProxy_->AsObject(); + if (!remoteObj) { + HILOGE("Failed to get remote object"); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + + auto callback = [](const wptr &obj) { + ServiceClient::InvaildInstance(); + }; + sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); + remoteObj->AddDeathRecipient(deathRecipient); + isLoadSuccess_.store(true); + proxyConVar_.notify_one(); +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + static_cast(BError::Codes::SA_INVAL_ARG)); + proxyConVar_.notify_one(); +} +} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp deleted file mode 100644 index bbb503bfa..000000000 --- a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp +++ /dev/null @@ -1,417 +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. - */ - -#include "service_proxy.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "svc_death_recipient.h" -#include "unique_fd.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::Release() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - if (!WriteParcelableVector(bundleNames, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL), data, reply, - option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION), data, - reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - if (!data.WriteStringVector(infos)) { - HILOGE("Failed to write infos"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - if (!data.WriteFileDescriptor(fd)) { - HILOGE("Failed to send the fd"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (fdFlag == true && !data.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -template -bool ServiceProxy::WriteParcelableVector(const std::vector &parcelableVector, Parcel &data) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!data.WriteUint32(parcelableVector.size())) { - HILOGE("failed to WriteInt32 for parcelableVector.size()"); - return false; - } - - for (const auto &parcelable : parcelableVector) { - if (!data.WriteParcelable(&parcelable)) { - HILOGE("failed to WriteParcelable for parcelable"); - return false; - } - } - - return true; -} - -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!Remote()) { - return BError(BError::Codes::SDK_INVAL_ARG, "Remote is nullptr").GetCode(); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadInt32(result); - HILOGI("ServiceProxy Cancel end, result:%{public}d", result); - - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp deleted file mode 100644 index 187f69ef7..000000000 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ /dev/null @@ -1,839 +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 "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_radar/b_radar.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "system_ability_definition.h" -#include "svc_death_recipient.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::InitRestoreSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Start() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilities() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - AppRadar::Info resInfo("", "", ""); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, "ServiceProxy::GetLocalCapabilities", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL, ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = fd < 0 ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(restoreRetInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the restoreRetInfo").GetCode(); - } - if (!data.WriteInt32(static_cast(scenario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!detailInfos.empty() && !data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &detailInfos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - if (!data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Finish() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -sptr ServiceProxy::GetServiceProxyPointer() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - unique_lock getInstanceLock(getInstanceMutex_); - unique_lock lock(proxyMutex_); - if (serviceProxy_ != nullptr) { - return serviceProxy_; - } - - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - HILOGE("Get an empty samgr"); - return nullptr; - } - sptr loadCallback = sptr(new ServiceProxyLoadCallback()); - if (loadCallback == nullptr) { - HILOGE("loadCallback is nullptr."); - return nullptr; - } - int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); - if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", - FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); - return nullptr; - } - - auto waitStatus = - loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), - [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); - if (!waitStatus) { - HILOGE("Load backup sa timeout"); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - BError(BError::Codes::SA_INVAL_ARG).GetCode()); - return nullptr; - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("invalid instance"); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, - (remoteObject != nullptr) ? "true" : "false"); - if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - unique_lock lock(proxyMutex_); - serviceProxy_ = iface_cast(remoteObject); - if (serviceProxy_ == nullptr) { - HILOGD("serviceProxy_ is nullptr"); - return; - } - auto remoteObj = serviceProxy_->AsObject(); - if (!remoteObj) { - HILOGE("Failed to get remote object"); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - - auto callback = [](const wptr &obj) { - ServiceProxy::InvaildInstance(); - HILOGE("Backup service died"); - }; - sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); - remoteObj->AddDeathRecipient(deathRecipient); - isLoadSuccess_.store(true); - proxyConVar_.notify_one(); -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); - proxyConVar_.notify_one(); -} - -ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) -{ - HILOGI("ServiceProxy GetBackupInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadString(result); - HILOGI("ServiceProxy GetBackupInfo end. result = %s", result.c_str()); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) -{ - HILOGI("ServiceProxy UpdateTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteUint32(timeout)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send timeout").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateTimer end. result = %d", result); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) -{ - HILOGD("ServiceProxy UpdateSendRate Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(sendRate)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateSendRate end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) -{ - HILOGD("ServiceProxy NotifyBundleProcessInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(processInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(static_cast(sennario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()-> SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - HILOGI("ServiceProxy NotifyBundleProcessInfo end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) -{ - HILOGI("ServiceProxy StartExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStart); - HILOGI("ServiceProxy StartExtTimer end. isExtStart = %d", isExtStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) -{ - HILOGI("ServiceProxy StartFwkTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isFwkStart); - HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) -{ - HILOGI("ServiceProxy StopExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStop); - HILOGI("ServiceProxy StopExtTimer end. isExtStop = %{public}d", isExtStop); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) -{ - HILOGI("ServiceProxy RefreshDatasize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteInt64(totalSize)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write totalSize").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - bool result = false; - reply.ReadBool(result); - if (!result) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to Refresh Datasize").GetCode(); - } - return BError(BError::Codes::OK, "success"); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("ServiceProxy, start GetLocalCapabilitiesForBundleInfos"); - if (Remote() == nullptr) { - HILOGE("Remote is nullptr"); - return UniqueFd(-EPERM); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - HILOGI("ServiceProxy, end GetLocalCapabilitiesForBundleInfos"); - return fd; -} - -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) -{ - HILOGI("ServiceProxy GetBackupDataSize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteBool(isPreciseScan)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write isPreciseScan").GetCode(); - } - if (!WriteParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write bundleNameList").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 45fe3c878..096d8feef 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/filemanagement/app_file_service/backup.gni") config("public_config") { include_dirs = [ ".", - "impl", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", ] } @@ -52,9 +52,8 @@ ohos_shared_library("backup_kit_inner") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", ] @@ -76,7 +75,10 @@ ohos_shared_library("backup_kit_inner") { "samgr:samgr_proxy", ] - deps = [ "${path_backup}/utils:backup_utils" ] + deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc", + "${path_backup}/utils:backup_utils", + ] cflags_cc = [ "-fdata-sections", diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h index 356ad5226..b7c3b759a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -13,32 +13,6 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H -#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#include "backup_file_info.h" -#include -#include - -#include "parcel.h" - -namespace OHOS::FileManagement::Backup { -using BundleName = std::string; -using TmpFileSN = uint32_t; - -struct BFileInfo : public Parcelable { - BundleName owner; - std::string fileName; - TmpFileSN sn; // 用于服务零拷贝接收文件场景 - - BFileInfo() = default; - BFileInfo(std::string bundleName, std::string strFileNanme, TmpFileSN id) - : owner(bundleName), fileName(strFileNanme), sn(id) {} - ~BFileInfo() override = default; - - bool ReadFromParcel(Parcel &parcel); - bool Marshalling(Parcel &parcel) const override; - static BFileInfo *Unmarshalling(Parcel &parcel); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +namespace OHOS::FileManagement::Backup {}; \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h index fa513fdcd..95a3bf248 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -12,36 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "backup_incremental_data.h" -#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H -#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H - -#include -#include - -#include "parcel.h" -#include "unique_fd.h" - -namespace OHOS::FileManagement::Backup { -struct BIncrementalData : public Parcelable { - std::string bundleName; - int64_t lastIncrementalTime; - int32_t manifestFd; - std::string backupParameters; - int32_t backupPriority; - - BIncrementalData() = default; - BIncrementalData(std::string name, int64_t nTime, int fd = -1, std::string parameters = "", int32_t priority = 0) - : bundleName(name), lastIncrementalTime(nTime), manifestFd(fd), backupParameters(parameters), - backupPriority(priority) - { - } - ~BIncrementalData() override = default; - - bool ReadFromParcel(Parcel &parcel); - bool Marshalling(Parcel &parcel) const override; - static BIncrementalData *Unmarshalling(Parcel &parcel); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +namespace OHOS::FileManagement::Backup {} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 50c47bf7b..b2b51235f 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -24,7 +24,8 @@ #include "b_file_info.h" #include "errors.h" -#include "i_service.h" +#include "iservice.h" +#include "service_common.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 64615acb2..58ca45178 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -24,7 +24,8 @@ #include "b_file_info.h" #include "errors.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h new file mode 100644 index 000000000..d00e16502 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H + +#include +#include + +#include "parcel.h" + +namespace OHOS::FileManagement::Backup { +using BundleName = std::string; +using TmpFileSN = uint32_t; + +struct BFileInfo : public Parcelable { + BundleName owner; + std::string fileName; + TmpFileSN sn; // 用于服务零拷贝接收文件场景 + + BFileInfo() = default; + BFileInfo(std::string bundleName, std::string strFileNanme, TmpFileSN id) + : owner(bundleName), fileName(strFileNanme), sn(id) {} + ~BFileInfo() override = default; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static BFileInfo *Unmarshalling(Parcel &parcel); +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h new file mode 100644 index 000000000..77785e18b --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H + +#include +#include + +#include "parcel.h" +#include "unique_fd.h" + +namespace OHOS::FileManagement::Backup { +struct BIncrementalData : public Parcelable { + std::string bundleName; + int64_t lastIncrementalTime; + int32_t manifestFd; + std::string backupParameters; + int32_t backupPriority; + + BIncrementalData() = default; + BIncrementalData(std::string name, int64_t nTime, int fd = -1, std::string parameters = "", int32_t priority = 0) + : bundleName(name), lastIncrementalTime(nTime), manifestFd(fd), backupParameters(parameters), + backupPriority(priority) + { + } + ~BIncrementalData() override = default; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static BIncrementalData *Unmarshalling(Parcel &parcel); +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h deleted file mode 100644 index 0108a3437..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ /dev/null @@ -1,104 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_H - -#include -#include - -#include - -#include "b_file_info.h" -#include "b_incremental_data.h" -#include "i_service_ipc_interface_code.h" -#include "i_service_reverse.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -const int DEFAULT_INVAL_VALUE = -1; - -typedef enum TypeRestoreTypeEnum { - RESTORE_DATA_WAIT_SEND = 0, - RESTORE_DATA_READDY = 1, -} RestoreTypeEnum; - -enum BackupRestoreScenario { - FULL_BACKUP = 0, - INCREMENTAL_BACKUP = 1, - FULL_RESTORE = 2, - INCREMENTAL_RESTORE = 3, -}; - -class IService : public IRemoteBroker { -public: - virtual ~IService() = default; - virtual ErrCode InitRestoreSession(sptr remote) = 0; - virtual ErrCode InitRestoreSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode InitBackupSession(sptr remote) = 0; - virtual ErrCode InitBackupSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode Start() = 0; - virtual UniqueFd GetLocalCapabilities() = 0; - virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; - virtual ErrCode PublishFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) = 0; - virtual ErrCode AppDone(ErrCode errCode) = 0; - virtual ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) = 0; - virtual ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; - virtual ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) = 0; - virtual ErrCode Finish() = 0; - virtual ErrCode Release() = 0; - virtual ErrCode Cancel(std::string bundleName, int32_t &result) = 0; - virtual UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) = 0; - virtual ErrCode GetAppLocalListAndDoIncrementalBackup() = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse) = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse, std::string &errMsg) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &bundleInfos) = 0; - - virtual ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) = 0; - virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) = 0; - virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; - virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; - virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) = 0; - virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0; - virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0; - virtual ErrCode StartExtTimer(bool &isExtStart) = 0; - virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0; - virtual ErrCode StopExtTimer(bool &isExtStop) = 0; - virtual ErrCode RefreshDataSize(int64_t totalSize) = 0; - virtual ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h deleted file mode 100644 index ba99705fe..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h +++ /dev/null @@ -1,64 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H - -/*SAID: 5203*/ -namespace OHOS::FileManagement::Backup { -enum class IServiceInterfaceCode { - SERVICE_CMD_INIT_RESTORE_SESSION, - SERVICE_CMD_INIT_RESTORE_SESSION_MSG, - SERVICE_CMD_INIT_BACKUP_SESSION, - SERVICE_CMD_INIT_BACKUP_SESSION_MSG, - SERVICE_CMD_GET_LOCAL_CAPABILITIES, - SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS, - SERVICE_CMD_PUBLISH_FILE, - SERVICE_CMD_APP_FILE_READY, - SERVICE_CMD_APP_DONE, - SERVICE_CMD_RESULT_REPORT, - SERVICE_CMD_START, - SERVICE_CMD_GET_FILE_NAME, - SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL, - SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, - SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, - SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS, - SERVICE_CMD_FINISH, - SERVICE_CMD_RELSEASE_SESSION, - SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL, - SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION, - SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG, - SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION, - SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS, - SERVICE_CMD_PUBLISH_INCREMENTAL_FILE, - SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE, - SERVICE_CMD_APP_INCREMENTAL_FILE_READY, - SERVICE_CMD_APP_INCREMENTAL_DONE, - SERVICE_CMD_GET_INCREMENTAL_FILE_NAME, - SERVICE_CMD_GET_BACKUP_INFO, - SERVICE_CMD_UPDATE_TIMER, - SERVICE_CMD_START_EXT_TIMER, - SERVICE_CMD_START_FWK_TIMER, - SERVICE_CMD_UPDATE_SENDRATE, - SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP, - SERVICE_CMD_REPORT_APP_PROCESS_INFO, - SERVICE_CMD_CANCEL_BUNDLE, - SERVICE_CMD_STOP_EXT_TIMER, - SERVICE_CMD_REFRESH_DATA_SIZE, - SERVICE_CMD_GET_BACKUP_DATA_SIZE, -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h similarity index 98% rename from interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h rename to interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h index 4ca5a7621..c91ca3d5b 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h new file mode 100644 index 000000000..2812aaae6 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H + +#include +#include +#include +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "system_ability_load_callback_stub.h" + + +namespace OHOS::FileManagement::Backup { +class ServiceClient { + +public: + static sptr GetServiceProxyPointer(); + static sptr GetInstance(); + static void InvaildInstance(); + bool CheckServiceProxy(); +public: + explicit ServiceClient(); + ~ServiceClient(); +public: + class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + + public: + std::condition_variable proxyConVar_; + std::atomic isLoadSuccess_ = {false}; + }; + +private: + static inline std::mutex proxyMutex_; + static inline std::mutex getInstanceMutex_; + static inline sptr serviceProxy_ = nullptr; +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h new file mode 100644 index 000000000..3cb31fc79 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H + +namespace OHOS::FileManagement::Backup { +const int DEFAULT_INVAL_VALUE = -1; + +typedef enum TypeRestoreTypeEnum { + RESTORE_DATA_WAIT_SEND = 0, + RESTORE_DATA_READDY = 1, +} RestoreTypeEnum; + +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h deleted file mode 100644 index 4302e07b8..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ /dev/null @@ -1,112 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H - -#include -#include -#include -#include - -#include "i_service.h" -#include "iremote_proxy.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceProxy : public IRemoteProxy { -public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; - ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; - ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; - ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override; - ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; - ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) override; - ErrCode Finish() override; - ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; - ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; - ErrCode AppIncrementalDone(ErrCode errCode) override; - ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; - ErrCode StartExtTimer(bool &isExtStart) override; - ErrCode StartFwkTimer(bool &isFwkStart) override; - ErrCode StopExtTimer(bool &isExtStop) override; - ErrCode RefreshDataSize(int64_t totalSize) override; - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) override; -public: - explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceProxy() override {} - -public: - template - bool WriteParcelableVector(const std::vector &parcelableVector, Parcel &data); - static sptr GetServiceProxyPointer(); - static sptr GetInstance(); - static void InvaildInstance(); - -public: - class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - public: - std::condition_variable proxyConVar_; - std::atomic isLoadSuccess_ = {false}; - }; - -private: - static inline std::mutex proxyMutex_; - static inline std::mutex getInstanceMutex_; - static inline sptr serviceProxy_ = nullptr; - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H \ No newline at end of file diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 16db36cef..8030493aa 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -159,6 +159,7 @@ ohos_shared_library("backup") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index e4a1ef547..e5b5c5950 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -15,14 +15,13 @@ #include "prop_n_operation.h" #include "b_error/b_error.h" -#include "b_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" #include "incremental_backup_data.h" #include "parse_inc_info_from_js.h" -#include "service_proxy.h" +#include "service_client.h" #include "access_token.h" #include "accesstoken_kit.h" #include "ipc_skeleton.h" @@ -39,13 +38,16 @@ static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg) auto fd = make_shared(); auto cbExec = [fd]() -> NError { HILOGI("called LocalCapabilities::AsyncCallback cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncCallback cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilities(); + int fdNum = -1; + proxy->GetLocalCapabilities(fdNum); + UniqueFd fdData(fdNum); + *fd = std::move(fdData); HILOGI("called LocalCapabilities::AsyncCallback cbExec success"); return NError(ERRNO_NOERR); }; @@ -81,15 +83,18 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) } auto fd = make_shared(); - auto cbExec = [fd, bundles { move(bundles) }]() -> NError { + auto cbExec = [fd, bundles {move(bundles)}]() -> NError { HILOGI("called LocalCapabilities::AsyncDataList cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncDataList cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilitiesIncremental(bundles); + int fdValue = -1; + proxy->GetLocalCapabilitiesIncremental(bundles, fdValue); + UniqueFd fdData(fdValue); + *fd = std::move(fdData); return NError(ERRNO_NOERR); }; auto cbCompl = [fd](napi_env env, NError err) -> NVal { @@ -165,8 +170,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info return nullptr; } - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoGetBackupInfo,failed to get proxy"); return nullptr; @@ -191,8 +196,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called UpdateSendRate,failed to get proxy"); return result; @@ -208,8 +213,8 @@ bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoUpdateTimer,failed to get proxy"); return result; diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 8c877bed7..d21cefe54 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -11,9 +11,136 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//foundation/filemanagement/app_file_service/backup.gni") +idl_gen_interface("backup_idl") { + sources = [ "IService.idl" ] + hitrace = "HITRACE_TAG_FILEMANAGEMENT" + log_domainid = "0xD004313" + log_tag = "AppFileService" +} + +config("public_idl_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("backup_sa_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_sa_ipc_type") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*_type.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_sa_ipc_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, []) + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +config("public_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + ohos_shared_library("backup_sa") { branch_protector_ret = "pac_ret" @@ -36,7 +163,6 @@ ohos_shared_library("backup_sa") { "src/module_ipc/service_incremental.cpp", "src/module_ipc/service_incremental_reverse_proxy.cpp", "src/module_ipc/service_reverse_proxy.cpp", - "src/module_ipc/service_stub.cpp", "src/module_ipc/sub_service.cpp", "src/module_ipc/svc_backup_connection.cpp", "src/module_ipc/svc_extension_incremental_proxy.cpp", @@ -55,9 +181,11 @@ ohos_shared_library("backup_sa") { include_dirs = [ "include", "include/module_notify", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", ] deps = [ + ":backup_sa_ipc", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", diff --git a/services/backup_sa/ExtensionType.idl b/services/backup_sa/ExtensionType.idl new file mode 100644 index 000000000..19014d92c --- /dev/null +++ b/services/backup_sa/ExtensionType.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.FileManagement.Backup.ExtensionType; + +struct UniqueFdGroup { + FileDescriptor fd; + FileDescriptor reportFd; + int errCode; +}; \ No newline at end of file diff --git a/services/backup_sa/IService.idl b/services/backup_sa/IService.idl new file mode 100644 index 000000000..5ecb32295 --- /dev/null +++ b/services/backup_sa/IService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +package OHOS.FileManagement.Backup; +import ServiceType; +interface OHOS.FileManagement.Backup.IServiceReverse; +sequenceable BackupFileInfo..OHOS.FileManagement.Backup.BFileInfo; +sequenceable BackupIncrementalData..OHOS.FileManagement.Backup.BIncrementalData; +interface OHOS.FileManagement.Backup.IService{ + [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 2] void InitBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 3] void InitBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 4] void Start(); + [ipccode 5] void GetLocalCapabilities([out] FileDescriptor fd); + [ipccode 6] void GetLocalCapabilitiesForBundleInfos([out] FileDescriptor fd); + [ipccode 7] void PublishFile([in] BFileInfo fileInfo); + [oneway, ipccode 8] void GetFileHandle([in] String bundleName, [in] String fileName); + [ipccode 9] void AppendBundlesRestoreSessionDataByDetail([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] String[] detailInfos, + [in] int restoreType, + [in] int userId); + [ipccode 10] void AppendBundlesRestoreSessionData([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] int restoreType, + [in] int userId); + [ipccode 11] void AppendBundlesBackupSession([in] String[] bundleNames); + [ipccode 12] void AppendBundlesDetailsBackupSession([in] String[] bundleNames, [in] String[] bundleInfos); + [ipccode 13] void Finish(); + [ipccode 14] void Release(); + [ipccode 15] void Cancel([in] String bundleName, [out] int cancelResult); + [ipccode 16] void GetAppLocalListAndDoIncrementalBackup(); + [ipccode 17] void GetIncrementalFileHandle([in] String bundleName, [in] String fileName); + [ipccode 18] void GetBackupInfo([in] String bundleName, [out] String getBackupInfoResult); + [ipccode 19] void UpdateTimer([in] String bundleName, [in] unsigned int timeout, [out] boolean updateTimerResult); + [ipccode 20] void UpdateSendRate([in] String bundleName, [in] int sendRate, [out] boolean updateSendRateResult); + [ipccode 21] void StartExtTimer([out] boolean isExtStart); + [ipccode 22] void StartFwkTimer([out] boolean isFwkStart); + [ipccode 23] void StopExtTimer([out] boolean isExtStop); + [ipccode 24] void GetLocalCapabilitiesIncremental([in] BIncrementalData[] bundleNames, [out] FileDescriptor fd); + [ipccode 25] void InitIncrementalBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 26] void InitIncrementalBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, + [out] String errMsg); + [ipccode 27] void AppendBundlesIncrementalBackupSession([in] BIncrementalData[] bundlesToBackup); + [ipccode 28] void AppendBundlesIncrementalBackupSessionWithBundleInfos([in] BIncrementalData[] bundlesToBackup, + [in]String[] bundleInfos); + [ipccode 29] void PublishIncrementalFile([in] BFileInfo fileInfo); + [ipccode 30] void PublishSAIncrementalFile([in] BFileInfo fileInfo, [in] FileDescriptor fd); + [ipccode 31] void AppIncrementalFileReady([in] String fileName, [in] FileDescriptor fd, [in] FileDescriptor manifestFd, + [in] int appIncrementalFileReadyErrCode); + [ipccode 32] void AppIncrementalDone([in] int appIncrementalDoneErrCode); + [ipccode 33] void ReportAppProcessInfo([in] String processInfo, [in] BackupRestoreScenario scenario); + [ipccode 34] void RefreshDataSize([in] long totalDataSize); + [ipccode 35] void AppDone([in] int appDoneErrCode); + [ipccode 36] void AppFileReady([in]String fileName, [in] FileDescriptor fd, [in] int appFileReadyErrCode); + [ipccode 37] void ServiceResultReport([in]String restoreRetInfo, [in] BackupRestoreScenario sennario, + [in] int serviceResultReportErrCode); + [ipccode 38] void GetBackupDataSize([in] boolean isPreciseScan,[in] BIncrementalData[] bundleNameList); + } \ No newline at end of file diff --git a/services/backup_sa/ServiceType.idl b/services/backup_sa/ServiceType.idl new file mode 100644 index 000000000..5fc7cb1cf --- /dev/null +++ b/services/backup_sa/ServiceType.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.FileManagement.Backup; + +enum BackupRestoreScenario { + FULL_BACKUP = 0, + INCREMENTAL_BACKUP = 1, + FULL_RESTORE = 2, + INCREMENTAL_RESTORE = 3, +}; \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 34a0fb99a..075f0b640 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -23,7 +23,7 @@ #include "b_json/b_json_clear_data_config.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_service_disposal_config.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" #include "module_sched/sched_scheduler.h" #include "service_stub.h" @@ -48,53 +48,70 @@ class Service : public SystemAbility, public ServiceStub, protected NoCopyable { // 以下都是IPC接口 public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitRestoreSession(const sptr& remote) override; + ErrCode InitRestoreSessionWithErrMsg(const sptr& reverseIpcRemoteObject, + std::string& errMsg) override; + ErrCode InitBackupSession(const sptr& remote) override; + ErrCode InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; + ErrCode GetLocalCapabilities(int& fd) override; + + ErrCode GetLocalCapabilitiesForBundleInfos(int& fd) override; ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) override; ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, + ErrCode ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) override; ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &bundleInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + + ErrCode AppendBundlesRestoreSessionDataByDetail( + int fd, + const std::vector& bundleNames, + const std::vector& detailInfos, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesRestoreSessionData( + int fd, + const std::vector& bundleNames, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; + ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; + ErrCode Cancel(const std::string& bundleName, int32_t &result) override; + ErrCode GetLocalCapabilitiesIncremental( + const std::vector& bundleNames, + int& fd) override; ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitIncrementalBackupSession(const sptr& remote) override; + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector& bundlesToBackup, + const std::vector& bundleInfos) override; + ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; + ErrCode PublishSAIncrementalFile( + const BFileInfo& fileInfo, + int fd) override; + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); + ErrCode AppIncrementalFileReady( + const std::string& fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; + ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; + ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override; + ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override; + ErrCode ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; ErrCode StopExtTimer(bool &isExtStop) override; @@ -104,7 +121,7 @@ public: const ErrCode errCode, const BackupRestoreScenario sennario); void StartGetFdTask(std::string bundleName, wptr ptr); - ErrCode GetBackupDataSize(bool isPreciseScan, vector bundleNameList) override; + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) override; // 以下都是非IPC接口 public: @@ -212,7 +229,7 @@ public: * @param bundleName 应用名称 * */ - AAFwk::Want CreateConnectWant (BundleName &bundleName); + AAFwk::Want CreateConnectWant (const BundleName &bundleName); /** * @brief SA backup回调 @@ -242,7 +259,8 @@ public: * @param bundleName 应用名称 * */ - std::function GetBackupInfoConnectDone(wptr obj, std::string &bundleName); + std::function GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName); /** * @brief GetBackupInfo extension死亡回调 @@ -252,7 +270,7 @@ public: * */ std::function GetBackupInfoConnectDied( - wptr obj, std::string &bundleName); + wptr obj, const std::string &bundleName); /** * @brief timeout callback @@ -526,7 +544,7 @@ private: * @param result 业务结果出参 * */ - ErrCode GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result); + ErrCode GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result); /** * @brief 添加需要清理的Session @@ -646,6 +664,28 @@ private: bool GetScanningInfo(wptr obj, size_t scannedSize, string &scanning); void SetScanningInfo(string &scanning, string name); + + ErrCode InitRestoreSession(const sptr& remote, std::string &errMsg); + + UniqueFd GetLocalCapabilities(); + UniqueFd GetLocalCapabilitiesForBundleInfos(); + + ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); + + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + + UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames); + + ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &infos); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h index 7578aca36..567082b54 100644 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ b/services/backup_sa/include/module_ipc/service_reverse_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -16,7 +16,7 @@ #ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H #define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h deleted file mode 100644 index d4484365a..000000000 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ /dev/null @@ -1,85 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H - -#include - -#include "i_service.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceStub(); - ~ServiceStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdStart(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdFinish(MessageParcel &data, MessageParcel &reply); - int32_t CmdRelease(MessageParcel &data, MessageParcel &reply); - int32_t CmdCancel(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply); - int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStopExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply); - void ServiceStubSupplement(); - void ServiceStubSuppAppendBundles(); - -public: - template - bool ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h index cb83798b9..cea2d222e 100644 --- a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h +++ b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -22,7 +22,8 @@ #include #include "b_json/b_json_entity_caps.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { 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 98fd49414..3585fd62c 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -32,8 +32,9 @@ #include "b_file_info.h" #include "b_incremental_data.h" #include "b_resources/b_constants.h" -#include "i_service.h" -#include "i_service_reverse.h" +#include "service_common.h" +#include "iservice.h" +#include "iservice_reverse.h" #include "module_ipc/svc_backup_connection.h" #include "module_ipc/sa_backup_connection.h" #include "svc_death_recipient.h" @@ -332,7 +333,7 @@ public: * * @param bundleName 应用名称 */ - sptr CreateBackupConnection(BundleName &bundleName); + sptr CreateBackupConnection(const BundleName &bundleName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 65a225c97..b4ce9a773 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -133,11 +133,11 @@ void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCod UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } } @@ -224,12 +224,12 @@ void Service::OnStart() } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { if (!bundleNameList.empty()) { - OnStartResRadarReport(bundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + HILOGI("bundleNameList !=null"); } if (!residualBundleNameList.empty()) { OnStartResRadarReport(residualBundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); } SetOccupySession(true); session_->Active( @@ -274,6 +274,14 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +ErrCode Service::GetLocalCapabilities(int& fd) +{ + UniqueFd fdResult(GetLocalCapabilities()); + fd = fdResult.Release(); + HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -362,8 +370,8 @@ void Service::PermissionCheckFailRadar(const std::string &info, const std::strin { std::string funcPos = "Service::"; AppRadar::Info resInfo("", "", info); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } @@ -379,8 +387,8 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) HILOGE("Verify and get caller name failed, Get hap token info failed"); return BError(BError::Codes::SA_INVAL_ARG); } - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, - hapTokenInfo.instIndex); + std::string bundleNameIndexInfo = + BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, hapTokenInfo.instIndex); ErrCode ret = session_->VerifyBundleName(bundleNameIndexInfo); if (ret != ERR_OK) { HILOGE("Verify bundle name failed, bundleNameIndexInfo:%{public}s", bundleNameIndexInfo.c_str()); @@ -461,7 +469,7 @@ ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) return VerifyCaller(); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -493,7 +501,7 @@ ErrCode Service::InitRestoreSession(sptr remote) return ret; } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitBackupSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -625,14 +633,15 @@ static vector GetRestoreBundleNames(UniqueFd fd, } void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) + const vector &appendBundleNames, + const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," "restoreBundleNames size:%{public}zu", appendBundleNames.size(), restoreBundleNames.size()); for (const auto &bundleName : appendBundleNames) { auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&bundleName](const auto &obj) { return obj == bundleName; }); + [&bundleName](const auto &obj) { return obj == bundleName; }); if (it == restoreBundleNames.end()) { HILOGE("AppendBundles failed, bundleName = %{public}s.", bundleName.c_str()); OnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), session, bundleName); @@ -641,8 +650,25 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &bundleInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionDataByDetail"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType, + int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); @@ -663,8 +689,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector bundleNamesOnly; std::map isClearDataFlags; std::map> bundleNameDetailMap = - BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - session_->GetSessionUserId(), isClearDataFlags); + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, session_->GetSessionUserId(), + isClearDataFlags); std::string oldBackupVersion; auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); @@ -675,8 +701,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("End"); @@ -695,7 +721,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &restoreBundleInfos, - std::vector &restoreBundleNames, RestoreTypeEnum restoreType, std::string &backupVersion) + std::vector &restoreBundleNames, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -706,11 +734,11 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); + restoreInfo.extensionName.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { @@ -731,6 +759,18 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionData"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); +} ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, @@ -779,7 +819,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } -void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, +void Service::SetCurrentSessProperties( + std::vector &restoreBundleInfos, std::vector &restoreBundleNames, std::map> &bundleNameDetailMap, std::map &isClearDataFlags, RestoreTypeEnum restoreType, std::string &backupVersion) @@ -795,7 +836,7 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); @@ -816,14 +857,14 @@ void Service::SetCurrentSessProperties(std::vector } BJsonUtil::BundleDetailInfo broadCastInfo; BJsonUtil::BundleDetailInfo uniCastInfo; - bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, - broadCastInfo); + bool broadCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, broadCastInfo); if (broadCastRet) { bool notifyRet = DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); HILOGI("Publish event end, notify result is:%{public}d", notifyRet); } - bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, - uniCastInfo); + bool uniCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo); if (uniCastRet) { HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); @@ -873,7 +914,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName } ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &bundleInfos) + const vector &bundleInfos) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -916,19 +957,20 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun } } -void Service::HandleCurGroupBackupInfos(std::vector &backupInfos, +void Service::HandleCurGroupBackupInfos( + std::vector &backupInfos, std::map> &bundleNameDetailMap, std::map &isClearDataFlags) { for (auto &info : backupInfos) { - HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", - info.name.c_str(), info.extensionName.c_str(), info.appIndex); + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", info.name.c_str(), + info.extensionName.c_str(), info.appIndex); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); BJsonUtil::BundleDetailInfo uniCastInfo; if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) { HILOGI("current bundle:%{public}s, unicast info:%{public}s, unicast info size:%{public}zu", - bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); + bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); @@ -937,8 +979,7 @@ void Service::HandleCurGroupBackupInfos(std::vector } } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -975,8 +1016,10 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } } -ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, - const ErrCode errCode, const BackupRestoreScenario sennario) +ErrCode Service::SAResultReport(const std::string bundleName, + const std::string restoreRetInfo, + const ErrCode errCode, + const BackupRestoreScenario sennario) { SADone(errCode, bundleName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { @@ -993,7 +1036,7 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); } else if (sennario == BackupRestoreScenario::FULL_BACKUP || - sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::BACKUP); } return BError(BError::Codes::OK); @@ -1003,8 +1046,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore { HILOGI("Begin"); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && - sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { return; } if (session_->OnBundleFileReady(bundleName)) { @@ -1092,9 +1134,9 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) int32_t errCode = 0; UniqueFd fd = proxy->GetFileHandle(fileName, errCode); if (errCode != ERR_OK) { - AppRadar::Info info (bundleName, "", ""); + AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); @@ -1181,7 +1223,8 @@ int Service::Dump(int fd, const vector &args) } void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, const ErrCode ret) + const std::string &bundleName, + const ErrCode ret) { try { if (session_ == nullptr) { @@ -1547,7 +1590,8 @@ void Service::SessionDeactive() } } -std::function Service::GetBackupInfoConnectDone(wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName) { HILOGI("GetBackupInfoConnectDone, bundleName: %{public}s", bundleName.c_str()); @@ -1560,8 +1604,8 @@ std::function Service::GetBackupInfoConnectDone(wptr }; } -std::function Service::GetBackupInfoConnectDied( - wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDied(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName, bool isCleanCalled) { HILOGI("GetBackupInfoConnectDied, bundleName: %{public}s", bundleName.c_str()); @@ -1604,7 +1648,7 @@ ErrCode Service::ClearResidualBundleData(const std::string &bundleName) return res; } -ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result) { if (session_ == nullptr) { HILOGE("Get BackupInfo error, session is empty."); @@ -1650,7 +1694,7 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { @@ -1660,7 +1704,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } try { std::lock_guard lock(getBackupInfoProcLock_); - HILOGI("Service::GetBackupInfo begin."); + HILOGI("Service::GetBackupInfo begin bundleName: %{public}s", bundleName.c_str()); if (session_ == nullptr || isOccupyingSession_.load()) { HILOGE("Get BackupInfo error, session is empty."); return BError(BError::Codes::SA_INVAL_ARG); @@ -1725,7 +1769,7 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { try { HILOGI("Service::UpdateTimer begin."); @@ -1754,7 +1798,7 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res } } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); if (session_ == nullptr || isOccupyingSession_.load()) { @@ -1793,7 +1837,8 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool ret = BError(BError::Codes::SA_INVAL_ARG); break; } - ret = proxy->UpdateFdSendRate(bundleName, sendRate); + std::string extBundleName = static_cast(bundleName); + ret = proxy->UpdateFdSendRate(extBundleName, sendRate); if (ret != NO_ERROR) { HILOGE("Extension do updateSendRate failed, ret:%{public}d", ret); result = false; @@ -1806,7 +1851,7 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool return ret; } -AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +AAFwk::Want Service::CreateConnectWant(const BundleName &bundleName) { BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; AAFwk::Want want; @@ -1842,12 +1887,14 @@ ErrCode Service::BackupSA(std::string bundleName) return BError(BError::Codes::OK); } -void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, - const ErrCode &errCode) +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) { auto task = [bundleName, fd, result, errCode, this]() { HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", - bundleName.c_str(), fd, result.c_str(), errCode); + bundleName.c_str(), fd, result.c_str(), errCode); session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); @@ -1864,8 +1911,8 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) { auto task = [bundleName, result, errCode, this]() { - HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", - bundleName.c_str(), result.c_str(), errCode); + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", bundleName.c_str(), + result.c_str(), errCode); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); }; threadPool_.AddTask([task]() { @@ -1915,16 +1962,10 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN auto ms = std::chrono::duration_cast(now.time_since_epoch()); std::stringstream strTime; strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "PROC_NAME", "ohos.appfileservice", - "BUNDLENAME", callerName, - "PID", getpid(), - "TIME", strTime.str() - ); + << (std::setw(INDEX)) << (ms.count() % MS_1000); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str()); } else if (scenario == IServiceReverse::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); @@ -1932,7 +1973,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN BundleEndRadarReport(callerName, errCode, scenario); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 307b4204b..9f757a668 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -121,6 +121,15 @@ void Service::CreateDirIfNotExist(const std::string &path) } } } +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin GetLocalCapabilitiesIncremental fd = %{private}d", fd); + UniqueFd fdResult(GetLocalCapabilitiesIncremental(bundleNames)); + fd = fdResult.Release(); + HILOGI("End GetLocalCapabilitiesIncremental fd = %{private}d", fd); + return BError(BError::Codes::OK); // anytime return OK +} UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) { @@ -211,9 +220,11 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); - string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). - append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); - HILOGD("path = %{public}s,bundleName = %{public}s", path.c_str(), bundleName.c_str()); + string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()) + .append(bundleName) + .append("/") + .append(BConstants::BACKUP_STAT_SYMBOL) + .append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { HILOGD("fdLocal open fail, error = %{public}d", errno); @@ -293,7 +304,7 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() } } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr& remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -328,7 +339,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return errCode; } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -414,6 +425,13 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return AppendBundlesIncrementalBackupSession(bundlesToBackup, bundleInfos); +} ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, const std::vector &infos) @@ -518,6 +536,13 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) +{ + HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); + UniqueFd uniquedParameter(fd); + return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); +} + ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { std::string bundleName = fileInfo.owner; @@ -541,8 +566,11 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd return saConnection->CallRestoreSA(move(fd)); } -ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, - UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, + const std::string &fileName, + UniqueFd fd, + UniqueFd manifestFd, + int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -556,13 +584,13 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st fd = session_->OnBundleExtManageInfo(bundleName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); + move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); if (ret != ERR_OK) { - HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); return ret; } } @@ -577,6 +605,23 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st } } +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + HILOGI("Begin AppIncrementalFileReady:%{public}s, fd:%{public}d, manifestFd:%{public}d, errcode:%{public}d", + fileName.c_str(), fd, manifestFd, appIncrementalFileReadyErrCode); + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); + } + UniqueFd fdUnique(fd); + UniqueFd manifestFdUnique(manifestFd); + return AppIncrementalFileReady(fileName, std::move(fdUnique), std::move(manifestFdUnique), + appIncrementalFileReadyErrCode); +} + ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -739,7 +784,8 @@ bool Service::IncrementalBackup(const string &bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); } return true; - } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + } else if (scenario == IServiceReverse::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -904,7 +950,7 @@ void Service::CancelTask(std::string bundleName, wptr ptr) thisPtr->OnAllBundlesFinished(BError(BError::Codes::OK)); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin, bundle name:%{public}s", bundleName.c_str()); diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp deleted file mode 100644 index ae94248e9..000000000 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ /dev/null @@ -1,858 +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. - */ - -/* - * 注意: - * - 注意点1:本文件原则上只处理与IPC模块的IO,具体业务逻辑实现在service.cpp中 - * - 注意点2:所有调用开头处打印 Begin 字样,通过BError返回正常结果/错误码,这是出于防抵赖的目的 - */ - -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "module_ipc/service_reverse_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; - - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER)] = - &ServiceStub::CmdStartExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] = - &ServiceStub::CmdStartFwkTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; -} - -void ServiceStub::ServiceStubSuppAppendBundles() -{ - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; -} - -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT)] = - &ServiceStub::CmdResultReport; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - ServiceStubSuppAppendBundles(); - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishSAIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE)] = - &ServiceStub::CmdAppIncrementalDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; - ServiceStubSupplement(); -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitRestoreSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitRestoreSession(iremote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int res = InitBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int res = InitBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppFileReady(fileName, move(fd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = AppDone(errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - int32_t scenario; - ErrCode errCode; - if (!data.ReadString(restoreRetInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreRetInfo"); - } - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive scenario"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - HILOGE("Failed to receive bundle detailInfos"); - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesBackupSession(bundleNames); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - - int32_t res = AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdGetBackupInfo Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - string result; - ret = GetBackupInfo(bundleName, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdGetBackupInfo end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateTimer Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); - } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateSendRate Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateSendRate")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateSendRate end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartExtTimer Begin."); - int ret = ERR_OK; - bool isExtStart; - ret = StartExtTimer(isExtStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isExtStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartFwkTimer Begin."); - int ret = ERR_OK; - bool isFwkStart; - ret = StartFwkTimer(isFwkStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isFwkStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartFwkTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!ReadParcelableVector(bundleNames, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - UniqueFd fd(GetLocalCapabilitiesIncremental(bundleNames)); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - int32_t res = GetAppLocalListAndDoIncrementalBackup(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitIncrementalBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitIncrementalBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - std::vector infos; - if (!data.ReadStringVector(&infos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive infos"); - } - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishIncrementalFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - UniqueFd fd(data.ReadFileDescriptor()); - int res = PublishSAIncrementalFile(*fileInfo, move(fd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - UniqueFd manifestFd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - manifestFd = UniqueFd(data.ReadFileDescriptor()); - if (manifestFd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive manifestFd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppIncrementalFileReady(fileName, move(fd), move(manifestFd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply) -{ - int32_t ret; - if (!data.ReadInt32(ret)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bool flag"); - } - int res = AppIncrementalDone(ret); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - return GetIncrementalFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - string processInfo; - if (!data.ReadString(processInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t scenario; - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - return ReportAppProcessInfo(processInfo, secenrioInfo); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStopExtTimer Begin."); - bool isExtStop; - auto ret = StopExtTimer(isExtStop); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call StopExtTimer")); - } - if (!reply.WriteBool(isExtStop)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStopExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdRefreshDataSize Begin."); - int64_t totalDatasize = 0; - if (!data.ReadInt64(totalDatasize)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive totalDatasize").GetCode(); - } - auto ret = RefreshDataSize(totalDatasize); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to receive totalDatasize")); - } - bool ifRefreshSuccess = true; - if (!reply.WriteBool(ifRefreshSuccess)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdRefreshDataSize end."); - return BError(BError::Codes::OK); -} - -template -bool ServiceStub::ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - HILOGE("Failed to read Parcelable size."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < BConstants::MAX_PARCELABLE_VECTOR_NUM) ? infoSize : BConstants::MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadParcelable(); - if (info == nullptr) { - HILOGE("Failed to read Parcelable infos."); - return false; - } - parcelableInfos.emplace_back(move(*info)); - } - - return true; -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdCancel Begin."); - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ErrCode res = Cancel(bundleName, result); - if (!reply.WriteInt32(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return res; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilitiesForBundleInfos()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub CmdGetBackupDataSize Begin."); - bool isPreciseScan = true; - isPreciseScan = data.ReadBool(); - vector bundleNameList; - if (!ReadParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - auto ret = GetBackupDataSize(isPreciseScan, bundleNameList); - HILOGI("ServiceStub GetBackupDataSize End ret = %{public}d", ret); - return ret; -} -} // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b679afd82..920f8bc36 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -243,6 +243,17 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) +{ + HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); + UniqueFd fdUnique(fd); + if (fd < 0) { + HILOGE("Error fd, fd = %{public}d", fd); + return BError(BError::Codes::SA_INVAL_ARG); + } + return AppFileReady(fileName, std::move(fdUnique), errCode); +} + ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -775,7 +786,13 @@ std::string Service::GetCallerName() return callerName; } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + HILOGI("Start InitRestoreSessionWithErrMsg,Msg :%{public}s", errMsg.c_str()); + return InitRestoreSession(remote, errMsg); +} + +ErrCode Service::InitRestoreSession(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -810,7 +827,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e return ret; } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -848,6 +865,14 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er return ret; } +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + UniqueFd uniqueFd(GetLocalCapabilitiesForBundleInfos()); + HILOGI("get GetLocalCapabilitiesForBundleInfos value"); + fd = uniqueFd.Release(); + return ErrCode(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilitiesForBundleInfos() { try { @@ -920,7 +945,7 @@ void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRes } } -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { HILOGI("start GetBackupDataSize"); 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 a0aafce1c..d04fea23f 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -682,7 +682,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.isAppendFinish = true; } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { HILOGD("SvcSessionManager::CreateBackupConnection begin."); return GetBackupAbilityExt(bundleName); diff --git a/test/fuzztest/backupext_fuzzer/BUILD.gn b/test/fuzztest/backupext_fuzzer/BUILD.gn index 81a738cca..a27cba754 100644 --- a/test/fuzztest/backupext_fuzzer/BUILD.gn +++ b/test/fuzztest/backupext_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("BackupExtFuzzTest") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsa_fuzzer/BUILD.gn b/test/fuzztest/backupsa_fuzzer/BUILD.gn index 2335ebb8f..b0025c1ea 100644 --- a/test/fuzztest/backupsa_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsa_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("BackupSaFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaanother_fuzzer/BUILD.gn b/test/fuzztest/backupsaanother_fuzzer/BUILD.gn index 99ab91e83..8331e81a8 100644 --- a/test/fuzztest/backupsaanother_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsaanother_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("BackupSaAnotherFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp index ca438cd7c..2b1f339e3 100644 --- a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp +++ b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp @@ -54,7 +54,7 @@ bool CmdGetFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE), datas, reply, option); service = nullptr; return true; @@ -79,7 +79,7 @@ bool CmdAppendBundlesBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -95,7 +95,7 @@ bool CmdReleaseFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -113,7 +113,7 @@ void GetBundleNamesData(const uint8_t *data, size_t size, vector(data)); - int32_t fd = *(reinterpret_cast(data)); + int fd = *(reinterpret_cast(data)); int32_t priority = *(reinterpret_cast(data + sizeof(int32_t))); string parameters = string(reinterpret_cast(data), size) + to_string(size - i); BIncrementalData incrementaData(name, nTime, fd, parameters, priority); @@ -152,7 +152,7 @@ bool CmdGetLocalCapabilitiesIncrementalFuzzTest(const uint8_t *data, size_t size MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -168,7 +168,7 @@ bool CmdInitIncrementalBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -189,7 +189,7 @@ bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(const uint8_t *data, size_ sptr service(new Service(SERVICE_ID)); uint32_t code = static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -216,7 +216,7 @@ bool CmdPublishIncrementalFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -242,7 +242,7 @@ bool CmdAppIncrementalFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -261,7 +261,7 @@ bool CmdAppIncrementalDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE), datas, reply, option); service = nullptr; return true; @@ -287,7 +287,7 @@ bool CmdGetIncrementalFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupsaappend_fuzzer/BUILD.gn b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn index f712886f6..ebeaa43a7 100644 --- a/test/fuzztest/backupsaappend_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("BackupSaAppendFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp index 2c44b7943..73826f873 100644 --- a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -45,7 +45,7 @@ bool CmdInitRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION), datas, reply, option); service = nullptr; return true; @@ -61,7 +61,7 @@ bool CmdInitBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION), datas, reply, option); service = nullptr; return true; @@ -87,7 +87,7 @@ bool CmdPublishFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE), datas, reply, option); service = nullptr; return true; @@ -103,7 +103,7 @@ bool CmdGetLocalCapabilitiesFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -127,7 +127,7 @@ bool CmdAppFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -145,7 +145,7 @@ bool CmdAppDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_DONE), datas, reply, option); service = nullptr; return true; @@ -161,7 +161,7 @@ bool CmdStartFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_START), datas, reply, option); service = nullptr; return true; @@ -177,7 +177,7 @@ bool CmdFinishFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_FINISH), datas, reply, option); service = nullptr; return true; @@ -219,7 +219,7 @@ bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupservicestub_fuzzer/BUILD.gn b/test/fuzztest/backupservicestub_fuzzer/BUILD.gn index e9fc47fb2..f32d8aa3d 100644 --- a/test/fuzztest/backupservicestub_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestub_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("BackupServiceStubFuzzTest") { deps = [ "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${app_file_service_path}/utils:backup_utils", ] diff --git a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp index 2858c657a..1d0c74cc6 100644 --- a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp +++ b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp @@ -72,547 +72,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd); - } - msg.WriteInt32(errCode); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(scenario); - msg.WriteInt32(errCode); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - msg.WriteStringVector(bundleNames); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundleNames, msg); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundlesToBackup, msg); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 2; - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - infos.emplace_back(string(reinterpret_cast(data + len + len), len)); - WriteParcelableVector(bundlesToBackup, msg); - msg.WriteStringVector(infos); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - msg.WriteFileDescriptor(fd); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd1); - msg.WriteFileDescriptor(fd2); - } - msg.WriteInt32(errCode); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteString(string(reinterpret_cast(data), size)); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t timeout = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(timeout); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(sendRate); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -625,32 +84,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn index dcaad28f4..43efb9222 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("BackupServiceStubBranchFuzzTest") { deps = [ "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_type", "${app_file_service_path}/utils:backup_utils", ] diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index 5b788a6cb..4b9fba7fa 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -193,6 +193,8 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } +constexpr int32_t SERVICE_ID = 5203; + template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -220,877 +222,18 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitRestoreSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdStart(msg, reply); - - ExpectReturn({true}); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetLocalCapabilities(msg, reply); - - ExpectReturn({true}); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - service->CmdAppFileReady(msg, reply); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - string restoreRetInfo(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({restoreRetInfo}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({restoreRetInfo, scenario}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, true}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, type}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, true}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdFinish(msg, reply); - - ExpectReturn({true}); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); - - int32_t infoSize = 1; - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - - ExpectReturn({true}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitIncrementalBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); - - ExpectReturn({false}); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - int32_t infoSize = 1; - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int32_t infoSize = 1; - int len = size >> 1; - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({fd, false}); - service->CmdPublishSAIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({fd, true}); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : - ExpectReturn({true, flag, fd1, fd2, errCode, false}); - } else { - ExpectReturn({true, flag, errCode, false}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : - ExpectReturn({true, flag, fd1, fd2, errCode, true}); - } else { - ExpectReturn({true, flag, errCode, true}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - string bundleName(reinterpret_cast(data), size); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - uint32_t timeout = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); if (service == nullptr) { return 0; } try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h deleted file mode 100644 index 6d074c8e3..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_H - -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "iremote_stub.h" -#include "service_stub.h" - -namespace OHOS::FileManagement::Backup { -class Service : public ServiceStub { -public: - ErrCode InitRestoreSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode Start() { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() { return UniqueFd(-1); } - UniqueFd GetLocalCapabilitiesForBundleInfos() { return UniqueFd(-1); } - ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string&, UniqueFd, int32_t) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string, - BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesDetailsBackupSession(const std::vector&, - const std::vector&) { return BError(BError::Codes::OK); } - ErrCode Finish() { return BError(BError::Codes::OK); } - ErrCode Release() { return BError(BError::Codes::OK); } - ErrCode Cancel(std::string, int32_t&) { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector&) { return UniqueFd(-1); } - ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo&, UniqueFd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string&, UniqueFd, UniqueFd, int32_t) - { return BError(BError::Codes::OK); } - ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode GetBackupInfo(BundleName&, std::string&) { return BError(BError::Codes::OK); } - ErrCode UpdateTimer(BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode UpdateSendRate(std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } - - ErrCode SAResultReport(const std::string, const std::string, - const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool, std::vector) { return BError(BError::Codes::OK); } -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file diff --git a/test/fuzztest/servicereverse_fuzzer/BUILD.gn b/test/fuzztest/servicereverse_fuzzer/BUILD.gn index 83e4237e0..ac3fee62e 100644 --- a/test/fuzztest/servicereverse_fuzzer/BUILD.gn +++ b/test/fuzztest/servicereverse_fuzzer/BUILD.gn @@ -42,6 +42,8 @@ ohos_fuzztest("ServiceReverseFuzzTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", ] diff --git a/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn b/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn index d091bc2ca..4c99a5352 100644 --- a/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("SvcRestoreDepsManagerFuzzTest") { 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", "${path_jsoncpp}:jsoncpp", ] diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp new file mode 100644 index 000000000..351c5dbc7 --- /dev/null +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -0,0 +1,80 @@ +/* + * 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 "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "iremote_object_mock.h" +#include "utils_mock_global_variable.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + if (!GetMockGetInstance()) { + return nullptr; + } + + if (!GetMockLoadSystemAbility()) { + serviceProxy_ = sptr(new ServiceProxy(nullptr)); + } else { + sptr object = new MockIRemoteObject(); + serviceProxy_ = sptr(new ServiceProxy(object)); + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index d7ce74b5c..5abdac177 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -31,7 +31,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +int32_t ServiceProxy::InitRestoreSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -39,7 +39,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote) return 0; } -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -47,7 +47,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote, std::stri return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote) +int32_t ServiceProxy::InitBackupSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -55,7 +55,7 @@ int32_t ServiceProxy::InitBackupSession(sptr remote) return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -68,12 +68,13 @@ ErrCode ServiceProxy::Start() return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { TestManager tm("ServiceProxyMock_GetFd_0100"); string filePath = tm.GetRootDirCurTest().append("tmp"); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - return fd; + UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + fd = fd_OpenData.Release(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) @@ -81,7 +82,7 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -91,7 +92,7 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, +ErrCode ServiceProxy::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); @@ -102,19 +103,19 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - const vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -125,7 +126,7 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl } ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) + const std::vector &detailInfos) { return BError(BError::Codes::OK); } @@ -140,15 +141,16 @@ ErrCode ServiceProxy::Release() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + fd = UniqueFd(-1).Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() @@ -156,23 +158,24 @@ ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr& remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const vector &infos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -182,12 +185,12 @@ ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -202,12 +205,12 @@ ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, co return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } @@ -232,58 +235,23 @@ ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario scenario) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() -{ - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - if (!GetMockGetInstance()) { - return nullptr; - } - - if (!GetMockLoadSystemAbility()) { - serviceProxy_ = sptr(new ServiceProxy(nullptr)); - } else { - sptr object = new MockIRemoteObject(); - serviceProxy_ = sptr(new ServiceProxy(object)); - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int& fd) { - return; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - return; -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); + fd=-1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector& bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h index fc5c50fe8..a0dc21137 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" 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 17634813c..899126848 100644 --- a/tests/mock/module_ipc/include/svc_session_manager_mock.h +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -38,7 +38,7 @@ public: virtual bool GetSchedBundleName(std::string&) = 0; virtual std::string GetBackupExtName(const std::string&) = 0; virtual std::string GetBackupExtInfo(const std::string&) = 0; - virtual sptr CreateBackupConnection(BundleName&) = 0; + virtual sptr CreateBackupConnection(const BundleName&) = 0; virtual bool IsOnAllBundlesFinished() = 0; virtual bool IsOnOnStartSched() = 0; virtual bool NeedToUnloadService() = 0; @@ -86,7 +86,7 @@ public: MOCK_METHOD(bool, GetSchedBundleName, (std::string&)); MOCK_METHOD(std::string, GetBackupExtName, (const std::string&)); MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName&)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName&)); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); MOCK_METHOD(bool, IsOnOnStartSched, ()); MOCK_METHOD(bool, NeedToUnloadService, ()); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 547ce2562..f0ebba00f 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -35,39 +35,72 @@ void Service::OnStart() {} void Service::OnStop() {} -UniqueFd Service::GetLocalCapabilities() +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -void Service::StopAll(const wptr &obj, bool force) {} +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::GetLocalCapabilities(int &fd) { + fd = -1; return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -82,7 +115,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -92,14 +125,16 @@ ErrCode Service::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -118,7 +153,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -186,15 +221,15 @@ ErrCode Service::Release() return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode Service::GetAppLocalListAndDoIncrementalBackup() @@ -202,12 +237,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } @@ -218,7 +253,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) + const std::vector &infos) { return BError(BError::Codes::OK); } @@ -228,12 +263,15 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode Service::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } @@ -248,7 +286,7 @@ ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } @@ -273,17 +311,17 @@ ErrCode Service::RefreshDataSize(int64_t totalDatasize) return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -307,26 +345,40 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName return make_shared(bundleName); } -void Service::RemoveExtensionMutex(const BundleName &bundleName) -{ -} +void Service::RemoveExtensionMutex(const BundleName &bundleName) {} void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) {} + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ +} -void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -359,32 +411,32 @@ void Service::ClearFailedBundles() {} void Service::GetOldDeviceBackupVersion() {} -void Service::CreateDirIfNotExist(const std::string &path) -{ -} - -void Service::StartRunningTimer(const std::string &bundleName) {} +void Service::CreateDirIfNotExist(const std::string &path) {} -std::vector Service::GetSupportBackupBundleNames(vector&, bool, - const vector&) +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) { return {}; } -void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} +void Service::StartRunningTimer(const std::string &bundleName) {} -void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} +void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} + +void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, - ErrCode errCode) {} +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ +} void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } @@ -401,7 +453,7 @@ void Service::DeleteFromList(size_t scannedSize) {} void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} -void Service::SendScannedInfo(const string&scannendInfos, sptr session) {} +void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 8a3c066a8..4d91c7c4d 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -13,384 +13,519 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" -#include "module_ipc/service_reverse_proxy.h" - +#include "service_stub.h" namespace OHOS::FileManagement::Backup { using namespace std; -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - ServiceStubSupplement(); - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; -} - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; -} - int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - return BError(BError::Codes::OK); - } - - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::OK); - } - return (this->*(interfaceIndex->second))(data, reply); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int32_t res = InitRestoreSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int32_t res = InitRestoreSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int res = InitBackupSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int res = InitBackupSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - reply.WriteFileDescriptor(fd); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - int res = PublishFile(*fileInfo); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - data.ReadString(fileName); - UniqueFd fd(data.ReadFileDescriptor()); - int res = AppFileReady(fileName, move(fd), 0); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - data.ReadInt32(errCode); - int res = AppDone(errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - data.ReadString(restoreRetInfo); - int32_t scenario; - data.ReadInt32(scenario); - ErrCode errCode; - data.ReadInt32(errCode); - BackupRestoreScenario type = static_cast(scenario); - int res = ServiceResultReport(restoreRetInfo, type, errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - data.ReadString(bundleName); - string fileName; - data.ReadString(fileName); - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesRestoreSession(move(fd), bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - std::vector detailInfos; - data.ReadStringVector(&detailInfos); - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesBackupSession(bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - std::string result; - ret = GetBackupInfo(bundleName, result); - return ret; -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName"); + switch (static_cast(code)) { + case IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitRestoreSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START: { + ErrCode errCode = Start(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES: { + int fd; + ErrCode errCode = GetLocalCapabilities(fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < bundleNamesSize; ++i1) { + std::string value1 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value1); + } + std::vector detailInfos; + int32_t detailInfosSize = data.ReadInt32(); + if (detailInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i2 = 0; i2 < detailInfosSize; ++i2) { + std::string value2 = Str16ToStr8(data.ReadString16()); + detailInfos.push_back(value2); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = + AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i3 = 0; i3 < bundleNamesSize; ++i3) { + std::string value3 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value3); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i4 = 0; i4 < bundleNamesSize; ++i4) { + std::string value4 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value4); + } + ErrCode errCode = AppendBundlesBackupSession(bundleNames); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i5 = 0; i5 < bundleNamesSize; ++i5) { + std::string value5 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value5); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i6 = 0; i6 < bundleInfosSize; ++i6) { + std::string value6 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value6); + } + ErrCode errCode = AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_FINISH: { + ErrCode errCode = Finish(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_RELEASE: { + ErrCode errCode = Release(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_CANCEL: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t cancelResult; + ErrCode errCode = Cancel(bundleName, cancelResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(cancelResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP: { + ErrCode errCode = GetAppLocalListAndDoIncrementalBackup(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetIncrementalFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_BACKUP_INFO: { + std::string bundleName; + std::string getBackupInfoResult; + ErrCode errCode = GetBackupInfo(bundleName, getBackupInfoResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteString16(Str8ToStr16(getBackupInfoResult))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_TIMER: { + std::string bundleName; + uint32_t timeout = data.ReadUint32(); + bool updateTimerResult; + ErrCode errCode = UpdateTimer(bundleName, timeout, updateTimerResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateTimerResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_SEND_RATE: { + std::string bundleName; + int32_t sendRate = data.ReadInt32(); + bool updateSendRateResult; + ErrCode errCode = UpdateSendRate(bundleName, sendRate, updateSendRateResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateSendRateResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_EXT_TIMER: { + bool isExtStart; + ErrCode errCode = StartExtTimer(isExtStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_FWK_TIMER: { + bool isFwkStart; + ErrCode errCode = StartFwkTimer(isFwkStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isFwkStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_STOP_EXT_TIMER: { + bool isExtStop; + ErrCode errCode = StopExtTimer(isExtStop); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStop ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i7 = 0; i7 < bundleNamesSize; ++i7) { + std::unique_ptr value7(data.ReadParcelable()); + if (!value7) { + return ERR_INVALID_DATA; + } + + bundleNames.push_back(*value7); + } + int fd; + ErrCode errCode = GetLocalCapabilitiesIncremental(bundleNames, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitIncrementalBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i8 = 0; i8 < bundlesToBackupSize; ++i8) { + std::unique_ptr value8(data.ReadParcelable()); + if (!value8) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value8); + } + ErrCode errCode = AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i9 = 0; i9 < bundlesToBackupSize; ++i9) { + std::unique_ptr value9(data.ReadParcelable()); + if (!value9) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value9); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i10 = 0; i10 < bundleInfosSize; ++i10) { + std::string value10 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value10); + } + ErrCode errCode = AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishIncrementalFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + int fd = data.ReadFileDescriptor(); + ErrCode errCode = PublishSAIncrementalFile(*fileInfo, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t appIncrementalFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalFileReady(fileName, fd, manifestFd, appIncrementalFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE: { + int32_t appIncrementalDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalDone(appIncrementalDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REPORT_APP_PROCESS_INFO: { + std::string processInfo = Str16ToStr8(data.ReadString16()); + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + ErrCode errCode = ReportAppProcessInfo(processInfo, scenario); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REFRESH_DATA_SIZE: { + int64_t totalDataSize = data.ReadInt64(); + ErrCode errCode = RefreshDataSize(totalDataSize); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_DONE: { + int32_t appDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppDone(appDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT: { + std::string restoreRetInfo; + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + int32_t serviceResultReportErrCode = data.ReadInt32(); + ErrCode errCode = ServiceResultReport(restoreRetInfo, scenario, serviceResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(restoreRetInfo))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t appFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppFileReady(fileName, fd, appFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ret = Cancel(bundleName, result); - reply.WriteInt32(result); - return ret; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); + return ERR_TRANSACTION_FAILED; } } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp index 2d46ff3ea..90b511001 100644 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" +#include "service_stub.h" #include "service_stub_mock.h" namespace OHOS::FileManagement::Backup { @@ -23,162 +23,246 @@ ServiceStub::ServiceStub() { } -void ServiceStub::ServiceStubSupplement() -{ -} - int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - return BServiceStub::stub->OnRemoteRequest(code, data, reply, option); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitBackupSession(data, reply); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStart(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilities(data, reply); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishFile(data, reply); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppFileReady(data, reply); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppDone(data, reply); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdResultReport(data, reply); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetFileHandle(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesBackupSession(data, reply); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdFinish(data, reply); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupInfo(data, reply); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateTimer(data, reply); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateSendRate(data, reply); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRelease(data, reply); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdCancel(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesIncremental(data, reply); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetAppLocalListAndDoIncrementalBackup(data, reply); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesIncrementalBackupSession(data, reply); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { + int32_t backupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t backupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { + int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { + int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t restoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t restoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { + int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { + int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { + int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { + int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, + incrementalRestoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { + int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; } -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishIncrementalFile(data, reply); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppIncrementalFileReady(data, reply); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStopExtTimer(data, reply); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRefreshDataSize(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesForBdInfos(data, reply); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupDataSize(data, reply); -} } // namespace OHOS::FileManagement::Backup 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 6c8b88f42..7f4bcf070 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -132,7 +132,7 @@ void SvcSessionManager::SetBundleUserId(const string &bundleName, const int32_t void SvcSessionManager::AppendBundles(const vector &, vector &) {} -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BSvcSessionManager::sessionManager->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 749be058a..06f5a6091 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -257,7 +257,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { GTEST_LOG_(INFO) << "CreateBackupConnection"; return GetBackupAbilityExt(bundleName); diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp index b7ac3a85e..f9e091a98 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp @@ -155,7 +155,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec BackupSvcSessionManager::session->AppendBundles(bundleNames, failedBundles); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BackupSvcSessionManager::session->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.h b/tests/mock/module_ipc/svc_session_manager_throw_mock.h index 455274faa..79306695a 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.h +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.h @@ -53,7 +53,7 @@ public: virtual void SetBackupExtName(const std::string &, const std::string &) = 0; virtual std::weak_ptr GetSAExtConnection(const BundleName &) = 0; virtual void AppendBundles(const std::vector &, std::vector &) = 0; - virtual sptr CreateBackupConnection(BundleName &) = 0; + virtual sptr CreateBackupConnection(const BundleName &) = 0; virtual ErrCode Start() = 0; virtual ErrCode Finish() = 0; virtual bool IsOnAllBundlesFinished() = 0; @@ -130,7 +130,7 @@ public: MOCK_METHOD(void, SetBackupExtName, (const std::string &, const std::string &)); MOCK_METHOD(std::weak_ptr, GetSAExtConnection, (const BundleName &)); MOCK_METHOD(void, AppendBundles, (const std::vector &, std::vector &)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName &)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName &)); MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, Finish, ()); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index c3fc260ee..852cbab80 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("b_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_session_backup_test.cpp", "b_session_restore_async_test.cpp", "b_session_restore_test.cpp", @@ -40,6 +41,7 @@ ohos_unittest("b_session_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", ] diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 1ef532c62..224b48652 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -53,7 +53,6 @@ ohos_unittest("backup_sa_impl_test") { sources = [ "${path_backup_mock}/system_ability_manager/service_registry_mock.cpp", "${path_backup_mock}/utils_mock/src/utils_mock_global_variable.cpp", - "service_proxy_test.cpp", "service_reverse_stub_test.cpp", "service_reverse_test.cpp", "svc_death_recipient_test.cpp", diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index d5371dae2..8694c8f4d 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -22,7 +22,7 @@ #include #include "b_error/b_error.h" -#include "i_service.h" +#include "iservice.h" #include "b_resources/b_constants.h" #include "iremote_stub.h" #include "test_manager.h" diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index cd066641e..a61dcc03b 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -19,7 +19,7 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp deleted file mode 100644 index ee2de7234..000000000 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ /dev/null @@ -1,1444 +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 -#include - -#include "b_file_info.h" -#include "i_service_mock.h" -#include "iremote_object_mock.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "service_reverse_mock.h" -#include "unique_fd.h" -#include "utils_mock_global_variable.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -constexpr int32_t SERVICE_ID = 5203; -} // namespace - -class ServiceProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override; - void TearDown() override; - - shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; - sptr remote_ = nullptr; -}; - -void ServiceProxyTest::SetUp() -{ - mock_ = sptr(new IServiceMock()); - proxy_ = make_shared(mock_); - remote_ = sptr(new ServiceReverseMock()); -} - -void ServiceProxyTest::TearDown() -{ - proxy_ = nullptr; - mock_ = nullptr; - remote_ = nullptr; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.desc: 测试 InitRestoreSession 注册restore Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.desc: 测试 InitRestoreSession 注册restore Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitBackupSession_0100 - * @tc.desc: 测试 InitBackupSession 注册backup Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitBackupSession_0200 - * @tc.desc: 测试 InitBackupSession 注册backup Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Start_0100 - * @tc.name: SUB_Service_proxy_Start_0100 - * @tc.desc: 测试 Start 启动备份恢复流程接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Start_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Start_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Start_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->Start(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->Start(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Start_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.desc: 测试 GetLocalCapabilities 获取能力文件接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilities_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilities_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - UniqueFd fd = proxy_->GetLocalCapabilities(); - EXPECT_GT(fd, BError(BError::Codes::OK)); - UniqueFd fdErr = proxy_->GetLocalCapabilities(); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilities_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishFile_0100 - * @tc.name: SUB_Service_proxy_PublishFile_0100 - * @tc.desc: 测试 PublishFile 推送接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->PublishFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppFileReady_0100 - * @tc.name: SUB_Service_proxy_AppFileReady_0100 - * @tc.desc: 测试 AppFileReady 文件就绪调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(3) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppFileReady(bundleName, move(fd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppFileReady(bundleName, move(fdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppFileReady(bundleName, UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppDone_0100 - * @tc.name: SUB_Service_proxy_AppDone_0100 - * @tc.desc: 测试 AppDone ext备份恢复流程结束调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.name: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.desc: 测试 ServiceResultReport - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ServiceResultReport_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ServiceResultReport_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ServiceResultReport_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string restoreRetInfo = "test_restoreRetInfo"; - BackupRestoreScenario scenario = FULL_BACKUP; - int32_t result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ServiceResultReport_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetFileHandle_0100 - * @tc.desc: 测试 GetFileHandle 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - std::vector detailInfos; - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0200 proxy_ == nullptr"; - return; - } - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.desc: 测试 AppendBundlesBackupSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - - int32_t result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.desc: 测试 AppendBundlesDetailsBackupSession - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector detailInfos; - - int32_t result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Finish_0100 - * @tc.name: SUB_Service_proxy_Finish_0100 - * @tc.desc: 测试 Finish 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Finish_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Finish_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Finish_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Finish(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Finish(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Finish_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Release_0100 - * @tc.name: SUB_Service_proxy_Release_0100 - * @tc.desc: 测试 Release 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Release_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Release_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Release_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Release(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Release(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Release_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.desc: 测试 GetLocalCapabilitiesIncremental 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - BIncrementalData data("com.example.app2backup", 0); - bundleNames.push_back(data); - UniqueFd fd = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_GT(fd, BError(BError::Codes::OK)); - - UniqueFd fdErr = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.desc: 测试 InitIncrementalBackupSession with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector infos; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.desc: 测试 PublishIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - fileName = "test"; - result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fd)); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fdErr)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0200 proxy_ == nullptr"; - return; - } - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - - ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, move(fd), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFdErr( - open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppIncrementalFileReady(bundleName, move(fdErr), move(manifestFdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Return(0)) - .WillOnce(Return(0)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_0200"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, move(fd), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0300"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0300 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0300"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.desc: 测试 AppIncrementalDone 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.desc: 测试 GetIncrementalFileHandle 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetIncrementalFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetIncrementalFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.desc: 测试 OnLoadSystemAbilityFail 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilityFail_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilityFail_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilityFail(SERVICE_ID); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetInstance_0100 - * @tc.name: SUB_Service_proxy_GetInstance_0100 - * @tc.desc: 测试 GetInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetInstance_0100 proxy_ == nullptr"; - return; - } - GTEST_LOG_(INFO) << "MockLoadSystemAbility is false"; - SetMockLoadSystemAbility(false); - auto proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "MockLoadSystemAbility is true"; - SetMockLoadSystemAbility(true); - proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - sptr object = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, object); - GTEST_LOG_(INFO) << "GetInstance is ok"; - proxy = ServiceProxy::GetInstance(); - EXPECT_NE(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InvaildInstance_0100 - * @tc.name: SUB_Service_proxy_InvaildInstance_0100 - * @tc.desc: 测试 InvaildInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InvaildInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InvaildInstance_0100 proxy_ == nullptr"; - return; - } - ServiceProxy::InvaildInstance(); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.name: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.desc: 测试 GetBackupInfo 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetBackupInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string result; - std::string bundleName = "com.example.app2backup"; - int32_t ret = proxy_->GetBackupInfo(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateTimer_0100 - * @tc.name: SUB_Service_proxy_UpdateTimer_0100 - * @tc.desc: 测试 UpdateTimer 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - uint32_t timeout = 30000; - int32_t ret = proxy_->UpdateTimer(bundleName, timeout, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.name: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.desc: 测试 UpdateSendRate 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateSendRate_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateSendRate_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - int32_t sendRate = 300; - int32_t ret = proxy_->UpdateSendRate(bundleName, sendRate, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.name: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.desc: 测试 ReportAppProcessInfo 接口成功 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.desc: 测试 ReportAppProcessInfo 接口失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_StartExtTimer_0100 - * @tc.name: SUB_Service_proxy_StartExtTimer_0100 - * @tc.desc: 测试 StartExtTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartExtTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartExtTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartExtTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isExtStart; - int32_t ret = proxy_->StartExtTimer(isExtStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartExtTimer(isExtStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartExtTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.name: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.desc: 测试 StartFwkTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartFwkTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartFwkTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartFwkTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isFwkStart; - int32_t ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartFwkTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Cancel_0100 - * @tc.name: SUB_Service_proxy_Cancel_0100 - * @tc.desc: 测试 Cancel 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Cancel_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Cancel_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Cancel_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string bundleName; - int result; - ErrCode ret = proxy_->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->Cancel(bundleName, result); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Cancel_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index 7c2284f6b..fb65b7d4f 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -23,7 +23,7 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "service_reverse_stub.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index aa8aa1317..b5bc0b2d5 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -25,11 +25,7 @@ ohos_unittest("ext_extension_test") { module_out_path = path_module_out_tests - sources = [ - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", - "ext_extension_test.cpp", - ] + sources = [ "ext_extension_test.cpp" ] include_dirs = [ "${path_backup}/frameworks/native/backup_ext/include", @@ -41,6 +37,7 @@ ohos_unittest("ext_extension_test") { ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", "//third_party/googletest:gtest_main", @@ -163,6 +160,7 @@ ohos_unittest("tar_file_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -240,6 +238,7 @@ ohos_unittest("untar_file_sup_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -314,6 +313,7 @@ ohos_unittest("untar_file_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -367,6 +367,7 @@ ohos_unittest("ext_backup_js_test") { ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", "${path_googletest}:gtest_main", diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 6685f522e..365428a5c 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -27,12 +27,10 @@ ohos_unittest("module_ipc_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_stub.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_backup_connection.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_reverse_proxy_test.cpp", - "service_stub_test.cpp", "svc_backup_connection_test.cpp", "svc_extension_proxy_test.cpp", ] @@ -49,6 +47,7 @@ ohos_unittest("module_ipc_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", @@ -114,6 +113,7 @@ ohos_unittest("backup_service_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -195,6 +195,7 @@ ohos_unittest("backup_service_throw_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -264,6 +265,7 @@ ohos_unittest("backup_service_session_test") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -317,6 +319,7 @@ ohos_unittest("backup_service_scheduler_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -381,6 +384,7 @@ ohos_unittest("backup_restore_deps_manager_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -414,14 +418,15 @@ ohos_unittest("backup_service_incremental_test") { "${path_backup_mock}/accesstoken/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", "${path_backup_mock}/module_sched/sched_scheduler_mock.cpp", "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_incremental_test.cpp", @@ -441,6 +446,7 @@ ohos_unittest("backup_service_incremental_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -475,11 +481,11 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/accesstoken/src/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/app_gallery_dispose_proxy_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/notify_work_service_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_restore_deps_manager_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", @@ -512,6 +518,7 @@ ohos_unittest("backup_service_other_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 4a6ed74b6..b956771c8 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -35,6 +35,15 @@ void Service::OnStart() {} void Service::OnStop() {} +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { return UniqueFd(-1); @@ -47,22 +56,17 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -77,32 +81,35 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppDone(ErrCode errCode) +ErrCode Service::AppDone(int32_t appDoneErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -113,7 +120,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -122,7 +129,10 @@ ErrCode Service::Finish() { return BError(BError::Codes::OK); } - +ErrCode Service::GetLocalCapabilities(int &fd) +{ + return BError(BError::Codes::OK); +} ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { return BError(BError::Codes::OK); @@ -181,17 +191,17 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} void Service::SessionDeactive() {} -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeOut, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } @@ -207,15 +217,11 @@ void Service::OnSARestore(const std::string &bundleName, const std::string &resu void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) {} -void Service::SendEndAppGalleryNotify(const BundleName &bundleName) -{ -} +void Service::SendEndAppGalleryNotify(const BundleName &bundleName) {} -void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) -{ -} +void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) {} -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -334,7 +340,7 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() } void Service::AppendBundles(const std::vector &bundleNames) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { return BError(BError::Codes::OK); } @@ -425,7 +431,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncr try { auto session_ = service->session_; service->session_ = nullptr; - auto fd = service->GetLocalCapabilitiesIncremental({}); + int fd = -1; + service->GetLocalCapabilitiesIncremental({}, fd); service->session_ = session_; EXPECT_EQ(static_cast(fd), -ENOENT); } catch (...) { @@ -535,13 +542,15 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes try { auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr srPrt = static_cast>(srProxy); + srPrt = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -565,14 +574,16 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes std::string errMsg; auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), - BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr reverseNUll = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -764,14 +775,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; @@ -780,7 +791,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -810,7 +821,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); @@ -824,7 +835,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(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 30ea8f00e..32be58d0b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -40,20 +40,38 @@ #include "sub_service.cpp" namespace OHOS::FileManagement::Backup { +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::Release() { return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector&) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } void Service::StartGetFdTask(std::string, wptr) {} @@ -63,12 +81,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr) +ErrCode Service::InitIncrementalBackupSession(const sptr &) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr, std::string &) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string &) { return BError(BError::Codes::OK); } @@ -123,8 +141,12 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode, const std::string&) {} void Service::SendUserIdToApp(string&, int32_t) {} -void Service::SetCurrentBackupSessProperties(const vector&, int32_t, - std::vector&, bool) {} +void Service::SetCurrentBackupSessProperties(const vector &, + int32_t, + std::vector &, + bool) +{ +} std::shared_ptr Service::GetExtensionMutex(const BundleName &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 c63b4b11f..e1e3c155b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -25,9 +25,9 @@ #include "b_error/b_error.h" #include "b_resources/b_constants.h" #include "ipc_types.h" -#include "i_service.h" +#include "iservice.h" #include "message_parcel_mock.h" -#include "module_ipc/service_stub.h" +#include "service_stub.h" #include "service_reverse_mock.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index ba99f49ff..77884fbf2 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -88,18 +88,20 @@ ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) EXPECT_TRUE(remote_ != nullptr); UniqueFd fd = servicePtr_->GetLocalCapabilities(); EXPECT_GE(fd, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitRestoreSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_, errMsg); + ret = servicePtr_->InitRestoreSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->Finish(); EXPECT_EQ(ret, BError(BError::Codes::OK)); } else if (scenario == IServiceReverse::Scenario::BACKUP) { - ret = servicePtr_->InitBackupSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitBackupSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitBackupSession(remote_, errMsg); + ret = servicePtr_->InitBackupSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesBackupSession(bundleNames); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -301,11 +303,11 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0100, testing::ext::TestSize.Leve try { string fileName = MANAGE_JSON; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppFileReady Branches"; fileName = "test"; - ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -329,7 +331,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0101, testing::ext::TestSize.Leve try { string fileName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -353,7 +355,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Leve try { string fileName = "manage.json"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 158372cd2..f712b7497 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -136,7 +136,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -147,7 +148,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -157,7 +158,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0100"; } @@ -180,7 +181,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -191,7 +193,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -202,7 +204,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -212,7 +214,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0200"; } @@ -234,7 +236,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -245,7 +248,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -255,7 +258,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0100"; } @@ -278,7 +281,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -289,7 +293,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -300,7 +304,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -310,7 +314,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0200"; } @@ -527,7 +531,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -540,7 +545,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -914,22 +919,23 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_010 throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); + int fd = -1; + ErrCode ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilitiesIncremental."; @@ -995,7 +1001,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1007,7 +1014,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1019,7 +1026,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0100"; } @@ -1042,7 +1049,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1054,7 +1062,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1066,7 +1074,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1078,7 +1086,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0200"; } @@ -1138,14 +1146,14 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSessi throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + auto ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, EPERM); } catch (...) { EXPECT_TRUE(false); @@ -1207,7 +1215,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -1220,7 +1229,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index 46b847da7..c7a2500c0 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -20,6 +20,13 @@ ohos_unittest("b_incremental_session_test") { 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", + ".", + "session", ] sources = [ @@ -31,16 +38,26 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "b_incremental_session_test.cpp", + "service_client_mock.cpp", "service_proxy_mock.cpp", ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + defines = [ "LOG_TAG=\"app_file_service\"", "LOG_DOMAIN=0xD200000", diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index e074a00e0..f059a92a8 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -20,6 +20,7 @@ #include "b_incremental_restore_session.h" #include "b_incremental_session_restore_async.h" #include "service_proxy_mock.h" +#include "service_client.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -45,7 +46,7 @@ void IncrementalSessionTest::SetUpTestCase() restoreSession = make_shared(); BIncrementalSessionRestoreAsync::Callbacks callbacks; restoreAsyncSession = make_shared(callbacks); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; } void IncrementalSessionTest::TearDownTestCase() @@ -53,7 +54,7 @@ void IncrementalSessionTest::TearDownTestCase() backupSession = nullptr; restoreSession = nullptr; restoreAsyncSession = nullptr; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; proxy = nullptr; } @@ -70,14 +71,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitIncrementalBackupSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks); @@ -103,11 +104,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); backupSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; backupSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -132,14 +133,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -162,13 +163,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -191,14 +192,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks); @@ -224,11 +225,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); restoreSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -253,16 +254,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -285,13 +286,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -314,14 +315,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,7 +346,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreSession != nullptr); @@ -353,7 +354,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -376,7 +377,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -384,8 +385,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -408,14 +409,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalSessionRestoreAsync::Callbacks callbacks; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreAsyncSession->Init(callbacks); @@ -441,11 +442,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); restoreAsyncSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreAsyncSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -470,16 +471,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -502,14 +503,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -533,7 +534,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreAsyncSession != nullptr); @@ -541,7 +542,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -564,7 +565,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -572,8 +573,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -596,13 +597,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -625,15 +626,15 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; vector infos; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSessionWithBundleInfos(_, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -656,7 +657,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; UniqueFd fd; EXPECT_TRUE(restoreSession != nullptr); @@ -664,7 +665,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishSAIncrementalFile(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishSAFile(fileInfo, move(fd)); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -687,14 +688,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -717,14 +718,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -747,14 +748,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -779,14 +780,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2400, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks, errMsg, errCode); @@ -813,14 +814,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2500, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitRestoreSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitRestoreSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks, errMsg, errCode); @@ -845,17 +846,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { @@ -878,17 +880,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp new file mode 100644 index 000000000..cf075fbd2 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -0,0 +1,51 @@ +/* + * 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 "service_client.h" +#include "iservice.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() {} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h new file mode 100644 index 000000000..6aa6d9884 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H +#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + +#include + +#include "service_client.h" + +namespace OHOS::FileManagement::Backup { +class ServiceClientMock : public ServiceClient { + +public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); +}; +} // End of namespace OHOS::FileManagement::Backup +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 41cce333d..0ed3fb8bf 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -16,225 +16,223 @@ #include "service_proxy.h" #include "b_error/b_error.h" - +#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +ErrCode ServiceProxy::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { - return 0; -} - -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote) +ErrCode ServiceProxy::AppDone(int32_t appDoneErrCode) { - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - return 0; -} - -ErrCode ServiceProxy::Start() +ErrCode ServiceProxy::RefreshDataSize(int64_t totalDataSize) { return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::AppIncrementalDone(int32_t appIncrementalDoneErrCode) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppDone(ErrCode errCode) +ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) +int32_t ServiceProxy::InitRestoreSession(const sptr &remote) { - return BError(BError::Codes::OK); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::Start() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Finish() +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &cancelResult) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Release() +ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario scenario) { - result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +int32_t ServiceProxy::InitBackupSession(const sptr &remote) { - return UniqueFd(-1); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() +ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, + BackupRestoreScenario scenario, + int32_t serviceResultReportErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &detailInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) +ErrCode ServiceProxy::Finish() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) +ErrCode ServiceProxy::Release() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) +ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::RefreshDataSize(int64_t totalsize) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) { - return serviceProxy_; + return BError(BError::Codes::OK); } -sptr ServiceProxy::GetInstance() +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { - return serviceProxy_; + return BError(BError::Codes::OK); } -void ServiceProxy::InvaildInstance() {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t, const OHOS::sptr&) {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + fd = -1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index b734c8dac..85a4e056e 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -26,48 +26,49 @@ public: explicit ServiceProxyMock(const sptr &impl) : ServiceProxy(impl) {} ~ServiceProxyMock() override {} public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(AsObject, sptr()); - MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); - MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); + MOCK_METHOD1(GetLocalCapabilitiesForBundleInfos, ErrCode(int32_t &)); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd)); - MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd, int32_t errCode)); - MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, int fd)); + MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, int fd, int32_t errCode)); + MOCK_METHOD1(AppDone, ErrCode(int32_t errCode)); + MOCK_METHOD2(GetFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - 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)); + MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); - MOCK_METHOD2(Cancel, ErrCode(std::string bundleName, int32_t &result)); - MOCK_METHOD1(GetLocalCapabilitiesIncremental, UniqueFd(const std::vector &bundleNames)); - MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD2(Cancel, ErrCode(const std::string &bundleName, int32_t &result)); + MOCK_METHOD2(GetLocalCapabilitiesIncremental, ErrCode(const std::vector &bundleNames, int &fd)); + MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitIncrementalBackupSessionWithErrMsg, + ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); - MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + MOCK_METHOD2(AppendBundlesIncrementalBackupSessionWithBundleInfos, + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); - MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); + MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, int fd)); + MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD1(AppIncrementalDone, ErrCode(int32_t errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD2(GetBackupInfo, ErrCode(BundleName &bundleName, std::string &result)); - MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); + MOCK_METHOD2(GetBackupInfo, ErrCode(const BundleName &bundleName, std::string &result)); + MOCK_METHOD3(UpdateTimer, ErrCode(const BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD0(GetAppLocalListAndDoIncrementalBackup, ErrCode()); MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); - MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, std::vector bundleNameList)); + MOCK_METHOD5( + AppendBundlesRestoreSessionDataByDetail, + ErrCode(int32_t, const std::vector &, const std::vector &, int32_t, int32_t)); + MOCK_METHOD4(AppendBundlesRestoreSessionData, + ErrCode(int32_t, const std::vector &, int32_t, int32_t)); + MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 0a0c1d50a..5703e4271 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -50,6 +50,8 @@ ohos_unittest("backup_tool_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -112,6 +114,8 @@ ohos_unittest("backup_tool_restore_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 745fe725e..f11c1c08b 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -39,7 +39,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_backup.h" @@ -240,12 +240,13 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; } - BFile::SendFile(fdLocal, proxy->GetLocalCapabilities()); + int fd = -1; + BFile::SendFile(fdLocal, proxy->GetLocalCapabilities(fd)); auto ctx = make_shared(); ctx->session_ = BSessionBackup::Init( diff --git a/tools/backup_tool/src/tools_op_check_sa.cpp b/tools/backup_tool/src/tools_op_check_sa.cpp index 5e781f316..a2173be23 100644 --- a/tools/backup_tool/src/tools_op_check_sa.cpp +++ b/tools/backup_tool/src/tools_op_check_sa.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -17,7 +17,7 @@ #include #include "errors.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_check_sa.h" @@ -31,7 +31,7 @@ static string GenHelpMsg() static int Exec(map> &mapArgToVal) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EFAULT; diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 41a97190c..b62616d02 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -42,7 +42,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" namespace OHOS::FileManagement::Backup { @@ -273,7 +273,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; @@ -286,11 +286,13 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, ctx->lastIncrementalData.push_back(data); num++; } - UniqueFd fd = proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData); + int fdVal = -1; + proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); + UniqueFd fd(fdVal); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { - BFile::SendFile(fdLocal, fd); + BFile::SendFile(fdLocal, std::move(fd)); } return 0; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 95b58a5ad..6a6928383 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -84,7 +84,10 @@ ohos_shared_library("backup_utils") { "src/b_utils/b_time.cpp", ] - configs = [ ":utils_private_config" ] + configs = [ + ":utils_private_config", + "${path_backup}/services/backup_sa:public_idl_config", + ] public_configs = [ ":utils_public_config" ] external_deps = [ @@ -110,6 +113,7 @@ ohos_shared_library("backup_utils") { deps = [ ":backup_cxx_cppdeps", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_type", "${path_jsoncpp}:jsoncpp", "//third_party/openssl:libcrypto_shared", ] diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 16d4a17f4..6b17d9851 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_B_RADAR_H #include #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { enum class BizStageBackup : int32_t { diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 1c7f7ac84..d25a28d29 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -23,7 +23,7 @@ #include "b_resources/b_constants.h" #include "b_utils/b_time.h" #include "hisysevent.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { int32_t AppRadar::GetUserId() -- Gitee From ff745935a2411f2852c5c9e5733c456bdf04d41e Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 28 Feb 2025 11:14:37 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86IDL=E5=8C=96=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- bundle.json | 6 +- frameworks/native/backup_ext/BUILD.gn | 1 + .../native/backup_ext/include/ext_extension.h | 5 +- .../native/backup_ext/src/ext_backup.cpp | 5 +- .../native/backup_ext/src/ext_extension.cpp | 75 +- .../backup_ext/src/sub_ext_extension.cpp | 17 +- .../include/service_reverse_stub.h | 4 +- .../backup_kit_inner/src/b_file_info.cpp | 4 +- .../src/b_incremental_backup_session.cpp | 38 +- .../src/b_incremental_data.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 61 +- .../b_incremental_session_restore_async.cpp | 41 +- .../backup_kit_inner/src/b_session_backup.cpp | 40 +- .../src/b_session_restore.cpp | 54 +- .../src/b_session_restore_async.cpp | 39 +- .../backup_kit_inner/src/service_client.cpp | 144 ++ .../src/service_incremental_proxy.cpp | 417 ----- .../backup_kit_inner/src/service_proxy.cpp | 839 ---------- .../native/backup_kit_inner/BUILD.gn | 10 +- .../backup_kit_inner/impl/b_file_info.h | 32 +- .../impl/b_incremental_data.h | 36 +- .../b_incremental_session_restore_async.h | 5 +- .../impl/b_session_restore_async.h | 5 +- .../backup_kit_inner/impl/backup_file_info.h | 44 + .../impl/backup_incremental_data.h | 47 + .../native/backup_kit_inner/impl/i_service.h | 104 -- .../impl/i_service_ipc_interface_code.h | 64 - ...i_service_reverse.h => iservice_reverse.h} | 2 +- .../backup_kit_inner/impl/service_client.h | 58 + .../backup_kit_inner/impl/service_common.h | 29 + .../backup_kit_inner/impl/service_proxy.h | 112 -- interfaces/kits/js/BUILD.gn | 1 + .../kits/js/backup/prop_n_operation.cpp | 37 +- services/backup_sa/BUILD.gn | 132 +- services/backup_sa/ExtensionType.idl | 22 + services/backup_sa/IService.idl | 72 + services/backup_sa/ServiceType.idl | 23 + .../backup_sa/include/module_ipc/service.h | 116 +- .../module_ipc/service_reverse_proxy.h | 4 +- .../include/module_ipc/service_stub.h | 85 - .../module_ipc/svc_restore_deps_manager.h | 5 +- .../include/module_ipc/svc_session_manager.h | 7 +- services/backup_sa/src/module_ipc/service.cpp | 183 ++- .../src/module_ipc/service_incremental.cpp | 70 +- .../backup_sa/src/module_ipc/service_stub.cpp | 858 ---------- .../backup_sa/src/module_ipc/sub_service.cpp | 33 +- .../src/module_ipc/svc_session_manager.cpp | 2 +- test/fuzztest/backupext_fuzzer/BUILD.gn | 1 + test/fuzztest/backupsa_fuzzer/BUILD.gn | 1 + test/fuzztest/backupsaanother_fuzzer/BUILD.gn | 1 + .../backupsaanother_fuzzer.cpp | 22 +- test/fuzztest/backupsaappend_fuzzer/BUILD.gn | 1 + .../backupsaappend_fuzzer.cpp | 18 +- .../backupservicestub_fuzzer/BUILD.gn | 1 + .../backupservicestub_fuzzer.cpp | 567 ------- .../backupservicestubbranch_fuzzer/BUILD.gn | 1 + .../backupservicestubbranch_fuzzer.cpp | 863 +--------- .../backupservicestubbranch_fuzzer/service.h | 87 - test/fuzztest/servicereverse_fuzzer/BUILD.gn | 2 + .../svcrestoredepsmanager_fuzzer/BUILD.gn | 1 + .../backup_kit_inner/service_client_mock.cpp | 80 + .../backup_kit_inner/service_proxy_mock.cpp | 114 +- .../include/service_reverse_proxy_mock.h | 4 +- .../include/svc_session_manager_mock.h | 4 +- tests/mock/module_ipc/service_mock.cpp | 158 +- tests/mock/module_ipc/service_stub_mock.cpp | 877 +++++----- .../mock/module_ipc/src/service_stub_mock.cpp | 394 +++-- .../src/svc_session_manager_mock.cpp | 2 +- .../module_ipc/svc_session_manager_mock.cpp | 2 +- .../svc_session_manager_throw_mock.cpp | 2 +- .../svc_session_manager_throw_mock.h | 4 +- tests/moduletests/backup_kit_inner/BUILD.gn | 2 + .../unittests/backup_api/backup_impl/BUILD.gn | 3 +- .../backup_impl/include/i_service_mock.h | 4 +- .../include/service_reverse_mock.h | 4 +- .../backup_impl/service_proxy_test.cpp | 1444 ----------------- .../backup_impl/service_reverse_stub_test.cpp | 4 +- tests/unittests/backup_ext/BUILD.gn | 13 +- tests/unittests/backup_sa/module_ipc/BUILD.gn | 15 +- .../module_ipc/service_incremental_test.cpp | 154 +- .../module_ipc/service_other_test.cpp | 36 +- .../module_ipc/service_stub_test.cpp | 6 +- .../backup_sa/module_ipc/service_test.cpp | 18 +- .../module_ipc/service_throw_test.cpp | 75 +- tests/unittests/backup_sa/session/BUILD.gn | 19 +- .../session/b_incremental_session_test.cpp | 139 +- .../backup_sa/session/service_client_mock.cpp | 51 + .../backup_sa/session/service_client_mock.h | 34 + .../backup_sa/session/service_proxy_mock.cpp | 146 +- .../backup_sa/session/service_proxy_mock.h | 59 +- tests/unittests/backup_tools/BUILD.gn | 4 + tools/backup_tool/src/tools_op_backup.cpp | 9 +- tools/backup_tool/src/tools_op_check_sa.cpp | 6 +- .../src/tools_op_incremental_backup.cpp | 12 +- utils/BUILD.gn | 6 +- utils/include/b_radar/b_radar.h | 4 +- utils/src/b_radar/b_radar.cpp | 4 +- 97 files changed, 2622 insertions(+), 6846 deletions(-) create mode 100644 frameworks/native/backup_kit_inner/src/service_client.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_proxy.cpp create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h rename interfaces/inner_api/native/backup_kit_inner/impl/{i_service_reverse.h => iservice_reverse.h} (98%) create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_client.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_common.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h create mode 100644 services/backup_sa/ExtensionType.idl create mode 100644 services/backup_sa/IService.idl create mode 100644 services/backup_sa/ServiceType.idl delete mode 100644 services/backup_sa/include/module_ipc/service_stub.h delete mode 100644 services/backup_sa/src/module_ipc/service_stub.cpp delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h create mode 100644 tests/mock/backup_kit_inner/service_client_mock.cpp delete mode 100644 tests/unittests/backup_api/backup_impl/service_proxy_test.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/bundle.json b/bundle.json index d81e5f73a..002d60fc6 100644 --- a/bundle.json +++ b/bundle.json @@ -143,12 +143,10 @@ "impl/b_session_restore.h", "impl/b_session_restore_async.h", "impl/b_file_info.h", - "impl/service_proxy.h", + "impl/service_client.h", "impl/b_session_backup.h", - "impl/i_service_ipc_interface_code.h", "impl/i_service_reverse_ipc_interface_code.h", - "impl/i_service.h", - "impl/i_service_reverse.h" + "impl/iservice_reverse.h" ] } }, diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index ec60d87cd..e1140901c 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("backup_extension_ability_native") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index db933dad2..2cc7e5a5a 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -30,7 +30,8 @@ #include "b_radar/b_radar.h" #include "ext_backup_js.h" #include "ext_extension_stub.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "tar_file.h" #include "thread_pool.h" #include "timer.h" diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index e75dcf5f8..fc37b3296 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -34,7 +34,8 @@ #include "ext_backup_js.h" #include "ext_extension.h" #include "filemgmt_libhilog.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 1119285af..1a9e4f089 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -53,9 +53,9 @@ #include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "iservice.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" namespace OHOS::FileManagement::Backup { @@ -400,7 +400,7 @@ tuple BackupExtExtension::GetIncrementalFileHandle( } VerifyCaller(); if (BDir::CheckFilePathInvalid(fileName)) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_IPC, string("Failed to AGetInstance")); } @@ -459,10 +459,10 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) cache.SetExtManage(pkgInfo); cachedEntity.Persist(); close(cachedEntity.GetFd().Release()); - + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); ErrCode ret = - proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)), - ERR_OK); + proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + ERR_OK); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully"); } else { @@ -500,8 +500,8 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro WaitToSendFd(startTime, fdNum); int32_t errCode = ERR_OK; string filePath = std::get<0>(item.second); - UniqueFd fd(open(filePath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(filePath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(filePath).c_str(), errno); errCode = errno; @@ -513,7 +513,7 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro continue; } } - ret = proxy->AppFileReady(item.first, std::move(fd), errCode); + ret = proxy->AppFileReady(item.first, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully, package name is %{public}s", item.first.c_str()); } else { @@ -685,15 +685,15 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string tarPath = path + tarName; int32_t errCode = ERR_OK; - UniqueFd fd(open(tarPath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(tarPath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("TarFileReady open file failed, file name is %{public}s, err = %{public}d", tarName.c_str(), errno); errCode = errno; AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", "TarFileReady", "tarFile", tarPath}; HiAudit::GetInstance(false).Write(auditLog); } - int ret = proxy->AppFileReady(tarName, std::move(fd), errCode); + int ret = proxy->AppFileReady(tarName, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("TarFileReady: AppFileReady success for %{public}s", tarName.c_str()); // 删除文件 @@ -776,7 +776,7 @@ int BackupExtExtension::DoBackup(TarMap &bigFileInfo, map &small return EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -841,9 +841,9 @@ bool BackupExtExtension::RefreshDataSize(int64_t totalSize) HILOGI("no backup datasize, don't need to refresh"); return true; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("start RefreshDatasize by ipc"); @@ -1709,9 +1709,9 @@ void BackupExtExtension::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("AppDone Begin."); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1724,8 +1724,8 @@ void BackupExtExtension::AppDone(ErrCode errCode) void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("restoreRetInfo is %{public}s", restoreRetInfo.c_str()); auto ret = proxy->ServiceResultReport(restoreRetInfo, scenario, errCode); if (ret != ERR_OK) { @@ -1735,8 +1735,8 @@ void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, void BackupExtExtension::StartExtTimer(bool &isExtStart) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start ext timer by ipc."); auto ret = proxy->StartExtTimer(isExtStart); if (ret != ERR_OK) { @@ -1747,8 +1747,8 @@ void BackupExtExtension::StartExtTimer(bool &isExtStart) void BackupExtExtension::StartFwkTimer(bool &isFwkStart) { HILOGI("Do backup, start fwk timer begin."); - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start fwk timer by ipc."); auto ret = proxy->StartFwkTimer(isFwkStart); if (ret != ERR_OK) { @@ -1761,9 +1761,9 @@ bool BackupExtExtension::StopExtTimer() { HILOGI("StopExtTimer start"); bool isExtStop; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("StopExtTimer by ipc"); @@ -1961,7 +1961,8 @@ static void WriteFile(const string &filename, const vector &srcFiles, sptr proxy) + const vector &srcFiles, + sptr proxy) { string tarFile = bigFileInfo.begin()->first; string manageFile = GetReportFileName(tarFile); @@ -1969,8 +1970,9 @@ ErrCode BackupExtExtension::IncrementalTarFileReady(const TarMap &bigFileInfo, WriteFile(file, srcFiles); string tarName = string(INDEX_FILE_INCREMENTAL_BACKUP).append(tarFile); - ErrCode ret = proxy->AppIncrementalFileReady(tarFile, UniqueFd(open(tarName.data(), O_RDONLY)), - UniqueFd(open(file.data(), O_RDONLY)), ERR_OK); + int fd = open(tarName.data(), O_RDONLY); + int manifestFd = open(file.data(), O_RDONLY); + ErrCode ret = proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalTarFileReady: The application is packaged successfully"); // 删除文件 @@ -2000,8 +2002,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, auto [path, sta, isBeforeTar] = item.second; int32_t errCode = ERR_OK; WaitToSendFd(startTime, fdNum); - UniqueFd fd(open(path.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(path.data(), O_RDONLY); + if (fdval < 0) { HILOGE("IncrementalBigFileReady open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(path).c_str(), errno); errCode = errno; @@ -2019,7 +2021,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, } string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); WriteFile(file, bigInfo); - ret = proxy->AppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY)), errCode); + int manifestFdval = open(file.data(), O_RDONLY); + ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); if (SUCCEEDED(ret)) { HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", item.first.c_str()); @@ -2051,11 +2054,11 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append("all")); WriteFile(file, srcFiles); - UniqueFd fd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)); - UniqueFd manifestFd(open(file.data(), O_RDONLY)); + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); + int manifestFdval = open(file.data(), O_RDONLY); ErrCode ret = - proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), std::move(fd), std::move(manifestFd), - ERR_OK); + proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + manifestFdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalAllFileReady successfully"); RemoveFile(file); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 24e2a9c11..a84f219a2 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -51,9 +51,8 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" #include "b_anony/b_anony.h" @@ -483,7 +482,7 @@ std::function BackupExtExtension::IncOnBackupC HILOGI("Begin get IncOnBackupCallback"); return [obj](ErrCode errCode, std::string errMsg) { HILOGI("App onbackup end"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -525,7 +524,7 @@ std::function BackupExtExtension::IncOnBackupE { HILOGI("Begin get HandleIncBackupEx callback"); return [obj](ErrCode errCode, const std::string backupExRetInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -575,7 +574,7 @@ std::function BackupExtExtension::IncOnBackupE void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Report app process error, proxy is empty"); return; @@ -739,9 +738,9 @@ void BackupExtExtension::CloseOnProcessTimeOutTimer() void BackupExtExtension::AppIncrementalDone(ErrCode errCode) { HILOGI("Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1173,7 +1172,7 @@ int BackupExtExtension::DoIncrementalBackup(const vector if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { throw BError(errno); } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h index 53a4964aa..c981c206f 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" namespace OHOS::FileManagement::Backup { diff --git a/frameworks/native/backup_kit_inner/src/b_file_info.cpp b/frameworks/native/backup_kit_inner/src/b_file_info.cpp index e068da158..c01b287eb 100644 --- a/frameworks/native/backup_kit_inner/src/b_file_info.cpp +++ b/frameworks/native/backup_kit_inner/src/b_file_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_file_info.h" +#include "backup_file_info.h" #include "filemgmt_libhilog.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index 97de333ab..c78a25e5e 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalBackupSession::~BIncrementalBackupSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -76,13 +76,13 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitIncrementalBackupSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +101,7 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks void BIncrementalBackupSession::RegisterBackupServiceDied(function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +111,7 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -122,12 +122,14 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct UniqueFd BIncrementalBackupSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -138,7 +140,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -153,7 +155,7 @@ ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector< ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -174,12 +176,12 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, std::vector infos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + int32_t res = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { @@ -194,7 +196,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -205,7 +207,7 @@ ErrCode BIncrementalBackupSession::Release() ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp index 571805e51..a0a5b1037 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "filemgmt_libhilog.h" #include "message_parcel.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 97468695a..b09e2ce64 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalRestoreSession::~BIncrementalRestoreSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -75,15 +75,15 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { errMsg = "Failed to get backup service"; errCode = BError(BError::Codes::SDK_BROKEN_IPC); HILOGE("Init IncrementalRestoreSession failed, %{public}s", errMsg.c_str()); return nullptr; } - errCode = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitRestoreSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", errCode); AppRadar::Info info ("", "", "create restore session failed"); @@ -104,12 +104,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -119,7 +121,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -128,16 +130,17 @@ ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalRestoreSession::PublishSAFile(BFileInfo fileInfo, UniqueFd fd) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->PublishSAIncrementalFile(fileInfo, move(fd)); + int fdValue = fd.Get(); + return proxy->PublishSAIncrementalFile(fileInfo, fdValue); } ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -147,11 +150,12 @@ ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, cons ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -159,19 +163,23 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -179,14 +187,15 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -207,7 +216,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -217,7 +226,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 170a50db6..fa1eb7624 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -19,7 +19,7 @@ #include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -31,7 +31,7 @@ BIncrementalSessionRestoreAsync::~BIncrementalSessionRestoreAsync() HILOGE("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -47,8 +47,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return nullptr; @@ -79,7 +79,7 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -88,7 +88,7 @@ ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -102,12 +102,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(fdCode, bundlesToRestore, detailInfos, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -115,7 +117,8 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } @@ -125,11 +128,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionData(fdCode, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -137,14 +143,15 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BIncrementalSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -154,7 +161,7 @@ ErrCode BIncrementalSessionRestoreAsync::Release() void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -171,7 +178,7 @@ void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function BSessionBackup::Init(Callbacks callbacks) try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -76,13 +76,13 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + errCode = proxy->InitBackupSessionWithErrMsg(sptr(new ServiceReverse(callbacks)), errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +101,7 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, void BSessionBackup::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +111,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -121,7 +121,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) ErrCode BSessionBackup::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -132,12 +132,14 @@ ErrCode BSessionBackup::Start() UniqueFd BSessionBackup::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -148,7 +150,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -163,7 +165,7 @@ ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -183,7 +185,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -203,7 +205,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector ErrCode BSessionBackup::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -213,7 +215,7 @@ ErrCode BSessionBackup::Finish() ErrCode BSessionBackup::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -224,7 +226,7 @@ ErrCode BSessionBackup::Release() ErrCode BSessionBackup::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 21fbc125f..ab86d5ab0 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BSessionRestore::~BSessionRestore() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,8 +46,8 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) try { HILOGI("Init RestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -72,12 +72,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) UniqueFd BSessionRestore::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -87,7 +89,7 @@ UniqueFd BSessionRestore::GetLocalCapabilities() ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -96,7 +98,7 @@ ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestore::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -106,7 +108,7 @@ ErrCode BSessionRestore::Start() ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -114,14 +116,17 @@ ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &f return proxy->GetFileHandle(bundleName, fileName); } -ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -129,18 +134,20 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -148,14 +155,15 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -165,7 +173,7 @@ ErrCode BSessionRestore::Finish() ErrCode BSessionRestore::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -175,7 +183,7 @@ ErrCode BSessionRestore::Release() void BSessionRestore::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -186,7 +194,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -196,7 +204,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) ErrCode BSessionRestore::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index a60c56462..f3f5276bd 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -20,8 +20,9 @@ #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" +#include "service_common.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -32,7 +33,7 @@ BSessionRestoreAsync::~BSessionRestoreAsync() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -48,8 +49,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -80,7 +81,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -89,7 +90,7 @@ ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -103,12 +104,14 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -126,12 +129,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -139,14 +145,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -156,7 +163,7 @@ ErrCode BSessionRestoreAsync::Release() void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -173,7 +180,7 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct ErrCode BSessionRestoreAsync::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp new file mode 100644 index 000000000..6efa0661f --- /dev/null +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022-2025 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 "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + unique_lock getInstanceLock(getInstanceMutex_); + unique_lock lock(proxyMutex_); + if (serviceProxy_ != nullptr) { + return serviceProxy_; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOGE("Get an empty samgr"); + return nullptr; + } + sptr loadCallback = sptr(new ServiceProxyLoadCallback()); + if (loadCallback == nullptr) { + HILOGE("loadCallback is nullptr."); + return nullptr; + } + int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); + if (ret != ERR_OK) { + HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", + FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); + return nullptr; + } + + auto waitStatus = + loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), + [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); + if (!waitStatus) { + HILOGE("Load backup sa timeout"); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceClient::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + BError(BError::Codes::SA_INVAL_ARG).GetCode()); + return nullptr; + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Invalid Instance"); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Load backup sa success, systemAbilityId: %{public}d, remoteObject result:%{public}s", systemAbilityId, + (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + unique_lock lock(proxyMutex_); + serviceProxy_ = iface_cast(remoteObject); + if (serviceProxy_ == nullptr) { + HILOGE("serviceProxy_ is nullptr"); + return; + } + auto remoteObj = serviceProxy_->AsObject(); + if (!remoteObj) { + HILOGE("Failed to get remote object"); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + + auto callback = [](const wptr &obj) { + ServiceClient::InvaildInstance(); + }; + sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); + remoteObj->AddDeathRecipient(deathRecipient); + isLoadSuccess_.store(true); + proxyConVar_.notify_one(); +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + static_cast(BError::Codes::SA_INVAL_ARG)); + proxyConVar_.notify_one(); +} +} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp deleted file mode 100644 index bbb503bfa..000000000 --- a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp +++ /dev/null @@ -1,417 +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. - */ - -#include "service_proxy.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "svc_death_recipient.h" -#include "unique_fd.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::Release() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - if (!WriteParcelableVector(bundleNames, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL), data, reply, - option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION), data, - reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - if (!data.WriteStringVector(infos)) { - HILOGE("Failed to write infos"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - if (!data.WriteFileDescriptor(fd)) { - HILOGE("Failed to send the fd"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (fdFlag == true && !data.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -template -bool ServiceProxy::WriteParcelableVector(const std::vector &parcelableVector, Parcel &data) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!data.WriteUint32(parcelableVector.size())) { - HILOGE("failed to WriteInt32 for parcelableVector.size()"); - return false; - } - - for (const auto &parcelable : parcelableVector) { - if (!data.WriteParcelable(&parcelable)) { - HILOGE("failed to WriteParcelable for parcelable"); - return false; - } - } - - return true; -} - -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!Remote()) { - return BError(BError::Codes::SDK_INVAL_ARG, "Remote is nullptr").GetCode(); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadInt32(result); - HILOGI("ServiceProxy Cancel end, result:%{public}d", result); - - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp deleted file mode 100644 index 187f69ef7..000000000 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ /dev/null @@ -1,839 +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 "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_radar/b_radar.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "system_ability_definition.h" -#include "svc_death_recipient.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::InitRestoreSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Start() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilities() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - AppRadar::Info resInfo("", "", ""); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, "ServiceProxy::GetLocalCapabilities", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL, ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = fd < 0 ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(restoreRetInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the restoreRetInfo").GetCode(); - } - if (!data.WriteInt32(static_cast(scenario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!detailInfos.empty() && !data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &detailInfos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - if (!data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Finish() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -sptr ServiceProxy::GetServiceProxyPointer() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - unique_lock getInstanceLock(getInstanceMutex_); - unique_lock lock(proxyMutex_); - if (serviceProxy_ != nullptr) { - return serviceProxy_; - } - - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - HILOGE("Get an empty samgr"); - return nullptr; - } - sptr loadCallback = sptr(new ServiceProxyLoadCallback()); - if (loadCallback == nullptr) { - HILOGE("loadCallback is nullptr."); - return nullptr; - } - int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); - if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", - FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); - return nullptr; - } - - auto waitStatus = - loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), - [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); - if (!waitStatus) { - HILOGE("Load backup sa timeout"); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - BError(BError::Codes::SA_INVAL_ARG).GetCode()); - return nullptr; - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("invalid instance"); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, - (remoteObject != nullptr) ? "true" : "false"); - if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - unique_lock lock(proxyMutex_); - serviceProxy_ = iface_cast(remoteObject); - if (serviceProxy_ == nullptr) { - HILOGD("serviceProxy_ is nullptr"); - return; - } - auto remoteObj = serviceProxy_->AsObject(); - if (!remoteObj) { - HILOGE("Failed to get remote object"); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - - auto callback = [](const wptr &obj) { - ServiceProxy::InvaildInstance(); - HILOGE("Backup service died"); - }; - sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); - remoteObj->AddDeathRecipient(deathRecipient); - isLoadSuccess_.store(true); - proxyConVar_.notify_one(); -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); - proxyConVar_.notify_one(); -} - -ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) -{ - HILOGI("ServiceProxy GetBackupInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadString(result); - HILOGI("ServiceProxy GetBackupInfo end. result = %s", result.c_str()); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) -{ - HILOGI("ServiceProxy UpdateTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteUint32(timeout)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send timeout").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateTimer end. result = %d", result); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) -{ - HILOGD("ServiceProxy UpdateSendRate Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(sendRate)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateSendRate end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) -{ - HILOGD("ServiceProxy NotifyBundleProcessInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(processInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(static_cast(sennario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()-> SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - HILOGI("ServiceProxy NotifyBundleProcessInfo end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) -{ - HILOGI("ServiceProxy StartExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStart); - HILOGI("ServiceProxy StartExtTimer end. isExtStart = %d", isExtStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) -{ - HILOGI("ServiceProxy StartFwkTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isFwkStart); - HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) -{ - HILOGI("ServiceProxy StopExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStop); - HILOGI("ServiceProxy StopExtTimer end. isExtStop = %{public}d", isExtStop); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) -{ - HILOGI("ServiceProxy RefreshDatasize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteInt64(totalSize)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write totalSize").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - bool result = false; - reply.ReadBool(result); - if (!result) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to Refresh Datasize").GetCode(); - } - return BError(BError::Codes::OK, "success"); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("ServiceProxy, start GetLocalCapabilitiesForBundleInfos"); - if (Remote() == nullptr) { - HILOGE("Remote is nullptr"); - return UniqueFd(-EPERM); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - HILOGI("ServiceProxy, end GetLocalCapabilitiesForBundleInfos"); - return fd; -} - -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) -{ - HILOGI("ServiceProxy GetBackupDataSize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteBool(isPreciseScan)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write isPreciseScan").GetCode(); - } - if (!WriteParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write bundleNameList").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 45fe3c878..096d8feef 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/filemanagement/app_file_service/backup.gni") config("public_config") { include_dirs = [ ".", - "impl", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", ] } @@ -52,9 +52,8 @@ ohos_shared_library("backup_kit_inner") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", ] @@ -76,7 +75,10 @@ ohos_shared_library("backup_kit_inner") { "samgr:samgr_proxy", ] - deps = [ "${path_backup}/utils:backup_utils" ] + deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc", + "${path_backup}/utils:backup_utils", + ] cflags_cc = [ "-fdata-sections", diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h index 356ad5226..b7c3b759a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -13,32 +13,6 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H -#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#include "backup_file_info.h" -#include -#include - -#include "parcel.h" - -namespace OHOS::FileManagement::Backup { -using BundleName = std::string; -using TmpFileSN = uint32_t; - -struct BFileInfo : public Parcelable { - BundleName owner; - std::string fileName; - TmpFileSN sn; // 用于服务零拷贝接收文件场景 - - BFileInfo() = default; - BFileInfo(std::string bundleName, std::string strFileNanme, TmpFileSN id) - : owner(bundleName), fileName(strFileNanme), sn(id) {} - ~BFileInfo() override = default; - - bool ReadFromParcel(Parcel &parcel); - bool Marshalling(Parcel &parcel) const override; - static BFileInfo *Unmarshalling(Parcel &parcel); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +namespace OHOS::FileManagement::Backup {}; \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h index fa513fdcd..95a3bf248 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -12,36 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "backup_incremental_data.h" -#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H -#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H - -#include -#include - -#include "parcel.h" -#include "unique_fd.h" - -namespace OHOS::FileManagement::Backup { -struct BIncrementalData : public Parcelable { - std::string bundleName; - int64_t lastIncrementalTime; - int32_t manifestFd; - std::string backupParameters; - int32_t backupPriority; - - BIncrementalData() = default; - BIncrementalData(std::string name, int64_t nTime, int fd = -1, std::string parameters = "", int32_t priority = 0) - : bundleName(name), lastIncrementalTime(nTime), manifestFd(fd), backupParameters(parameters), - backupPriority(priority) - { - } - ~BIncrementalData() override = default; - - bool ReadFromParcel(Parcel &parcel); - bool Marshalling(Parcel &parcel) const override; - static BIncrementalData *Unmarshalling(Parcel &parcel); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +namespace OHOS::FileManagement::Backup {} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 50c47bf7b..b2b51235f 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -24,7 +24,8 @@ #include "b_file_info.h" #include "errors.h" -#include "i_service.h" +#include "iservice.h" +#include "service_common.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 64615acb2..58ca45178 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -24,7 +24,8 @@ #include "b_file_info.h" #include "errors.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h new file mode 100644 index 000000000..d00e16502 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H + +#include +#include + +#include "parcel.h" + +namespace OHOS::FileManagement::Backup { +using BundleName = std::string; +using TmpFileSN = uint32_t; + +struct BFileInfo : public Parcelable { + BundleName owner; + std::string fileName; + TmpFileSN sn; // 用于服务零拷贝接收文件场景 + + BFileInfo() = default; + BFileInfo(std::string bundleName, std::string strFileNanme, TmpFileSN id) + : owner(bundleName), fileName(strFileNanme), sn(id) {} + ~BFileInfo() override = default; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static BFileInfo *Unmarshalling(Parcel &parcel); +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h new file mode 100644 index 000000000..77785e18b --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H + +#include +#include + +#include "parcel.h" +#include "unique_fd.h" + +namespace OHOS::FileManagement::Backup { +struct BIncrementalData : public Parcelable { + std::string bundleName; + int64_t lastIncrementalTime; + int32_t manifestFd; + std::string backupParameters; + int32_t backupPriority; + + BIncrementalData() = default; + BIncrementalData(std::string name, int64_t nTime, int fd = -1, std::string parameters = "", int32_t priority = 0) + : bundleName(name), lastIncrementalTime(nTime), manifestFd(fd), backupParameters(parameters), + backupPriority(priority) + { + } + ~BIncrementalData() override = default; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static BIncrementalData *Unmarshalling(Parcel &parcel); +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h deleted file mode 100644 index 0108a3437..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ /dev/null @@ -1,104 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_H - -#include -#include - -#include - -#include "b_file_info.h" -#include "b_incremental_data.h" -#include "i_service_ipc_interface_code.h" -#include "i_service_reverse.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -const int DEFAULT_INVAL_VALUE = -1; - -typedef enum TypeRestoreTypeEnum { - RESTORE_DATA_WAIT_SEND = 0, - RESTORE_DATA_READDY = 1, -} RestoreTypeEnum; - -enum BackupRestoreScenario { - FULL_BACKUP = 0, - INCREMENTAL_BACKUP = 1, - FULL_RESTORE = 2, - INCREMENTAL_RESTORE = 3, -}; - -class IService : public IRemoteBroker { -public: - virtual ~IService() = default; - virtual ErrCode InitRestoreSession(sptr remote) = 0; - virtual ErrCode InitRestoreSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode InitBackupSession(sptr remote) = 0; - virtual ErrCode InitBackupSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode Start() = 0; - virtual UniqueFd GetLocalCapabilities() = 0; - virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; - virtual ErrCode PublishFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) = 0; - virtual ErrCode AppDone(ErrCode errCode) = 0; - virtual ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) = 0; - virtual ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; - virtual ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) = 0; - virtual ErrCode Finish() = 0; - virtual ErrCode Release() = 0; - virtual ErrCode Cancel(std::string bundleName, int32_t &result) = 0; - virtual UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) = 0; - virtual ErrCode GetAppLocalListAndDoIncrementalBackup() = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse) = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse, std::string &errMsg) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &bundleInfos) = 0; - - virtual ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) = 0; - virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) = 0; - virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; - virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; - virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) = 0; - virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0; - virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0; - virtual ErrCode StartExtTimer(bool &isExtStart) = 0; - virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0; - virtual ErrCode StopExtTimer(bool &isExtStop) = 0; - virtual ErrCode RefreshDataSize(int64_t totalSize) = 0; - virtual ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h deleted file mode 100644 index ba99705fe..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h +++ /dev/null @@ -1,64 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H - -/*SAID: 5203*/ -namespace OHOS::FileManagement::Backup { -enum class IServiceInterfaceCode { - SERVICE_CMD_INIT_RESTORE_SESSION, - SERVICE_CMD_INIT_RESTORE_SESSION_MSG, - SERVICE_CMD_INIT_BACKUP_SESSION, - SERVICE_CMD_INIT_BACKUP_SESSION_MSG, - SERVICE_CMD_GET_LOCAL_CAPABILITIES, - SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS, - SERVICE_CMD_PUBLISH_FILE, - SERVICE_CMD_APP_FILE_READY, - SERVICE_CMD_APP_DONE, - SERVICE_CMD_RESULT_REPORT, - SERVICE_CMD_START, - SERVICE_CMD_GET_FILE_NAME, - SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL, - SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, - SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, - SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS, - SERVICE_CMD_FINISH, - SERVICE_CMD_RELSEASE_SESSION, - SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL, - SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION, - SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG, - SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION, - SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS, - SERVICE_CMD_PUBLISH_INCREMENTAL_FILE, - SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE, - SERVICE_CMD_APP_INCREMENTAL_FILE_READY, - SERVICE_CMD_APP_INCREMENTAL_DONE, - SERVICE_CMD_GET_INCREMENTAL_FILE_NAME, - SERVICE_CMD_GET_BACKUP_INFO, - SERVICE_CMD_UPDATE_TIMER, - SERVICE_CMD_START_EXT_TIMER, - SERVICE_CMD_START_FWK_TIMER, - SERVICE_CMD_UPDATE_SENDRATE, - SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP, - SERVICE_CMD_REPORT_APP_PROCESS_INFO, - SERVICE_CMD_CANCEL_BUNDLE, - SERVICE_CMD_STOP_EXT_TIMER, - SERVICE_CMD_REFRESH_DATA_SIZE, - SERVICE_CMD_GET_BACKUP_DATA_SIZE, -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h similarity index 98% rename from interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h rename to interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h index 4ca5a7621..c91ca3d5b 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/iservice_reverse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h new file mode 100644 index 000000000..2812aaae6 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H + +#include +#include +#include +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "system_ability_load_callback_stub.h" + + +namespace OHOS::FileManagement::Backup { +class ServiceClient { + +public: + static sptr GetServiceProxyPointer(); + static sptr GetInstance(); + static void InvaildInstance(); + bool CheckServiceProxy(); +public: + explicit ServiceClient(); + ~ServiceClient(); +public: + class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + + public: + std::condition_variable proxyConVar_; + std::atomic isLoadSuccess_ = {false}; + }; + +private: + static inline std::mutex proxyMutex_; + static inline std::mutex getInstanceMutex_; + static inline sptr serviceProxy_ = nullptr; +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h new file mode 100644 index 000000000..3cb31fc79 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H + +namespace OHOS::FileManagement::Backup { +const int DEFAULT_INVAL_VALUE = -1; + +typedef enum TypeRestoreTypeEnum { + RESTORE_DATA_WAIT_SEND = 0, + RESTORE_DATA_READDY = 1, +} RestoreTypeEnum; + +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h deleted file mode 100644 index 4302e07b8..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ /dev/null @@ -1,112 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H - -#include -#include -#include -#include - -#include "i_service.h" -#include "iremote_proxy.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceProxy : public IRemoteProxy { -public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; - ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; - ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; - ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override; - ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; - ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) override; - ErrCode Finish() override; - ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; - ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; - ErrCode AppIncrementalDone(ErrCode errCode) override; - ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; - ErrCode StartExtTimer(bool &isExtStart) override; - ErrCode StartFwkTimer(bool &isFwkStart) override; - ErrCode StopExtTimer(bool &isExtStop) override; - ErrCode RefreshDataSize(int64_t totalSize) override; - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) override; -public: - explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceProxy() override {} - -public: - template - bool WriteParcelableVector(const std::vector &parcelableVector, Parcel &data); - static sptr GetServiceProxyPointer(); - static sptr GetInstance(); - static void InvaildInstance(); - -public: - class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - public: - std::condition_variable proxyConVar_; - std::atomic isLoadSuccess_ = {false}; - }; - -private: - static inline std::mutex proxyMutex_; - static inline std::mutex getInstanceMutex_; - static inline sptr serviceProxy_ = nullptr; - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H \ No newline at end of file diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 16db36cef..8030493aa 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -159,6 +159,7 @@ ohos_shared_library("backup") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index e4a1ef547..e5b5c5950 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -15,14 +15,13 @@ #include "prop_n_operation.h" #include "b_error/b_error.h" -#include "b_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" #include "incremental_backup_data.h" #include "parse_inc_info_from_js.h" -#include "service_proxy.h" +#include "service_client.h" #include "access_token.h" #include "accesstoken_kit.h" #include "ipc_skeleton.h" @@ -39,13 +38,16 @@ static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg) auto fd = make_shared(); auto cbExec = [fd]() -> NError { HILOGI("called LocalCapabilities::AsyncCallback cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncCallback cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilities(); + int fdNum = -1; + proxy->GetLocalCapabilities(fdNum); + UniqueFd fdData(fdNum); + *fd = std::move(fdData); HILOGI("called LocalCapabilities::AsyncCallback cbExec success"); return NError(ERRNO_NOERR); }; @@ -81,15 +83,18 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) } auto fd = make_shared(); - auto cbExec = [fd, bundles { move(bundles) }]() -> NError { + auto cbExec = [fd, bundles {move(bundles)}]() -> NError { HILOGI("called LocalCapabilities::AsyncDataList cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncDataList cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilitiesIncremental(bundles); + int fdValue = -1; + proxy->GetLocalCapabilitiesIncremental(bundles, fdValue); + UniqueFd fdData(fdValue); + *fd = std::move(fdData); return NError(ERRNO_NOERR); }; auto cbCompl = [fd](napi_env env, NError err) -> NVal { @@ -165,8 +170,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info return nullptr; } - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoGetBackupInfo,failed to get proxy"); return nullptr; @@ -191,8 +196,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called UpdateSendRate,failed to get proxy"); return result; @@ -208,8 +213,8 @@ bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoUpdateTimer,failed to get proxy"); return result; diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 8c877bed7..d21cefe54 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -11,9 +11,136 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//foundation/filemanagement/app_file_service/backup.gni") +idl_gen_interface("backup_idl") { + sources = [ "IService.idl" ] + hitrace = "HITRACE_TAG_FILEMANAGEMENT" + log_domainid = "0xD004313" + log_tag = "AppFileService" +} + +config("public_idl_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("backup_sa_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_sa_ipc_type") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*_type.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_sa_ipc_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, []) + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +config("public_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + ohos_shared_library("backup_sa") { branch_protector_ret = "pac_ret" @@ -36,7 +163,6 @@ ohos_shared_library("backup_sa") { "src/module_ipc/service_incremental.cpp", "src/module_ipc/service_incremental_reverse_proxy.cpp", "src/module_ipc/service_reverse_proxy.cpp", - "src/module_ipc/service_stub.cpp", "src/module_ipc/sub_service.cpp", "src/module_ipc/svc_backup_connection.cpp", "src/module_ipc/svc_extension_incremental_proxy.cpp", @@ -55,9 +181,11 @@ ohos_shared_library("backup_sa") { include_dirs = [ "include", "include/module_notify", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", ] deps = [ + ":backup_sa_ipc", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", diff --git a/services/backup_sa/ExtensionType.idl b/services/backup_sa/ExtensionType.idl new file mode 100644 index 000000000..19014d92c --- /dev/null +++ b/services/backup_sa/ExtensionType.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.FileManagement.Backup.ExtensionType; + +struct UniqueFdGroup { + FileDescriptor fd; + FileDescriptor reportFd; + int errCode; +}; \ No newline at end of file diff --git a/services/backup_sa/IService.idl b/services/backup_sa/IService.idl new file mode 100644 index 000000000..5ecb32295 --- /dev/null +++ b/services/backup_sa/IService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022-2025 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. + */ + +package OHOS.FileManagement.Backup; +import ServiceType; +interface OHOS.FileManagement.Backup.IServiceReverse; +sequenceable BackupFileInfo..OHOS.FileManagement.Backup.BFileInfo; +sequenceable BackupIncrementalData..OHOS.FileManagement.Backup.BIncrementalData; +interface OHOS.FileManagement.Backup.IService{ + [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 2] void InitBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 3] void InitBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 4] void Start(); + [ipccode 5] void GetLocalCapabilities([out] FileDescriptor fd); + [ipccode 6] void GetLocalCapabilitiesForBundleInfos([out] FileDescriptor fd); + [ipccode 7] void PublishFile([in] BFileInfo fileInfo); + [oneway, ipccode 8] void GetFileHandle([in] String bundleName, [in] String fileName); + [ipccode 9] void AppendBundlesRestoreSessionDataByDetail([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] String[] detailInfos, + [in] int restoreType, + [in] int userId); + [ipccode 10] void AppendBundlesRestoreSessionData([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] int restoreType, + [in] int userId); + [ipccode 11] void AppendBundlesBackupSession([in] String[] bundleNames); + [ipccode 12] void AppendBundlesDetailsBackupSession([in] String[] bundleNames, [in] String[] bundleInfos); + [ipccode 13] void Finish(); + [ipccode 14] void Release(); + [ipccode 15] void Cancel([in] String bundleName, [out] int cancelResult); + [ipccode 16] void GetAppLocalListAndDoIncrementalBackup(); + [ipccode 17] void GetIncrementalFileHandle([in] String bundleName, [in] String fileName); + [ipccode 18] void GetBackupInfo([in] String bundleName, [out] String getBackupInfoResult); + [ipccode 19] void UpdateTimer([in] String bundleName, [in] unsigned int timeout, [out] boolean updateTimerResult); + [ipccode 20] void UpdateSendRate([in] String bundleName, [in] int sendRate, [out] boolean updateSendRateResult); + [ipccode 21] void StartExtTimer([out] boolean isExtStart); + [ipccode 22] void StartFwkTimer([out] boolean isFwkStart); + [ipccode 23] void StopExtTimer([out] boolean isExtStop); + [ipccode 24] void GetLocalCapabilitiesIncremental([in] BIncrementalData[] bundleNames, [out] FileDescriptor fd); + [ipccode 25] void InitIncrementalBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 26] void InitIncrementalBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, + [out] String errMsg); + [ipccode 27] void AppendBundlesIncrementalBackupSession([in] BIncrementalData[] bundlesToBackup); + [ipccode 28] void AppendBundlesIncrementalBackupSessionWithBundleInfos([in] BIncrementalData[] bundlesToBackup, + [in]String[] bundleInfos); + [ipccode 29] void PublishIncrementalFile([in] BFileInfo fileInfo); + [ipccode 30] void PublishSAIncrementalFile([in] BFileInfo fileInfo, [in] FileDescriptor fd); + [ipccode 31] void AppIncrementalFileReady([in] String fileName, [in] FileDescriptor fd, [in] FileDescriptor manifestFd, + [in] int appIncrementalFileReadyErrCode); + [ipccode 32] void AppIncrementalDone([in] int appIncrementalDoneErrCode); + [ipccode 33] void ReportAppProcessInfo([in] String processInfo, [in] BackupRestoreScenario scenario); + [ipccode 34] void RefreshDataSize([in] long totalDataSize); + [ipccode 35] void AppDone([in] int appDoneErrCode); + [ipccode 36] void AppFileReady([in]String fileName, [in] FileDescriptor fd, [in] int appFileReadyErrCode); + [ipccode 37] void ServiceResultReport([in]String restoreRetInfo, [in] BackupRestoreScenario sennario, + [in] int serviceResultReportErrCode); + [ipccode 38] void GetBackupDataSize([in] boolean isPreciseScan,[in] BIncrementalData[] bundleNameList); + } \ No newline at end of file diff --git a/services/backup_sa/ServiceType.idl b/services/backup_sa/ServiceType.idl new file mode 100644 index 000000000..5fc7cb1cf --- /dev/null +++ b/services/backup_sa/ServiceType.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.FileManagement.Backup; + +enum BackupRestoreScenario { + FULL_BACKUP = 0, + INCREMENTAL_BACKUP = 1, + FULL_RESTORE = 2, + INCREMENTAL_RESTORE = 3, +}; \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 34a0fb99a..075f0b640 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -23,7 +23,7 @@ #include "b_json/b_json_clear_data_config.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_service_disposal_config.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" #include "module_sched/sched_scheduler.h" #include "service_stub.h" @@ -48,53 +48,70 @@ class Service : public SystemAbility, public ServiceStub, protected NoCopyable { // 以下都是IPC接口 public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitRestoreSession(const sptr& remote) override; + ErrCode InitRestoreSessionWithErrMsg(const sptr& reverseIpcRemoteObject, + std::string& errMsg) override; + ErrCode InitBackupSession(const sptr& remote) override; + ErrCode InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; + ErrCode GetLocalCapabilities(int& fd) override; + + ErrCode GetLocalCapabilitiesForBundleInfos(int& fd) override; ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) override; ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, + ErrCode ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) override; ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &bundleInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + + ErrCode AppendBundlesRestoreSessionDataByDetail( + int fd, + const std::vector& bundleNames, + const std::vector& detailInfos, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesRestoreSessionData( + int fd, + const std::vector& bundleNames, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; + ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; + ErrCode Cancel(const std::string& bundleName, int32_t &result) override; + ErrCode GetLocalCapabilitiesIncremental( + const std::vector& bundleNames, + int& fd) override; ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitIncrementalBackupSession(const sptr& remote) override; + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector& bundlesToBackup, + const std::vector& bundleInfos) override; + ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; + ErrCode PublishSAIncrementalFile( + const BFileInfo& fileInfo, + int fd) override; + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); + ErrCode AppIncrementalFileReady( + const std::string& fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; + ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; + ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override; + ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override; + ErrCode ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; ErrCode StopExtTimer(bool &isExtStop) override; @@ -104,7 +121,7 @@ public: const ErrCode errCode, const BackupRestoreScenario sennario); void StartGetFdTask(std::string bundleName, wptr ptr); - ErrCode GetBackupDataSize(bool isPreciseScan, vector bundleNameList) override; + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) override; // 以下都是非IPC接口 public: @@ -212,7 +229,7 @@ public: * @param bundleName 应用名称 * */ - AAFwk::Want CreateConnectWant (BundleName &bundleName); + AAFwk::Want CreateConnectWant (const BundleName &bundleName); /** * @brief SA backup回调 @@ -242,7 +259,8 @@ public: * @param bundleName 应用名称 * */ - std::function GetBackupInfoConnectDone(wptr obj, std::string &bundleName); + std::function GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName); /** * @brief GetBackupInfo extension死亡回调 @@ -252,7 +270,7 @@ public: * */ std::function GetBackupInfoConnectDied( - wptr obj, std::string &bundleName); + wptr obj, const std::string &bundleName); /** * @brief timeout callback @@ -526,7 +544,7 @@ private: * @param result 业务结果出参 * */ - ErrCode GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result); + ErrCode GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result); /** * @brief 添加需要清理的Session @@ -646,6 +664,28 @@ private: bool GetScanningInfo(wptr obj, size_t scannedSize, string &scanning); void SetScanningInfo(string &scanning, string name); + + ErrCode InitRestoreSession(const sptr& remote, std::string &errMsg); + + UniqueFd GetLocalCapabilities(); + UniqueFd GetLocalCapabilitiesForBundleInfos(); + + ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); + + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + + UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames); + + ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &infos); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h index 7578aca36..567082b54 100644 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ b/services/backup_sa/include/module_ipc/service_reverse_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -16,7 +16,7 @@ #ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H #define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h deleted file mode 100644 index d4484365a..000000000 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ /dev/null @@ -1,85 +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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H - -#include - -#include "i_service.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceStub(); - ~ServiceStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdStart(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdFinish(MessageParcel &data, MessageParcel &reply); - int32_t CmdRelease(MessageParcel &data, MessageParcel &reply); - int32_t CmdCancel(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply); - int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStopExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply); - void ServiceStubSupplement(); - void ServiceStubSuppAppendBundles(); - -public: - template - bool ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h index cb83798b9..cea2d222e 100644 --- a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h +++ b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -22,7 +22,8 @@ #include #include "b_json/b_json_entity_caps.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { 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 98fd49414..3585fd62c 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -32,8 +32,9 @@ #include "b_file_info.h" #include "b_incremental_data.h" #include "b_resources/b_constants.h" -#include "i_service.h" -#include "i_service_reverse.h" +#include "service_common.h" +#include "iservice.h" +#include "iservice_reverse.h" #include "module_ipc/svc_backup_connection.h" #include "module_ipc/sa_backup_connection.h" #include "svc_death_recipient.h" @@ -332,7 +333,7 @@ public: * * @param bundleName 应用名称 */ - sptr CreateBackupConnection(BundleName &bundleName); + sptr CreateBackupConnection(const BundleName &bundleName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 65a225c97..b4ce9a773 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -133,11 +133,11 @@ void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCod UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } } @@ -224,12 +224,12 @@ void Service::OnStart() } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { if (!bundleNameList.empty()) { - OnStartResRadarReport(bundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + HILOGI("bundleNameList !=null"); } if (!residualBundleNameList.empty()) { OnStartResRadarReport(residualBundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); } SetOccupySession(true); session_->Active( @@ -274,6 +274,14 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +ErrCode Service::GetLocalCapabilities(int& fd) +{ + UniqueFd fdResult(GetLocalCapabilities()); + fd = fdResult.Release(); + HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -362,8 +370,8 @@ void Service::PermissionCheckFailRadar(const std::string &info, const std::strin { std::string funcPos = "Service::"; AppRadar::Info resInfo("", "", info); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } @@ -379,8 +387,8 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) HILOGE("Verify and get caller name failed, Get hap token info failed"); return BError(BError::Codes::SA_INVAL_ARG); } - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, - hapTokenInfo.instIndex); + std::string bundleNameIndexInfo = + BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, hapTokenInfo.instIndex); ErrCode ret = session_->VerifyBundleName(bundleNameIndexInfo); if (ret != ERR_OK) { HILOGE("Verify bundle name failed, bundleNameIndexInfo:%{public}s", bundleNameIndexInfo.c_str()); @@ -461,7 +469,7 @@ ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) return VerifyCaller(); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -493,7 +501,7 @@ ErrCode Service::InitRestoreSession(sptr remote) return ret; } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitBackupSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -625,14 +633,15 @@ static vector GetRestoreBundleNames(UniqueFd fd, } void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) + const vector &appendBundleNames, + const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," "restoreBundleNames size:%{public}zu", appendBundleNames.size(), restoreBundleNames.size()); for (const auto &bundleName : appendBundleNames) { auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&bundleName](const auto &obj) { return obj == bundleName; }); + [&bundleName](const auto &obj) { return obj == bundleName; }); if (it == restoreBundleNames.end()) { HILOGE("AppendBundles failed, bundleName = %{public}s.", bundleName.c_str()); OnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), session, bundleName); @@ -641,8 +650,25 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &bundleInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionDataByDetail"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType, + int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); @@ -663,8 +689,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector bundleNamesOnly; std::map isClearDataFlags; std::map> bundleNameDetailMap = - BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - session_->GetSessionUserId(), isClearDataFlags); + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, session_->GetSessionUserId(), + isClearDataFlags); std::string oldBackupVersion; auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); @@ -675,8 +701,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("End"); @@ -695,7 +721,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &restoreBundleInfos, - std::vector &restoreBundleNames, RestoreTypeEnum restoreType, std::string &backupVersion) + std::vector &restoreBundleNames, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -706,11 +734,11 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); + restoreInfo.extensionName.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { @@ -731,6 +759,18 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionData"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); +} ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, @@ -779,7 +819,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } -void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, +void Service::SetCurrentSessProperties( + std::vector &restoreBundleInfos, std::vector &restoreBundleNames, std::map> &bundleNameDetailMap, std::map &isClearDataFlags, RestoreTypeEnum restoreType, std::string &backupVersion) @@ -795,7 +836,7 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); @@ -816,14 +857,14 @@ void Service::SetCurrentSessProperties(std::vector } BJsonUtil::BundleDetailInfo broadCastInfo; BJsonUtil::BundleDetailInfo uniCastInfo; - bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, - broadCastInfo); + bool broadCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, broadCastInfo); if (broadCastRet) { bool notifyRet = DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); HILOGI("Publish event end, notify result is:%{public}d", notifyRet); } - bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, - uniCastInfo); + bool uniCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo); if (uniCastRet) { HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); @@ -873,7 +914,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName } ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &bundleInfos) + const vector &bundleInfos) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -916,19 +957,20 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun } } -void Service::HandleCurGroupBackupInfos(std::vector &backupInfos, +void Service::HandleCurGroupBackupInfos( + std::vector &backupInfos, std::map> &bundleNameDetailMap, std::map &isClearDataFlags) { for (auto &info : backupInfos) { - HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", - info.name.c_str(), info.extensionName.c_str(), info.appIndex); + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", info.name.c_str(), + info.extensionName.c_str(), info.appIndex); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); BJsonUtil::BundleDetailInfo uniCastInfo; if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) { HILOGI("current bundle:%{public}s, unicast info:%{public}s, unicast info size:%{public}zu", - bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); + bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); @@ -937,8 +979,7 @@ void Service::HandleCurGroupBackupInfos(std::vector } } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -975,8 +1016,10 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } } -ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, - const ErrCode errCode, const BackupRestoreScenario sennario) +ErrCode Service::SAResultReport(const std::string bundleName, + const std::string restoreRetInfo, + const ErrCode errCode, + const BackupRestoreScenario sennario) { SADone(errCode, bundleName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { @@ -993,7 +1036,7 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); } else if (sennario == BackupRestoreScenario::FULL_BACKUP || - sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::BACKUP); } return BError(BError::Codes::OK); @@ -1003,8 +1046,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore { HILOGI("Begin"); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && - sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { return; } if (session_->OnBundleFileReady(bundleName)) { @@ -1092,9 +1134,9 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) int32_t errCode = 0; UniqueFd fd = proxy->GetFileHandle(fileName, errCode); if (errCode != ERR_OK) { - AppRadar::Info info (bundleName, "", ""); + AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); @@ -1181,7 +1223,8 @@ int Service::Dump(int fd, const vector &args) } void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, const ErrCode ret) + const std::string &bundleName, + const ErrCode ret) { try { if (session_ == nullptr) { @@ -1547,7 +1590,8 @@ void Service::SessionDeactive() } } -std::function Service::GetBackupInfoConnectDone(wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName) { HILOGI("GetBackupInfoConnectDone, bundleName: %{public}s", bundleName.c_str()); @@ -1560,8 +1604,8 @@ std::function Service::GetBackupInfoConnectDone(wptr }; } -std::function Service::GetBackupInfoConnectDied( - wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDied(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName, bool isCleanCalled) { HILOGI("GetBackupInfoConnectDied, bundleName: %{public}s", bundleName.c_str()); @@ -1604,7 +1648,7 @@ ErrCode Service::ClearResidualBundleData(const std::string &bundleName) return res; } -ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result) { if (session_ == nullptr) { HILOGE("Get BackupInfo error, session is empty."); @@ -1650,7 +1694,7 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { @@ -1660,7 +1704,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } try { std::lock_guard lock(getBackupInfoProcLock_); - HILOGI("Service::GetBackupInfo begin."); + HILOGI("Service::GetBackupInfo begin bundleName: %{public}s", bundleName.c_str()); if (session_ == nullptr || isOccupyingSession_.load()) { HILOGE("Get BackupInfo error, session is empty."); return BError(BError::Codes::SA_INVAL_ARG); @@ -1725,7 +1769,7 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { try { HILOGI("Service::UpdateTimer begin."); @@ -1754,7 +1798,7 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res } } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); if (session_ == nullptr || isOccupyingSession_.load()) { @@ -1793,7 +1837,8 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool ret = BError(BError::Codes::SA_INVAL_ARG); break; } - ret = proxy->UpdateFdSendRate(bundleName, sendRate); + std::string extBundleName = static_cast(bundleName); + ret = proxy->UpdateFdSendRate(extBundleName, sendRate); if (ret != NO_ERROR) { HILOGE("Extension do updateSendRate failed, ret:%{public}d", ret); result = false; @@ -1806,7 +1851,7 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool return ret; } -AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +AAFwk::Want Service::CreateConnectWant(const BundleName &bundleName) { BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; AAFwk::Want want; @@ -1842,12 +1887,14 @@ ErrCode Service::BackupSA(std::string bundleName) return BError(BError::Codes::OK); } -void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, - const ErrCode &errCode) +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) { auto task = [bundleName, fd, result, errCode, this]() { HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", - bundleName.c_str(), fd, result.c_str(), errCode); + bundleName.c_str(), fd, result.c_str(), errCode); session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); @@ -1864,8 +1911,8 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) { auto task = [bundleName, result, errCode, this]() { - HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", - bundleName.c_str(), result.c_str(), errCode); + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", bundleName.c_str(), + result.c_str(), errCode); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); }; threadPool_.AddTask([task]() { @@ -1915,16 +1962,10 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN auto ms = std::chrono::duration_cast(now.time_since_epoch()); std::stringstream strTime; strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "PROC_NAME", "ohos.appfileservice", - "BUNDLENAME", callerName, - "PID", getpid(), - "TIME", strTime.str() - ); + << (std::setw(INDEX)) << (ms.count() % MS_1000); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str()); } else if (scenario == IServiceReverse::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); @@ -1932,7 +1973,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN BundleEndRadarReport(callerName, errCode, scenario); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 307b4204b..9f757a668 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -121,6 +121,15 @@ void Service::CreateDirIfNotExist(const std::string &path) } } } +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin GetLocalCapabilitiesIncremental fd = %{private}d", fd); + UniqueFd fdResult(GetLocalCapabilitiesIncremental(bundleNames)); + fd = fdResult.Release(); + HILOGI("End GetLocalCapabilitiesIncremental fd = %{private}d", fd); + return BError(BError::Codes::OK); // anytime return OK +} UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) { @@ -211,9 +220,11 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); - string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). - append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); - HILOGD("path = %{public}s,bundleName = %{public}s", path.c_str(), bundleName.c_str()); + string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()) + .append(bundleName) + .append("/") + .append(BConstants::BACKUP_STAT_SYMBOL) + .append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { HILOGD("fdLocal open fail, error = %{public}d", errno); @@ -293,7 +304,7 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() } } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr& remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -328,7 +339,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return errCode; } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -414,6 +425,13 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return AppendBundlesIncrementalBackupSession(bundlesToBackup, bundleInfos); +} ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, const std::vector &infos) @@ -518,6 +536,13 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) +{ + HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); + UniqueFd uniquedParameter(fd); + return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); +} + ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { std::string bundleName = fileInfo.owner; @@ -541,8 +566,11 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd return saConnection->CallRestoreSA(move(fd)); } -ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, - UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, + const std::string &fileName, + UniqueFd fd, + UniqueFd manifestFd, + int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -556,13 +584,13 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st fd = session_->OnBundleExtManageInfo(bundleName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); + move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); if (ret != ERR_OK) { - HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); return ret; } } @@ -577,6 +605,23 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st } } +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + HILOGI("Begin AppIncrementalFileReady:%{public}s, fd:%{public}d, manifestFd:%{public}d, errcode:%{public}d", + fileName.c_str(), fd, manifestFd, appIncrementalFileReadyErrCode); + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); + } + UniqueFd fdUnique(fd); + UniqueFd manifestFdUnique(manifestFd); + return AppIncrementalFileReady(fileName, std::move(fdUnique), std::move(manifestFdUnique), + appIncrementalFileReadyErrCode); +} + ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -739,7 +784,8 @@ bool Service::IncrementalBackup(const string &bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); } return true; - } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + } else if (scenario == IServiceReverse::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -904,7 +950,7 @@ void Service::CancelTask(std::string bundleName, wptr ptr) thisPtr->OnAllBundlesFinished(BError(BError::Codes::OK)); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin, bundle name:%{public}s", bundleName.c_str()); diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp deleted file mode 100644 index ae94248e9..000000000 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ /dev/null @@ -1,858 +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. - */ - -/* - * 注意: - * - 注意点1:本文件原则上只处理与IPC模块的IO,具体业务逻辑实现在service.cpp中 - * - 注意点2:所有调用开头处打印 Begin 字样,通过BError返回正常结果/错误码,这是出于防抵赖的目的 - */ - -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "module_ipc/service_reverse_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; - - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER)] = - &ServiceStub::CmdStartExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] = - &ServiceStub::CmdStartFwkTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; -} - -void ServiceStub::ServiceStubSuppAppendBundles() -{ - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; -} - -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT)] = - &ServiceStub::CmdResultReport; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - ServiceStubSuppAppendBundles(); - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishSAIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE)] = - &ServiceStub::CmdAppIncrementalDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; - ServiceStubSupplement(); -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitRestoreSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitRestoreSession(iremote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int res = InitBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int res = InitBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppFileReady(fileName, move(fd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = AppDone(errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - int32_t scenario; - ErrCode errCode; - if (!data.ReadString(restoreRetInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreRetInfo"); - } - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive scenario"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - HILOGE("Failed to receive bundle detailInfos"); - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesBackupSession(bundleNames); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - - int32_t res = AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdGetBackupInfo Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - string result; - ret = GetBackupInfo(bundleName, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdGetBackupInfo end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateTimer Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); - } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateSendRate Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateSendRate")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateSendRate end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartExtTimer Begin."); - int ret = ERR_OK; - bool isExtStart; - ret = StartExtTimer(isExtStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isExtStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartFwkTimer Begin."); - int ret = ERR_OK; - bool isFwkStart; - ret = StartFwkTimer(isFwkStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isFwkStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartFwkTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!ReadParcelableVector(bundleNames, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - UniqueFd fd(GetLocalCapabilitiesIncremental(bundleNames)); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - int32_t res = GetAppLocalListAndDoIncrementalBackup(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitIncrementalBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitIncrementalBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - std::vector infos; - if (!data.ReadStringVector(&infos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive infos"); - } - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishIncrementalFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - UniqueFd fd(data.ReadFileDescriptor()); - int res = PublishSAIncrementalFile(*fileInfo, move(fd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - UniqueFd manifestFd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - manifestFd = UniqueFd(data.ReadFileDescriptor()); - if (manifestFd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive manifestFd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppIncrementalFileReady(fileName, move(fd), move(manifestFd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply) -{ - int32_t ret; - if (!data.ReadInt32(ret)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bool flag"); - } - int res = AppIncrementalDone(ret); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - return GetIncrementalFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - string processInfo; - if (!data.ReadString(processInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t scenario; - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - return ReportAppProcessInfo(processInfo, secenrioInfo); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStopExtTimer Begin."); - bool isExtStop; - auto ret = StopExtTimer(isExtStop); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call StopExtTimer")); - } - if (!reply.WriteBool(isExtStop)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStopExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdRefreshDataSize Begin."); - int64_t totalDatasize = 0; - if (!data.ReadInt64(totalDatasize)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive totalDatasize").GetCode(); - } - auto ret = RefreshDataSize(totalDatasize); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to receive totalDatasize")); - } - bool ifRefreshSuccess = true; - if (!reply.WriteBool(ifRefreshSuccess)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdRefreshDataSize end."); - return BError(BError::Codes::OK); -} - -template -bool ServiceStub::ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - HILOGE("Failed to read Parcelable size."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < BConstants::MAX_PARCELABLE_VECTOR_NUM) ? infoSize : BConstants::MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadParcelable(); - if (info == nullptr) { - HILOGE("Failed to read Parcelable infos."); - return false; - } - parcelableInfos.emplace_back(move(*info)); - } - - return true; -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdCancel Begin."); - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ErrCode res = Cancel(bundleName, result); - if (!reply.WriteInt32(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return res; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilitiesForBundleInfos()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub CmdGetBackupDataSize Begin."); - bool isPreciseScan = true; - isPreciseScan = data.ReadBool(); - vector bundleNameList; - if (!ReadParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - auto ret = GetBackupDataSize(isPreciseScan, bundleNameList); - HILOGI("ServiceStub GetBackupDataSize End ret = %{public}d", ret); - return ret; -} -} // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b679afd82..920f8bc36 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -243,6 +243,17 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) +{ + HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); + UniqueFd fdUnique(fd); + if (fd < 0) { + HILOGE("Error fd, fd = %{public}d", fd); + return BError(BError::Codes::SA_INVAL_ARG); + } + return AppFileReady(fileName, std::move(fdUnique), errCode); +} + ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -775,7 +786,13 @@ std::string Service::GetCallerName() return callerName; } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + HILOGI("Start InitRestoreSessionWithErrMsg,Msg :%{public}s", errMsg.c_str()); + return InitRestoreSession(remote, errMsg); +} + +ErrCode Service::InitRestoreSession(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -810,7 +827,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e return ret; } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -848,6 +865,14 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er return ret; } +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + UniqueFd uniqueFd(GetLocalCapabilitiesForBundleInfos()); + HILOGI("get GetLocalCapabilitiesForBundleInfos value"); + fd = uniqueFd.Release(); + return ErrCode(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilitiesForBundleInfos() { try { @@ -920,7 +945,7 @@ void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRes } } -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { HILOGI("start GetBackupDataSize"); 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 a0aafce1c..d04fea23f 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -682,7 +682,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.isAppendFinish = true; } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { HILOGD("SvcSessionManager::CreateBackupConnection begin."); return GetBackupAbilityExt(bundleName); diff --git a/test/fuzztest/backupext_fuzzer/BUILD.gn b/test/fuzztest/backupext_fuzzer/BUILD.gn index 81a738cca..a27cba754 100644 --- a/test/fuzztest/backupext_fuzzer/BUILD.gn +++ b/test/fuzztest/backupext_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("BackupExtFuzzTest") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsa_fuzzer/BUILD.gn b/test/fuzztest/backupsa_fuzzer/BUILD.gn index 2335ebb8f..b0025c1ea 100644 --- a/test/fuzztest/backupsa_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsa_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("BackupSaFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaanother_fuzzer/BUILD.gn b/test/fuzztest/backupsaanother_fuzzer/BUILD.gn index 99ab91e83..8331e81a8 100644 --- a/test/fuzztest/backupsaanother_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsaanother_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("BackupSaAnotherFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp index ca438cd7c..2b1f339e3 100644 --- a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp +++ b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp @@ -54,7 +54,7 @@ bool CmdGetFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE), datas, reply, option); service = nullptr; return true; @@ -79,7 +79,7 @@ bool CmdAppendBundlesBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -95,7 +95,7 @@ bool CmdReleaseFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -113,7 +113,7 @@ void GetBundleNamesData(const uint8_t *data, size_t size, vector(data)); - int32_t fd = *(reinterpret_cast(data)); + int fd = *(reinterpret_cast(data)); int32_t priority = *(reinterpret_cast(data + sizeof(int32_t))); string parameters = string(reinterpret_cast(data), size) + to_string(size - i); BIncrementalData incrementaData(name, nTime, fd, parameters, priority); @@ -152,7 +152,7 @@ bool CmdGetLocalCapabilitiesIncrementalFuzzTest(const uint8_t *data, size_t size MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -168,7 +168,7 @@ bool CmdInitIncrementalBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -189,7 +189,7 @@ bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(const uint8_t *data, size_ sptr service(new Service(SERVICE_ID)); uint32_t code = static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -216,7 +216,7 @@ bool CmdPublishIncrementalFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -242,7 +242,7 @@ bool CmdAppIncrementalFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -261,7 +261,7 @@ bool CmdAppIncrementalDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE), datas, reply, option); service = nullptr; return true; @@ -287,7 +287,7 @@ bool CmdGetIncrementalFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupsaappend_fuzzer/BUILD.gn b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn index f712886f6..ebeaa43a7 100644 --- a/test/fuzztest/backupsaappend_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("BackupSaAppendFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp index 2c44b7943..73826f873 100644 --- a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -45,7 +45,7 @@ bool CmdInitRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION), datas, reply, option); service = nullptr; return true; @@ -61,7 +61,7 @@ bool CmdInitBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION), datas, reply, option); service = nullptr; return true; @@ -87,7 +87,7 @@ bool CmdPublishFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE), datas, reply, option); service = nullptr; return true; @@ -103,7 +103,7 @@ bool CmdGetLocalCapabilitiesFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -127,7 +127,7 @@ bool CmdAppFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -145,7 +145,7 @@ bool CmdAppDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_DONE), datas, reply, option); service = nullptr; return true; @@ -161,7 +161,7 @@ bool CmdStartFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_START), datas, reply, option); service = nullptr; return true; @@ -177,7 +177,7 @@ bool CmdFinishFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_FINISH), datas, reply, option); service = nullptr; return true; @@ -219,7 +219,7 @@ bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupservicestub_fuzzer/BUILD.gn b/test/fuzztest/backupservicestub_fuzzer/BUILD.gn index e9fc47fb2..f32d8aa3d 100644 --- a/test/fuzztest/backupservicestub_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestub_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("BackupServiceStubFuzzTest") { deps = [ "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_stub", "${app_file_service_path}/utils:backup_utils", ] diff --git a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp index 2858c657a..1d0c74cc6 100644 --- a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp +++ b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp @@ -72,547 +72,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd); - } - msg.WriteInt32(errCode); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(scenario); - msg.WriteInt32(errCode); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - msg.WriteStringVector(bundleNames); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundleNames, msg); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundlesToBackup, msg); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 2; - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - infos.emplace_back(string(reinterpret_cast(data + len + len), len)); - WriteParcelableVector(bundlesToBackup, msg); - msg.WriteStringVector(infos); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - msg.WriteFileDescriptor(fd); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd1); - msg.WriteFileDescriptor(fd2); - } - msg.WriteInt32(errCode); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteString(string(reinterpret_cast(data), size)); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t timeout = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(timeout); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(sendRate); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -625,32 +84,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn index dcaad28f4..43efb9222 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("BackupServiceStubBranchFuzzTest") { deps = [ "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${app_file_service_path}/services/backup_sa:backup_sa", + "${app_file_service_path}/services/backup_sa:backup_sa_ipc_type", "${app_file_service_path}/utils:backup_utils", ] diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index 5b788a6cb..4b9fba7fa 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -193,6 +193,8 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } +constexpr int32_t SERVICE_ID = 5203; + template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -220,877 +222,18 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitRestoreSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdStart(msg, reply); - - ExpectReturn({true}); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetLocalCapabilities(msg, reply); - - ExpectReturn({true}); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - service->CmdAppFileReady(msg, reply); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - string restoreRetInfo(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({restoreRetInfo}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({restoreRetInfo, scenario}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, true}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, type}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, true}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdFinish(msg, reply); - - ExpectReturn({true}); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); - - int32_t infoSize = 1; - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - - ExpectReturn({true}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitIncrementalBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); - - ExpectReturn({false}); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - int32_t infoSize = 1; - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int32_t infoSize = 1; - int len = size >> 1; - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({fd, false}); - service->CmdPublishSAIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({fd, true}); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : - ExpectReturn({true, flag, fd1, fd2, errCode, false}); - } else { - ExpectReturn({true, flag, errCode, false}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : - ExpectReturn({true, flag, fd1, fd2, errCode, true}); - } else { - ExpectReturn({true, flag, errCode, true}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - string bundleName(reinterpret_cast(data), size); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - uint32_t timeout = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); if (service == nullptr) { return 0; } try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h deleted file mode 100644 index 6d074c8e3..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_H - -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "iremote_stub.h" -#include "service_stub.h" - -namespace OHOS::FileManagement::Backup { -class Service : public ServiceStub { -public: - ErrCode InitRestoreSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode Start() { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() { return UniqueFd(-1); } - UniqueFd GetLocalCapabilitiesForBundleInfos() { return UniqueFd(-1); } - ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string&, UniqueFd, int32_t) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string, - BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesDetailsBackupSession(const std::vector&, - const std::vector&) { return BError(BError::Codes::OK); } - ErrCode Finish() { return BError(BError::Codes::OK); } - ErrCode Release() { return BError(BError::Codes::OK); } - ErrCode Cancel(std::string, int32_t&) { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector&) { return UniqueFd(-1); } - ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo&, UniqueFd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string&, UniqueFd, UniqueFd, int32_t) - { return BError(BError::Codes::OK); } - ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode GetBackupInfo(BundleName&, std::string&) { return BError(BError::Codes::OK); } - ErrCode UpdateTimer(BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode UpdateSendRate(std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } - - ErrCode SAResultReport(const std::string, const std::string, - const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool, std::vector) { return BError(BError::Codes::OK); } -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file diff --git a/test/fuzztest/servicereverse_fuzzer/BUILD.gn b/test/fuzztest/servicereverse_fuzzer/BUILD.gn index 83e4237e0..ac3fee62e 100644 --- a/test/fuzztest/servicereverse_fuzzer/BUILD.gn +++ b/test/fuzztest/servicereverse_fuzzer/BUILD.gn @@ -42,6 +42,8 @@ ohos_fuzztest("ServiceReverseFuzzTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", ] diff --git a/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn b/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn index d091bc2ca..4c99a5352 100644 --- a/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/svcrestoredepsmanager_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("SvcRestoreDepsManagerFuzzTest") { 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", "${path_jsoncpp}:jsoncpp", ] diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp new file mode 100644 index 000000000..351c5dbc7 --- /dev/null +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -0,0 +1,80 @@ +/* + * 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 "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "iremote_object_mock.h" +#include "utils_mock_global_variable.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + if (!GetMockGetInstance()) { + return nullptr; + } + + if (!GetMockLoadSystemAbility()) { + serviceProxy_ = sptr(new ServiceProxy(nullptr)); + } else { + sptr object = new MockIRemoteObject(); + serviceProxy_ = sptr(new ServiceProxy(object)); + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index d7ce74b5c..5abdac177 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -31,7 +31,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +int32_t ServiceProxy::InitRestoreSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -39,7 +39,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote) return 0; } -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -47,7 +47,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote, std::stri return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote) +int32_t ServiceProxy::InitBackupSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -55,7 +55,7 @@ int32_t ServiceProxy::InitBackupSession(sptr remote) return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -68,12 +68,13 @@ ErrCode ServiceProxy::Start() return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { TestManager tm("ServiceProxyMock_GetFd_0100"); string filePath = tm.GetRootDirCurTest().append("tmp"); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - return fd; + UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + fd = fd_OpenData.Release(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) @@ -81,7 +82,7 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -91,7 +92,7 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, +ErrCode ServiceProxy::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); @@ -102,19 +103,19 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - const vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -125,7 +126,7 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl } ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) + const std::vector &detailInfos) { return BError(BError::Codes::OK); } @@ -140,15 +141,16 @@ ErrCode ServiceProxy::Release() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + fd = UniqueFd(-1).Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() @@ -156,23 +158,24 @@ ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr& remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const vector &infos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -182,12 +185,12 @@ ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -202,12 +205,12 @@ ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, co return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } @@ -232,58 +235,23 @@ ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario scenario) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() -{ - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - if (!GetMockGetInstance()) { - return nullptr; - } - - if (!GetMockLoadSystemAbility()) { - serviceProxy_ = sptr(new ServiceProxy(nullptr)); - } else { - sptr object = new MockIRemoteObject(); - serviceProxy_ = sptr(new ServiceProxy(object)); - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int& fd) { - return; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - return; -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); + fd=-1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector& bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h index fc5c50fe8..a0dc21137 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" 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 17634813c..899126848 100644 --- a/tests/mock/module_ipc/include/svc_session_manager_mock.h +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -38,7 +38,7 @@ public: virtual bool GetSchedBundleName(std::string&) = 0; virtual std::string GetBackupExtName(const std::string&) = 0; virtual std::string GetBackupExtInfo(const std::string&) = 0; - virtual sptr CreateBackupConnection(BundleName&) = 0; + virtual sptr CreateBackupConnection(const BundleName&) = 0; virtual bool IsOnAllBundlesFinished() = 0; virtual bool IsOnOnStartSched() = 0; virtual bool NeedToUnloadService() = 0; @@ -86,7 +86,7 @@ public: MOCK_METHOD(bool, GetSchedBundleName, (std::string&)); MOCK_METHOD(std::string, GetBackupExtName, (const std::string&)); MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName&)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName&)); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); MOCK_METHOD(bool, IsOnOnStartSched, ()); MOCK_METHOD(bool, NeedToUnloadService, ()); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 547ce2562..f0ebba00f 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -35,39 +35,72 @@ void Service::OnStart() {} void Service::OnStop() {} -UniqueFd Service::GetLocalCapabilities() +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -void Service::StopAll(const wptr &obj, bool force) {} +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::GetLocalCapabilities(int &fd) { + fd = -1; return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -82,7 +115,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -92,14 +125,16 @@ ErrCode Service::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -118,7 +153,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -186,15 +221,15 @@ ErrCode Service::Release() return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode Service::GetAppLocalListAndDoIncrementalBackup() @@ -202,12 +237,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } @@ -218,7 +253,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) + const std::vector &infos) { return BError(BError::Codes::OK); } @@ -228,12 +263,15 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode Service::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } @@ -248,7 +286,7 @@ ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } @@ -273,17 +311,17 @@ ErrCode Service::RefreshDataSize(int64_t totalDatasize) return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -307,26 +345,40 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName return make_shared(bundleName); } -void Service::RemoveExtensionMutex(const BundleName &bundleName) -{ -} +void Service::RemoveExtensionMutex(const BundleName &bundleName) {} void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) {} + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ +} -void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ +} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -359,32 +411,32 @@ void Service::ClearFailedBundles() {} void Service::GetOldDeviceBackupVersion() {} -void Service::CreateDirIfNotExist(const std::string &path) -{ -} - -void Service::StartRunningTimer(const std::string &bundleName) {} +void Service::CreateDirIfNotExist(const std::string &path) {} -std::vector Service::GetSupportBackupBundleNames(vector&, bool, - const vector&) +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) { return {}; } -void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} +void Service::StartRunningTimer(const std::string &bundleName) {} -void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} +void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} + +void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, - ErrCode errCode) {} +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ +} void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } @@ -401,7 +453,7 @@ void Service::DeleteFromList(size_t scannedSize) {} void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} -void Service::SendScannedInfo(const string&scannendInfos, sptr session) {} +void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 8a3c066a8..4d91c7c4d 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -13,384 +13,519 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" -#include "module_ipc/service_reverse_proxy.h" - +#include "service_stub.h" namespace OHOS::FileManagement::Backup { using namespace std; -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - ServiceStubSupplement(); - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; -} - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; -} - int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - return BError(BError::Codes::OK); - } - - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::OK); - } - return (this->*(interfaceIndex->second))(data, reply); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int32_t res = InitRestoreSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int32_t res = InitRestoreSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int res = InitBackupSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int res = InitBackupSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - reply.WriteFileDescriptor(fd); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - int res = PublishFile(*fileInfo); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - data.ReadString(fileName); - UniqueFd fd(data.ReadFileDescriptor()); - int res = AppFileReady(fileName, move(fd), 0); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - data.ReadInt32(errCode); - int res = AppDone(errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - data.ReadString(restoreRetInfo); - int32_t scenario; - data.ReadInt32(scenario); - ErrCode errCode; - data.ReadInt32(errCode); - BackupRestoreScenario type = static_cast(scenario); - int res = ServiceResultReport(restoreRetInfo, type, errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - data.ReadString(bundleName); - string fileName; - data.ReadString(fileName); - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesRestoreSession(move(fd), bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - std::vector detailInfos; - data.ReadStringVector(&detailInfos); - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesBackupSession(bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - std::string result; - ret = GetBackupInfo(bundleName, result); - return ret; -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName"); + switch (static_cast(code)) { + case IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitRestoreSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START: { + ErrCode errCode = Start(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES: { + int fd; + ErrCode errCode = GetLocalCapabilities(fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < bundleNamesSize; ++i1) { + std::string value1 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value1); + } + std::vector detailInfos; + int32_t detailInfosSize = data.ReadInt32(); + if (detailInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i2 = 0; i2 < detailInfosSize; ++i2) { + std::string value2 = Str16ToStr8(data.ReadString16()); + detailInfos.push_back(value2); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = + AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i3 = 0; i3 < bundleNamesSize; ++i3) { + std::string value3 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value3); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i4 = 0; i4 < bundleNamesSize; ++i4) { + std::string value4 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value4); + } + ErrCode errCode = AppendBundlesBackupSession(bundleNames); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i5 = 0; i5 < bundleNamesSize; ++i5) { + std::string value5 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value5); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i6 = 0; i6 < bundleInfosSize; ++i6) { + std::string value6 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value6); + } + ErrCode errCode = AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_FINISH: { + ErrCode errCode = Finish(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_RELEASE: { + ErrCode errCode = Release(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_CANCEL: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t cancelResult; + ErrCode errCode = Cancel(bundleName, cancelResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(cancelResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP: { + ErrCode errCode = GetAppLocalListAndDoIncrementalBackup(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetIncrementalFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_BACKUP_INFO: { + std::string bundleName; + std::string getBackupInfoResult; + ErrCode errCode = GetBackupInfo(bundleName, getBackupInfoResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteString16(Str8ToStr16(getBackupInfoResult))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_TIMER: { + std::string bundleName; + uint32_t timeout = data.ReadUint32(); + bool updateTimerResult; + ErrCode errCode = UpdateTimer(bundleName, timeout, updateTimerResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateTimerResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_SEND_RATE: { + std::string bundleName; + int32_t sendRate = data.ReadInt32(); + bool updateSendRateResult; + ErrCode errCode = UpdateSendRate(bundleName, sendRate, updateSendRateResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateSendRateResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_EXT_TIMER: { + bool isExtStart; + ErrCode errCode = StartExtTimer(isExtStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_FWK_TIMER: { + bool isFwkStart; + ErrCode errCode = StartFwkTimer(isFwkStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isFwkStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_STOP_EXT_TIMER: { + bool isExtStop; + ErrCode errCode = StopExtTimer(isExtStop); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStop ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i7 = 0; i7 < bundleNamesSize; ++i7) { + std::unique_ptr value7(data.ReadParcelable()); + if (!value7) { + return ERR_INVALID_DATA; + } + + bundleNames.push_back(*value7); + } + int fd; + ErrCode errCode = GetLocalCapabilitiesIncremental(bundleNames, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitIncrementalBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i8 = 0; i8 < bundlesToBackupSize; ++i8) { + std::unique_ptr value8(data.ReadParcelable()); + if (!value8) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value8); + } + ErrCode errCode = AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i9 = 0; i9 < bundlesToBackupSize; ++i9) { + std::unique_ptr value9(data.ReadParcelable()); + if (!value9) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value9); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i10 = 0; i10 < bundleInfosSize; ++i10) { + std::string value10 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value10); + } + ErrCode errCode = AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishIncrementalFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + int fd = data.ReadFileDescriptor(); + ErrCode errCode = PublishSAIncrementalFile(*fileInfo, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t appIncrementalFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalFileReady(fileName, fd, manifestFd, appIncrementalFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE: { + int32_t appIncrementalDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalDone(appIncrementalDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REPORT_APP_PROCESS_INFO: { + std::string processInfo = Str16ToStr8(data.ReadString16()); + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + ErrCode errCode = ReportAppProcessInfo(processInfo, scenario); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REFRESH_DATA_SIZE: { + int64_t totalDataSize = data.ReadInt64(); + ErrCode errCode = RefreshDataSize(totalDataSize); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_DONE: { + int32_t appDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppDone(appDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT: { + std::string restoreRetInfo; + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + int32_t serviceResultReportErrCode = data.ReadInt32(); + ErrCode errCode = ServiceResultReport(restoreRetInfo, scenario, serviceResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(restoreRetInfo))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t appFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppFileReady(fileName, fd, appFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ret = Cancel(bundleName, result); - reply.WriteInt32(result); - return ret; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); + return ERR_TRANSACTION_FAILED; } } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp index 2d46ff3ea..90b511001 100644 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" +#include "service_stub.h" #include "service_stub_mock.h" namespace OHOS::FileManagement::Backup { @@ -23,162 +23,246 @@ ServiceStub::ServiceStub() { } -void ServiceStub::ServiceStubSupplement() -{ -} - int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - return BServiceStub::stub->OnRemoteRequest(code, data, reply, option); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitBackupSession(data, reply); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStart(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilities(data, reply); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishFile(data, reply); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppFileReady(data, reply); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppDone(data, reply); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdResultReport(data, reply); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetFileHandle(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesBackupSession(data, reply); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdFinish(data, reply); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupInfo(data, reply); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateTimer(data, reply); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateSendRate(data, reply); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRelease(data, reply); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdCancel(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesIncremental(data, reply); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetAppLocalListAndDoIncrementalBackup(data, reply); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesIncrementalBackupSession(data, reply); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { + int32_t backupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t backupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { + int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { + int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t restoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t restoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { + int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { + int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { + int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { + int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, + incrementalRestoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { + int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; } -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishIncrementalFile(data, reply); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppIncrementalFileReady(data, reply); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStopExtTimer(data, reply); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRefreshDataSize(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesForBdInfos(data, reply); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupDataSize(data, reply); -} } // namespace OHOS::FileManagement::Backup 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 6c8b88f42..7f4bcf070 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -132,7 +132,7 @@ void SvcSessionManager::SetBundleUserId(const string &bundleName, const int32_t void SvcSessionManager::AppendBundles(const vector &, vector &) {} -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BSvcSessionManager::sessionManager->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 749be058a..06f5a6091 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -257,7 +257,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { GTEST_LOG_(INFO) << "CreateBackupConnection"; return GetBackupAbilityExt(bundleName); diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp index b7ac3a85e..f9e091a98 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp @@ -155,7 +155,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec BackupSvcSessionManager::session->AppendBundles(bundleNames, failedBundles); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BackupSvcSessionManager::session->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.h b/tests/mock/module_ipc/svc_session_manager_throw_mock.h index 455274faa..79306695a 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.h +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.h @@ -53,7 +53,7 @@ public: virtual void SetBackupExtName(const std::string &, const std::string &) = 0; virtual std::weak_ptr GetSAExtConnection(const BundleName &) = 0; virtual void AppendBundles(const std::vector &, std::vector &) = 0; - virtual sptr CreateBackupConnection(BundleName &) = 0; + virtual sptr CreateBackupConnection(const BundleName &) = 0; virtual ErrCode Start() = 0; virtual ErrCode Finish() = 0; virtual bool IsOnAllBundlesFinished() = 0; @@ -130,7 +130,7 @@ public: MOCK_METHOD(void, SetBackupExtName, (const std::string &, const std::string &)); MOCK_METHOD(std::weak_ptr, GetSAExtConnection, (const BundleName &)); MOCK_METHOD(void, AppendBundles, (const std::vector &, std::vector &)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName &)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName &)); MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, Finish, ()); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index c3fc260ee..852cbab80 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("b_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_session_backup_test.cpp", "b_session_restore_async_test.cpp", "b_session_restore_test.cpp", @@ -40,6 +41,7 @@ ohos_unittest("b_session_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", ] diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 1ef532c62..224b48652 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -53,7 +53,6 @@ ohos_unittest("backup_sa_impl_test") { sources = [ "${path_backup_mock}/system_ability_manager/service_registry_mock.cpp", "${path_backup_mock}/utils_mock/src/utils_mock_global_variable.cpp", - "service_proxy_test.cpp", "service_reverse_stub_test.cpp", "service_reverse_test.cpp", "svc_death_recipient_test.cpp", diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index d5371dae2..8694c8f4d 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -22,7 +22,7 @@ #include #include "b_error/b_error.h" -#include "i_service.h" +#include "iservice.h" #include "b_resources/b_constants.h" #include "iremote_stub.h" #include "test_manager.h" diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index cd066641e..a61dcc03b 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -19,7 +19,7 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp deleted file mode 100644 index ee2de7234..000000000 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ /dev/null @@ -1,1444 +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 -#include - -#include "b_file_info.h" -#include "i_service_mock.h" -#include "iremote_object_mock.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "service_reverse_mock.h" -#include "unique_fd.h" -#include "utils_mock_global_variable.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -constexpr int32_t SERVICE_ID = 5203; -} // namespace - -class ServiceProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override; - void TearDown() override; - - shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; - sptr remote_ = nullptr; -}; - -void ServiceProxyTest::SetUp() -{ - mock_ = sptr(new IServiceMock()); - proxy_ = make_shared(mock_); - remote_ = sptr(new ServiceReverseMock()); -} - -void ServiceProxyTest::TearDown() -{ - proxy_ = nullptr; - mock_ = nullptr; - remote_ = nullptr; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.desc: 测试 InitRestoreSession 注册restore Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.desc: 测试 InitRestoreSession 注册restore Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitBackupSession_0100 - * @tc.desc: 测试 InitBackupSession 注册backup Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitBackupSession_0200 - * @tc.desc: 测试 InitBackupSession 注册backup Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Start_0100 - * @tc.name: SUB_Service_proxy_Start_0100 - * @tc.desc: 测试 Start 启动备份恢复流程接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Start_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Start_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Start_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->Start(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->Start(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Start_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.desc: 测试 GetLocalCapabilities 获取能力文件接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilities_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilities_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - UniqueFd fd = proxy_->GetLocalCapabilities(); - EXPECT_GT(fd, BError(BError::Codes::OK)); - UniqueFd fdErr = proxy_->GetLocalCapabilities(); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilities_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishFile_0100 - * @tc.name: SUB_Service_proxy_PublishFile_0100 - * @tc.desc: 测试 PublishFile 推送接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->PublishFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppFileReady_0100 - * @tc.name: SUB_Service_proxy_AppFileReady_0100 - * @tc.desc: 测试 AppFileReady 文件就绪调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(3) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppFileReady(bundleName, move(fd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppFileReady(bundleName, move(fdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppFileReady(bundleName, UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppDone_0100 - * @tc.name: SUB_Service_proxy_AppDone_0100 - * @tc.desc: 测试 AppDone ext备份恢复流程结束调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.name: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.desc: 测试 ServiceResultReport - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ServiceResultReport_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ServiceResultReport_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ServiceResultReport_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string restoreRetInfo = "test_restoreRetInfo"; - BackupRestoreScenario scenario = FULL_BACKUP; - int32_t result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ServiceResultReport_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetFileHandle_0100 - * @tc.desc: 测试 GetFileHandle 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - std::vector detailInfos; - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0200 proxy_ == nullptr"; - return; - } - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.desc: 测试 AppendBundlesBackupSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - - int32_t result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.desc: 测试 AppendBundlesDetailsBackupSession - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector detailInfos; - - int32_t result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Finish_0100 - * @tc.name: SUB_Service_proxy_Finish_0100 - * @tc.desc: 测试 Finish 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Finish_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Finish_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Finish_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Finish(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Finish(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Finish_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Release_0100 - * @tc.name: SUB_Service_proxy_Release_0100 - * @tc.desc: 测试 Release 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Release_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Release_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Release_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Release(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Release(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Release_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.desc: 测试 GetLocalCapabilitiesIncremental 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - BIncrementalData data("com.example.app2backup", 0); - bundleNames.push_back(data); - UniqueFd fd = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_GT(fd, BError(BError::Codes::OK)); - - UniqueFd fdErr = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.desc: 测试 InitIncrementalBackupSession with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector infos; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.desc: 测试 PublishIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - fileName = "test"; - result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fd)); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fdErr)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0200 proxy_ == nullptr"; - return; - } - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - - ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, move(fd), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFdErr( - open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppIncrementalFileReady(bundleName, move(fdErr), move(manifestFdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Return(0)) - .WillOnce(Return(0)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_0200"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, move(fd), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0300"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0300 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0300"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.desc: 测试 AppIncrementalDone 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.desc: 测试 GetIncrementalFileHandle 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetIncrementalFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetIncrementalFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.desc: 测试 OnLoadSystemAbilityFail 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilityFail_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilityFail_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilityFail(SERVICE_ID); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetInstance_0100 - * @tc.name: SUB_Service_proxy_GetInstance_0100 - * @tc.desc: 测试 GetInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetInstance_0100 proxy_ == nullptr"; - return; - } - GTEST_LOG_(INFO) << "MockLoadSystemAbility is false"; - SetMockLoadSystemAbility(false); - auto proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "MockLoadSystemAbility is true"; - SetMockLoadSystemAbility(true); - proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - sptr object = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, object); - GTEST_LOG_(INFO) << "GetInstance is ok"; - proxy = ServiceProxy::GetInstance(); - EXPECT_NE(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InvaildInstance_0100 - * @tc.name: SUB_Service_proxy_InvaildInstance_0100 - * @tc.desc: 测试 InvaildInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InvaildInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InvaildInstance_0100 proxy_ == nullptr"; - return; - } - ServiceProxy::InvaildInstance(); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.name: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.desc: 测试 GetBackupInfo 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetBackupInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string result; - std::string bundleName = "com.example.app2backup"; - int32_t ret = proxy_->GetBackupInfo(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateTimer_0100 - * @tc.name: SUB_Service_proxy_UpdateTimer_0100 - * @tc.desc: 测试 UpdateTimer 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - uint32_t timeout = 30000; - int32_t ret = proxy_->UpdateTimer(bundleName, timeout, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.name: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.desc: 测试 UpdateSendRate 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateSendRate_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateSendRate_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - int32_t sendRate = 300; - int32_t ret = proxy_->UpdateSendRate(bundleName, sendRate, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.name: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.desc: 测试 ReportAppProcessInfo 接口成功 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.desc: 测试 ReportAppProcessInfo 接口失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_StartExtTimer_0100 - * @tc.name: SUB_Service_proxy_StartExtTimer_0100 - * @tc.desc: 测试 StartExtTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartExtTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartExtTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartExtTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isExtStart; - int32_t ret = proxy_->StartExtTimer(isExtStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartExtTimer(isExtStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartExtTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.name: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.desc: 测试 StartFwkTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartFwkTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartFwkTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartFwkTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isFwkStart; - int32_t ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartFwkTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Cancel_0100 - * @tc.name: SUB_Service_proxy_Cancel_0100 - * @tc.desc: 测试 Cancel 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Cancel_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Cancel_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Cancel_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string bundleName; - int result; - ErrCode ret = proxy_->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->Cancel(bundleName, result); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Cancel_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index 7c2284f6b..fb65b7d4f 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -23,7 +23,7 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "service_reverse_stub.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index aa8aa1317..b5bc0b2d5 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -25,11 +25,7 @@ ohos_unittest("ext_extension_test") { module_out_path = path_module_out_tests - sources = [ - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", - "ext_extension_test.cpp", - ] + sources = [ "ext_extension_test.cpp" ] include_dirs = [ "${path_backup}/frameworks/native/backup_ext/include", @@ -41,6 +37,7 @@ ohos_unittest("ext_extension_test") { ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", "//third_party/googletest:gtest_main", @@ -163,6 +160,7 @@ ohos_unittest("tar_file_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -240,6 +238,7 @@ ohos_unittest("untar_file_sup_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -314,6 +313,7 @@ ohos_unittest("untar_file_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -367,6 +367,7 @@ ohos_unittest("ext_backup_js_test") { ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", "${path_googletest}:gtest_main", diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 6685f522e..365428a5c 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -27,12 +27,10 @@ ohos_unittest("module_ipc_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_stub.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_backup_connection.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_reverse_proxy_test.cpp", - "service_stub_test.cpp", "svc_backup_connection_test.cpp", "svc_extension_proxy_test.cpp", ] @@ -49,6 +47,7 @@ ohos_unittest("module_ipc_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", @@ -114,6 +113,7 @@ ohos_unittest("backup_service_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -195,6 +195,7 @@ ohos_unittest("backup_service_throw_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -264,6 +265,7 @@ ohos_unittest("backup_service_session_test") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -317,6 +319,7 @@ ohos_unittest("backup_service_scheduler_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -381,6 +384,7 @@ ohos_unittest("backup_restore_deps_manager_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -414,14 +418,15 @@ ohos_unittest("backup_service_incremental_test") { "${path_backup_mock}/accesstoken/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", "${path_backup_mock}/module_sched/sched_scheduler_mock.cpp", "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_incremental_test.cpp", @@ -441,6 +446,7 @@ ohos_unittest("backup_service_incremental_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -475,11 +481,11 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/accesstoken/src/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/app_gallery_dispose_proxy_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/notify_work_service_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_restore_deps_manager_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", @@ -512,6 +518,7 @@ ohos_unittest("backup_service_other_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index fbbe9d945..18da1bbab 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -33,24 +33,23 @@ using namespace std; class BService { public: - virtual UniqueFd GetLocalCapabilities() = 0; + virtual ErrCode GetLocalCapabilities(int& fd) = 0; virtual ErrCode VerifyCallerAndGetCallerName(std::string&) = 0; - virtual ErrCode InitRestoreSession(sptr) = 0; - virtual ErrCode InitRestoreSession(sptr, std::string&) = 0; - virtual ErrCode InitBackupSession(sptr) = 0; - virtual ErrCode InitBackupSession(sptr, std::string&) = 0; + virtual ErrCode InitRestoreSession(const sptr&) = 0; + virtual ErrCode InitRestoreSessionWithErrMsg(const sptr&, std::string&) = 0; + virtual ErrCode InitBackupSession(const sptr&) = 0; + virtual ErrCode InitBackupSessionWithErrMsg(const sptr&, std::string&) = 0; virtual ErrCode Start() = 0; virtual ErrCode PublishFile(const BFileInfo&) = 0; - virtual ErrCode AppFileReady(const string&, UniqueFd, int32_t) = 0; + virtual ErrCode AppFileReady(const std::string &, int, int32_t) = 0; virtual ErrCode AppDone(ErrCode) = 0; virtual ErrCode ServiceResultReport(const std::string, BackupRestoreScenario, ErrCode) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd, const std::vector&, - const std::vector&, RestoreTypeEnum, int32_t) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd, const std::vector&, RestoreTypeEnum, - int32_t) = 0; + virtual ErrCode AppendBundlesRestoreSessionDataByDetail(int, const std::vector&, + const std::vector&, int32_t, int32_t) = 0; + virtual ErrCode AppendBundlesRestoreSessionData(int, const std::vector&, int32_t, int32_t) = 0; virtual ErrCode AppendBundlesBackupSession(const std::vector&) = 0; virtual ErrCode AppendBundlesDetailsBackupSession(const std::vector&, - const std::vector&) = 0; + const std::vector&) = 0; virtual ErrCode Finish() = 0; virtual ErrCode LaunchBackupExtension(const BundleName&) = 0; virtual ErrCode LaunchBackupSAExtension(const BundleName&) = 0; @@ -59,9 +58,9 @@ public: virtual ErrCode VerifyCaller() = 0; virtual ErrCode VerifyCaller(IServiceReverse::Scenario) = 0; virtual int32_t GetUserIdDefault() = 0; - virtual ErrCode GetBackupInfo(BundleName&, std::string&) = 0; - virtual ErrCode UpdateTimer(BundleName&, uint32_t, bool&) = 0; - virtual ErrCode UpdateSendRate(std::string&, int32_t, bool&) = 0; + virtual ErrCode GetBackupInfo(const BundleName&, std::string&) = 0; + virtual ErrCode UpdateTimer(const BundleName&, uint32_t, bool&) = 0; + virtual ErrCode UpdateSendRate(const std::string&, int32_t, bool&) = 0; virtual ErrCode ReportAppProcessInfo(const std::string, BackupRestoreScenario) = 0; virtual ErrCode StartExtTimer(bool&) = 0; virtual ErrCode StartFwkTimer(bool&) = 0; @@ -75,7 +74,7 @@ public: virtual ErrCode HandleCurBundleFileReady(const std::string&, const std::string&, bool) = 0; virtual ErrCode HandleCurAppDone(ErrCode, const std::string&, bool) = 0; virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; - virtual ErrCode GetBackupDataSize(bool, vector) = 0; + virtual ErrCode GetBackupDataSize(bool, const std::vector&) = 0; public: virtual bool UpdateToRestoreBundleMap(const string&, const string&) = 0; public: @@ -87,20 +86,20 @@ public: class ServiceMock : public BService { public: - MOCK_METHOD(UniqueFd, GetLocalCapabilities, ()); + MOCK_METHOD(ErrCode, GetLocalCapabilities, (int&)); MOCK_METHOD(ErrCode, VerifyCallerAndGetCallerName, (std::string&)); - MOCK_METHOD(ErrCode, InitRestoreSession, (sptr)); - MOCK_METHOD(ErrCode, InitRestoreSession, (sptr, std::string&)); - MOCK_METHOD(ErrCode, InitBackupSession, (sptr)); - MOCK_METHOD(ErrCode, InitBackupSession, ((sptr), std::string&)); + MOCK_METHOD(ErrCode, InitRestoreSession, (const sptr&)); + MOCK_METHOD(ErrCode, InitRestoreSessionWithErrMsg, (const sptr&, std::string&)); + MOCK_METHOD(ErrCode, InitBackupSession, (const sptr&)); + MOCK_METHOD(ErrCode, InitBackupSessionWithErrMsg, (const sptr&, std::string&)); MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, PublishFile, (const BFileInfo&)); - MOCK_METHOD(ErrCode, AppFileReady, (const string&, UniqueFd, int32_t)); + MOCK_METHOD(ErrCode, AppFileReady, (const string&, int, int32_t)); MOCK_METHOD(ErrCode, AppDone, (ErrCode)); MOCK_METHOD(ErrCode, ServiceResultReport, (const std::string, BackupRestoreScenario, ErrCode)); - MOCK_METHOD(ErrCode, AppendBundlesRestoreSession, (UniqueFd, (const std::vector&), - (const std::vector&), RestoreTypeEnum, int32_t)); - MOCK_METHOD(ErrCode, AppendBundlesRestoreSession, (UniqueFd, (const std::vector&), RestoreTypeEnum, + MOCK_METHOD(ErrCode, AppendBundlesRestoreSessionDataByDetail, (int, (const std::vector&), + (const std::vector&), int32_t, int32_t)); + MOCK_METHOD(ErrCode, AppendBundlesRestoreSessionData, (int, (const std::vector&), int32_t, int32_t)); MOCK_METHOD(ErrCode, AppendBundlesBackupSession, (const std::vector&)); MOCK_METHOD(ErrCode, AppendBundlesDetailsBackupSession, ((const std::vector&), @@ -113,9 +112,9 @@ public: MOCK_METHOD(ErrCode, VerifyCaller, ()); MOCK_METHOD(ErrCode, VerifyCaller, (IServiceReverse::Scenario)); MOCK_METHOD(int32_t, GetUserIdDefault, ()); - MOCK_METHOD(ErrCode, GetBackupInfo, (BundleName&, std::string&)); - MOCK_METHOD(ErrCode, UpdateTimer, (BundleName&, uint32_t, bool&)); - MOCK_METHOD(ErrCode, UpdateSendRate, (std::string&, int32_t, bool&)); + MOCK_METHOD(ErrCode, GetBackupInfo, (const BundleName&, std::string&)); + MOCK_METHOD(ErrCode, UpdateTimer, (const BundleName&, uint32_t, bool&)); + MOCK_METHOD(ErrCode, UpdateSendRate, (const std::string&, int32_t, bool&)); MOCK_METHOD(ErrCode, ReportAppProcessInfo, (const std::string, BackupRestoreScenario)); MOCK_METHOD(ErrCode, StartExtTimer, (bool&)); MOCK_METHOD(ErrCode, StartFwkTimer, (bool&)); @@ -129,7 +128,7 @@ public: MOCK_METHOD(ErrCode, HandleCurBundleFileReady, (const std::string&, const std::string&, bool)); MOCK_METHOD(ErrCode, HandleCurAppDone, (ErrCode, const std::string&, bool)); MOCK_METHOD(UniqueFd, GetLocalCapabilitiesForBundleInfos, ()); - MOCK_METHOD(ErrCode, GetBackupDataSize, (bool, vector)); + MOCK_METHOD(ErrCode, GetBackupDataSize, (bool, const std::vector&)); public: MOCK_METHOD(bool, UpdateToRestoreBundleMap, (const string&, const string&)); }; @@ -138,9 +137,18 @@ void Service::OnStart() {} void Service::OnStop() {} -UniqueFd Service::GetLocalCapabilities() +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return BService::serviceMock->GetLocalCapabilities(); + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::GetLocalCapabilities(int &fd) +{ + return BService::serviceMock->GetLocalCapabilities(fd); } void Service::StopAll(const wptr&, bool) {} @@ -150,26 +158,21 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) return BService::serviceMock->VerifyCallerAndGetCallerName(bundleName); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BService::serviceMock->InitRestoreSession(remote); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BService::serviceMock->InitRestoreSession(remote, errMsg); + return BService::serviceMock->InitRestoreSessionWithErrMsg(remote, errMsg); } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitBackupSession(const sptr &remote) { return BService::serviceMock->InitBackupSession(remote); } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) -{ - return BService::serviceMock->InitBackupSession(remote, errMsg); -} - ErrCode Service::Start() { return BService::serviceMock->Start(); @@ -180,31 +183,37 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BService::serviceMock->PublishFile(fileInfo); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { - return BService::serviceMock->AppFileReady(fileName, move(fd), errCode); + return BService::serviceMock->AppFileReady(fileName, fd, appFileReadyErrCode); } -ErrCode Service::AppDone(ErrCode errCode) +ErrCode Service::AppDone(int32_t appDoneErrCode) { - return BService::serviceMock->AppDone(errCode); + return BService::serviceMock->AppDone(appDoneErrCode); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, + BackupRestoreScenario sennario, ErrCode errCode) { return BService::serviceMock->ServiceResultReport(restoreRetInfo, sennario, errCode); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { - return BService::serviceMock->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos, restoreType, userId); + return BService::serviceMock->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { - return BService::serviceMock->AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); + return BService::serviceMock->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userId); } ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) @@ -213,7 +222,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BService::serviceMock->AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); } @@ -278,17 +287,17 @@ void Service::SendStartAppGalleryNotify(const BundleName&) {} void Service::SessionDeactive() {} -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BService::serviceMock->GetBackupInfo(bundleName, result); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeOut, bool &result) { return BService::serviceMock->UpdateTimer(bundleName, timeOut, result); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BService::serviceMock->UpdateSendRate(bundleName, sendRate, result); } @@ -303,7 +312,7 @@ void Service::SendEndAppGalleryNotify(const BundleName&) {} void Service::NoticeClientFinish(const string&, ErrCode) {} -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { return BService::serviceMock->ReportAppProcessInfo(processInfo, sennario); } @@ -418,9 +427,8 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() return BService::serviceMock->GetLocalCapabilitiesForBundleInfos(); } -void Service::AppendBundles(const std::vector&) {} - -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +void Service::AppendBundles(const std::vector &bundleNames) {} +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { return BService::serviceMock->GetBackupDataSize(isPreciseScan, bundleNameList); } @@ -516,7 +524,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncr try { auto session_ = service->session_; service->session_ = nullptr; - auto fd = service->GetLocalCapabilitiesIncremental({}); + int fd = -1; + service->GetLocalCapabilitiesIncremental({}, fd); service->session_ = session_; EXPECT_EQ(static_cast(fd), -ENOENT); @@ -741,7 +750,9 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes auto session_ = service->session_; service->session_ = nullptr; EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr srPrt = static_cast>(srProxy); + srPrt = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -749,7 +760,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); @@ -786,14 +797,15 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_InitIncrementalBackupSession_0100"; try { std::string errMsg; + sptr reverseNUll = nullptr; EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::SA_INVAL_ARG).GetCode()); auto session_ = service->session_; service->session_ = nullptr; EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; @@ -802,7 +814,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); @@ -813,7 +825,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*session, GetSessionCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, GetSessionActiveTime()).WillOnce(Return("")); EXPECT_CALL(*jsonUtil, BuildInitSessionErrInfo(_, _, _)).WillOnce(Return("")); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -821,7 +833,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -1045,14 +1057,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - auto ret = service->AppIncrementalFileReady(bundleName, fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(bundleName, fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; @@ -1061,7 +1073,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(bundleName, fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -1092,7 +1104,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*srvMock, HandleCurBundleFileReady(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); - auto ret = service->AppIncrementalFileReady(bundleName, fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; @@ -1102,7 +1114,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*srvMock, HandleCurBundleFileReady(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - ret = service->AppIncrementalFileReady(bundleName, fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(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 30ea8f00e..32be58d0b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -40,20 +40,38 @@ #include "sub_service.cpp" namespace OHOS::FileManagement::Backup { +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::Release() { return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector&) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } void Service::StartGetFdTask(std::string, wptr) {} @@ -63,12 +81,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr) +ErrCode Service::InitIncrementalBackupSession(const sptr &) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr, std::string &) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string &) { return BError(BError::Codes::OK); } @@ -123,8 +141,12 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode, const std::string&) {} void Service::SendUserIdToApp(string&, int32_t) {} -void Service::SetCurrentBackupSessProperties(const vector&, int32_t, - std::vector&, bool) {} +void Service::SetCurrentBackupSessProperties(const vector &, + int32_t, + std::vector &, + bool) +{ +} std::shared_ptr Service::GetExtensionMutex(const BundleName &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 c63b4b11f..e1e3c155b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -25,9 +25,9 @@ #include "b_error/b_error.h" #include "b_resources/b_constants.h" #include "ipc_types.h" -#include "i_service.h" +#include "iservice.h" #include "message_parcel_mock.h" -#include "module_ipc/service_stub.h" +#include "service_stub.h" #include "service_reverse_mock.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index ba99f49ff..77884fbf2 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -88,18 +88,20 @@ ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) EXPECT_TRUE(remote_ != nullptr); UniqueFd fd = servicePtr_->GetLocalCapabilities(); EXPECT_GE(fd, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitRestoreSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_, errMsg); + ret = servicePtr_->InitRestoreSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->Finish(); EXPECT_EQ(ret, BError(BError::Codes::OK)); } else if (scenario == IServiceReverse::Scenario::BACKUP) { - ret = servicePtr_->InitBackupSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitBackupSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitBackupSession(remote_, errMsg); + ret = servicePtr_->InitBackupSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesBackupSession(bundleNames); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -301,11 +303,11 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0100, testing::ext::TestSize.Leve try { string fileName = MANAGE_JSON; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppFileReady Branches"; fileName = "test"; - ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -329,7 +331,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0101, testing::ext::TestSize.Leve try { string fileName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -353,7 +355,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Leve try { string fileName = "manage.json"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 158372cd2..f712b7497 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -136,7 +136,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -147,7 +148,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -157,7 +158,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0100"; } @@ -180,7 +181,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -191,7 +193,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -202,7 +204,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -212,7 +214,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0200"; } @@ -234,7 +236,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -245,7 +248,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -255,7 +258,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0100"; } @@ -278,7 +281,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -289,7 +293,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -300,7 +304,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -310,7 +314,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0200"; } @@ -527,7 +531,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -540,7 +545,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -914,22 +919,23 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_010 throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); + int fd = -1; + ErrCode ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilitiesIncremental."; @@ -995,7 +1001,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1007,7 +1014,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1019,7 +1026,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0100"; } @@ -1042,7 +1049,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1054,7 +1062,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1066,7 +1074,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1078,7 +1086,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0200"; } @@ -1138,14 +1146,14 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSessi throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + auto ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, EPERM); } catch (...) { EXPECT_TRUE(false); @@ -1207,7 +1215,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -1220,7 +1229,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index 46b847da7..c7a2500c0 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -20,6 +20,13 @@ ohos_unittest("b_incremental_session_test") { 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", + ".", + "session", ] sources = [ @@ -31,16 +38,26 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "b_incremental_session_test.cpp", + "service_client_mock.cpp", "service_proxy_mock.cpp", ] deps = [ + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + defines = [ "LOG_TAG=\"app_file_service\"", "LOG_DOMAIN=0xD200000", diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index e074a00e0..f059a92a8 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -20,6 +20,7 @@ #include "b_incremental_restore_session.h" #include "b_incremental_session_restore_async.h" #include "service_proxy_mock.h" +#include "service_client.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -45,7 +46,7 @@ void IncrementalSessionTest::SetUpTestCase() restoreSession = make_shared(); BIncrementalSessionRestoreAsync::Callbacks callbacks; restoreAsyncSession = make_shared(callbacks); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; } void IncrementalSessionTest::TearDownTestCase() @@ -53,7 +54,7 @@ void IncrementalSessionTest::TearDownTestCase() backupSession = nullptr; restoreSession = nullptr; restoreAsyncSession = nullptr; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; proxy = nullptr; } @@ -70,14 +71,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitIncrementalBackupSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks); @@ -103,11 +104,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); backupSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; backupSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -132,14 +133,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -162,13 +163,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -191,14 +192,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks); @@ -224,11 +225,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); restoreSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -253,16 +254,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -285,13 +286,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -314,14 +315,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,7 +346,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreSession != nullptr); @@ -353,7 +354,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -376,7 +377,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -384,8 +385,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -408,14 +409,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalSessionRestoreAsync::Callbacks callbacks; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreAsyncSession->Init(callbacks); @@ -441,11 +442,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); restoreAsyncSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreAsyncSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -470,16 +471,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -502,14 +503,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -533,7 +534,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreAsyncSession != nullptr); @@ -541,7 +542,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -564,7 +565,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -572,8 +573,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -596,13 +597,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -625,15 +626,15 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; vector infos; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSessionWithBundleInfos(_, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -656,7 +657,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; UniqueFd fd; EXPECT_TRUE(restoreSession != nullptr); @@ -664,7 +665,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishSAIncrementalFile(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishSAFile(fileInfo, move(fd)); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -687,14 +688,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -717,14 +718,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -747,14 +748,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -779,14 +780,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2400, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks, errMsg, errCode); @@ -813,14 +814,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2500, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitRestoreSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitRestoreSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks, errMsg, errCode); @@ -845,17 +846,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { @@ -878,17 +880,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp new file mode 100644 index 000000000..cf075fbd2 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -0,0 +1,51 @@ +/* + * 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 "service_client.h" +#include "iservice.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() {} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h new file mode 100644 index 000000000..6aa6d9884 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H +#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + +#include + +#include "service_client.h" + +namespace OHOS::FileManagement::Backup { +class ServiceClientMock : public ServiceClient { + +public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); +}; +} // End of namespace OHOS::FileManagement::Backup +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 41cce333d..0ed3fb8bf 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -16,225 +16,223 @@ #include "service_proxy.h" #include "b_error/b_error.h" - +#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +ErrCode ServiceProxy::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { - return 0; -} - -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote) +ErrCode ServiceProxy::AppDone(int32_t appDoneErrCode) { - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - return 0; -} - -ErrCode ServiceProxy::Start() +ErrCode ServiceProxy::RefreshDataSize(int64_t totalDataSize) { return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::AppIncrementalDone(int32_t appIncrementalDoneErrCode) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppDone(ErrCode errCode) +ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) +int32_t ServiceProxy::InitRestoreSession(const sptr &remote) { - return BError(BError::Codes::OK); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::Start() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Finish() +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &cancelResult) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Release() +ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario scenario) { - result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +int32_t ServiceProxy::InitBackupSession(const sptr &remote) { - return UniqueFd(-1); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() +ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, + BackupRestoreScenario scenario, + int32_t serviceResultReportErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &detailInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) +ErrCode ServiceProxy::Finish() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) +ErrCode ServiceProxy::Release() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) +ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::RefreshDataSize(int64_t totalsize) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) { - return serviceProxy_; + return BError(BError::Codes::OK); } -sptr ServiceProxy::GetInstance() +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { - return serviceProxy_; + return BError(BError::Codes::OK); } -void ServiceProxy::InvaildInstance() {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t, const OHOS::sptr&) {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + fd = -1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index b734c8dac..85a4e056e 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -26,48 +26,49 @@ public: explicit ServiceProxyMock(const sptr &impl) : ServiceProxy(impl) {} ~ServiceProxyMock() override {} public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(AsObject, sptr()); - MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); - MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); + MOCK_METHOD1(GetLocalCapabilitiesForBundleInfos, ErrCode(int32_t &)); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd)); - MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd, int32_t errCode)); - MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, int fd)); + MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, int fd, int32_t errCode)); + MOCK_METHOD1(AppDone, ErrCode(int32_t errCode)); + MOCK_METHOD2(GetFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - 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)); + MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); - MOCK_METHOD2(Cancel, ErrCode(std::string bundleName, int32_t &result)); - MOCK_METHOD1(GetLocalCapabilitiesIncremental, UniqueFd(const std::vector &bundleNames)); - MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD2(Cancel, ErrCode(const std::string &bundleName, int32_t &result)); + MOCK_METHOD2(GetLocalCapabilitiesIncremental, ErrCode(const std::vector &bundleNames, int &fd)); + MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitIncrementalBackupSessionWithErrMsg, + ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); - MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + MOCK_METHOD2(AppendBundlesIncrementalBackupSessionWithBundleInfos, + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); - MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); + MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, int fd)); + MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD1(AppIncrementalDone, ErrCode(int32_t errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD2(GetBackupInfo, ErrCode(BundleName &bundleName, std::string &result)); - MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); + MOCK_METHOD2(GetBackupInfo, ErrCode(const BundleName &bundleName, std::string &result)); + MOCK_METHOD3(UpdateTimer, ErrCode(const BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD0(GetAppLocalListAndDoIncrementalBackup, ErrCode()); MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); - MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, std::vector bundleNameList)); + MOCK_METHOD5( + AppendBundlesRestoreSessionDataByDetail, + ErrCode(int32_t, const std::vector &, const std::vector &, int32_t, int32_t)); + MOCK_METHOD4(AppendBundlesRestoreSessionData, + ErrCode(int32_t, const std::vector &, int32_t, int32_t)); + MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 0a0c1d50a..5703e4271 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -50,6 +50,8 @@ ohos_unittest("backup_tool_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -112,6 +114,8 @@ ohos_unittest("backup_tool_restore_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 745fe725e..f11c1c08b 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -39,7 +39,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_backup.h" @@ -240,12 +240,13 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; } - BFile::SendFile(fdLocal, proxy->GetLocalCapabilities()); + int fd = -1; + BFile::SendFile(fdLocal, proxy->GetLocalCapabilities(fd)); auto ctx = make_shared(); ctx->session_ = BSessionBackup::Init( diff --git a/tools/backup_tool/src/tools_op_check_sa.cpp b/tools/backup_tool/src/tools_op_check_sa.cpp index 5e781f316..a2173be23 100644 --- a/tools/backup_tool/src/tools_op_check_sa.cpp +++ b/tools/backup_tool/src/tools_op_check_sa.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -17,7 +17,7 @@ #include #include "errors.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_check_sa.h" @@ -31,7 +31,7 @@ static string GenHelpMsg() static int Exec(map> &mapArgToVal) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EFAULT; diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 41a97190c..b62616d02 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -42,7 +42,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" namespace OHOS::FileManagement::Backup { @@ -273,7 +273,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; @@ -286,11 +286,13 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, ctx->lastIncrementalData.push_back(data); num++; } - UniqueFd fd = proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData); + int fdVal = -1; + proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); + UniqueFd fd(fdVal); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { - BFile::SendFile(fdLocal, fd); + BFile::SendFile(fdLocal, std::move(fd)); } return 0; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 95b58a5ad..6a6928383 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -84,7 +84,10 @@ ohos_shared_library("backup_utils") { "src/b_utils/b_time.cpp", ] - configs = [ ":utils_private_config" ] + configs = [ + ":utils_private_config", + "${path_backup}/services/backup_sa:public_idl_config", + ] public_configs = [ ":utils_public_config" ] external_deps = [ @@ -110,6 +113,7 @@ ohos_shared_library("backup_utils") { deps = [ ":backup_cxx_cppdeps", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/services/backup_sa:backup_sa_ipc_type", "${path_jsoncpp}:jsoncpp", "//third_party/openssl:libcrypto_shared", ] diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 16d4a17f4..6b17d9851 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_B_RADAR_H #include #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { enum class BizStageBackup : int32_t { diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 1c7f7ac84..d25a28d29 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -23,7 +23,7 @@ #include "b_resources/b_constants.h" #include "b_utils/b_time.h" #include "hisysevent.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { int32_t AppRadar::GetUserId() -- Gitee From 85b8a3f459b3d283bccec21242b92070cd046041 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 28 Feb 2025 15:22:13 +0800 Subject: [PATCH 03/21] Fixed code check. Signed-off-by: BrainL Change-Id: I1688d4dc48c96d968f76b47c2262011624dc5a5d --- .../backup_kit_inner/impl/b_file_info.h | 6 +- .../impl/b_incremental_data.h | 7 +- .../backup_kit_inner/impl/backup_file_info.h | 6 +- .../impl/backup_incremental_data.h | 6 +- .../backup_sa/include/module_ipc/service.h | 2 - .../mock/module_ipc/src/service_stub_mock.cpp | 268 ------------------ .../module_ipc/service_incremental_test.cpp | 7 +- 7 files changed, 21 insertions(+), 281 deletions(-) delete mode 100644 tests/mock/module_ipc/src/service_stub_mock.cpp diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h index b7c3b759a..339f9025c 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h @@ -13,6 +13,10 @@ * limitations under the License. */ +#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H + #include "backup_file_info.h" -namespace OHOS::FileManagement::Backup {}; \ No newline at end of file +namespace OHOS::FileManagement::Backup {}; // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h index 95a3bf248..f3642bb37 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h @@ -12,6 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H + #include "backup_incremental_data.h" -namespace OHOS::FileManagement::Backup {} \ No newline at end of file +namespace OHOS::FileManagement::Backup {} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h index d00e16502..16f9f7ea7 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H -#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#ifndef OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H #include #include @@ -41,4 +41,4 @@ struct BFileInfo : public Parcelable { }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#endif // OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h index 77785e18b..1704a3fda 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H -#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#ifndef OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H #include #include @@ -44,4 +44,4 @@ struct BIncrementalData : public Parcelable { }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#endif // OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 075f0b640..22ebc6944 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -93,8 +93,6 @@ public: ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( const std::vector& bundlesToBackup, const std::vector& bundleInfos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; ErrCode PublishSAIncrementalFile( const BFileInfo& fileInfo, diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp deleted file mode 100644 index 90b511001..000000000 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ /dev/null @@ -1,268 +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. - */ - -#include "service_stub.h" -#include "service_stub_mock.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ServiceStub::ServiceStub() -{ -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - std::u16string localDescriptor = GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (localDescriptor != remoteDescriptor) { - return ERR_TRANSACTION_FAILED; - } - switch (static_cast(code)) { - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { - int32_t backupOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int32_t backupOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnResultReport(myResult, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { - int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { - int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { - int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int32_t restoreOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - int32_t restoreOnResultReportErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { - int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { - int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { - int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int manifestFd = data.ReadFileDescriptor(); - int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = - IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { - int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { - int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { - int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int manifestFd = data.ReadFileDescriptor(); - int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, - incrementalRestoreOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); - ErrCode errCode = - IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { - int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { - int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return ERR_TRANSACTION_FAILED; -} - -} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 18da1bbab..29d59f3ad 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -205,7 +205,8 @@ ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, int32_t restoreType, int32_t userId) { - return BService::serviceMock->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); + return BService::serviceMock->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, + restoreType, userId); } ErrCode Service::AppendBundlesRestoreSessionData(int fd, @@ -814,8 +815,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::OK).GetCode()); - + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); -- Gitee From 878f8d8011f2637eb1f5b970c9ea0b735789a0ba Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 28 Feb 2025 15:41:49 +0800 Subject: [PATCH 04/21] fix code check. Signed-off-by: BrainL --- .../backup_kit_inner/impl/b_file_info.h | 6 +- .../impl/b_incremental_data.h | 7 +- .../backup_kit_inner/impl/backup_file_info.h | 6 +- .../impl/backup_incremental_data.h | 6 +- .../backup_sa/include/module_ipc/service.h | 2 - .../mock/module_ipc/src/service_stub_mock.cpp | 268 ------------------ .../module_ipc/service_incremental_test.cpp | 7 +- 7 files changed, 21 insertions(+), 281 deletions(-) delete mode 100644 tests/mock/module_ipc/src/service_stub_mock.cpp diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h index b7c3b759a..f82e057d6 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h @@ -13,6 +13,10 @@ * limitations under the License. */ +#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H + #include "backup_file_info.h" -namespace OHOS::FileManagement::Backup {}; \ No newline at end of file +namespace OHOS::FileManagement::Backup {}; // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h index 95a3bf248..48253bd46 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h @@ -12,6 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H + #include "backup_incremental_data.h" -namespace OHOS::FileManagement::Backup {} \ No newline at end of file +namespace OHOS::FileManagement::Backup {} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h index d00e16502..16f9f7ea7 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H -#define OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#ifndef OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H +#define OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H #include #include @@ -41,4 +41,4 @@ struct BFileInfo : public Parcelable { }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_FILE_INFO_H +#endif // OHOS_FILEMGMT_BACKUP_BACKUP_FILE_INFO_H diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h index 77785e18b..1704a3fda 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H -#define OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#ifndef OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H +#define OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H #include #include @@ -44,4 +44,4 @@ struct BIncrementalData : public Parcelable { }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_INCREMENTAL_DATA_H +#endif // OHOS_FILEMGMT_BACKUP_BACKUP_INCREMENTAL_DATA_H diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 075f0b640..22ebc6944 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -93,8 +93,6 @@ public: ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( const std::vector& bundlesToBackup, const std::vector& bundleInfos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; ErrCode PublishSAIncrementalFile( const BFileInfo& fileInfo, diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp deleted file mode 100644 index 90b511001..000000000 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ /dev/null @@ -1,268 +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. - */ - -#include "service_stub.h" -#include "service_stub_mock.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ServiceStub::ServiceStub() -{ -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - std::u16string localDescriptor = GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (localDescriptor != remoteDescriptor) { - return ERR_TRANSACTION_FAILED; - } - switch (static_cast(code)) { - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { - int32_t backupOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int32_t backupOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnResultReport(myResult, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { - int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { - int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { - int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int32_t restoreOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - int32_t restoreOnResultReportErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { - int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { - int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { - int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int manifestFd = data.ReadFileDescriptor(); - int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = - IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { - int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { - int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { - int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int manifestFd = data.ReadFileDescriptor(); - int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, - incrementalRestoreOnFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { - std::string myResult = Str16ToStr8(data.ReadString16()); - std::string bundleName = Str16ToStr8(data.ReadString16()); - int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); - ErrCode errCode = - IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { - int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { - int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); - ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string processInfo = Str16ToStr8(data.ReadString16()); - ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return ERR_TRANSACTION_FAILED; -} - -} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 18da1bbab..29d59f3ad 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -205,7 +205,8 @@ ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, int32_t restoreType, int32_t userId) { - return BService::serviceMock->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); + return BService::serviceMock->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, + restoreType, userId); } ErrCode Service::AppendBundlesRestoreSessionData(int fd, @@ -814,8 +815,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetCallerName()).WillOnce(Return("")); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), BError(BError::Codes::OK).GetCode()); - + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*srvMock, VerifyCaller()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*srvMock, GetUserIdDefault()).WillOnce(Return(0)); -- Gitee From c05fcd611521521abc20ebe00cfbb53e0a4f8ec8 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 1 Mar 2025 11:53:25 +0800 Subject: [PATCH 05/21] Fixed the error of unit test. Signed-off-by: BrainL Change-Id: I7187a82b7ee8a0660bf5448a4f6969ab86216a72 --- .../module_ipc/service_incremental_test.cpp | 16 +++++++++++++--- .../backup_sa/session/service_client_mock.cpp | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 29d59f3ad..f33f33ef9 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -1055,26 +1055,32 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ string bundleName; string fileName; int32_t errCode = 0; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); + auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); + ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); + ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -1099,6 +1105,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ string bundleName; string fileName; int32_t errCode = 0; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); @@ -1109,6 +1117,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp index cf075fbd2..a7c450c2a 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.cpp +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -17,6 +17,7 @@ #include "service_client.h" #include "iservice.h" #include "service_proxy.h" +#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -37,6 +38,9 @@ sptr ServiceClient::GetServiceProxyPointer() sptr ServiceClient::GetInstance() { + if (!GetMockGetInstance()) { + return nullptr; + } return serviceProxy_; } -- Gitee From 7f2573bcd871112414b55c09e6ef069ec4f565ea Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 13:49:53 +0800 Subject: [PATCH 06/21] Fixed the unit test. Signed-off-by: BrainL Change-Id: I1af68430d6e000092a4e7a1da750de41405c335b --- .../unittests/backup_sa/module_ipc/service_incremental_test.cpp | 2 +- tests/unittests/backup_tools/BUILD.gn | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index f33f33ef9..3cb7407dd 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -1056,7 +1056,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ string fileName; int32_t errCode = 0; EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) - .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 5703e4271..7cc90eda8 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -27,6 +27,7 @@ ohos_unittest("backup_tool_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_backup_mock.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", "${path_backup}/tools/backup_tool/src/tools_op_backup.cpp", "${path_backup}/tools/backup_tool/src/tools_op_check_sa.cpp", -- Gitee From 5da7601f7e517dad2079f9675e76afcbec7a23af Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 14:24:56 +0800 Subject: [PATCH 07/21] Fixed the unit test. Signed-off-by: BrainL Change-Id: If82bd35985baf10a9181d1a9bf2e592f55758906 --- tests/unittests/backup_sa/session/service_client_mock.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp index a7c450c2a..cf075fbd2 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.cpp +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -17,7 +17,6 @@ #include "service_client.h" #include "iservice.h" #include "service_proxy.h" -#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -38,9 +37,6 @@ sptr ServiceClient::GetServiceProxyPointer() sptr ServiceClient::GetInstance() { - if (!GetMockGetInstance()) { - return nullptr; - } return serviceProxy_; } -- Gitee From 24fb80ec732b96f988bbd81979f0730976e6f315 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 4 Mar 2025 17:10:00 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B6=85=E5=A4=A7?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- services/backup_sa/src/module_ipc/service.cpp | 1 - .../src/module_ipc/service_incremental.cpp | 7 +- tests/mock/module_ipc/service_stub_mock.cpp | 504 +----------------- 3 files changed, 4 insertions(+), 508 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b4ce9a773..ad4b6ac37 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1800,7 +1800,6 @@ ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, boo ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { - HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); if (session_ == nullptr || isOccupyingSession_.load()) { HILOGE("Update Send Rate error, session is empty."); result = false; diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 9f757a668..772fe2da2 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -220,11 +220,8 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); - string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()) - .append(bundleName) - .append("/") - .append(BConstants::BACKUP_STAT_SYMBOL) - .append(to_string(lastTime)); + string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). + append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { HILOGD("fdLocal open fail, error = %{public}d", errno); diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 4d91c7c4d..4cf3e930a 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -24,508 +24,8 @@ int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (static_cast(code)) { - case IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION: { - sptr reverseIpcRemoteObject; - ErrCode errCode = InitRestoreSession(reverseIpcRemoteObject); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (reverseIpcRemoteObject == nullptr) { - return ERR_INVALID_DATA; - } - if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION: { - sptr reverseIpcRemoteObject; - ErrCode errCode = InitBackupSession(reverseIpcRemoteObject); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (reverseIpcRemoteObject == nullptr) { - return ERR_INVALID_DATA; - } - if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_START: { - ErrCode errCode = Start(); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES: { - int fd; - ErrCode errCode = GetLocalCapabilities(fd); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(fd)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_PUBLISH_FILE: { - std::unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return ERR_INVALID_DATA; - } - - ErrCode errCode = PublishFile(*fileInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_FILE_HANDLE: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = GetFileHandle(bundleName, fileName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL: { - int fd = data.ReadFileDescriptor(); - std::vector bundleNames; - int32_t bundleNamesSize = data.ReadInt32(); - if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i1 = 0; i1 < bundleNamesSize; ++i1) { - std::string value1 = Str16ToStr8(data.ReadString16()); - bundleNames.push_back(value1); - } - std::vector detailInfos; - int32_t detailInfosSize = data.ReadInt32(); - if (detailInfosSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i2 = 0; i2 < detailInfosSize; ++i2) { - std::string value2 = Str16ToStr8(data.ReadString16()); - detailInfos.push_back(value2); - } - int32_t restoreType = data.ReadInt32(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = - AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA: { - int fd = data.ReadFileDescriptor(); - std::vector bundleNames; - int32_t bundleNamesSize = data.ReadInt32(); - if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i3 = 0; i3 < bundleNamesSize; ++i3) { - std::string value3 = Str16ToStr8(data.ReadString16()); - bundleNames.push_back(value3); - } - int32_t restoreType = data.ReadInt32(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userId); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION: { - std::vector bundleNames; - int32_t bundleNamesSize = data.ReadInt32(); - if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i4 = 0; i4 < bundleNamesSize; ++i4) { - std::string value4 = Str16ToStr8(data.ReadString16()); - bundleNames.push_back(value4); - } - ErrCode errCode = AppendBundlesBackupSession(bundleNames); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION: { - std::vector bundleNames; - int32_t bundleNamesSize = data.ReadInt32(); - if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i5 = 0; i5 < bundleNamesSize; ++i5) { - std::string value5 = Str16ToStr8(data.ReadString16()); - bundleNames.push_back(value5); - } - std::vector bundleInfos; - int32_t bundleInfosSize = data.ReadInt32(); - if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i6 = 0; i6 < bundleInfosSize; ++i6) { - std::string value6 = Str16ToStr8(data.ReadString16()); - bundleInfos.push_back(value6); - } - ErrCode errCode = AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_FINISH: { - ErrCode errCode = Finish(); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_RELEASE: { - ErrCode errCode = Release(); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_CANCEL: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - int32_t cancelResult; - ErrCode errCode = Cancel(bundleName, cancelResult); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(cancelResult)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP: { - ErrCode errCode = GetAppLocalListAndDoIncrementalBackup(); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - std::string fileName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = GetIncrementalFileHandle(bundleName, fileName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_BACKUP_INFO: { - std::string bundleName; - std::string getBackupInfoResult; - ErrCode errCode = GetBackupInfo(bundleName, getBackupInfoResult); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteString16(Str8ToStr16(bundleName))) { - return ERR_INVALID_DATA; - } - if (!reply.WriteString16(Str8ToStr16(getBackupInfoResult))) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_UPDATE_TIMER: { - std::string bundleName; - uint32_t timeout = data.ReadUint32(); - bool updateTimerResult; - ErrCode errCode = UpdateTimer(bundleName, timeout, updateTimerResult); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteString16(Str8ToStr16(bundleName))) { - return ERR_INVALID_DATA; - } - if (!reply.WriteInt32(updateTimerResult ? 1 : 0)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_UPDATE_SEND_RATE: { - std::string bundleName; - int32_t sendRate = data.ReadInt32(); - bool updateSendRateResult; - ErrCode errCode = UpdateSendRate(bundleName, sendRate, updateSendRateResult); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteString16(Str8ToStr16(bundleName))) { - return ERR_INVALID_DATA; - } - if (!reply.WriteInt32(updateSendRateResult ? 1 : 0)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_START_EXT_TIMER: { - bool isExtStart; - ErrCode errCode = StartExtTimer(isExtStart); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(isExtStart ? 1 : 0)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_START_FWK_TIMER: { - bool isFwkStart; - ErrCode errCode = StartFwkTimer(isFwkStart); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(isFwkStart ? 1 : 0)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_STOP_EXT_TIMER: { - bool isExtStop; - ErrCode errCode = StopExtTimer(isExtStop); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(isExtStop ? 1 : 0)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL: { - std::vector bundleNames; - int32_t bundleNamesSize = data.ReadInt32(); - if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i7 = 0; i7 < bundleNamesSize; ++i7) { - std::unique_ptr value7(data.ReadParcelable()); - if (!value7) { - return ERR_INVALID_DATA; - } - - bundleNames.push_back(*value7); - } - int fd; - ErrCode errCode = GetLocalCapabilitiesIncremental(bundleNames, fd); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteInt32(fd)) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION: { - sptr reverseIpcRemoteObject; - ErrCode errCode = InitIncrementalBackupSession(reverseIpcRemoteObject); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (reverseIpcRemoteObject == nullptr) { - return ERR_INVALID_DATA; - } - if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION: { - std::vector bundlesToBackup; - int32_t bundlesToBackupSize = data.ReadInt32(); - if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i8 = 0; i8 < bundlesToBackupSize; ++i8) { - std::unique_ptr value8(data.ReadParcelable()); - if (!value8) { - return ERR_INVALID_DATA; - } - - bundlesToBackup.push_back(*value8); - } - ErrCode errCode = AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS: { - std::vector bundlesToBackup; - int32_t bundlesToBackupSize = data.ReadInt32(); - if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i9 = 0; i9 < bundlesToBackupSize; ++i9) { - std::unique_ptr value9(data.ReadParcelable()); - if (!value9) { - return ERR_INVALID_DATA; - } - - bundlesToBackup.push_back(*value9); - } - std::vector bundleInfos; - int32_t bundleInfosSize = data.ReadInt32(); - if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { - return ERR_INVALID_DATA; - } - for (int32_t i10 = 0; i10 < bundleInfosSize; ++i10) { - std::string value10 = Str16ToStr8(data.ReadString16()); - bundleInfos.push_back(value10); - } - ErrCode errCode = AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, bundleInfos); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE: { - std::unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return ERR_INVALID_DATA; - } - - ErrCode errCode = PublishIncrementalFile(*fileInfo); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE: { - std::unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return ERR_INVALID_DATA; - } - - int fd = data.ReadFileDescriptor(); - ErrCode errCode = PublishSAIncrementalFile(*fileInfo, fd); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY: { - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int manifestFd = data.ReadFileDescriptor(); - int32_t appIncrementalFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = AppIncrementalFileReady(fileName, fd, manifestFd, appIncrementalFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE: { - int32_t appIncrementalDoneErrCode = data.ReadInt32(); - ErrCode errCode = AppIncrementalDone(appIncrementalDoneErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_REPORT_APP_PROCESS_INFO: { - std::string processInfo = Str16ToStr8(data.ReadString16()); - BackupRestoreScenario scenario; - { - uint64_t enumTmp = 0; - if (!data.ReadUint64(enumTmp)) { - return ERR_INVALID_DATA; - } - scenario = static_cast(enumTmp); - } - ErrCode errCode = ReportAppProcessInfo(processInfo, scenario); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_REFRESH_DATA_SIZE: { - int64_t totalDataSize = data.ReadInt64(); - ErrCode errCode = RefreshDataSize(totalDataSize); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APP_DONE: { - int32_t appDoneErrCode = data.ReadInt32(); - ErrCode errCode = AppDone(appDoneErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT: { - std::string restoreRetInfo; - BackupRestoreScenario scenario; - { - uint64_t enumTmp = 0; - if (!data.ReadUint64(enumTmp)) { - return ERR_INVALID_DATA; - } - scenario = static_cast(enumTmp); - } - int32_t serviceResultReportErrCode = data.ReadInt32(); - ErrCode errCode = ServiceResultReport(restoreRetInfo, scenario, serviceResultReportErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - if (SUCCEEDED(errCode)) { - if (!reply.WriteString16(Str8ToStr16(restoreRetInfo))) { - return ERR_INVALID_DATA; - } - } - return ERR_NONE; - } - case IServiceIpcCode::COMMAND_APP_FILE_READY: { - std::string fileName = Str16ToStr8(data.ReadString16()); - int fd = data.ReadFileDescriptor(); - int32_t appFileReadyErrCode = data.ReadInt32(); - ErrCode errCode = AppFileReady(fileName, fd, appFileReadyErrCode); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + else { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - - return ERR_TRANSACTION_FAILED; } } // namespace OHOS::FileManagement::Backup -- Gitee From 31a2ce19cca170b3d8bb501bda8391b71552e8ec Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 4 Mar 2025 17:43:26 +0800 Subject: [PATCH 09/21] fix code check Signed-off-by: BrainL --- tests/mock/module_ipc/service_stub_mock.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 4cf3e930a..c6c2462ea 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -23,8 +23,7 @@ int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; - } - else { + } else { return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } -- Gitee From 8f6e4ccdcc7d7e606420232fef59a39aacc32f65 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 12 Mar 2025 18:04:22 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E5=A4=96=E9=83=A8=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- interfaces/inner_api/native/backup_kit_inner/BUILD.gn | 5 ++++- .../backup_sa/session/b_incremental_session_test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 096d8feef..699a965c0 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -64,7 +64,10 @@ ohos_shared_library("backup_kit_inner") { ] configs = [ ":private_config" ] - public_configs = [ ":public_config" ] + public_configs = [ + ":public_config", + "${path_backup}/services/backup_sa:public_idl_config", + ] external_deps = [ "c_utils:utils", diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index 2798824fe..cd176ce50 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -916,12 +916,12 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2800, testing::e try { bool isPreciseScan = false; vector bundleNameList; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; ASSERT_TRUE(backupSession != nullptr); auto err = backupSession->GetBackupDataSize(isPreciseScan, bundleNameList); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; EXPECT_CALL(*proxy, GetBackupDataSize(_, _)).WillOnce(Return(BError(BError::Codes::SDK_BROKEN_IPC).GetCode())); err = backupSession->GetBackupDataSize(isPreciseScan, bundleNameList); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); -- Gitee From 4b004aac2f1b40ec3652f6c82bc8c8c9d012203b Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 14 Mar 2025 11:18:39 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9FUZZ=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../backup_sa/include/module_ipc/service.h | 3 +- .../backupservicestub_fuzzer.cpp | 624 ++++++++++++ .../backupservicestubbranch_fuzzer/BUILD.gn | 1 - .../backupservicestubbranch_fuzzer.cpp | 920 +++++++++++++++++- .../backupservicestubbranch_fuzzer/service.h | 88 ++ .../module_ipc/service_other_test.cpp | 33 + .../module_ipc/service_reverse_proxy_test.cpp | 159 +++ .../backup_sa/module_ipc/service_test.cpp | 293 ++++++ .../module_ipc/svc_session_manager_test.cpp | 95 ++ .../b_jsonutil/b_jsonutil_other_test.cpp | 100 ++ 10 files changed, 2311 insertions(+), 5 deletions(-) create mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 22ebc6944..6838d64ef 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -103,7 +103,6 @@ public: int fd, int manifestFd, int32_t appIncrementalFileReadyErrCode) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; @@ -670,6 +669,8 @@ private: ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); + ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); + ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, const std::vector &bundleInfos, diff --git a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp index 1d0c74cc6..6172e19b2 100644 --- a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp +++ b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp @@ -72,6 +72,604 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } + +bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION); + + try { + BSessionRestore::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION); + + try { + BSessionBackup::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_START); + + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); + + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE); + + try { + int pos = 0; + BFileInfo info; + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + msg.WriteParcelable(&info); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + bool fdFlag = TypeCast(data + pos, &pos); + msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteBool(fdFlag); + if (fdFlag) { + msg.WriteFileDescriptor(fd); + } + msg.WriteInt32(errCode); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_DONE); + + try { + int32_t errCode = TypeCast(data); + msg.WriteInt32(errCode); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT); + + try { + int pos = 0; + int32_t scenario = TypeCast(data, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteInt32(scenario); + msg.WriteInt32(errCode); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE); + + try { + int len = size >> 1; + msg.WriteString(string(reinterpret_cast(data), len)); + msg.WriteString(string(reinterpret_cast(data + len), size - len)); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t type = TypeCast(data + pos, &pos); + int32_t userId = TypeCast(data + pos, &pos); + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteFileDescriptor(fd); + msg.WriteStringVector(bundleNames); + msg.WriteInt32(type); + msg.WriteInt32(userId); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t type = TypeCast(data + pos, &pos); + int32_t userId = TypeCast(data + pos, &pos); + int len = (size - pos) >> 1; + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); + vector detailInfos; + detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); + msg.WriteFileDescriptor(fd); + msg.WriteStringVector(bundleNames); + msg.WriteStringVector(detailInfos); + msg.WriteInt32(type); + msg.WriteInt32(userId); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); + + try { + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data), size)); + msg.WriteStringVector(bundleNames); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION); + + try { + int len = size >> 1; + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data), len)); + vector detailInfos; + detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); + msg.WriteStringVector(bundleNames); + msg.WriteStringVector(detailInfos); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_FINISH); + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); + + try { + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data), size), 0); + WriteParcelableVector(bundleNames, msg); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP); + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); + + try { + BIncrementalBackupSession::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + + try { + vector bundlesToBackup; + bundlesToBackup.emplace_back(string(reinterpret_cast(data), size), 0); + WriteParcelableVector(bundlesToBackup, msg); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast( + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS); + + try { + int len = size >> 2; + vector bundlesToBackup; + bundlesToBackup.emplace_back(string(reinterpret_cast(data), len), 0); + std::vector infos; + infos.emplace_back(string(reinterpret_cast(data + len), len)); + infos.emplace_back(string(reinterpret_cast(data + len + len), len)); + WriteParcelableVector(bundlesToBackup, msg); + msg.WriteStringVector(infos); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); + + try { + int pos = 0; + BFileInfo info; + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + msg.WriteParcelable(&info); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE); + + try { + int pos = 0; + BFileInfo info; + int fd = TypeCast(data, &pos); + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + msg.WriteParcelable(&info); + msg.WriteFileDescriptor(fd); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); + + try { + int pos = 0; + int fd1 = TypeCast(data, &pos); + int fd2 = TypeCast(data + pos, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + bool fdFlag = TypeCast(data + pos, &pos); + msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteBool(fdFlag); + if (fdFlag) { + msg.WriteFileDescriptor(fd1); + msg.WriteFileDescriptor(fd2); + } + msg.WriteInt32(errCode); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE); + + try { + int32_t errCode = TypeCast(data); + msg.WriteInt32(errCode); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE); + + try { + int len = size >> 1; + msg.WriteString(string(reinterpret_cast(data), len)); + msg.WriteString(string(reinterpret_cast(data + len), size - len)); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_BACKUP_INFO); + + try { + msg.WriteString(string(reinterpret_cast(data), size)); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_TIMER); + + try { + int pos = 0; + int32_t timeout = TypeCast(data, &pos); + msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteInt32(timeout); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_SEND_RATE); + + try { + int pos = 0; + int32_t sendRate = TypeCast(data, &pos); + msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); + msg.WriteInt32(sendRate); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} } // namespace OHOS /* Fuzzer entry point */ @@ -84,6 +682,32 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); + CmdInitRestoreSessionFuzzTest(service, data, size); + CmdInitBackupSessionFuzzTest(service, data, size); + CmdStartFuzzTest(service, data, size); + CmdGetLocalCapabilitiesFuzzTest(service, data, size); + CmdPublishFileFuzzTest(service, data, size); + CmdAppFileReadyFuzzTest(service, data, size); + CmdAppDoneFuzzTest(service, data, size); + CmdResultReportFuzzTest(service, data, size); + CmdGetFileHandleFuzzTest(service, data, size); + CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); + CmdAppendBundlesBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); + CmdFinishFuzzTest(service, data, size); + CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); + CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); + CmdInitIncrementalBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); + CmdPublishIncrementalFileFuzzTest(service, data, size); + CmdAppIncrementalFileReadyFuzzTest(service, data, size); + CmdAppIncrementalDoneFuzzTest(service, data, size); + CmdGetIncrementalFileHandleFuzzTest(service, data, size); + CmdGetBackupInfoFuzzTest(service, data, size); + CmdUpdateTimerFuzzTest(service, data, size); + CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn index 43efb9222..dcaad28f4 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn @@ -41,7 +41,6 @@ ohos_fuzztest("BackupServiceStubBranchFuzzTest") { deps = [ "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${app_file_service_path}/services/backup_sa:backup_sa", - "${app_file_service_path}/services/backup_sa:backup_sa_ipc_type", "${app_file_service_path}/utils:backup_utils", ] diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index 4b9fba7fa..6e76cd4d5 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -193,8 +193,6 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } -constexpr int32_t SERVICE_ID = 5203; - template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -222,18 +220,934 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } + +bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION); + + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + + BSessionRestore::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION); + + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + + BSessionBackup::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_START); + + try { + msg.WriteBuffer(data, size); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); + + try { + msg.WriteBuffer(data, size); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE); + + try { + int pos = 0; + BFileInfo info; + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + + msg.WriteParcelable(&info); + ExpectReturn({1, true, true, true, false}); + ExpectArgReturn({info.owner, info.fileName, info.sn}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteParcelable(&info); + ExpectReturn({1, true, true, true, true}); + ExpectArgReturn({info.owner, info.fileName, info.sn}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + bool flag = TypeCast(data + pos, &pos); + string fileName(reinterpret_cast(data + pos), size - pos); + + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({false}); + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_DONE); + + try { + int32_t errCode = TypeCast(data); + + ExpectReturn({false}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT); + + try { + int pos = 0; + int32_t scenario = TypeCast(data, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + string restoreRetInfo(reinterpret_cast(data + pos), size - pos); + + ExpectReturn({false}); + ExpectArgReturn({restoreRetInfo}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({restoreRetInfo, scenario}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, false}); + ExpectArgReturn({restoreRetInfo, scenario, errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, false}); + ExpectArgReturn({restoreRetInfo, scenario, errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true}); + ExpectArgReturn({restoreRetInfo, scenario, errCode}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE); + + try { + int len = size >> 1; + string bundleName(reinterpret_cast(data), len); + string fileName(reinterpret_cast(data + len), size - len); + + ExpectReturn({false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleName, fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({bundleName, fileName}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t type = TypeCast(data + pos, &pos); + int32_t userId = TypeCast(data + pos, &pos); + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); + + ExpectReturn({fd, false}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, false}); + ExpectArgReturn({bundleNames, type}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, false}); + ExpectArgReturn({bundleNames, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, true, false}); + ExpectArgReturn({bundleNames, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, true, true}); + ExpectArgReturn({bundleNames, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL); + + try { + int pos = 0; + int fd = TypeCast(data, &pos); + int32_t type = TypeCast(data + pos, &pos); + int32_t userId = TypeCast(data + pos, &pos); + int len = (size - pos) >> 1; + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); + vector detailInfos; + detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); + + ExpectReturn({fd, false}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, false}); + ExpectArgReturn({bundleNames, detailInfos}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, false}); + ExpectArgReturn({bundleNames, detailInfos, type}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, true, false}); + ExpectArgReturn({bundleNames, detailInfos, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, true, true, false}); + ExpectArgReturn({bundleNames, detailInfos, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({fd, true, true, true, true, true}); + ExpectArgReturn({bundleNames, detailInfos, type, userId}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); + + try { + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data), size)); + + ExpectReturn({false}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION); + + try { + int len = size >> 1; + vector bundleNames; + bundleNames.emplace_back(string(reinterpret_cast(data), len)); + vector detailInfos; + detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); + + ExpectReturn({false}); + ExpectArgReturn({bundleNames}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleNames, detailInfos}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, false}); + ExpectArgReturn({bundleNames, detailInfos}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true}); + ExpectArgReturn({bundleNames, detailInfos}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_FINISH); + try { + msg.WriteBuffer(data, size); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); + + try { + BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); + + int32_t infoSize = 1; + ExpectReturn({false}); + ExpectArgReturn({infoSize}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); + ExpectArgReturn({infoSize, "", "", 1}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundleNames); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); + ExpectArgReturn({infoSize, "", "", 1}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundleNames); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP); + try { + msg.WriteBuffer(data, size); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); + + try { + msg.WriteBuffer(data, size); + service->OnRemoteRequest(code, msg, reply, option); + + BIncrementalBackupSession::Callbacks callbacks; + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteRemoteObject(new ServiceReverse(callbacks)); + ExpectReturn({true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + + try { + BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); + + ExpectReturn({false}); + service->OnRemoteRequest(code, msg, reply, option); + + int32_t infoSize = 1; + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); + ExpectArgReturn({infoSize, "", "", 1}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundlesToBackup); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); + ExpectArgReturn({infoSize, "", "", 1}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundlesToBackup); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast( + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS); + + try { + int32_t infoSize = 1; + int len = size >> 1; + BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); + std::vector infos; + infos.emplace_back(string(reinterpret_cast(data + len), len)); + + ExpectReturn({false}); + ExpectArgReturn({infoSize}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); + ExpectArgReturn({infoSize, "", "", 1, infos}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundlesToBackup); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); + ExpectArgReturn({infoSize, "", "", 1, infos}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundlesToBackup); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); + ExpectArgReturn({infoSize, "", "", 1, infos}); + msg.FlushBuffer(); + msg.WriteParcelable(&bundlesToBackup); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); + + try { + int pos = 0; + BFileInfo info; + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + + msg.WriteParcelable(&info); + ExpectReturn({1, true, true, true, false}); + ExpectArgReturn({info.owner, info.fileName, info.sn}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteParcelable(&info); + ExpectReturn({1, true, true, true, true}); + ExpectArgReturn({info.owner, info.fileName, info.sn}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE); + + try { + int pos = 0; + BFileInfo info; + int fd = TypeCast(data, &pos); + info.sn = TypeCast(data, &pos); + int len = (size - pos) >> 1; + info.owner = string(reinterpret_cast(data + pos), len); + info.fileName = string(reinterpret_cast(data + pos + len), len); + + msg.WriteParcelable(&info); + ExpectReturn({fd, false}); + service->OnRemoteRequest(code, msg, reply, option); + + msg.FlushBuffer(); + msg.WriteParcelable(&info); + ExpectReturn({fd, true}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); + + try { + int pos = 0; + int fd1 = TypeCast(data, &pos); + int fd2 = TypeCast(data + pos, &pos); + int32_t errCode = TypeCast(data + pos, &pos); + bool flag = TypeCast(data + pos, &pos); + string fileName(reinterpret_cast(data + pos), size - pos); + + ExpectReturn({false}); + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + if (flag) { + fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : + ExpectReturn({true, flag, fd1, fd2, errCode, false}); + } else { + ExpectReturn({true, flag, errCode, false}); + } + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + if (flag) { + fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : + ExpectReturn({true, flag, fd1, fd2, errCode, true}); + } else { + ExpectReturn({true, flag, errCode, true}); + } + ExpectArgReturn({fileName}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE); + + try { + int32_t errCode = TypeCast(data); + + ExpectReturn({false}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({errCode}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE); + + try { + int len = size >> 1; + string bundleName(reinterpret_cast(data), len); + string fileName(reinterpret_cast(data + len), size - len); + + ExpectReturn({false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleName, fileName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({bundleName, fileName}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_BACKUP_INFO); + + try { + string bundleName(reinterpret_cast(data), size); + + ExpectReturn({false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_TIMER); + + try { + int pos = 0; + uint32_t timeout = TypeCast(data, &pos); + string bundleName(reinterpret_cast(data + pos), size - pos); + + ExpectReturn({false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleName, timeout}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, false}); + ExpectArgReturn({bundleName, timeout}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true}); + ExpectArgReturn({bundleName, timeout}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} + +bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return true; + } + + MessageParcel msg; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_SEND_RATE); + + try { + int pos = 0; + int32_t sendRate = TypeCast(data, &pos); + string bundleName(reinterpret_cast(data + pos), size - pos); + + ExpectReturn({false}); + ExpectArgReturn({bundleName}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, false}); + ExpectArgReturn({bundleName, sendRate}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, false}); + ExpectArgReturn({bundleName, sendRate}); + service->OnRemoteRequest(code, msg, reply, option); + + ExpectReturn({true, true, true}); + ExpectArgReturn({bundleName, sendRate}); + service->OnRemoteRequest(code, msg, reply, option); + } catch (OHOS::FileManagement::Backup::BError &err) { + // Only filter BError errors, Other results are not expected. + } + return true; +} } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); if (service == nullptr) { return 0; } try { OHOS::OnRemoteRequestFuzzTest(service, data, size); + CmdInitRestoreSessionFuzzTest(service, data, size); + CmdInitBackupSessionFuzzTest(service, data, size); + CmdStartFuzzTest(service, data, size); + CmdGetLocalCapabilitiesFuzzTest(service, data, size); + CmdPublishFileFuzzTest(service, data, size); + CmdAppFileReadyFuzzTest(service, data, size); + CmdAppDoneFuzzTest(service, data, size); + CmdResultReportFuzzTest(service, data, size); + CmdGetFileHandleFuzzTest(service, data, size); + CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); + CmdAppendBundlesBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); + CmdFinishFuzzTest(service, data, size); + CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); + CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); + CmdInitIncrementalBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); + CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); + CmdPublishIncrementalFileFuzzTest(service, data, size); + CmdAppIncrementalFileReadyFuzzTest(service, data, size); + CmdAppIncrementalDoneFuzzTest(service, data, size); + CmdGetIncrementalFileHandleFuzzTest(service, data, size); + CmdGetBackupInfoFuzzTest(service, data, size); + CmdUpdateTimerFuzzTest(service, data, size); + CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h new file mode 100644 index 000000000..72f10c32c --- /dev/null +++ b/test/fuzztest/backupservicestubbranch_fuzzer/service.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_H + +#include +#include + +#include "b_error/b_error.h" +#include "iservice_reverse.h" +#include "iremote_stub.h" +#include "service_stub.h" +#include "service_common.h" + +namespace OHOS::FileManagement::Backup { +class Service : public ServiceStub { +public: + ErrCode InitRestoreSession(const sptr&) { return BError(BError::Codes::OK); } + ErrCode InitRestoreSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode InitBackupSession(const sptr&) { return BError(BError::Codes::OK); } + ErrCode InitBackupSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode Start() { return BError(BError::Codes::OK); } + ErrCode GetLocalCapabilities(int&) { return BError(BError::Codes::OK); } + ErrCode GetLocalCapabilitiesForBundleInfos(int&) { return BError(BError::Codes::OK); } + ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } + ErrCode AppFileReady(const std::string&, int, int32_t) { return BError(BError::Codes::OK); } + ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } + ErrCode ServiceResultReport(const std::string&, + BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } + ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesRestoreSessionDataByDetail(int, + const std::vector&, + const std::vector&, + int32_t, + int32_t) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesRestoreSessionData(int, + const std::vector&, + int32_t, + int32_t) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesDetailsBackupSession(const std::vector&, + const std::vector&) { return BError(BError::Codes::OK); } + ErrCode Finish() { return BError(BError::Codes::OK); } + ErrCode Release() { return BError(BError::Codes::OK); } + ErrCode Cancel(const std::string&, int32_t&) { return BError(BError::Codes::OK); } + ErrCode GetLocalCapabilitiesIncremental(const std::vector&, int&) { return BError(BError::Codes::OK); } + ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } + ErrCode InitIncrementalBackupSession(const sptr&) { return BError(BError::Codes::OK); } + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) + { return BError(BError::Codes::OK); } + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector&, const std::vector&) + { return BError(BError::Codes::OK); } + ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } + ErrCode PublishSAIncrementalFile(const BFileInfo&, int) { return BError(BError::Codes::OK); } + ErrCode AppIncrementalFileReady(const std::string&, int, int, int32_t) + { return BError(BError::Codes::OK); } + ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } + ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } + ErrCode GetBackupInfo(const BundleName&, std::string&) { return BError(BError::Codes::OK); } + ErrCode UpdateTimer(const BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } + ErrCode UpdateSendRate(const std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } + ErrCode ReportAppProcessInfo(const std::string&, BackupRestoreScenario) { return BError(BError::Codes::OK); } + ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } + + ErrCode SAResultReport(const std::string, const std::string, + const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } + ErrCode GetBackupDataSize(bool, const std::vector&) { return BError(BError::Codes::OK); } +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file 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 32be58d0b..79b53f0e6 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -877,6 +877,39 @@ HWTEST_F(ServiceTest, SUB_Service_AppendBundlesRestoreSession_0200, TestSize.Lev GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppendBundlesRestoreSession_0200"; } +/** + * @tc.number: SUB_Service_AppendBundlesRestoreSession_0300 + * @tc.name: SUB_Service_AppendBundlesRestoreSession_0300 + * @tc.desc: 测试 AppendBundlesRestoreSession + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceTest, SUB_Service_AppendBundlesRestoreSession_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppendBundlesRestoreSession_0300"; + try { + ASSERT_TRUE(service != nullptr); + std::vector bundleNames; + RestoreTypeEnum restoreType = RESTORE_DATA_READDY; + int32_t userId = 100; + + service->session_ = nullptr; + auto ret = service->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, restoreType, userId); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + + service->session_ = sptr(new SvcSessionManager(wptr(service))); + service->isOccupyingSession_.store(true); + ret = service->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, restoreType, userId); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppendBundlesRestoreSession."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppendBundlesRestoreSession_0300"; +} + /** * @tc.number: SUB_Service_SetCurrentSessProperties_0100 * @tc.name: SUB_Service_SetCurrentSessProperties_0100 diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 48853ff35..f554d5263 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -2524,4 +2524,163 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnP } GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_IncrementalRestoreOnProcessInfo_0101"; } + +/** + * @tc.number: SUB_ServiceReverse_proxy_BackupOnScanningInfo_0100 + * @tc.name: SUB_ServiceReverse_proxy_BackupOnScanningInfo_0100 + * @tc.desc: Test function of BackupOnScanningInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnScanningInfo_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_BackupOnScanningInfo_0100"; + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); + EXPECT_TRUE(proxy_ != nullptr); + std::string scannedInfo; + proxy_->BackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-an exception occurred by BackupOnScanningInfo."; + } + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_BackupOnScanningInfo_0100"; +} + +/** + * @tc.number: SUB_ServiceReverse_proxy_BackupOnScanningInfo_0101 + * @tc.name: SUB_ServiceReverse_proxy_BackupOnScanningInfo_0101 + * @tc.desc: Test function of BackupOnScanningInfo interface for FAILURE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnScanningInfo_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_BackupOnScanningInfo_0101"; + try { + std::string scannedInfo; + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); + EXPECT_TRUE(proxy_ != nullptr); + proxy_->BackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); + EXPECT_TRUE(proxy_ != nullptr); + proxy_->BackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); + proxy_->BackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-an exception occurred by BackupOnScanningInfo."; + } + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_BackupOnScanningInfo_0101"; +} + +/** + * @tc.number: SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0100 + * @tc.name: SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0100 + * @tc.desc: Test function of IncrementalBackupOnScanningInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0100"; + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); + EXPECT_TRUE(proxy_ != nullptr); + std::string scannedInfo; + proxy_->IncrementalBackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-an exception occurred by IncrementalBackupOnScanningInfo."; + } + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0100"; +} + +/** + * @tc.number: SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0101 + * @tc.name: SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0101 + * @tc.desc: Test function of IncrementalBackupOnScanningInfo interface for FAILURE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0101"; + try { + std::string scannedInfo; + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); + EXPECT_TRUE(proxy_ != nullptr); + proxy_->IncrementalBackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); + EXPECT_TRUE(proxy_ != nullptr); + proxy_->IncrementalBackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); + proxy_->IncrementalBackupOnScanningInfo(scannedInfo); + EXPECT_TRUE(false); + } catch (BError &err) { + EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); + } + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-an exception occurred by IncrementalBackupOnScanningInfo."; + } + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_IncrementalBackupOnScanningInfo_0101"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 77884fbf2..8e29a796f 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -364,6 +364,30 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Leve GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0102"; } +/** + * @tc.number: SUB_Service_AppFileReady_0103 + * @tc.name: SUB_Service_AppFileReady_0103 + * @tc.desc: 测试 AppFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0103, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0103"; + try { + string fileName = "/manage.json"; + EXPECT_TRUE(servicePtr_ != nullptr); + auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0103"; +} + /** * @tc.number: SUB_Service_AppDone_0100 * @tc.name: SUB_Service_AppDone_0100 @@ -1795,4 +1819,273 @@ HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0100, testing::ext::TestSi } GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_DeleteDisConfigFile_0100"; } + +/** + * @tc.number: SUB_Service_ExtensionConnectFailRadarReport_0100 + * @tc.name: SUB_Service_ExtensionConnectFailRadarReport_0100 + * @tc.desc: 测试 ExtensionConnectFailRadarReport 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_ExtensionConnectFailRadarReport_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtensionConnectFailRadarReport_0100"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->ClearBundleRadarReport(); + servicePtr_->ExtensionConnectFailRadarReport(BUNDLE_NAME, BError(BError::Codes::OK), + IServiceReverse::Scenario::BACKUP); + EXPECT_TRUE(true); + + ret = Init(IServiceReverse::Scenario::RESTORE); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + servicePtr_->ExtensionConnectFailRadarReport(BUNDLE_NAME, BError(BError::Codes::OK), + IServiceReverse::Scenario::RESTORE); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtensionConnectFailRadarReport."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtensionConnectFailRadarReport_0100"; +} + +/** + * @tc.number: SUB_Service_StartRunningTimer_0100 + * @tc.name: SUB_Service_StartRunningTimer_0100 + * @tc.desc: 测试 StartRunningTimer 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_StartRunningTimer_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StartRunningTimer_0100"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->StartRunningTimer(BUNDLE_NAME); + EXPECT_TRUE(true); + + ret = Init(IServiceReverse::Scenario::RESTORE); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + servicePtr_->StartRunningTimer(BUNDLE_NAME); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StartRunningTimer."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartRunningTimer_0100"; +} + +/** + * @tc.number: SUB_Service_TimeoutRadarReport_0100 + * @tc.name: SUB_Service_TimeoutRadarReport_0100 + * @tc.desc: 测试 TimeoutRadarReport 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_TimeoutRadarReport_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TimeoutRadarReport_0100"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_TRUE(servicePtr_ != nullptr); + std::string bundleName = BUNDLE_NAME; + servicePtr_->ClearBundleRadarReport(); + servicePtr_->TimeoutRadarReport(IServiceReverse::Scenario::BACKUP, bundleName); + EXPECT_TRUE(true); + + ret = Init(IServiceReverse::Scenario::RESTORE); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + servicePtr_->TimeoutRadarReport(IServiceReverse::Scenario::RESTORE, bundleName); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TimeoutRadarReport."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TimeoutRadarReport_0100"; +} + +/** + * @tc.number: SUB_Service_ReportOnBundleStarted_0100 + * @tc.name: SUB_Service_ReportOnBundleStarted_0100 + * @tc.desc: 测试 ReportOnBundleStarted 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_ReportOnBundleStarted_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ReportOnBundleStarted_0100"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->ReportOnBundleStarted(IServiceReverse::Scenario::BACKUP, BUNDLE_NAME); + EXPECT_TRUE(true); + + ret = Init(IServiceReverse::Scenario::RESTORE); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + servicePtr_->ReportOnBundleStarted(IServiceReverse::Scenario::RESTORE, BUNDLE_NAME); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ReportOnBundleStarted."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ReportOnBundleStarted_0100"; +} + +/** + * @tc.number: SUB_Service_HandleNotSupportBundleNames_0100 + * @tc.name: SUB_Service_HandleNotSupportBundleNames_0100 + * @tc.desc: 测试 HandleNotSupportBundleNames 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_HandleNotSupportBundleNames_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleNotSupportBundleNames_0100"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_TRUE(servicePtr_ != nullptr); + const std::vector srcBundleNames = {"test0", "test1", "test2", "test3"}; + std::vector supportBundleNames = {"test2", "test3", "test4", "test5"}; + + servicePtr_->HandleNotSupportBundleNames(srcBundleNames, supportBundleNames, false); + EXPECT_TRUE(true); + servicePtr_->HandleNotSupportBundleNames(srcBundleNames, supportBundleNames, true); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleNotSupportBundleNames."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleNotSupportBundleNames_0100"; +} + +/** + * @tc.number: SUB_Service_RefreshDataSize_0100 + * @tc.name: SUB_Service_RefreshDataSize_0100 + * @tc.desc: 测试 RefreshDataSize 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_RefreshDataSize_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_RefreshDataSize_0100"; + try { + string fileName = MANAGE_JSON; + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->session_ = nullptr; + auto ret = servicePtr_->RefreshDataSize(0); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + + servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); + ret = servicePtr_->RefreshDataSize(0); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by RefreshDataSize."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_RefreshDataSize_0100"; +} + +/** + * @tc.number: SUB_Service_StopExtTimer_0100 + * @tc.name: SUB_Service_StopExtTimer_0100 + * @tc.desc: 测试 StopExtTimer 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_StopExtTimer_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopExtTimer_0100"; + try { + string fileName = MANAGE_JSON; + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->session_ = nullptr; + bool isExtStop = false; + + auto ret = servicePtr_->StopExtTimer(isExtStop); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + + servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); + ret = servicePtr_->StopExtTimer(isExtStop); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopExtTimer."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopExtTimer_0100"; +} + +/** + * @tc.number: SUB_Service_PublishFile_0103 + * @tc.name: SUB_Service_PublishFile_0103 + * @tc.desc: 测试 PublishFile 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_PublishFile_0103, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0103"; + try { + ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + BFileInfo fileInfo {BUNDLE_NAME, "", 0}; + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->session_ = nullptr; + ret = servicePtr_->PublishFile(fileInfo); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by PublishFile."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_PublishFile_0103"; +} + +/** + * @tc.number: SUB_Service_AppFileReady_0104 + * @tc.name: SUB_Service_AppFileReady_0104 + * @tc.desc: 测试 AppFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0104, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0104"; + try { + string fileName = "manage.json"; + EXPECT_TRUE(servicePtr_ != nullptr); + servicePtr_->session_ = nullptr; + auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); + servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0104"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index 54c6a5067..00fb5bd64 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -1996,5 +1996,100 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetImplRestoreType_0100, t } GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_SetImplRestoreType_0100"; } + +/** + * @tc.number: SUB_backup_sa_session_Exception_0100 + * @tc.name: SUB_backup_sa_session_Exception_0100 + * @tc.desc: 测试 Exception + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Exception_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_Exception_0100"; + try { + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + + sessionManagerPtr_->SetExtFileNameRequest(BUNDLE_NAME, ""); + EXPECT_TRUE(true); + + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + std::set fileSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); + EXPECT_TRUE(fileSet.empty()); + + sessionManagerPtr_->SetBackupExtName(BUNDLE_NAME, ""); + EXPECT_TRUE(true); + + std::string extName = sessionManagerPtr_->GetBackupExtName(BUNDLE_NAME); + EXPECT_TRUE(extName.empty()); + + sessionManagerPtr_->SetBackupExtInfo(BUNDLE_NAME, ""); + EXPECT_TRUE(true); + + std::string extInfo = sessionManagerPtr_->GetBackupExtInfo(BUNDLE_NAME); + EXPECT_TRUE(extInfo.empty()); + + sessionManagerPtr_->SetBundleUserId(BUNDLE_NAME, 0); + EXPECT_TRUE(true); + + int32_t id = sessionManagerPtr_->GetBundleUserId(BUNDLE_NAME); + EXPECT_EQ(id, sessionManagerPtr_->GetSessionUserId()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by Exception."; + } + GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_Exception_0100"; +} + +/** + * @tc.number: SUB_backup_sa_session_Exception_0200 + * @tc.name: SUB_backup_sa_session_Exception_0200 + * @tc.desc: 测试 Exception + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Exception_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_Exception_0200"; + try { + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + + sessionManagerPtr_->SetBundleRestoreType(BUNDLE_NAME, RestoreTypeEnum::RESTORE_DATA_WAIT_SEND); + EXPECT_TRUE(true); + + RestoreTypeEnum restoreType = sessionManagerPtr_->GetBundleRestoreType(BUNDLE_NAME); + EXPECT_EQ(restoreType, RestoreTypeEnum::RESTORE_DATA_WAIT_SEND); + + sessionManagerPtr_->SetBundleVersionCode(BUNDLE_NAME, 0); + EXPECT_TRUE(true); + + int64_t versionCode = sessionManagerPtr_->GetBundleVersionCode(BUNDLE_NAME); + EXPECT_EQ(versionCode, 0); + + sessionManagerPtr_->SetBundleVersionName(BUNDLE_NAME, ""); + EXPECT_TRUE(true); + + std::string versionName = sessionManagerPtr_->GetBundleVersionName(BUNDLE_NAME); + EXPECT_TRUE(versionName.empty()); + + sessionManagerPtr_->SetClearDataFlag(BUNDLE_NAME, true); + EXPECT_TRUE(true); + + bool flag = sessionManagerPtr_->GetClearDataFlag(BUNDLE_NAME); + EXPECT_TRUE(flag); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by Exception."; + } + GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_Exception_0200"; +} #include "svc_session_manager_ex_test.cpp" } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp index b33ae44cf..397424299 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp @@ -301,4 +301,104 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleNameIndexInfo_0601, testing::ext:: } GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleNameIndexInfo_0601"; } + +/** + * @tc.number: b_jsonutil_BuildInitSessionErrInfo_0701 + * @tc.name: b_jsonutil_BuildInitSessionErrInfo_0701 + * @tc.desc: Test function of BuildInitSessionErrInfo interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildInitSessionErrInfo_0701"; + try { + int32_t userId = 0; + std::string callerName; + std::string activeTime; + int cjson = 0; + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(nullptr)); + auto result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); + EXPECT_EQ(result, ""); + + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); + EXPECT_EQ(result, ""); + + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); + EXPECT_EQ(result, ""); + + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()) + .WillOnce(Return(reinterpret_cast(&cjson))) + .WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToArray(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)) + .WillOnce(Return(nullptr)) + .WillOnce(Return(nullptr)) + .WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); + EXPECT_EQ(result, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildInitSessionErrInfo_0701"; +} + +/** + * @tc.number: b_jsonutil_WriteToStr_0801 + * @tc.name: b_jsonutil_WriteToStr_0801 + * @tc.desc: Test function of WriteToStr interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_WriteToStr_0801, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin WriteToStr_0801"; + try { + std::vector bundleDataList; + size_t listSize = 0; + std::string scanning; + std::string jsonStr; + int cjson = 0; + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(nullptr)); + auto result = BJsonUtil::WriteToStr(bundleDataList, listSize, scanning, jsonStr); + EXPECT_FALSE(result); + + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + result = BJsonUtil::WriteToStr(bundleDataList, listSize, scanning, jsonStr); + EXPECT_FALSE(result); + + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + result = BJsonUtil::WriteToStr(bundleDataList, listSize, scanning, jsonStr); + EXPECT_FALSE(result); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end WriteToStr_0801"; +} } \ No newline at end of file -- Gitee From 7bab3638e3542d93ee26f5b529ec6b6c43015306 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 14 Mar 2025 17:28:09 +0800 Subject: [PATCH 12/21] update FUZZ Signed-off-by: BrainL --- .../backupservicestubbranch_fuzzer/service.h | 31 ++-- .../backup_kit_inner/service_client_mock.cpp | 18 +-- tests/mock/module_ipc/service_mock.cpp | 139 ++++++------------ tests/unittests/backup_sa/session/BUILD.gn | 2 +- .../backup_sa/session/service_client_mock.cpp | 51 ------- .../backup_sa/session/service_client_mock.h | 34 ----- 6 files changed, 69 insertions(+), 206 deletions(-) delete mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp delete mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h index 72f10c32c..69f8f2dfa 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ b/test/fuzztest/backupservicestubbranch_fuzzer/service.h @@ -29,9 +29,11 @@ namespace OHOS::FileManagement::Backup { class Service : public ServiceStub { public: ErrCode InitRestoreSession(const sptr&) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode InitRestoreSessionWithErrMsg(const sptr&, + std::string&) { return BError(BError::Codes::OK); } ErrCode InitBackupSession(const sptr&) { return BError(BError::Codes::OK); } - ErrCode InitBackupSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode InitBackupSessionWithErrMsg(const sptr&, + std::string&) { return BError(BError::Codes::OK); } ErrCode Start() { return BError(BError::Codes::OK); } ErrCode GetLocalCapabilities(int&) { return BError(BError::Codes::OK); } ErrCode GetLocalCapabilitiesForBundleInfos(int&) { return BError(BError::Codes::OK); } @@ -42,28 +44,31 @@ public: BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } ErrCode AppendBundlesRestoreSessionDataByDetail(int, - const std::vector&, - const std::vector&, - int32_t, - int32_t) { return BError(BError::Codes::OK); } + const std::vector&, + const std::vector&, + int32_t, + int32_t) { return BError(BError::Codes::OK); } ErrCode AppendBundlesRestoreSessionData(int, - const std::vector&, - int32_t, - int32_t) { return BError(BError::Codes::OK); } + const std::vector&, + int32_t, + int32_t) { return BError(BError::Codes::OK); } ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } ErrCode AppendBundlesDetailsBackupSession(const std::vector&, const std::vector&) { return BError(BError::Codes::OK); } ErrCode Finish() { return BError(BError::Codes::OK); } ErrCode Release() { return BError(BError::Codes::OK); } ErrCode Cancel(const std::string&, int32_t&) { return BError(BError::Codes::OK); } - ErrCode GetLocalCapabilitiesIncremental(const std::vector&, int&) { return BError(BError::Codes::OK); } + ErrCode GetLocalCapabilitiesIncremental(const std::vector&, + int&) { return BError(BError::Codes::OK); } ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } ErrCode InitIncrementalBackupSession(const sptr&) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string&) { return BError(BError::Codes::OK); } + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr&, + std::string&) { return BError(BError::Codes::OK); } ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector&, + const std::vector&) + { return BError(BError::Codes::OK); } ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } ErrCode PublishSAIncrementalFile(const BFileInfo&, int) { return BError(BError::Codes::OK); } ErrCode AppIncrementalFileReady(const std::string&, int, int, int32_t) diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp index 351c5dbc7..bc5a8ef35 100644 --- a/tests/mock/backup_kit_inner/service_client_mock.cpp +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -45,12 +45,7 @@ bool ServiceClient::CheckServiceProxy() } return isNull; } - -sptr ServiceClient::GetServiceProxyPointer() -{ - return serviceProxy_; -} - +sptr ServiceClient::GetServiceProxyPointer() { return serviceProxy_; } sptr ServiceClient::GetInstance() { if (!GetMockGetInstance()) { @@ -65,16 +60,9 @@ sptr ServiceClient::GetInstance() } return serviceProxy_; } - -void ServiceClient::InvaildInstance() -{ - serviceProxy_ = nullptr; -} - +void ServiceClient::InvaildInstance() { serviceProxy_ = nullptr; } void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr &remoteObject) -{ -} - +{} void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} } \ No newline at end of file diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index f0ebba00f..9dff4f224 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -35,72 +35,39 @@ void Service::OnStart() {} void Service::OnStop() {} -ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) -{ - return BError(BError::Codes::OK); -} -ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +ErrCode Service::GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return BError(BError::Codes::OK); + return UniqueFd(-1); } -ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - int32_t restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} +void Service::StopAll(const wptr &obj, bool force) {} -ErrCode Service::AppendBundlesRestoreSessionData(int fd, - const std::vector &bundleNames, - int32_t restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} -ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( - const std::vector &bundlesToBackup, - const std::vector &bundleInfos) +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) { return BError(BError::Codes::OK); } -ErrCode Service::GetLocalCapabilities(int &fd) +ErrCode Service::InitRestoreSession(const sptr &remote) { - fd = -1; return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilities() -{ - return UniqueFd(-1); -} - -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); -} - -void Service::StopAll(const wptr &obj, bool force) {} - -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(const sptr &remote) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(const sptr &remote) +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } @@ -125,24 +92,25 @@ ErrCode Service::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, + BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -252,8 +220,9 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -345,40 +314,26 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName return make_shared(bundleName); } -void Service::RemoveExtensionMutex(const BundleName &bundleName) {} +void Service::RemoveExtensionMutex(const BundleName &bundleName) +{ +} void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, - const vector &restoreBundleNames) -{ -} + const vector &appendBundleNames, const vector &restoreBundleNames) {} -void Service::BundleBeginRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverse::Scenario scenario) -{ -} +void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} -void Service::BundleEndRadarReport(const std::string &bundleName, - ErrCode errCode, - const IServiceReverse::Scenario scenario) -{ -} +void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, + const IServiceReverse::Scenario scenario) {} -void Service::FileReadyRadarReport(const std::string &bundleName, - const std::string &fileName, - const ErrCode errCode, - const IServiceReverse::Scenario scenario) -{ -} +void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverse::Scenario scenario) -{ -} +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -411,28 +366,28 @@ void Service::ClearFailedBundles() {} void Service::GetOldDeviceBackupVersion() {} -void Service::CreateDirIfNotExist(const std::string &path) {} - -std::vector Service::GetSupportBackupBundleNames(vector &, - bool, - const vector &) +void Service::CreateDirIfNotExist(const std::string &path) { - return {}; } void Service::StartRunningTimer(const std::string &bundleName) {} -void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} +std::vector Service::GetSupportBackupBundleNames(vector&, bool, + const vector&) +{ + return {}; +} + +void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} -void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} +void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) -{ -} +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, + ErrCode errCode) {} void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} @@ -453,7 +408,7 @@ void Service::DeleteFromList(size_t scannedSize) {} void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} -void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} +void Service::SendScannedInfo(const string&scannendInfos, sptr session) {} void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index c7a2500c0..2715b02ec 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -39,8 +39,8 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_incremental_session_test.cpp", - "service_client_mock.cpp", "service_proxy_mock.cpp", ] diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp deleted file mode 100644 index cf075fbd2..000000000 --- a/tests/unittests/backup_sa/session/service_client_mock.cpp +++ /dev/null @@ -1,51 +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 "service_client.h" -#include "iservice.h" -#include "service_proxy.h" -namespace OHOS::FileManagement::Backup { -using namespace std; - -bool ServiceClient::CheckServiceProxy() -{ - serviceProxy_ = ServiceClient::GetInstance(); - bool isNull = false; - if (serviceProxy_ != nullptr) { - isNull = true; - } - return isNull; -} - -sptr ServiceClient::GetServiceProxyPointer() -{ - return serviceProxy_; -} - -sptr ServiceClient::GetInstance() -{ - return serviceProxy_; -} - -void ServiceClient::InvaildInstance() {} - -void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) -{ -} - -void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} -} \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h deleted file mode 100644 index 6aa6d9884..000000000 --- a/tests/unittests/backup_sa/session/service_client_mock.h +++ /dev/null @@ -1,34 +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. - */ - -#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H -#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H - -#include - -#include "service_client.h" - -namespace OHOS::FileManagement::Backup { -class ServiceClientMock : public ServiceClient { - -public: - MOCK_METHOD0(GetServiceProxyPointer, bool()); - MOCK_METHOD0(GetInstance, sptr()); - MOCK_METHOD0(InvaildInstance, sptr()); - MOCK_METHOD0(InvaildInstance, void()); - MOCK_METHOD0(Start, ErrCode()); -}; -} // End of namespace OHOS::FileManagement::Backup -#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H -- Gitee From 027018993ca13bc79fab55daf39fb8e4182ad4f2 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 14 Mar 2025 19:50:31 +0800 Subject: [PATCH 13/21] UT Signed-off-by: BrainL --- .../backupservicestubbranch_fuzzer/service.h | 4 +- .../backup_sa/session/service_client_mock.cpp | 40 +++++++++++++++++++ .../backup_sa/session/service_client_mock.h | 33 +++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h index 69f8f2dfa..7848c335a 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ b/test/fuzztest/backupservicestubbranch_fuzzer/service.h @@ -66,9 +66,9 @@ public: std::string&) { return BError(BError::Codes::OK); } ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector&, + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } + { return BError(BError::Codes::OK); } ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } ErrCode PublishSAIncrementalFile(const BFileInfo&, int) { return BError(BError::Codes::OK); } ErrCode AppIncrementalFileReady(const std::string&, int, int, int32_t) diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp new file mode 100644 index 000000000..fa5c2a822 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -0,0 +1,40 @@ +/* + * 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 "service_client.h" + #include "iservice.h" + #include "service_proxy.h" + namespace OHOS::FileManagement::Backup { + using namespace std; + + bool ServiceClient::CheckServiceProxy() + { + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; + } + + sptr ServiceClient::GetServiceProxyPointer() { return serviceProxy_; } + sptr ServiceClient::GetInstance() { return serviceProxy_; } + void ServiceClient::InvaildInstance() {} + void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) + {} + void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} + } \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h new file mode 100644 index 000000000..d83dc21b9 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -0,0 +1,33 @@ +/* + * 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. + */ + + #ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + #define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + + #include + #include "service_client.h" + + namespace OHOS::FileManagement::Backup { + class ServiceClientMock : public ServiceClient { + + public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); + }; + } // End of namespace OHOS::FileManagement::Backup + #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H \ No newline at end of file -- Gitee From dce6f9b37c2a40cbc9f2092a1ee651fbb1d7c6b0 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 14 Mar 2025 20:11:34 +0800 Subject: [PATCH 14/21] format build gn Signed-off-by: BrainL --- tests/unittests/backup_sa/session/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index 2715b02ec..c7a2500c0 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -39,8 +39,8 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", - "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_incremental_session_test.cpp", + "service_client_mock.cpp", "service_proxy_mock.cpp", ] -- Gitee From adebd65a5fe90b641f9d82a18e5889b6db410601 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 15 Mar 2025 13:02:24 +0800 Subject: [PATCH 15/21] Code lines modify. Signed-off-by: BrainL --- .../backup_kit_inner/src/service_client.cpp | 3 -- .../backup_kit_inner/impl/service_client.h | 1 - .../backup_sa/include/module_ipc/service.h | 41 ++++---------- services/backup_sa/src/module_ipc/service.cpp | 54 +++++++------------ .../src/module_ipc/service_incremental.cpp | 30 +++-------- .../backup_sa/src/module_ipc/sub_service.cpp | 7 +-- .../backup_kit_inner/service_client_mock.cpp | 1 - .../backup_sa/session/service_client_mock.cpp | 46 ++++++++-------- .../backup_sa/session/service_client_mock.h | 32 +++++------ .../backup_sa/session/service_proxy_mock.cpp | 17 ++---- 10 files changed, 83 insertions(+), 149 deletions(-) diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp index 6efa0661f..f4af54168 100644 --- a/frameworks/native/backup_kit_inner/src/service_client.cpp +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -53,7 +53,6 @@ sptr ServiceClient::GetInstance() if (serviceProxy_ != nullptr) { return serviceProxy_; } - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { HILOGE("Get an empty samgr"); @@ -70,7 +69,6 @@ sptr ServiceClient::GetInstance() FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); return nullptr; } - auto waitStatus = loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); @@ -118,7 +116,6 @@ void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t proxyConVar_.notify_one(); return; } - auto callback = [](const wptr &obj) { ServiceClient::InvaildInstance(); }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h index 2812aaae6..28a90dd2d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h @@ -25,7 +25,6 @@ #include "iservice.h" #include "system_ability_load_callback_stub.h" - namespace OHOS::FileManagement::Backup { class ServiceClient { diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 6838d64ef..dee0e5f14 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -70,39 +70,27 @@ public: const std::vector& detailInfos, int32_t restoreType, int32_t userId) override; - ErrCode AppendBundlesRestoreSessionData( - int fd, - const std::vector& bundleNames, - int32_t restoreType, - int32_t userId) override; + ErrCode AppendBundlesRestoreSessionData(int fd, const std::vector& bundleNames, + int32_t restoreType, int32_t userId) override; ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; - ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; ErrCode Cancel(const std::string& bundleName, int32_t &result) override; - ErrCode GetLocalCapabilitiesIncremental( - const std::vector& bundleNames, - int& fd) override; + ErrCode GetLocalCapabilitiesIncremental(const std::vector& bundleNames, int& fd) override; ErrCode GetAppLocalListAndDoIncrementalBackup() override; ErrCode InitIncrementalBackupSession(const sptr& remote) override; ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( - const std::vector& bundlesToBackup, - const std::vector& bundleInfos) override; + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector& bundlesToBackup, + const std::vector& bundleInfos) override; ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile( - const BFileInfo& fileInfo, - int fd) override; + ErrCode PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) override; ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); - ErrCode AppIncrementalFileReady( - const std::string& fileName, - int fd, - int manifestFd, - int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReady(const std::string& fileName, int fd, int manifestFd, + int32_t appIncrementalFileReadyErrCode) override; ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; @@ -666,25 +654,18 @@ private: UniqueFd GetLocalCapabilities(); UniqueFd GetLocalCapabilitiesForBundleInfos(); - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); - - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, + ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, const std::vector &bundleInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE); - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, + ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE); - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames); - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos); + const std::vector &infos); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index ad4b6ac37..8a9b5bd2d 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -225,11 +225,10 @@ void Service::OnStart() if (!bundleNameList.empty() || !residualBundleNameList.empty()) { if (!bundleNameList.empty()) { OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); - HILOGI("bundleNameList !=null"); } if (!residualBundleNameList.empty()) { OnStartResRadarReport(residualBundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); } SetOccupySession(true); session_->Active( @@ -278,7 +277,6 @@ ErrCode Service::GetLocalCapabilities(int& fd) { UniqueFd fdResult(GetLocalCapabilities()); fd = fdResult.Release(); - HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); return BError(BError::Codes::OK); } @@ -370,8 +368,8 @@ void Service::PermissionCheckFailRadar(const std::string &info, const std::strin { std::string funcPos = "Service::"; AppRadar::Info resInfo("", "", info); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), - BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } @@ -632,9 +630,8 @@ static vector GetRestoreBundleNames(UniqueFd fd, return restoreBundleInfos; } -void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, - const vector &restoreBundleNames) +void Service::HandleExceptionOnAppendBundles( + sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," @@ -650,15 +647,12 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, - const std::vector &bundleNames, +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, - int32_t restoreType, - int32_t userId) + int32_t restoreType, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Begin AppendBundlesRestoreSessionDataByDetail"); - HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + HILOGI("Begin fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); UniqueFd fdUnique(fd); RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); @@ -722,8 +716,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, std::vector &restoreBundleNames, - RestoreTypeEnum restoreType, - std::string &backupVersion) + RestoreTypeEnum restoreType, std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -734,11 +727,11 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); + restoreInfo.extensionName.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { @@ -759,14 +752,11 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } -ErrCode Service::AppendBundlesRestoreSessionData(int fd, - const std::vector &bundleNames, - int32_t restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, + int32_t restoreType, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Begin AppendBundlesRestoreSessionData"); - HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + HILOGI("Begin fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); UniqueFd fdUnique(fd); RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); @@ -1016,10 +1006,8 @@ ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRe } } -ErrCode Service::SAResultReport(const std::string bundleName, - const std::string restoreRetInfo, - const ErrCode errCode, - const BackupRestoreScenario sennario) +ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, + const ErrCode errCode, const BackupRestoreScenario sennario) { SADone(errCode, bundleName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { @@ -1046,7 +1034,8 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore { HILOGI("Begin"); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + if (sennario != BackupRestoreScenario::FULL_RESTORE && + sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { return; } if (session_->OnBundleFileReady(bundleName)) { @@ -1223,8 +1212,7 @@ int Service::Dump(int fd, const vector &args) } void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, - const ErrCode ret) + const std::string &bundleName, const ErrCode ret) { try { if (session_ == nullptr) { @@ -1886,9 +1874,7 @@ ErrCode Service::BackupSA(std::string bundleName) return BError(BError::Codes::OK); } -void Service::OnSABackup(const std::string &bundleName, - const int &fd, - const std::string &result, +void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, const ErrCode &errCode) { auto task = [bundleName, fd, result, errCode, this]() { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 772fe2da2..2f78c020c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -124,10 +124,8 @@ void Service::CreateDirIfNotExist(const std::string &path) ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Begin GetLocalCapabilitiesIncremental fd = %{private}d", fd); UniqueFd fdResult(GetLocalCapabilitiesIncremental(bundleNames)); fd = fdResult.Release(); - HILOGI("End GetLocalCapabilitiesIncremental fd = %{private}d", fd); return BError(BError::Codes::OK); // anytime return OK } @@ -423,8 +421,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &bundleInfos) + const std::vector &bundlesToBackup, const std::vector &bundleInfos) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); return AppendBundlesIncrementalBackupSession(bundlesToBackup, bundleInfos); @@ -535,7 +532,6 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) { - HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); UniqueFd uniquedParameter(fd); return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); } @@ -563,17 +559,14 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd return saConnection->CallRestoreSA(move(fd)); } -ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, - const std::string &fileName, - UniqueFd fd, - UniqueFd manifestFd, - int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, + UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); + move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); return BError(BError::Codes::OK); } @@ -586,8 +579,8 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); if (ret != ERR_OK) { - HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), - GetAnonyPath(fileName).c_str()); + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", + bundleName.c_str(), GetAnonyPath(fileName).c_str()); return ret; } } @@ -602,17 +595,11 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, } } -ErrCode Service::AppIncrementalFileReady(const std::string &fileName, - int fd, - int manifestFd, +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, int fd, int manifestFd, int32_t appIncrementalFileReadyErrCode) { HILOGI("Begin AppIncrementalFileReady:%{public}s, fd:%{public}d, manifestFd:%{public}d, errcode:%{public}d", fileName.c_str(), fd, manifestFd, appIncrementalFileReadyErrCode); - if (fd < 0 || manifestFd < 0) { - HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); - return BError(BError::Codes::SA_INVAL_ARG).GetCode(); - } UniqueFd fdUnique(fd); UniqueFd manifestFdUnique(manifestFd); return AppIncrementalFileReady(fileName, std::move(fdUnique), std::move(manifestFdUnique), @@ -781,8 +768,7 @@ bool Service::IncrementalBackup(const string &bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); } return true; - } else if (scenario == IServiceReverse::Scenario::RESTORE && - BackupPara().GetBackupOverrideIncrementalRestore() && + } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 920f8bc36..c2ba14e1c 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -245,12 +245,8 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) { - HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); + HILOGI("Begin fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); UniqueFd fdUnique(fd); - if (fd < 0) { - HILOGE("Error fd, fd = %{public}d", fd); - return BError(BError::Codes::SA_INVAL_ARG); - } return AppFileReady(fileName, std::move(fdUnique), errCode); } @@ -868,7 +864,6 @@ ErrCode Service::InitBackupSessionWithErrMsg(const sptr& remote ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { UniqueFd uniqueFd(GetLocalCapabilitiesForBundleInfos()); - HILOGI("get GetLocalCapabilitiesForBundleInfos value"); fd = uniqueFd.Release(); return ErrCode(BError::Codes::OK); } diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp index bc5a8ef35..007e795db 100644 --- a/tests/mock/backup_kit_inner/service_client_mock.cpp +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -51,7 +51,6 @@ sptr ServiceClient::GetInstance() if (!GetMockGetInstance()) { return nullptr; } - if (!GetMockLoadSystemAbility()) { serviceProxy_ = sptr(new ServiceProxy(nullptr)); } else { diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp index fa5c2a822..2e34c235c 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.cpp +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -13,28 +13,26 @@ * limitations under the License. */ +#include "service_client.h" +#include "iservice.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; - #include "service_client.h" - #include "iservice.h" - #include "service_proxy.h" - namespace OHOS::FileManagement::Backup { - using namespace std; - - bool ServiceClient::CheckServiceProxy() - { - serviceProxy_ = ServiceClient::GetInstance(); - bool isNull = false; - if (serviceProxy_ != nullptr) { - isNull = true; - } - return isNull; - } - - sptr ServiceClient::GetServiceProxyPointer() { return serviceProxy_; } - sptr ServiceClient::GetInstance() { return serviceProxy_; } - void ServiceClient::InvaildInstance() {} - void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) - {} - void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} - } \ No newline at end of file +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} +sptr ServiceClient::GetServiceProxyPointer() { return serviceProxy_; } +sptr ServiceClient::GetInstance() { return serviceProxy_; } +void ServiceClient::InvaildInstance() {} +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{} +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h index d83dc21b9..dc5936734 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.h +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -13,21 +13,21 @@ * limitations under the License. */ - #ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H - #define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H - - #include - #include "service_client.h" +#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H +#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + +#include +#include "service_client.h" - namespace OHOS::FileManagement::Backup { - class ServiceClientMock : public ServiceClient { +namespace OHOS::FileManagement::Backup { +class ServiceClientMock : public ServiceClient { - public: - MOCK_METHOD0(GetServiceProxyPointer, bool()); - MOCK_METHOD0(GetInstance, sptr()); - MOCK_METHOD0(InvaildInstance, sptr()); - MOCK_METHOD0(InvaildInstance, void()); - MOCK_METHOD0(Start, ErrCode()); - }; - } // End of namespace OHOS::FileManagement::Backup - #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H \ No newline at end of file +public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); +}; +} // End of namespace OHOS::FileManagement::Backup +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 0ed3fb8bf..bfdd210af 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -40,10 +40,7 @@ ErrCode ServiceProxy::AppIncrementalDone(int32_t appIncrementalDoneErrCode) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, - int fd, - int manifestFd, - int32_t appIncrementalFileReadyErrCode) +ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -82,8 +79,7 @@ ErrCode ServiceProxy::Start() } ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( - const std::vector &bundlesToBackup, - const std::vector &bundleInfos) + const std::vector &bundlesToBackup, const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -116,8 +112,7 @@ int32_t ServiceProxy::InitBackupSession(const sptr &remote) return 1; } -ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, - BackupRestoreScenario scenario, +ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario scenario, int32_t serviceResultReportErrCode) { return BError(BError::Codes::OK); @@ -138,11 +133,9 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, - const std::vector &bundleNames, +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, - int32_t restoreType, - int32_t userId) + int32_t restoreType, int32_t userId) { return BError(BError::Codes::OK); } -- Gitee From a4a40b73ef21ce072e84016f0741f709dc9c4562 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 15 Mar 2025 14:00:24 +0800 Subject: [PATCH 16/21] Code check modify. Signed-off-by: BrainL --- tests/unittests/backup_sa/session/service_client_mock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h index dc5936734..53c8e8783 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.h +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -30,4 +30,4 @@ public: MOCK_METHOD0(Start, ErrCode()); }; } // End of namespace OHOS::FileManagement::Backup -#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H -- Gitee From 9bcdfe946ebc45586faf1f3d3d1b67c3d387dc79 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 15 Mar 2025 14:19:23 +0800 Subject: [PATCH 17/21] Code check modify. Signed-off-by: BrainL --- services/backup_sa/src/module_ipc/service.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 8a9b5bd2d..8f7bfa679 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -630,8 +630,9 @@ static vector GetRestoreBundleNames(UniqueFd fd, return restoreBundleInfos; } -void Service::HandleExceptionOnAppendBundles( - sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) +void Service::HandleExceptionOnAppendBundles(sptr session, + const vector &appendBundleNames, + const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," -- Gitee From dbd92f85e6da5b819938b33b9ed2da35d862c755 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 20 Mar 2025 20:54:39 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=B8=BB=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- BUILD.gn | 8 +- backup.gni | 2 +- bundle.json | 4 +- .../native/backup_ext/src/ext_backup_js.cpp | 25 +--- .../native/backup_ext/src/untar_file.cpp | 2 +- .../kits/js/backup/general_callbacks.cpp | 65 ++++------ .../js/backup/session_backup_n_exporter.cpp | 6 +- .../session_incremental_backup_n_exporter.cpp | 6 +- .../js/backup/session_restore_n_exporter.cpp | 6 +- .../src/module_external/bms_adapter.cpp | 11 +- test/unittest/file_permission_native/BUILD.gn | 2 +- test/unittest/file_share_native/BUILD.gn | 2 +- .../file_share_permission_sup_test/BUILD.gn | 2 +- .../file_share_permission_test/BUILD.gn | 2 +- test/unittest/file_uri_native/BUILD.gn | 2 +- test/unittest/file_uri_ndk_test/BUILD.gn | 2 +- .../permission/BUILD.gn | 2 +- test/unittest/js_file_uri_test/BUILD.gn | 2 +- test/unittest/remote_file_share/BUILD.gn | 2 +- tests/mock/napi/include/napi_mock.h | 8 +- tests/mock/napi/src/napi_mock.cpp | 11 +- .../backup_tool/tool_help_test.cpp | 4 +- tests/unittests/BUILD.gn | 4 +- .../backup_ext/ext_backup_js_test.cpp | 107 ++++------------- .../backup_ext/ext_extension_test.cpp | 62 ++++++++++ .../external_ext_backup_js_test.cpp | 11 +- .../ext_backup_js_external_test.cpp | 42 ++----- .../module_ipc/service_incremental_test.cpp | 3 +- .../module_ipc/service_other_test.cpp | 19 +-- .../module_ipc/service_throw_test.cpp | 69 ++--------- .../backup_sa/module_ipc/sub_service_test.cpp | 70 +++-------- .../module_ipc/svc_session_manager_test.cpp | 109 +++++++++++++++++ .../backup_sa/session/service_client_mock.h | 2 +- tests/unittests/backup_tools/BUILD.gn | 2 +- tests/unittests/backup_utils/BUILD.gn | 2 +- .../backup_utils/b_anony/b_anony_test.cpp | 2 +- .../backup_utils/b_error/b_error_test.cpp | 60 +++++----- .../backup_utils/b_filesystem/b_dir_test.cpp | 4 +- .../b_filesystem/b_file_hash_test.cpp | 4 +- .../b_json/b_json_cached_entity_test.cpp | 24 ++-- .../b_json/b_json_clear_data_config_test.cpp | 113 +++++++++++++++++- .../b_json/b_json_entity_ext_manage_test.cpp | 22 ++-- .../b_json_entity_extension_config_test.cpp | 8 +- .../b_json/b_report_entity_test.cpp | 2 +- .../b_jsonutil/b_jsonutil_other_test.cpp | 29 ++--- .../b_jsonutil/b_jsonutil_test.cpp | 38 +++--- .../backup_utils/b_process/b_process_test.cpp | 20 ++-- utils/src/b_jsonutil/b_jsonutil.cpp | 12 +- 48 files changed, 523 insertions(+), 493 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index da9bf75da..bf6e14266 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -34,7 +34,7 @@ group("tgt_backup_sa") { ] } -group("tgt_backup_tests") { +group("backup_tests") { testonly = true deps = [ @@ -42,3 +42,9 @@ group("tgt_backup_tests") { "tests/unittests", ] } + +group("file_share_tests") { + testonly = true + + deps = [ "test/unittest" ] +} diff --git a/backup.gni b/backup.gni index 3b07587da..348cfa221 100644 --- a/backup.gni +++ b/backup.gni @@ -12,7 +12,7 @@ # limitations under the License. path_backup = "//foundation/filemanagement/app_file_service" -path_module_out_tests = "filemanagement/app_file_service/backup" +path_module_out_tests = "app_file_service/app_file_service/backup" path_ability_runtime = "//foundation/ability/ability_runtime" path_access_token = "//base/security/access_token" diff --git a/bundle.json b/bundle.json index 002d60fc6..8b177b5c5 100644 --- a/bundle.json +++ b/bundle.json @@ -164,8 +164,8 @@ ], "test": [ "//foundation/filemanagement/app_file_service/test/fuzztest:fuzztest", - "//foundation/filemanagement/app_file_service/test/unittest:unittest", - "//foundation/filemanagement/app_file_service:tgt_backup_tests" + "//foundation/filemanagement/app_file_service:file_share_tests", + "//foundation/filemanagement/app_file_service:backup_tests" ] } } diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 387297b51..0960d8c17 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -870,27 +870,12 @@ int ExtBackupJs::CallJsMethod(const std::string &funcName, InputArgsParser argParser, ResultValueParser retParser) { - uv_loop_s *loop = nullptr; - napi_status status = napi_get_uv_event_loop(jsRuntime.GetNapiEnv(), &loop); - if (status != napi_ok) { - HILOGE("failed to get uv event loop."); - return EINVAL; - } auto param = std::make_shared(funcName, &jsRuntime, jsObj, argParser, retParser); BExcepUltils::BAssert(param, BError::Codes::EXT_BROKEN_FRAMEWORK, "failed to new param."); - auto work = std::make_shared(); - BExcepUltils::BAssert(work, BError::Codes::EXT_BROKEN_FRAMEWORK, "failed to new uv_work_t."); - - work->data = reinterpret_cast(param.get()); HILOGI("Will execute current js method"); - auto task = [work {work.get()}]() { - if (work == nullptr) { - HILOGE("failed to get work."); - return; - } - HILOGI("AsyncWork Enter, %{public}zu", (size_t)work); - CallJsParam *param = reinterpret_cast(work->data); + auto task = [](void* ptr) ->void { + auto param = reinterpret_cast(ptr); do { if (param == nullptr) { HILOGE("failed to get CallJsParam."); @@ -906,9 +891,11 @@ int ExtBackupJs::CallJsMethod(const std::string &funcName, param->isReady.store(true); param->backupOperateCondition.notify_all(); }; - auto ret = napi_send_event(jsRuntime.GetNapiEnv(), task, napi_eprio_high); + uint64_t handleId = 0; + auto ret = napi_send_cancelable_event(jsRuntime.GetNapiEnv(), task, param.get(), napi_eprio_high, &handleId, + funcName.c_str()); if (ret != napi_status::napi_ok) { - HILOGE("failed to napi_send_event, ret:%{public}d.", ret); + HILOGE("failed to napi_send_cancelable_event, ret:%{public}d, name:%{public}s.", ret, funcName.c_str()); return EINVAL; } HILOGI("Wait execute current js method"); diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index f78ce3c9d..41b16c7e6 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -740,7 +740,7 @@ std::tuple UntarFile::GetLongName(uint32_t recLen, uint32_t al break; } string pathLen = content.substr(pos, lenEnd - pos); - int recLen = std::atoi(pathLen.c_str()); + size_t recLen = static_cast(std::atoi(pathLen.c_str())); string KvPair = content.substr(lenEnd + 1, recLen - (lenEnd - pos + 1)); size_t eqPos = KvPair.find('='); if (eqPos == string::npos) { diff --git a/interfaces/kits/js/backup/general_callbacks.cpp b/interfaces/kits/js/backup/general_callbacks.cpp index acf3bd5dd..e79d780bb 100644 --- a/interfaces/kits/js/backup/general_callbacks.cpp +++ b/interfaces/kits/js/backup/general_callbacks.cpp @@ -62,38 +62,28 @@ BackupRestoreCallback::~BackupRestoreCallback() } unique_ptr ptr(ctx_); - uv_loop_s *loop = nullptr; - napi_status status = napi_get_uv_event_loop(env_, &loop); - if (status != napi_ok) { - HILOGE("Failed to get uv event loop"); - ptr->cb_.CleanJsEnv(); - return; - } - - auto work = make_unique(); - if (work == nullptr) { - HILOGE("Failed to new uv_work_t"); - return; - } - work->data = static_cast(ctx_); - - auto task = [work {work.get()}]() { - if (work == nullptr) { - HILOGE("failed to get work."); + auto task = [](void* ptr) ->void { + auto ctx = reinterpret_cast(ptr); + if (ctx == nullptr) { + HILOGE("failed to get ctx."); return; } - LibN::NAsyncContextCallback *ctx = static_cast(work->data); HILOGI("BackupRestoreCallback destruct delete ctx"); + if (bool(ctx->cb_)) { + ctx->cb_.CleanJsEnv(); + } delete ctx; - delete work; }; - auto ret = napi_send_event(env_, task, napi_eprio_high); + uint64_t handleId = 0; + auto ret = napi_send_cancelable_event(env_, task, ptr.get(), napi_eprio_high, &handleId, "destructor"); if (ret != napi_status::napi_ok) { - HILOGE("Failed to call napi_send_event, ret:%{public}d, status:%{public}d", ret, status); + HILOGE("failed to napi_send_cancelable_event, ret:%{public}d, name:%{public}s.", ret, "destructor"); + if (bool(ctx_->cb_)) { + ctx_->cb_.CleanJsEnv(); + } return; } ptr.release(); - work.release(); ctx_ = nullptr; HILOGI("BackupRestoreCallback destruct end"); } @@ -128,12 +118,12 @@ static void DoCallJsMethod(napi_env env, void *data, InputArgsParser argParser) } napi_value global = nullptr; napi_get_global(env, &global); - napi_value callback = ctx->cb_.Deref(env).val_; if (!bool(ctx->cb_)) { HILOGE("Failed to get ref."); napi_close_handle_scope(env, scope); return; } + napi_value callback = ctx->cb_.Deref(env).val_; napi_value result = nullptr; napi_status status = napi_call_function(env, global, callback, argv.size(), argv.data(), &result); if (status != napi_ok) { @@ -146,29 +136,16 @@ static void DoCallJsMethod(napi_env env, void *data, InputArgsParser argParser) void BackupRestoreCallback::CallJsMethod(InputArgsParser argParser) { HILOGI("call BackupRestoreCallback CallJsMethod begin."); - uv_loop_s *loop = nullptr; - napi_status status = napi_get_uv_event_loop(env_, &loop); - if (status != napi_ok) { - HILOGE("failed to get uv event loop."); - return; - } auto workArgs = make_shared(); - auto work = make_unique(); - if (workArgs == nullptr || work == nullptr) { + if (workArgs == nullptr) { HILOGE("failed to new workArgs or uv_work_t."); return; } workArgs->ptr = this; workArgs->argParser = argParser; - work->data = reinterpret_cast(workArgs.get()); HILOGI("Will execute current js method"); - auto task = [work {work.get()}]() { - if (work == nullptr) { - HILOGE("failed to get work."); - return; - } - HILOGI("AsyncWork Enter, %{public}zu", (size_t)work); - auto workArgs = reinterpret_cast(work->data); + auto task = [](void* ptr) ->void { + auto workArgs = reinterpret_cast(ptr); do { if (workArgs == nullptr) { HILOGE("failed to get workArgs."); @@ -180,18 +157,16 @@ void BackupRestoreCallback::CallJsMethod(InputArgsParser argParser) std::unique_lock lock(workArgs->callbackMutex); workArgs->isReady.store(true); workArgs->callbackCondition.notify_all(); - delete work; }; - auto ret = napi_send_event(env_, task, napi_eprio_high); + uint64_t handleId = 0; + auto ret = napi_send_cancelable_event(env_, task, workArgs.get(), napi_eprio_high, &handleId, "jsmethod"); if (ret != napi_status::napi_ok) { - HILOGE("failed to napi_send_event, ret:%{public}d.", ret); - work.reset(); + HILOGE("failed to napi_send_cancelable_event, ret:%{public}d, name:%{public}s.", ret, "jsmethod"); return; } std::unique_lock lock(workArgs->callbackMutex); HILOGI("Wait execute callback method end"); workArgs->callbackCondition.wait(lock, [workArgs]() { return workArgs->isReady.load(); }); - work.release(); HILOGI("call BackupRestoreCallback CallJsMethod end."); } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index ee0c14adc..f331a15f3 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -379,8 +379,8 @@ napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info .onProcess = bind(OnProcess, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupSizeReport = bind(OnBackupSizeReport, backupEntity->callbacks, placeholders::_1)}, errMsg, errCode); if (!backupEntity->session) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index d3a84c628..5d61b6db4 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -382,8 +382,8 @@ napi_value SessionIncrementalBackupNExporter::Constructor(napi_env env, napi_cal .onProcess = bind(OnProcess, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupSizeReport = bind(OnBackupSizeReport, backupEntity->callbacks, placeholders::_1)}, errMsg, errCode); if (!backupEntity->session) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 23df85f3d..bb507b410 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -469,8 +469,8 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks), .onProcess = bind(OnProcess, restoreEntity->callbacks, placeholders::_1, placeholders::_2)}, errMsg, errCode); if (!restoreEntity->sessionSheet) { - std::tuple errInfo = - std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode) + ", " + errMsg); + std::tuple errInfo = (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) ? + std::make_tuple(errCode, errMsg) : std::make_tuple(errCode, BError::GetBackupMsgByErrno(errCode)); ErrParam errorParam = [ errInfo ]() { return errInfo;}; NError(errorParam).ThrowErr(env); return nullptr; diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 12a70dd62..bf1a73223 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -34,6 +34,7 @@ #include "module_ipc/service.h" #include "module_ipc/svc_session_manager.h" #include "module_sched/sched_scheduler.h" +#include "parameters.h" #include "status_receiver_host.h" #include "system_ability_definition.h" #include "if_system_ability_manager.h" @@ -47,6 +48,7 @@ const string HMOS_HAP_CODE_PATH = "1"; const string LINUX_HAP_CODE_PATH = "2"; const string MEDIA_LIBRARY_HAP = "com.ohos.medialibrary.medialibrarydata"; const string EXTERNAL_FILE_HAP = "com.ohos.UserFile.ExternalFileManager"; +const string APP_GALLERY_BUNDLE_NAME = "const.appgallery.shaderowner.bundlename"; const int E_ERR = -1; const vector dataDir = {"app", "local", "distributed", "database", "cache"}; } // namespace @@ -152,11 +154,8 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto string BundleMgrAdapter::GetAppGalleryBundleName() { - auto bms = GetBundleManager(); - - string bundleName = ""; - auto ret = bms->QueryAppGalleryBundleName(bundleName); - if (!ret) { + string bundleName = OHOS::system::GetParameter(APP_GALLERY_BUNDLE_NAME, ""); + if (bundleName.empty()) { HILOGI("Get App Gallery BundleName fail!"); } else { HILOGI("App Gallery BundleName: %{public}s", bundleName.c_str()); diff --git a/test/unittest/file_permission_native/BUILD.gn b/test/unittest/file_permission_native/BUILD.gn index bef7bfa9c..bb78d1e47 100644 --- a/test/unittest/file_permission_native/BUILD.gn +++ b/test/unittest/file_permission_native/BUILD.gn @@ -24,7 +24,7 @@ ohos_unittest("file_permission_test") { blocklist = "${app_file_service_path}/cfi_blocklist.txt" } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" include_dirs = [ "include", "${app_file_service_path}/tests/mock/file_permission_native/include", diff --git a/test/unittest/file_share_native/BUILD.gn b/test/unittest/file_share_native/BUILD.gn index e5feaa091..745736a50 100644 --- a/test/unittest/file_share_native/BUILD.gn +++ b/test/unittest/file_share_native/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("file_share_test") { debug = false } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" resource_config_file = "../resource/ohos_test.xml" sources = [ "file_share_test.cpp" ] diff --git a/test/unittest/file_share_ndk_test/file_share_permission_sup_test/BUILD.gn b/test/unittest/file_share_ndk_test/file_share_permission_sup_test/BUILD.gn index 5d75c18f5..662683f46 100644 --- a/test/unittest/file_share_ndk_test/file_share_permission_sup_test/BUILD.gn +++ b/test/unittest/file_share_ndk_test/file_share_permission_sup_test/BUILD.gn @@ -24,7 +24,7 @@ ohos_unittest("file_share_permission_ndk_sup_test") { blocklist = "${app_file_service_path}/cfi_blocklist.txt" } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" include_dirs = [ "include", "${app_file_service_path}/interfaces/kits/ndk/fileshare/include", diff --git a/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn b/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn index 88e9a42ec..ad79bbed7 100644 --- a/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn +++ b/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn @@ -23,7 +23,7 @@ ohos_unittest("file_share_permission_ndk_test") { debug = false } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" include_dirs = [ "include", "${app_file_service_path}/interfaces/kits/ndk/fileshare/include", diff --git a/test/unittest/file_uri_native/BUILD.gn b/test/unittest/file_uri_native/BUILD.gn index 447faf2f7..96ab25bbf 100644 --- a/test/unittest/file_uri_native/BUILD.gn +++ b/test/unittest/file_uri_native/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("file_uri_test") { debug = false } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" resource_config_file = "../resource/ohos_test.xml" sources = [ "file_uri_test.cpp" ] diff --git a/test/unittest/file_uri_ndk_test/BUILD.gn b/test/unittest/file_uri_ndk_test/BUILD.gn index 006bc9fa0..577727daf 100644 --- a/test/unittest/file_uri_ndk_test/BUILD.gn +++ b/test/unittest/file_uri_ndk_test/BUILD.gn @@ -23,7 +23,7 @@ ohos_unittest("file_uri_ndk_test") { debug = false } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" include_dirs = [ "include", "${app_file_service_path}/interfaces/kits/ndk/fileuri/include", diff --git a/test/unittest/js_file_permission_test/permission/BUILD.gn b/test/unittest/js_file_permission_test/permission/BUILD.gn index 2073c5c28..b76e94fdb 100644 --- a/test/unittest/js_file_permission_test/permission/BUILD.gn +++ b/test/unittest/js_file_permission_test/permission/BUILD.gn @@ -13,7 +13,7 @@ import("//build/test.gni") ohos_js_unittest("FileShareTestPermission") { - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" hap_profile = "./config.json" diff --git a/test/unittest/js_file_uri_test/BUILD.gn b/test/unittest/js_file_uri_test/BUILD.gn index 3a1d2cb6e..5242b2e55 100644 --- a/test/unittest/js_file_uri_test/BUILD.gn +++ b/test/unittest/js_file_uri_test/BUILD.gn @@ -13,7 +13,7 @@ import("//build/test.gni") ohos_js_unittest("FileUriTest") { - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" hap_profile = "./config.json" diff --git a/test/unittest/remote_file_share/BUILD.gn b/test/unittest/remote_file_share/BUILD.gn index 13ca80d73..2c1246947 100644 --- a/test/unittest/remote_file_share/BUILD.gn +++ b/test/unittest/remote_file_share/BUILD.gn @@ -23,7 +23,7 @@ ohos_unittest("remote_file_share_test") { debug = false } - module_out_path = "filemanagement/app_file_service" + module_out_path = "app_file_service/app_file_service/file_share" fuzz_config_file = "${app_file_service_path}/test/fuzztest/remotefileshare_fuzzer" resource_config_file = "../resource/ohos_test.xml" diff --git a/tests/mock/napi/include/napi_mock.h b/tests/mock/napi/include/napi_mock.h index 907a39ebc..68716848b 100644 --- a/tests/mock/napi/include/napi_mock.h +++ b/tests/mock/napi/include/napi_mock.h @@ -31,12 +31,12 @@ class Napi { public: virtual ~Napi() = default; public: - virtual napi_status napi_get_uv_event_loop(napi_env, struct uv_loop_s**) = 0; virtual napi_status napi_call_function(napi_env, napi_value, napi_value, size_t, const napi_value*, napi_value*) = 0; virtual napi_status napi_get_reference_value(napi_env, napi_ref, napi_value*) = 0; virtual napi_status napi_get_named_property(napi_env, napi_value, const char*, napi_value*) = 0; - virtual napi_status napi_send_event(napi_env, const std::function, napi_event_priority) = 0; + virtual napi_status napi_send_cancelable_event(napi_env, const std::function&, void*, + napi_event_priority, uint64_t*, const char*) = 0; virtual napi_status napi_get_value_int32(napi_env, napi_value, int32_t*) = 0; virtual napi_status napi_get_value_int64(napi_env, napi_value, int64_t*) = 0; virtual napi_status napi_create_string_utf8(napi_env, const char*, size_t, napi_value*) = 0; @@ -68,12 +68,12 @@ public: class NapiMock : public Napi { public: - MOCK_METHOD(napi_status, napi_get_uv_event_loop, (napi_env, struct uv_loop_s**)); MOCK_METHOD(napi_status, napi_call_function, (napi_env, napi_value, napi_value, size_t, const napi_value*, napi_value*)); MOCK_METHOD(napi_status, napi_get_reference_value, (napi_env, napi_ref, napi_value*)); MOCK_METHOD(napi_status, napi_get_named_property, (napi_env, napi_value, const char*, napi_value*)); - MOCK_METHOD(napi_status, napi_send_event, (napi_env, const std::function, napi_event_priority)); + MOCK_METHOD(napi_status, napi_send_cancelable_event, (napi_env, (const std::function&), void*, + napi_event_priority, uint64_t*, const char*)); MOCK_METHOD(napi_status, napi_get_value_int32, (napi_env, napi_value, int32_t*)); MOCK_METHOD(napi_status, napi_get_value_int64, (napi_env, napi_value, int64_t*)); MOCK_METHOD(napi_status, napi_create_int64, (napi_env, int64_t, napi_value*)); diff --git a/tests/mock/napi/src/napi_mock.cpp b/tests/mock/napi/src/napi_mock.cpp index 5274eecb4..d57634b32 100644 --- a/tests/mock/napi/src/napi_mock.cpp +++ b/tests/mock/napi/src/napi_mock.cpp @@ -16,14 +16,11 @@ #include "napi_mock.h" #include "uv.h" -napi_status napi_send_event(napi_env env, const std::function cb, napi_event_priority priority) +napi_status napi_send_cancelable_event(napi_env env, const std::function& cb, void* data, + napi_event_priority priority, uint64_t* handleId, const char* name) { - return OHOS::FileManagement::Backup::Napi::napi->napi_send_event(env, cb, priority); -} - -napi_status napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop) -{ - return OHOS::FileManagement::Backup::Napi::napi->napi_get_uv_event_loop(env, loop); + return OHOS::FileManagement::Backup::Napi::napi->napi_send_cancelable_event(env, cb, data, priority, handleId, + name); } napi_status napi_call_function(napi_env env, napi_value recv, napi_value func, size_t argc, const napi_value* argv, diff --git a/tests/moduletests/backup_tool/tool_help_test.cpp b/tests/moduletests/backup_tool/tool_help_test.cpp index 26ad00ab1..3b6dc6cbd 100644 --- a/tests/moduletests/backup_tool/tool_help_test.cpp +++ b/tests/moduletests/backup_tool/tool_help_test.cpp @@ -35,7 +35,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(ToolsTest, tool_help_0100, testing::ext::TestSize.Level0) +HWTEST_F(ToolsTest, tool_help_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ToolsTest-begin tool_help_0100"; try { @@ -60,7 +60,7 @@ HWTEST_F(ToolsTest, tool_help_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(ToolsTest, tool_help_0200, testing::ext::TestSize.Level0) +HWTEST_F(ToolsTest, tool_help_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ToolsTest-begin tool_help_0200"; try { diff --git a/tests/unittests/BUILD.gn b/tests/unittests/BUILD.gn index 082474e55..2467ce9a4 100644 --- a/tests/unittests/BUILD.gn +++ b/tests/unittests/BUILD.gn @@ -21,7 +21,7 @@ group("unittests") { "backup_api:backup_api_test", "backup_ext:backup_ext_test", "backup_sa:backup_sa_test", - "backup_tools:backup_test", - "backup_utils:backup_test", + "backup_tools:backup_tools_test", + "backup_utils:backup_utils_test", ] } diff --git a/tests/unittests/backup_ext/ext_backup_js_test.cpp b/tests/unittests/backup_ext/ext_backup_js_test.cpp index 3cad9f934..c55a76ae4 100644 --- a/tests/unittests/backup_ext/ext_backup_js_test.cpp +++ b/tests/unittests/backup_ext/ext_backup_js_test.cpp @@ -988,17 +988,10 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsMethod_0100, testing::ext::Tes { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsMethod_0100"; try { - extBackupJs->jsObj_ = make_unique(); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); EXPECT_EQ(ret, EINVAL); - - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); - EXPECT_EQ(ret, EINVAL); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ExtBackupJsTest-an exception occurred by CallJsMethod."; @@ -1209,26 +1202,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0100, testing::ext: { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsOnBackupEx_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsOnBackupEx(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsOnBackupEx(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1253,13 +1239,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0200, testing::ext: try { extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1282,25 +1267,18 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0100, testing::ext::T { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsOnBackup_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsOnBackup(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsOnBackup(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1325,13 +1303,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0200, testing::ext::T try { extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1354,26 +1331,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestoreEx_0100, testing::ext:: { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJSRestoreEx_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJSRestoreEx(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJSRestoreEx(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJSRestoreEx(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJSRestoreEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1398,13 +1368,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestoreEx_0200, testing::ext:: try { extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJSRestoreEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1427,25 +1396,18 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestore_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJSRestore_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJSRestore(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJSRestore(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJSRestore(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJSRestore(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1470,13 +1432,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestore_0200, testing::ext::Te try { extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJSRestore(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1499,18 +1460,11 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_GetBackupInfo_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_GetBackupInfo_0100"; try { - extBackupJs->jsObj_ = make_unique(); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){}); - EXPECT_EQ(ret, EINVAL); - EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){}); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); } catch (...) { EXPECT_TRUE(false); @@ -1535,21 +1489,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_GetBackupInfo_0200, testing::ext::Te extBackupJs->jsObj_ = make_unique(); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_ok)) .WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1572,18 +1524,11 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_OnProcess_0100, testing::ext::TestSi { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_OnProcess_0100"; try { - extBackupJs->jsObj_ = make_unique(); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->OnProcess([](ErrCode, std::string){}); - EXPECT_EQ(ret, EINVAL); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->OnProcess([](ErrCode, std::string){}); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->OnProcess([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); } catch (...) { EXPECT_TRUE(false); @@ -1606,18 +1551,16 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_OnProcess_0200, testing::ext::TestSi GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_OnProcess_0200"; try { EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_ok)) .WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->OnProcess([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->OnProcess([](ErrCode, std::string){}); EXPECT_EQ(ret, EINVAL); } catch (...) { diff --git a/tests/unittests/backup_ext/ext_extension_test.cpp b/tests/unittests/backup_ext/ext_extension_test.cpp index 204661ec8..ca36c7b7c 100644 --- a/tests/unittests/backup_ext/ext_extension_test.cpp +++ b/tests/unittests/backup_ext/ext_extension_test.cpp @@ -592,4 +592,66 @@ HWTEST_F(ExtExtensionTest, Ext_Extension_Test_1000, testing::ext::TestSize.Level } GTEST_LOG_(INFO) << "ExtExtensionTest-end Ext_Extension_Test_1000"; } + +/** + * @tc.number: SUB_Ext_Extension_1100 + * @tc.name: Ext_Extension_Test_1100 + * @tc.desc: 测试 GetFileHandleForSpecialCloneCloud + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9P3Y3 + */ +HWTEST_F(ExtExtensionTest, Ext_Extension_Test_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ExtExtensionTest-begin Ext_Extension_Test_1100"; + try { + ErrCode errCode = ERR_OK; + int64_t cost = 0; + uint32_t includeNum = 0; + uint32_t excludeNum = 0; + AppRadar::DoBackupInfo backupInfo = {cost, 0, 0, 0, includeNum, excludeNum}; + RecordDoBackupRes(BUNDLE_NAME, errCode, backupInfo); + + cost = BConstants::MAX_TIME_COST; + includeNum = BConstants::MAX_INEXCLUDE_SIZE; + backupInfo = {cost, 0, 0, 0, includeNum, excludeNum}; + RecordDoBackupRes(BUNDLE_NAME, errCode, backupInfo); + + errCode = BError(BError::Codes::EXT_BROKEN_IPC); + RecordDoBackupRes(BUNDLE_NAME, errCode, backupInfo); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ExtExtensionTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ExtExtensionTest-end Ext_Extension_Test_1100"; +} + +/** + * @tc.number: SUB_Ext_Extension_1200 + * @tc.name: Ext_Extension_Test_1200 + * @tc.desc: 测试 GetFileHandleForSpecialCloneCloud + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9P3Y3 + */ +HWTEST_F(ExtExtensionTest, Ext_Extension_Test_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ExtExtensionTest-begin Ext_Extension_Test_1200"; + try { + const string fileName = "1.txt"; + string tarName = "2.tar"; + auto ret = GetIncrementalFileHandlePath(fileName, BUNDLE_NAME, tarName); + EXPECT_NE(ret, ERR_OK); + ret = GetIncrementalFileHandlePath(fileName, BConstants::BUNDLE_FILE_MANAGER, tarName); + EXPECT_NE(ret, ERR_OK); + ret = GetIncrementalFileHandlePath(fileName, BConstants::BUNDLE_MEDIAL_DATA, tarName); + EXPECT_NE(ret, ERR_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ExtExtensionTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ExtExtensionTest-end Ext_Extension_Test_1200"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_ext/external_ext_backup_js_test.cpp b/tests/unittests/backup_ext/external_ext_backup_js_test.cpp index 79d551a7c..139ebbb64 100644 --- a/tests/unittests/backup_ext/external_ext_backup_js_test.cpp +++ b/tests/unittests/backup_ext/external_ext_backup_js_test.cpp @@ -816,16 +816,9 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsMethod_0100, testing::ext::Tes { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsMethod_0100"; try { - extBackupJs->jsObj_ = make_unique(); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); - EXPECT_EQ(ret, EINVAL); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); EXPECT_EQ(ret, EINVAL); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_ext/tests/unittests/backup_ext/ext_backup_js_external_test.cpp b/tests/unittests/backup_ext/tests/unittests/backup_ext/ext_backup_js_external_test.cpp index c9b08a3b4..13f224829 100644 --- a/tests/unittests/backup_ext/tests/unittests/backup_ext/ext_backup_js_external_test.cpp +++ b/tests/unittests/backup_ext/tests/unittests/backup_ext/ext_backup_js_external_test.cpp @@ -817,15 +817,9 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsMethod_0100, testing::ext::Tes GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsMethod_0100"; try { extBackupJs->jsObj_ = make_unique(); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); - EXPECT_EQ(ret, EINVAL); - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr); EXPECT_EQ(ret, EINVAL); } catch (...) { EXPECT_TRUE(false); @@ -1059,26 +1053,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0100, testing::ext: { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsOnBackupEx_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsOnBackupEx(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsOnBackupEx(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1103,13 +1090,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0200, testing::ext: try { extBackupJs->callbackInfoEx_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJsOnBackupEx(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1132,25 +1118,18 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0100, testing::ext::T { GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_CallJsOnBackup_0100"; try { - EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); - auto ret = extBackupJs->CallJsOnBackup(); - EXPECT_EQ(ret, EINVAL); - extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); - ret = extBackupJs->CallJsOnBackup(); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); + auto ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); } catch (...) { @@ -1175,13 +1154,12 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0200, testing::ext::T try { extBackupJs->callbackInfo_ = std::make_shared([](ErrCode, std::string){}); EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr)); - EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_is_promise(_, _, _)) .WillOnce(DoAll(SetArgPointee(true), Return(napi_ok))); EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok)); EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg)); - EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg)); + EXPECT_CALL(*napiMock, napi_send_cancelable_event(_, _, _, _, _, _)).WillOnce(Return(napi_invalid_arg)); auto ret = extBackupJs->CallJsOnBackup(); EXPECT_EQ(ret, EINVAL); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 3cb7407dd..83c6b708a 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -1832,7 +1832,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_CancelTask_0100, TestSiz service->CancelTask("", service); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)).WillOnce(Return(nullptr)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, HandleClear()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(false)); @@ -1938,7 +1938,6 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0100, TestSize.Le EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::Codes::OK).GetCode()); } catch (...) { 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 79b53f0e6..35d3b3f4d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -615,8 +615,6 @@ HWTEST_F(ServiceTest, SUB_Service_VerifyCaller_0100, TestSize.Level1) .WillOnce(Return(Security::AccessToken::PermissionState::PERMISSION_GRANTED)); EXPECT_CALL(*token, IsSystemAppByFullTokenID(_)).WillOnce(Return(false)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); ret = service->VerifyCaller(); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -1311,7 +1309,6 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0200, TestSize.Level1) EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->AppDone(errCode); EXPECT_NE(ret, BError(BError::Codes::OK)); } catch (...) { @@ -1342,20 +1339,17 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, TestSize.Level1) senario = BackupRestoreScenario::FULL_RESTORE; EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->HandleCurBundleEndWork(bundleName, senario); EXPECT_TRUE(true); } catch (...) { @@ -1447,8 +1441,6 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL)); @@ -1467,8 +1459,6 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL)); } catch (...) { @@ -1757,7 +1747,6 @@ HWTEST_F(ServiceTest, SUB_Service_SADone_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SADone_0000"; try { EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->SADone(0, ""); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1775,7 +1764,6 @@ HWTEST_F(ServiceTest, SUB_Service_SADone_0000, TestSize.Level1) EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SADone(0, ""); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1809,7 +1797,6 @@ HWTEST_F(ServiceTest, SUB_Service_NotifyCallerCurAppDone_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); service->NotifyCallerCurAppDone(0, ""); @@ -1946,8 +1933,6 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0000, TestSize.Level1) shared_ptr sa = nullptr; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->DoTimeout(service, bundleName); @@ -1975,8 +1960,6 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0100, TestSize.Level1) string bundleName; shared_ptr sa = nullptr; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->DoTimeout(service, bundleName); diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index f712b7497..8c05e2e5c 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -192,7 +192,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -204,7 +203,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); + ret = service->InitRestoreSession(nullptr, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -247,7 +246,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -292,7 +290,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -303,7 +300,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); @@ -505,7 +501,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_PublishFile_0100, testing::ext::Tes EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE)); EXPECT_CALL(*token, VerifyAccessToken(_, _)) .WillOnce(Return(Security::AccessToken::PermissionState::PERMISSION_DENIED)); - EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); ret = service->PublishFile(fileInfo); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_PublishFile_0100"; @@ -535,15 +530,11 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te auto ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)) - .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")); + EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -573,7 +564,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppDone_0100, testing::ext::TestSiz EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->AppDone(0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { @@ -660,9 +650,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing EXPECT_CALL(*sessionMock, GetScenario()) .WillOnce(Return(IServiceReverse::Scenario::CLEAN)) .WillOnce(Return(IServiceReverse::Scenario::CLEAN)); - EXPECT_CALL(*sessionMock, VerifyBundleName(_)) - .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))) - .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); + EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*sessionMock, StopFwkTimer(_)).WillOnce(Invoke([]() { throw BError(BError::Codes::EXT_THROW_EXCEPTION); return true; @@ -738,9 +726,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_NoticeClientFinish_0100, testing::e EXPECT_NE(service, nullptr); string bundleName; ErrCode errCode = 0; - EXPECT_CALL(*sessionMock, GetScenario()) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, errCode); EXPECT_TRUE(true); @@ -811,11 +797,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetBackupInfo_0100, testing::ext::T EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - EXPECT_CALL(*sessionMock, GetImpl()).WillOnce(Invoke([]() { - throw "未知错误"; - return SvcSessionManager::Impl(); - })); - EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); auto ret = service->GetBackupInfo(bundleName, result); EXPECT_NE(ret, EPERM); } catch (...) { @@ -1022,8 +1003,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->InitIncrementalBackupSession(reverse); @@ -1058,10 +1037,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -1070,10 +1047,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); @@ -1082,8 +1057,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); @@ -1219,15 +1192,11 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi auto ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)) - .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")); + EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); @@ -1252,31 +1221,21 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalDone_0100, testing::e GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppIncrementalDone_0100"; try { EXPECT_NE(service, nullptr); - EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)) - .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")); + EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->AppIncrementalDone(0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)) - .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)) .WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")) - .WillOnce(Return("bundleName")); + EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->AppIncrementalDone(0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { @@ -1304,18 +1263,12 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetIncrementalFileHandle_0100, test string fileName; 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)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce( Return(BError(BError::Codes::SDK_MIXED_SCENARIO))); auto ret = service->GetIncrementalFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::SDK_MIXED_SCENARIO).GetCode()); 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)); - EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce( Return(BError(BError::Codes::SA_REFUSED_ACT))); ret = service->GetIncrementalFileHandle(bundleName, fileName); 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 fd9a45968..6e3a6b114 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -31,10 +31,6 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurGroupBackupInfos_0000, TestSize.Level map> bundleNameDetailMap; map isClearDataFlags; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); - EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*jsonUtil, FindBundleInfoByName(_, _, _, _)).WillOnce(Return(false)); service->HandleCurGroupBackupInfos(backupInfos, bundleNameDetailMap, isClearDataFlags); EXPECT_TRUE(true); @@ -352,7 +348,6 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); @@ -389,7 +384,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -402,7 +396,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -416,7 +409,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -450,35 +442,23 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) service->ExtStart(callName); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); - EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtStart(callName); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); - EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtStart(callName); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtStart(callName); EXPECT_TRUE(true); } catch (...) { @@ -523,8 +503,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtStart(callName); @@ -539,8 +517,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); service->ExtStart(callName); EXPECT_TRUE(true); @@ -655,13 +631,11 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NoticeClientFinish_0000"; try { string bundleName; - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); @@ -670,7 +644,6 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); @@ -680,7 +653,6 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); @@ -709,7 +681,6 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NoticeClientFinish_0100"; try { string bundleName; - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); @@ -719,7 +690,6 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); - EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); @@ -749,7 +719,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDone_0000, TestSize.Level1) try { EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::WAIT)); - EXPECT_CALL(*cdConfig, InsertClearBundleRecord(_)).WillOnce(Return(true)); service->ExtConnectDone(""); EXPECT_TRUE(true); @@ -764,7 +733,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDone_0000, TestSize.Level1) EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::START)); EXPECT_CALL(*cdConfig, FindClearBundleRecord(_)).WillOnce(Return(false)); - EXPECT_CALL(*cdConfig, InsertClearBundleRecord(_)).WillOnce(Return(true)); service->ExtConnectDone(""); EXPECT_TRUE(true); } catch (...) { @@ -1140,6 +1108,11 @@ HWTEST_F(ServiceTest, SUB_Service_TryToClearDispose_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TryToClearDispose_0000"; try { BundleName bundleName; + EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); + service->TryToClearDispose(bundleName); + EXPECT_TRUE(true); + + bundleName = "100-test"; EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); service->TryToClearDispose(bundleName); @@ -1180,7 +1153,7 @@ HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0000, TestSize.Level1) service->SendErrAppGalleryNotify(); EXPECT_TRUE(true); - bundleNameList.emplace_back("bundleName"); + bundleNameList.emplace_back("100-bundleName"); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); @@ -1212,7 +1185,7 @@ HWTEST_F(ServiceTest, SUB_Service_ClearDisposalOnSaStart_0000, TestSize.Level1) service->ClearDisposalOnSaStart(); EXPECT_TRUE(true); - bundleNameList.emplace_back("bundleName"); + bundleNameList.emplace_back("100-bundleName"); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); @@ -1495,13 +1468,9 @@ HWTEST_F(ServiceTest, SUB_Service_TimeoutRadarReport_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TimeoutRadarReport_0000"; try { string bundleName; - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); service->TimeoutRadarReport(IServiceReverse::Scenario::BACKUP, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); service->TimeoutRadarReport(IServiceReverse::Scenario::RESTORE, bundleName); EXPECT_TRUE(true); @@ -1573,7 +1542,6 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupDataSize_0000, TestSize.Level1) service->session_ = session_; EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE)); - EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*token, VerifyAccessToken(_, _)) .WillOnce(Return(Security::AccessToken::PermissionState::PERMISSION_DENIED)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) @@ -1581,12 +1549,8 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupDataSize_0000, TestSize.Level1) ret = service->GetBackupDataSize(isPreciseScan, bundleNameList); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - 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)); - EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); ret = service->GetBackupDataSize(isPreciseScan, bundleNameList); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { @@ -1813,13 +1777,9 @@ HWTEST_F(ServiceTest, SUB_Service_GetPrecisesSize_0100, TestSize.Level1) dataTwo.bundleName = BUNDLE_NAME; dataTwo.lastIncrementalTime = 1; bundleNameListTwo.push_back(dataTwo); - EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)) - .WillOnce(Return(info)).WillOnce(Return(info)); - EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)).WillOnce(Return(0)) - .WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); + EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); service->GetPrecisesSize(bundleNameListTwo, scanning); EXPECT_EQ(service->bundleDataSizeList_.size(), 0); diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index 00fb5bd64..54519072f 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -2091,5 +2091,114 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Exception_0200, testing::e } GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_Exception_0200"; } + +/** + * @tc.number: SUB_backup_sa_session_Exception_0300 + * @tc.name: SUB_backup_sa_session_Exception_0300 + * @tc.desc: 测试 Exception + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Exception_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_Exception_0300"; + try { + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + + sessionManagerPtr_->SetOldBackupVersion(""); + EXPECT_TRUE(true); + + auto result = sessionManagerPtr_->GetOldBackupVersion(); + EXPECT_EQ(result, ""); + + sessionManagerPtr_->SetIsReadyLaunch(BUNDLE_NAME); + EXPECT_TRUE(true); + + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + bool stopFwkTimer = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME); + EXPECT_EQ(stopFwkTimer, false); + + bool stopExtTimer = sessionManagerPtr_->StopExtTimer(BUNDLE_NAME); + EXPECT_EQ(stopExtTimer, false); + + BIncrementalData incrementalData; + sessionManagerPtr_->SetIncrementalData(incrementalData); + EXPECT_TRUE(true); + + int32_t manifestFd = sessionManagerPtr_->GetIncrementalManifestFd(BUNDLE_NAME); + EXPECT_EQ(manifestFd, BConstants::INVALID_FD_NUM); + + int64_t lastIncrementalTime = sessionManagerPtr_->GetLastIncrementalTime(BUNDLE_NAME); + EXPECT_EQ(lastIncrementalTime, 0); + + uint32_t timeout = sessionManagerPtr_->GetTimeoutValue(BUNDLE_NAME); + EXPECT_EQ(timeout, BConstants::TIMEOUT_INVALID); + + sessionManagerPtr_->SetPublishFlag(BUNDLE_NAME); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by Exception."; + } + GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_Exception_0300"; +} + +/** + * @tc.number: SUB_backup_sa_session_GetSessionCallerName_0100 + * @tc.name: SUB_backup_sa_session_GetSessionCallerName_0100 + * @tc.desc: 测试 GetSessionCallerName + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetSessionCallerName_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetSessionCallerName_0100"; + try { + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto result = sessionManagerPtr_->GetSessionCallerName(); + EXPECT_EQ(result, ""); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + result = sessionManagerPtr_->GetSessionCallerName(); + EXPECT_EQ(result, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetSessionCallerName."; + } + GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetSessionCallerName_0100"; +} + +/** + * @tc.number: SUB_backup_sa_session_GetSessionActiveTime_0100 + * @tc.name: SUB_backup_sa_session_GetSessionActiveTime_0100 + * @tc.desc: 测试 GetSessionActiveTime + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetSessionActiveTime_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetSessionActiveTime_0100"; + try { + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto result = sessionManagerPtr_->GetSessionActiveTime(); + EXPECT_EQ(result, ""); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + result = sessionManagerPtr_->GetSessionActiveTime(); + EXPECT_EQ(result, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetSessionActiveTime."; + } + GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetSessionActiveTime_0100"; +} #include "svc_session_manager_ex_test.cpp" } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h index 53c8e8783..0db15eab6 100644 --- a/tests/unittests/backup_sa/session/service_client_mock.h +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -30,4 +30,4 @@ public: MOCK_METHOD0(Start, ErrCode()); }; } // End of namespace OHOS::FileManagement::Backup -#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H \ No newline at end of file diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 7cc90eda8..2fa914802 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -153,7 +153,7 @@ ohos_unittest("backup_tool_restore_test") { use_exceptions = true } -group("backup_test") { +group("backup_tools_test") { testonly = true deps = [ diff --git a/tests/unittests/backup_utils/BUILD.gn b/tests/unittests/backup_utils/BUILD.gn index 4a16ef68c..9825597ba 100644 --- a/tests/unittests/backup_utils/BUILD.gn +++ b/tests/unittests/backup_utils/BUILD.gn @@ -395,7 +395,7 @@ ohos_unittest("b_json_clear_data_test") { use_exceptions = true } -group("backup_test") { +group("backup_utils_test") { testonly = true deps = [ diff --git a/tests/unittests/backup_utils/b_anony/b_anony_test.cpp b/tests/unittests/backup_utils/b_anony/b_anony_test.cpp index fbe16d220..382eebb6d 100644 --- a/tests/unittests/backup_utils/b_anony/b_anony_test.cpp +++ b/tests/unittests/backup_utils/b_anony/b_anony_test.cpp @@ -36,7 +36,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BAnonyTest, b_anony_GetAnonyPath_0100, testing::ext::TestSize.Level0) +HWTEST_F(BAnonyTest, b_anony_GetAnonyPath_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BAnonyTest-begin b_anony_GetAnonyPath_0100"; try { diff --git a/tests/unittests/backup_utils/b_error/b_error_test.cpp b/tests/unittests/backup_utils/b_error/b_error_test.cpp index 861f6440a..2466b8b49 100644 --- a/tests/unittests/backup_utils/b_error/b_error_test.cpp +++ b/tests/unittests/backup_utils/b_error/b_error_test.cpp @@ -36,7 +36,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0100"; try { @@ -57,7 +57,7 @@ HWTEST_F(BErrorTest, b_error_construction_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0300, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0300"; try { @@ -79,7 +79,7 @@ HWTEST_F(BErrorTest, b_error_construction_0300, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0500, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0500"; try { @@ -102,7 +102,7 @@ HWTEST_F(BErrorTest, b_error_construction_0500, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0700, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0700, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0700"; try { @@ -125,7 +125,7 @@ HWTEST_F(BErrorTest, b_error_construction_0700, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0900, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0900, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0900"; try { @@ -148,7 +148,7 @@ HWTEST_F(BErrorTest, b_error_construction_0900, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0200"; try { @@ -171,7 +171,7 @@ HWTEST_F(BErrorTest, b_error_construction_0200, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_construction_0400, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_construction_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0400"; try { @@ -194,7 +194,7 @@ HWTEST_F(BErrorTest, b_error_construction_0400, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0100"; BError be(BError::Codes::OK); @@ -212,7 +212,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0200"; BError be(BError::Codes::UTILS_INVAL_JSON_ENTITY); @@ -230,7 +230,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0200, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0300, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0300"; BError be(BError::Codes::UTILS_INVAL_FILE_HANDLE); @@ -248,7 +248,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0300, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0400, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0400"; BError be(BError::Codes::UTILS_INVAL_TARBALL_ARG); @@ -266,7 +266,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0400, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0500, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0500"; BError be(BError::Codes::UTILS_INVAL_PROCESS_ARG); @@ -284,7 +284,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0500, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCode_0600, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCode_0600, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0600"; BError be(BError::Codes::UTILS_INTERRUPTED_PROCESS); @@ -302,7 +302,7 @@ HWTEST_F(BErrorTest, b_error_GetCode_0600, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0100"; BError be(BError::Codes::OK); @@ -320,7 +320,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0200"; BError be(BError::Codes::UTILS_INVAL_JSON_ENTITY); @@ -338,7 +338,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0200, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0300, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0300"; BError be(BError::Codes::UTILS_INVAL_FILE_HANDLE); @@ -356,7 +356,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0300, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0400, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0400"; BError be(BError::Codes::UTILS_INVAL_TARBALL_ARG); @@ -374,7 +374,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0400, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0500, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0500"; BError be(BError::Codes::UTILS_INVAL_PROCESS_ARG); @@ -392,7 +392,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0500, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetRawCode_0600, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetRawCode_0600, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0600"; BError be(BError::Codes::UTILS_INTERRUPTED_PROCESS); @@ -410,7 +410,7 @@ HWTEST_F(BErrorTest, b_error_GetRawCode_0600, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_what_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_what_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_what_0100"; BError be(BError::Codes::OK); @@ -428,7 +428,7 @@ HWTEST_F(BErrorTest, b_error_what_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_bool_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_bool_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_bool_0100"; bool result = BError(); @@ -445,7 +445,7 @@ HWTEST_F(BErrorTest, b_error_bool_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_int_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_int_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_int_0100"; int result = BError(); @@ -462,7 +462,7 @@ HWTEST_F(BErrorTest, b_error_int_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0100"; int32_t errnoSys = 0; @@ -480,7 +480,7 @@ HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0200"; int32_t errnoSys = EPERM; @@ -498,7 +498,7 @@ HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0200, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0300, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0300"; int32_t errnoSys = -EPERM; @@ -516,7 +516,7 @@ HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0300, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetBackupCodeByErrno_0100"; int err = ERR_OK; @@ -534,7 +534,7 @@ HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0100, testing::ext::TestSize.L * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetBackupCodeByErrno_0200"; int err = BError(BError::Codes::SA_INVAL_ARG).GetCode(); @@ -555,7 +555,7 @@ HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0200, testing::ext::TestSize.L * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0300, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetBackupCodeByErrno_0300"; int err = -EPERM; @@ -573,7 +573,7 @@ HWTEST_F(BErrorTest, b_error_GetBackupCodeByErrno_0300, testing::ext::TestSize.L * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetBackupMsgByErrno_0100, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetBackupMsgByErrno_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetBackupMsgByErrno_0100"; int err = BError(BError::BackupErrorCode::E_PERM).GetCode(); @@ -594,7 +594,7 @@ HWTEST_F(BErrorTest, b_error_GetBackupMsgByErrno_0100, testing::ext::TestSize.Le * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BErrorTest, b_error_GetBackupMsgByErrno_0200, testing::ext::TestSize.Level0) +HWTEST_F(BErrorTest, b_error_GetBackupMsgByErrno_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetBackupMsgByErrno_0200"; int err = -EPERM; diff --git a/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp b/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp index a893b8164..6cd5d7f4f 100644 --- a/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp +++ b/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp @@ -48,7 +48,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BDirTest, b_dir_GetDirFiles_0100, testing::ext::TestSize.Level0) +HWTEST_F(BDirTest, b_dir_GetDirFiles_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BDirTest-begin b_dir_GetDirFiles_0100"; try { @@ -86,7 +86,7 @@ HWTEST_F(BDirTest, b_dir_GetDirFiles_0100, testing::ext::TestSize.Level0) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BDirTest, b_dir_GetDirFiles_0104, testing::ext::TestSize.Level0) +HWTEST_F(BDirTest, b_dir_GetDirFiles_0104, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BDirTest-begin b_dir_GetDirFiles_0104"; try { diff --git a/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp b/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp index bedfa2e60..e745dedf4 100644 --- a/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp +++ b/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp @@ -58,7 +58,7 @@ static tuple GetTestFile(const TestManager &tm) * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0100, testing::ext::TestSize.Level0) +HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BFileHashTest-begin b_file_hash_HashWithSHA256_0100"; try { @@ -83,7 +83,7 @@ HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0100, testing::ext::TestSize. * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0101, testing::ext::TestSize.Level0) +HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BFileHashTest-begin b_file_hash_HashWithSHA256_0101"; try { diff --git a/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp b/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp index 2cebb5ad9..61868d40f 100644 --- a/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp @@ -43,7 +43,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0100"; try { @@ -68,7 +68,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0100, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0101, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0101"; try { @@ -93,7 +93,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0101, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0102, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0102, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0102"; try { @@ -118,7 +118,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0102, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0104, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0104, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0104"; try { @@ -143,7 +143,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0104, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0105, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0105, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0105"; try { @@ -168,7 +168,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0105, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0106, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0106, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0106"; try { @@ -193,7 +193,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0106, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_construction_0107, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0107, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0107"; try { @@ -218,7 +218,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0107, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_Structuralize_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_Structuralize_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_Structuralize_0100"; try { @@ -244,7 +244,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_Structuralize_0100, testing::ext::TestSiz * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_GetFd_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_GetFd_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_GetFd_0100"; try { @@ -270,7 +270,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_GetFd_0100, testing::ext::TestSize.Level0 * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_Persist_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_Persist_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_Persist_0100"; try { @@ -296,7 +296,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_Persist_0100, testing::ext::TestSize.Leve * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromFile_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromFile_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_ReloadFromFile_0100"; try { @@ -323,7 +323,7 @@ HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromFile_0100, testing::ext::TestSi * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromString_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromString_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_ReloadFromString_0100"; try { diff --git a/tests/unittests/backup_utils/b_json/b_json_clear_data_config_test.cpp b/tests/unittests/backup_utils/b_json/b_json_clear_data_config_test.cpp index f18f1c1df..357ff2ada 100644 --- a/tests/unittests/backup_utils/b_json/b_json_clear_data_config_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_clear_data_config_test.cpp @@ -436,12 +436,16 @@ HWTEST_F(BJsonClearDataConfigTest, Clear_Data_Config_Test_0700, testing::ext::Te BJsonClearDataConfig config; EXPECT_EQ(access(filePath.c_str(), F_OK), 0); - EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); auto ret = config.InsertClearBundleRecord(bundleName); EXPECT_FALSE(ret); EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetArraySize(_)).WillOnce(Return(0)); + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); ret = config.InsertClearBundleRecord(bundleName); EXPECT_FALSE(ret); @@ -476,19 +480,116 @@ HWTEST_F(BJsonClearDataConfigTest, Clear_Data_Config_Test_0800, testing::ext::Te BJsonClearDataConfig config; EXPECT_EQ(access(filePath.c_str(), F_OK), 0); - EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); auto ret = config.GetAllClearBundleRecords(); - EXPECT_EQ(ret.size(), 0); + EXPECT_TRUE(ret.empty()); EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetArraySize(_)).WillOnce(Return(0)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); ret = config.GetAllClearBundleRecords(); - EXPECT_EQ(ret.size(), 0); + EXPECT_TRUE(ret.empty()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-an exception occurred by construction."; } GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-end Clear_Data_Config_Test_0800"; } + +/** + * @tc.number: SUB_Clear_Data_Config_Test_0900 + * @tc.name: Clear_Data_Config_Test_0900 + * @tc.desc: 测试 InsertClearBundleRecord 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IAAMIK + */ +HWTEST_F(BJsonClearDataConfigTest, Clear_Data_Config_Test_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-begin Clear_Data_Config_Test_0900"; + try { + string bundleName = "test1"; + string filePath = PATH + CONFIG_NAME; + int cjson = 0; + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + BJsonClearDataConfig config; + EXPECT_EQ(access(filePath.c_str(), F_OK), 0); + + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetArraySize(_)).WillOnce(Return(1)).WillOnce(Return(0)); + EXPECT_CALL(*cJsonMock, cJSON_GetArrayItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + auto ret = config.InsertClearBundleRecord(bundleName); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-end Clear_Data_Config_Test_0900"; +} + +/** + * @tc.number: SUB_Clear_Data_Config_Test_1000 + * @tc.name: Clear_Data_Config_Test_1000 + * @tc.desc: 测试 InsertClearBundleRecord 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IAAMIK + */ +HWTEST_F(BJsonClearDataConfigTest, Clear_Data_Config_Test_1000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-begin Clear_Data_Config_Test_1000"; + try { + string bundleName = "test1"; + string filePath = PATH + CONFIG_NAME; + int cjson = 0; + EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + BJsonClearDataConfig config; + EXPECT_EQ(access(filePath.c_str(), F_OK), 0); + + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)) + .WillOnce(Return(reinterpret_cast(&cjson))) + .WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetArraySize(_)).WillOnce(Return(1)).WillOnce(Return(0)); + EXPECT_CALL(*cJsonMock, cJSON_GetArrayItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); + auto ret = config.InsertClearBundleRecord(bundleName); + EXPECT_FALSE(ret); + + EXPECT_CALL(*cJsonMock, cJSON_Parse(_)) + .WillOnce(Return(reinterpret_cast(&cjson))) + .WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetArraySize(_)).WillOnce(Return(1)).WillOnce(Return(0)); + EXPECT_CALL(*cJsonMock, cJSON_GetArrayItem(_, _)).WillOnce(Return(reinterpret_cast(&cjson))); + EXPECT_CALL(*cJsonMock, cJSON_GetObjectItem(_, _)) + .WillOnce(Return(reinterpret_cast(&cjson))) + .WillOnce(Return(nullptr)) + .WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()).WillOnce(Return()); + ret = config.InsertClearBundleRecord(bundleName); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonClearDataConfigTest-end Clear_Data_Config_Test_1000"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp b/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp index 239a274bd..f13dd9d0b 100644 --- a/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp @@ -132,7 +132,7 @@ struct stat GetFileStat(const string &pathTestFile) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0100"; try { @@ -175,7 +175,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0100, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0200"; try { @@ -228,7 +228,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0200, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0300, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0300"; try { @@ -291,7 +291,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0300, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0400, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0400"; try { @@ -355,7 +355,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0400, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0500, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0500"; try { @@ -410,7 +410,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0500, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0700, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0700, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0700"; try { @@ -435,7 +435,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0700, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0800, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0800, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0800"; try { @@ -460,7 +460,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0800, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0801, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0801, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0801"; try { @@ -485,7 +485,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0801, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0802, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0802, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0802"; try { @@ -510,7 +510,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0802, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0803, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0803, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0803"; try { @@ -535,7 +535,7 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0803, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0804, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0804, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0804"; try { diff --git a/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp b/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp index 937245c1a..3da3ab4c1 100644 --- a/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp @@ -70,7 +70,7 @@ static vector DEFAULT_EXCLUDE_DIR = {}; * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_0100"; try { @@ -102,7 +102,7 @@ HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0100, te * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_0200"; try { @@ -133,7 +133,7 @@ HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0200, te * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0300, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_0300"; try { @@ -164,7 +164,7 @@ HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0300, te * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0400, testing::ext::TestSize.Level0) +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_0400"; try { diff --git a/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp b/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp index 5bc9fd747..6624bba1a 100644 --- a/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp @@ -63,7 +63,7 @@ static tuple GetTestFile(const TestManager &tm, const string con * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(BReportEntityTest, b_report_entity_GetReportInfos_0100, testing::ext::TestSize.Level0) +HWTEST_F(BReportEntityTest, b_report_entity_GetReportInfos_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_GetReportInfos_0100"; try { diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp index 397424299..7cac718a4 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_other_test.cpp @@ -69,7 +69,7 @@ void BJsonUtilTest::TearDownTestCase() * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0101, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0101"; try { @@ -104,7 +104,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0101, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0201, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0201, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0201"; try { @@ -137,7 +137,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0201, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0301, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0301, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildOnProcessRetInfo_0301"; try { @@ -183,7 +183,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0301, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfoJson_0401, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfoJson_0401, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfoJson_0401"; try { @@ -227,7 +227,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfoJson_0401, testing::ext::TestS * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessErrInfo_0501, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessErrInfo_0501, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildOnProcessErrInfo_0501"; try { @@ -283,7 +283,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessErrInfo_0501, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleNameIndexInfo_0601, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleNameIndexInfo_0601, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleNameIndexInfo_0601"; try { @@ -311,7 +311,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleNameIndexInfo_0601, testing::ext:: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildInitSessionErrInfo_0701"; try { @@ -324,30 +324,21 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::T EXPECT_EQ(result, ""); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(nullptr)); - EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); - result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); - EXPECT_EQ(result, ""); - - EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); EXPECT_EQ(result, ""); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_CreateArray()).WillOnce(Return(reinterpret_cast(&cjson))); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_CreateObject()) .WillOnce(Return(reinterpret_cast(&cjson))) .WillOnce(Return(nullptr)); - EXPECT_CALL(*cJsonMock, cJSON_AddItemToArray(_, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_AddStringToObject(_, _, _)) + .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)); + EXPECT_CALL(*cJsonMock, cJSON_AddItemToObject(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cJsonMock, cJSON_Print(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*cJsonMock, cJSON_Delete(_)).WillOnce(Return()); result = BJsonUtil::BuildInitSessionErrInfo(userId, callerName, activeTime); @@ -368,7 +359,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildInitSessionErrInfo_0701, testing::ext::T * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_WriteToStr_0801, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_WriteToStr_0801, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin WriteToStr_0801"; try { diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp index 11bd5ee79..44a5f6da5 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp @@ -51,7 +51,7 @@ public: * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin b_dir_GetDirFiles_0100"; try { @@ -74,7 +74,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::T * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin ParseBundleNameIndexStr_0200"; try { @@ -97,7 +97,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::T * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0100"; try { @@ -131,7 +131,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0200"; try { @@ -163,7 +163,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0300"; try { @@ -195,7 +195,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0301"; try { @@ -227,7 +227,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0400"; try { @@ -262,7 +262,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0500"; try { @@ -296,7 +296,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0600"; try { @@ -330,7 +330,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0700"; try { @@ -363,7 +363,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0800"; try { @@ -396,7 +396,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0900"; try { @@ -429,7 +429,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_1000"; try { @@ -462,7 +462,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0100"; try { @@ -489,7 +489,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::Test * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0200"; try { @@ -521,7 +521,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::Test * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0300"; try { @@ -553,7 +553,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::Test * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildOnProcessRetInfo_0100"; try { @@ -580,7 +580,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0100, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0100"; try { @@ -609,7 +609,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::Tes * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0200, testing::ext::TestSize.Level0) +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0200"; try { diff --git a/tests/unittests/backup_utils/b_process/b_process_test.cpp b/tests/unittests/backup_utils/b_process/b_process_test.cpp index 1c8534d99..fc8171422 100644 --- a/tests/unittests/backup_utils/b_process/b_process_test.cpp +++ b/tests/unittests/backup_utils/b_process/b_process_test.cpp @@ -51,7 +51,7 @@ static bool DetectFatalLog(string_view output) * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0100, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0100"; try { @@ -86,7 +86,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0100, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0200, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0200, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0200"; try { @@ -114,7 +114,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0200, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0300, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0300, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0300"; try { @@ -141,7 +141,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0300, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0400, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0400, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0400"; try { @@ -168,7 +168,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0400, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0500, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0500, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0500"; try { @@ -195,7 +195,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0500, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0600, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0600, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0600"; try { @@ -222,7 +222,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0600, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0700, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0700, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0700"; try { @@ -249,7 +249,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0700, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0800, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0800, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0800"; try { @@ -276,7 +276,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0800, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0900, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0900, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0900"; try { @@ -301,7 +301,7 @@ HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0900, testing::ext::TestSize.Lev * @tc.level Level 0 * @tc.require: I6F3GV */ -HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_1000, testing::ext::TestSize.Level0) +HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_1000, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_1000"; try { diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index bc3bebd9b..cdd7a085d 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -468,23 +468,17 @@ std::string BJsonUtil::BuildInitSessionErrInfo(int32_t userId, std::string calle HILOGE("Failed to create cJSON object info, update errMsg failed"); return ""; } - cJSON *sessionInfoArray = cJSON_CreateArray(); - if (sessionInfoArray == nullptr) { - HILOGE("Failed to create cJSON array sessionInfoArray, update errMsg failed"); - cJSON_Delete(info); - return ""; - } - cJSON_AddItemToObject(info, "sessionInfo", sessionInfoArray); cJSON *sessionInfoObject = cJSON_CreateObject(); if (sessionInfoObject == nullptr) { HILOGE("Failed to create cJSON object sessionInfoObject, update errMsg failed"); cJSON_Delete(info); return ""; } - cJSON_AddItemToArray(sessionInfoArray, sessionInfoObject); + cJSON_AddStringToObject(sessionInfoObject, "error", "Session Conflict"); cJSON_AddStringToObject(sessionInfoObject, "userId", to_string(userId).c_str()); cJSON_AddStringToObject(sessionInfoObject, "name", callerName.c_str()); cJSON_AddStringToObject(sessionInfoObject, "activeTime", activeTime.c_str()); + cJSON_AddItemToObject(info, "sessionInfo", sessionInfoObject); char *jsonStr = cJSON_Print(info); if (jsonStr == nullptr) { HILOGE("update errMsg failed"); -- Gitee From 1d318c26915b8a83d45e43004718868095fd5ad8 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 20 Mar 2025 22:49:36 +0800 Subject: [PATCH 19/21] update fuzz test Signed-off-by: BrainL --- test/fuzztest/BUILD.gn | 1 - .../backupservicestubbranch_fuzzer/BUILD.gn | 65 - .../backupservicestubbranch_fuzzer.cpp | 1155 ----------------- .../backupservicestubbranch_fuzzer.h | 21 - .../corpus/init | 16 - .../project.xml | 25 - .../module_ipc/service_throw_test.cpp | 4 +- 7 files changed, 2 insertions(+), 1285 deletions(-) delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/corpus/init delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 5b26911f6..1c4a33aca 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -21,7 +21,6 @@ group("fuzztest") { "backupsaanother_fuzzer:BackupSaAnotherFuzzTest", "backupsaappend_fuzzer:BackupSaAppendFuzzTest", "backupservicestub_fuzzer:BackupServiceStubFuzzTest", - "backupservicestubbranch_fuzzer:BackupServiceStubBranchFuzzTest", "fileshare_fuzzer:FileShareFuzzTest", "remotefileshare_fuzzer:RemoteFileShareFuzzTest", "servicereverse_fuzzer:ServiceReverseFuzzTest", diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn deleted file mode 100644 index dcaad28f4..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (c) 2021-2023 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("//foundation/filemanagement/app_file_service/app_file_service.gni") -import("//foundation/filemanagement/app_file_service/backup.gni") - -##############################fuzztest########################################## -ohos_fuzztest("BackupServiceStubBranchFuzzTest") { - module_out_path = "app_file_service/app_file_service" - fuzz_config_file = - "${app_file_service_path}/test/fuzztest/backupservicestubbranch_fuzzer" - include_dirs = [ - "${app_file_service_path}/frameworks/native/backup_kit_inner/include", - "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner/impl", - "${app_file_service_path}/services/backup_sa/include", - "${app_file_service_path}/services/backup_sa/include/module_ipc", - "${app_file_service_path}/utils/include", - "${app_file_service_path}/utils/include/b_hilog", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "backupservicestubbranch_fuzzer.cpp" ] - - deps = [ - "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${app_file_service_path}/services/backup_sa:backup_sa", - "${app_file_service_path}/utils:backup_utils", - ] - - external_deps = [ - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD004303", - "private=public", - ] - - use_exceptions = true -} -############################################################################### diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp deleted file mode 100644 index 6e76cd4d5..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ /dev/null @@ -1,1155 +0,0 @@ -/* - * Copyright (c) 2024-2025 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 "backupservicestubbranch_fuzzer.h" - -#include -#include - -#include "b_incremental_data.h" -#include "b_session_backup.h" -#include "b_session_restore.h" -#include "message_parcel.h" -#include "refbase.h" -#include "service.h" -#include "service_reverse.h" - -namespace OHOS { -using namespace FileManagement::Backup; -using namespace std; - -using FAFVariant = std::variant>; - -list que; -list arg; - -void ExpectReturn(list&& value) -{ - std::swap(que, value); -} - -void ExpectArgReturn(list&& value) -{ - std::swap(arg, value); -} - -bool GetBoolResult() -{ - bool ret = true; - if (!que.empty()) { - ret = std::get(que.front()); - que.pop_front(); - } - return ret; -} - -Parcelable::Parcelable() : Parcelable(false) -{} - -Parcelable::Parcelable(bool asRemote) -{ - asRemote_ = asRemote; - behavior_ = 0; -} - -template -bool Parcel::Write(T value) -{ - size_t desireCapacity = sizeof(T); - - if (EnsureWritableCapacity(desireCapacity)) { - *reinterpret_cast(data_ + writeCursor_) = value; - writeCursor_ += desireCapacity; - dataSize_ += desireCapacity; - return true; - } - - return false; -} - -bool Parcel::WriteParcelable(const Parcelable *object) -{ - if (object == nullptr) { - return WriteInt32(0); - } - - if (!object->asRemote_) { - bool flag = WriteInt32(1); - object->Marshalling(*this); - return flag; - } - - bool flag = WriteInt32(1); - WriteRemoteObject(const_cast(object)); - return flag; -} - -bool Parcel::WriteInt32(int32_t value) -{ - Write(value); - return GetBoolResult(); -} - -bool Parcel::WriteUint32(uint32_t value) -{ - Write(value); - return GetBoolResult(); -} - -int32_t Parcel::ReadInt32() -{ - int32_t ret = 0; - if (!que.empty()) { - ret = std::get(que.front()); - que.pop_front(); - } - return ret; -} - -bool Parcel::ReadInt32(int32_t &value) -{ - if (!arg.empty()) { - value = std::get(arg.front()); - arg.pop_front(); - } - return GetBoolResult(); -} - -bool Parcel::ReadBool() -{ - return GetBoolResult(); -} - -bool Parcel::ReadBool(bool &value) -{ - if (!arg.empty()) { - value = std::get(arg.front()); - arg.pop_front(); - } - return GetBoolResult(); -} - -bool Parcel::WriteBool(bool value) -{ - return GetBoolResult(); -} - -bool Parcel::WriteString(const std::string &value) -{ - return GetBoolResult(); -} - -bool Parcel::ReadString(std::string &value) -{ - if (!arg.empty()) { - value = std::get(arg.front()); - arg.pop_front(); - } - return GetBoolResult(); -} - -bool Parcel::ReadStringVector(std::vector *value) -{ - if (!arg.empty()) { - *value = std::get>(arg.front()); - arg.pop_front(); - } - return GetBoolResult(); -} - -bool MessageParcel::WriteFileDescriptor(int fd) -{ - return GetBoolResult(); -} - -int MessageParcel::ReadFileDescriptor() -{ - int32_t ret = 0; - if (!que.empty()) { - ret = std::get(que.front()); - que.pop_front(); - } - return ret; -} - -bool Parcel::ReadUint32(uint32_t &value) -{ - if (!arg.empty()) { - value = std::get(arg.front()); - arg.pop_front(); - } - return GetBoolResult(); -} - - -template -T TypeCast(const uint8_t *data, int *pos = nullptr) -{ - if (pos) { - *pos += sizeof(T); - } - return *(reinterpret_cast(data)); -} - -bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(uint32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = TypeCast(data); - - service->OnRemoteRequest(code, msg, reply, option); - - msg.WriteInterfaceToken(ServiceStub::GetDescriptor()); - service->OnRemoteRequest(code, msg, reply, option); - return true; -} - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION); - - try { - msg.WriteBuffer(data, size); - service->OnRemoteRequest(code, msg, reply, option); - - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION); - - try { - msg.WriteBuffer(data, size); - service->OnRemoteRequest(code, msg, reply, option); - - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_START); - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE); - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_DONE); - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT); - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - string restoreRetInfo(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({restoreRetInfo}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({restoreRetInfo, scenario}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE); - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA); - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, type}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, true, true}); - ExpectArgReturn({bundleNames, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL); - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({fd, true, true, true, true, true}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION); - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleNames, detailInfos}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_FINISH); - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); - try { - msg.WriteBuffer(data, size); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); - - try { - BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); - - int32_t infoSize = 1; - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP); - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); - - try { - msg.WriteBuffer(data, size); - service->OnRemoteRequest(code, msg, reply, option); - - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); - - try { - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); - - ExpectReturn({false}); - service->OnRemoteRequest(code, msg, reply, option); - - int32_t infoSize = 1; - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast( - IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS); - - try { - int32_t infoSize = 1; - int len = size >> 1; - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE); - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({fd, false}); - service->OnRemoteRequest(code, msg, reply, option); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({fd, true}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : - ExpectReturn({true, flag, fd1, fd2, errCode, false}); - } else { - ExpectReturn({true, flag, errCode, false}); - } - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : - ExpectReturn({true, flag, fd1, fd2, errCode, true}); - } else { - ExpectReturn({true, flag, errCode, true}); - } - ExpectArgReturn({fileName}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE); - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE); - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_BACKUP_INFO); - - try { - string bundleName(reinterpret_cast(data), size); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_TIMER); - - try { - int pos = 0; - uint32_t timeout = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, timeout}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, timeout}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, timeout}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IServiceIpcCode::COMMAND_UPDATE_SEND_RATE); - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->OnRemoteRequest(code, msg, reply, option); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, sendRate}); - service->OnRemoteRequest(code, msg, reply, option); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); - if (service == nullptr) { - return 0; - } - - try { - OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h deleted file mode 100644 index 7e7ba1c46..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2024-2025 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. - */ - -#ifndef BACKUP_SERVICE_STUB_FUZZER_H -#define BACKUP_SERVICE_STUB_FUZZER_H - -#define FUZZ_PROJECT_NAME "backupservicestubbranch_fuzzer" - -#endif \ No newline at end of file diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/corpus/init b/test/fuzztest/backupservicestubbranch_fuzzer/corpus/init deleted file mode 100644 index 6198079a2..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/project.xml b/test/fuzztest/backupservicestubbranch_fuzzer/project.xml deleted file mode 100644 index 7133b2b92..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 2da55b4b9..316992b95 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -147,7 +147,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -201,7 +201,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); -- Gitee From fbb541777594b885c39caabdd11fd19de410579e Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Mar 2025 17:02:24 +0800 Subject: [PATCH 20/21] comments modify. Signed-off-by: BrainL --- .../native/backup_kit_inner/include/service_reverse.h | 3 +++ .../backup_kit_inner/src/b_incremental_backup_session.cpp | 2 +- .../backup_kit_inner/src/b_incremental_restore_session.cpp | 6 +++--- frameworks/native/backup_kit_inner/src/b_session_backup.cpp | 2 +- .../native/backup_kit_inner/src/b_session_restore.cpp | 6 +++--- interfaces/kits/js/backup/prop_n_operation.cpp | 4 ++-- services/backup_sa/include/module_ipc/service.h | 1 + 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index c19668973..83faba703 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -23,6 +23,9 @@ #include "service_reverse_stub.h" namespace OHOS::FileManagement::Backup { +const int DEFAULT_RESTORE_TYPE = 0; +const int DEFAULT_USER_ID = -1; + class ServiceReverse final : public ServiceReverseStub { public: void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index c78a25e5e..2413f9de2 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -127,7 +127,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - int fdvalue = -1; + int fdvalue = INVALID_FD; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); UniqueFd fd(fdvalue); if (fd < 0) { diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index b09e2ce64..c0859a47a 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -109,7 +109,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - int fdvalue = -1; + int fdvalue = INVALID_FD; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); UniqueFd fd(fdvalue); if (fd < 0) { @@ -178,8 +178,8 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } int32_t remoteCapInt = remoteCap.Get(); - ErrCode res = - proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, + DEFAULT_RESTORE_TYPE, DEFAULT_USER_ID); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index 9742e6d92..cbecc9896 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -137,7 +137,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - int fdvalue = -1; + int fdvalue = INVALID_FD; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); UniqueFd fd(fdvalue); if (fd < 0) { diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index ab86d5ab0..38e7dfd40 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -77,7 +77,7 @@ UniqueFd BSessionRestore::GetLocalCapabilities() HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - int fdvalue = -1; + int fdvalue = INVALID_FD; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); UniqueFd fd(fdvalue); if (fd < 0) { @@ -125,8 +125,8 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } int32_t remoteCapInt = remoteCap.Get(); - ErrCode res = - proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, + DEFAULT_RESTORE_TYPE, DEFAULT_USER_ID); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index e5b5c5950..1aea2c602 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -44,7 +44,7 @@ static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg) HILOGI("called LocalCapabilities::AsyncCallback cbExec, failed to get proxy"); return NError(errno); } - int fdNum = -1; + int fdNum = INVALID_FD; proxy->GetLocalCapabilities(fdNum); UniqueFd fdData(fdNum); *fd = std::move(fdData); @@ -91,7 +91,7 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) HILOGI("called LocalCapabilities::AsyncDataList cbExec, failed to get proxy"); return NError(errno); } - int fdValue = -1; + int fdValue = INVALID_FD; proxy->GetLocalCapabilitiesIncremental(bundles, fdValue); UniqueFd fdData(fdValue); *fd = std::move(fdData); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index dee0e5f14..277b00f21 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -42,6 +42,7 @@ struct BundleTaskInfo { std::string reportTime; ErrCode errCode; }; +const int INVALID_FD = -1; class Service : public SystemAbility, public ServiceStub, protected NoCopyable { DECLARE_SYSTEM_ABILITY(Service); -- Gitee From 2c5e793cc927cd0260f1c653b3236f26f59427be Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 25 Mar 2025 17:37:56 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../backup_kit_inner/src/b_incremental_restore_session.cpp | 3 ++- frameworks/native/backup_kit_inner/src/b_session_restore.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index c0859a47a..461763e15 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -155,7 +155,8 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, + DEFAULT_RESTORE_TYPE, DEFAULT_USER_ID); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 38e7dfd40..d0a9d1644 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -147,7 +147,8 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } int32_t remoteCapInt = remoteCap.Get(); - ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, + DEFAULT_RESTORE_TYPE, DEFAULT_USER_ID); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { -- Gitee