From 6de214b64b0dc2c8fe5ecec584ab757617fb1119 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 20 May 2025 11:01:25 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=BF=BD=E5=8A=A0service=20mock,=E5=B9=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AE=B9=E6=98=93proxy.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL Change-Id: I787fafd963d3687c76c37409029c44c11bd7ef72 --- .../src/module_ipc/svc_extension_proxy.cpp | 215 ------ .../backup_sa/module_client/BUILD.gn | 2 +- .../module_client/service_client_test.cpp | 6 +- .../backup_sa/module_client/service_mock.cpp | 625 ++++++++++++++++++ .../module_ipc/svc_extension_proxy_test.cpp | 544 --------------- 5 files changed, 629 insertions(+), 763 deletions(-) delete mode 100644 services/backup_sa/src/module_ipc/svc_extension_proxy.cpp create mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp delete mode 100644 tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp deleted file mode 100644 index bd0d8e8a0..000000000 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ /dev/null @@ -1,215 +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 "extension_proxy.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; - -UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName, int32_t &errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - if (!data.WriteString(fileName)) { - BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName"); - return UniqueFd(-1); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_GET_FILE_HANDLE), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return UniqueFd(-ret); - } - - HILOGI("Successful"); - bool fdFlag = reply.ReadBool(); - errCode = reply.ReadInt32(); - UniqueFd fd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(reply.ReadFileDescriptor()); - } - return UniqueFd(fd.Release()); -} - -ErrCode SvcExtensionProxy::HandleClear() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_HANDLE_CLAER), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGI("Successful"); - return reply.ReadInt32(); -} - -ErrCode SvcExtensionProxy::HandleBackup(bool isClearData) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteBool(isClearData)) { - return BError(BError::Codes::SDK_INVAL_ARG, "build param fail."); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_HANDLE_BACKUP), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGI("Successful"); - return reply.ReadInt32(); -} - -ErrCode SvcExtensionProxy::PublishFile(const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - if (!data.WriteString(fileName)) { - BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName"); - return ErrCode(EPERM); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_PUBLISH_FILE), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGD("Successful"); - return reply.ReadInt32(); -} - -ErrCode SvcExtensionProxy::HandleRestore(bool isClearData) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteBool(isClearData)) { - return BError(BError::Codes::SDK_INVAL_ARG, "build param fail."); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_HANDLE_RESTORE), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGI("Successful"); - return reply.ReadInt32(); -} - -ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) -{ - HILOGD("SvcExtensionProxy::GetBackupInfo begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_GET_BACKUP_INFO), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - if (!reply.ReadInt32(ret)) { - HILOGE("fail to ReadInt32 ret"); - return ErrCode(ret); - } - if (ret != NO_ERROR) { - HILOGE("ret is not NO_ERROR. ret = %d", ret); - return ErrCode(ret); - } - if (!reply.ReadString(result)) { - HILOGE("fail to ReadInt32 ret"); - return ErrCode(ret); - } - HILOGI("SvcExtensionProxy::GetBackupInfo end. result: %s", result.c_str()); - return ret; -} - -ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) -{ - HILOGD("SvcExtensionProxy::UpdateFdSendRate begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - if (!data.WriteString(bundleName)) { - BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName"); - return ErrCode(EPERM); - } - if (!data.WriteInt32(sendRate)) { - BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate"); - return ErrCode(EPERM); - } - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE), data, reply, - option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - if (!reply.ReadInt32(ret)) { - HILOGE("fail to read ret, ret is %{public}d", ret); - return ErrCode(ret); - } - HILOGI("SvcExtensionProxy::UpdateFdSendRate end."); - return ret; -} -} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn index 47a26fff8..bb988d321 100644 --- a/tests/unittests/backup_sa/module_client/BUILD.gn +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -32,11 +32,11 @@ ohos_unittest("service_client_test") { sources = [ "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "service_client_test.cpp", + "service_mock.cpp", ] deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 0cecf86a5..e1d19b4a8 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -346,13 +346,13 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); EXPECT_EQ(errMsg, ""); ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); EXPECT_EQ(errMsg, ""); ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); EXPECT_EQ(errMsg, ""); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; diff --git a/tests/unittests/backup_sa/module_client/service_mock.cpp b/tests/unittests/backup_sa/module_client/service_mock.cpp new file mode 100644 index 000000000..08ffa9783 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/service_mock.cpp @@ -0,0 +1,625 @@ +/* + * 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 "module_ipc/service.h" + +#include +#include +#include +#include + +#include "b_error/b_error.h" +#include "b_resources/b_constants.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +int32_t Service::GetUserIdDefault() +{ + return 0; +} + +void Service::OnStart() {} + +void Service::OnStop() {} + +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + fd = 1; + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) +{ + if (reverseIpcRemoteObject == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (detailInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (restoreType < 0 || userId < 0 || fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (restoreType < 0 || userId < 0 || fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + if (bundlesToBackup.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (bundleInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetLocalCapabilities(int &fd) +{ + 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) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::InitRestoreSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::InitBackupSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::Start() +{ + GTEST_LOG_(INFO) << "Service mock start"; + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishFile(const BFileInfo &fileInfo) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) +{ + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppDone(ErrCode errCode) +{ + if (errCode == 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (errCode == -1) { + return BError(BError::BackupErrorCode::E_EMPTY); + } + if (errCode > 0) { + return BError(BError::Codes::OK); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) +{ + if (restoreRetInfo.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &bundleInfos) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (bundleInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::Finish() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +void Service::OnBackupExtensionDied(const string &&bundleName, bool isCleanCalled) {} + +void Service::ExtConnectDied(const string &callName) {} + +void Service::ExtStart(const string &bundleName) {} + +int Service::Dump(int fd, const vector &args) +{ + return 0; +} + +void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) +{ + GTEST_LOG_(INFO) << "ExtConnectFailed is OK"; +} + +void Service::ExtConnectDone(string bundleName) {} + +void Service::ClearSessionAndSchedInfo(const string &bundleName) {} + +ErrCode Service::VerifyCaller() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) +{ + return BError(BError::Codes::OK); +} + +void Service::OnAllBundlesFinished(ErrCode errCode) {} + +void Service::OnStartSched() {} + +void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} + +void Service::SessionDeactive() {} + +ErrCode Service::Release() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (!bundleName.empty()) { + result = 0; + return BError(BError::Codes::OK); + } + result = BError(BError::Codes::OK); + return BError(BError::Codes::OK); +} + +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + fd = 1; + return BError(BError::Codes::OK); +} + +ErrCode Service::GetAppLocalListAndDoIncrementalBackup() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &infos) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fd < 0 || manifestFd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppIncrementalDone(ErrCode errCode) +{ + if (errCode == 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (errCode == -1) { + return BError(BError::BackupErrorCode::E_EMPTY); + } + if (errCode > 0) { + return BError(BError::Codes::OK); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) +{ + result = "abc"; + return BError(BError::Codes::OK); +} + +ErrCode Service::StartExtTimer(bool &isExtStart) +{ + if (isExtStart) { + return BError(BError::Codes::OK); + } + + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::StartFwkTimer(bool &isFwkStart) +{ + if (isFwkStart) { + return BError(BError::Codes::OK); + } + + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::StopExtTimer(bool &isExtStop) +{ + if (isExtStop) { + return BError(BError::Codes::OK); + } + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::RefreshDataSize(int64_t totalDatasize) +{ + if (totalDatasize < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + if (timeout < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + result = true; + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + if (sendRate < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + result = true; + return BError(BError::Codes::OK); +} + +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) +{ + if (processInfo.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) +{ +} + +void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} + +ErrCode Service::ClearResidualBundleData(const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) +{ + return make_shared(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) +{ +} + +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} + +void Service::OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) {} + +std::string Service::GetCallerName() +{ + return ""; +} + +bool Service::IsReportBundleExecFail(const std::string &bundleName) +{ + return true; +} + +void Service::ClearBundleRadarReport() {} + +void Service::UpdateBundleRadarReport(const std::string &bundleName) {} + +bool Service::IsReportFileReadyFail(const std::string &bundleName) +{ + return true; +} + +void Service::ClearFileReadyRadarReport() {} + +void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} + +void Service::ClearFailedBundles() {} + +void Service::GetOldDeviceBackupVersion() {} + +void Service::CreateDirIfNotExist(const std::string &path) {} + +void Service::StartRunningTimer(const std::string &bundleName) {} + +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) +{ + return {}; +} + +void Service::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::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} + +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) +{ + return BError(BError::Codes::OK); +} + +void Service::GetDataSizeStepByStep(bool isPreciseScan, vector bundleNameList, string &scanning) {} + +void Service::GetPresumablySize(vector bundleNameList, string &scanning) {} + +void Service::GetPrecisesSize(vector bundleNameList, string &scanning) {} + +void Service::WriteToList(BJsonUtil::BundleDataSize bundleDataSize) {} + +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::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} + +bool Service::GetScanningInfo(wptr obj, size_t scannedSize, string &scanning) +{ + return true; +} + +void Service::SetScanningInfo(string &scanning, string name) {} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp deleted file mode 100644 index 75782d0a6..000000000 --- a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp +++ /dev/null @@ -1,544 +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_error/b_error.h" -#include "ext_extension_mock.h" -#include "message_parcel_mock.h" -#include "extension_proxy.h" -#include "unique_fd.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -class SvcExtensionProxyTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(); - void SetUp() override {}; - void TearDown() override {}; -public: - static inline sptr proxy_ = nullptr; - static inline sptr mock_ = nullptr; - static inline shared_ptr messageParcelMock_ = nullptr; -}; - -void SvcExtensionProxyTest::SetUpTestCase() -{ - mock_ = sptr(new BackupExtExtensionMock()); - proxy_ = sptr(new ExtensionProxy(mock_)); - messageParcelMock_ = make_shared(); - MessageParcelMock::messageParcel = messageParcelMock_; -} -void SvcExtensionProxyTest::TearDownTestCase() -{ - mock_ = nullptr; - proxy_ = nullptr; - MessageParcelMock::messageParcel = nullptr; - messageParcelMock_ = nullptr; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_GetFileHandle_0100 - * @tc.name: SUB_Ext_Extension_proxy_GetFileHandle_0100 - * @tc.desc: 测试 GetFileHandle 获取真实文件接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_GetFileHandle_0100"; - try { - string fileName = "1.tar"; - int32_t errCode = 0; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - UniqueFd fd = proxy_->GetFileHandle(fileName, errCode); - EXPECT_LT(fd, BError(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - fd = proxy_->GetFileHandle(fileName, errCode); - EXPECT_LT(fd, BError(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, ReadFileDescriptor()).WillOnce(Return(-1)); - fd = proxy_->GetFileHandle(fileName, errCode); - EXPECT_LT(fd, BError(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadBool()).WillOnce(Return(false)); - fd = proxy_->GetFileHandle(fileName, errCode); - EXPECT_LT(fd, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by GetFileHandle."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetFileHandle_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_HandleClear_0100 - * @tc.name: SUB_Ext_Extension_proxy_HandleClear_0100 - * @tc.desc: 测试 HandleClear 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_HandleClear_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_HandleClear_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->HandleClear(); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); - ret = proxy_->HandleClear(); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by HandleClear."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_HandleClear_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_HandleBackup_0100 - * @tc.name: SUB_Ext_Extension_proxy_HandleBackup_0100 - * @tc.desc: 测试 HandleBackup 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_HandleBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_HandleBackup_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->HandleBackup(true); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); - ret = proxy_->HandleBackup(true); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by HandleBackup."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_HandleBackup_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_PublishFile_0100 - * @tc.name: SUB_Ext_Extension_proxy_PublishFile_0100 - * @tc.desc: 测试 PublishFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_PublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_PublishFile_0100"; - try { - string fileName = "1.tar"; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->PublishFile(fileName); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - ret = proxy_->PublishFile(fileName); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); - ret = proxy_->PublishFile(fileName); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by PublishFile."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_PublishFile_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_HandleRestore_0100 - * @tc.name: SUB_Ext_Extension_proxy_HandleRestore_0100 - * @tc.desc: 测试 HandleRestore 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_HandleRestore_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_HandleRestore_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->HandleRestore(true); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); - ret = proxy_->HandleRestore(true); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by HandleRestore."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_HandleRestore_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_GetBackupInfo_0100 - * @tc.name: SUB_Ext_Extension_proxy_GetBackupInfo_0100 - * @tc.desc: 测试 GetBackupInfo 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_GetBackupInfo_0100"; - try { - string result = "result_report"; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->GetBackupInfo(result); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(Return(false)); - ret = proxy_->GetBackupInfo(result); - EXPECT_EQ(BError(BError::Codes::OK), ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(EPERM), Return(true))); - ret = proxy_->GetBackupInfo(result); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(NO_ERROR), Return(true))); - EXPECT_CALL(*messageParcelMock_, ReadString(_)).WillOnce(Return(false)); - ret = proxy_->GetBackupInfo(result); - EXPECT_EQ(BError(BError::Codes::OK), ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(NO_ERROR), Return(true))); - EXPECT_CALL(*messageParcelMock_, ReadString(_)).WillOnce(Return(true)); - ret = proxy_->GetBackupInfo(result); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by GetBackupInfo."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_UpdateFdSendRate_0100 - * @tc.name: SUB_Ext_Extension_proxy_UpdateFdSendRate_0100 - * @tc.desc: 测试 HandleRestore 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Service_GetBackupInfoCmdHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_UpdateFdSendRate_0100"; - try { - std::string bundleName = "bundleName"; - int32_t sendRate = 0; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->UpdateFdSendRate(bundleName, sendRate); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->UpdateFdSendRate(bundleName, sendRate); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->UpdateFdSendRate(bundleName, sendRate); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->UpdateFdSendRate(bundleName, sendRate); - EXPECT_EQ(BError(BError::Codes::OK), ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32(_)).WillOnce(Return(true)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->UpdateFdSendRate(bundleName, sendRate); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by UpdateFdSendRate."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_UpdateFdSendRate_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_GetIncrementalFileHandle_0100 - * @tc.name: SUB_Ext_Extension_proxy_GetIncrementalFileHandle_0100 - * @tc.desc: 测试 GetIncrementalFileHandle 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_GetIncrementalFileHandle_0100"; - try { - string fileName = "1.tar"; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - auto [ret, fd, reportFd] = proxy_->GetIncrementalFileHandle(fileName); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - tie(ret, fd, reportFd) = proxy_->GetIncrementalFileHandle(fileName); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadFileDescriptor()).WillOnce(Return(-1)).WillOnce(Return(-1)); - tie(ret, fd, reportFd) = proxy_->GetIncrementalFileHandle(fileName); - EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by GetIncrementalFileHandle."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_PublishIncrementalFile_0100 - * @tc.name: SUB_Ext_Extension_proxy_PublishIncrementalFile_0100 - * @tc.desc: 测试 PublishIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_PublishIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_PublishIncrementalFile_0100"; - try { - string fileName = "1.tar"; - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->PublishIncrementalFile(fileName); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - ret = proxy_->PublishIncrementalFile(fileName); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(NO_ERROR)); - ret = proxy_->PublishIncrementalFile(fileName); - EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by PublishIncrementalFile."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_PublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_HandleIncrementalBackup_0100 - * @tc.name: SUB_Ext_Extension_proxy_HandleIncrementalBackup_0100 - * @tc.desc: 测试 HandleIncrementalBackup 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_HandleIncrementalBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_HandleIncrementalBackup_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->HandleIncrementalBackup(UniqueFd(-1), UniqueFd(-1)); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(NO_ERROR)); - ret = proxy_->HandleIncrementalBackup(UniqueFd(-1), UniqueFd(-1)); - EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by HandleIncrementalBackup."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_HandleIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_IncrementalOnBackup_0100 - * @tc.name: SUB_Ext_Extension_proxy_IncrementalOnBackup_0100 - * @tc.desc: 测试 IncrementalOnBackup 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_IncrementalOnBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_IncrementalOnBackup_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->IncrementalOnBackup(true); - EXPECT_NE(ret, ErrCode(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(false)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->IncrementalOnBackup(true); - EXPECT_NE(ret, ErrCode(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->IncrementalOnBackup(true); - EXPECT_EQ(ret, ErrCode(EPERM)); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock_, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_TRUE(proxy_ != nullptr); - ret = proxy_->IncrementalOnBackup(true); - EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by IncrementalOnBackup."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_IncrementalOnBackup_0100"; -} - -/** - * @tc.number: SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100 - * @tc.name: SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100 - * @tc.desc: 测试 GetIncrementalBackupFileHandle 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - auto [incrementalFd, manifestFd] = proxy_->GetIncrementalBackupFileHandle(); - EXPECT_EQ(incrementalFd, -1); - EXPECT_EQ(manifestFd, -1); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR)); - EXPECT_CALL(*messageParcelMock_, ReadFileDescriptor()).WillOnce(Return(-1)).WillOnce(Return(-1)); - tie(incrementalFd, manifestFd) = proxy_->GetIncrementalBackupFileHandle(); - EXPECT_EQ(incrementalFd, -1); - EXPECT_EQ(manifestFd, -1); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by GetIncrementalBackupFileHandle."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 0396ce79aaf467b5d87ccc9ab43752bdd9d5de4c Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 20 May 2025 14:42:58 +0800 Subject: [PATCH 2/8] service_client_test modify. Signed-off-by: BrainL Change-Id: I78de99e3076f2130874e621cfc46bacd0b513b3f --- .../backup_sa/module_client/service_client_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index e1d19b4a8..f21fbcb18 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -346,13 +346,13 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_EQ(errMsg, ""); ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_EQ(errMsg, ""); ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::OK)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_EQ(errMsg, ""); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; -- Gitee From 647d00a0b1ecf89ff2f4155427f2b25c9d079259 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 21 May 2025 18:01:30 +0800 Subject: [PATCH 3/8] fixed the gn for mock. Signed-off-by: BrainL Change-Id: I2610826ef2b9923f2a7ade6b84a52a81220b8a07 --- tests/unittests/backup_sa/module_client/BUILD.gn | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn index bb988d321..6f1f0af70 100644 --- a/tests/unittests/backup_sa/module_client/BUILD.gn +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -30,13 +30,16 @@ ohos_unittest("service_client_test") { ] sources = [ + "${path_backup}/frameworks/native/backup_kit_inner/src/b_file_info.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_reverse.cpp", "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "service_client_test.cpp", - "service_mock.cpp", ] deps = [ - "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] -- Gitee From 3a5600ce638a8ae888ca17f555c0475f4e246877 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 25 May 2025 16:29:27 +0800 Subject: [PATCH 4/8] afs idl fd modify. Signed-off-by: BrainL Change-Id: I32de1ecff9723413ec9cba2d650db96c1f9cdc96 --- .../native/backup_ext/include/ext_extension.h | 4 +-- .../native/backup_ext/src/ext_extension.cpp | 31 +++++++++++++++---- services/backup_sa/BUILD.gn | 1 - services/backup_sa/ExtensionType.idl | 22 ------------- services/backup_sa/IExtension.idl | 6 ++-- .../src/module_ipc/service_incremental.cpp | 24 ++++++++------ 6 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 services/backup_sa/ExtensionType.idl diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 6687ec5f9..312b23036 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -51,11 +51,11 @@ public: ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleBackup(bool isClearData) override; ErrCode HandleRestore(bool isClearData) override; - ErrCode GetIncrementalFileHandle(const std::string &fileName, UniqueFdGroup &fdGroup) override; + ErrCode GetIncrementalFileHandle(const std::string &fileName, int &fd, int &reportFd, int &errCode) override; ErrCode PublishIncrementalFile(const std::string &fileName) override; ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) override; ErrCode IncrementalOnBackup(bool isClearData) override; - ErrCode GetIncrementalBackupFileHandle(UniqueFdGroup &fdGroup) override; + ErrCode GetIncrementalBackupFileHandle(int &fd, int &reportFd) override; ErrCode GetBackupInfo(std::string &result) override; ErrCode UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) override; void AsyncTaskRestoreForUpgrade(void); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 8bba955eb..ef1f18d10 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -222,7 +222,7 @@ ErrCode BackupExtExtension::GetFileHandleWithUniqueFd(const std::string &fileNam int &fd) { UniqueFd fileHandleFd(GetFileHandle(fileName, getFileHandleErrCode)); - fd = fileHandleFd.Release(); + fd = dup(fileHandleFd.Get()); return ERR_OK; } @@ -388,13 +388,14 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm return {errCode, move(fd), move(reportFd)}; } -ErrCode BackupExtExtension::GetIncrementalFileHandle(const std::string &fileName, UniqueFdGroup &fdGroup) +ErrCode BackupExtExtension::GetIncrementalFileHandle(const std::string &fileName, + int &fd, int &reportFd, int &errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - auto [errCode, fd, reportFd] = GetIncrementalFileHandle(fileName); - fdGroup.errCode = errCode; - fdGroup.fd = fd.Release(); - fdGroup.reportFd = reportFd.Release(); + auto [errCode, fdval, reportFdVal] = GetIncrementalFileHandle(fileName); + errCode = errCode; + fd = dup(fdval.Get()); + reportFd = dup(reportFdVal.Get()); return ERR_OK; } @@ -532,6 +533,7 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro } else { HILOGW("Current file execute app file ready interface failed, ret is:%{public}d", ret); } + close(fdval); fdNum++; RefreshTimeInfo(startTime, fdNum); } @@ -713,6 +715,7 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) } else { HILOGE("TarFileReady AppFileReady fail to be invoked for %{public}s: ret = %{public}d", tarName.c_str(), ret); } + close(fdval); return ret; } @@ -2081,6 +2084,20 @@ ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) return ERR_OK; } +ErrCode BackupExtExtension::GetIncrementalBackupFileHandle(int &fd, int &reportFd) +{ + auto [fd, reportFd] = GetIncrementalBackupFileHandle(); + fd = dup(fd.Get()); + reportFd = dup(reportFd.Get()); + return BError(BError::Codes::OK).GetCode(); +} + +tuple BackupExtExtension::GetIncrementalBackupFileHandle() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return {UniqueFd(-1), UniqueFd(-1)}; +} + static void WriteFile(const string &filename, const vector &srcFiles) { fstream f; @@ -2215,6 +2232,8 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, } else { HILOGI("successfully but the IncrementalAllFileReady interface fails to be invoked: %{public}d", ret); } + close(fdval); + close(manifestFdval); return ret; } diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index d20605286..c5983d3a5 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -22,7 +22,6 @@ idl_gen_interface("backup_idl") { "IServiceReverse.idl", ] sources_common = [ - "ExtensionType.idl", "ServiceReverseType.idl", "ServiceType.idl", ] diff --git a/services/backup_sa/ExtensionType.idl b/services/backup_sa/ExtensionType.idl deleted file mode 100644 index 19014d92c..000000000 --- a/services/backup_sa/ExtensionType.idl +++ /dev/null @@ -1,22 +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. - */ - -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/IExtension.idl b/services/backup_sa/IExtension.idl index 4dcff5076..1d9b70b3a 100644 --- a/services/backup_sa/IExtension.idl +++ b/services/backup_sa/IExtension.idl @@ -13,18 +13,18 @@ * limitations under the License. */ -import ExtensionType; interface OHOS.FileManagement.Backup.IExtension{ [ipccode 1] void GetFileHandleWithUniqueFd([in] String fileName, [out] int getFileHandleErrCode, [out] FileDescriptor fd); [ipccode 2] void HandleClear(); [ipccode 3] void HandleBackup([in] boolean isClearData); [ipccode 4] void PublishFile([in] String fileName); [ipccode 5] void HandleRestore([in] boolean isClearData); - [ipccode 6] void GetIncrementalFileHandle([in] String fileName, [out] UniqueFdGroup fdGroup); + [ipccode 6] void GetIncrementalFileHandle([in] String fileName, + [out] FileDescriptor fd, [out] FileDescriptor reportFd, [out] int errCode); [ipccode 7] void PublishIncrementalFile([in] String fileName); [ipccode 8] void HandleIncrementalBackup([in] FileDescriptor incrementalFd, [in] FileDescriptor manifestFd); [ipccode 9] void IncrementalOnBackup([in] boolean isClearData); - [ipccode 10] void GetIncrementalBackupFileHandle([out] UniqueFdGroup fdGroup); + [ipccode 10] void GetIncrementalBackupFileHandle([out] FileDescriptor fd, [out] FileDescriptor reportFd); [ipccode 11] void GetBackupInfo([out] String getBackupInfoResult); [ipccode 12] void UpdateFdSendRate([in] String bundleName, [in] int sendRate); [ipccode 13] void User0OnBackup(); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index adfbf0e69..0c90e37e5 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -762,11 +762,13 @@ ErrCode Service::SendIncrementalFileHandle(const std::string &bundleName, const HILOGE("GetIncrementalFileHandle failed, bundleName:%{public}s", bundleName.c_str()); return BError(BError::Codes::SA_INVAL_ARG); } - UniqueFdGroup fdGroup; - proxy->GetIncrementalFileHandle(fileName, fdGroup); - UniqueFd fd(fdGroup.fd); - UniqueFd reportFd(fdGroup.reportFd); - auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); + int fdVal = -1; + int reportFdVal = -1; + int errCode = -1; + proxy->GetIncrementalFileHandle(fileName, fdVal, reportFdVal, errCode); + UniqueFd fd(fdVal); + UniqueFd reportFd(reportFdVal); + auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); if (err != ERR_OK) { HILOGE("Failed to send file handle, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), GetAnonyPath(fileName).c_str()); @@ -829,11 +831,13 @@ bool Service::IncrementalBackup(const string &bundleName) } ErrCode Service::HelpToAppIncrementalFileReady(const string &bundleName, const string &fileName, sptr proxy) { - UniqueFdGroup fdGroup; - proxy->GetIncrementalFileHandle(fileName, fdGroup); - UniqueFd fd(fdGroup.fd); - UniqueFd reportFd(fdGroup.reportFd); - auto ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); + int fdVal = -1; + int reportFdVal = -1; + int errCode = -1; + proxy->GetIncrementalFileHandle(fileName, fdVal, reportFdVal, errCode); + UniqueFd fd(fdVal); + UniqueFd reportFd(reportFdVal); + auto ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); return ret; } -- Gitee From bdd1047c7ffd9dd0513bbec9eb06467a022dcbfb Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 25 May 2025 16:40:28 +0800 Subject: [PATCH 5/8] fixed ut Signed-off-by: BrainL Change-Id: I4c9356ab3895d2ffe8c8ebb7def44233ff67e557 --- .../backup_sa/module_client/BUILD.gn | 5 +- .../module_client/service_client_test.cpp | 6 +- .../backup_sa/module_client/service_mock.cpp | 625 ------------------ 3 files changed, 4 insertions(+), 632 deletions(-) delete mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn index 6f1f0af70..47a26fff8 100644 --- a/tests/unittests/backup_sa/module_client/BUILD.gn +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -30,15 +30,12 @@ ohos_unittest("service_client_test") { ] sources = [ - "${path_backup}/frameworks/native/backup_kit_inner/src/b_file_info.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_reverse.cpp", "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "service_client_test.cpp", ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/services/backup_sa:backup_sa_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index f21fbcb18..0cecf86a5 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -346,13 +346,13 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; diff --git a/tests/unittests/backup_sa/module_client/service_mock.cpp b/tests/unittests/backup_sa/module_client/service_mock.cpp deleted file mode 100644 index 08ffa9783..000000000 --- a/tests/unittests/backup_sa/module_client/service_mock.cpp +++ /dev/null @@ -1,625 +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 "module_ipc/service.h" - -#include -#include -#include -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -int32_t Service::GetUserIdDefault() -{ - return 0; -} - -void Service::OnStart() {} - -void Service::OnStop() {} - -ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) -{ - fd = 1; - return BError(BError::Codes::OK); -} -ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) -{ - if (reverseIpcRemoteObject == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - int32_t restoreType, - int32_t userId) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (detailInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (restoreType < 0 || userId < 0 || fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSessionData(int fd, - const std::vector &bundleNames, - int32_t restoreType, - int32_t userId) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (restoreType < 0 || userId < 0 || fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} -ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( - const std::vector &bundlesToBackup, - const std::vector &bundleInfos) -{ - if (bundlesToBackup.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (bundleInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetLocalCapabilities(int &fd) -{ - 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) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::InitBackupSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::Start() -{ - GTEST_LOG_(INFO) << "Service mock start"; - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishFile(const BFileInfo &fileInfo) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) -{ - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppDone(ErrCode errCode) -{ - if (errCode == 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (errCode == -1) { - return BError(BError::BackupErrorCode::E_EMPTY); - } - if (errCode > 0) { - return BError(BError::Codes::OK); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) -{ - if (restoreRetInfo.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (bundleInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::Finish() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -void Service::OnBackupExtensionDied(const string &&bundleName, bool isCleanCalled) {} - -void Service::ExtConnectDied(const string &callName) {} - -void Service::ExtStart(const string &bundleName) {} - -int Service::Dump(int fd, const vector &args) -{ - return 0; -} - -void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) -{ - GTEST_LOG_(INFO) << "ExtConnectFailed is OK"; -} - -void Service::ExtConnectDone(string bundleName) {} - -void Service::ClearSessionAndSchedInfo(const string &bundleName) {} - -ErrCode Service::VerifyCaller() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) -{ - return BError(BError::Codes::OK); -} - -void Service::OnAllBundlesFinished(ErrCode errCode) {} - -void Service::OnStartSched() {} - -void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} - -void Service::SessionDeactive() {} - -ErrCode Service::Release() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (!bundleName.empty()) { - result = 0; - return BError(BError::Codes::OK); - } - result = BError(BError::Codes::OK); - return BError(BError::Codes::OK); -} - -ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) -{ - fd = 1; - return BError(BError::Codes::OK); -} - -ErrCode Service::GetAppLocalListAndDoIncrementalBackup() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitIncrementalBackupSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::AppIncrementalFileReady(const std::string &fileName, - int fd, - int manifestFd, - int32_t appIncrementalFileReadyErrCode) -{ - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fd < 0 || manifestFd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppIncrementalDone(ErrCode errCode) -{ - if (errCode == 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (errCode == -1) { - return BError(BError::BackupErrorCode::E_EMPTY); - } - if (errCode > 0) { - return BError(BError::Codes::OK); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) -{ - result = "abc"; - return BError(BError::Codes::OK); -} - -ErrCode Service::StartExtTimer(bool &isExtStart) -{ - if (isExtStart) { - return BError(BError::Codes::OK); - } - - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::StartFwkTimer(bool &isFwkStart) -{ - if (isFwkStart) { - return BError(BError::Codes::OK); - } - - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::StopExtTimer(bool &isExtStop) -{ - if (isExtStop) { - return BError(BError::Codes::OK); - } - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::RefreshDataSize(int64_t totalDatasize) -{ - if (totalDatasize < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - if (timeout < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - result = true; - return BError(BError::Codes::OK); -} - -ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - if (sendRate < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - result = true; - return BError(BError::Codes::OK); -} - -ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) -{ - if (processInfo.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -void Service::OnSABackup(const std::string &bundleName, - const int &fd, - const std::string &result, - const ErrCode &errCode) -{ -} - -void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} - -ErrCode Service::ClearResidualBundleData(const std::string &bundleName) -{ - return BError(BError::Codes::OK); -} - -std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) -{ - return make_shared(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) -{ -} - -void Service::BundleBeginRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::BundleEndRadarReport(const std::string &bundleName, - ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::FileReadyRadarReport(const std::string &bundleName, - const std::string &fileName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} - -void Service::OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) {} - -std::string Service::GetCallerName() -{ - return ""; -} - -bool Service::IsReportBundleExecFail(const std::string &bundleName) -{ - return true; -} - -void Service::ClearBundleRadarReport() {} - -void Service::UpdateBundleRadarReport(const std::string &bundleName) {} - -bool Service::IsReportFileReadyFail(const std::string &bundleName) -{ - return true; -} - -void Service::ClearFileReadyRadarReport() {} - -void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} - -void Service::ClearFailedBundles() {} - -void Service::GetOldDeviceBackupVersion() {} - -void Service::CreateDirIfNotExist(const std::string &path) {} - -void Service::StartRunningTimer(const std::string &bundleName) {} - -std::vector Service::GetSupportBackupBundleNames(vector &, - bool, - const vector &) -{ - return {}; -} - -void Service::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::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} - -ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) -{ - return BError(BError::Codes::OK); -} - -void Service::GetDataSizeStepByStep(bool isPreciseScan, vector bundleNameList, string &scanning) {} - -void Service::GetPresumablySize(vector bundleNameList, string &scanning) {} - -void Service::GetPrecisesSize(vector bundleNameList, string &scanning) {} - -void Service::WriteToList(BJsonUtil::BundleDataSize bundleDataSize) {} - -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::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} - -bool Service::GetScanningInfo(wptr obj, size_t scannedSize, string &scanning) -{ - return true; -} - -void Service::SetScanningInfo(string &scanning, string name) {} -} // namespace OHOS::FileManagement::Backup -- Gitee From d337ef651c177cb358aef196c20dfb6a2a505e30 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 25 May 2025 20:22:58 +0800 Subject: [PATCH 6/8] fixed ut. Signed-off-by: BrainL Change-Id: Ie5385f13878e64efc50e6e0240b4dbda2749e16a --- .../native/backup_ext/include/ext_extension.h | 2 +- .../native/backup_ext/src/ext_extension.cpp | 18 ++---------------- .../backup_ext/src/sub_ext_extension.cpp | 8 ++++---- services/backup_sa/IExtension.idl | 2 +- .../src/module_ipc/service_incremental.cpp | 12 ++++++------ .../include/svc_extension_proxy_mock.h | 4 ++-- .../module_ipc/svc_extension_proxy_mock.cpp | 5 +++-- .../backup_impl/include/ext_extension_mock.h | 5 +++-- .../module_ipc/service_incremental_test.cpp | 8 ++++---- .../backup_sa/module_ipc/sub_service_test.cpp | 4 ++-- 10 files changed, 28 insertions(+), 40 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 312b23036..1a0086f2e 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -51,7 +51,7 @@ public: ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleBackup(bool isClearData) override; ErrCode HandleRestore(bool isClearData) override; - ErrCode GetIncrementalFileHandle(const std::string &fileName, int &fd, int &reportFd, int &errCode) override; + ErrCode GetIncrementalFileHandle(const std::string &fileName, int &fd, int &reportFd, int32_t &fdErrCode) override; ErrCode PublishIncrementalFile(const std::string &fileName) override; ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) override; ErrCode IncrementalOnBackup(bool isClearData) override; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index ef1f18d10..72010a892 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -389,11 +389,11 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm } ErrCode BackupExtExtension::GetIncrementalFileHandle(const std::string &fileName, - int &fd, int &reportFd, int &errCode) + int &fd, int &reportFd, int32_t &fdErrCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto [errCode, fdval, reportFdVal] = GetIncrementalFileHandle(fileName); - errCode = errCode; + fdErrCode = errCode; fd = dup(fdval.Get()); reportFd = dup(reportFdVal.Get()); return ERR_OK; @@ -2084,20 +2084,6 @@ ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) return ERR_OK; } -ErrCode BackupExtExtension::GetIncrementalBackupFileHandle(int &fd, int &reportFd) -{ - auto [fd, reportFd] = GetIncrementalBackupFileHandle(); - fd = dup(fd.Get()); - reportFd = dup(reportFd.Get()); - return BError(BError::Codes::OK).GetCode(); -} - -tuple BackupExtExtension::GetIncrementalBackupFileHandle() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return {UniqueFd(-1), UniqueFd(-1)}; -} - static void WriteFile(const string &filename, const vector &srcFiles) { fstream f; diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index f54990c69..d9c7b07ec 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1668,11 +1668,11 @@ void BackupExtExtension::PreDealExcludes(std::vector &excludes) excludes.resize(j); } -ErrCode BackupExtExtension::GetIncrementalBackupFileHandle(UniqueFdGroup& fdGroup) +ErrCode BackupExtExtension::GetIncrementalBackupFileHandle((int &fd, int &reportFd) { - auto [fd, reportFd] = GetIncrementalBackupFileHandle(); - fdGroup.fd = fd.Release(); - fdGroup.reportFd = reportFd.Release(); + auto [fdval, reportFdval] = GetIncrementalBackupFileHandle(); + fd = dup(fdval.Get()); + reportFd = dup(reportFd.Get()); return BError(BError::Codes::OK).GetCode(); } diff --git a/services/backup_sa/IExtension.idl b/services/backup_sa/IExtension.idl index 1d9b70b3a..c9c88cd95 100644 --- a/services/backup_sa/IExtension.idl +++ b/services/backup_sa/IExtension.idl @@ -20,7 +20,7 @@ interface OHOS.FileManagement.Backup.IExtension{ [ipccode 4] void PublishFile([in] String fileName); [ipccode 5] void HandleRestore([in] boolean isClearData); [ipccode 6] void GetIncrementalFileHandle([in] String fileName, - [out] FileDescriptor fd, [out] FileDescriptor reportFd, [out] int errCode); + [out] FileDescriptor fd, [out] FileDescriptor reportFd, [out] int fdErrCode); [ipccode 7] void PublishIncrementalFile([in] String fileName); [ipccode 8] void HandleIncrementalBackup([in] FileDescriptor incrementalFd, [in] FileDescriptor manifestFd); [ipccode 9] void IncrementalOnBackup([in] boolean isClearData); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 0c90e37e5..2215a7110 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -762,9 +762,9 @@ ErrCode Service::SendIncrementalFileHandle(const std::string &bundleName, const HILOGE("GetIncrementalFileHandle failed, bundleName:%{public}s", bundleName.c_str()); return BError(BError::Codes::SA_INVAL_ARG); } - int fdVal = -1; - int reportFdVal = -1; - int errCode = -1; + int fdVal = BConstants::INVALID_FD_NUM; + int reportFdVal = BConstants::INVALID_FD_NUM; + int errCode = BConstants::INVALID_FD_NUM; proxy->GetIncrementalFileHandle(fileName, fdVal, reportFdVal, errCode); UniqueFd fd(fdVal); UniqueFd reportFd(reportFdVal); @@ -831,9 +831,9 @@ bool Service::IncrementalBackup(const string &bundleName) } ErrCode Service::HelpToAppIncrementalFileReady(const string &bundleName, const string &fileName, sptr proxy) { - int fdVal = -1; - int reportFdVal = -1; - int errCode = -1; + int fdVal = BConstants::INVALID_FD_NUM; + int reportFdVal = BConstants::INVALID_FD_NUM; + int errCode = BConstants::INVALID_FD_NUM; proxy->GetIncrementalFileHandle(fileName, fdVal, reportFdVal, errCode); UniqueFd fd(fdVal); UniqueFd reportFd(reportFdVal); diff --git a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h index 429f8b618..912fb53c7 100644 --- a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -30,11 +30,11 @@ MOCK_METHOD(ErrCode, HandleClear, ()); MOCK_METHOD(ErrCode, HandleBackup, (bool)); MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); MOCK_METHOD(ErrCode, HandleRestore, (bool)); -MOCK_METHOD(ErrCode, GetIncrementalFileHandle, (const std::string &, UniqueFdGroup &)); +MOCK_METHOD(ErrCode, GetIncrementalFileHandle, (const std::string &, int &, int &, int32_t &)); MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &)); MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool)); -MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandle, (UniqueFdGroup &)); +MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandle, (int &, int &)); MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); MOCK_METHOD(ErrCode, UpdateFdSendRate, (const std::string &, int32_t)); MOCK_METHOD(ErrCode, User0OnBackup, ()); diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index d9e0e8c94..e73ee49e1 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -48,7 +48,8 @@ ErrCode ExtensionProxy::GetBackupInfo(std::string &result) return 0; } -ErrCode ExtensionProxy::GetIncrementalFileHandle(const string &fileName, UniqueFdGroup &fdGroup) +ErrCode ExtensionProxy::GetIncrementalFileHandle(const string &fileName, + int &fd, int &reportFd, int32_t &fdErrCode) { return 0; } @@ -78,7 +79,7 @@ ErrCode ExtensionProxy::User0OnBackup() return 0; } -ErrCode ExtensionProxy::GetIncrementalBackupFileHandle(UniqueFdGroup &fdGroup) +ErrCode ExtensionProxy::GetIncrementalBackupFileHandle(int &fd, int &reportFd) { return 0; } diff --git a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h index 34aaef2ae..495583473 100644 --- a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h @@ -111,7 +111,8 @@ public: return BError(BError::Codes::OK); }; - ErrCode GetIncrementalFileHandle(const std::string &fileName, UniqueFdGroup &fdGroup) override + ErrCode GetIncrementalFileHandle(const std::string &fileName, + int &fd, int &reportFd, int32_t &fdErrCode) override { return BError(BError::Codes::OK); } @@ -139,7 +140,7 @@ public: return BError(BError::Codes::OK); }; - ErrCode GetIncrementalBackupFileHandle(UniqueFdGroup &fdGroup) override + ErrCode GetIncrementalBackupFileHandle(int &fd, int &reportFd) override { return BError(BError::Codes::OK); }; 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 708919917..5813e2ea9 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -1354,7 +1354,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetIncrementalFileHandle EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); @@ -1369,7 +1369,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetIncrementalFileHandle EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); @@ -1488,7 +1488,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetOldBackupVersion()).WillOnce(Return("")); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_TRUE(service->IncrementalBackup(bundleName)); } catch (...) { @@ -1525,7 +1525,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetOldBackupVersion()).WillOnce(Return("1.0.0")); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_TRUE(service->IncrementalBackup(bundleName)); 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 bb02a82c8..06c29f388 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -300,7 +300,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, TestSize.Level1) EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(0)); auto ret = service->GetFileHandle(bundleName, fileName); @@ -313,7 +313,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, TestSize.Level1) EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); -- Gitee From 0b736600f5ff95a8c8f5739d3ad941e5e5ffa9fb Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 25 May 2025 20:33:37 +0800 Subject: [PATCH 7/8] fixed ut Signed-off-by: BrainL Change-Id: I340920e6ee8e1bdd54511909dd3470ee43cd84d4 --- frameworks/native/backup_ext/src/sub_ext_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index d9c7b07ec..81ac52519 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1679,6 +1679,6 @@ ErrCode BackupExtExtension::GetIncrementalBackupFileHandle((int &fd, int &report tuple BackupExtExtension::GetIncrementalBackupFileHandle() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return {UniqueFd(-1), UniqueFd(-1)}; + return {UniqueFd(BConstants::INVALID_FD_NUM), UniqueFd(BConstants::INVALID_FD_NUM)}; } } // namespace OHOS::FileManagement::Backup -- Gitee From 865ad4a767f1144c196f2e19cdfee6f0b329daac Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 25 May 2025 21:43:07 +0800 Subject: [PATCH 8/8] fixedcode Signed-off-by: BrainL Change-Id: Idc5d28621b72ce9592c98c7447d05828cf42d97e --- frameworks/native/backup_ext/src/sub_ext_extension.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 81ac52519..b771262fe 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -1668,11 +1668,11 @@ void BackupExtExtension::PreDealExcludes(std::vector &excludes) excludes.resize(j); } -ErrCode BackupExtExtension::GetIncrementalBackupFileHandle((int &fd, int &reportFd) +ErrCode BackupExtExtension::GetIncrementalBackupFileHandle(int &fd, int &reportFd) { auto [fdval, reportFdval] = GetIncrementalBackupFileHandle(); fd = dup(fdval.Get()); - reportFd = dup(reportFd.Get()); + reportFd = dup(reportFdval.Get()); return BError(BError::Codes::OK).GetCode(); } -- Gitee