From 8e577918b61349241cbae10c3af005ecf661ac3a Mon Sep 17 00:00:00 2001 From: mano-fan Date: Wed, 19 Feb 2025 14:43:32 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86IDL=E5=8C=96=20=E5=BA=94=E7=94=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=AE=A1=E7=90=86IDL=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.gni | 4 +- bundle.json | 12 +- frameworks/native/backup_ext/BUILD.gn | 3 +- .../native/backup_ext/include/ext_extension.h | 24 +- .../backup_ext/include/ext_extension_stub.h | 54 - .../native/backup_ext/src/ext_backup.cpp | 3 +- .../native/backup_ext/src/ext_extension.cpp | 133 +- .../backup_ext/src/ext_extension_stub.cpp | 266 --- .../backup_ext/src/sub_ext_extension.cpp | 18 +- .../include/service_reverse.h | 74 +- .../include/service_reverse_stub.h | 70 - .../backup_kit_inner/src/b_file_info.cpp | 2 +- .../src/b_incremental_backup_session.cpp | 41 +- .../src/b_incremental_data.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 65 +- .../b_incremental_session_restore_async.cpp | 41 +- .../backup_kit_inner/src/b_session_backup.cpp | 43 +- .../src/b_session_restore.cpp | 63 +- .../src/b_session_restore_async.cpp | 39 +- .../backup_kit_inner/src/service_client.cpp | 148 ++ .../src/service_incremental_proxy.cpp | 417 ----- .../src/service_incremental_reverse.cpp | 83 +- .../backup_kit_inner/src/service_proxy.cpp | 839 ---------- .../backup_kit_inner/src/service_reverse.cpp | 75 +- .../src/service_reverse_stub.cpp | 359 ---- .../native/backup_kit_inner/BUILD.gn | 144 +- .../native/backup_kit_inner/ExtensionType.idl | 22 + .../native/backup_kit_inner/IExtension.idl | 31 + .../native/backup_kit_inner/IService.idl | 72 + .../backup_kit_inner/IServiceReverse.idl | 63 + .../ServiceReverseInnerType.idl | 23 + .../backup_kit_inner/ServiceReverseType.idl | 24 + .../impl/b_incremental_backup_session.h | 4 +- .../impl/b_incremental_restore_session.h | 4 +- .../b_incremental_session_restore_async.h | 5 +- .../backup_kit_inner/impl/b_session_backup.h | 4 +- .../backup_kit_inner/impl/b_session_restore.h | 2 +- .../impl/b_session_restore_async.h | 5 +- .../{b_file_info.h => backup_file_info.h} | 0 ...ental_data.h => backup_incremental_data.h} | 0 .../native/backup_kit_inner/impl/i_service.h | 104 -- .../backup_kit_inner/impl/i_service_reverse.h | 76 - .../backup_kit_inner/impl/service_client.h | 56 +- .../impl/{i_extension.h => service_common.h} | 36 +- .../backup_kit_inner/impl/service_proxy.h | 112 -- .../kits/js/backup/parse_inc_info_from_js.h | 2 +- .../kits/js/backup/prop_n_operation.cpp | 38 +- .../session_incremental_backup_n_exporter.cpp | 2 +- services/backup_sa/BUILD.gn | 6 +- .../include/module_external/bms_adapter.h | 2 +- .../backup_sa/include/module_ipc/service.h | 106 +- .../module_ipc/service_reverse_proxy.h | 68 - .../include/module_ipc/service_stub.h | 85 - .../module_ipc/svc_backup_connection.h | 2 +- .../module_ipc/svc_restore_deps_manager.h | 3 +- .../include/module_ipc/svc_session_manager.h | 19 +- .../src/module_external/bms_adapter.cpp | 2 +- services/backup_sa/src/module_ipc/service.cpp | 346 ++-- .../src/module_ipc/service_incremental.cpp | 181 ++- .../service_incremental_reverse_proxy.cpp | 274 ---- .../src/module_ipc/service_reverse_proxy.cpp | 259 --- .../backup_sa/src/module_ipc/service_stub.cpp | 858 ---------- .../backup_sa/src/module_ipc/sub_service.cpp | 116 +- .../src/module_ipc/svc_backup_connection.cpp | 4 +- .../svc_extension_incremental_proxy.cpp | 173 -- .../src/module_ipc/svc_extension_proxy.cpp | 215 --- .../src/module_ipc/svc_session_manager.cpp | 32 +- .../src/module_sched/sched_scheduler.cpp | 8 +- test/fuzztest/backupext_fuzzer/BUILD.gn | 1 - .../backupext_fuzzer/backupext_fuzzer.cpp | 150 +- test/fuzztest/backupsa_fuzzer/BUILD.gn | 1 + .../backupsa_fuzzer/backupsa_fuzzer.cpp | 10 +- .../backupsaanother_fuzzer.cpp | 22 +- .../backupsaappend_fuzzer.cpp | 18 +- .../backupservicestub_fuzzer.cpp | 569 +------ .../backupservicestubbranch_fuzzer.cpp | 861 +--------- test/fuzztest/servicereverse_fuzzer/BUILD.gn | 2 + .../backup_ext/include/ext_extension_mock.h | 40 +- .../include/ext_extension_stub_mock.h | 2 +- .../backup_ext/src/ext_extension_mock.cpp | 20 + .../src/ext_extension_stub_mock.cpp | 4 +- .../backup_kit_inner/service_client_mock.cpp | 80 + .../backup_kit_inner/service_proxy_mock.cpp | 112 +- .../mock/module_ipc/extension_proxy_mock.cpp | 85 + tests/mock/module_ipc/extension_type_mock.cpp | 43 + .../module_ipc/include/extension_proxy_mock.h | 43 + .../include/service_reverse_proxy_mock.h | 64 +- .../module_ipc/include/service_stub_mock.h | 92 +- .../include/svc_extension_proxy_mock.h | 16 +- .../include/svc_session_manager_mock.h | 8 +- tests/mock/module_ipc/message_parcel_mock.h | 4 +- tests/mock/module_ipc/service_mock.cpp | 160 +- .../module_ipc/service_reverse_proxy_mock.cpp | 204 ++- tests/mock/module_ipc/service_stub_mock.cpp | 883 +++++----- .../mock/module_ipc/src/service_stub_mock.cpp | 399 +++-- .../src/svc_session_manager_mock.cpp | 6 +- .../module_ipc/svc_backup_connection_mock.cpp | 2 +- .../module_ipc/svc_extension_proxy_mock.cpp | 14 +- .../module_ipc/svc_session_manager_mock.cpp | 6 +- .../svc_session_manager_throw_mock.cpp | 6 +- .../svc_session_manager_throw_mock.h | 12 +- tests/moduletests/backup_kit_inner/BUILD.gn | 5 +- .../b_session_backup_test.cpp | 2 +- .../b_session_restore_async_test.cpp | 2 +- .../b_session_restore_test.cpp | 2 +- .../unittests/backup_api/backup_impl/BUILD.gn | 2 - .../backup_impl/b_file_info_test.cpp | 2 +- .../backup_impl/include/ext_extension_mock.h | 36 +- .../backup_impl/include/i_service_mock.h | 101 +- .../include/service_reverse_mock.h | 179 +- .../backup_impl/service_proxy_test.cpp | 1444 ----------------- .../backup_impl/service_reverse_stub_test.cpp | 889 ---------- .../backup_impl/service_reverse_test.cpp | 142 +- tests/unittests/backup_ext/BUILD.gn | 62 +- .../backup_ext/ext_extension_stub_test.cpp | 606 ------- tests/unittests/backup_sa/BUILD.gn | 1 + .../backup_sa/module_client/BUILD.gn | 87 + .../module_client/service_client_test.cpp | 434 +++++ .../backup_sa/module_client/service_mock.cpp | 625 +++++++ tests/unittests/backup_sa/module_ipc/BUILD.gn | 22 +- .../module_ipc/extension_proxy_test.cpp | 544 +++++++ .../module_ipc/sched_scheduler_test.cpp | 6 +- .../module_ipc/service_incremental_test.cpp | 218 +-- .../module_ipc/service_other_test.cpp | 148 +- .../module_ipc/service_reverse_proxy_test.cpp | 38 +- .../module_ipc/service_stub_test.cpp | 39 +- .../backup_sa/module_ipc/service_test.cpp | 130 +- .../module_ipc/service_throw_test.cpp | 109 +- .../backup_sa/module_ipc/sub_service_test.cpp | 317 ++-- .../module_ipc/svc_session_manager_test.cpp | 54 +- tests/unittests/backup_sa/session/BUILD.gn | 30 +- .../session/b_incremental_session_test.cpp | 138 +- .../backup_sa/session/service_client_mock.cpp | 51 + .../backup_sa/session/service_client_mock.h | 34 + .../backup_sa/session/service_proxy_mock.cpp | 146 +- .../backup_sa/session/service_proxy_mock.h | 59 +- tests/unittests/backup_tools/BUILD.gn | 5 +- .../backup_tool/tools_op_check_sa_test.cpp | 1 + .../tools_op_restore_async_test.cpp | 2 +- .../backup_tool/tools_op_restore_test.cpp | 2 +- tools/backup_tool/src/tools_op_backup.cpp | 7 +- tools/backup_tool/src/tools_op_check_sa.cpp | 4 +- .../src/tools_op_incremental_backup.cpp | 10 +- utils/BUILD.gn | 8 +- utils/include/b_radar/b_radar.h | 4 +- utils/src/b_radar/b_radar.cpp | 9 +- 146 files changed, 5912 insertions(+), 11249 deletions(-) delete mode 100644 frameworks/native/backup_ext/include/ext_extension_stub.h delete mode 100644 frameworks/native/backup_ext/src/ext_extension_stub.cpp delete mode 100644 frameworks/native/backup_kit_inner/include/service_reverse_stub.h create mode 100644 frameworks/native/backup_kit_inner/src/service_client.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp create mode 100644 interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IExtension.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IService.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl rename interfaces/inner_api/native/backup_kit_inner/impl/{b_file_info.h => backup_file_info.h} (100%) rename interfaces/inner_api/native/backup_kit_inner/impl/{b_incremental_data.h => backup_incremental_data.h} (100%) delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h rename services/backup_sa/include/module_ipc/svc_extension_proxy.h => interfaces/inner_api/native/backup_kit_inner/impl/service_client.h (35%) rename interfaces/inner_api/native/backup_kit_inner/impl/{i_extension.h => service_common.h} (34%) delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h delete mode 100644 services/backup_sa/include/module_ipc/service_reverse_proxy.h delete mode 100644 services/backup_sa/include/module_ipc/service_stub.h delete mode 100644 services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/service_reverse_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/service_stub.cpp delete mode 100644 services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/svc_extension_proxy.cpp create mode 100644 tests/mock/backup_kit_inner/service_client_mock.cpp create mode 100644 tests/mock/module_ipc/extension_proxy_mock.cpp create mode 100644 tests/mock/module_ipc/extension_type_mock.cpp create mode 100644 tests/mock/module_ipc/include/extension_proxy_mock.h delete mode 100644 tests/unittests/backup_api/backup_impl/service_proxy_test.cpp delete mode 100644 tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp delete mode 100644 tests/unittests/backup_ext/ext_extension_stub_test.cpp create mode 100644 tests/unittests/backup_sa/module_client/BUILD.gn create mode 100644 tests/unittests/backup_sa/module_client/service_client_test.cpp create mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp create mode 100644 tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/backup.gni b/backup.gni index 3b07587da..a23d5e191 100644 --- a/backup.gni +++ b/backup.gni @@ -41,7 +41,8 @@ backup_mock_src = [ "$path_backup_mock/module_ipc/service_reverse_proxy_mock.cpp", "$path_backup_mock/module_ipc/service_stub_mock.cpp", "$path_backup_mock/module_ipc/svc_backup_connection_mock.cpp", - "$path_backup_mock/module_ipc/svc_extension_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_type_mock.cpp", ] backup_mock_session_manager_src = [ "$path_backup_mock/module_ipc/svc_session_manager_mock.cpp" ] @@ -55,6 +56,7 @@ backup_mock_service_src = [ "$path_backup_mock/module_ipc/service_mock.cpp" ] backup_mock_utils_include = [ "$path_backup_mock/utils_mock/include" ] backup_mock_proxy_src = [ "$path_backup_mock/backup_kit_inner/service_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_type_mock.cpp", "$path_backup_mock/utils_mock/src/utils_mock_global_variable.cpp", "$path_backup/frameworks/native/backup_kit_inner/src/b_file_info.cpp", ] diff --git a/bundle.json b/bundle.json index d81e5f73a..3bda61564 100644 --- a/bundle.json +++ b/bundle.json @@ -138,17 +138,13 @@ "header_files": [ "backup_kit_inner.h", "impl/b_incremental_backup_session.h", - "impl/b_incremental_data.h", + "impl/backup_incremental_data.h", "impl/b_incremental_restore_session.h", "impl/b_session_restore.h", "impl/b_session_restore_async.h", - "impl/b_file_info.h", - "impl/service_proxy.h", - "impl/b_session_backup.h", - "impl/i_service_ipc_interface_code.h", - "impl/i_service_reverse_ipc_interface_code.h", - "impl/i_service.h", - "impl/i_service_reverse.h" + "impl/backup_file_info.h", + "impl/service_client.h", + "impl/b_session_backup.h" ] } }, diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index ec60d87cd..6a0a7ebcc 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -33,7 +33,6 @@ ohos_shared_library("backup_extension_ability_native") { "src/ext_backup_js.cpp", "src/ext_backup_loader.cpp", "src/ext_extension.cpp", - "src/ext_extension_stub.cpp", "src/sub_ext_extension.cpp", "src/tar_file.cpp", "src/untar_file.cpp", @@ -50,10 +49,12 @@ ohos_shared_library("backup_extension_ability_native") { "${path_ability_runtime}/services/common/include", "${path_ability_runtime}/interfaces/kits/napi/aafwk/inner/napi_common", "${path_ability_runtime}/interfaces/kits/native/appkit/ability_runtime", + "${path_backup}/services/backup_sa/include/module_ipc", ] deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index db933dad2..36cefbbab 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -29,8 +29,9 @@ #include "b_json/b_report_entity.h" #include "b_radar/b_radar.h" #include "ext_backup_js.h" -#include "ext_extension_stub.h" -#include "i_service.h" +#include "extension_stub.h" +#include "service_common.h" +#include "iservice.h" #include "tar_file.h" #include "thread_pool.h" #include "timer.h" @@ -41,20 +42,23 @@ namespace OHOS::FileManagement::Backup { using CompareFilesResult = tuple, map, map>; -class BackupExtExtension : public ExtExtensionStub { +class BackupExtExtension : public ExtensionStub { public: - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override; + ErrCode GetFileHandleWithUniqueFd( + const std::string& fileName, + int32_t& getFileHandleErrCode, + int& fd) override; ErrCode HandleClear() override; ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleBackup(bool isClearData) override; ErrCode HandleRestore(bool isClearData) override; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override; + ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) override; ErrCode PublishIncrementalFile(const std::string &fileName) override; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; + ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) override; ErrCode IncrementalOnBackup(bool isClearData) override; - std::tuple GetIncrementalBackupFileHandle() override; + ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) override; ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; + ErrCode UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); void AsyncTaskIncrementalRestoreForUpgrade(void); @@ -336,6 +340,10 @@ private: void ClearNoPermissionFiles(TarMap &pkgInfo, vector &noPermissionFiles); std::function ReportOnProcessResultCallback(wptr obj, BackupRestoreScenario scenario); + UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode); + std::tuple GetIncrementalFileHandle(const std::string &fileName); + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd); + std::tuple GetIncrementalBackupFileHandle(); private: std::shared_mutex lock_; diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h deleted file mode 100644 index d969b3e9b..000000000 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H -#define OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H - -#include - -#include "i_extension.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ExtExtensionStub : public IRemoteStub { -public: - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ExtExtensionStub(); - ~ExtExtensionStub() = default; - -private: - ErrCode CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleClear(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdPublishFile(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleRestore(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleIncrementalBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdIncrementalOnBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - ErrCode CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleUser0Backup(MessageParcel &data, MessageParcel &reply); - -private: - using ExtensionInterface = int32_t (ExtExtensionStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H \ No newline at end of file diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index e75dcf5f8..94e4a1e76 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -34,7 +34,8 @@ #include "ext_backup_js.h" #include "ext_extension.h" #include "filemgmt_libhilog.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 1119285af..03a2f4824 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -53,9 +53,10 @@ #include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "service_common.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" +#include "extension_type.h" #include "tar_file.h" namespace OHOS::FileManagement::Backup { @@ -239,6 +240,14 @@ static UniqueFd GetFileHandleForSpecialCloneCloud(const string &fileName) } return fd; } +ErrCode BackupExtExtension::GetFileHandleWithUniqueFd(const std::string &fileName, + int32_t &getFileHandleErrCode, + int &fd) +{ + UniqueFd fileHandleFd(GetFileHandle(fileName, getFileHandleErrCode)); + fd = fileHandleFd.Release(); + return ERR_OK; +} UniqueFd BackupExtExtension::GetFileHandle(const string &fileName, int32_t &errCode) { @@ -299,8 +308,9 @@ static tuple GetIncreFileHandleForSpecialVersion(co UniqueFd fd = GetFileHandleForSpecialCloneCloud(fileName); if (fd < 0) { HILOGE("Failed to open file = %{private}s, err = %{public}d", fileName.c_str(), errno); - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForSpecialVersion", "CommonFile", GetAnonyPath(fileName)}; + AuditLog auditLog = { + false, "Open fd failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForSpecialVersion", + "CommonFile", GetAnonyPath(fileName)}; HiAudit::GetInstance(false).Write(auditLog); errCode = errno; } @@ -309,8 +319,9 @@ static tuple GetIncreFileHandleForSpecialVersion(co if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { HILOGE("Failed to create restore folder : %{private}s, err = %{public}d", path.c_str(), errno); errCode = errno; - AuditLog auditLog = {false, "mkdir failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForSpecialVersion", "CommonFile", GetAnonyPath(path)}; + AuditLog auditLog = { + false, "mkdir failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForSpecialVersion", + "CommonFile", GetAnonyPath(path)}; HiAudit::GetInstance(false).Write(auditLog); } string reportName = path + BConstants::BLANK_REPORT_NAME; @@ -358,15 +369,16 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm break; } if (access(tarName.c_str(), F_OK) == 0) { - HILOGE("The file already exists, tarname = %{public}s, err =%{public}d", - GetAnonyPath(tarName).c_str(), errno); + HILOGE("The file already exists, tarname = %{public}s, err =%{public}d", GetAnonyPath(tarName).c_str(), + errno); } fd = UniqueFd(open(tarName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("Failed to open tar file = %{public}s, err = %{public}d", GetAnonyPath(tarName).c_str(), errno); errCode = errno; - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForNormalVersion", "CommonFile", GetAnonyPath(tarName)}; + AuditLog auditLog = { + false, "Open fd failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForNormalVersion", + "CommonFile", GetAnonyPath(tarName)}; HiAudit::GetInstance(false).Write(auditLog); break; } @@ -385,6 +397,17 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm return {errCode, move(fd), move(reportFd)}; } +ErrCode BackupExtExtension::GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, + UniqueFdGroup &fdGroup) +{ + 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(); + return ERR_OK; +} + tuple BackupExtExtension::GetIncrementalFileHandle(const string &fileName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -395,12 +418,12 @@ tuple BackupExtExtension::GetIncrementalFileHandle( } if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { HILOGE("Failed to get incremental file handle, action is invalid, action %{public}d.", - extension_->GetExtensionAction()); + extension_->GetExtensionAction()); throw BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid"); } VerifyCaller(); if (BDir::CheckFilePathInvalid(fileName)) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_IPC, string("Failed to AGetInstance")); } @@ -459,10 +482,10 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) cache.SetExtManage(pkgInfo); cachedEntity.Persist(); close(cachedEntity.GetFd().Release()); - + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); ErrCode ret = - proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)), - ERR_OK); + proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + ERR_OK); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully"); } else { @@ -500,8 +523,8 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro WaitToSendFd(startTime, fdNum); int32_t errCode = ERR_OK; string filePath = std::get<0>(item.second); - UniqueFd fd(open(filePath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(filePath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(filePath).c_str(), errno); errCode = errno; @@ -513,7 +536,7 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro continue; } } - ret = proxy->AppFileReady(item.first, std::move(fd), errCode); + ret = proxy->AppFileReady(item.first, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully, package name is %{public}s", item.first.c_str()); } else { @@ -685,15 +708,15 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string tarPath = path + tarName; int32_t errCode = ERR_OK; - UniqueFd fd(open(tarPath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(tarPath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("TarFileReady open file failed, file name is %{public}s, err = %{public}d", tarName.c_str(), errno); errCode = errno; AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", "TarFileReady", "tarFile", tarPath}; HiAudit::GetInstance(false).Write(auditLog); } - int ret = proxy->AppFileReady(tarName, std::move(fd), errCode); + int ret = proxy->AppFileReady(tarName, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("TarFileReady: AppFileReady success for %{public}s", tarName.c_str()); // 删除文件 @@ -776,7 +799,7 @@ int BackupExtExtension::DoBackup(TarMap &bigFileInfo, map &small return EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -841,9 +864,9 @@ bool BackupExtExtension::RefreshDataSize(int64_t totalSize) HILOGI("no backup datasize, don't need to refresh"); return true; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("start RefreshDatasize by ipc"); @@ -1709,9 +1732,9 @@ void BackupExtExtension::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("AppDone Begin."); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1724,8 +1747,8 @@ void BackupExtExtension::AppDone(ErrCode errCode) void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("restoreRetInfo is %{public}s", restoreRetInfo.c_str()); auto ret = proxy->ServiceResultReport(restoreRetInfo, scenario, errCode); if (ret != ERR_OK) { @@ -1735,8 +1758,8 @@ void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, void BackupExtExtension::StartExtTimer(bool &isExtStart) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start ext timer by ipc."); auto ret = proxy->StartExtTimer(isExtStart); if (ret != ERR_OK) { @@ -1747,8 +1770,8 @@ void BackupExtExtension::StartExtTimer(bool &isExtStart) void BackupExtExtension::StartFwkTimer(bool &isFwkStart) { HILOGI("Do backup, start fwk timer begin."); - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start fwk timer by ipc."); auto ret = proxy->StartFwkTimer(isFwkStart); if (ret != ERR_OK) { @@ -1761,9 +1784,9 @@ bool BackupExtExtension::StopExtTimer() { HILOGI("StopExtTimer start"); bool isExtStop; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("StopExtTimer by ipc"); @@ -1896,6 +1919,17 @@ void BackupExtExtension::FillFileInfos(UniqueFd incrementalFd, allFiles.size(), smallFiles.size(), bigFiles.size()); } +ErrCode BackupExtExtension::HandleIncrementalBackup(int incrementalFd, int manifestFd) +{ + HILOGI("Start HandleIncrementalBackup. incrementalFd:%{public}d, manifestFd:%{public}d", incrementalFd, manifestFd); + UniqueFd incrementalFdUnique(dup(incrementalFd)); + UniqueFd manifestFdUnique(dup(manifestFd)); + ErrCode ret = HandleIncrementalBackup(std::move(incrementalFdUnique), std::move(manifestFdUnique)); + close(incrementalFd); + close(manifestFd); + return ret; +} + ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1925,6 +1959,14 @@ ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) return ERR_OK; } +ErrCode BackupExtExtension::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup& fdGroup) +{ + auto [fd, reportFd] = GetIncrementalBackupFileHandle(); + fdGroup.fd = fd.Get(); + fdGroup.reportFd = reportFd.Get(); + return BError(BError::Codes::OK).GetCode(); +} + tuple BackupExtExtension::GetIncrementalBackupFileHandle() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1961,7 +2003,8 @@ static void WriteFile(const string &filename, const vector &srcFiles, sptr proxy) + const vector &srcFiles, + sptr proxy) { string tarFile = bigFileInfo.begin()->first; string manageFile = GetReportFileName(tarFile); @@ -1969,8 +2012,9 @@ ErrCode BackupExtExtension::IncrementalTarFileReady(const TarMap &bigFileInfo, WriteFile(file, srcFiles); string tarName = string(INDEX_FILE_INCREMENTAL_BACKUP).append(tarFile); - ErrCode ret = proxy->AppIncrementalFileReady(tarFile, UniqueFd(open(tarName.data(), O_RDONLY)), - UniqueFd(open(file.data(), O_RDONLY)), ERR_OK); + int fd = open(tarName.data(), O_RDONLY); + int manifestFd = open(file.data(), O_RDONLY); + ErrCode ret = proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalTarFileReady: The application is packaged successfully"); // 删除文件 @@ -2000,8 +2044,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, auto [path, sta, isBeforeTar] = item.second; int32_t errCode = ERR_OK; WaitToSendFd(startTime, fdNum); - UniqueFd fd(open(path.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(path.data(), O_RDONLY); + if (fdval < 0) { HILOGE("IncrementalBigFileReady open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(path).c_str(), errno); errCode = errno; @@ -2019,7 +2063,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, } string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); WriteFile(file, bigInfo); - ret = proxy->AppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY)), errCode); + int manifestFdval = open(file.data(), O_RDONLY); + ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); if (SUCCEEDED(ret)) { HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", item.first.c_str()); @@ -2051,11 +2096,11 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append("all")); WriteFile(file, srcFiles); - UniqueFd fd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)); - UniqueFd manifestFd(open(file.data(), O_RDONLY)); + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); + int manifestFdval = open(file.data(), O_RDONLY); ErrCode ret = - proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), std::move(fd), std::move(manifestFd), - ERR_OK); + proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + manifestFdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalAllFileReady successfully"); RemoveFile(file); diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp deleted file mode 100644 index 38f4ce2f3..000000000 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ /dev/null @@ -1,266 +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 "ext_extension_stub.h" - -#include -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ExtExtensionStub::ExtExtensionStub() -{ - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_CLAER)] = - &ExtExtensionStub::CmdHandleClear; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_BACKUP)] = - &ExtExtensionStub::CmdHandleBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_PUBLISH_FILE)] = - &ExtExtensionStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_RESTORE)] = - &ExtExtensionStub::CmdHandleRestore; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_PUBLISH_INCREMENTAL_FILE)] = - &ExtExtensionStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_INCREMENTAL_BACKUP)] = - &ExtExtensionStub::CmdHandleIncrementalBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetIncrementalBackupFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_BACKUP_INFO)] = - &ExtExtensionStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_INCREMENTAL_ON_BACKUP)] = - &ExtExtensionStub::CmdIncrementalOnBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE)] = - &ExtExtensionStub::CmdUpdateFdSendRate; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_USER_0_BACKUP)] = - &ExtExtensionStub::CmdHandleUser0Backup; -} - -int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, - MessageParcel &reply, - MessageOption &option) -{ - const std::u16string descriptor = ExtExtensionStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::EXT_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGI("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -ErrCode ExtExtensionStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - int32_t errCode = ERR_OK; - UniqueFd fd = GetFileHandle(fileName, errCode); - bool fdFlag = fd < 0 ? false : true; - reply.WriteBool(fdFlag); - reply.WriteInt32(errCode); - if (fdFlag == true && !reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleClear(MessageParcel &data, MessageParcel &reply) -{ - ErrCode res = HandleClear(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleBackup(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = HandleBackup(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName"); - } - - ErrCode res = PublishFile(fileName); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleRestore(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = HandleRestore(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - auto[errCode, fd, reportFd] = GetIncrementalFileHandle(fileName); - if (!reply.WriteInt32(errCode)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(reportFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName"); - } - - ErrCode res = PublishIncrementalFile(fileName); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd incrementalFd(data.ReadFileDescriptor()); - UniqueFd manifestFd(data.ReadFileDescriptor()); - ErrCode res = HandleIncrementalBackup(move(incrementalFd), move(manifestFd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdIncrementalOnBackup(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = IncrementalOnBackup(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply) -{ - auto [incrementalFd, manifestFd] = GetIncrementalBackupFileHandle(); - if (!reply.WriteFileDescriptor(incrementalFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("CmdGetBackupInfo Begin"); - std::string result; - int ret = GetBackupInfo(result); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the result").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGD("CmdUpdateFdSendRate Begin"); - std::string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive sendRate").GetCode(); - } - int ret = UpdateFdSendRate(bundleName, sendRate); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleUser0Backup(MessageParcel &data, MessageParcel &reply) -{ - HILOGD("CmdHandleUser0Backup Begin"); - int ret = User0OnBackup(); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - return BError(BError::Codes::OK); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 24e2a9c11..08f46d26b 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -51,9 +51,9 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "service_common.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" #include "b_anony/b_anony.h" @@ -483,7 +483,7 @@ std::function BackupExtExtension::IncOnBackupC HILOGI("Begin get IncOnBackupCallback"); return [obj](ErrCode errCode, std::string errMsg) { HILOGI("App onbackup end"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -525,7 +525,7 @@ std::function BackupExtExtension::IncOnBackupE { HILOGI("Begin get HandleIncBackupEx callback"); return [obj](ErrCode errCode, const std::string backupExRetInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -575,7 +575,7 @@ std::function BackupExtExtension::IncOnBackupE void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Report app process error, proxy is empty"); return; @@ -739,9 +739,9 @@ void BackupExtExtension::CloseOnProcessTimeOutTimer() void BackupExtExtension::AppIncrementalDone(ErrCode errCode) { HILOGI("Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -785,7 +785,7 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result) return ERR_OK; } -ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) +ErrCode BackupExtExtension::UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) { try { std::lock_guard lock(updateSendRateLock_); @@ -1173,7 +1173,7 @@ int BackupExtExtension::DoIncrementalBackup(const vector if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { throw BError(errno); } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index c19668973..5973451df 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -25,39 +25,53 @@ namespace OHOS::FileManagement::Backup { class ServiceReverse final : public ServiceReverseStub { public: - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void BackupOnResultReport(std::string result, std::string bundleName) override; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void BackupOnAllBundlesFinished(int32_t errCode) override; - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void BackupOnScanningInfo(std::string scannedInfo) override; + ErrCode BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override; + ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override; + ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode BackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; + ErrCode BackupOnScanningInfo(const std::string &scannedInfo) override; - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void RestoreOnAllBundlesFinished(int32_t errCode) override; - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override; + ErrCode RestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode = 0) override; + ErrCode RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override; + ErrCode IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override; + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override; + ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalBackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; + ErrCode IncrementalBackupOnScanningInfo(const std::string &scannedInfo) override; - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override; + ErrCode IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode) override; + ErrCode IncrementalRestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; public: ServiceReverse() = delete; diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h deleted file mode 100644 index 53a4964aa..000000000 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H - -#include - -#include "i_service_reverse.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceReverseStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceReverseStub(); - ~ServiceReverseStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceReverseStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdIncrementalRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply); - void ServiceReverseStubSupplement(); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H diff --git a/frameworks/native/backup_kit_inner/src/b_file_info.cpp b/frameworks/native/backup_kit_inner/src/b_file_info.cpp index e068da158..883fe8964 100644 --- a/frameworks/native/backup_kit_inner/src/b_file_info.cpp +++ b/frameworks/native/backup_kit_inner/src/b_file_info.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_file_info.h" +#include "backup_file_info.h" #include "filemgmt_libhilog.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index 97de333ab..a9d589c33 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalBackupSession::~BIncrementalBackupSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,14 +46,14 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - - int32_t res = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks))); + sptr reverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitIncrementalBackupSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); @@ -76,13 +76,14 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr newProxy = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitIncrementalBackupSessionWithErrMsg(newProxy, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +102,7 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks void BIncrementalBackupSession::RegisterBackupServiceDied(function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +112,7 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -122,12 +123,14 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct UniqueFd BIncrementalBackupSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -138,7 +141,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -153,7 +156,7 @@ ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector< ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -174,12 +177,12 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, std::vector infos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + int32_t res = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { @@ -194,7 +197,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -205,7 +208,7 @@ ErrCode BIncrementalBackupSession::Release() ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp index 571805e51..a0a5b1037 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "filemgmt_libhilog.h" #include "message_parcel.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 97468695a..1bfe24faf 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -18,9 +18,9 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" - +#include "service_common.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -30,7 +30,7 @@ BIncrementalRestoreSession::~BIncrementalRestoreSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,13 +46,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks))); + sptr session = sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitRestoreSession(session); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -75,15 +76,16 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { errMsg = "Failed to get backup service"; errCode = BError(BError::Codes::SDK_BROKEN_IPC); HILOGE("Init IncrementalRestoreSession failed, %{public}s", errMsg.c_str()); return nullptr; } - errCode = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr session = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitRestoreSessionWithErrMsg(session, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", errCode); AppRadar::Info info ("", "", "create restore session failed"); @@ -104,12 +106,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -119,7 +123,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -128,16 +132,17 @@ ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalRestoreSession::PublishSAFile(BFileInfo fileInfo, UniqueFd fd) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->PublishSAIncrementalFile(fileInfo, move(fd)); + int fdValue = fd.Get(); + return proxy->PublishSAIncrementalFile(fileInfo, fdValue); } ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -147,11 +152,12 @@ ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, cons ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -159,19 +165,23 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -179,14 +189,15 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -207,7 +218,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -217,7 +228,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 170a50db6..9f2aa0e9d 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -19,7 +19,7 @@ #include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -31,7 +31,7 @@ BIncrementalSessionRestoreAsync::~BIncrementalSessionRestoreAsync() HILOGE("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -47,8 +47,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return nullptr; @@ -60,7 +60,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini .onAllBundlesFinished = callbacks.onAllBundlesFinished, .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied}; - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); + sptr reverse = sptr(new ServiceReverse(callbacksTmp)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -79,16 +80,17 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } + return proxy->PublishIncrementalFile(fileInfo); } ErrCode BIncrementalSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -102,12 +104,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fdCode, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -125,11 +129,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fdCode, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -137,24 +144,24 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BIncrementalSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->Release(); } void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -171,7 +178,7 @@ void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function BSessionBackup::Init(Callbacks callbacks) try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - - int32_t res = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks))); + sptrreverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitBackupSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); @@ -76,13 +76,14 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr session = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitBackupSessionWithErrMsg(session, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +102,7 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, void BSessionBackup::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +112,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -121,7 +122,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) ErrCode BSessionBackup::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -132,12 +133,14 @@ ErrCode BSessionBackup::Start() UniqueFd BSessionBackup::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -148,7 +151,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -163,7 +166,7 @@ ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -183,7 +186,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -203,7 +206,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector ErrCode BSessionBackup::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -213,7 +216,7 @@ ErrCode BSessionBackup::Finish() ErrCode BSessionBackup::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -224,7 +227,7 @@ ErrCode BSessionBackup::Release() ErrCode BSessionBackup::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 21fbc125f..1dbfa2040 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -18,8 +18,9 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -30,7 +31,7 @@ BSessionRestore::~BSessionRestore() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,13 +47,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) try { HILOGI("Init RestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacks)); + sptrreverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -72,12 +74,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) UniqueFd BSessionRestore::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -87,7 +91,8 @@ UniqueFd BSessionRestore::GetLocalCapabilities() ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("PublishFile begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -96,7 +101,7 @@ ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestore::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -106,7 +111,7 @@ ErrCode BSessionRestore::Start() ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -114,14 +119,18 @@ ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &f return proxy->GetFileHandle(bundleName, fileName); } -ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("AppendBundles begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -129,18 +138,21 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("AppendBundles begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -148,14 +160,16 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::Finish() { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("Finish begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -165,7 +179,8 @@ ErrCode BSessionRestore::Finish() ErrCode BSessionRestore::Release() { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("Release begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -175,7 +190,8 @@ ErrCode BSessionRestore::Release() void BSessionRestore::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("RegisterBackupServiceDied begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -186,7 +202,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -195,8 +211,9 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) ErrCode BSessionRestore::Cancel(std::string bundleName) { + HILOGI("Cancel begin"); ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index a60c56462..2bbbb4a8b 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -20,7 +20,7 @@ #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -32,7 +32,7 @@ BSessionRestoreAsync::~BSessionRestoreAsync() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -48,8 +48,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -61,7 +61,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied, .onProcess = callbacks.onProcess}; - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); + sptr reverse = sptr(new ServiceReverse(callbacksTmp)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -80,7 +81,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -89,7 +90,7 @@ ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -103,12 +104,14 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -126,12 +129,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -139,14 +145,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -156,7 +163,7 @@ ErrCode BSessionRestoreAsync::Release() void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -173,7 +180,7 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct ErrCode BSessionRestoreAsync::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp new file mode 100644 index 000000000..5451bd047 --- /dev/null +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + unique_lock getInstanceLock(getInstanceMutex_); + unique_lock lock(proxyMutex_); + if (serviceProxy_ != nullptr) { + return serviceProxy_; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOGE("Get an empty samgr"); + return nullptr; + } + sptr loadCallback = sptr(new ServiceProxyLoadCallback()); + if (loadCallback == nullptr) { + HILOGE("loadCallback is nullptr."); + return nullptr; + } + int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); + if (ret != ERR_OK) { + HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", + FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); + return nullptr; + } + + auto waitStatus = + loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), + [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); + if (!waitStatus) { + HILOGE("Load backup sa timeout"); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceClient::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + BError(BError::Codes::SA_INVAL_ARG).GetCode()); + return nullptr; + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Invalid Instance"); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Load backup sa success, systemAbilityId: %{public}d, remoteObject result:%{public}s", systemAbilityId, + (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + unique_lock lock(proxyMutex_); + std::string remoteDescriptor = Str16ToStr8(remoteObject->GetInterfaceDescriptor()); + HILOGE("GetInterfaceDescriptor result:%{public}s", remoteDescriptor.c_str()); + serviceProxy_ = iface_cast(remoteObject); + if (serviceProxy_ == nullptr) { + HILOGE("serviceProxy_ is nullptr"); + return; + } + auto remoteObj = serviceProxy_->AsObject(); + if (!remoteObj) { + HILOGE("Failed to get remote object"); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + + auto callback = [](const wptr &obj) { + ServiceClient::InvaildInstance(); + HILOGE("Backup service died"); + }; + sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); + remoteObj->AddDeathRecipient(deathRecipient); + isLoadSuccess_.store(true); + proxyConVar_.notify_one(); +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + static_cast(BError::Codes::SA_INVAL_ARG)); + proxyConVar_.notify_one(); +} +} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp deleted file mode 100644 index bbb503bfa..000000000 --- a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "service_proxy.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "svc_death_recipient.h" -#include "unique_fd.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::Release() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - if (!WriteParcelableVector(bundleNames, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL), data, reply, - option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION), data, - reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - if (!data.WriteStringVector(infos)) { - HILOGE("Failed to write infos"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - if (!data.WriteFileDescriptor(fd)) { - HILOGE("Failed to send the fd"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (fdFlag == true && !data.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -template -bool ServiceProxy::WriteParcelableVector(const std::vector &parcelableVector, Parcel &data) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!data.WriteUint32(parcelableVector.size())) { - HILOGE("failed to WriteInt32 for parcelableVector.size()"); - return false; - } - - for (const auto &parcelable : parcelableVector) { - if (!data.WriteParcelable(&parcelable)) { - HILOGE("failed to WriteParcelable for parcelable"); - return false; - } - } - - return true; -} - -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!Remote()) { - return BError(BError::Codes::SDK_INVAL_ARG, "Remote is nullptr").GetCode(); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadInt32(result); - HILOGI("ServiceProxy Cancel end, result:%{public}d", result); - - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index 81f6ed9e6..d1f32b5db 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -22,137 +22,162 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) +ErrCode ServiceReverse::IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksIncrementalBackup_.onFileReady(bFileInfo, UniqueFd(fd), UniqueFd(manifestFd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnResultReport(const std::string& result, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksIncrementalBackup_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::IncrementalBackupOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalBackupOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onProcess) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnScanningInfo(std::string scannedInfo) +ErrCode ServiceReverse::IncrementalBackupOnScanningInfo(const std::string& scannedInfo) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBackupSizeReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onBackupSizeReport(scannedInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksIncrementalRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) +ErrCode ServiceReverse::IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) { + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG); + } if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksIncrementalRestore_.onFileReady(bFileInfo, UniqueFd(fd), UniqueFd(manifestFd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) +ErrCode ServiceReverse::IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode) { HILOGI("begin incremental restore on result report, bundleName:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalRestoreOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("begin incremental report processInfo, bundleName:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onProcess) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BIncrementalBackupSession::Callbacks callbacks) diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp deleted file mode 100644 index 187f69ef7..000000000 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ /dev/null @@ -1,839 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_radar/b_radar.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "system_ability_definition.h" -#include "svc_death_recipient.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::InitRestoreSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Start() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilities() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - AppRadar::Info resInfo("", "", ""); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, "ServiceProxy::GetLocalCapabilities", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL, ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = fd < 0 ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(restoreRetInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the restoreRetInfo").GetCode(); - } - if (!data.WriteInt32(static_cast(scenario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!detailInfos.empty() && !data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &detailInfos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - if (!data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Finish() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -sptr ServiceProxy::GetServiceProxyPointer() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - unique_lock getInstanceLock(getInstanceMutex_); - unique_lock lock(proxyMutex_); - if (serviceProxy_ != nullptr) { - return serviceProxy_; - } - - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - HILOGE("Get an empty samgr"); - return nullptr; - } - sptr loadCallback = sptr(new ServiceProxyLoadCallback()); - if (loadCallback == nullptr) { - HILOGE("loadCallback is nullptr."); - return nullptr; - } - int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); - if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", - FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); - return nullptr; - } - - auto waitStatus = - loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), - [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); - if (!waitStatus) { - HILOGE("Load backup sa timeout"); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - BError(BError::Codes::SA_INVAL_ARG).GetCode()); - return nullptr; - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("invalid instance"); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, - (remoteObject != nullptr) ? "true" : "false"); - if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - unique_lock lock(proxyMutex_); - serviceProxy_ = iface_cast(remoteObject); - if (serviceProxy_ == nullptr) { - HILOGD("serviceProxy_ is nullptr"); - return; - } - auto remoteObj = serviceProxy_->AsObject(); - if (!remoteObj) { - HILOGE("Failed to get remote object"); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - - auto callback = [](const wptr &obj) { - ServiceProxy::InvaildInstance(); - HILOGE("Backup service died"); - }; - sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); - remoteObj->AddDeathRecipient(deathRecipient); - isLoadSuccess_.store(true); - proxyConVar_.notify_one(); -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); - proxyConVar_.notify_one(); -} - -ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) -{ - HILOGI("ServiceProxy GetBackupInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadString(result); - HILOGI("ServiceProxy GetBackupInfo end. result = %s", result.c_str()); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) -{ - HILOGI("ServiceProxy UpdateTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteUint32(timeout)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send timeout").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateTimer end. result = %d", result); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) -{ - HILOGD("ServiceProxy UpdateSendRate Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(sendRate)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateSendRate end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) -{ - HILOGD("ServiceProxy NotifyBundleProcessInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(processInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(static_cast(sennario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()-> SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - HILOGI("ServiceProxy NotifyBundleProcessInfo end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) -{ - HILOGI("ServiceProxy StartExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStart); - HILOGI("ServiceProxy StartExtTimer end. isExtStart = %d", isExtStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) -{ - HILOGI("ServiceProxy StartFwkTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isFwkStart); - HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) -{ - HILOGI("ServiceProxy StopExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStop); - HILOGI("ServiceProxy StopExtTimer end. isExtStop = %{public}d", isExtStop); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) -{ - HILOGI("ServiceProxy RefreshDatasize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteInt64(totalSize)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write totalSize").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - bool result = false; - reply.ReadBool(result); - if (!result) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to Refresh Datasize").GetCode(); - } - return BError(BError::Codes::OK, "success"); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("ServiceProxy, start GetLocalCapabilitiesForBundleInfos"); - if (Remote() == nullptr) { - HILOGE("Remote is nullptr"); - return UniqueFd(-EPERM); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - HILOGI("ServiceProxy, end GetLocalCapabilitiesForBundleInfos"); - return fd; -} - -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) -{ - HILOGI("ServiceProxy GetBackupDataSize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteBool(isPreciseScan)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write isPreciseScan").GetCode(); - } - if (!WriteParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write bundleNameList").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 100a0dd09..b84ceb9b9 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -21,137 +21,156 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksBackup_.onFileReady(bFileInfo, UniqueFd(fd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::BackupOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::BackupOnResultReport(const std::string& result, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::BackupOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksBackup_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::BackupOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::BackupOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onProcess) { HILOGI("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnScanningInfo(std::string scannedInfo) +ErrCode ServiceReverse::BackupOnScanningInfo(const std::string& scannedInfo) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBackupSizeReport) { HILOGE("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onBackupSizeReport(scannedInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::RestoreOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) { HILOGD("begin, bundleName is:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksRestore_.onFileReady(bFileInfo, UniqueFd(fd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode) +ErrCode ServiceReverse::RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) { HILOGI("ServiceReverse RestoreOnResultReport bundle %{public}s begin with result: %{public}s", bundleName.c_str(), - result.c_str()); + result.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::RestoreOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onProcess) { HILOGI("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BSessionBackup::Callbacks callbacks) diff --git a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp deleted file mode 100644 index 2fae0a24a..000000000 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "service_reverse_stub.h" - -#include -#include - -#include "b_error/b_error.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; -int32_t ServiceReverseStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, - MessageParcel &reply, - MessageOption &option) -{ - const std::u16string descriptor = ServiceReverseStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return (this->*(interfaceIndex->second))(data, reply); -} -void ServiceReverseStub::ServiceReverseStubSupplement() -{ - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SCANNED_INFO)] = - &ServiceReverseStub::CmdIncrementalBackupOnScanningInfo; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY)] = - &ServiceReverseStub::CmdIncrementalRestoreOnFileReady; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnBundleStarted; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdIncrementalRestoreOnResultReport; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnBundleFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnAllBundlesFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdIncrementalRestoreOnProcessInfo; -} - -ServiceReverseStub::ServiceReverseStub() -{ - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY)] = - &ServiceReverseStub::CmdBackupOnFileReady; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdBackupOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdBackupOnResultReport; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdBackupOnBundleFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdBackupOnAllBundlesFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdBackupOnProcessInfo; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SCANNED_INFO)] = - &ServiceReverseStub::CmdBackupOnScanningInfo; - - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY)] = - &ServiceReverseStub::CmdRestoreOnFileReady; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdRestoreOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdRestoreOnResultReport; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdRestoreOnBundleFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdRestoreOnAllBundlesFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdRestoreOnProcessInfo; - - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY)] = - &ServiceReverseStub::CmdIncrementalBackupOnFileReady; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdIncrementalBackupOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT)] - = &ServiceReverseStub::CmdIncrementalBackupOnResultReport; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalBackupOnBundleFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalBackupOnAllBundlesFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdIncrementalBackupOnProcessInfo; - ServiceReverseStubSupplement(); -} - -int32_t ServiceReverseStub::CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - BackupOnFileReady(bundleName, fileName, fd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result = data.ReadString(); - std::string bundleName = data.ReadString(); - BackupOnResultReport(result, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - BackupOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - BackupOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - BackupOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - BackupOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string scannedInfo = data.ReadString(); - BackupOnScanningInfo(scannedInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - RestoreOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - RestoreOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - RestoreOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - RestoreOnFileReady(bundleName, fileName, fd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result; - if (!data.ReadString(result)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read result").GetCode(); - } - std::string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read bundleName").GetCode(); - } - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read errCode").GetCode(); - } - RestoreOnResultReport(result, bundleName, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - RestoreOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - int manifestFd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - manifestFd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalBackupOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result = data.ReadString(); - std::string bundleName = data.ReadString(); - IncrementalBackupOnResultReport(result, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalBackupOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - IncrementalBackupOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - IncrementalBackupOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string scannedInfo = data.ReadString(); - IncrementalBackupOnScanningInfo(scannedInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalRestoreOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalRestoreOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - IncrementalRestoreOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - int manifestFd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - manifestFd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - auto result = data.ReadString(); - auto bundleName = data.ReadString(); - ErrCode errCode = data.ReadInt32(); - IncrementalRestoreOnResultReport(result, bundleName, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto processInfo = data.ReadString(); - IncrementalRestoreOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 45fe3c878..2ceda9e2c 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -11,14 +11,149 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//build/ohos_var.gni") import("//foundation/filemanagement/app_file_service/backup.gni") +idl_gen_interface("backup_idl") { + sources = [ + "IExtension.idl", + "IService.idl", + "IServiceReverse.idl", + ] + sources_common = [ + "ServiceReverseType.idl", + "ExtensionType.idl", + "ServiceReverseInnerType.idl", + ] + hitrace = "HITRACE_TAG_FILEMANAGEMENT" + log_domainid = "0xD004313" + log_tag = "AppFileService" +} + +config("public_idl_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("backup_kit_inner_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "impl", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_kit_inner_ipc_type") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*_type.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_kit_inner_ipc_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [ "${target_gen_dir}/service_reverse_stub.cpp" ] + + sources += filter_include(output_values, + [ + "service_reverse_stub.cpp", + "service_reverse_stub.h", + "extension_type.cpp", + ]) + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + config("public_config") { include_dirs = [ ".", "impl", + "${target_gen_dir}/", ] } @@ -52,11 +187,9 @@ ohos_shared_library("backup_kit_inner") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", ] defines = [ @@ -76,7 +209,10 @@ ohos_shared_library("backup_kit_inner") { "samgr:samgr_proxy", ] - deps = [ "${path_backup}/utils:backup_utils" ] + deps = [ + ":backup_kit_inner_ipc", + "${path_backup}/utils:backup_utils", + ] cflags_cc = [ "-fdata-sections", diff --git a/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl b/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl new file mode 100644 index 000000000..6b481aa4e --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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/interfaces/inner_api/native/backup_kit_inner/IExtension.idl b/interfaces/inner_api/native/backup_kit_inner/IExtension.idl new file mode 100644 index 000000000..e58f8ab1f --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IExtension.idl @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 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 GetIncrementalFileHandleWithUniqueFdGroup([in] String fileName, [out] UniqueFdGroup fdGroup); + [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 GetIncrementalBackupFileHandleWithUniqueFdGroup([out] UniqueFdGroup fdGroup); + [ipccode 11] void GetBackupInfo([out] String getBackupInfoResult); + [ipccode 12] void UpdateFdSendRate([in] String bundleName, [in] int sendRate); + [ipccode 13] void User0OnBackup(); +} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/IService.idl b/interfaces/inner_api/native/backup_kit_inner/IService.idl new file mode 100644 index 000000000..c6e0a8905 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; +import IServiceReverse; +import ServiceReverseType; +sequenceable BackupFileInfo..OHOS.FileManagement.Backup.BFileInfo; +sequenceable BackupIncrementalData..OHOS.FileManagement.Backup.BIncrementalData; +interface OHOS.FileManagement.Backup.IService{ + [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 2] void InitBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 3] void InitBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 4] void Start(); + [ipccode 5] void GetLocalCapabilities([out] FileDescriptor fd); + [ipccode 6] void GetLocalCapabilitiesForBundleInfos([out] FileDescriptor fd); + [ipccode 7] void PublishFile([in] BFileInfo fileInfo); + [oneway, ipccode 8] void GetFileHandle([in] String bundleName, [in] String fileName); + [ipccode 9] void AppendBundlesRestoreSessionRestoreDataWaitSend([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] String[] detailInfos, + [in] int restoreType, + [in] int userId); + [ipccode 10] void AppendBundlesRestoreSessionRestoreDataWaitReady([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] int restoreType, + [in] int userId); + [ipccode 11] void AppendBundlesBackupSession([in] String[] bundleNames); + [ipccode 12] void AppendBundlesDetailsBackupSession([in] String[] bundleNames, [in] String[] bundleInfos); + [ipccode 13] void Finish(); + [ipccode 14] void Release(); + [ipccode 15] void Cancel([in] String bundleName, [out] int cancelResult); + [ipccode 16] void GetAppLocalListAndDoIncrementalBackup(); + [ipccode 17] void GetIncrementalFileHandle([in] String bundleName, [in] String fileName); + [ipccode 18] void GetBackupInfo([in] String bundleName, [out] String getBackupInfoResult); + [ipccode 19] void UpdateTimer([in] String bundleName, [in] unsigned int timeout, [out] boolean updateTimerResult); + [ipccode 20] void UpdateSendRate([in] String bundleName, [in] int sendRate, [out] boolean updateSendRateResult); + [ipccode 21] void StartExtTimer([out] boolean isExtStart); + [ipccode 22] void StartFwkTimer([out] boolean isFwkStart); + [ipccode 23] void StopExtTimer([out] boolean isExtStop); + [ipccode 24] void GetLocalCapabilitiesIncremental([in] BIncrementalData[] bundleNames, [out] FileDescriptor fd); + [ipccode 25] void InitIncrementalBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 26] void InitIncrementalBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, + [out] String errMsg); + [ipccode 27] void AppendBundlesIncrementalBackupSession([in] BIncrementalData[] bundlesToBackup); + [ipccode 28] void AppendBundlesIncrementalBackupSessionWithBundleInfos([in] BIncrementalData[] bundlesToBackup, + [in]String[] bundleInfos); + [ipccode 29] void PublishIncrementalFile([in] BFileInfo fileInfo); + [ipccode 30] void PublishSAIncrementalFile([in] BFileInfo fileInfo, [in] FileDescriptor fd); + [ipccode 31] void AppIncrementalFileReady([in] String fileName, [in] FileDescriptor fd, [in] FileDescriptor manifestFd, + [in] int appIncrementalFileReadyErrCode); + [ipccode 32] void AppIncrementalDone([in] int appIncrementalDoneErrCode); + [ipccode 33] void ReportAppProcessInfo([in] String processInfo, [in] BackupRestoreScenario scenario); + [ipccode 34] void RefreshDataSize([in] long totalDataSize); + [ipccode 35] void AppDone([in] int appDoneErrCode); + [ipccode 36] void AppFileReady([in]String fileName, [in] FileDescriptor fd, [in] int appFileReadyErrCode); + [ipccode 37] void ServiceResultReport([in]String restoreRetInfo, [in] BackupRestoreScenario sennario, + [in] int serviceResultReportErrCode); + [ipccode 38] void GetBackupDataSize([in] boolean isPreciseScan,[in] BIncrementalData[] bundleNameList); + } \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl b/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl new file mode 100644 index 000000000..bc44d90bc --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; + +import ServiceReverseType; +import ServiceReverseInnerType; +interface OHOS.FileManagement.Backup.IServiceReverse{ + [ipccode 999] void BackupOnBundleStarted([in] int backupOnBundleStartedErrCode, [in] String bundleName); + [ipccode 1] void BackupOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd, + [in] int backupOnFileReadyErrCode); + [ipccode 2] void BackupOnResultReport([in] String myResult, [in] String bundleName); + [ipccode 3] void BackupOnBundleFinished([in] int backupOnBundleFinishedErrCode, [in] String bundleName); + [ipccode 4] void BackupOnAllBundlesFinished([in] int backupOnAllBundlesFinishedErrCode); + [ipccode 5] void BackupOnProcessInfo([in] String bundleName, [in] String processInfo); + [ipccode 6] void BackupOnScanningInfo([in] String scannedInfo); + [ipccode 7] void RestoreOnBundleStarted([in] int restoreOnBundleStartedErrCode, [in] String bundleName); + [ipccode 8] void RestoreOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd, + [in] int restoreOnFileReadyErrCode); + [ipccode 9] void RestoreOnResultReport([in] String myResult, [in] String bundleName, + [in] int restoreOnResultReportErrCode); + [ipccode 10] void RestoreOnBundleFinished([in] int restoreOnBundleFinishedErrCode, [in] String bundleName); + [ipccode 11] void RestoreOnAllBundlesFinished([in] int restoreOnAllBundlesFinishedErrCode); + [ipccode 12] void RestoreOnProcessInfo([in] String bundleName, [in] String processInfo); + + [ipccode 13] void IncrementalBackupOnBundleStarted([in] int incrementalBackupOnBundleStartedErrCode, + [in] String bundleName); + [ipccode 14] void IncrementalBackupOnFileReady([in] String bundleName, + [in] String fileName, [in] FileDescriptor fd, + [in] FileDescriptor manifestFd, [in] int incrementalBackupOnFileReadyErrCode); + [ipccode 15] void IncrementalBackupOnResultReport([in] String myResult, [in] String bundleName); + [ipccode 16] void IncrementalBackupOnBundleFinished([in] int incrementalBackupOnBundleFinishedErrCode, + [in] String bundleName); + [ipccode 17] void IncrementalBackupOnAllBundlesFinished([in] int incrementalBackupOnAllBundlesFinishedErrCode); + [ipccode 18] void IncrementalBackupOnProcessInfo([in] String bundleName, [in] String processInfo); + [ipccode 19] void IncrementalBackupOnScanningInfo([in] String scannedInfo); + + [ipccode 20] void IncrementalRestoreOnBundleStarted([in] int incrementalRestoreOnBundleStartedErrCode, + [in] String bundleName); + [ipccode 21] void IncrementalRestoreOnFileReady([in] String bundleName, + [in] String fileName, + [in] FileDescriptor fd, + [in] FileDescriptor manifestFd, + [in] int incrementalRestoreOnFileReadyErrCode); + [ipccode 22] void IncrementalRestoreOnResultReport([in] String myResult, [in] String bundleName, + [in] int incrementalRestoreOnResultReportErrCode); + [ipccode 23] void IncrementalRestoreOnBundleFinished([in] int incrementalRestoreOnBundleFinishedErrCode, + [in] String bundleName); + [ipccode 24] void IncrementalRestoreOnAllBundlesFinished([in] int incrementalRestoreOnAllBundlesFinishedErrCode); + [ipccode 25] void IncrementalRestoreOnProcessInfo( [in] String bundleName, [in] String processInfo); +} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl new file mode 100644 index 000000000..85cd436dd --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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.IServiceReverseType; + +enum Scenario { + UNDEFINED, + BACKUP, + RESTORE, + CLEAN, +}; diff --git a/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl new file mode 100644 index 000000000..3e8910046 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; + +enum BackupRestoreScenario { + FULL_BACKUP = 0, + INCREMENTAL_BACKUP = 1, + FULL_RESTORE = 2, + INCREMENTAL_RESTORE = 3, +}; + diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h index 934cb5593..339c47266 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index 3b0e46a9c..d671cebed 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 50c47bf7b..275df6f21 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -22,9 +22,10 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" -#include "i_service.h" +#include "iservice.h" +#include "service_common.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index 0fbcb4dc2..fb4b06d1a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "errors.h" #include "svc_death_recipient.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index 7aa5fdcd8..7b916abf1 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -20,7 +20,7 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 64615acb2..02a311601 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -22,9 +22,10 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h similarity index 100% rename from interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h rename to interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h similarity index 100% rename from interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h rename to interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h deleted file mode 100644 index 0108a3437..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_H - -#include -#include - -#include - -#include "b_file_info.h" -#include "b_incremental_data.h" -#include "i_service_ipc_interface_code.h" -#include "i_service_reverse.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -const int DEFAULT_INVAL_VALUE = -1; - -typedef enum TypeRestoreTypeEnum { - RESTORE_DATA_WAIT_SEND = 0, - RESTORE_DATA_READDY = 1, -} RestoreTypeEnum; - -enum BackupRestoreScenario { - FULL_BACKUP = 0, - INCREMENTAL_BACKUP = 1, - FULL_RESTORE = 2, - INCREMENTAL_RESTORE = 3, -}; - -class IService : public IRemoteBroker { -public: - virtual ~IService() = default; - virtual ErrCode InitRestoreSession(sptr remote) = 0; - virtual ErrCode InitRestoreSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode InitBackupSession(sptr remote) = 0; - virtual ErrCode InitBackupSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode Start() = 0; - virtual UniqueFd GetLocalCapabilities() = 0; - virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; - virtual ErrCode PublishFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) = 0; - virtual ErrCode AppDone(ErrCode errCode) = 0; - virtual ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) = 0; - virtual ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; - virtual ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) = 0; - virtual ErrCode Finish() = 0; - virtual ErrCode Release() = 0; - virtual ErrCode Cancel(std::string bundleName, int32_t &result) = 0; - virtual UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) = 0; - virtual ErrCode GetAppLocalListAndDoIncrementalBackup() = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse) = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse, std::string &errMsg) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &bundleInfos) = 0; - - virtual ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) = 0; - virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) = 0; - virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; - virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; - virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) = 0; - virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0; - virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0; - virtual ErrCode StartExtTimer(bool &isExtStart) = 0; - virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0; - virtual ErrCode StopExtTimer(bool &isExtStop) = 0; - virtual ErrCode RefreshDataSize(int64_t totalSize) = 0; - virtual ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h deleted file mode 100644 index 4ca5a7621..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H - -#include - -#include "i_service_reverse_ipc_interface_code.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -class IServiceReverse : public IRemoteBroker { -public: - enum class Scenario { - UNDEFINED, - BACKUP, - RESTORE, - CLEAN, - }; - -public: - virtual ~IServiceReverse() = default; - virtual void BackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; - virtual void BackupOnResultReport(std::string result, std::string bundleName) = 0; - virtual void BackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void BackupOnAllBundlesFinished(int32_t errCode) = 0; - virtual void BackupOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - virtual void BackupOnScanningInfo(std::string scannedInfo) = 0; - - virtual void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; - virtual void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) = 0; - virtual void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void RestoreOnAllBundlesFinished(int32_t errCode) = 0; - virtual void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - - virtual void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) = 0; - virtual void IncrementalBackupOnResultReport(std::string result, std::string bundleName) = 0; - virtual void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalBackupOnAllBundlesFinished(int32_t errCode) = 0; - virtual void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - virtual void IncrementalBackupOnScanningInfo(std::string scannedInfo) = 0; - - virtual void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalRestoreOnFileReady(std::string bundleName, - std::string fileName, - int fd, - int manifestFd, int32_t errCode) = 0; - virtual void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) = 0; - virtual void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) = 0; - virtual void IncrementalRestoreOnProcessInfo(const std::string bundleName, const std::string processInfo) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IServiceReverse") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h similarity index 35% rename from services/backup_sa/include/module_ipc/svc_extension_proxy.h rename to interfaces/inner_api/native/backup_kit_inner/impl/service_client.h index dd38f936a..86c12f988 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h @@ -13,36 +13,46 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H + +#include +#include +#include +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "system_ability_load_callback_stub.h" -#include "i_extension.h" -#include "iremote_proxy.h" -#include "unique_fd.h" namespace OHOS::FileManagement::Backup { -class SvcExtensionProxy : public IRemoteProxy { -public: - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override; - ErrCode HandleClear() override; - ErrCode HandleBackup(bool isClearData) override; - ErrCode PublishFile(const std::string &fileName) override; - ErrCode HandleRestore(bool isClearData) override; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override; - ErrCode PublishIncrementalFile(const std::string &fileName) override; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; - ErrCode IncrementalOnBackup(bool isClearData) override; - std::tuple GetIncrementalBackupFileHandle() override; - ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; - ErrCode User0OnBackup() override; +class ServiceClient { public: - explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} + static sptr GetServiceProxyPointer(); + static sptr GetInstance(); + static void InvaildInstance(); + bool CheckServiceProxy(); +public: + explicit ServiceClient(); + ~ServiceClient(); +public: + class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + + public: + std::condition_variable proxyConVar_; + std::atomic isLoadSuccess_ = {false}; + }; private: - static inline BrokerDelegator delegator_; + static inline std::mutex proxyMutex_; + static inline std::mutex getInstanceMutex_; + static inline sptr serviceProxy_ = nullptr; }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h similarity index 34% rename from interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h rename to interfaces/inner_api/native/backup_kit_inner/impl/service_common.h index 7ce72f1a3..390900866 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h @@ -13,35 +13,17 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_I_EXTENSION_H -#define OHOS_FILEMGMT_BACKUP_I_EXTENSION_H - -#include "errors.h" -#include "i_extension_ipc_interface_code.h" -#include "iremote_broker.h" -#include "unique_fd.h" +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H namespace OHOS::FileManagement::Backup { -class IExtension : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IExtension"); +const int DEFAULT_INVAL_VALUE = -1; + +typedef enum TypeRestoreTypeEnum { + RESTORE_DATA_WAIT_SEND = 0, + RESTORE_DATA_READDY = 1, +} RestoreTypeEnum; -public: - virtual ~IExtension() = default; - virtual UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) = 0; - virtual ErrCode HandleClear() = 0; - virtual ErrCode HandleBackup(bool isClearData) = 0; - virtual ErrCode PublishFile(const std::string &fileName) = 0; - virtual ErrCode HandleRestore(bool isClearData) = 0; - virtual std::tuple GetIncrementalFileHandle(const std::string &fileName) = 0; - virtual ErrCode PublishIncrementalFile(const std::string &fileName) = 0; - virtual ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) = 0; - virtual ErrCode IncrementalOnBackup(bool isClearData) = 0; - virtual std::tuple GetIncrementalBackupFileHandle() = 0; - virtual ErrCode GetBackupInfo(std::string &result) = 0; - virtual ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) = 0; - virtual ErrCode User0OnBackup() = 0; -}; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_I_EXTENSION_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h deleted file mode 100644 index 4302e07b8..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H - -#include -#include -#include -#include - -#include "i_service.h" -#include "iremote_proxy.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceProxy : public IRemoteProxy { -public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; - ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; - ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; - ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override; - ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; - ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) override; - ErrCode Finish() override; - ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; - ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; - ErrCode AppIncrementalDone(ErrCode errCode) override; - ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; - ErrCode StartExtTimer(bool &isExtStart) override; - ErrCode StartFwkTimer(bool &isFwkStart) override; - ErrCode StopExtTimer(bool &isExtStop) override; - ErrCode RefreshDataSize(int64_t totalSize) override; - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) override; -public: - explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceProxy() override {} - -public: - template - bool WriteParcelableVector(const std::vector &parcelableVector, Parcel &data); - static sptr GetServiceProxyPointer(); - static sptr GetInstance(); - static void InvaildInstance(); - -public: - class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - public: - std::condition_variable proxyConVar_; - std::atomic isLoadSuccess_ = {false}; - }; - -private: - static inline std::mutex proxyMutex_; - static inline std::mutex getInstanceMutex_; - static inline sptr serviceProxy_ = nullptr; - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H \ No newline at end of file diff --git a/interfaces/kits/js/backup/parse_inc_info_from_js.h b/interfaces/kits/js/backup/parse_inc_info_from_js.h index b3856dddb..461ce8513 100644 --- a/interfaces/kits/js/backup/parse_inc_info_from_js.h +++ b/interfaces/kits/js/backup/parse_inc_info_from_js.h @@ -18,7 +18,7 @@ #include #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" namespace OHOS::FileManagement::Backup { class Parse { diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index e4a1ef547..5aa1c573c 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -15,14 +15,14 @@ #include "prop_n_operation.h" #include "b_error/b_error.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" #include "incremental_backup_data.h" #include "parse_inc_info_from_js.h" -#include "service_proxy.h" +#include "service_client.h" #include "access_token.h" #include "accesstoken_kit.h" #include "ipc_skeleton.h" @@ -39,13 +39,18 @@ static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg) auto fd = make_shared(); auto cbExec = [fd]() -> NError { HILOGI("called LocalCapabilities::AsyncCallback cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncCallback cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilities(); + int fdNum = -1; + HILOGI("called LocalCapabilities::AsyncCallback start fdNum:%{public}d}", fdNum); + proxy->GetLocalCapabilities(fdNum); + HILOGI("called LocalCapabilities::AsyncCallback end fdNum:%{public}d}", fdNum); + UniqueFd fdData(fdNum); + *fd = std::move(fdData); HILOGI("called LocalCapabilities::AsyncCallback cbExec success"); return NError(ERRNO_NOERR); }; @@ -81,15 +86,18 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) } auto fd = make_shared(); - auto cbExec = [fd, bundles { move(bundles) }]() -> NError { + auto cbExec = [fd, bundles {move(bundles)}]() -> NError { HILOGI("called LocalCapabilities::AsyncDataList cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncDataList cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilitiesIncremental(bundles); + int fdValue = -1; + proxy->GetLocalCapabilitiesIncremental(bundles, fdValue); + UniqueFd fdData(fdValue); + *fd = std::move(fdData); return NError(ERRNO_NOERR); }; auto cbCompl = [fd](napi_env env, NError err) -> NVal { @@ -165,8 +173,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info return nullptr; } - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoGetBackupInfo,failed to get proxy"); return nullptr; @@ -191,8 +199,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called UpdateSendRate,failed to get proxy"); return result; @@ -208,8 +216,8 @@ bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoUpdateTimer,failed to get proxy"); return result; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index d3a84c628..5f96544dd 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -20,7 +20,7 @@ #include "b_error/b_error.h" #include "b_filesystem/b_file.h" #include "b_incremental_backup_session.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "backup_kit_inner.h" diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 8c877bed7..f7a2a84f1 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -34,13 +34,8 @@ ohos_shared_library("backup_sa") { "src/module_ipc/sa_backup_connection.cpp", "src/module_ipc/service.cpp", "src/module_ipc/service_incremental.cpp", - "src/module_ipc/service_incremental_reverse_proxy.cpp", - "src/module_ipc/service_reverse_proxy.cpp", - "src/module_ipc/service_stub.cpp", "src/module_ipc/sub_service.cpp", "src/module_ipc/svc_backup_connection.cpp", - "src/module_ipc/svc_extension_incremental_proxy.cpp", - "src/module_ipc/svc_extension_proxy.cpp", "src/module_ipc/svc_restore_deps_manager.cpp", "src/module_ipc/svc_session_manager.cpp", "src/module_notify/notify_work_service.cpp", @@ -59,6 +54,7 @@ ohos_shared_library("backup_sa") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index 13a7be7a1..eba30a79f 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -21,7 +21,7 @@ #include "b_json/b_json_entity_caps.h" #include "bundlemgr/bundle_mgr_interface.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "istorage_manager.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 34a0fb99a..89e95f355 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -23,13 +23,14 @@ #include "b_json/b_json_clear_data_config.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_service_disposal_config.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" #include "module_sched/sched_scheduler.h" #include "service_stub.h" #include "svc_session_manager.h" #include "system_ability.h" #include "thread_pool.h" +#include "service_reverse_inner_type.h" namespace OHOS::FileManagement::Backup { struct ExtensionMutexInfo { @@ -48,53 +49,83 @@ class Service : public SystemAbility, public ServiceStub, protected NoCopyable { // 以下都是IPC接口 public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitRestoreSession(const sptr& remote) override; + ErrCode InitRestoreSessionWithErrMsg(const sptr& reverseIpcRemoteObject, + std::string& errMsg) override; + ErrCode InitRestoreSession(const sptr& remote, std::string &errMsg); + ErrCode InitBackupSession(const sptr& remote) override; + ErrCode InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; + ErrCode GetLocalCapabilities(int& fd) override; + UniqueFd GetLocalCapabilities(); + ErrCode GetLocalCapabilitiesForBundleInfos(int& fd) override; + UniqueFd GetLocalCapabilitiesForBundleInfos(); ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, + ErrCode ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) override; ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend( + int fd, + const std::vector& bundleNames, + const std::vector& detailInfos, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady( + int fd, + const std::vector& bundleNames, + int32_t restoreType, + int32_t userId) override; ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, const std::vector &bundleInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + int32_t userId = DEFAULT_INVAL_VALUE); ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + int32_t userId = DEFAULT_INVAL_VALUE); ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; + ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; + ErrCode Cancel(const std::string& bundleName, int32_t &result) override; + ErrCode GetLocalCapabilitiesIncremental( + const std::vector& bundleNames, + int& fd) override; + UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames); ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitIncrementalBackupSession(const sptr& remote) override; + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector& bundlesToBackup, + const std::vector& bundleInfos) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; + const std::vector &infos); ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; + ErrCode PublishSAIncrementalFile( + const BFileInfo& fileInfo, + int fd) override; + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); + ErrCode AppIncrementalFileReady( + const std::string& fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; + ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; + ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override; + ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override; + ErrCode ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; ErrCode StopExtTimer(bool &isExtStop) override; @@ -104,7 +135,7 @@ public: const ErrCode errCode, const BackupRestoreScenario sennario); void StartGetFdTask(std::string bundleName, wptr ptr); - ErrCode GetBackupDataSize(bool isPreciseScan, vector bundleNameList) override; + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) override; // 以下都是非IPC接口 public: @@ -212,7 +243,7 @@ public: * @param bundleName 应用名称 * */ - AAFwk::Want CreateConnectWant (BundleName &bundleName); + AAFwk::Want CreateConnectWant (const BundleName &bundleName); /** * @brief SA backup回调 @@ -242,7 +273,8 @@ public: * @param bundleName 应用名称 * */ - std::function GetBackupInfoConnectDone(wptr obj, std::string &bundleName); + std::function GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName); /** * @brief GetBackupInfo extension死亡回调 @@ -252,7 +284,7 @@ public: * */ std::function GetBackupInfoConnectDied( - wptr obj, std::string &bundleName); + wptr obj, const std::string &bundleName); /** * @brief timeout callback @@ -313,7 +345,7 @@ public: string BundleNameWithUserId(const string& bundleName, const int32_t userId); std::tuple SplitBundleName(const string& bundleNameWithId); void AppendBundles(const std::vector &bundleNames); - void ReportOnBundleStarted(IServiceReverse::Scenario scenario, const std::string &bundleName); + void ReportOnBundleStarted(IServiceReverseType::Scenario scenario, const std::string &bundleName); ErrCode AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); public: @@ -362,7 +394,7 @@ private: * * @param scenario Scenario状态 */ - ErrCode VerifyCaller(IServiceReverse::Scenario scenario); + ErrCode VerifyCaller(IServiceReverseType::Scenario scenario); /** * @brief 验证调用者并返回名称 @@ -526,7 +558,7 @@ private: * @param result 业务结果出参 * */ - ErrCode GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result); + ErrCode GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result); /** * @brief 添加需要清理的Session @@ -544,7 +576,7 @@ private: */ void SetOccupySession(bool isOccupyingSession); - void ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, + void ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, const std::string &bundleName, const ErrCode ret); void ReleaseOnException(); @@ -561,7 +593,7 @@ private: std::map> &bundleNameDetailMap, std::map &isClearDataFlags); - void TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName); + void TimeoutRadarReport(IServiceReverseType::Scenario scenario, std::string &bundleName); void OnBundleStarted(BError error, sptr session, const BundleName &bundleName); @@ -569,16 +601,16 @@ private: const vector &restoreBundleNames); void BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage); diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h deleted file mode 100644 index 7578aca36..000000000 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H - -#include "i_service_reverse.h" -#include "iremote_proxy.h" - -namespace OHOS::FileManagement::Backup { -class ServiceReverseProxy final : public IRemoteProxy, protected NoCopyable { -public: - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void BackupOnResultReport(std::string result, std::string bundleName) override; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void BackupOnAllBundlesFinished(int32_t errCode) override; - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void BackupOnScanningInfo(std::string scannedInfo) override; - - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void RestoreOnAllBundlesFinished(int32_t errCode) override; - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; - - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override; - - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; - -public: - explicit ServiceReverseProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceReverseProxy() override = default; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h deleted file mode 100644 index d4484365a..000000000 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H - -#include - -#include "i_service.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceStub(); - ~ServiceStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdStart(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdFinish(MessageParcel &data, MessageParcel &reply); - int32_t CmdRelease(MessageParcel &data, MessageParcel &reply); - int32_t CmdCancel(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply); - int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStopExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply); - void ServiceStubSupplement(); - void ServiceStubSuppAppendBundles(); - -public: - template - bool ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_backup_connection.h b/services/backup_sa/include/module_ipc/svc_backup_connection.h index 8b6c2477c..33c1c6978 100644 --- a/services/backup_sa/include/module_ipc/svc_backup_connection.h +++ b/services/backup_sa/include/module_ipc/svc_backup_connection.h @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_H #include "ability_connect_callback_stub.h" -#include "i_extension.h" +#include "iextension.h" namespace OHOS::FileManagement::Backup { class SvcBackupConnection : public AAFwk::AbilityConnectionStub { diff --git a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h index cb83798b9..d0a198256 100644 --- a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h +++ b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h @@ -22,7 +22,8 @@ #include #include "b_json/b_json_entity_caps.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 98fd49414..3130f4e42 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -29,11 +29,12 @@ #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" -#include "i_service.h" -#include "i_service_reverse.h" +#include "service_common.h" +#include "iservice.h" +#include "iservice_reverse.h" #include "module_ipc/svc_backup_connection.h" #include "module_ipc/sa_backup_connection.h" #include "svc_death_recipient.h" @@ -80,7 +81,7 @@ class SvcSessionManager : public virtual RefBase { public: struct Impl { uint32_t clientToken {0}; - IServiceReverse::Scenario scenario {IServiceReverse::Scenario::UNDEFINED}; + IServiceReverseType::Scenario scenario {IServiceReverseType::Scenario::UNDEFINED}; std::map backupExtNameMap; sptr clientProxy; bool isBackupStart {false}; @@ -106,7 +107,7 @@ public: * * @return ErrCode 错误码 */ - ErrCode VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const; + ErrCode VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const; /** * @brief 激活会话 @@ -147,10 +148,10 @@ public: /** * @brief 获取Scenario * - * @return IServiceReverse::Scenario 返回scenario + * @return IServiceReverseType::Scenario 返回scenario * @throw BError::Codes::SA_INVAL_ARG 获取异常 */ - IServiceReverse::Scenario GetScenario(); + IServiceReverseType::Scenario GetScenario(); /** * @brief 获取当前处理事务会话对应的userId @@ -332,7 +333,7 @@ public: * * @param bundleName 应用名称 */ - sptr CreateBackupConnection(BundleName &bundleName); + sptr CreateBackupConnection(const BundleName &bundleName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 12a70dd62..db46d69e7 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -21,7 +21,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_jsonutil/b_jsonutil.h" #include "b_json/b_json_entity_extension_config.h" #include "b_resources/b_constants.h" diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 65a225c97..20d4a6f1b 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -38,11 +38,12 @@ #include #include "ability_manager_client.h" +#include "access_token.h" #include "accesstoken_kit.h" #include "b_anony/b_anony.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_hiaudit/hi_audit.h" #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" @@ -57,7 +58,7 @@ #include "hisysevent.h" #include "hitrace_meter.h" #include "ipc_skeleton.h" -#include "access_token.h" +#include "service_reverse_inner_type.h" #include "tokenid_kit.h" #include "module_app_gallery/app_gallery_dispose_proxy.h" #include "module_external/bms_adapter.h" @@ -118,7 +119,7 @@ void Service::OnStartResRadarReport(const std::vector &bundleNameLi } void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK || errCode == BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()) { return; @@ -132,17 +133,17 @@ void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCod taskInfo.errCode = errCode; UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } } void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK) { successBundlesNum_++; @@ -160,17 +161,17 @@ void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCod taskInfo.errCode = errCode; UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleEndRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_EXECU_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleEndRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_EXECU_FAIL, errCode); } } void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK) { return; @@ -180,17 +181,17 @@ void Service::FileReadyRadarReport(const std::string &bundleName, const std::str } std::string fileNameReport = std::string("fileName:\"") + GetAnonyPath(fileName) + "\""; AppRadar::Info info(bundleName, "", fileNameReport); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::FileReadyRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::FileReadyRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_DO_BACKUP, errCode); } } void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (!IsReportBundleExecFail(bundleName)) { return; @@ -199,11 +200,11 @@ void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, con std::stringstream ss; ss << "errCode:" << errCode; AppRadar::Info info(bundleName, "", ss.str()); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::ExtensionConnectFailRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_CONNECT_EXTENSION_FAIL, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::ExtensionConnectFailRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_CONNECT_EXTENSION_FAIL, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); @@ -217,25 +218,30 @@ void Service::OnStart() std::vector bundleNameList; if (disposal_ != nullptr) { bundleNameList = disposal_->GetBundleNameFromConfigFile(); + HILOGI("disposal_ !=null"); + } else { + HILOGI("disposal_ ==null"); } std::vector residualBundleNameList; if (clearRecorder_ != nullptr) { residualBundleNameList = clearRecorder_->GetAllClearBundleRecords(); } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { + HILOGI("!bundleNameList.empty() || !residualBundleNameList.empty() !=null"); if (!bundleNameList.empty()) { - OnStartResRadarReport(bundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + HILOGI("bundleNameList !=null"); } if (!residualBundleNameList.empty()) { OnStartResRadarReport(residualBundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + HILOGI("residualBundleNameList !=null"); } SetOccupySession(true); session_->Active( { .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::CLEAN, + .scenario = IServiceReverseType::Scenario::CLEAN, .clientProxy = nullptr, .userId = GetUserIdDefault(), .callerName = "BackupSA", @@ -274,6 +280,14 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +ErrCode Service::GetLocalCapabilities(int& fd) +{ + UniqueFd fdResult(GetLocalCapabilities()); + fd = fdResult.Release(); + HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -349,7 +363,7 @@ void Service::StopAll(const wptr &obj, bool force) ss << "}"; string resultInfo = ss.str(); AppRadar::StatInfo statInfo("", resultInfo); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); AppRadar::GetInstance().RecordStatisticRes(statInfo, GetUserIdDefault(), scenario, successBundlesNum_.load(), fail_cnt, result); } @@ -362,8 +376,8 @@ void Service::PermissionCheckFailRadar(const std::string &info, const std::strin { std::string funcPos = "Service::"; AppRadar::Info resInfo("", "", info); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } @@ -379,8 +393,8 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) HILOGE("Verify and get caller name failed, Get hap token info failed"); return BError(BError::Codes::SA_INVAL_ARG); } - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, - hapTokenInfo.instIndex); + std::string bundleNameIndexInfo = + BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, hapTokenInfo.instIndex); ErrCode ret = session_->VerifyBundleName(bundleNameIndexInfo); if (ret != ERR_OK) { HILOGE("Verify bundle name failed, bundleNameIndexInfo:%{public}s", bundleNameIndexInfo.c_str()); @@ -450,7 +464,7 @@ ErrCode Service::VerifyCaller() return ret; } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = session_->VerifyCallerAndScenario(IPCSkeleton::GetCallingTokenID(), scenario); @@ -461,7 +475,7 @@ ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) return VerifyCaller(); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -471,7 +485,7 @@ ErrCode Service::InitRestoreSession(sptr remote) } ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::RESTORE, + .scenario = IServiceReverseType::Scenario::RESTORE, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -493,7 +507,7 @@ ErrCode Service::InitRestoreSession(sptr remote) return ret; } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitBackupSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -506,7 +520,7 @@ ErrCode Service::InitBackupSession(sptr remote) session_->SetMemParaCurSize(oldSize); ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -531,12 +545,14 @@ ErrCode Service::InitBackupSession(sptr remote) ErrCode Service::Start() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Service Start"); ErrCode ret = VerifyCaller(session_->GetScenario()); if (ret != ERR_OK) { HILOGE("Service start failed, Verify caller failed, ret:%{public}d", ret); return ret; } ret = session_->Start(); + HILOGI("Service Start End"); if (ret != ERR_OK) { HILOGE("Service start failed, session is invalid, ret:%{public}d", ret); return ret; @@ -558,11 +574,11 @@ static bool SpecialVersion(const string &versionName) void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) { - IServiceReverse::Scenario scenario = session->GetScenario(); - if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + IServiceReverseType::Scenario scenario = session->GetScenario(); + if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(error, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); } BundleBeginRadarReport(bundleName, error.GetCode(), scenario); @@ -625,14 +641,15 @@ static vector GetRestoreBundleNames(UniqueFd fd, } void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) + const vector &appendBundleNames, + const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," "restoreBundleNames size:%{public}zu", appendBundleNames.size(), restoreBundleNames.size()); for (const auto &bundleName : appendBundleNames) { auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&bundleName](const auto &obj) { return obj == bundleName; }); + [&bundleName](const auto &obj) { return obj == bundleName; }); if (it == restoreBundleNames.end()) { HILOGE("AppendBundles failed, bundleName = %{public}s.", bundleName.c_str()); OnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), session, bundleName); @@ -641,8 +658,25 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &bundleInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitSend"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(static_cast(fd)); + RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType, + int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); @@ -653,7 +687,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); SetUserIdAndRestoreType(restoreType, userId); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -663,8 +697,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector bundleNamesOnly; std::map isClearDataFlags; std::map> bundleNameDetailMap = - BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - session_->GetSessionUserId(), isClearDataFlags); + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, session_->GetSessionUserId(), + isClearDataFlags); std::string oldBackupVersion; auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); @@ -675,8 +709,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("End"); @@ -695,7 +729,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &restoreBundleInfos, - std::vector &restoreBundleNames, RestoreTypeEnum restoreType, std::string &backupVersion) + std::vector &restoreBundleNames, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -706,11 +742,11 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); + restoreInfo.extensionName.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { @@ -731,6 +767,18 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitReady"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(static_cast(fd)); + RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_READDY; + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); +} ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, @@ -745,7 +793,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); SetUserIdAndRestoreType(restoreType, userId); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -779,10 +827,13 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } -void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, +void Service::SetCurrentSessProperties( + std::vector &restoreBundleInfos, std::vector &restoreBundleNames, std::map> &bundleNameDetailMap, - std::map &isClearDataFlags, RestoreTypeEnum restoreType, std::string &backupVersion) + std::map &isClearDataFlags, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -795,7 +846,7 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); @@ -816,14 +867,14 @@ void Service::SetCurrentSessProperties(std::vector } BJsonUtil::BundleDetailInfo broadCastInfo; BJsonUtil::BundleDetailInfo uniCastInfo; - bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, - broadCastInfo); + bool broadCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, broadCastInfo); if (broadCastRet) { bool notifyRet = DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); HILOGI("Publish event end, notify result is:%{public}d", notifyRet); } - bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, - uniCastInfo); + bool uniCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo); if (uniCastRet) { HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); @@ -843,7 +894,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("AppendBundles backup session error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -873,7 +924,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName } ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &bundleInfos) + const vector &bundleInfos) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -882,7 +933,7 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("AppendBundles backup session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -916,19 +967,20 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun } } -void Service::HandleCurGroupBackupInfos(std::vector &backupInfos, +void Service::HandleCurGroupBackupInfos( + std::vector &backupInfos, std::map> &bundleNameDetailMap, std::map &isClearDataFlags) { for (auto &info : backupInfos) { - HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", - info.name.c_str(), info.extensionName.c_str(), info.appIndex); + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", info.name.c_str(), + info.extensionName.c_str(), info.appIndex); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); BJsonUtil::BundleDetailInfo uniCastInfo; if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) { HILOGI("current bundle:%{public}s, unicast info:%{public}s, unicast info size:%{public}zu", - bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); + bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); @@ -937,12 +989,13 @@ void Service::HandleCurGroupBackupInfos(std::vector } } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("ServiceResultReport restoreRetInfo:%{public}s, sennario:%{public}d, errCode:%{public}d", + restoreRetInfo.c_str(), sennario, errCode); ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { HILOGE("Result report fail, bundleName:%{public}s, ret:%{public}d", callerName.c_str(), ret); @@ -975,14 +1028,16 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } } -ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, - const ErrCode errCode, const BackupRestoreScenario sennario) +ErrCode Service::SAResultReport(const std::string bundleName, + const std::string restoreRetInfo, + const ErrCode errCode, + const BackupRestoreScenario sennario) { SADone(errCode, bundleName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); @@ -991,10 +1046,10 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string } OnAllBundlesFinished(BError(BError::Codes::OK)); if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::RESTORE); } else if (sennario == BackupRestoreScenario::FULL_BACKUP || - sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::BACKUP); + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::BACKUP); } return BError(BError::Codes::OK); } @@ -1003,8 +1058,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore { HILOGI("Begin"); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && - sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { return; } if (session_->OnBundleFileReady(bundleName)) { @@ -1039,7 +1093,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) { string extInfo = session_->GetBackupExtInfo(bundleName); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); if (SAUtils::IsSABundleName(bundleName)) { auto saBackUpConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = saBackUpConnection.lock(); @@ -1047,9 +1101,9 @@ ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) HILOGE("lock sa connection ptr is nullptr"); return BError(BError::Codes::SA_INVAL_ARG); } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_BACKUP, extInfo); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_RESTORE, extInfo); } } @@ -1059,14 +1113,13 @@ ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("GetFileHandle bundleName:%{public}s,fileName:%{public}s", bundleName.c_str(), fileName.c_str()); try { if (session_ == nullptr) { - HILOGE("GetFileHandle error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { - HILOGE("verify caller failed, bundleName:%{public}s", bundleName.c_str()); return ret; } bool updateRes = SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); @@ -1090,14 +1143,16 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) return BError(BError::Codes::SA_INVAL_ARG); } int32_t errCode = 0; - UniqueFd fd = proxy->GetFileHandle(fileName, errCode); + int32_t fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(static_cast(fdCode)); if (errCode != ERR_OK) { - AppRadar::Info info (bundleName, "", ""); + AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); } else { session_->SetExtFileNameRequest(bundleName, fileName); } @@ -1131,7 +1186,7 @@ void Service::ExtStart(const string &bundleName) void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) { HILOGI("Begin handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("Error, backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); @@ -1144,7 +1199,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) ReportOnBundleStarted(scenario, bundleName); return; } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); @@ -1153,7 +1208,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); } - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); GetOldDeviceBackupVersion(); @@ -1161,7 +1216,9 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (const auto &fileName : fileNameVec) { int32_t errCode = 0; - UniqueFd fd = proxy->GetFileHandle(fileName, errCode); + int fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(static_cast(fdCode)); session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } @@ -1180,18 +1237,19 @@ int Service::Dump(int fd, const vector &args) return 0; } -void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, const ErrCode ret) +void Service::ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, + const std::string &bundleName, + const ErrCode ret) { try { if (session_ == nullptr) { HILOGE("Report extConnectfailed error, session info is empty"); return; } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -1200,10 +1258,10 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, session_->GetBundleUserId(bundleName)); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName, @@ -1219,7 +1277,7 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = IServiceReverse::Scenario::UNDEFINED; + IServiceReverseType::Scenario scenario = IServiceReverseType::Scenario::UNDEFINED; try { HILOGE("begin %{public}s", bundleName.data()); scenario = session_->GetScenario(); @@ -1241,9 +1299,9 @@ void Service::StartRunningTimer(const std::string &bundleName) { auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); auto scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->StartExtTimer(bundleName, timeoutCallback); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->StartFwkTimer(bundleName, timeoutCallback); } } @@ -1317,7 +1375,7 @@ void Service::ClearSessionAndSchedInfo(const string &bundleName) void Service::HandleRestoreDepsBundle(const string &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (session_->GetScenario() != IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() != IServiceReverseType::Scenario::RESTORE) { return; } HILOGI("Begin, bundleName: %{public}s", bundleName.c_str()); @@ -1372,8 +1430,8 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) HILOGI("SA does not need to StartRestore"); return; } - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } int32_t userId = session_->GetBundleUserId(bundleName); @@ -1395,8 +1453,8 @@ void Service::SendEndAppGalleryNotify(const BundleName &bundleName) HILOGI("SA does not need to EndRestore"); return; } - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } int32_t userId = session_->GetBundleUserId(bundleName); @@ -1445,8 +1503,8 @@ void Service::TryToClearDispose(const BundleName &bundleName) void Service::SendErrAppGalleryNotify() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); @@ -1477,8 +1535,8 @@ void Service::ClearDisposalOnSaStart() void Service::DeleteDisConfigFile() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); @@ -1497,14 +1555,14 @@ void Service::SessionDeactive() try { HILOGI("Begin"); isInRelease_.store(true); - //清理处置状态 + // 清理处置状态 if (session_ == nullptr) { HILOGE("Session deactive error, session is empty"); return; } ErrCode ret = BError(BError::Codes::OK); std::vector bundleNameList; - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE && + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE && session_->CleanAndCheckIfNeedWait(ret, bundleNameList)) { if (ret != ERR_OK) { isRmConfigFile_.store(false); @@ -1547,7 +1605,8 @@ void Service::SessionDeactive() } } -std::function Service::GetBackupInfoConnectDone(wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName) { HILOGI("GetBackupInfoConnectDone, bundleName: %{public}s", bundleName.c_str()); @@ -1560,8 +1619,8 @@ std::function Service::GetBackupInfoConnectDone(wptr }; } -std::function Service::GetBackupInfoConnectDied( - wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDied(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName, bool isCleanCalled) { HILOGI("GetBackupInfoConnectDied, bundleName: %{public}s", bundleName.c_str()); @@ -1598,13 +1657,13 @@ ErrCode Service::ClearResidualBundleData(const std::string &bundleName) } ClearSessionAndSchedInfo(bundleName); // 非清理任务,需要上报 - if (session_->GetScenario() != IServiceReverse::Scenario::CLEAN) { + if (session_->GetScenario() != IServiceReverseType::Scenario::CLEAN) { OnAllBundlesFinished(BError(BError::Codes::OK)); } return res; } -ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result) { if (session_ == nullptr) { HILOGE("Get BackupInfo error, session is empty."); @@ -1650,7 +1709,7 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { @@ -1660,7 +1719,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } try { std::lock_guard lock(getBackupInfoProcLock_); - HILOGI("Service::GetBackupInfo begin."); + HILOGI("Service::GetBackupInfo begin bundleName: %{public}s", bundleName.c_str()); if (session_ == nullptr || isOccupyingSession_.load()) { HILOGE("Get BackupInfo error, session is empty."); return BError(BError::Codes::SA_INVAL_ARG); @@ -1725,7 +1784,7 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { try { HILOGI("Service::UpdateTimer begin."); @@ -1737,7 +1796,8 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { - HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", bundleName.c_str()); + HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", + bundleName.c_str()); result = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return ret; @@ -1754,7 +1814,7 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res } } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); if (session_ == nullptr || isOccupyingSession_.load()) { @@ -1806,7 +1866,7 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool return ret; } -AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +AAFwk::Want Service::CreateConnectWant(const BundleName &bundleName) { BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; AAFwk::Want want; @@ -1819,14 +1879,14 @@ AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) ErrCode Service::BackupSA(std::string bundleName) { HILOGI("BackupSA begin %{public}s", bundleName.c_str()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = backUpConnection.lock(); if (saConnection == nullptr) { HILOGE("lock sa connection ptr is nullptr"); return BError(BError::Codes::SA_INVAL_ARG); } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { auto ret = saConnection->CallBackupSA(); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); @@ -1836,20 +1896,22 @@ ErrCode Service::BackupSA(std::string bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); return BError(ret); } - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); } return BError(BError::Codes::OK); } -void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, - const ErrCode &errCode) +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) { auto task = [bundleName, fd, result, errCode, this]() { HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", - bundleName.c_str(), fd, result.c_str(), errCode); + bundleName.c_str(), fd, result.c_str(), errCode); session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); - FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); + FileReadyRadarReport(bundleName, "", errCode, IServiceReverseType::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); }; threadPool_.AddTask([task]() { @@ -1864,8 +1926,8 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) { auto task = [bundleName, result, errCode, this]() { - HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", - bundleName.c_str(), result.c_str(), errCode); + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", bundleName.c_str(), + result.c_str(), errCode); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); }; threadPool_.AddTask([task]() { @@ -1897,7 +1959,7 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName) } catch (const BError &e) { ReleaseOnException(); return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch(...) { + } catch (...) { HILOGE("Unexpected exception"); ReleaseOnException(); return EPERM; @@ -1906,8 +1968,8 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName) void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is Backup"); session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); auto now = std::chrono::system_clock::now(); @@ -1915,24 +1977,18 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN auto ms = std::chrono::duration_cast(now.time_since_epoch()); std::stringstream strTime; strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "PROC_NAME", "ohos.appfileservice", - "BUNDLENAME", callerName, - "PID", getpid(), - "TIME", strTime.str() - ); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + << (std::setw(INDEX)) << (ms.count() % MS_1000); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str()); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); } BundleEndRadarReport(callerName, errCode, scenario); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -1993,7 +2049,7 @@ void Service::DoTimeout(wptr ptr, std::string bundleName) HILOGE("SessionPtr is nullptr."); return; } - IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + IServiceReverseType::Scenario scenario = sessionPtr->GetScenario(); try { std::shared_ptr mutexPtr = GetExtensionMutex(bundleName); if (mutexPtr == nullptr) { @@ -2057,8 +2113,8 @@ void Service::DelClearBundleRecord(const std::vector &bundleNames) void Service::ReleaseOnException() { if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverseType::Scenario::RESTORE)) { HILOGI("Will execute destory session info"); SessionDeactive(); } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 307b4204b..dab1cc3fa 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -15,6 +15,8 @@ #include "module_ipc/service.h" +#include "extension_type.h" + #include #include #include @@ -67,18 +69,18 @@ const static string UNICAST_TYPE = "unicast"; ErrCode Service::Release() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("KILL"); + HILOGI("Start Release"); if (session_ == nullptr) { HILOGE("Release error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); VerifyCaller(scenario); AppRadar::Info info("", "", "call release"); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); } @@ -112,6 +114,7 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) void Service::CreateDirIfNotExist(const std::string &path) { + HILOGI("Begin CreateDirIfNotExist, path = %{private}s", path.c_str()); if (access(path.c_str(), F_OK) != 0) { bool created = ForceCreateDirectory(path.data()); if (created) { @@ -121,6 +124,15 @@ void Service::CreateDirIfNotExist(const std::string &path) } } } +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin GetLocalCapabilitiesIncremental fd = %{private}d", fd); + UniqueFd fdResult(GetLocalCapabilitiesIncremental(bundleNames)); + fd = fdResult.Release(); + HILOGI("End GetLocalCapabilitiesIncremental fd = %{private}d", fd); + return BError(BError::Codes::OK); // anytime return OK +} UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) { @@ -177,9 +189,9 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector ptr) { + HILOGI("Begin StartGetFdTask bundleName = %{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { - HILOGE("this pointer is null"); return; } auto session = thisPtr->session_; @@ -211,9 +223,11 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); - string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). - append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); - HILOGD("path = %{public}s,bundleName = %{public}s", path.c_str(), bundleName.c_str()); + string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()) + .append(bundleName) + .append("/") + .append(BConstants::BACKUP_STAT_SYMBOL) + .append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { HILOGD("fdLocal open fail, error = %{public}d", errno); @@ -231,6 +245,7 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) void Service::RefreshBundleDataSize(const vector &newBundleInfos, std::string bundleName, wptr ptr) { + HILOGI("Begin RefreshBundleDataSize bundleName = %{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { HILOGE("this pointer is null"); @@ -293,7 +308,7 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() } } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr& remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -306,7 +321,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return BError(BError::Codes::SA_INVAL_ARG); } errCode = session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .isIncrementalBackup = true, @@ -328,7 +343,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return errCode; } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -341,7 +356,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote, std: return BError(BError::Codes::SA_INVAL_ARG); } errCode = session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .isIncrementalBackup = true, @@ -386,7 +401,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 bundleNames = GetBundleNameByDetails(bundlesToBackup); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("Append bundles incremental session failed, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -414,6 +429,13 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return AppendBundlesIncrementalBackupSession(bundlesToBackup, bundleInfos); +} ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, const std::vector &infos) @@ -423,11 +445,11 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 bundleNames = GetBundleNameByDetails(bundlesToBackup); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("Append bundles incremental session with infos failed, verify caller failed, ret:%{public}d", ret); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); @@ -447,7 +469,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("Failed, errCode = %{public}d", e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -485,7 +507,7 @@ void Service::HandleCurGroupIncBackupInfos(vector & ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("Publish incremental file failed, bundleName:%{public}s", fileInfo.owner.c_str()); return ret; @@ -518,6 +540,13 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) +{ + HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); + UniqueFd uniquedParameter(static_cast(fd)); + return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); +} + ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { std::string bundleName = fileInfo.owner; @@ -529,45 +558,50 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd } if (!SAUtils::IsSABundleName(bundleName)) { HILOGE("Bundle name %{public}s is not sa", bundleName.c_str()); - return BError(BError::Codes::SA_EXT_ERR_CALL); + return BError(BError::Codes::SA_EXT_ERR_CALL).GetCode(); } HILOGI("Bundle name %{public}s is sa, publish sa incremental file", bundleName.c_str()); auto backupConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = backupConnection.lock(); if (saConnection == nullptr) { HILOGE("lock sa connection ptr is nullptr"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } return saConnection->CallRestoreSA(move(fd)); } -ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, - UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, + const std::string &fileName, + UniqueFd fd, + UniqueFd manifestFd, + int32_t errCode) { + HILOGI("Begin AppIncrementalFileReadybundleName:%{public}s, fileName:%p{ublic}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(bundleName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); - return BError(BError::Codes::OK); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); + return BError(BError::Codes::OK).GetCode(); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(bundleName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); + move(manifestFd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); if (ret != ERR_OK) { - HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); return ret; } } OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); + return ErrCode((BError::Codes::OK)); } catch (const BError &e) { HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 @@ -577,28 +611,47 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st } } +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + HILOGI("Begin AppIncrementalFileReady:%{public}s, fd:%{public}d, manifestFd:%{public}d, errcode:%{public}d", + fileName.c_str(), fd, manifestFd, appIncrementalFileReadyErrCode); + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); + } + UniqueFd fdUnique(fd); + UniqueFd manifestFdUnique(manifestFd); + return AppIncrementalFileReady(fileName, std::move(fdUnique), std::move(manifestFdUnique), + appIncrementalFileReadyErrCode); +} + ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("Begin AppIncrementalFileReady:%{public}s, errcode:%{public}d", + fileName.c_str(), errCode); string callerName; ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { HILOGE("Verify caller failed, ret:%{public}d", ret); return ret; } - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::RESTORE); - return BError(BError::Codes::OK); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); + return BError(BError::Codes::OK).GetCode(); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::BACKUP); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(callerName, fileName)) { ErrCode ret = HandleCurBundleFileReady(callerName, fileName, true); if (ret != ERR_OK) { @@ -608,7 +661,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f } } OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 @@ -667,9 +720,9 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s try { if (session_ == nullptr) { HILOGE("GetIncrementalFileHandle error, session is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("Error, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), GetAnonyPath(fileName).c_str()); @@ -678,24 +731,25 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::UNKNOWN) { HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("GetIncrementalFileHandle failed, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - auto[errCode, fd, reportFd] = proxy->GetIncrementalFileHandle(fileName); - auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); + UniqueFdGroup fdGroup; + proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); + UniqueFd fd(static_cast(fdGroup.fd)); + UniqueFd reportFd(static_cast(fdGroup.reportFd)); + auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (err != ERR_OK) { - HILOGE("Failed to send file handle, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); AppRadar::Info info (bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandle", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, err); @@ -704,7 +758,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); session_->SetExtFileNameRequest(bundleName, fileName); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("GetIncrementalFileHandle exception, bundleName:%{public}s", bundleName.c_str()); return e.GetCode(); @@ -714,7 +768,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s bool Service::IncrementalBackup(const string &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); @@ -729,17 +783,18 @@ bool Service::IncrementalBackup(const string &bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); return true; } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { auto ret = proxy->IncrementalOnBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); - BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::BACKUP); + BundleBeginRadarReport(bundleName, ret, IServiceReverseType::Scenario::BACKUP); if (ret) { SendEndAppGalleryNotify(bundleName); ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); } return true; - } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -747,12 +802,14 @@ bool Service::IncrementalBackup(const string &bundleName) if (oldBackupVersion.empty()) { HILOGE("Failed to get backupVersion of old device"); } - HILOGD("backupVersion of old device = %{public}s", oldBackupVersion.c_str()); - BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::RESTORE); + BundleBeginRadarReport(bundleName, ret, IServiceReverseType::Scenario::RESTORE); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (const auto &fileName : fileNameVec) { - auto[errCode, fd, reportFd] = proxy->GetIncrementalFileHandle(fileName); - ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); + UniqueFdGroup fdGroup; + proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); + UniqueFd fd(static_cast(fdGroup.fd)); + UniqueFd reportFd(static_cast(fdGroup.reportFd)); + ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (ret) { HILOGE("Failed to send file handle %{public}s", GetAnonyString(fileName).c_str()); } @@ -764,8 +821,10 @@ bool Service::IncrementalBackup(const string &bundleName) void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string &callerName) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + HILOGI("Begin NotifyCallerCurAppIncrementDone errCode = %{public}d, callerName = %{public}s", + errCode, callerName.c_str()); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is incremental backup"); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); @@ -782,7 +841,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string "PROC_NAME", "ohos.appfileservice", "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str() ); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); @@ -791,6 +850,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string void Service::SendUserIdToApp(string &bundleName, int32_t userId) { + HILOGI("Begin SendUserIdToApp bundleName%{public}s, userId%{public}d", bundleName.c_str(), userId); if (session_ == nullptr) { HILOGI("session_ is nullptr"); return; @@ -858,6 +918,7 @@ void Service::SetBundleIncDataInfo(const std::vector& bundlesT void Service::CancelTask(std::string bundleName, wptr ptr) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin CancelTask bundleName%{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { HILOGE("this pointer is null"); @@ -891,9 +952,9 @@ void Service::CancelTask(std::string bundleName, wptr ptr) session->StopExtTimer(bundleName); backUpConnection->DisconnectBackupExtAbility(); thisPtr->ClearSessionAndSchedInfo(bundleName); - IServiceReverse::Scenario scenario = session->GetScenario(); - if ((scenario == IServiceReverse::Scenario::BACKUP && session->GetIsIncrementalBackup()) || - (scenario == IServiceReverse::Scenario::RESTORE && + IServiceReverseType::Scenario scenario = session->GetScenario(); + if ((scenario == IServiceReverseType::Scenario::BACKUP && session->GetIsIncrementalBackup()) || + (scenario == IServiceReverseType::Scenario::RESTORE && session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND))) { thisPtr->NotifyCallerCurAppIncrementDone(BError(BError::Codes::OK), bundleName); } else { @@ -904,7 +965,7 @@ void Service::CancelTask(std::string bundleName, wptr ptr) thisPtr->OnAllBundlesFinished(BError(BError::Codes::OK)); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin, bundle name:%{public}s", bundleName.c_str()); @@ -912,7 +973,7 @@ ErrCode Service::Cancel(std::string bundleName, int32_t &result) HILOGE("Cancel error, session is null"); return BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK); } - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); ErrCode ret = VerifyCaller(scenario); if (ret != ERR_OK) { HILOGE("Verify caller failed, bundleName:%{public}s, scenario:%{public}d", bundleName.c_str(), scenario); diff --git a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp deleted file mode 100644 index 57e412c92..000000000 --- a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "module_ipc/service_reverse_proxy.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" -#include "module_app_gallery/app_gallery_dispose_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = true; - if (fd < 0 || manifestFd < 0) { - fdFlag = false; - } - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || - !data.WriteString(fileName) || !data.WriteBool(fdFlag) || - (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || - !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnResultReport(std::string result, std::string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnScanningInfo(std::string scannedInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SCANNED_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED), - data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnResultReport(std::string result, - std::string bundleName, ErrCode errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || - !data.WriteString(bundleName) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || - !data.WriteString(fileName) || !data.WriteBool(fdFlag) || - (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || - !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp deleted file mode 100644 index 2d2dbab36..000000000 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ /dev/null @@ -1,259 +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_reverse_proxy.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = fd < 0 ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || - !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnResultReport(std::string result, std::string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_PROCESS_INFO), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnScanningInfo(std::string scannedInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SCANNED_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = fd < 0 ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || - !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode) -{ - HILOGI("ServiceReverseProxy::RestoreOnResultReport Begin with result: %s", result.c_str()); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || - !data.WriteString(bundleName) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp deleted file mode 100644 index ae94248e9..000000000 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ /dev/null @@ -1,858 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * 注意: - * - 注意点1:本文件原则上只处理与IPC模块的IO,具体业务逻辑实现在service.cpp中 - * - 注意点2:所有调用开头处打印 Begin 字样,通过BError返回正常结果/错误码,这是出于防抵赖的目的 - */ - -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "module_ipc/service_reverse_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; - - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER)] = - &ServiceStub::CmdStartExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] = - &ServiceStub::CmdStartFwkTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; -} - -void ServiceStub::ServiceStubSuppAppendBundles() -{ - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; -} - -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT)] = - &ServiceStub::CmdResultReport; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - ServiceStubSuppAppendBundles(); - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishSAIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE)] = - &ServiceStub::CmdAppIncrementalDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; - ServiceStubSupplement(); -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitRestoreSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitRestoreSession(iremote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int res = InitBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int res = InitBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppFileReady(fileName, move(fd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = AppDone(errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - int32_t scenario; - ErrCode errCode; - if (!data.ReadString(restoreRetInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreRetInfo"); - } - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive scenario"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - HILOGE("Failed to receive bundle detailInfos"); - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesBackupSession(bundleNames); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - - int32_t res = AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdGetBackupInfo Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - string result; - ret = GetBackupInfo(bundleName, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdGetBackupInfo end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateTimer Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); - } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateSendRate Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateSendRate")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateSendRate end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartExtTimer Begin."); - int ret = ERR_OK; - bool isExtStart; - ret = StartExtTimer(isExtStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isExtStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartFwkTimer Begin."); - int ret = ERR_OK; - bool isFwkStart; - ret = StartFwkTimer(isFwkStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isFwkStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartFwkTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!ReadParcelableVector(bundleNames, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - UniqueFd fd(GetLocalCapabilitiesIncremental(bundleNames)); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - int32_t res = GetAppLocalListAndDoIncrementalBackup(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitIncrementalBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitIncrementalBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - std::vector infos; - if (!data.ReadStringVector(&infos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive infos"); - } - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishIncrementalFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - UniqueFd fd(data.ReadFileDescriptor()); - int res = PublishSAIncrementalFile(*fileInfo, move(fd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - UniqueFd manifestFd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - manifestFd = UniqueFd(data.ReadFileDescriptor()); - if (manifestFd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive manifestFd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppIncrementalFileReady(fileName, move(fd), move(manifestFd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply) -{ - int32_t ret; - if (!data.ReadInt32(ret)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bool flag"); - } - int res = AppIncrementalDone(ret); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - return GetIncrementalFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - string processInfo; - if (!data.ReadString(processInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t scenario; - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - return ReportAppProcessInfo(processInfo, secenrioInfo); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStopExtTimer Begin."); - bool isExtStop; - auto ret = StopExtTimer(isExtStop); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call StopExtTimer")); - } - if (!reply.WriteBool(isExtStop)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStopExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdRefreshDataSize Begin."); - int64_t totalDatasize = 0; - if (!data.ReadInt64(totalDatasize)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive totalDatasize").GetCode(); - } - auto ret = RefreshDataSize(totalDatasize); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to receive totalDatasize")); - } - bool ifRefreshSuccess = true; - if (!reply.WriteBool(ifRefreshSuccess)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdRefreshDataSize end."); - return BError(BError::Codes::OK); -} - -template -bool ServiceStub::ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - HILOGE("Failed to read Parcelable size."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < BConstants::MAX_PARCELABLE_VECTOR_NUM) ? infoSize : BConstants::MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadParcelable(); - if (info == nullptr) { - HILOGE("Failed to read Parcelable infos."); - return false; - } - parcelableInfos.emplace_back(move(*info)); - } - - return true; -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdCancel Begin."); - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ErrCode res = Cancel(bundleName, result); - if (!reply.WriteInt32(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return res; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilitiesForBundleInfos()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub CmdGetBackupDataSize Begin."); - bool isPreciseScan = true; - isPreciseScan = data.ReadBool(); - vector bundleNameList; - if (!ReadParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - auto ret = GetBackupDataSize(isPreciseScan, bundleNameList); - HILOGI("ServiceStub GetBackupDataSize End ret = %{public}d", ret); - return ret; -} -} // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b679afd82..1b125b3ea 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -36,7 +36,7 @@ #include "b_anony/b_anony.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_hiaudit/hi_audit.h" #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" @@ -82,11 +82,11 @@ void Service::AppendBundles(const std::vector &bundleNames) } } -void Service::ReportOnBundleStarted(IServiceReverse::Scenario scenario, const std::string &bundleName) +void Service::ReportOnBundleStarted(IServiceReverseType::Scenario scenario, const std::string &bundleName) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), bundleName); } } @@ -163,7 +163,7 @@ bool Service::IsReportFileReadyFail(const std::string &bundleName) return true; } -void Service::TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName) +void Service::TimeoutRadarReport(IServiceReverseType::Scenario scenario, std::string &bundleName) { if (!IsReportBundleExecFail(bundleName)) { return; @@ -173,11 +173,11 @@ void Service::TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string if (session_->GetTimeoutValue(bundleName) == 0) { errCode = BError::BackupErrorCode::E_FORCE_TIMEOUT; } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::Info info(bundleName, "", "on backup timeout"); AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::TimeOutCallback", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_ON_BACKUP, errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::Info info(bundleName, "", "on restore timeout"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::TimeOutCallback", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_ON_RESTORE, errCode); @@ -216,7 +216,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) HILOGE("PublishFile error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("PublishFile error, verify caller by scenario failed, ret:%{public}d", ret); return ret; @@ -243,6 +243,17 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) +{ + HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); + UniqueFd fdUnique(static_cast(fd)); + if (fd < 0) { + HILOGE("Error fd, fd = %{public}d", fd); + return BError(BError::Codes::SA_INVAL_ARG); + } + return AppFileReady(fileName, std::move(fdUnique), errCode); +} + ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -288,6 +299,7 @@ ErrCode Service::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("AppDone errCode =%{public}d", errCode); if (session_ == nullptr) { HILOGE("App finish error, session info is empty"); return BError(BError::Codes::SA_INVAL_ARG); @@ -330,17 +342,17 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("begin %{public}s", bundleName.data()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); BConstants::ExtensionAction action; - if (scenario == IServiceReverse::Scenario::BACKUP || scenario == IServiceReverse::Scenario::CLEAN) { + if (scenario == IServiceReverseType::Scenario::BACKUP || scenario == IServiceReverseType::Scenario::CLEAN) { action = BConstants::ExtensionAction::BACKUP; - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { action = BConstants::ExtensionAction::RESTORE; } else { action = BConstants::ExtensionAction::INVALID; HILOGE("Launch current bundle backupExtension failed, action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (SAUtils::IsSABundleName(bundleName)) { return LaunchBackupSAExtension(bundleName); @@ -350,25 +362,25 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("LaunchBackupExtension error, backUpConnection is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (backUpConnection->IsExtAbilityConnected() && !backUpConnection->WaitDisconnectDone()) { HILOGE("LaunchBackupExtension error, WaitDisconnectDone failed"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } BConstants::ServiceSchedAction bundleAction = session_->GetServiceSchedAction(bundleName); if (bundleAction == BConstants::ServiceSchedAction::UNKNOWN) { HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId(), bundleAction == BConstants::ServiceSchedAction::CLEAN); if (ret != ERR_OK) { HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); ExtensionConnectFailRadarReport(bundleName, ret, scenario); - return BError(BError::Codes::SA_BOOT_EXT_FAIL); + return BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode(); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } void Service::SetWant(AAFwk::Want &want, const BundleName &bundleName, const BConstants::ExtensionAction &action) @@ -414,7 +426,7 @@ std::vector Service::GetSupportBackupBundleNames(vectorGetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); }; BundleEndRadarReport(bundleName, errCode, scenario); @@ -643,20 +655,20 @@ void Service::OnAllBundlesFinished(ErrCode errCode) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("called begin."); if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverseType::Scenario::RESTORE)) { HILOGI("Will destory session info"); SessionDeactive(); } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnAllBundlesFinished(errCode); } if (!BackupPara().GetBackupOverrideBackupSARelease()) { @@ -674,12 +686,12 @@ ErrCode Service::VerifySendRateParam() HILOGE("Update send rate fail, verify caller failed, ret:%{public}d", ret); return ret; } - IServiceReverse::Scenario scenario = session_ -> GetScenario(); - if (scenario != IServiceReverse::Scenario::BACKUP) { + IServiceReverseType::Scenario scenario = session_ -> GetScenario(); + if (scenario != IServiceReverseType::Scenario::BACKUP) { HILOGE("This method is applicable to the backup scenario"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const std::string &fileName, bool isIncBackup) @@ -687,12 +699,12 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("AppFileReady error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("AppFileReady error, Extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } // 通知extension清空缓存 proxy->HandleClear(); @@ -703,7 +715,7 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s if (isIncBackup) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), bundleName); - BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); + BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverseType::Scenario::BACKUP); } else { session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), bundleName); BundleEndRadarReport(bundleName, BError(BError::Codes::OK), session_->GetScenario()); @@ -711,7 +723,7 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(bundleName); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup) @@ -719,12 +731,12 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("App finish error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("App finish error, extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } proxy->HandleClear(); session_->StopFwkTimer(bundleName); @@ -741,7 +753,7 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName bundleName.c_str(), errCode); NotifyCallerCurAppDone(errCode, bundleName); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } std::string Service::GetCallerName() @@ -775,7 +787,13 @@ std::string Service::GetCallerName() return callerName; } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + HILOGI("Start InitRestoreSessionWithErrMsg,Msg :%{public}s", errMsg.c_str()); + return InitRestoreSession(remote, errMsg); +} + +ErrCode Service::InitRestoreSession(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -785,7 +803,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e } ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::RESTORE, + .scenario = IServiceReverseType::Scenario::RESTORE, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -810,7 +828,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e return ret; } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -823,7 +841,7 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er session_->SetMemParaCurSize(oldSize); ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -848,6 +866,14 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er return ret; } +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + UniqueFd uniqueFd(GetLocalCapabilitiesForBundleInfos()); + HILOGI("get GetLocalCapabilitiesForBundleInfos value"); + fd = uniqueFd.Release(); + return ErrCode(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilitiesForBundleInfos() { try { @@ -920,7 +946,7 @@ void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRes } } -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { HILOGI("start GetBackupDataSize"); @@ -1133,7 +1159,7 @@ void Service::SendScannedInfo(const string&scannendInfos, sptrGetScenario() == IServiceReverse::Scenario::BACKUP && session->GetIsIncrementalBackup()) { + if (session->GetScenario() == IServiceReverseType::Scenario::BACKUP && session->GetIsIncrementalBackup()) { HILOGI("this is incremental backup sending info"); session->GetServiceReverseProxy()->IncrementalBackupOnScanningInfo(scannendInfos); return; diff --git a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp index 7dc6d5eec..58bdb6158 100644 --- a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp @@ -21,7 +21,7 @@ #include "ability_manager_client.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" -#include "module_ipc/svc_extension_proxy.h" +#include "extension_proxy.h" #include "module_ipc/svc_session_manager.h" namespace OHOS::FileManagement::Backup { @@ -40,7 +40,7 @@ void SvcBackupConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &el HILOGE("Failed to ability connect done, remote is nullptr"); return; } - backupProxy_ = iface_cast(remoteObject); + backupProxy_ = iface_cast(remoteObject); if (backupProxy_ == nullptr) { HILOGE("Failed to ability connect done, backupProxy_ is nullptr"); return; diff --git a/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp deleted file mode 100644 index c29b0e72b..000000000 --- a/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "module_ipc/svc_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; - -std::tuple SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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), UniqueFd(-1), UniqueFd(-1)}; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_FILE_HANDLE), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return {ErrCode(ret), UniqueFd(-1), UniqueFd(-1)}; - } - - HILOGD("Successful"); - ErrCode err(reply.ReadInt32()); - UniqueFd fd(reply.ReadFileDescriptor()); - UniqueFd reportFd(reply.ReadFileDescriptor()); - return {err, move(fd), move(reportFd)}; -} - -ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_INCREMENTAL_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::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - data.WriteFileDescriptor(incrementalFd); - data.WriteFileDescriptor(manifestFd); - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_HANDLE_INCREMENTAL_BACKUP), - 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::IncrementalOnBackup(bool isClearData) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_INCREMENTAL_ON_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGD("Successful"); - return BError(BError::Codes::OK); -} - -ErrCode SvcExtensionProxy::User0OnBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_USER_0_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGD("Successful"); - return reply.ReadInt32(); -} - -tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_GET_INCREMENTAL_BACKUP_FILE_HANDLE), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return {UniqueFd(-1), UniqueFd(-1)}; - } - - HILOGD("Successful"); - UniqueFd incrementalFd(reply.ReadFileDescriptor()); - UniqueFd manifestFd(reply.ReadFileDescriptor()); - return {move(incrementalFd), move(manifestFd)}; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 ce2bfcc36..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 "module_ipc/svc_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/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index a0aafce1c..fdf175875 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -25,7 +25,7 @@ #include "b_anony/b_anony.h" #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_entity_ext_manage.h" #include "b_radar/b_radar.h" @@ -40,7 +40,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { shared_lock lock(lock_); if (impl_.scenario != scenario) { @@ -88,7 +88,7 @@ ErrCode SvcSessionManager::Active(Impl newImpl, bool isOccupyingSession) HILOGE("Active session fail, No caller token was specified"); return BError(BError::Codes::SA_INVAL_ARG); } - if (!isOccupyingSession && newImpl.scenario == IServiceReverse::Scenario::UNDEFINED) { + if (!isOccupyingSession && newImpl.scenario == IServiceReverseType::Scenario::UNDEFINED) { HILOGE("Active session fail, No scenario was specified"); return BError(BError::Codes::SA_INVAL_ARG); } @@ -124,10 +124,10 @@ ErrCode SvcSessionManager::Deactive(const wptr &remoteInAction, b deathRecipient_ = nullptr; AppRadar::Info info("", "", "deactive session success"); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, BizStageRestore::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); - } else if (impl_.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (impl_.scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, BizStageBackup::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); } @@ -163,12 +163,12 @@ sptr SvcSessionManager::GetServiceReverseProxy() return impl_.clientProxy; } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { shared_lock lock(lock_); if (!impl_.clientToken) { HILOGE("Get scenario failed, No caller token was specified"); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; } return impl_.scenario; } @@ -217,10 +217,10 @@ bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string return false; } // 判断是否结束 通知EXTENTION清理资源 TOOL应用完成备份 - if (impl_.scenario == IServiceReverse::Scenario::RESTORE || SAUtils::IsSABundleName(bundleName)) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE || SAUtils::IsSABundleName(bundleName)) { it->second.isBundleFinished = true; return true; - } else if (impl_.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (impl_.scenario == IServiceReverseType::Scenario::BACKUP) { if (!fileName.empty() && fileName != BConstants::EXT_BACKUP_MANAGE) { auto ret = it->second.fileNameInfo.emplace(fileName); if (!ret.second) { @@ -246,7 +246,7 @@ UniqueFd SvcSessionManager::OnBundleExtManageInfo(const string &bundleName, Uniq HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); return UniqueFd(-EPERM); } - if (impl_.scenario != IServiceReverse::Scenario::BACKUP) { + if (impl_.scenario != IServiceReverseType::Scenario::BACKUP) { HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); return UniqueFd(-EPERM); } @@ -436,10 +436,10 @@ ErrCode SvcSessionManager::InitClient(Impl &newImpl) deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); AppRadar::Info info("", "", "active session success"); - if (newImpl.scenario == IServiceReverse::Scenario::RESTORE) { + if (newImpl.scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, BizStageRestore::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); - } else if (newImpl.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (newImpl.scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, BizStageBackup::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); } @@ -470,7 +470,7 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string return std::set(); } - if (impl_.scenario != IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario != IServiceReverseType::Scenario::RESTORE) { HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); return std::set(); } @@ -682,7 +682,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.isAppendFinish = true; } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { HILOGD("SvcSessionManager::CreateBackupConnection begin."); return GetBackupAbilityExt(bundleName); @@ -718,7 +718,7 @@ bool SvcSessionManager::IsOnAllBundlesFinished() return false; } bool isAllBundlesFinished = !impl_.backupExtNameMap.size(); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isAllBundlesFinished = (isAllBundlesFinished && isAllBundlesRestored); } @@ -748,7 +748,7 @@ bool SvcSessionManager::NeedToUnloadService() return false; } bool isNeedToUnloadService = (!impl_.backupExtNameMap.size() && (sessionCnt_.load() <= 0)); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isNeedToUnloadService = (isNeedToUnloadService && isAllBundlesRestored); } diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 5c8b5de7a..ebdf00c28 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -40,16 +40,16 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ExtDiedClearFailRadarReport(const string& bundleName, IServiceReverse::Scenario scenario, ErrCode res) +void ExtDiedClearFailRadarReport(const string& bundleName, IServiceReverseType::Scenario scenario, ErrCode res) { if (res == ERR_OK) { return; } AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SchedScheduler::ExecutingQueueTasks", AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SchedScheduler::ExecutingQueueTasks", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); } @@ -240,7 +240,7 @@ void SchedScheduler::StartExecuteBundleTask(const std::string &bundleName, BCons } else if (action == BConstants::ServiceSchedAction::CLEAN) { HILOGI("Current bundle %{public}s process is cleaning", bundleName.data()); ErrCode res = reversePtr_->ClearResidualBundleData(bundleName); - IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); + IServiceReverseType::Scenario scenario = sessionPtr_->GetScenario(); ExtDiedClearFailRadarReport(bundleName, scenario, res); } } diff --git a/test/fuzztest/backupext_fuzzer/BUILD.gn b/test/fuzztest/backupext_fuzzer/BUILD.gn index 81a738cca..66f9093fd 100644 --- a/test/fuzztest/backupext_fuzzer/BUILD.gn +++ b/test/fuzztest/backupext_fuzzer/BUILD.gn @@ -41,7 +41,6 @@ ohos_fuzztest("BackupExtFuzzTest") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", diff --git a/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp b/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp index 19065f4cc..f2fa08267 100644 --- a/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp +++ b/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp @@ -47,7 +47,7 @@ bool OnRemoteRequestFuzzTest(shared_ptr extension, const uin int pos = 0; uint32_t code = TypeCast(data, &pos); - msg.WriteInterfaceToken(ExtExtensionStub::GetDescriptor()); + msg.WriteInterfaceToken(ExtensionStub::GetDescriptor()); msg.WriteBuffer(data + pos, size - pos); msg.RewindRead(0); @@ -160,137 +160,6 @@ bool SetCreatorFuzzTest(shared_ptr backup, const uint8_t *data, size_ backup->SetCreator(creator); return true; } - -bool CmdGetFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdGetFileHandle(msg, reply); - return true; -} - -bool CmdHandleClearFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdHandleClear(msg, reply); - return true; -} - -bool CmdHandleUser0BackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdHandleUser0Backup(msg, reply); - return true; -} - -bool CmdHandleBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdHandleBackup(msg, reply); - return true; -} - -bool CmdPublishFileFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdPublishFile(msg, reply); - return true; -} - -bool CmdHandleRestoreFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdHandleRestore(msg, reply); - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdGetIncrementalFileHandle(msg, reply); - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdPublishIncrementalFile(msg, reply); - return true; -} - -bool CmdHandleIncrementalBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - int pos = 0; - int incrementalFd = TypeCast(data, &pos); - int manifestFd = TypeCast(data + pos); - msg.WriteFileDescriptor(incrementalFd); - msg.WriteFileDescriptor(manifestFd); - extension->CmdPublishIncrementalFile(msg, reply); - return true; -} - -bool CmdIncrementalOnBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdIncrementalOnBackup(msg, reply); - return true; -} - -bool CmdGetIncrementalBackupFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, - size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdGetIncrementalBackupFileHandle(msg, reply); - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -313,22 +182,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::RestoreDataReadyFuzzTest(extBackup, data, size); OHOS::InvokeAppExtMethodFuzzTest(extBackup, data, size); OHOS::SetCreatorFuzzTest(extBackup, data, size); - - try { - OHOS::CmdGetFileHandleFuzzTest(extension, data, size); - OHOS::CmdHandleClearFuzzTest(extension, data, size); - OHOS::CmdHandleUser0BackupFuzzTest(extension, data, size); - OHOS::CmdHandleBackupFuzzTest(extension, data, size); - OHOS::CmdPublishFileFuzzTest(extension, data, size); - OHOS::CmdHandleRestoreFuzzTest(extension, data, size); - OHOS::CmdGetIncrementalFileHandleFuzzTest(extension, data, size); - OHOS::CmdPublishIncrementalFileFuzzTest(extension, data, size); - OHOS::CmdHandleIncrementalBackupFuzzTest(extension, data, size); - OHOS::CmdIncrementalOnBackupFuzzTest(extension, data, size); - OHOS::CmdGetIncrementalBackupFileHandleFuzzTest(extension, data, size); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return 0; } diff --git a/test/fuzztest/backupsa_fuzzer/BUILD.gn b/test/fuzztest/backupsa_fuzzer/BUILD.gn index 2335ebb8f..3db3c922c 100644 --- a/test/fuzztest/backupsa_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsa_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("BackupSaFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp b/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp index a811dcc08..e3b108070 100644 --- a/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp +++ b/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp @@ -19,12 +19,12 @@ #include #include -#include #include "message_parcel.h" -#include "service_stub.h" -#include "service.h" #include "securec.h" +#include "service.h" +#include "service_stub.h" #include "system_ability.h" +#include #include "filemgmt_libhilog.h" @@ -48,13 +48,13 @@ bool BackupSaFuzzTest(const uint8_t *data, size_t size) } sptr service = sptr(new Service(SERVICE_ID)); - uint32_t code = GetU32Data(reinterpret_cast(data)); + uint32_t code = GetU32Data(reinterpret_cast(data)); if (code == 0) { return true; } MessageParcel datas; datas.WriteInterfaceToken(ServiceStub::GetDescriptor()); - datas.WriteBuffer(reinterpret_cast(data + U32_AT_SIZE), size - U32_AT_SIZE); + datas.WriteBuffer(reinterpret_cast(data + U32_AT_SIZE), size - U32_AT_SIZE); datas.RewindRead(0); MessageParcel reply; MessageOption option; diff --git a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp index ca438cd7c..2b1f339e3 100644 --- a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp +++ b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp @@ -54,7 +54,7 @@ bool CmdGetFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE), datas, reply, option); service = nullptr; return true; @@ -79,7 +79,7 @@ bool CmdAppendBundlesBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -95,7 +95,7 @@ bool CmdReleaseFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -113,7 +113,7 @@ void GetBundleNamesData(const uint8_t *data, size_t size, vector(data)); - int32_t fd = *(reinterpret_cast(data)); + int fd = *(reinterpret_cast(data)); int32_t priority = *(reinterpret_cast(data + sizeof(int32_t))); string parameters = string(reinterpret_cast(data), size) + to_string(size - i); BIncrementalData incrementaData(name, nTime, fd, parameters, priority); @@ -152,7 +152,7 @@ bool CmdGetLocalCapabilitiesIncrementalFuzzTest(const uint8_t *data, size_t size MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -168,7 +168,7 @@ bool CmdInitIncrementalBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -189,7 +189,7 @@ bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(const uint8_t *data, size_ sptr service(new Service(SERVICE_ID)); uint32_t code = static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -216,7 +216,7 @@ bool CmdPublishIncrementalFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -242,7 +242,7 @@ bool CmdAppIncrementalFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -261,7 +261,7 @@ bool CmdAppIncrementalDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE), datas, reply, option); service = nullptr; return true; @@ -287,7 +287,7 @@ bool CmdGetIncrementalFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp index 2c44b7943..6d94b527d 100644 --- a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -45,7 +45,7 @@ bool CmdInitRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION), datas, reply, option); service = nullptr; return true; @@ -61,7 +61,7 @@ bool CmdInitBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION), datas, reply, option); service = nullptr; return true; @@ -87,7 +87,7 @@ bool CmdPublishFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE), datas, reply, option); service = nullptr; return true; @@ -103,7 +103,7 @@ bool CmdGetLocalCapabilitiesFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -127,7 +127,7 @@ bool CmdAppFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -145,7 +145,7 @@ bool CmdAppDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_DONE), datas, reply, option); service = nullptr; return true; @@ -161,7 +161,7 @@ bool CmdStartFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_START), datas, reply, option); service = nullptr; return true; @@ -177,7 +177,7 @@ bool CmdFinishFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_FINISH), datas, reply, option); service = nullptr; return true; @@ -219,7 +219,7 @@ bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp index 2858c657a..11fbc23eb 100644 --- a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp +++ b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp @@ -17,7 +17,7 @@ #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_session_backup.h" #include "b_session_restore.h" #include "message_parcel.h" @@ -72,547 +72,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd); - } - msg.WriteInt32(errCode); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(scenario); - msg.WriteInt32(errCode); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - msg.WriteStringVector(bundleNames); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundleNames, msg); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundlesToBackup, msg); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 2; - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - infos.emplace_back(string(reinterpret_cast(data + len + len), len)); - WriteParcelableVector(bundlesToBackup, msg); - msg.WriteStringVector(infos); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - msg.WriteFileDescriptor(fd); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd1); - msg.WriteFileDescriptor(fd2); - } - msg.WriteInt32(errCode); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteString(string(reinterpret_cast(data), size)); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t timeout = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(timeout); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(sendRate); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -625,32 +84,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index 5b788a6cb..d94bd33ef 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -18,7 +18,7 @@ #include #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_session_backup.h" #include "b_session_restore.h" #include "message_parcel.h" @@ -220,839 +220,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitRestoreSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdStart(msg, reply); - - ExpectReturn({true}); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetLocalCapabilities(msg, reply); - - ExpectReturn({true}); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - service->CmdAppFileReady(msg, reply); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - string restoreRetInfo(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({restoreRetInfo}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({restoreRetInfo, scenario}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, true}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, type}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, true}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdFinish(msg, reply); - - ExpectReturn({true}); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); - - int32_t infoSize = 1; - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - - ExpectReturn({true}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitIncrementalBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); - - ExpectReturn({false}); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - int32_t infoSize = 1; - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int32_t infoSize = 1; - int len = size >> 1; - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({fd, false}); - service->CmdPublishSAIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({fd, true}); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : - ExpectReturn({true, flag, fd1, fd2, errCode, false}); - } else { - ExpectReturn({true, flag, errCode, false}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : - ExpectReturn({true, flag, fd1, fd2, errCode, true}); - } else { - ExpectReturn({true, flag, errCode, true}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - string bundleName(reinterpret_cast(data), size); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - uint32_t timeout = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -1065,32 +232,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/servicereverse_fuzzer/BUILD.gn b/test/fuzztest/servicereverse_fuzzer/BUILD.gn index 83e4237e0..ac3fee62e 100644 --- a/test/fuzztest/servicereverse_fuzzer/BUILD.gn +++ b/test/fuzztest/servicereverse_fuzzer/BUILD.gn @@ -42,6 +42,8 @@ ohos_fuzztest("ServiceReverseFuzzTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", ] diff --git a/tests/mock/backup_ext/include/ext_extension_mock.h b/tests/mock/backup_ext/include/ext_extension_mock.h index 65733f7ad..5d7d2d779 100644 --- a/tests/mock/backup_ext/include/ext_extension_mock.h +++ b/tests/mock/backup_ext/include/ext_extension_mock.h @@ -23,6 +23,7 @@ namespace OHOS::FileManagement::Backup { class BExtExtension { public: + virtual ErrCode GetFileHandleWithUniqueFd(const std::string &fileName, int32_t &getFileHandleErrCode, int &fd) = 0; virtual ErrCode GetIncrementalFileHandle(const string &) = 0; virtual UniqueFd GetFileHandle(const string &, int32_t &) = 0; virtual ErrCode HandleClear() = 0; @@ -45,28 +46,37 @@ public: virtual void AppResultReport(const std::string, BackupRestoreScenario, ErrCode) = 0; virtual void AsyncTaskOnBackup() = 0; virtual ErrCode HandleRestore() = 0; - virtual void PreparaBackupFiles(UniqueFd, UniqueFd, std::vector&, - std::vector&, std::vector&) = 0; + virtual ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) = 0; + virtual ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) = 0; + virtual void PreparaBackupFiles(UniqueFd, + UniqueFd, + std::vector &, + std::vector &, + std::vector &) = 0; + virtual ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) = 0; virtual ErrCode HandleIncrementalBackup(UniqueFd, UniqueFd) = 0; virtual ErrCode IncrementalOnBackup() = 0; virtual tuple GetIncrementalBackupFileHandle() = 0; - virtual ErrCode IncrementalBigFileReady(const TarMap&, const std::vector&, - sptr) = 0; + virtual ErrCode IncrementalBigFileReady(const TarMap &, + const std::vector &, + sptr) = 0; virtual void AsyncTaskDoIncrementalBackup(UniqueFd, UniqueFd) = 0; virtual void AsyncTaskOnIncrementalBackup() = 0; - virtual void IncrementalPacket(const std::vector&, TarMap&, sptr) = 0; - virtual int DoIncrementalBackup(const std::vector&, - const std::vector&, const std::vector&) = 0; + virtual void IncrementalPacket(const std::vector &, TarMap &, sptr) = 0; + virtual int DoIncrementalBackup(const std::vector &, + const std::vector &, + const std::vector &) = 0; virtual void AppIncrementalDone(ErrCode) = 0; - virtual ErrCode GetBackupInfo(std::string&) = 0; - virtual ErrCode UpdateFdSendRate(std::string&, int32_t) = 0; + virtual ErrCode GetBackupInfo(std::string &) = 0; + virtual ErrCode UpdateFdSendRate(std::string &, int32_t) = 0; virtual std::function RestoreResultCallbackEx(wptr) = 0; virtual std::function AppDoneCallbackEx(wptr) = 0; virtual std::function IncRestoreResultCallbackEx(wptr) = 0; virtual std::function HandleBackupEx(wptr) = 0; virtual std::function HandleTaskBackupEx(wptr) = 0; - virtual void WaitToSendFd(std::chrono::system_clock::time_point&, int&) = 0; - virtual void RefreshTimeInfo(std::chrono::system_clock::time_point&, int&) = 0; + virtual void WaitToSendFd(std::chrono::system_clock::time_point &, int &) = 0; + virtual void RefreshTimeInfo(std::chrono::system_clock::time_point &, int &) = 0; + public: BExtExtension() = default; virtual ~BExtExtension() = default; @@ -76,8 +86,8 @@ public: class ExtExtensionMock : public BExtExtension { public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const string &, int32_t &)); - MOCK_METHOD(std::tuple, GetIncrementalFileHandle, (const string &)); + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const string &, int32_t &, int32_t &)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const string &, UniqueFdGroup &fdGroup)); MOCK_METHOD(ErrCode, HandleClear, ()); MOCK_METHOD(ErrCode, BigFileReady, (sptr)); MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); @@ -100,9 +110,9 @@ public: MOCK_METHOD(ErrCode, HandleRestore, ()); MOCK_METHOD(void, FillFileInfos, (UniqueFd, UniqueFd, (std::vector&), (std::vector&), (std::vector&))); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); MOCK_METHOD(ErrCode, IncrementalOnBackup, ()); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup& fdGroup)); MOCK_METHOD(ErrCode, IncrementalBigFileReady, (const TarMap&, (const std::vector&), sptr)); MOCK_METHOD(void, AsyncTaskDoIncrementalBackup, (UniqueFd, UniqueFd)); diff --git a/tests/mock/backup_ext/include/ext_extension_stub_mock.h b/tests/mock/backup_ext/include/ext_extension_stub_mock.h index 6cc34071e..089b1cc80 100644 --- a/tests/mock/backup_ext/include/ext_extension_stub_mock.h +++ b/tests/mock/backup_ext/include/ext_extension_stub_mock.h @@ -21,7 +21,7 @@ #include "ext_extension_stub.h" namespace OHOS::FileManagement::Backup { -class ExtExtensionStubMock : public ExtExtensionStub { +class ExtExtensionStubMock : public ExtensionStub { public: MOCK_METHOD(int, OnRemoteRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); MOCK_METHOD(ErrCode, CmdGetFileHandle, (MessageParcel &, MessageParcel &)); diff --git a/tests/mock/backup_ext/src/ext_extension_mock.cpp b/tests/mock/backup_ext/src/ext_extension_mock.cpp index 4c54b88bf..15c541105 100644 --- a/tests/mock/backup_ext/src/ext_extension_mock.cpp +++ b/tests/mock/backup_ext/src/ext_extension_mock.cpp @@ -21,6 +21,26 @@ using namespace std; void BackupExtExtension::VerifyCaller() { } +ErrCode BackupExtExtension::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) +{ + return BExtExtension::extExtension->GetIncrementalBackupFileHandleWithUniqueFdGroup(fdGroup); +} +ErrCode BackupExtExtension::HandleIncrementalBackup(int32_t incrementalFd, int32_t manifestFd) +{ + return BExtExtension::extExtension->HandleIncrementalBackup(incrementalFd, manifestFd); +} +ErrCode BackupExtExtension::GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, + UniqueFdGroup &fdGroup) +{ + return BExtExtension::extExtension->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); +} + +ErrCode BackupExtExtension::GetFileHandleWithUniqueFd(const std::string &fileName, + int32_t &getFileHandleErrCode, + int &fd) +{ + return BExtExtension::extExtension->GetFileHandleWithUniqueFd(fileName, getFileHandleErrCode, fd); +} UniqueFd BackupExtExtension::GetFileHandle(const string &fileName, int32_t &errCode) { diff --git a/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp index 6f9309402..4ab92951c 100644 --- a/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp +++ b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp @@ -16,11 +16,11 @@ #include "ext_extension_stub_mock.h" namespace OHOS::FileManagement::Backup { -ExtExtensionStub::ExtExtensionStub() +ExtensionStub::ExtensionStub() { } -int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, +int32_t ExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return static_cast(this)->OnRemoteRequest(code, data, reply, option); diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp new file mode 100644 index 000000000..351c5dbc7 --- /dev/null +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "iremote_object_mock.h" +#include "utils_mock_global_variable.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + if (!GetMockGetInstance()) { + return nullptr; + } + + if (!GetMockLoadSystemAbility()) { + serviceProxy_ = sptr(new ServiceProxy(nullptr)); + } else { + sptr object = new MockIRemoteObject(); + serviceProxy_ = sptr(new ServiceProxy(object)); + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index d7ce74b5c..d27050da3 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -31,7 +31,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +int32_t ServiceProxy::InitRestoreSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -39,7 +39,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote) return 0; } -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -47,7 +47,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote, std::stri return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote) +int32_t ServiceProxy::InitBackupSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -55,7 +55,7 @@ int32_t ServiceProxy::InitBackupSession(sptr remote) return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -68,12 +68,13 @@ ErrCode ServiceProxy::Start() return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { TestManager tm("ServiceProxyMock_GetFd_0100"); string filePath = tm.GetRootDirCurTest().append("tmp"); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - return fd; + UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + fd = fd_OpenData.Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) @@ -81,7 +82,7 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -91,7 +92,7 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, +ErrCode ServiceProxy::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); @@ -102,19 +103,19 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - const vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -125,7 +126,7 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl } ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) + const std::vector &detailInfos) { return BError(BError::Codes::OK); } @@ -140,15 +141,16 @@ ErrCode ServiceProxy::Release() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + fd = UniqueFd(-1).Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() @@ -156,23 +158,24 @@ ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr& remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const vector &infos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -182,12 +185,12 @@ ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -202,12 +205,12 @@ ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, co return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } @@ -232,58 +235,23 @@ ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario scenario) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() -{ - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - if (!GetMockGetInstance()) { - return nullptr; - } - - if (!GetMockLoadSystemAbility()) { - serviceProxy_ = sptr(new ServiceProxy(nullptr)); - } else { - sptr object = new MockIRemoteObject(); - serviceProxy_ = sptr(new ServiceProxy(object)); - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int& fd) { - return; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - return; -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); + fd=-1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector& bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/mock/module_ipc/extension_proxy_mock.cpp b/tests/mock/module_ipc/extension_proxy_mock.cpp new file mode 100644 index 000000000..6c58a6b73 --- /dev/null +++ b/tests/mock/module_ipc/extension_proxy_mock.cpp @@ -0,0 +1,85 @@ +/* + * 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" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +ErrCode ExtensionProxy::GetFileHandleWithUniqueFd(const string &fileName, int32_t &errCode, int &fd) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleClear() +{ + return 0; +} + +ErrCode ExtensionProxy::HandleBackup(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::PublishFile(const string &fileName) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleRestore(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::GetBackupInfo(std::string &result) +{ + return 0; +} + +ErrCode ExtensionProxy::GetIncrementalFileHandleWithUniqueFdGroup(const string &fileName, UniqueFdGroup &fdGroup) +{ + return 0; +} + +ErrCode ExtensionProxy::PublishIncrementalFile(const string &fileName) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleIncrementalBackup(int incrementalFd, int manifestFd) +{ + return 0; +} + +ErrCode ExtensionProxy::IncrementalOnBackup(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) +{ + return 0; +} + +ErrCode ExtensionProxy::User0OnBackup() +{ + return 0; +} + +ErrCode ExtensionProxy::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) +{ + return 0; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/extension_type_mock.cpp b/tests/mock/module_ipc/extension_type_mock.cpp new file mode 100644 index 000000000..6876bacb9 --- /dev/null +++ b/tests/mock/module_ipc/extension_type_mock.cpp @@ -0,0 +1,43 @@ +/* + * 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_type.h" + +namespace OHOS { +namespace FileManagement { +namespace Backup { +namespace ExtensionType { + +ErrCode UniqueFdGroupBlockMarshalling(OHOS::MessageParcel& data, const UniqueFdGroup& dataBlock) +{ + if (!data.WriteUnpadBuffer(&dataBlock, sizeof(UniqueFdGroup))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +ErrCode UniqueFdGroupBlockUnmarshalling(OHOS::MessageParcel &data, UniqueFdGroup &dataBlock) +{ + const UniqueFdGroup *dataBlockPtr = + reinterpret_cast(data.ReadUnpadBuffer(sizeof(UniqueFdGroup))); + if (dataBlockPtr == nullptr) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} +} // namespace ExtensionType +} // namespace Backup +} // namespace FileManagement +} // namespace OHOS diff --git a/tests/mock/module_ipc/include/extension_proxy_mock.h b/tests/mock/module_ipc/include/extension_proxy_mock.h new file mode 100644 index 000000000..9e50bddb9 --- /dev/null +++ b/tests/mock/module_ipc/include/extension_proxy_mock.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_EXTENSION_PROXY_MOCK_H +#define OHOS_FILEMGMT_BACKUP_EXTENSION_PROXY_MOCK_H + +#include + +#include "extension_proxy.h" + +namespace OHOS::FileManagement::Backup { +class ExtensionProxyMock : public ExtensionProxy { +public: + ExtensionProxyMock() : ExtensionProxy(nullptr) {}; +public: + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int32_t &)); + MOCK_METHOD(ErrCode, HandleClear, ()); + MOCK_METHOD(ErrCode, HandleBackup, (bool)); + MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleRestore, (bool)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const std::string &, UniqueFdGroup &)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); + MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool)); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup &)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (const std::string &, int32_t)); + MOCK_METHOD(ErrCode, User0OnBackup, ()); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h index fc5c50fe8..55736f3f2 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -18,42 +18,44 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" namespace OHOS::FileManagement::Backup { class ServiceReverseProxyMock : public IRemoteProxy { public: - MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); - MOCK_METHOD(void, BackupOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, BackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnResultReport, (std::string, std::string));; - MOCK_METHOD(void, BackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, BackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, BackupOnScanningInfo, (std::string)); - - MOCK_METHOD(void, RestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, RestoreOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, RestoreOnResultReport, (std::string, std::string, ErrCode)); - MOCK_METHOD(void, RestoreOnProcessInfo, (std::string, std::string)); - - MOCK_METHOD(void, IncrementalBackupOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalBackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnResultReport, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalBackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnScanningInfo, (std::string)); - - MOCK_METHOD(void, IncrementalRestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnResultReport, (std::string, std::string, ErrCode));; - MOCK_METHOD(void, IncrementalRestoreOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + MOCK_METHOD(ErrCode, BackupOnFileReady, (const std::string &, const std::string &, int, int32_t)); + MOCK_METHOD(ErrCode, BackupOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnResultReport, (const std::string &, const std::string &)); + ; + MOCK_METHOD(ErrCode, BackupOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, BackupOnProcessInfo, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnScanningInfo, (const std::string &)); + + MOCK_METHOD(ErrCode, RestoreOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, RestoreOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, RestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, RestoreOnFileReady, (const std::string &, const std::string &, int32_t, int32_t)); + MOCK_METHOD(ErrCode, RestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); + MOCK_METHOD(ErrCode, RestoreOnProcessInfo, (const std::string &, const std::string &)); + + MOCK_METHOD(ErrCode, IncrementalBackupOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnResultReport, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnProcessInfo, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnScanningInfo, (const std::string &)); + + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); + ; + MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (const std::string &, const std::string &)); public: ServiceReverseProxyMock() : IRemoteProxy(nullptr) {} diff --git a/tests/mock/module_ipc/include/service_stub_mock.h b/tests/mock/module_ipc/include/service_stub_mock.h index 27d151755..565a19e2b 100644 --- a/tests/mock/module_ipc/include/service_stub_mock.h +++ b/tests/mock/module_ipc/include/service_stub_mock.h @@ -17,91 +17,15 @@ #define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H #include - +#include "module_ipc/service_stub.h" namespace OHOS::FileManagement::Backup { -class BServiceStub { -public: - virtual int32_t OnRemoteRequest(uint32_t, MessageParcel&, MessageParcel&, MessageOption&) = 0; - virtual int32_t CmdInitRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdInitBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdStart(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilities(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppFileReady(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppDone(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdResultReport(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetFileHandle(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdFinish(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdRelease(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdCancel(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdInitIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishIncrementalFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishSAIncrementalFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppIncrementalFileReady(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppIncrementalDone(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetIncrementalFileHandle(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetBackupInfo(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdUpdateTimer(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdUpdateSendRate(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdStopExtTimer(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdRefreshDataSize(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetBackupDataSize(MessageParcel&, MessageParcel&) = 0; - virtual void ServiceStubSupplement() = 0; - virtual void ServiceStubSuppAppendBundles() = 0; - -public: - BServiceStub() = default; - virtual ~BServiceStub() = default; -public: - static inline std::shared_ptr stub = nullptr; -}; - -class ServiceStubMock : public BServiceStub { +class ServiceStub : public IRemoteStub { public: - MOCK_METHOD(int32_t, OnRemoteRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); - MOCK_METHOD(int32_t, CmdInitRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdInitBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdStart, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilities, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilitiesForBdInfos, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppFileReady, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppDone, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdResultReport, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetFileHandle, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdFinish, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdRelease, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilitiesIncremental, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetAppLocalListAndDoIncrementalBackup, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdInitIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishIncrementalFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishSAIncrementalFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppIncrementalFileReady, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppIncrementalDone, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetIncrementalFileHandle, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetBackupInfo, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdUpdateTimer, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdUpdateSendRate, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdStopExtTimer, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdRefreshDataSize, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetBackupDataSize, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(void, ServiceStubSupplement, ()); - MOCK_METHOD(void, ServiceStubSuppAppendBundles, ()); + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H \ No newline at end of file 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 a042be3ab..af46f1d8c 100644 --- a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -25,18 +25,18 @@ class SvcExtensionProxyMock : public SvcExtensionProxy { public: SvcExtensionProxyMock() : SvcExtensionProxy(nullptr) {}; public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const std::string&, int32_t&)); + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int32_t &)); MOCK_METHOD(ErrCode, HandleClear, ()); MOCK_METHOD(ErrCode, HandleBackup, (bool)); - MOCK_METHOD(ErrCode, PublishFile, (const std::string&)); + MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); MOCK_METHOD(ErrCode, HandleRestore, (bool)); - MOCK_METHOD((std::tuple), GetIncrementalFileHandle, (const std::string&)); - MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string&)); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const std::string &, UniqueFdGroup &)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool)); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); - MOCK_METHOD(ErrCode, GetBackupInfo, (std::string&)); - MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string&, int32_t)); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup &)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string &, int32_t)); MOCK_METHOD(ErrCode, User0OnBackup, ()); }; } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/include/svc_session_manager_mock.h b/tests/mock/module_ipc/include/svc_session_manager_mock.h index 17634813c..83d363ceb 100644 --- a/tests/mock/module_ipc/include/svc_session_manager_mock.h +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -25,7 +25,7 @@ class BSvcSessionManager { public: virtual ErrCode Active(struct SvcSessionManager::Impl, bool) = 0; virtual sptr GetServiceReverseProxy() = 0; - virtual IServiceReverse::Scenario GetScenario() = 0; + virtual IServiceReverseType::Scenario GetScenario() = 0; virtual int32_t GetSessionUserId() = 0; virtual std::string GetSessionCallerName() = 0; virtual std::string GetSessionActiveTime() = 0; @@ -38,7 +38,7 @@ public: virtual bool GetSchedBundleName(std::string&) = 0; virtual std::string GetBackupExtName(const std::string&) = 0; virtual std::string GetBackupExtInfo(const std::string&) = 0; - virtual sptr CreateBackupConnection(BundleName&) = 0; + virtual sptr CreateBackupConnection(const BundleName&) = 0; virtual bool IsOnAllBundlesFinished() = 0; virtual bool IsOnOnStartSched() = 0; virtual bool NeedToUnloadService() = 0; @@ -73,7 +73,7 @@ class SvcSessionManagerMock : public BSvcSessionManager { public: MOCK_METHOD(ErrCode, Active, (struct SvcSessionManager::Impl, bool)); MOCK_METHOD((sptr), GetServiceReverseProxy, ()); - MOCK_METHOD(IServiceReverse::Scenario, GetScenario, ()); + MOCK_METHOD(IServiceReverseType::Scenario, GetScenario, ()); MOCK_METHOD(int32_t, GetSessionUserId, ()); MOCK_METHOD(std::string, GetSessionCallerName, ()); MOCK_METHOD(std::string, GetSessionActiveTime, ()); @@ -86,7 +86,7 @@ public: MOCK_METHOD(bool, GetSchedBundleName, (std::string&)); MOCK_METHOD(std::string, GetBackupExtName, (const std::string&)); MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName&)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName&)); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); MOCK_METHOD(bool, IsOnOnStartSched, ()); MOCK_METHOD(bool, NeedToUnloadService, ()); diff --git a/tests/mock/module_ipc/message_parcel_mock.h b/tests/mock/module_ipc/message_parcel_mock.h index 97984c231..d8b473a86 100644 --- a/tests/mock/module_ipc/message_parcel_mock.h +++ b/tests/mock/module_ipc/message_parcel_mock.h @@ -21,8 +21,8 @@ #include "message_parcel.h" #include "iremote_broker.h" -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" namespace OHOS::FileManagement::Backup { class BackupIfaceCast { diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 547ce2562..740e6b30c 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -35,39 +35,72 @@ void Service::OnStart() {} void Service::OnStop() {} -UniqueFd Service::GetLocalCapabilities() +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -void Service::StopAll(const wptr &obj, bool force) {} +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::GetLocalCapabilities(int &fd) { + fd = -1; return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -82,7 +115,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -92,14 +125,16 @@ ErrCode Service::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -118,7 +153,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -168,7 +203,7 @@ ErrCode Service::VerifyCaller() return BError(BError::Codes::OK); } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { return BError(BError::Codes::OK); } @@ -186,15 +221,15 @@ ErrCode Service::Release() return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode Service::GetAppLocalListAndDoIncrementalBackup() @@ -202,12 +237,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } @@ -218,7 +253,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) + const std::vector &infos) { return BError(BError::Codes::OK); } @@ -228,12 +263,15 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode Service::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } @@ -248,7 +286,7 @@ ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } @@ -273,17 +311,17 @@ ErrCode Service::RefreshDataSize(int64_t totalDatasize) return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -307,26 +345,40 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName return make_shared(bundleName); } -void Service::RemoveExtensionMutex(const BundleName &bundleName) -{ -} +void Service::RemoveExtensionMutex(const BundleName &bundleName) {} void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) {} + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ +} -void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -359,32 +411,32 @@ void Service::ClearFailedBundles() {} void Service::GetOldDeviceBackupVersion() {} -void Service::CreateDirIfNotExist(const std::string &path) -{ -} - -void Service::StartRunningTimer(const std::string &bundleName) {} +void Service::CreateDirIfNotExist(const std::string &path) {} -std::vector Service::GetSupportBackupBundleNames(vector&, bool, - const vector&) +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) { return {}; } -void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} +void Service::StartRunningTimer(const std::string &bundleName) {} -void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} +void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} + +void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, - ErrCode errCode) {} +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ +} void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } @@ -401,7 +453,7 @@ void Service::DeleteFromList(size_t scannedSize) {} void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} -void Service::SendScannedInfo(const string&scannendInfos, sptr session) {} +void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index ee7e924e0..c794edad3 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -13,64 +13,160 @@ * limitations under the License. */ -#include "module_ipc/service_reverse_proxy.h" +#include "service_reverse_proxy.h" #include "b_error/b_error.h" namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::BackupOnScanningInfo(std::string scannedInfo) {} - -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalBackupOnScanningInfo(std::string scannedInfo) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} +ErrCode ServiceReverseProxy::BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnResultReport(const std::string &result, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnScanningInfo(const std::string &scannedInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnProcessInfo(const std::string &bundleName, + const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnScanningInfo(const std::string &scannedInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnProcessInfo(const std::string &bundleName, + const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 8a3c066a8..07b4d4695 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -13,384 +13,523 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" -#include "module_ipc/service_reverse_proxy.h" - +#include "service_stub.h" namespace OHOS::FileManagement::Backup { using namespace std; -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - ServiceStubSupplement(); - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; -} - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - return BError(BError::Codes::OK); - } - - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::OK); - } - return (this->*(interfaceIndex->second))(data, reply); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int32_t res = InitRestoreSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int32_t res = InitRestoreSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int res = InitBackupSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int res = InitBackupSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - reply.WriteFileDescriptor(fd); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - int res = PublishFile(*fileInfo); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - data.ReadString(fileName); - UniqueFd fd(data.ReadFileDescriptor()); - int res = AppFileReady(fileName, move(fd), 0); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - data.ReadInt32(errCode); - int res = AppDone(errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - data.ReadString(restoreRetInfo); - int32_t scenario; - data.ReadInt32(scenario); - ErrCode errCode; - data.ReadInt32(errCode); - BackupRestoreScenario type = static_cast(scenario); - int res = ServiceResultReport(restoreRetInfo, type, errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - data.ReadString(bundleName); - string fileName; - data.ReadString(fileName); - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesRestoreSession(move(fd), bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - std::vector detailInfos; - data.ReadStringVector(&detailInfos); - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesBackupSession(bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) +int32_t ServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) { - int res = Finish(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - std::string result; - ret = GetBackupInfo(bundleName, result); - return ret; -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName"); + switch (static_cast(code)) { + case IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitRestoreSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START: { + ErrCode errCode = Start(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES: { + int fd; + ErrCode errCode = GetLocalCapabilities(fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < bundleNamesSize; ++i1) { + std::string value1 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value1); + } + std::vector detailInfos; + int32_t detailInfosSize = data.ReadInt32(); + if (detailInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i2 = 0; i2 < detailInfosSize; ++i2) { + std::string value2 = Str16ToStr8(data.ReadString16()); + detailInfos.push_back(value2); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = + AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_READY: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i3 = 0; i3 < bundleNamesSize; ++i3) { + std::string value3 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value3); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i4 = 0; i4 < bundleNamesSize; ++i4) { + std::string value4 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value4); + } + ErrCode errCode = AppendBundlesBackupSession(bundleNames); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i5 = 0; i5 < bundleNamesSize; ++i5) { + std::string value5 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value5); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i6 = 0; i6 < bundleInfosSize; ++i6) { + std::string value6 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value6); + } + ErrCode errCode = AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_FINISH: { + ErrCode errCode = Finish(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_RELEASE: { + ErrCode errCode = Release(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_CANCEL: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t cancelResult; + ErrCode errCode = Cancel(bundleName, cancelResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(cancelResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP: { + ErrCode errCode = GetAppLocalListAndDoIncrementalBackup(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetIncrementalFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_BACKUP_INFO: { + std::string bundleName; + std::string getBackupInfoResult; + ErrCode errCode = GetBackupInfo(bundleName, getBackupInfoResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteString16(Str8ToStr16(getBackupInfoResult))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_TIMER: { + std::string bundleName; + uint32_t timeout = data.ReadUint32(); + bool updateTimerResult; + ErrCode errCode = UpdateTimer(bundleName, timeout, updateTimerResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateTimerResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_SEND_RATE: { + std::string bundleName; + int32_t sendRate = data.ReadInt32(); + bool updateSendRateResult; + ErrCode errCode = UpdateSendRate(bundleName, sendRate, updateSendRateResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateSendRateResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_EXT_TIMER: { + bool isExtStart; + ErrCode errCode = StartExtTimer(isExtStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_FWK_TIMER: { + bool isFwkStart; + ErrCode errCode = StartFwkTimer(isFwkStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isFwkStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_STOP_EXT_TIMER: { + bool isExtStop; + ErrCode errCode = StopExtTimer(isExtStop); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStop ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i7 = 0; i7 < bundleNamesSize; ++i7) { + std::unique_ptr value7(data.ReadParcelable()); + if (!value7) { + return ERR_INVALID_DATA; + } + + bundleNames.push_back(*value7); + } + int fd; + ErrCode errCode = GetLocalCapabilitiesIncremental(bundleNames, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitIncrementalBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i8 = 0; i8 < bundlesToBackupSize; ++i8) { + std::unique_ptr value8(data.ReadParcelable()); + if (!value8) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value8); + } + ErrCode errCode = AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i9 = 0; i9 < bundlesToBackupSize; ++i9) { + std::unique_ptr value9(data.ReadParcelable()); + if (!value9) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value9); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i10 = 0; i10 < bundleInfosSize; ++i10) { + std::string value10 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value10); + } + ErrCode errCode = AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishIncrementalFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + int fd = data.ReadFileDescriptor(); + ErrCode errCode = PublishSAIncrementalFile(*fileInfo, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t appIncrementalFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalFileReady(fileName, fd, manifestFd, appIncrementalFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE: { + int32_t appIncrementalDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalDone(appIncrementalDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REPORT_APP_PROCESS_INFO: { + std::string processInfo = Str16ToStr8(data.ReadString16()); + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + ErrCode errCode = ReportAppProcessInfo(processInfo, scenario); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REFRESH_DATA_SIZE: { + int64_t totalDataSize = data.ReadInt64(); + ErrCode errCode = RefreshDataSize(totalDataSize); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_DONE: { + int32_t appDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppDone(appDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT: { + std::string restoreRetInfo; + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + int32_t serviceResultReportErrCode = data.ReadInt32(); + ErrCode errCode = ServiceResultReport(restoreRetInfo, scenario, serviceResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(restoreRetInfo))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t appFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppFileReady(fileName, fd, appFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ret = Cancel(bundleName, result); - reply.WriteInt32(result); - return ret; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); + return ERR_TRANSACTION_FAILED; } } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp index 2d46ff3ea..a28229fb3 100644 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -23,162 +23,251 @@ ServiceStub::ServiceStub() { } -void ServiceStub::ServiceStubSupplement() -{ -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - return BServiceStub::stub->OnRemoteRequest(code, data, reply, option); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitBackupSession(data, reply); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStart(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilities(data, reply); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishFile(data, reply); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppFileReady(data, reply); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppDone(data, reply); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdResultReport(data, reply); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetFileHandle(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesBackupSession(data, reply); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdFinish(data, reply); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupInfo(data, reply); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateTimer(data, reply); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateSendRate(data, reply); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRelease(data, reply); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdCancel(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesIncremental(data, reply); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetAppLocalListAndDoIncrementalBackup(data, reply); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishIncrementalFile(data, reply); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppIncrementalFileReady(data, reply); -} -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); +int32_t ServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { + int32_t backupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t backupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { + int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { + int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t restoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t restoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { + int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { + int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { + int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { + int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, + incrementalRestoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { + int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; } -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStopExtTimer(data, reply); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRefreshDataSize(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesForBdInfos(data, reply); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupDataSize(data, reply); -} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp index 6c8b88f42..017a8e9b4 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -21,7 +21,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t, IServiceReverse::Scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t, IServiceReverseType::Scenario) const { return BError(BError::Codes::OK); } @@ -46,7 +46,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return BSvcSessionManager::sessionManager->GetServiceReverseProxy(); } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { return BSvcSessionManager::sessionManager->GetScenario(); } @@ -132,7 +132,7 @@ void SvcSessionManager::SetBundleUserId(const string &bundleName, const int32_t void SvcSessionManager::AppendBundles(const vector &, vector &) {} -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BSvcSessionManager::sessionManager->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_backup_connection_mock.cpp b/tests/mock/module_ipc/svc_backup_connection_mock.cpp index 001f3dee2..061ded0a6 100644 --- a/tests/mock/module_ipc/svc_backup_connection_mock.cpp +++ b/tests/mock/module_ipc/svc_backup_connection_mock.cpp @@ -17,7 +17,7 @@ #include -#include "module_ipc/svc_extension_proxy.h" +#include "extension_proxy.h" #include "module_ipc/svc_session_manager.h" namespace OHOS::FileManagement::Backup { diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index a2534d899..d7eadf7dc 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -18,9 +18,9 @@ namespace OHOS::FileManagement::Backup { using namespace std; -UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName, int32_t &errCode) +ErrCode SvcExtensionProxy::GetFileHandleWithUniqueFd(const string &fileName, int32_t &errCode, int &fd) { - return UniqueFd(-1); + return 0; } ErrCode SvcExtensionProxy::HandleClear() @@ -48,9 +48,9 @@ ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) return 0; } -std::tuple SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) +ErrCode SvcExtensionProxy::GetIncrementalFileHandleWithUniqueFdGroup(const string &fileName, UniqueFdGroup &fdGroup) { - return {0, UniqueFd(-1), UniqueFd(-1)}; + return 0; } ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) @@ -58,7 +58,7 @@ ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) return 0; } -ErrCode SvcExtensionProxy::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +ErrCode SvcExtensionProxy::HandleIncrementalBackup(int incrementalFd, int manifestFd) { return 0; } @@ -78,8 +78,8 @@ ErrCode SvcExtensionProxy::User0OnBackup() return 0; } -tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() +ErrCode SvcExtensionProxy::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) { - return {UniqueFd(-1), UniqueFd(-1)}; + return 0; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 749be058a..61a2c2eb7 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -36,7 +36,7 @@ static int32_t g_nFileReadyNum = 0; static int32_t g_nAllBundlesFinished = 0; } // namespace -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { GTEST_LOG_(INFO) << "VerifyCallerAndScenario"; return BError(BError::Codes::OK); @@ -68,7 +68,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return impl_.clientProxy; } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { GTEST_LOG_(INFO) << "GetScenario"; return impl_.scenario; @@ -257,7 +257,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { GTEST_LOG_(INFO) << "CreateBackupConnection"; return GetBackupAbilityExt(bundleName); diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp index b7ac3a85e..fdec296b7 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp @@ -19,7 +19,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { return BackupSvcSessionManager::session->VerifyCallerAndScenario(clientToken, scenario); } @@ -44,7 +44,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return BackupSvcSessionManager::session->GetServiceReverseProxy(); } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { return BackupSvcSessionManager::session->GetScenario(); } @@ -155,7 +155,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec BackupSvcSessionManager::session->AppendBundles(bundleNames, failedBundles); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BackupSvcSessionManager::session->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.h b/tests/mock/module_ipc/svc_session_manager_throw_mock.h index 455274faa..effea3050 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.h +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.h @@ -27,12 +27,12 @@ class BackupSvcSessionManager { public: virtual ~BackupSvcSessionManager() = default; public: - virtual ErrCode VerifyCallerAndScenario(uint32_t, IServiceReverse::Scenario) = 0; + virtual ErrCode VerifyCallerAndScenario(uint32_t, IServiceReverseType::Scenario) = 0; virtual ErrCode Active(SvcSessionManager::Impl) = 0; virtual ErrCode Deactive(const wptr &, bool) = 0; virtual ErrCode VerifyBundleName(std::string &) = 0; virtual sptr GetServiceReverseProxy() = 0; - virtual IServiceReverse::Scenario GetScenario() = 0; + virtual IServiceReverseType::Scenario GetScenario() = 0; virtual bool OnBundleFileReady(const std::string &, const std::string &) = 0; virtual UniqueFd OnBundleExtManageInfo(const std::string &, UniqueFd) = 0; virtual void RemoveExtInfo(const std::string &) = 0; @@ -53,7 +53,7 @@ public: virtual void SetBackupExtName(const std::string &, const std::string &) = 0; virtual std::weak_ptr GetSAExtConnection(const BundleName &) = 0; virtual void AppendBundles(const std::vector &, std::vector &) = 0; - virtual sptr CreateBackupConnection(BundleName &) = 0; + virtual sptr CreateBackupConnection(const BundleName &) = 0; virtual ErrCode Start() = 0; virtual ErrCode Finish() = 0; virtual bool IsOnAllBundlesFinished() = 0; @@ -104,12 +104,12 @@ public: class SvcSessionManagerMock : public BackupSvcSessionManager { public: - MOCK_METHOD(ErrCode, VerifyCallerAndScenario, (uint32_t, IServiceReverse::Scenario)); + MOCK_METHOD(ErrCode, VerifyCallerAndScenario, (uint32_t, IServiceReverseType::Scenario)); MOCK_METHOD(ErrCode, Active, (SvcSessionManager::Impl)); MOCK_METHOD(ErrCode, Deactive, (const wptr &, bool)); MOCK_METHOD(ErrCode, VerifyBundleName, (std::string &)); MOCK_METHOD(sptr, GetServiceReverseProxy, ()); - MOCK_METHOD(IServiceReverse::Scenario, GetScenario, ()); + MOCK_METHOD(IServiceReverseType::Scenario, GetScenario, ()); MOCK_METHOD(bool, OnBundleFileReady, (const std::string &, const std::string &)); MOCK_METHOD(UniqueFd, OnBundleExtManageInfo, (const std::string &, UniqueFd)); MOCK_METHOD(void, RemoveExtInfo, (const std::string &)); @@ -130,7 +130,7 @@ public: MOCK_METHOD(void, SetBackupExtName, (const std::string &, const std::string &)); MOCK_METHOD(std::weak_ptr, GetSAExtConnection, (const BundleName &)); MOCK_METHOD(void, AppendBundles, (const std::vector &, std::vector &)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName &)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName &)); MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, Finish, ()); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index c3fc260ee..8d19f9adc 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -25,21 +25,22 @@ ohos_unittest("b_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_session_backup_test.cpp", "b_session_restore_async_test.cpp", "b_session_restore_test.cpp", ] sources += backup_mock_proxy_src - include_dirs = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner/", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/frameworks/native/backup_kit_inner/include", ] + include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", ] diff --git a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp index a4a5583f2..0afa8e568 100644 --- a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp @@ -16,7 +16,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "backup_kit_inner.h" #include "unique_fd.h" #include "utils_mock_global_variable.h" diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index aa3f5a3ed..66539a9ea 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -20,7 +20,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_session_restore_async.h" #include "backup_kit_inner.h" #include "unique_fd.h" diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp index 0c2b9b32c..6c5ff1b3c 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -17,7 +17,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "backup_kit_inner.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 1ef532c62..08046348f 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -53,8 +53,6 @@ ohos_unittest("backup_sa_impl_test") { sources = [ "${path_backup_mock}/system_ability_manager/service_registry_mock.cpp", "${path_backup_mock}/utils_mock/src/utils_mock_global_variable.cpp", - "service_proxy_test.cpp", - "service_reverse_stub_test.cpp", "service_reverse_test.cpp", "svc_death_recipient_test.cpp", ] diff --git a/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp b/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp index 283508801..c8ab0443d 100644 --- a/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp +++ b/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp @@ -15,7 +15,7 @@ #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "parcel.h" namespace OHOS::FileManagement::Backup { 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 3399bc312..778d91488 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 @@ -20,9 +20,9 @@ #include #include #include - +#include "unique_fd.h" #include "b_error/b_error.h" -#include "i_extension.h" +#include "iextension.h" #include "iremote_stub.h" #include "test_manager.h" @@ -51,9 +51,16 @@ public: reply.WriteInt32(0); reply.WriteFileDescriptor(fd); return BError(BError::Codes::OK); - } + }; + + ErrCode GetFileHandleWithUniqueFd(const std::string &fileName, int32_t &getFileHandleErrCode, int &fd) override + { + UniqueFd f = GetFileHandle(fileName, getFileHandleErrCode); + fd = f.Get(); + return getFileHandleErrCode; + }; - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override + UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) { GTEST_LOG_(INFO) << "GetFileHandle" << fileName; if (fileName == "testName") { @@ -104,7 +111,11 @@ public: return BError(BError::Codes::OK); }; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override + ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) override + { + return BError(BError::Codes::OK); + } + std::tuple GetIncrementalFileHandle(const std::string &fileName) { return {BError(BError::Codes::OK), UniqueFd(-1), UniqueFd(-1)}; }; @@ -114,7 +125,11 @@ public: return BError(BError::Codes::OK); }; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override + ErrCode HandleIncrementalBackup (int incrementalFd, int manifestFd) override + { + return BError(BError::Codes::OK); + }; + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) { return BError(BError::Codes::OK); }; @@ -124,7 +139,12 @@ public: return BError(BError::Codes::OK); }; - std::tuple GetIncrementalBackupFileHandle() override + ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) override + { + return BError(BError::Codes::OK); + }; + + std::tuple GetIncrementalBackupFileHandle() { return {UniqueFd(-1), UniqueFd(-1)}; }; @@ -134,7 +154,7 @@ public: return BError(BError::Codes::OK); }; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override + ErrCode UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) override { return BError(BError::Codes::OK); }; diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index d5371dae2..a3890ba0a 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -16,17 +16,17 @@ #ifndef MOCK_I_SERVICE_MOCK_H #define MOCK_I_SERVICE_MOCK_H -#include -#include -#include -#include - #include "b_error/b_error.h" -#include "i_service.h" #include "b_resources/b_constants.h" #include "iremote_stub.h" +#include "service_client.h" +#include "service_common.h" #include "test_manager.h" - +#include "unique_fd.h" +#include +#include +#include +#include namespace OHOS::FileManagement::Backup { class IServiceMock : public IRemoteStub { public: @@ -62,22 +62,22 @@ public: return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr remote) override + ErrCode InitRestoreSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override + ErrCode InitRestoreSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr remote) override + ErrCode InitBackupSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override + ErrCode InitBackupSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } @@ -87,33 +87,37 @@ public: return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() override + ErrCode GetLocalCapabilities(int &fd) { - return UniqueFd(-1); + return -1; } - UniqueFd GetLocalCapabilitiesForBundleInfos() override + ErrCode GetLocalCapabilitiesForBundleInfos(int &fd) override { - return UniqueFd(-1); + return -1; + } + + ErrCode PublishFile(const BFileInfo &fileInfo) + { + return BError(BError::Codes::OK); } - ErrCode PublishFile(const BFileInfo &fileInfo) override + ErrCode GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode errCode) override + ErrCode AppDone(ErrCode errCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override + ErrCode ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); } @@ -127,7 +131,7 @@ public: const std::vector &bundleNames, const std::vector &detailInfos, RestoreTypeEnum restoreType, - int32_t userId) override + int32_t userId) { return BError(BError::Codes::OK); } @@ -135,18 +139,18 @@ public: ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, - int32_t userId) override + int32_t userId) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override + ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) { return BError(BError::Codes::OK); } ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) override + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -181,7 +185,7 @@ public: return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t totalsize) override + ErrCode RefreshDataSize(int64_t totalsize) { return BError(BError::Codes::OK); } @@ -196,15 +200,15 @@ public: return BError(BError::Codes::OK); } - ErrCode Cancel(std::string bundleName, int32_t &result) override + ErrCode Cancel(const std::string &, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override + ErrCode GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode GetAppLocalListAndDoIncrementalBackup() override @@ -212,38 +216,38 @@ public: return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr remote) override + ErrCode InitIncrementalBackupSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override + ErrCode InitIncrementalBackupSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override + ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override + const std::vector &infos) { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override + ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) + ErrCode AppIncrementalFileReady(const std::string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -258,12 +262,35 @@ public: return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) + ErrCode ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index cd066641e..91ca1af35 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -19,8 +19,8 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" #include "iremote_stub.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { class ServiceReverseMock : public IRemoteStub { @@ -36,37 +36,152 @@ public: code_ = code; return BError(BError::Codes::OK); } - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void BackupOnResultReport(std::string result, std::string bundleName) override {}; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void BackupOnAllBundlesFinished(int32_t errCode) override {} - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} - void BackupOnScanningInfo(std::string scannedInfo) override {} - - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void RestoreOnAllBundlesFinished(int32_t errCode) override {} - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void RestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {} - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} - - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override {} - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override {} - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override {} - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override {} - - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override {} - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override {} - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {}; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} + + ErrCode BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + }; + + ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnScanningInfo(const std::string &scannedInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnScanningInfo(const std::string &scannedInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } }; } // namespace OHOS::FileManagement::Backup #endif // MOCK_SERVICE_REVERSE_MOCK_H \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp deleted file mode 100644 index ee2de7234..000000000 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ /dev/null @@ -1,1444 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "b_file_info.h" -#include "i_service_mock.h" -#include "iremote_object_mock.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "service_reverse_mock.h" -#include "unique_fd.h" -#include "utils_mock_global_variable.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -constexpr int32_t SERVICE_ID = 5203; -} // namespace - -class ServiceProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override; - void TearDown() override; - - shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; - sptr remote_ = nullptr; -}; - -void ServiceProxyTest::SetUp() -{ - mock_ = sptr(new IServiceMock()); - proxy_ = make_shared(mock_); - remote_ = sptr(new ServiceReverseMock()); -} - -void ServiceProxyTest::TearDown() -{ - proxy_ = nullptr; - mock_ = nullptr; - remote_ = nullptr; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.desc: 测试 InitRestoreSession 注册restore Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.desc: 测试 InitRestoreSession 注册restore Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitBackupSession_0100 - * @tc.desc: 测试 InitBackupSession 注册backup Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitBackupSession_0200 - * @tc.desc: 测试 InitBackupSession 注册backup Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Start_0100 - * @tc.name: SUB_Service_proxy_Start_0100 - * @tc.desc: 测试 Start 启动备份恢复流程接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Start_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Start_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Start_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->Start(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->Start(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Start_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.desc: 测试 GetLocalCapabilities 获取能力文件接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilities_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilities_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - UniqueFd fd = proxy_->GetLocalCapabilities(); - EXPECT_GT(fd, BError(BError::Codes::OK)); - UniqueFd fdErr = proxy_->GetLocalCapabilities(); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilities_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishFile_0100 - * @tc.name: SUB_Service_proxy_PublishFile_0100 - * @tc.desc: 测试 PublishFile 推送接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->PublishFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppFileReady_0100 - * @tc.name: SUB_Service_proxy_AppFileReady_0100 - * @tc.desc: 测试 AppFileReady 文件就绪调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(3) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppFileReady(bundleName, move(fd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppFileReady(bundleName, move(fdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppFileReady(bundleName, UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppDone_0100 - * @tc.name: SUB_Service_proxy_AppDone_0100 - * @tc.desc: 测试 AppDone ext备份恢复流程结束调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.name: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.desc: 测试 ServiceResultReport - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ServiceResultReport_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ServiceResultReport_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ServiceResultReport_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string restoreRetInfo = "test_restoreRetInfo"; - BackupRestoreScenario scenario = FULL_BACKUP; - int32_t result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ServiceResultReport_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetFileHandle_0100 - * @tc.desc: 测试 GetFileHandle 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - std::vector detailInfos; - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0200 proxy_ == nullptr"; - return; - } - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.desc: 测试 AppendBundlesBackupSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - - int32_t result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.desc: 测试 AppendBundlesDetailsBackupSession - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector detailInfos; - - int32_t result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Finish_0100 - * @tc.name: SUB_Service_proxy_Finish_0100 - * @tc.desc: 测试 Finish 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Finish_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Finish_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Finish_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Finish(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Finish(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Finish_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Release_0100 - * @tc.name: SUB_Service_proxy_Release_0100 - * @tc.desc: 测试 Release 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Release_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Release_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Release_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Release(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Release(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Release_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.desc: 测试 GetLocalCapabilitiesIncremental 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - BIncrementalData data("com.example.app2backup", 0); - bundleNames.push_back(data); - UniqueFd fd = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_GT(fd, BError(BError::Codes::OK)); - - UniqueFd fdErr = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.desc: 测试 InitIncrementalBackupSession with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector infos; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.desc: 测试 PublishIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - fileName = "test"; - result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fd)); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fdErr)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0200 proxy_ == nullptr"; - return; - } - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - - ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, move(fd), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFdErr( - open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppIncrementalFileReady(bundleName, move(fdErr), move(manifestFdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Return(0)) - .WillOnce(Return(0)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_0200"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, move(fd), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0300"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0300 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0300"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.desc: 测试 AppIncrementalDone 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.desc: 测试 GetIncrementalFileHandle 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetIncrementalFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetIncrementalFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.desc: 测试 OnLoadSystemAbilityFail 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilityFail_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilityFail_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilityFail(SERVICE_ID); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetInstance_0100 - * @tc.name: SUB_Service_proxy_GetInstance_0100 - * @tc.desc: 测试 GetInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetInstance_0100 proxy_ == nullptr"; - return; - } - GTEST_LOG_(INFO) << "MockLoadSystemAbility is false"; - SetMockLoadSystemAbility(false); - auto proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "MockLoadSystemAbility is true"; - SetMockLoadSystemAbility(true); - proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - sptr object = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, object); - GTEST_LOG_(INFO) << "GetInstance is ok"; - proxy = ServiceProxy::GetInstance(); - EXPECT_NE(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InvaildInstance_0100 - * @tc.name: SUB_Service_proxy_InvaildInstance_0100 - * @tc.desc: 测试 InvaildInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InvaildInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InvaildInstance_0100 proxy_ == nullptr"; - return; - } - ServiceProxy::InvaildInstance(); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.name: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.desc: 测试 GetBackupInfo 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetBackupInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string result; - std::string bundleName = "com.example.app2backup"; - int32_t ret = proxy_->GetBackupInfo(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateTimer_0100 - * @tc.name: SUB_Service_proxy_UpdateTimer_0100 - * @tc.desc: 测试 UpdateTimer 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - uint32_t timeout = 30000; - int32_t ret = proxy_->UpdateTimer(bundleName, timeout, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.name: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.desc: 测试 UpdateSendRate 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateSendRate_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateSendRate_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - int32_t sendRate = 300; - int32_t ret = proxy_->UpdateSendRate(bundleName, sendRate, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.name: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.desc: 测试 ReportAppProcessInfo 接口成功 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.desc: 测试 ReportAppProcessInfo 接口失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_StartExtTimer_0100 - * @tc.name: SUB_Service_proxy_StartExtTimer_0100 - * @tc.desc: 测试 StartExtTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartExtTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartExtTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartExtTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isExtStart; - int32_t ret = proxy_->StartExtTimer(isExtStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartExtTimer(isExtStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartExtTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.name: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.desc: 测试 StartFwkTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartFwkTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartFwkTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartFwkTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isFwkStart; - int32_t ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartFwkTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Cancel_0100 - * @tc.name: SUB_Service_proxy_Cancel_0100 - * @tc.desc: 测试 Cancel 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Cancel_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Cancel_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Cancel_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string bundleName; - int result; - ErrCode ret = proxy_->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->Cancel(bundleName, result); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Cancel_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp deleted file mode 100644 index 7c2284f6b..000000000 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ /dev/null @@ -1,889 +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 -#include -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "service_reverse_stub.h" -#include "test_manager.h" -#include "unique_fd.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -const string FILE_NAME_MANIFEST = "1.fr"; -} // namespace - -class MockServiceReverse final : public ServiceReverseStub { -public: - MOCK_METHOD4(BackupOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD2(BackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(BackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(BackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(BackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(BackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_METHOD1(BackupOnScanningInfo, void(std::string scannedInfo)); - - MOCK_METHOD2(RestoreOnBundleStarted, void(int32_t errCode, std::string bundleName)); - MOCK_METHOD2(RestoreOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(RestoreOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD4(RestoreOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD3(RestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(RestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); - - MOCK_METHOD5(IncrementalBackupOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(IncrementalBackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(IncrementalBackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(IncrementalBackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_METHOD1(IncrementalBackupOnScanningInfo, void(std::string scannedInfo)); - - MOCK_METHOD2(IncrementalRestoreOnBundleStarted, void(int32_t errCode, std::string bundleName)); - MOCK_METHOD2(IncrementalRestoreOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(IncrementalRestoreOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD5(IncrementalRestoreOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD3(IncrementalRestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(IncrementalRestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); -}; - -class ServiceReverseStubTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override {}; - void TearDown() override {}; -}; - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnFileReady_0100 - * @tc.desc: Test function of BackupOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_BackupOnFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnFileReady(_, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0100"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - data.WriteInt32(0); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100 - * @tc.desc: Test function of BackupOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnBundleStarted."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnResultReport_0100 - * @tc.desc: Test function of BackupOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnResultReport(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnResultReport."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100 - * @tc.desc: Test function of BackupOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnBundleFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100 - * @tc.desc: Test function of BackupOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100 - * @tc.desc: Test function of RestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnBundleStarted."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100 - * @tc.desc: Test function of RestoreOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnBundleFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100 - * @tc.desc: Test function of RestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100 - * @tc.desc: Test function of RestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t errCode = 0; - bool fdFlag = true; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - - TestManager tm("ServiceReverseStub_0200"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - if (fd < 0) { - errCode = BError::GetCodeByErrno(errno); - fdFlag = false; - } - data.WriteBool(fdFlag); - if (fdFlag == true) { - data.WriteFileDescriptor(fd); - } - data.WriteInt32(errCode); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_error_0100 - * @tc.name: SUB_backup_ServiceReverseStub_error_0100 - * @tc.desc: Test function of RestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_error_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_error_0100"; - try { - MockServiceReverse service; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_TRUE(data.WriteInterfaceToken(Str8ToStr16("test"))); - - EXPECT_NE(BError(BError::Codes::OK), service.OnRemoteRequest(3333, data, reply, option)); - EXPECT_NE( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_error_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100 - * @tc.desc: Test function of IncrementalBackupOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0300"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - TestManager tm2("ServiceReverseStub_0301"); - string filePathManifest = tm2.GetRootDirCurTest().append(FILE_NAME_MANIFEST); - UniqueFd fdManifest(open(filePathManifest.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fdManifest); - data.WriteInt32(0); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100 - * @tc.desc: Test function of IncrementalBackupOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnBundleStarted."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100 - * @tc.desc: Test function of IncrementalBackupOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100 - * @tc.desc: Test function of IncrementalBackupOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnBundleFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100 - * @tc.desc: Test function of IncrementalBackupOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ - -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100 - * @tc.desc: Test function of IncrementalRestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnBundleStarted."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100 - * @tc.desc: Test function of IncrementalRestoreOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnBundleFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100 - * @tc.desc: Test function of IncrementalRestoreOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100 - * @tc.desc: Test function of IncrementalRestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0400"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - TestManager tm2("ServiceReverseStub_0401"); - string filePathManifest = tm2.GetRootDirCurTest().append(FILE_NAME_MANIFEST); - UniqueFd fdManifest(open(filePathManifest.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fdManifest); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 - * @tc.desc: Test function of RestoreOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnResultReport(_, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::string resultReport = "result_report"; - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(resultReport)); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteInt32(0)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100 - * @tc.desc: Test function of IncrementalRestoreOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::string resultReport = "result_report"; - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(resultReport)); - EXPECT_TRUE(data.WriteInt32(0)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 98bccfac2..05e4d6c77 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -45,8 +45,8 @@ public: void SetUp() override {}; void TearDown() override; - void Init(IServiceReverse::Scenario scenario, int nType = 0); - void IncrementalInit(IServiceReverse::Scenario scenario, int nType = 0); + void Init(IServiceReverseType::Scenario scenario, int nType = 0); + void IncrementalInit(IServiceReverseType::Scenario scenario, int nType = 0); sptr service_ = nullptr; }; @@ -89,9 +89,9 @@ void ServiceReverseTest::TearDown() service_ = nullptr; } -void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) +void ServiceReverseTest::Init(IServiceReverseType::Scenario scenario, int nType) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { if (nType) { service_ = new ServiceReverse(BSessionBackup::Callbacks {.onFileReady = nullptr, .onBundleStarted = nullptr, @@ -128,9 +128,9 @@ void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) } } -void ServiceReverseTest::IncrementalInit(IServiceReverse::Scenario scenario, int nType) +void ServiceReverseTest::IncrementalInit(IServiceReverseType::Scenario scenario, int nType) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { if (nType) { service_ = new ServiceReverse(BIncrementalBackupSession::Callbacks {.onFileReady = nullptr, .onBundleStarted = nullptr, @@ -179,7 +179,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0100, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0100 service_ == nullptr"; @@ -207,7 +207,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0101, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0101 service_ == nullptr"; @@ -234,7 +234,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0102, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0102 service_ == nullptr"; @@ -261,7 +261,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 service_ == nullptr"; @@ -289,7 +289,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0101 service_ == nullptr"; @@ -316,7 +316,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0102 service_ == nullptr"; @@ -343,7 +343,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0100 service_ == nullptr"; @@ -371,7 +371,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0101 service_ == nullptr"; @@ -398,7 +398,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0102 service_ == nullptr"; @@ -425,7 +425,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100 service_ == nullptr"; @@ -453,7 +453,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101 service_ == nullptr"; @@ -480,7 +480,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102 service_ == nullptr"; @@ -507,7 +507,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0100, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0100 service_ == nullptr"; @@ -535,7 +535,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0101, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0101 service_ == nullptr"; @@ -562,7 +562,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0102, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0102 service_ == nullptr"; @@ -589,7 +589,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 service_ == nullptr"; @@ -617,7 +617,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101 service_ == nullptr"; @@ -644,7 +644,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102 service_ == nullptr"; @@ -671,7 +671,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100 service_ == nullptr"; @@ -699,7 +699,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101 service_ == nullptr"; @@ -726,7 +726,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102 service_ == nullptr"; @@ -753,7 +753,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100 service_ == nullptr"; @@ -781,7 +781,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101 service_ == nullptr"; @@ -808,7 +808,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102 service_ == nullptr"; @@ -835,7 +835,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0100, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0100 service_ == nullptr"; @@ -865,7 +865,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0101, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0101 service_ == nullptr"; @@ -894,7 +894,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0102, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0102 service_ == nullptr"; @@ -923,7 +923,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0200, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0200"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0200 service_ == nullptr"; @@ -953,7 +953,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0201, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0201"; try { - Init(IServiceReverse::Scenario::RESTORE, 0); + Init(IServiceReverseType::Scenario::RESTORE, 0); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0201 service_ == nullptr"; @@ -983,7 +983,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0300, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0300"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0300 service_ == nullptr"; @@ -1013,7 +1013,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0301, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0301"; try { - Init(IServiceReverse::Scenario::BACKUP, 0); + Init(IServiceReverseType::Scenario::BACKUP, 0); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0301 service_ == nullptr"; @@ -1043,7 +1043,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100 service_ == nullptr"; @@ -1071,7 +1071,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101 service_ == nullptr"; @@ -1079,7 +1079,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe } service_->IncrementalBackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); } catch (...) { EXPECT_TRUE(false); @@ -1103,7 +1103,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100 service_ == nullptr"; @@ -1133,7 +1133,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0101 service_ == nullptr"; @@ -1141,7 +1141,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1165,7 +1165,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0100 service_ == nullptr"; @@ -1195,7 +1195,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0101 service_ == nullptr"; @@ -1203,7 +1203,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1227,7 +1227,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0100 service_ == nullptr"; @@ -1257,7 +1257,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0101 service_ == nullptr"; @@ -1265,7 +1265,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnAllBundlesFinished(BError(BError::Codes::OK)); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -1289,7 +1289,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0100 service_ == nullptr"; @@ -1319,7 +1319,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0101 service_ == nullptr"; @@ -1327,7 +1327,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); } catch (...) { EXPECT_TRUE(false); @@ -1351,7 +1351,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100 service_ == nullptr"; @@ -1381,7 +1381,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0101 service_ == nullptr"; @@ -1389,7 +1389,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1413,7 +1413,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0100 service_ == nullptr"; @@ -1443,7 +1443,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0101 service_ == nullptr"; @@ -1451,7 +1451,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1476,7 +1476,7 @@ HWTEST_F(ServiceReverseTest, GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0100 service_ == nullptr"; @@ -1507,7 +1507,7 @@ HWTEST_F(ServiceReverseTest, GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0101 service_ == nullptr"; @@ -1515,7 +1515,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnAllBundlesFinished(BError(BError::Codes::OK)); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -1537,7 +1537,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnResultReport_0100 service_ == nullptr"; return; @@ -1565,7 +1565,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0101"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnResultReport_0101 service_ == nullptr"; return; @@ -1594,14 +1594,14 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalRestoreOnResul { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0100 service_ == nullptr"; return; } std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; - service_->IncrementalRestoreOnResultReport(resultReport, bundleName); + service_->IncrementalRestoreOnResultReport(resultReport, bundleName, 0); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by IncrementalRestoreOnResultReport."; @@ -1623,14 +1623,14 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalRestoreOnResul { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0101 service_ == nullptr"; return; } std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; - service_->IncrementalRestoreOnResultReport(resultReport, bundleName); + service_->IncrementalRestoreOnResultReport(resultReport, bundleName, 0); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by IncrementalRestoreOnResultReport."; @@ -1651,7 +1651,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnResultReport_0100 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnResultReport_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1679,7 +1679,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnResultReport_0101 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnResultReport_0101"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1708,7 +1708,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnResult { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnResultReport_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1737,7 +1737,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnResult { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnResultReport_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index aa8aa1317..7ff525e0a 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -25,11 +25,7 @@ ohos_unittest("ext_extension_test") { module_out_path = path_module_out_tests - sources = [ - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", - "ext_extension_test.cpp", - ] + sources = [ "ext_extension_test.cpp" ] include_dirs = [ "${path_backup}/frameworks/native/backup_ext/include", @@ -41,6 +37,7 @@ ohos_unittest("ext_extension_test") { ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", "//third_party/googletest:gtest_main", @@ -78,49 +75,6 @@ ohos_unittest("ext_extension_test") { use_exceptions = true } -ohos_unittest("ext_extension_stub_test") { - module_out_path = path_module_out_tests - - sources = [ - "${path_backup_mock}/module_ipc/message_parcel_mock.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", - "ext_extension_stub_test.cpp", - ] - - include_dirs = [ - "${path_backup_mock}/module_ipc", - "${path_backup}/frameworks/native/backup_ext/include", - "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/interfaces/common/include", - "${path_backup}/utils/include", - ] - - deps = [ - "${path_backup}/utils:backup_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] - - cflags = [ "--coverage" ] - ldflags = [ "--coverage" ] - cflags_cc = [ "--coverage" ] - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD004303", - "private=public", - ] - - use_exceptions = true -} - ohos_unittest("tar_file_test") { branch_protector_ret = "pac_ret" sanitize = { @@ -139,7 +93,6 @@ ohos_unittest("tar_file_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", @@ -214,7 +167,6 @@ ohos_unittest("untar_file_sup_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/tests/mock/library_func_mock/library_func_mock.cpp", @@ -290,7 +242,6 @@ ohos_unittest("untar_file_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", @@ -367,6 +318,7 @@ ohos_unittest("ext_backup_js_test") { ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", "${path_googletest}:gtest_main", @@ -403,6 +355,13 @@ ohos_unittest("ext_backup_js_test") { "private=public", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + use_exceptions = true } @@ -445,7 +404,6 @@ group("backup_ext_test") { if (!use_libfuzzer) { deps = [ ":ext_backup_js_test", - ":ext_extension_stub_test", ":ext_extension_test", ":tar_file_sub_test", ":tar_file_test", diff --git a/tests/unittests/backup_ext/ext_extension_stub_test.cpp b/tests/unittests/backup_ext/ext_extension_stub_test.cpp deleted file mode 100644 index 6e07ddd4d..000000000 --- a/tests/unittests/backup_ext/ext_extension_stub_test.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "b_error/b_error.h" -#include "ext_extension_stub.h" -#include "message_parcel_mock.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -class ExtExtensionStubMock : public ExtExtensionStub { -public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const std::string &fileName, int32_t &errCode)); - MOCK_METHOD(ErrCode, HandleClear, ()); - MOCK_METHOD(ErrCode, HandleBackup, (bool isClearData)); - MOCK_METHOD(ErrCode, PublishFile, (const std::string &fileName)); - MOCK_METHOD(ErrCode, HandleRestore, (bool isClearData)); - MOCK_METHOD((std::tuple), GetIncrementalFileHandle, (const std::string &fileName)); - MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &fileName)); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd incrementalFd, UniqueFd manifestFd)); - MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool isClearData)); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); - MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &result)); - MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string &bundleName, int32_t sendRate)); - MOCK_METHOD(ErrCode, User0OnBackup, ()); -}; - -class ExtExtensionStubTest : public testing::Test { -public: - //所有测试用例执行之前执行 - static void SetUpTestCase(void); - //所有测试用例执行之后执行 - static void TearDownTestCase(void); - //每次测试用例执行之前执行 - void SetUp() {}; - //每次测试用例执行之后执行 - void TearDown() {}; -public: - static inline shared_ptr stub = nullptr; - static inline shared_ptr messageParcelMock = nullptr; -}; - -void ExtExtensionStubTest::SetUpTestCase() -{ - stub = make_shared(); - messageParcelMock = make_shared(); - MessageParcelMock::messageParcel = messageParcelMock; -} - -void ExtExtensionStubTest::TearDownTestCase() -{ - stub = nullptr; - MessageParcelMock::messageParcel = nullptr; - messageParcelMock = nullptr; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100 - * @tc.desc: 测试 OnRemoteRequest 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100"; - try { - ASSERT_TRUE(stub != nullptr); - uint32_t code = 0; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(u16string())); - auto err = stub->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - const std::u16string descriptor = ExtExtensionStub::GetDescriptor(); - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(descriptor)); - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - err = stub->OnRemoteRequest(static_cast(IExtensionInterfaceCode::CMD_GET_FILE_HANDLE), - data, reply, option); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(descriptor)); - auto ret = stub->OnRemoteRequest(-1, data, reply, option); - EXPECT_EQ(ret, IPC_STUB_UNKNOW_TRANS_ERR); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by OnRemoteRequest."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100 - * @tc.desc: 测试 CmdGetFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(-1))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(0))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(false)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(0))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetFileHandle."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100 - * @tc.desc: 测试 CmdHandleClear 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, HandleClear()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleClear(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, HandleClear()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleClear(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleClear."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100 - * @tc.desc: 测试 CmdHandleBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100 - * @tc.desc: 测试 CmdPublishFile 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdPublishFile."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100 - * @tc.desc: 测试 CmdHandleRestore 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleRestore(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleRestore(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleRestore(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleRestore(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleRestore."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100 - * @tc.desc: 测试 CmdGetIncrementalFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetIncrementalFileHandle."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100 - * @tc.desc: 测试 CmdPublishIncrementalFile 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishIncrementalFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishIncrementalFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdPublishIncrementalFile."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100 - * @tc.desc: 测试 CmdHandleIncrementalBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadFileDescriptor()).WillOnce(Return(0)).WillOnce(Return(0)); - EXPECT_CALL(*stub, HandleIncrementalBackup(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleIncrementalBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadFileDescriptor()).WillOnce(Return(0)).WillOnce(Return(0)); - EXPECT_CALL(*stub, HandleIncrementalBackup(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleIncrementalBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleIncrementalBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100 - * @tc.desc: 测试 CmdIncrementalOnBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, IncrementalOnBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdIncrementalOnBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, IncrementalOnBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdIncrementalOnBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdIncrementalOnBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100 - * @tc.desc: 测试 CmdGetIncrementalBackupFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << - "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(false)); - auto err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(false)); - err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetIncrementalBackupFileHandle."; - } - GTEST_LOG_(INFO) << - "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100 - * @tc.desc: 测试 CmdGetBackupInfo 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(false)); - err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); - err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetBackupInfo."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 - * @tc.desc: 测试 CmdUpdateSendRate 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(false)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdUpdateSendRate."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdUser0_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdUser0_0100 - * @tc.desc: 测试 CmdHandleUser0Backup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issues - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdUser0_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdUser0_0100"; - try { - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, User0OnBackup()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - EXPECT_TRUE(stub != nullptr); - auto err = stub->CmdHandleUser0Backup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, User0OnBackup()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleUser0Backup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleClear."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdUser0_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/BUILD.gn b/tests/unittests/backup_sa/BUILD.gn index 5351c84bd..b552944b3 100644 --- a/tests/unittests/backup_sa/BUILD.gn +++ b/tests/unittests/backup_sa/BUILD.gn @@ -19,6 +19,7 @@ group("backup_sa_test") { deps = [ "module_app_gallery:app_gallery_test", + "module_client:service_client_test", "module_external:adapter_test", "module_ipc:backup_sa_ipc_test", "session:session_test", diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn new file mode 100644 index 000000000..9ff89a21a --- /dev/null +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -0,0 +1,87 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") + +ohos_unittest("service_client_test") { + module_out_path = path_module_out_tests + + include_dirs = [ + "${path_backup}/frameworks/native/backup_kit_inner/include", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_notify", + "${path_backup}/utils/include", + "${path_backup}/utils/src", + "${path_backup}/tests/mock/utils_mock/include", + ".", + ] + + sources = [ + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", + "service_client_test.cpp", + ] + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", + "${path_backup}/utils:backup_utils", + ] + + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + defines = [ + "LOG_TAG=\"app_file_service\"", + "LOG_DOMAIN=0xD200000", + "private = public", + "protected = public", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_connect_callback_stub", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] + + use_exceptions = true +} + +group("backup_sa_service_client_test") { + testonly = true + deps = [ ":service_client_test" ] +} diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp new file mode 100644 index 000000000..9352d63b6 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "b_error/b_error.h" +#include "service_client.h" +#include "service_reverse.h" +#include "b_session_restore.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +using namespace testing; + +class ServiceClientTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp() override {}; + void TearDown() override {}; + +public: + static inline sptr proxy = nullptr; +}; + +void ServiceClientTest::SetUpTestCase() +{ + GTEST_LOG_(INFO) << "begin SetUpTestCase"; + proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + GTEST_LOG_(INFO) << "Failed to get ServiceClient instance"; + } +} + +void ServiceClientTest::TearDownTestCase() +{ + if (proxy != nullptr) { + ServiceClient::InvaildInstance(); + proxy = nullptr; + } + ServiceClient::InvaildInstance(); +} + +/** + * @tc.number: SUB_service_client_test_0100 + * @tc.name: SUB_service_client_test_0100 + * @tc.desc: 测试 InitIncrementalBackupSession 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9KPRL + */ +HWTEST_F(ServiceClientTest, SUB_service_client_test_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0100"; + EXPECT_NE(proxy, nullptr); + ServiceClient::InvaildInstance(); + proxy=ServiceClient::serviceProxy_; + EXPECT_EQ(proxy, nullptr); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode ret = proxy->Start(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Finish(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Release(); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->GetAppLocalListAndDoIncrementalBackup(); + EXPECT_NE(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + int32_t result = -1; + ErrCode ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = ""; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = "test"; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + EXPECT_NE(result, 0); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0400"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0400"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0500"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0500"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0600"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = -1; + ErrCode ret = proxy->GetLocalCapabilities(fd); + EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_NE(fd, BError(BError::Codes::OK)); + fd = -2; + ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); + EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_NE(fd, 1); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0700"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + ErrCode ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + fileName = "test"; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0700"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0800"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + bool booleanValue = false; + ErrCode ret = proxy->GetBackupInfo(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_BEF)); + EXPECT_EQ(bundleName, ""); + EXPECT_EQ(fileName, ""); + booleanValue = true; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret,BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bool isExt = true; + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = "test"; + ret = proxy->UpdateTimer(bundleName, 10, isExt); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(isExt, false); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + bundleName = "test"; + ret = proxy->UpdateSendRate(bundleName, 10, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = "name"; + ret = proxy->AppFileReady(fileName, -1, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = "test"; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0900"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string stringVal = ""; + ErrCode ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = "test"; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + int64_t val = -1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + val = 1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize.Level1) +{ + std::string bundleName = ""; + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1000"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + BFileInfo *fileInfo = nullptr; + BFileInfo bf {bundleName, "", 0}; + ErrCode ret = proxy->PublishFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishIncrementalFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); + EXPECT_NE(ret, BError(BError::Codes::OK)); + fileInfo = &bf; + ret = proxy->PublishFile(*fileInfo); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->PublishIncrementalFile(*fileInfo); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1100"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = 0; + int32_t restoreType = -1; + int32_t userid = -1; + std::vector bundleNames; + std::vector detailInfos; + std::vector bundlesToBackup; + ErrCode ret = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleNames.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + detailInfos.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + restoreType = 1; + userid = 1; + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + sptr srptr = nullptr; + ErrCode ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + std::string errMsg = ""; + std::string result = "err"; + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + BSessionRestore::Callbacks callback; + srptr = sptr(new ServiceReverse(callback)); + ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file 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..28ba6a6f6 --- /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::AppendBundlesRestoreSessionRestoreDataWaitSend(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::AppendBundlesRestoreSessionRestoreDataWaitReady(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) +{ + 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) +{ + bundleName = "name"; + 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/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 6685f522e..4bceea4fd 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -22,19 +22,12 @@ ohos_unittest("module_ipc_test") { sources = [ "${path_backup_mock}/module_ipc/app_gallery_dispose_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", "${path_backup_mock}/module_ipc/message_parcel_mock.cpp", "${path_backup_mock}/timer/timer_mock.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_stub.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_backup_connection.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", - "service_reverse_proxy_test.cpp", - "service_stub_test.cpp", "svc_backup_connection_test.cpp", - "svc_extension_proxy_test.cpp", ] include_dirs = [ @@ -414,16 +407,17 @@ ohos_unittest("backup_service_incremental_test") { "${path_backup_mock}/accesstoken/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/extension_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", "${path_backup_mock}/module_sched/sched_scheduler_mock.cpp", "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "service_incremental_test.cpp", ] @@ -475,11 +469,13 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/accesstoken/src/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/extension_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/app_gallery_dispose_proxy_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/notify_work_service_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_restore_deps_manager_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", @@ -490,8 +486,6 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/b_sa_utils_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_other_test.cpp", ] diff --git a/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp new file mode 100644 index 000000000..767c26153 --- /dev/null +++ b/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp @@ -0,0 +1,544 @@ +/* + * 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 "module_ipc/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 diff --git a/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp b/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp index 505e0eb57..788616b82 100644 --- a/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp @@ -42,7 +42,7 @@ public: static void TearDownTestCase(); void SetUp() override {}; void TearDown() override {}; - void Init(IServiceReverse::Scenario scenario); + void Init(IServiceReverseType::Scenario scenario); static inline sptr schedPtr_ = nullptr; static inline sptr sessionManagerPtr_ = nullptr; @@ -63,7 +63,7 @@ void SchedSchedulerTest::TearDownTestCase() sessionManagerPtr_ = nullptr; } -void SchedSchedulerTest::Init(IServiceReverse::Scenario scenario) +void SchedSchedulerTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; map backupExtNameMap; @@ -99,7 +99,7 @@ HWTEST_F(SchedSchedulerTest, SUB_Service_Sched_0100, testing::ext::TestSize.Leve { GTEST_LOG_(INFO) << "SchedSchedulerTest-begin SUB_Service_Sched_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(schedPtr_ != nullptr); schedPtr_->Sched(); GTEST_LOG_(INFO) << "SchedSchedulerTest-Sched Branches"; diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 4a6ed74b6..63b688ed6 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -23,7 +23,7 @@ #include "sa_backup_connection_mock.h" #include "service_reverse_proxy_mock.h" #include "svc_backup_connection_mock.h" -#include "svc_extension_proxy_mock.h" +#include "extension_proxy_mock.h" #include "svc_session_manager_mock.h" #include "service_incremental.cpp" @@ -35,6 +35,15 @@ void Service::OnStart() {} void Service::OnStop() {} +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { return UniqueFd(-1); @@ -47,22 +56,15 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } - -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } - -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -77,43 +79,45 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppDone(ErrCode errCode) +ErrCode Service::AppDone(int32_t appDoneErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } - ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) { return BError(BError::Codes::OK); } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -122,7 +126,10 @@ ErrCode Service::Finish() { return BError(BError::Codes::OK); } - +ErrCode Service::GetLocalCapabilities(int &fd) +{ + return BError(BError::Codes::OK); +} ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { return BError(BError::Codes::OK); @@ -163,7 +170,7 @@ ErrCode Service::VerifyCaller() return BError(BError::Codes::OK); } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { return BError(BError::Codes::OK); } @@ -181,17 +188,17 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} void Service::SessionDeactive() {} -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeOut, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } @@ -207,15 +214,11 @@ void Service::OnSARestore(const std::string &bundleName, const std::string &resu void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) {} -void Service::SendEndAppGalleryNotify(const BundleName &bundleName) -{ -} +void Service::SendEndAppGalleryNotify(const BundleName &bundleName) {} -void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) -{ -} +void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) {} -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -268,16 +271,16 @@ void Service::HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) {} void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -334,7 +337,7 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() } void Service::AppendBundles(const std::vector &bundleNames) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { return BError(BError::Codes::OK); } @@ -359,7 +362,7 @@ public: static inline shared_ptr jsonUtil = nullptr; static inline shared_ptr session = nullptr; static inline shared_ptr bms = nullptr; - static inline sptr svcProxy = nullptr; + static inline sptr svcProxy = nullptr; static inline sptr connect = nullptr; static inline shared_ptr saConnect = nullptr; static inline shared_ptr skeleton = nullptr; @@ -376,7 +379,7 @@ void ServiceIncrementalTest::SetUpTestCase(void) BJsonUtilMock::jsonUtil = jsonUtil; session = make_shared(); SvcSessionManagerMock::sessionManager = session; - svcProxy = sptr(new SvcExtensionProxyMock()); + svcProxy = sptr(new ExtensionProxyMock()); bms = make_shared(); BundleMgrAdapterMock::bms = bms; connect = sptr(new SvcBackupConnectionMock()); @@ -386,6 +389,16 @@ void ServiceIncrementalTest::SetUpTestCase(void) skeleton = make_shared(); IPCSkeletonMock::skeleton = skeleton; srProxy = sptr(new ServiceReverseProxyMock()); + EXPECT_NE(service, nullptr); + EXPECT_NE(param, nullptr); + EXPECT_NE(jsonUtil, nullptr); + EXPECT_NE(session, nullptr); + EXPECT_NE(bms, nullptr); + EXPECT_NE(svcProxy, nullptr); + EXPECT_NE(connect, nullptr); + EXPECT_NE(saConnect, nullptr); + EXPECT_NE(skeleton, nullptr); + EXPECT_NE(srProxy, nullptr); } void ServiceIncrementalTest::TearDownTestCase() @@ -425,7 +438,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncr try { auto session_ = service->session_; service->session_ = nullptr; - auto fd = service->GetLocalCapabilitiesIncremental({}); + int fd = -1; + service->GetLocalCapabilitiesIncremental({}, fd); service->session_ = session_; EXPECT_EQ(static_cast(fd), -ENOENT); } catch (...) { @@ -535,13 +549,15 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes try { auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr srPrt = static_cast>(srProxy); + srPrt = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -565,14 +581,16 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes std::string errMsg; auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), - BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr reverseNUll = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -761,26 +779,26 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ try { string fileName; int32_t errCode = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -804,27 +822,27 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ try { string fileName; int32_t errCode = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, HandleClear()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(0)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -900,10 +918,10 @@ 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(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); ret = service->GetIncrementalFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -932,46 +950,46 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0000, GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_IncrementalBackup_0000"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); bool res = service->IncrementalBackup(bundleName); EXPECT_TRUE(res); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); res = service->IncrementalBackup(bundleName); EXPECT_TRUE(res); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); auto ret = service->IncrementalBackup(bundleName); EXPECT_FALSE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); @@ -998,14 +1016,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_IncrementalBackup_0100"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); auto ret = service->IncrementalBackup(bundleName); EXPECT_FALSE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1014,7 +1032,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_FALSE(ret); set fileNameVec { "fileName" }; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1022,14 +1040,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)) - .WillOnce(Return(make_tuple(BError(BError::Codes::OK).GetCode(), UniqueFd(-1), UniqueFd(-1)))); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -1055,7 +1072,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, try { string bundleName; set fileNameVec { "fileName" }; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1063,14 +1080,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)) - .WillOnce(Return(make_tuple(BError(BError::Codes::SA_INVAL_ARG).GetCode(), UniqueFd(-1), UniqueFd(-1)))); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); auto ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -1096,19 +1112,19 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_NotifyCallerCurAppIncrem try { ErrCode errCode = 0; string callerName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); } catch (...) { @@ -1208,17 +1224,17 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Release_0000, TestSize.L EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1282,24 +1298,24 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0000, TestSize.Le impl.backupExtNameMap.insert(make_pair(bundleName, info)); int32_t result; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::CLEAN)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::START)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index 30ea8f00e..2f0330b99 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -31,7 +31,7 @@ #include "service_reverse_proxy_mock.h" #include "sms_adapter_mock.h" #include "svc_backup_connection_mock.h" -#include "svc_extension_proxy_mock.h" +#include "extension_proxy_mock.h" #include "svc_restore_deps_manager_mock.h" #include "svc_session_manager_mock.h" #include "system_ability_mock.h" @@ -40,20 +40,38 @@ #include "sub_service.cpp" namespace OHOS::FileManagement::Backup { +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::Release() { return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector&) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } void Service::StartGetFdTask(std::string, wptr) {} @@ -63,12 +81,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr) +ErrCode Service::InitIncrementalBackupSession(const sptr &) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr, std::string &) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string &) { return BError(BError::Codes::OK); } @@ -123,8 +141,12 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode, const std::string&) {} void Service::SendUserIdToApp(string&, int32_t) {} -void Service::SetCurrentBackupSessProperties(const vector&, int32_t, - std::vector&, bool) {} +void Service::SetCurrentBackupSessProperties(const vector &, + int32_t, + std::vector &, + bool) +{ +} std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) { @@ -134,7 +156,7 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName void Service::RemoveExtensionMutex(const BundleName&) {} void Service::CreateDirIfNotExist(const std::string&) {} -} +} // namespace OHOS::FileManagement::Backup class BThreadPool { public: @@ -176,7 +198,7 @@ public: static inline shared_ptr jsonUtil = nullptr; static inline shared_ptr session = nullptr; static inline shared_ptr bms = nullptr; - static inline sptr svcProxy = nullptr; + static inline sptr svcProxy = nullptr; static inline sptr connect = nullptr; static inline shared_ptr saConnect = nullptr; static inline shared_ptr skeleton = nullptr; @@ -203,7 +225,7 @@ void ServiceTest::SetUpTestCase(void) BJsonUtilMock::jsonUtil = jsonUtil; session = make_shared(); SvcSessionManagerMock::sessionManager = session; - svcProxy = sptr(new SvcExtensionProxyMock()); + svcProxy = sptr(new ExtensionProxyMock()); bms = make_shared(); BundleMgrAdapterMock::bms = bms; connect = sptr(new SvcBackupConnectionMock()); @@ -693,30 +715,30 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) BError error(BError::Codes::OK); sptr session_ = service->session_; BundleName bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); } catch (...) { @@ -767,7 +789,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleExceptionOnAppendBundles_0100, TestSize. try { vector appendBundleNames { "bundleName" }; vector restoreBundleNames; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); EXPECT_TRUE(true); @@ -915,7 +937,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleNames.emplace_back("bundleName"); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); EXPECT_TRUE(true); @@ -923,7 +945,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleInfos[0].allToBackup = true; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); @@ -933,7 +955,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleInfos[0].versionName = string(BConstants::DEFAULT_VERSION_NAME); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); @@ -1325,12 +1347,12 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, TestSize.Level1) try { ASSERT_TRUE(service != nullptr); std::string bundleName = ""; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); BJsonUtil::BundleDetailInfo info; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1342,7 +1364,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, TestSize.Level1) ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1378,7 +1400,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) ASSERT_TRUE(service != nullptr); string bundleName = ""; BJsonUtil::BundleDetailInfo info; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1397,7 +1419,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1566,14 +1588,14 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0000, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); ret = service->UpdateSendRate(bundleName, 0, result); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); ret = service->UpdateSendRate(bundleName, 0, result); @@ -1604,7 +1626,7 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, UpdateFdSendRate(_, _)).WillOnce(Return(EPERM)); @@ -1614,7 +1636,7 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, UpdateFdSendRate(_, _)).WillOnce(Return(NO_ERROR)); @@ -1642,42 +1664,42 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) try { string bundleName; shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); auto ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); sa = make_shared(nullptr, nullptr, nullptr, nullptr); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1718,7 +1740,7 @@ HWTEST_F(ServiceTest, SUB_Service_SADone_0000, TestSize.Level1) EXPECT_CALL(*saConnect, DisconnectBackupSAExt()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SADone(0, ""); @@ -1743,20 +1765,20 @@ HWTEST_F(ServiceTest, SUB_Service_NotifyCallerCurAppDone_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NotifyCallerCurAppDone_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); } catch (...) { @@ -1785,7 +1807,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return(1)); auto ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1794,7 +1816,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1803,7 +1825,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1812,7 +1834,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1876,9 +1898,9 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0000, TestSize.Level1) service->session_ = session_; EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -1890,7 +1912,7 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0000, TestSize.Level1) EXPECT_TRUE(true); shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); @@ -1919,7 +1941,7 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0100, TestSize.Level1) try { string bundleName; shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); @@ -1928,16 +1950,16 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0100, TestSize.Level1) EXPECT_TRUE(true); sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->DoTimeout(service, bundleName); EXPECT_TRUE(true); sa = make_shared(nullptr, nullptr, nullptr, nullptr); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, DisconnectBackupSAExt()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -2028,19 +2050,19 @@ HWTEST_F(ServiceTest, SUB_Service_ReleaseOnException_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); service->isInRelease_ = false; service->ReleaseOnException(); EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); service->isInRelease_ = true; service->ReleaseOnException(); EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); service->isInRelease_ = true; auto session_ = service->session_; service->session_ = nullptr; diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 48853ff35..63d09d7d7 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -20,7 +20,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "iservice_registry.h" #include "message_parcel_mock.h" #include "module_ipc/service_reverse_proxy.h" @@ -93,7 +93,8 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnFileReady_010 std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, fd, 0); + int fdValue = fd.Get(); + proxy_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, fdValue, 0); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -360,7 +361,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnBundleFinishe .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->BackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + proxy_->BackupOnBundleFinished(BError(BError::Codes::OK).GetCode(), BUNDLE_NAME); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1924,7 +1925,8 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; EXPECT_TRUE(proxy_ != nullptr); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + int32_t code=0; + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1946,11 +1948,12 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport { GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_RestoreOnResultReport_0101"; try { + int32_t code = 0; std::string bundleName = "app01"; try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1959,7 +1962,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1968,7 +1971,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(false)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1979,7 +1982,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2012,8 +2015,10 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; + EXPECT_TRUE(proxy_ != nullptr); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + int32_t code = 0; + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -2031,16 +2036,19 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR * @tc.level Level 1 * @tc.require: I9OVHB */ -HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101, - testing::ext::TestSize.Level1) +HWTEST_F(ServiceReverseProxyTest, + SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101, + testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101"; try { + int32_t code = 0; std::string bundleName = "app01"; try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2049,7 +2057,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2058,7 +2066,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(false)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2069,7 +2077,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index c63b4b11f..2fbd84033 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -25,7 +25,7 @@ #include "b_error/b_error.h" #include "b_resources/b_constants.h" #include "ipc_types.h" -#include "i_service.h" +#include "iservice.h" #include "message_parcel_mock.h" #include "module_ipc/service_stub.h" #include "service_reverse_mock.h" @@ -43,26 +43,27 @@ const string FILE_NAME = "1.tar"; class ServiceMock final : public ServiceStub { public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); MOCK_METHOD3(AppFileReady, ErrCode(const string &fileName, UniqueFd fd, int32_t errCode)); MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD3(ServiceResultReport, + ErrCode(const string &restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode)); MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); - MOCK_METHOD5( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, - RestoreTypeEnum restoreType, int32_t userId)); - MOCK_METHOD4( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD5(AppendBundlesRestoreSessionRestoreDataWaitSend, + ErrCode(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId)); + MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + ErrCode(UniqueFd fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId)); MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD2(AppendBundlesDetailsBackupSession, ErrCode(const std::vector &bundleNames, const std::vector &bundleInfos)); @@ -75,12 +76,12 @@ public: MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode)); MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); MOCK_METHOD2(GetBackupInfo, ErrCode(string &bundleName, string &result)); @@ -1181,7 +1182,7 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitIncrementalBackupSession EXPECT_CALL(*messageParcelMock, ReadRemoteObject()).WillOnce(Return(remote)); EXPECT_CALL(*castMock, iface_cast(_)).WillOnce(Return(remote)); - EXPECT_CALL(*service, InitIncrementalBackupSession(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); err = service->CmdInitIncrementalBackupSessionMsg(data, reply); @@ -1189,7 +1190,7 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitIncrementalBackupSession EXPECT_CALL(*messageParcelMock, ReadRemoteObject()).WillOnce(Return(remote)); EXPECT_CALL(*castMock, iface_cast(_)).WillOnce(Return(remote)); - EXPECT_CALL(*service, InitIncrementalBackupSession(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); auto ret = service->CmdInitIncrementalBackupSessionMsg(data, reply); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index ba99f49ff..7aac06a15 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -44,7 +44,7 @@ public: void SetUp() {}; void TearDown() {}; - ErrCode Init(IServiceReverse::Scenario scenario); + ErrCode Init(IServiceReverseType::Scenario scenario); static inline sptr servicePtr_ = nullptr; static inline sptr remote_ = nullptr; @@ -64,7 +64,7 @@ void ServiceTest::TearDownTestCase() remote_ = nullptr; } -ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) +ErrCode ServiceTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; vector detailInfos; @@ -83,23 +83,25 @@ ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) detailInfos.emplace_back(json); string errMsg; ErrCode ret = 0; - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { EXPECT_TRUE(servicePtr_ != nullptr); EXPECT_TRUE(remote_ != nullptr); UniqueFd fd = servicePtr_->GetLocalCapabilities(); EXPECT_GE(fd, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitRestoreSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_, errMsg); + ret = servicePtr_->InitRestoreSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->Finish(); EXPECT_EQ(ret, BError(BError::Codes::OK)); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - ret = servicePtr_->InitBackupSession(remote_); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitBackupSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitBackupSession(remote_, errMsg); + ret = servicePtr_->InitBackupSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesBackupSession(bundleNames); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -213,7 +215,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0100, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -243,7 +245,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0101, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -273,7 +275,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0102, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0102"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -301,11 +303,11 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0100, testing::ext::TestSize.Leve try { string fileName = MANAGE_JSON; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppFileReady Branches"; fileName = "test"; - ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -329,7 +331,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0101, testing::ext::TestSize.Leve try { string fileName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -353,7 +355,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Leve try { string fileName = "manage.json"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -377,16 +379,16 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0100, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_AppDone_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches"; ret = servicePtr_->AppDone(1); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches End"; - ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -410,12 +412,12 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0101, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_AppDone_0101 RESTORE"; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -440,7 +442,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0102, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; string bundleName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -500,13 +502,13 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -531,7 +533,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0101, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0101"; try { GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 UNDEFINED"; - ErrCode ret = Init(IServiceReverse::Scenario::UNDEFINED); + ErrCode ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); @@ -556,7 +558,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->GetFileHandle(BUNDLE_NAME, FILE_NAME); @@ -581,7 +583,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0101, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; @@ -617,13 +619,13 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0100, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); string bundleName = BUNDLE_NAME; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->OnBackupExtensionDied(move(bundleName)); GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); bundleName = BUNDLE_NAME; servicePtr_->OnBackupExtensionDied(move(bundleName)); @@ -648,7 +650,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0101, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0101"; try { GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); string bundleName = BUNDLE_NAME; SvcSessionManager::Impl impl_; @@ -658,12 +660,12 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0101, testing::ext::Test extInfo.versionName = "0.0.0.0-0.0.0.0"; impl_.restoreDataType = RESTORE_DATA_WAIT_SEND; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->OnBackupExtensionDied(move(bundleName)); GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); impl_.restoreDataType = RESTORE_DATA_READDY; bundleName = "123456789"; @@ -690,14 +692,14 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtStart_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 BACKUP"; - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtStart(BUNDLE_NAME); GTEST_LOG_(INFO) << "ServiceTest-ExtStart BACKUP Branches"; servicePtr_->ExtStart(BUNDLE_NAME); GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 RESTORE"; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); servicePtr_->ExtStart(BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -721,7 +723,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0101 BACKUP"; std::string bundleName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtStart(bundleName); @@ -736,16 +738,16 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); extInfo.backUpConnection->backupProxy_ = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::UNDEFINED; - ret = Init(IServiceReverse::Scenario::UNDEFINED); + impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; + ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::UNDEFINED); + ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); } catch (...) { @@ -841,19 +843,19 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectFailed_0100, testing::ext::TestSize. GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectFailed_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; impl_.restoreDataType = RESTORE_DATA_READDY; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); } catch (...) { @@ -1064,7 +1066,7 @@ HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0101, testing::ext:: { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendStartAppGalleryNotify_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendStartAppGalleryNotify(BUNDLE_NAME); @@ -1112,7 +1114,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0100, testing::ext::TestSize.Lev try { std::string bundleName = "com.example.app2backup"; std::string backupInfo = "backup info"; - auto ret = Init(IServiceReverse::Scenario::BACKUP); + auto ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->GetBackupInfo(bundleName, backupInfo); @@ -1138,7 +1140,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0101, testing::ext::TestSize.Lev try { std::string bundleName = "com.example.app2backup"; std::string result = "ok"; - auto ret = Init(IServiceReverse::Scenario::BACKUP); + auto ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->session_ = nullptr; @@ -1280,7 +1282,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, testing::ext::TestSize.L servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); SvcSessionManager::Impl impl_; impl_.clientToken = 1; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1524,7 +1526,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, testing::ext::Tes BackupExtInfo extInfo {}; extInfo.backUpConnection = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->HandleCurBundleEndWork(BUNDLE_NAME, BackupRestoreScenario::FULL_RESTORE); } catch (...) { @@ -1548,7 +1550,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0100, testing::ext::Te GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupSAExtension_0100"; try { std::string bundleName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupSAExtension(BUNDLE_NAME); @@ -1571,7 +1573,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0100, testing::ext::Te ret = servicePtr_->LaunchBackupSAExtension(bundleName); EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->LaunchBackupSAExtension(bundleName); EXPECT_NE(ret, BError(BError::Codes::OK)); @@ -1596,7 +1598,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectDied_0100"; try { std::string callName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; @@ -1606,7 +1608,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le string bundleNameIndexInfo = "123456789"; extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtConnectDied(callName); extInfo.backUpConnection->isConnected_.store(true); @@ -1631,19 +1633,19 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, testing::ext::TestSiz { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NoticeClientFinish_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_NoticeClientFinish_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; impl_.restoreDataType = RESTORE_DATA_READDY; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); } catch (...) { @@ -1666,13 +1668,13 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0100, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnAllBundlesFinished_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK)); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { @@ -1695,12 +1697,12 @@ HWTEST_F(ServiceTest, SUB_Service_SendEndAppGalleryNotify_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendEndAppGalleryNotify_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME); } catch (...) { @@ -1723,12 +1725,12 @@ HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendErrAppGalleryNotify_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendErrAppGalleryNotify(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->SendErrAppGalleryNotify(); } catch (...) { @@ -1751,12 +1753,12 @@ HWTEST_F(ServiceTest, SUB_Service_ClearDisposalOnSaStart_0100, testing::ext::Tes { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ClearDisposalOnSaStart_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ClearDisposalOnSaStart(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ClearDisposalOnSaStart(); } catch (...) { @@ -1779,12 +1781,12 @@ HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0100, testing::ext::TestSi { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_DeleteDisConfigFile_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->DeleteDisConfigFile(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->DeleteDisConfigFile(); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 158372cd2..186592052 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -136,7 +136,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -146,8 +147,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -157,7 +158,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0100"; } @@ -180,7 +181,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -190,8 +192,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -201,8 +203,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -212,7 +214,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0200"; } @@ -234,7 +236,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -244,8 +247,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -255,7 +258,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0100"; } @@ -278,7 +281,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -288,8 +292,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -299,8 +303,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -310,7 +314,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0200"; } @@ -527,7 +531,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -540,7 +545,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -593,7 +598,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_LaunchBackupExtension_0100, testing try { EXPECT_NE(service, nullptr); BundleName bundleName; - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { @@ -653,8 +658,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing EXPECT_NE(service, nullptr); string bundleName; EXPECT_CALL(*sessionMock, GetScenario()) - .WillOnce(Return(IServiceReverse::Scenario::CLEAN)) - .WillOnce(Return(IServiceReverse::Scenario::CLEAN)); + .WillOnce(Return(IServiceReverseType::Scenario::CLEAN)) + .WillOnce(Return(IServiceReverseType::Scenario::CLEAN)); EXPECT_CALL(*sessionMock, VerifyBundleName(_)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); @@ -692,21 +697,21 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtConnectFailed_0100, testing::ext BundleName bundleName; EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw BError(BError::Codes::EXT_THROW_EXCEPTION); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw "未知错误"; - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); @@ -734,8 +739,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_NoticeClientFinish_0100, testing::e string bundleName; ErrCode errCode = 0; EXPECT_CALL(*sessionMock, GetScenario()) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, errCode); EXPECT_TRUE(true); @@ -914,22 +919,23 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_010 throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); + int fd = -1; + ErrCode ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilitiesIncremental."; @@ -995,7 +1001,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1006,8 +1013,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1019,7 +1026,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0100"; } @@ -1042,7 +1049,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1053,8 +1061,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1065,8 +1073,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1078,7 +1086,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0200"; } @@ -1138,14 +1146,14 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSessi throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + auto ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, EPERM); } catch (...) { EXPECT_TRUE(false); @@ -1207,7 +1215,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -1220,7 +1229,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index a982e92e2..aabfdfd6f 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -27,12 +27,12 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurGroupBackupInfos_0000, TestSize.Level GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleCurGroupBackupInfos_0000"; try { vector backupInfos = { - {.name = "bundleName", .appIndex = 0, .allToBackup = false, .versionName = ""} }; + {.name = "bundleName", .appIndex = 0, .allToBackup = false, .versionName = ""}}; map> bundleNameDetailMap; map isClearDataFlags; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*jsonUtil, FindBundleInfoByName(_, _, _, _)).WillOnce(Return(false)); @@ -75,7 +75,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -87,7 +87,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -100,7 +100,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(1)); ret = service->ServiceResultReport("", BackupRestoreScenario::FULL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -110,7 +110,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(1)); ret = service->ServiceResultReport("", BackupRestoreScenario::INCREMENTAL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -134,29 +134,29 @@ HWTEST_F(ServiceTest, SUB_Service_SAResultReport_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SAResultReport_0000"; try { EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_BACKUP); @@ -183,14 +183,14 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) try { BundleName bundleName; EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); auto ret = service->LaunchBackupSAExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); shared_ptr sa = nullptr; EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->LaunchBackupSAExtension(bundleName); @@ -198,14 +198,14 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) sa = make_shared(nullptr, nullptr, nullptr, nullptr); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->LaunchBackupSAExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, ConnectBackupSAExt(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -213,7 +213,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, ConnectBackupSAExt(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -303,9 +303,9 @@ 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, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(-1))); + EXPECT_CALL(*svcProxy, GetFileHandleWithUniqueFd(_, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(1)); auto ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -316,12 +316,12 @@ 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, GetFileHandle(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(UniqueFd(-1)))); + EXPECT_CALL(*svcProxy, GetFileHandleWithUniqueFd(_, _, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(0))); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(1)); ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,15 +345,16 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0000"; try { service->isOccupyingSession_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->OnBackupExtensionDied("", true); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); @@ -388,9 +389,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -401,9 +403,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -415,9 +418,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -445,15 +449,16 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) string callName; shared_ptr sa = make_shared(nullptr, nullptr, nullptr, nullptr); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->ExtStart(callName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -461,9 +466,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -472,9 +478,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -503,26 +510,27 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) try { string callName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); service->ExtStart(callName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::BACKUP)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -532,13 +540,13 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) set fileNameVec; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); @@ -546,7 +554,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtStart."; } GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtStart_0100"; } @@ -593,46 +600,46 @@ HWTEST_F(ServiceTest, SUB_Service_ReportOnExtConnectFailed_0000, TestSize.Level1 string bundleName; auto session_ = service->session_; service->session_ = nullptr; - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::UNDEFINED, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::UNDEFINED, bundleName, 0); service->session_ = session_; EXPECT_TRUE(true); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::UNDEFINED, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::UNDEFINED, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -656,35 +663,35 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) try { string bundleName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -710,20 +717,20 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) try { string bundleName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -789,13 +796,13 @@ HWTEST_F(ServiceTest, SUB_Service_ClearSessionAndSchedInfo_0000, TestSize.Level1 try { string bundleName; service->isOccupyingSession_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); service->ClearSessionAndSchedInfo(bundleName); EXPECT_TRUE(true); service->isOccupyingSession_ = true; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ClearSessionAndSchedInfo(bundleName); @@ -803,7 +810,7 @@ HWTEST_F(ServiceTest, SUB_Service_ClearSessionAndSchedInfo_0000, TestSize.Level1 service->failedBundles_.clear(); service->successBundlesNum_ = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); service->ClearSessionAndSchedInfo(bundleName); @@ -829,19 +836,19 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleRestoreDepsBundle_0000"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->HandleRestoreDepsBundle(bundleName); EXPECT_TRUE(true); map bundleMap; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); service->HandleRestoreDepsBundle(bundleName); EXPECT_TRUE(true); bundleMap["bundleName"] = {.fileNames_ = {"name"}}; vector bundleInfos {{.name = "name"}}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); EXPECT_CALL(*depManager, GetAllBundles()).WillOnce(Return(bundleInfos)); service->HandleRestoreDepsBundle(bundleName); @@ -849,7 +856,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) bundleInfos.clear(); bundleInfos = {{.name = "bundleName"}}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); EXPECT_CALL(*depManager, GetAllBundles()).WillOnce(Return(bundleInfos)); service->HandleRestoreDepsBundle(bundleName); @@ -861,7 +868,6 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleRestoreDepsBundle_0000"; } - /** * @tc.number: SUB_Service_OnAllBundlesFinished_0000 * @tc.name: SUB_Service_OnAllBundlesFinished_0000 @@ -881,36 +887,37 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0000, TestSize.Level1) service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)).WillOnce(Return(true)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -936,32 +943,32 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0100, TestSize.Level1) try { service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -987,17 +994,17 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0200, TestSize.Level1) try { service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(false)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -1054,18 +1061,18 @@ HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0000, TestSize.Level EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendStartAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, IfBundleNameInDisposalConfigFile(_)).WillOnce(Return(false)); service->SendStartAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, IfBundleNameInDisposalConfigFile(_)).WillOnce(Return(true)); EXPECT_CALL(*gallery, StartRestore(_, _)).WillOnce(Return(DisposeErr::OK)); service->SendStartAppGalleryNotify(bundleName); @@ -1096,25 +1103,25 @@ HWTEST_F(ServiceTest, SUB_Service_SendEndAppGalleryNotify_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::REQUEST_FAIL)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(false)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); service->SendEndAppGalleryNotify(bundleName); @@ -1145,7 +1152,8 @@ HWTEST_F(ServiceTest, SUB_Service_TryToClearDispose_0000, TestSize.Level1) service->TryToClearDispose(bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::REQUEST_FAIL)) + EXPECT_CALL(*gallery, EndRestore(_, _)) + .WillOnce(Return(DisposeErr::REQUEST_FAIL)) .WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(false)); service->TryToClearDispose(bundleName); @@ -1170,18 +1178,18 @@ HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendErrAppGalleryNotify_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendErrAppGalleryNotify(); EXPECT_TRUE(true); vector bundleNameList; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); service->SendErrAppGalleryNotify(); EXPECT_TRUE(true); bundleNameList.emplace_back("bundleName"); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); @@ -1238,24 +1246,24 @@ HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_DeleteDisConfigFile_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); vector bundleNameList {"bundleName"}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); bundleNameList.clear(); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*jdConfig, DeleteConfigFile()).WillOnce(Return(false)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*jdConfig, DeleteConfigFile()).WillOnce(Return(true)); service->DeleteDisConfigFile(); @@ -1288,27 +1296,29 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0000, TestSize.Level1) auto sched = service->sched_; service->sched_ = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)).WillOnce(Return(false)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)) .WillOnce(DoAll(SetArgReferee<0>(BError(BError::Codes::SA_INVAL_ARG)), Return(true))); service->SessionDeactive(); EXPECT_TRUE(true); vector bundleNameList {"bundleName"}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)) .WillOnce(DoAll(SetArgReferee<1>(bundleNameList), Return(true))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -1337,18 +1347,20 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, TestSize.Level1) try { service->failedBundles_.clear(); service->successBundlesNum_ = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); EXPECT_TRUE(true); service->isRmConfigFile_ = true; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*cdConfig, DeleteConfigFile()).WillOnce(Return(false)); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); @@ -1356,9 +1368,10 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, TestSize.Level1) EXPECT_TRUE(true); service->isRmConfigFile_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); @@ -1388,17 +1401,19 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0200, TestSize.Level1) service->isRmConfigFile_ = false; auto clearRecorder = service->clearRecorder_; service->clearRecorder_ = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(-1)); service->SessionDeactive(); @@ -1497,15 +1512,15 @@ HWTEST_F(ServiceTest, SUB_Service_TimeoutRadarReport_0000, TestSize.Level1) string bundleName; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - service->TimeoutRadarReport(IServiceReverse::Scenario::BACKUP, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::BACKUP, bundleName); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - service->TimeoutRadarReport(IServiceReverse::Scenario::RESTORE, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::RESTORE, bundleName); EXPECT_TRUE(true); - service->TimeoutRadarReport(IServiceReverse::Scenario::UNDEFINED, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::UNDEFINED, bundleName); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1528,7 +1543,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetLocalCapabilitiesForBdInfos_0000, TestSize. GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetLocalCapabilitiesForBdInfos_0000"; try { ASSERT_TRUE(service != nullptr); - auto session_ = service->session_; + auto session_ = service->session_; service->session_ = nullptr; EXPECT_EQ(-EPERM, service->GetLocalCapabilitiesForBundleInfos()); @@ -1808,10 +1823,14 @@ HWTEST_F(ServiceTest, SUB_Service_GetPrecisesSize_0100, TestSize.Level1) dataTwo.bundleName = BUNDLE_NAME; dataTwo.lastIncrementalTime = 1; bundleNameListTwo.push_back(dataTwo); - EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)) - .WillOnce(Return(info)).WillOnce(Return(info)); - EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)).WillOnce(Return(0)) - .WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)) + .WillOnce(Return(info)) + .WillOnce(Return(info)) + .WillOnce(Return(info)); + EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)) + .WillOnce(Return(0)) + .WillOnce(Return(0)) + .WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) @@ -1892,16 +1911,12 @@ HWTEST_F(ServiceTest, SUB_Service_GetDataSizeStepByStep_0000, TestSize.Level1) bool isPreciseScan = false; vector bundleNameList; string scanning = ""; - EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { - f(); - }))); + EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { f(); }))); service->GetDataSizeStepByStep(isPreciseScan, bundleNameList, scanning); EXPECT_TRUE(true); isPreciseScan = true; - EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { - f(); - }))); + EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { f(); }))); service->GetDataSizeStepByStep(isPreciseScan, bundleNameList, scanning); EXPECT_TRUE(true); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index 54c6a5067..e388a28d1 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -44,7 +44,7 @@ public: static void TearDownTestCase(void); void SetUp() override {}; void TearDown() override {}; - void Init(IServiceReverse::Scenario scenario); + void Init(IServiceReverseType::Scenario scenario); static inline sptr sessionManagerPtr_ = nullptr; static inline sptr remote_ = nullptr; @@ -67,7 +67,7 @@ void SvcSessionManagerTest::TearDownTestCase(void) remote_ = nullptr; } -void SvcSessionManagerTest::Init(IServiceReverse::Scenario scenario) +void SvcSessionManagerTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; vector failedBundles; @@ -96,19 +96,19 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_VerifyCallerAndScenario_01 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_VerifyCallerAndScenario_0100"; try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; ErrCode ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, - IServiceReverse::Scenario::RESTORE); + IServiceReverseType::Scenario::RESTORE); EXPECT_TRUE(ret == BError(BError::Codes::SDK_MIXED_SCENARIO).GetCode()); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; sessionManagerPtr_->impl_.clientToken = 0; - ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverse::Scenario::BACKUP); + ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(ret == BError(BError::Codes::SA_REFUSED_ACT).GetCode()); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverse::Scenario::BACKUP); + ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(ret == ERR_OK); } catch (...) { EXPECT_TRUE(false); @@ -141,13 +141,13 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Active_0100, testing::ext: EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); newImpl.clientToken = CLIENT_TOKEN_ID; - newImpl.scenario = IServiceReverse::Scenario::UNDEFINED; + newImpl.scenario = IServiceReverseType::Scenario::UNDEFINED; sessionManagerPtr_->impl_.clientToken = 0; res = sessionManagerPtr_->Active(newImpl); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); newImpl.clientToken = CLIENT_TOKEN_ID; - newImpl.scenario = IServiceReverse::Scenario::BACKUP; + newImpl.scenario = IServiceReverseType::Scenario::BACKUP; newImpl.clientProxy = nullptr; sessionManagerPtr_->impl_.clientToken = 0; res = sessionManagerPtr_->Active(newImpl); @@ -282,12 +282,12 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_getscenario_0100, testing: try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = 0; - IServiceReverse::Scenario scenario = sessionManagerPtr_->GetScenario(); - EXPECT_TRUE(scenario == IServiceReverse::Scenario::UNDEFINED); + IServiceReverseType::Scenario scenario = sessionManagerPtr_->GetScenario(); + EXPECT_TRUE(scenario == IServiceReverseType::Scenario::UNDEFINED); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; scenario = sessionManagerPtr_->GetScenario(); - EXPECT_TRUE(scenario == IServiceReverse::Scenario::UNDEFINED); + EXPECT_TRUE(scenario == IServiceReverseType::Scenario::UNDEFINED); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by getscenario."; @@ -320,21 +320,21 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0100, te sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); EXPECT_TRUE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap["123"] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady("123"); EXPECT_TRUE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); EXPECT_FALSE(fileReady); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_onBundlefileready_0100"; @@ -356,21 +356,21 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0101, te sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); EXPECT_FALSE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, "test"); EXPECT_FALSE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, string(BConstants::EXT_BACKUP_MANAGE)); EXPECT_FALSE(fileReady); @@ -402,7 +402,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleExtManageInfo_0100 EXPECT_TRUE(move(ret) == -1); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); EXPECT_TRUE(move(ret) == -1); @@ -583,7 +583,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0102 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0102"; EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); EXPECT_TRUE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0102"; @@ -603,7 +603,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0103 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0103"; EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); EXPECT_FALSE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0103"; @@ -1009,14 +1009,14 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_NeedToUnloadService_0100, sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; sessionManagerPtr_->impl_.restoreDataType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->NeedToUnloadService(); EXPECT_FALSE(ret); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; sessionManagerPtr_->impl_.restoreDataType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; ret = sessionManagerPtr_->NeedToUnloadService(); EXPECT_FALSE(ret); } catch (...) { @@ -1079,7 +1079,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleFileReady_0200, te try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->Deactive(nullptr, true); - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); EXPECT_FALSE(fileReady); fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); @@ -1470,12 +1470,12 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_IsOnAllBundlesFinished_010 EXPECT_FALSE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->IsOnAllBundlesFinished(); EXPECT_FALSE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; ret = sessionManagerPtr_->IsOnAllBundlesFinished(); EXPECT_FALSE(ret); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_IsOnAllBundlesFinished_0100"; diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index 46b847da7..5b5e76d10 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") import("//foundation/filemanagement/app_file_service/backup.gni") ohos_unittest("b_incremental_session_test") { @@ -20,6 +21,13 @@ ohos_unittest("b_incremental_session_test") { include_dirs = [ "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_notify", + "${path_backup}/utils/include", + "${path_backup}/utils/src", + "${path_backup}/tests/mock/utils_mock/include", + ".", + "session", ] sources = [ @@ -30,17 +38,26 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "b_incremental_session_test.cpp", + "service_client_mock.cpp", "service_proxy_mock.cpp", ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + defines = [ "LOG_TAG=\"app_file_service\"", "LOG_DOMAIN=0xD200000", @@ -49,12 +66,23 @@ ohos_unittest("b_incremental_session_test") { ] external_deps = [ + "ability_base:want", + "ability_runtime:ability_connect_callback_stub", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", "c_utils:utils", + "common_event_service:cesfwk_innerkits", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", + "jsoncpp:jsoncpp", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", ] use_exceptions = true diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index e074a00e0..b04fe944b 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -20,6 +20,7 @@ #include "b_incremental_restore_session.h" #include "b_incremental_session_restore_async.h" #include "service_proxy_mock.h" +#include "service_client.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -45,7 +46,7 @@ void IncrementalSessionTest::SetUpTestCase() restoreSession = make_shared(); BIncrementalSessionRestoreAsync::Callbacks callbacks; restoreAsyncSession = make_shared(callbacks); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; } void IncrementalSessionTest::TearDownTestCase() @@ -53,7 +54,7 @@ void IncrementalSessionTest::TearDownTestCase() backupSession = nullptr; restoreSession = nullptr; restoreAsyncSession = nullptr; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; proxy = nullptr; } @@ -70,14 +71,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks); @@ -103,11 +103,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); backupSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; backupSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -132,14 +132,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -162,13 +162,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -191,14 +191,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks); @@ -224,11 +224,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); restoreSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -253,16 +253,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -285,13 +285,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -314,14 +314,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,7 +345,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreSession != nullptr); @@ -353,7 +353,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -376,7 +376,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -384,8 +384,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -408,14 +408,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalSessionRestoreAsync::Callbacks callbacks; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreAsyncSession->Init(callbacks); @@ -441,11 +441,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); restoreAsyncSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreAsyncSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -470,16 +470,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -502,14 +502,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -533,7 +533,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreAsyncSession != nullptr); @@ -541,7 +541,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -564,7 +564,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -572,8 +572,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -596,13 +596,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -625,15 +625,15 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; vector infos; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSessionWithBundleInfos(_, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -656,7 +656,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; UniqueFd fd; EXPECT_TRUE(restoreSession != nullptr); @@ -664,7 +664,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishSAIncrementalFile(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishSAFile(fileInfo, move(fd)); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -687,14 +687,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -717,14 +717,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -747,14 +747,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -779,14 +779,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2400, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks, errMsg, errCode); @@ -813,14 +813,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2500, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitRestoreSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitRestoreSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks, errMsg, errCode); @@ -845,17 +845,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { @@ -878,17 +879,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp new file mode 100644 index 000000000..cf075fbd2 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "service_client.h" +#include "iservice.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() {} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h new file mode 100644 index 000000000..6aa6d9884 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H +#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + +#include + +#include "service_client.h" + +namespace OHOS::FileManagement::Backup { +class ServiceClientMock : public ServiceClient { + +public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); +}; +} // End of namespace OHOS::FileManagement::Backup +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 41cce333d..765206376 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -16,225 +16,223 @@ #include "service_proxy.h" #include "b_error/b_error.h" - +#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +ErrCode ServiceProxy::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { - return 0; -} - -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote) +ErrCode ServiceProxy::AppDone(int32_t appDoneErrCode) { - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - return 0; -} - -ErrCode ServiceProxy::Start() +ErrCode ServiceProxy::RefreshDataSize(int64_t totalDataSize) { return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::AppIncrementalDone(int32_t appIncrementalDoneErrCode) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppDone(ErrCode errCode) +ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) +int32_t ServiceProxy::InitRestoreSession(const sptr &remote) { - return BError(BError::Codes::OK); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::Start() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Finish() +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &cancelResult) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Release() +ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario scenario) { - result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +int32_t ServiceProxy::InitBackupSession(const sptr &remote) { - return UniqueFd(-1); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() +ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, + BackupRestoreScenario scenario, + int32_t serviceResultReportErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &detailInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) +ErrCode ServiceProxy::Finish() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) +ErrCode ServiceProxy::Release() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) +ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::RefreshDataSize(int64_t totalsize) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) { - return serviceProxy_; + return BError(BError::Codes::OK); } -sptr ServiceProxy::GetInstance() +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { - return serviceProxy_; + return BError(BError::Codes::OK); } -void ServiceProxy::InvaildInstance() {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t, const OHOS::sptr&) {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + fd = -1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index b734c8dac..1b3846170 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -26,48 +26,49 @@ public: explicit ServiceProxyMock(const sptr &impl) : ServiceProxy(impl) {} ~ServiceProxyMock() override {} public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(AsObject, sptr()); - MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); - MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); + MOCK_METHOD1(GetLocalCapabilitiesForBundleInfos, ErrCode(int32_t &)); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd)); - MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd, int32_t errCode)); - MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, int fd)); + MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, int fd, int32_t errCode)); + MOCK_METHOD1(AppDone, ErrCode(int32_t errCode)); + MOCK_METHOD2(GetFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD5(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId)); - MOCK_METHOD4(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, - RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); - MOCK_METHOD2(Cancel, ErrCode(std::string bundleName, int32_t &result)); - MOCK_METHOD1(GetLocalCapabilitiesIncremental, UniqueFd(const std::vector &bundleNames)); - MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD2(Cancel, ErrCode(const std::string &bundleName, int32_t &result)); + MOCK_METHOD2(GetLocalCapabilitiesIncremental, ErrCode(const std::vector &bundleNames, int &fd)); + MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitIncrementalBackupSessionWithErrMsg, + ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); - MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + MOCK_METHOD2(AppendBundlesIncrementalBackupSessionWithBundleInfos, + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); - MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); + MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, int fd)); + MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD1(AppIncrementalDone, ErrCode(int32_t errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD2(GetBackupInfo, ErrCode(BundleName &bundleName, std::string &result)); - MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); + MOCK_METHOD2(GetBackupInfo, ErrCode(const BundleName &bundleName, std::string &result)); + MOCK_METHOD3(UpdateTimer, ErrCode(const BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD0(GetAppLocalListAndDoIncrementalBackup, ErrCode()); MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); - MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, std::vector bundleNameList)); + MOCK_METHOD5( + AppendBundlesRestoreSessionRestoreDataWaitSend, + ErrCode(int32_t, const std::vector &, const std::vector &, int32_t, int32_t)); + MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + ErrCode(int32_t, const std::vector &, int32_t, int32_t)); + MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 0a0c1d50a..55f0d5f49 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("backup_tool_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_data.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_backup_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", "${path_backup}/tools/backup_tool/src/tools_op_backup.cpp", @@ -50,6 +49,7 @@ ohos_unittest("backup_tool_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -91,7 +91,6 @@ ohos_unittest("backup_tool_restore_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", @@ -108,10 +107,12 @@ ohos_unittest("backup_tool_restore_test") { "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/tools/backup_tool/include", "${path_backup}/tools/backup_tool/src", + "${target_gen_dir}/interfaces/inner_api/native/backup_kit_inner", ] include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp index 1d3dc5078..13e96ddd2 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp @@ -101,6 +101,7 @@ HWTEST_F(ToolsOpCheckSaTest, SUB_backup_tools_op_check_sa_0200, testing::ext::Te } GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); + CheckSaRegister(); if (matchedOp != opeartions.end()) { ret = matchedOp->Execute(mapArgToVal); EXPECT_NE(ret, 0); diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp index cc797c548..51acb7436 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp @@ -27,7 +27,7 @@ #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "tools_op_restore_async.cpp" namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp index 6244fabf5..de6e6ba91 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp @@ -28,7 +28,7 @@ #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "tools_op_restore.cpp" namespace OHOS::FileManagement::Backup { diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 745fe725e..d2b6a18d3 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -39,7 +39,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_backup.h" @@ -240,12 +240,13 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; } - BFile::SendFile(fdLocal, proxy->GetLocalCapabilities()); + int fd = -1; + BFile::SendFile(fdLocal, proxy->GetLocalCapabilities(fd)); auto ctx = make_shared(); ctx->session_ = BSessionBackup::Init( diff --git a/tools/backup_tool/src/tools_op_check_sa.cpp b/tools/backup_tool/src/tools_op_check_sa.cpp index 5e781f316..56535dea5 100644 --- a/tools/backup_tool/src/tools_op_check_sa.cpp +++ b/tools/backup_tool/src/tools_op_check_sa.cpp @@ -17,7 +17,7 @@ #include #include "errors.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_check_sa.h" @@ -31,7 +31,7 @@ static string GenHelpMsg() static int Exec(map> &mapArgToVal) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EFAULT; diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 41a97190c..3e18b7ba7 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -42,7 +42,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" namespace OHOS::FileManagement::Backup { @@ -273,7 +273,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; @@ -286,11 +286,13 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, ctx->lastIncrementalData.push_back(data); num++; } - UniqueFd fd = proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData); + int fdVal = -1; + proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); + UniqueFd fd(static_cast(fdVal)); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { - BFile::SendFile(fdLocal, fd); + BFile::SendFile(fdLocal, std::move(fd)); } return 0; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 95b58a5ad..0acecd72e 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -84,7 +84,10 @@ ohos_shared_library("backup_utils") { "src/b_utils/b_time.cpp", ] - configs = [ ":utils_private_config" ] + configs = [ + ":utils_private_config", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:public_idl_config", + ] public_configs = [ ":utils_public_config" ] external_deps = [ @@ -106,9 +109,10 @@ ohos_shared_library("backup_utils") { "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/utils/include", ] - + print("utils_public_config include_dirs:", configs) deps = [ ":backup_cxx_cppdeps", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_type", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_jsoncpp}:jsoncpp", "//third_party/openssl:libcrypto_shared", diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 16d4a17f4..a90a34b49 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_B_RADAR_H #include #include -#include "i_service_reverse.h" +#include "service_reverse_inner_type.h" namespace OHOS::FileManagement::Backup { enum class BizStageBackup : int32_t { @@ -119,7 +119,7 @@ public: enum BizStageBackup bizStage, int32_t resultCode); void RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId, enum BizStageRestore bizStage, int32_t resultCode); - void RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, + void RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverseType::Scenario scenario, int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode); private: AppRadar() = default; diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 1c7f7ac84..8ab04e149 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -23,7 +23,6 @@ #include "b_resources/b_constants.h" #include "b_utils/b_time.h" #include "hisysevent.h" -#include "i_service_reverse.h" namespace OHOS::FileManagement::Backup { int32_t AppRadar::GetUserId() @@ -49,7 +48,7 @@ void AppRadar::RecordDefaultFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::UNDEFINED), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::UNDEFINED), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, @@ -70,7 +69,7 @@ void AppRadar::RecordBackupFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::BACKUP), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::BACKUP), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, @@ -91,14 +90,14 @@ void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::RESTORE), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::RESTORE), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, "RESULT_INFO", ss.str()); } -void AppRadar::RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, +void AppRadar::RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverseType::Scenario scenario, int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode) { std::stringstream ss; -- Gitee From c8bcb8cac73f61fcd52a49e1b23be869f94c90f9 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 19 Feb 2025 22:54:32 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=96=87=E4=BB=B6IDL?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- backup.gni | 4 +- bundle.json | 12 +- frameworks/native/backup_ext/BUILD.gn | 3 +- .../native/backup_ext/include/ext_extension.h | 24 +- .../backup_ext/include/ext_extension_stub.h | 54 - .../native/backup_ext/src/ext_backup.cpp | 3 +- .../native/backup_ext/src/ext_extension.cpp | 133 +- .../backup_ext/src/ext_extension_stub.cpp | 266 --- .../backup_ext/src/sub_ext_extension.cpp | 18 +- .../include/service_reverse.h | 74 +- .../include/service_reverse_stub.h | 70 - .../backup_kit_inner/src/b_file_info.cpp | 2 +- .../src/b_incremental_backup_session.cpp | 41 +- .../src/b_incremental_data.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 65 +- .../b_incremental_session_restore_async.cpp | 41 +- .../backup_kit_inner/src/b_session_backup.cpp | 43 +- .../src/b_session_restore.cpp | 63 +- .../src/b_session_restore_async.cpp | 39 +- .../backup_kit_inner/src/service_client.cpp | 148 ++ .../src/service_incremental_proxy.cpp | 417 ----- .../src/service_incremental_reverse.cpp | 83 +- .../backup_kit_inner/src/service_proxy.cpp | 839 ---------- .../backup_kit_inner/src/service_reverse.cpp | 75 +- .../src/service_reverse_stub.cpp | 359 ---- .../native/backup_kit_inner/BUILD.gn | 144 +- .../native/backup_kit_inner/ExtensionType.idl | 22 + .../native/backup_kit_inner/IExtension.idl | 31 + .../native/backup_kit_inner/IService.idl | 72 + .../backup_kit_inner/IServiceReverse.idl | 63 + .../ServiceReverseInnerType.idl | 23 + .../backup_kit_inner/ServiceReverseType.idl | 24 + .../impl/b_incremental_backup_session.h | 4 +- .../impl/b_incremental_restore_session.h | 4 +- .../b_incremental_session_restore_async.h | 5 +- .../backup_kit_inner/impl/b_session_backup.h | 4 +- .../backup_kit_inner/impl/b_session_restore.h | 2 +- .../impl/b_session_restore_async.h | 5 +- .../{b_file_info.h => backup_file_info.h} | 0 ...ental_data.h => backup_incremental_data.h} | 0 .../native/backup_kit_inner/impl/i_service.h | 104 -- .../backup_kit_inner/impl/i_service_reverse.h | 76 - .../backup_kit_inner/impl/service_client.h | 56 +- .../impl/{i_extension.h => service_common.h} | 36 +- .../backup_kit_inner/impl/service_proxy.h | 112 -- .../kits/js/backup/parse_inc_info_from_js.h | 2 +- .../kits/js/backup/prop_n_operation.cpp | 38 +- .../session_incremental_backup_n_exporter.cpp | 2 +- services/backup_sa/BUILD.gn | 6 +- .../include/module_external/bms_adapter.h | 2 +- .../backup_sa/include/module_ipc/service.h | 106 +- .../module_ipc/service_reverse_proxy.h | 68 - .../include/module_ipc/service_stub.h | 85 - .../module_ipc/svc_backup_connection.h | 2 +- .../module_ipc/svc_restore_deps_manager.h | 3 +- .../include/module_ipc/svc_session_manager.h | 19 +- .../src/module_external/bms_adapter.cpp | 2 +- services/backup_sa/src/module_ipc/service.cpp | 346 ++-- .../src/module_ipc/service_incremental.cpp | 181 ++- .../service_incremental_reverse_proxy.cpp | 274 ---- .../src/module_ipc/service_reverse_proxy.cpp | 259 --- .../backup_sa/src/module_ipc/service_stub.cpp | 858 ---------- .../backup_sa/src/module_ipc/sub_service.cpp | 116 +- .../src/module_ipc/svc_backup_connection.cpp | 4 +- .../svc_extension_incremental_proxy.cpp | 173 -- .../src/module_ipc/svc_extension_proxy.cpp | 215 --- .../src/module_ipc/svc_session_manager.cpp | 32 +- .../src/module_sched/sched_scheduler.cpp | 8 +- test/fuzztest/backupext_fuzzer/BUILD.gn | 1 - .../backupext_fuzzer/backupext_fuzzer.cpp | 150 +- test/fuzztest/backupsa_fuzzer/BUILD.gn | 1 + .../backupsa_fuzzer/backupsa_fuzzer.cpp | 10 +- .../backupsaanother_fuzzer.cpp | 22 +- .../backupsaappend_fuzzer.cpp | 18 +- .../backupservicestub_fuzzer.cpp | 569 +------ .../backupservicestubbranch_fuzzer.cpp | 861 +--------- test/fuzztest/servicereverse_fuzzer/BUILD.gn | 2 + .../backup_ext/include/ext_extension_mock.h | 40 +- .../include/ext_extension_stub_mock.h | 2 +- .../backup_ext/src/ext_extension_mock.cpp | 20 + .../src/ext_extension_stub_mock.cpp | 4 +- .../backup_kit_inner/service_client_mock.cpp | 80 + .../backup_kit_inner/service_proxy_mock.cpp | 112 +- .../mock/module_ipc/extension_proxy_mock.cpp | 85 + tests/mock/module_ipc/extension_type_mock.cpp | 43 + .../module_ipc/include/extension_proxy_mock.h | 43 + .../include/service_reverse_proxy_mock.h | 64 +- .../module_ipc/include/service_stub_mock.h | 92 +- .../include/svc_extension_proxy_mock.h | 16 +- .../include/svc_session_manager_mock.h | 8 +- tests/mock/module_ipc/message_parcel_mock.h | 4 +- tests/mock/module_ipc/service_mock.cpp | 160 +- .../module_ipc/service_reverse_proxy_mock.cpp | 204 ++- tests/mock/module_ipc/service_stub_mock.cpp | 883 +++++----- .../mock/module_ipc/src/service_stub_mock.cpp | 399 +++-- .../src/svc_session_manager_mock.cpp | 6 +- .../module_ipc/svc_backup_connection_mock.cpp | 2 +- .../module_ipc/svc_extension_proxy_mock.cpp | 14 +- .../module_ipc/svc_session_manager_mock.cpp | 6 +- .../svc_session_manager_throw_mock.cpp | 6 +- .../svc_session_manager_throw_mock.h | 12 +- tests/moduletests/backup_kit_inner/BUILD.gn | 5 +- .../b_session_backup_test.cpp | 2 +- .../b_session_restore_async_test.cpp | 2 +- .../b_session_restore_test.cpp | 2 +- .../unittests/backup_api/backup_impl/BUILD.gn | 2 - .../backup_impl/b_file_info_test.cpp | 2 +- .../backup_impl/include/ext_extension_mock.h | 36 +- .../backup_impl/include/i_service_mock.h | 101 +- .../include/service_reverse_mock.h | 179 +- .../backup_impl/service_proxy_test.cpp | 1444 ----------------- .../backup_impl/service_reverse_stub_test.cpp | 889 ---------- .../backup_impl/service_reverse_test.cpp | 142 +- tests/unittests/backup_ext/BUILD.gn | 62 +- .../backup_ext/ext_extension_stub_test.cpp | 606 ------- tests/unittests/backup_sa/BUILD.gn | 1 + .../backup_sa/module_client/BUILD.gn | 87 + .../module_client/service_client_test.cpp | 434 +++++ .../backup_sa/module_client/service_mock.cpp | 625 +++++++ tests/unittests/backup_sa/module_ipc/BUILD.gn | 22 +- .../module_ipc/extension_proxy_test.cpp | 544 +++++++ .../module_ipc/sched_scheduler_test.cpp | 6 +- .../module_ipc/service_incremental_test.cpp | 218 +-- .../module_ipc/service_other_test.cpp | 148 +- .../module_ipc/service_reverse_proxy_test.cpp | 38 +- .../module_ipc/service_stub_test.cpp | 39 +- .../backup_sa/module_ipc/service_test.cpp | 130 +- .../module_ipc/service_throw_test.cpp | 109 +- .../backup_sa/module_ipc/sub_service_test.cpp | 317 ++-- .../module_ipc/svc_session_manager_test.cpp | 54 +- tests/unittests/backup_sa/session/BUILD.gn | 30 +- .../session/b_incremental_session_test.cpp | 138 +- .../backup_sa/session/service_client_mock.cpp | 51 + .../backup_sa/session/service_client_mock.h | 34 + .../backup_sa/session/service_proxy_mock.cpp | 146 +- .../backup_sa/session/service_proxy_mock.h | 59 +- tests/unittests/backup_tools/BUILD.gn | 5 +- .../backup_tool/tools_op_check_sa_test.cpp | 1 + .../tools_op_restore_async_test.cpp | 2 +- .../backup_tool/tools_op_restore_test.cpp | 2 +- tools/backup_tool/src/tools_op_backup.cpp | 7 +- tools/backup_tool/src/tools_op_check_sa.cpp | 4 +- .../src/tools_op_incremental_backup.cpp | 10 +- utils/BUILD.gn | 8 +- utils/include/b_radar/b_radar.h | 4 +- utils/src/b_radar/b_radar.cpp | 9 +- 146 files changed, 5912 insertions(+), 11249 deletions(-) delete mode 100644 frameworks/native/backup_ext/include/ext_extension_stub.h delete mode 100644 frameworks/native/backup_ext/src/ext_extension_stub.cpp delete mode 100644 frameworks/native/backup_kit_inner/include/service_reverse_stub.h create mode 100644 frameworks/native/backup_kit_inner/src/service_client.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_proxy.cpp delete mode 100644 frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp create mode 100644 interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IExtension.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IService.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl create mode 100644 interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl rename interfaces/inner_api/native/backup_kit_inner/impl/{b_file_info.h => backup_file_info.h} (100%) rename interfaces/inner_api/native/backup_kit_inner/impl/{b_incremental_data.h => backup_incremental_data.h} (100%) delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service.h delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h rename services/backup_sa/include/module_ipc/svc_extension_proxy.h => interfaces/inner_api/native/backup_kit_inner/impl/service_client.h (35%) rename interfaces/inner_api/native/backup_kit_inner/impl/{i_extension.h => service_common.h} (34%) delete mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h delete mode 100644 services/backup_sa/include/module_ipc/service_reverse_proxy.h delete mode 100644 services/backup_sa/include/module_ipc/service_stub.h delete mode 100644 services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/service_reverse_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/service_stub.cpp delete mode 100644 services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp delete mode 100644 services/backup_sa/src/module_ipc/svc_extension_proxy.cpp create mode 100644 tests/mock/backup_kit_inner/service_client_mock.cpp create mode 100644 tests/mock/module_ipc/extension_proxy_mock.cpp create mode 100644 tests/mock/module_ipc/extension_type_mock.cpp create mode 100644 tests/mock/module_ipc/include/extension_proxy_mock.h delete mode 100644 tests/unittests/backup_api/backup_impl/service_proxy_test.cpp delete mode 100644 tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp delete mode 100644 tests/unittests/backup_ext/ext_extension_stub_test.cpp create mode 100644 tests/unittests/backup_sa/module_client/BUILD.gn create mode 100644 tests/unittests/backup_sa/module_client/service_client_test.cpp create mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp create mode 100644 tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.cpp create mode 100644 tests/unittests/backup_sa/session/service_client_mock.h diff --git a/backup.gni b/backup.gni index 3b07587da..a23d5e191 100644 --- a/backup.gni +++ b/backup.gni @@ -41,7 +41,8 @@ backup_mock_src = [ "$path_backup_mock/module_ipc/service_reverse_proxy_mock.cpp", "$path_backup_mock/module_ipc/service_stub_mock.cpp", "$path_backup_mock/module_ipc/svc_backup_connection_mock.cpp", - "$path_backup_mock/module_ipc/svc_extension_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_type_mock.cpp", ] backup_mock_session_manager_src = [ "$path_backup_mock/module_ipc/svc_session_manager_mock.cpp" ] @@ -55,6 +56,7 @@ backup_mock_service_src = [ "$path_backup_mock/module_ipc/service_mock.cpp" ] backup_mock_utils_include = [ "$path_backup_mock/utils_mock/include" ] backup_mock_proxy_src = [ "$path_backup_mock/backup_kit_inner/service_proxy_mock.cpp", + "$path_backup_mock/module_ipc/extension_type_mock.cpp", "$path_backup_mock/utils_mock/src/utils_mock_global_variable.cpp", "$path_backup/frameworks/native/backup_kit_inner/src/b_file_info.cpp", ] diff --git a/bundle.json b/bundle.json index d81e5f73a..3bda61564 100644 --- a/bundle.json +++ b/bundle.json @@ -138,17 +138,13 @@ "header_files": [ "backup_kit_inner.h", "impl/b_incremental_backup_session.h", - "impl/b_incremental_data.h", + "impl/backup_incremental_data.h", "impl/b_incremental_restore_session.h", "impl/b_session_restore.h", "impl/b_session_restore_async.h", - "impl/b_file_info.h", - "impl/service_proxy.h", - "impl/b_session_backup.h", - "impl/i_service_ipc_interface_code.h", - "impl/i_service_reverse_ipc_interface_code.h", - "impl/i_service.h", - "impl/i_service_reverse.h" + "impl/backup_file_info.h", + "impl/service_client.h", + "impl/b_session_backup.h" ] } }, diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index ec60d87cd..6a0a7ebcc 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -33,7 +33,6 @@ ohos_shared_library("backup_extension_ability_native") { "src/ext_backup_js.cpp", "src/ext_backup_loader.cpp", "src/ext_extension.cpp", - "src/ext_extension_stub.cpp", "src/sub_ext_extension.cpp", "src/tar_file.cpp", "src/untar_file.cpp", @@ -50,10 +49,12 @@ ohos_shared_library("backup_extension_ability_native") { "${path_ability_runtime}/services/common/include", "${path_ability_runtime}/interfaces/kits/napi/aafwk/inner/napi_common", "${path_ability_runtime}/interfaces/kits/native/appkit/ability_runtime", + "${path_backup}/services/backup_sa/include/module_ipc", ] deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index db933dad2..36cefbbab 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -29,8 +29,9 @@ #include "b_json/b_report_entity.h" #include "b_radar/b_radar.h" #include "ext_backup_js.h" -#include "ext_extension_stub.h" -#include "i_service.h" +#include "extension_stub.h" +#include "service_common.h" +#include "iservice.h" #include "tar_file.h" #include "thread_pool.h" #include "timer.h" @@ -41,20 +42,23 @@ namespace OHOS::FileManagement::Backup { using CompareFilesResult = tuple, map, map>; -class BackupExtExtension : public ExtExtensionStub { +class BackupExtExtension : public ExtensionStub { public: - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override; + ErrCode GetFileHandleWithUniqueFd( + const std::string& fileName, + int32_t& getFileHandleErrCode, + int& fd) override; ErrCode HandleClear() override; ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleBackup(bool isClearData) override; ErrCode HandleRestore(bool isClearData) override; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override; + ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) override; ErrCode PublishIncrementalFile(const std::string &fileName) override; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; + ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) override; ErrCode IncrementalOnBackup(bool isClearData) override; - std::tuple GetIncrementalBackupFileHandle() override; + ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) override; ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; + ErrCode UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); void AsyncTaskIncrementalRestoreForUpgrade(void); @@ -336,6 +340,10 @@ private: void ClearNoPermissionFiles(TarMap &pkgInfo, vector &noPermissionFiles); std::function ReportOnProcessResultCallback(wptr obj, BackupRestoreScenario scenario); + UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode); + std::tuple GetIncrementalFileHandle(const std::string &fileName); + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd); + std::tuple GetIncrementalBackupFileHandle(); private: std::shared_mutex lock_; diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h deleted file mode 100644 index d969b3e9b..000000000 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H -#define OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H - -#include - -#include "i_extension.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ExtExtensionStub : public IRemoteStub { -public: - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ExtExtensionStub(); - ~ExtExtensionStub() = default; - -private: - ErrCode CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleClear(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdPublishFile(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleRestore(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleIncrementalBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdIncrementalOnBackup(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply); - ErrCode CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - ErrCode CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply); - ErrCode CmdHandleUser0Backup(MessageParcel &data, MessageParcel &reply); - -private: - using ExtensionInterface = int32_t (ExtExtensionStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_H \ No newline at end of file diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index e75dcf5f8..94e4a1e76 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -34,7 +34,8 @@ #include "ext_backup_js.h" #include "ext_extension.h" #include "filemgmt_libhilog.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 1119285af..03a2f4824 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -53,9 +53,10 @@ #include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "service_common.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" +#include "extension_type.h" #include "tar_file.h" namespace OHOS::FileManagement::Backup { @@ -239,6 +240,14 @@ static UniqueFd GetFileHandleForSpecialCloneCloud(const string &fileName) } return fd; } +ErrCode BackupExtExtension::GetFileHandleWithUniqueFd(const std::string &fileName, + int32_t &getFileHandleErrCode, + int &fd) +{ + UniqueFd fileHandleFd(GetFileHandle(fileName, getFileHandleErrCode)); + fd = fileHandleFd.Release(); + return ERR_OK; +} UniqueFd BackupExtExtension::GetFileHandle(const string &fileName, int32_t &errCode) { @@ -299,8 +308,9 @@ static tuple GetIncreFileHandleForSpecialVersion(co UniqueFd fd = GetFileHandleForSpecialCloneCloud(fileName); if (fd < 0) { HILOGE("Failed to open file = %{private}s, err = %{public}d", fileName.c_str(), errno); - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForSpecialVersion", "CommonFile", GetAnonyPath(fileName)}; + AuditLog auditLog = { + false, "Open fd failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForSpecialVersion", + "CommonFile", GetAnonyPath(fileName)}; HiAudit::GetInstance(false).Write(auditLog); errCode = errno; } @@ -309,8 +319,9 @@ static tuple GetIncreFileHandleForSpecialVersion(co if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { HILOGE("Failed to create restore folder : %{private}s, err = %{public}d", path.c_str(), errno); errCode = errno; - AuditLog auditLog = {false, "mkdir failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForSpecialVersion", "CommonFile", GetAnonyPath(path)}; + AuditLog auditLog = { + false, "mkdir failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForSpecialVersion", + "CommonFile", GetAnonyPath(path)}; HiAudit::GetInstance(false).Write(auditLog); } string reportName = path + BConstants::BLANK_REPORT_NAME; @@ -358,15 +369,16 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm break; } if (access(tarName.c_str(), F_OK) == 0) { - HILOGE("The file already exists, tarname = %{public}s, err =%{public}d", - GetAnonyPath(tarName).c_str(), errno); + HILOGE("The file already exists, tarname = %{public}s, err =%{public}d", GetAnonyPath(tarName).c_str(), + errno); } fd = UniqueFd(open(tarName.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("Failed to open tar file = %{public}s, err = %{public}d", GetAnonyPath(tarName).c_str(), errno); errCode = errno; - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", - "GetIncreFileHandleForNormalVersion", "CommonFile", GetAnonyPath(tarName)}; + AuditLog auditLog = { + false, "Open fd failed", "ADD", "", 1, "FAILED", "GetIncreFileHandleForNormalVersion", + "CommonFile", GetAnonyPath(tarName)}; HiAudit::GetInstance(false).Write(auditLog); break; } @@ -385,6 +397,17 @@ tuple BackupExtExtension::GetIncreFileHandleForNorm return {errCode, move(fd), move(reportFd)}; } +ErrCode BackupExtExtension::GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, + UniqueFdGroup &fdGroup) +{ + 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(); + return ERR_OK; +} + tuple BackupExtExtension::GetIncrementalFileHandle(const string &fileName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -395,12 +418,12 @@ tuple BackupExtExtension::GetIncrementalFileHandle( } if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { HILOGE("Failed to get incremental file handle, action is invalid, action %{public}d.", - extension_->GetExtensionAction()); + extension_->GetExtensionAction()); throw BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid"); } VerifyCaller(); if (BDir::CheckFilePathInvalid(fileName)) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_IPC, string("Failed to AGetInstance")); } @@ -459,10 +482,10 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) cache.SetExtManage(pkgInfo); cachedEntity.Persist(); close(cachedEntity.GetFd().Release()); - + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); ErrCode ret = - proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)), - ERR_OK); + proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + ERR_OK); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully"); } else { @@ -500,8 +523,8 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro WaitToSendFd(startTime, fdNum); int32_t errCode = ERR_OK; string filePath = std::get<0>(item.second); - UniqueFd fd(open(filePath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(filePath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(filePath).c_str(), errno); errCode = errno; @@ -513,7 +536,7 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro continue; } } - ret = proxy->AppFileReady(item.first, std::move(fd), errCode); + ret = proxy->AppFileReady(item.first, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully, package name is %{public}s", item.first.c_str()); } else { @@ -685,15 +708,15 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string tarPath = path + tarName; int32_t errCode = ERR_OK; - UniqueFd fd(open(tarPath.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(tarPath.data(), O_RDONLY); + if (fdval < 0) { HILOGE("TarFileReady open file failed, file name is %{public}s, err = %{public}d", tarName.c_str(), errno); errCode = errno; AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", "TarFileReady", "tarFile", tarPath}; HiAudit::GetInstance(false).Write(auditLog); } - int ret = proxy->AppFileReady(tarName, std::move(fd), errCode); + int ret = proxy->AppFileReady(tarName, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("TarFileReady: AppFileReady success for %{public}s", tarName.c_str()); // 删除文件 @@ -776,7 +799,7 @@ int BackupExtExtension::DoBackup(TarMap &bigFileInfo, map &small return EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -841,9 +864,9 @@ bool BackupExtExtension::RefreshDataSize(int64_t totalSize) HILOGI("no backup datasize, don't need to refresh"); return true; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("start RefreshDatasize by ipc"); @@ -1709,9 +1732,9 @@ void BackupExtExtension::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("AppDone Begin."); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -1724,8 +1747,8 @@ void BackupExtExtension::AppDone(ErrCode errCode) void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("restoreRetInfo is %{public}s", restoreRetInfo.c_str()); auto ret = proxy->ServiceResultReport(restoreRetInfo, scenario, errCode); if (ret != ERR_OK) { @@ -1735,8 +1758,8 @@ void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, void BackupExtExtension::StartExtTimer(bool &isExtStart) { - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start ext timer by ipc."); auto ret = proxy->StartExtTimer(isExtStart); if (ret != ERR_OK) { @@ -1747,8 +1770,8 @@ void BackupExtExtension::StartExtTimer(bool &isExtStart) void BackupExtExtension::StartFwkTimer(bool &isFwkStart) { HILOGI("Do backup, start fwk timer begin."); - auto proxy = ServiceProxy::GetInstance(); - BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); + auto proxy = ServiceClient::GetInstance(); + BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceClient handle"); HILOGI("Start fwk timer by ipc."); auto ret = proxy->StartFwkTimer(isFwkStart); if (ret != ERR_OK) { @@ -1761,9 +1784,9 @@ bool BackupExtExtension::StopExtTimer() { HILOGI("StopExtTimer start"); bool isExtStop; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); return false; } HILOGI("StopExtTimer by ipc"); @@ -1896,6 +1919,17 @@ void BackupExtExtension::FillFileInfos(UniqueFd incrementalFd, allFiles.size(), smallFiles.size(), bigFiles.size()); } +ErrCode BackupExtExtension::HandleIncrementalBackup(int incrementalFd, int manifestFd) +{ + HILOGI("Start HandleIncrementalBackup. incrementalFd:%{public}d, manifestFd:%{public}d", incrementalFd, manifestFd); + UniqueFd incrementalFdUnique(dup(incrementalFd)); + UniqueFd manifestFdUnique(dup(manifestFd)); + ErrCode ret = HandleIncrementalBackup(std::move(incrementalFdUnique), std::move(manifestFdUnique)); + close(incrementalFd); + close(manifestFd); + return ret; +} + ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1925,6 +1959,14 @@ ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) return ERR_OK; } +ErrCode BackupExtExtension::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup& fdGroup) +{ + auto [fd, reportFd] = GetIncrementalBackupFileHandle(); + fdGroup.fd = fd.Get(); + fdGroup.reportFd = reportFd.Get(); + return BError(BError::Codes::OK).GetCode(); +} + tuple BackupExtExtension::GetIncrementalBackupFileHandle() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1961,7 +2003,8 @@ static void WriteFile(const string &filename, const vector &srcFiles, sptr proxy) + const vector &srcFiles, + sptr proxy) { string tarFile = bigFileInfo.begin()->first; string manageFile = GetReportFileName(tarFile); @@ -1969,8 +2012,9 @@ ErrCode BackupExtExtension::IncrementalTarFileReady(const TarMap &bigFileInfo, WriteFile(file, srcFiles); string tarName = string(INDEX_FILE_INCREMENTAL_BACKUP).append(tarFile); - ErrCode ret = proxy->AppIncrementalFileReady(tarFile, UniqueFd(open(tarName.data(), O_RDONLY)), - UniqueFd(open(file.data(), O_RDONLY)), ERR_OK); + int fd = open(tarName.data(), O_RDONLY); + int manifestFd = open(file.data(), O_RDONLY); + ErrCode ret = proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalTarFileReady: The application is packaged successfully"); // 删除文件 @@ -2000,8 +2044,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, auto [path, sta, isBeforeTar] = item.second; int32_t errCode = ERR_OK; WaitToSendFd(startTime, fdNum); - UniqueFd fd(open(path.data(), O_RDONLY)); - if (fd < 0) { + int fdval = open(path.data(), O_RDONLY); + if (fdval < 0) { HILOGE("IncrementalBigFileReady open file failed, file name is %{public}s, err = %{public}d", GetAnonyString(path).c_str(), errno); errCode = errno; @@ -2019,7 +2063,8 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, } string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); WriteFile(file, bigInfo); - ret = proxy->AppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY)), errCode); + int manifestFdval = open(file.data(), O_RDONLY); + ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); if (SUCCEEDED(ret)) { HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", item.first.c_str()); @@ -2051,11 +2096,11 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append("all")); WriteFile(file, srcFiles); - UniqueFd fd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)); - UniqueFd manifestFd(open(file.data(), O_RDONLY)); + int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); + int manifestFdval = open(file.data(), O_RDONLY); ErrCode ret = - proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), std::move(fd), std::move(manifestFd), - ERR_OK); + proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, + manifestFdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalAllFileReady successfully"); RemoveFile(file); diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp deleted file mode 100644 index 38f4ce2f3..000000000 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ /dev/null @@ -1,266 +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 "ext_extension_stub.h" - -#include -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ExtExtensionStub::ExtExtensionStub() -{ - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_CLAER)] = - &ExtExtensionStub::CmdHandleClear; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_BACKUP)] = - &ExtExtensionStub::CmdHandleBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_PUBLISH_FILE)] = - &ExtExtensionStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_RESTORE)] = - &ExtExtensionStub::CmdHandleRestore; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_PUBLISH_INCREMENTAL_FILE)] = - &ExtExtensionStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_INCREMENTAL_BACKUP)] = - &ExtExtensionStub::CmdHandleIncrementalBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE)] = - &ExtExtensionStub::CmdGetIncrementalBackupFileHandle; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_BACKUP_INFO)] = - &ExtExtensionStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_INCREMENTAL_ON_BACKUP)] = - &ExtExtensionStub::CmdIncrementalOnBackup; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE)] = - &ExtExtensionStub::CmdUpdateFdSendRate; - opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_HANDLE_USER_0_BACKUP)] = - &ExtExtensionStub::CmdHandleUser0Backup; -} - -int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, - MessageParcel &reply, - MessageOption &option) -{ - const std::u16string descriptor = ExtExtensionStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::EXT_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGI("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -ErrCode ExtExtensionStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - int32_t errCode = ERR_OK; - UniqueFd fd = GetFileHandle(fileName, errCode); - bool fdFlag = fd < 0 ? false : true; - reply.WriteBool(fdFlag); - reply.WriteInt32(errCode); - if (fdFlag == true && !reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleClear(MessageParcel &data, MessageParcel &reply) -{ - ErrCode res = HandleClear(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleBackup(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = HandleBackup(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName"); - } - - ErrCode res = PublishFile(fileName); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleRestore(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = HandleRestore(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - auto[errCode, fd, reportFd] = GetIncrementalFileHandle(fileName); - if (!reply.WriteInt32(errCode)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(reportFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName"); - } - - ErrCode res = PublishIncrementalFile(fileName); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd incrementalFd(data.ReadFileDescriptor()); - UniqueFd manifestFd(data.ReadFileDescriptor()); - ErrCode res = HandleIncrementalBackup(move(incrementalFd), move(manifestFd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdIncrementalOnBackup(MessageParcel &data, MessageParcel &reply) -{ - bool isClearData = true; - isClearData = data.ReadBool(); - ErrCode res = IncrementalOnBackup(isClearData); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::EXT_BROKEN_IPC, ss.str()).GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply) -{ - auto [incrementalFd, manifestFd] = GetIncrementalBackupFileHandle(); - if (!reply.WriteFileDescriptor(incrementalFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - if (!reply.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the file").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("CmdGetBackupInfo Begin"); - std::string result; - int ret = GetBackupInfo(result); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the result").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGD("CmdUpdateFdSendRate Begin"); - std::string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive sendRate").GetCode(); - } - int ret = UpdateFdSendRate(bundleName, sendRate); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - return BError(BError::Codes::OK); -} - -ErrCode ExtExtensionStub::CmdHandleUser0Backup(MessageParcel &data, MessageParcel &reply) -{ - HILOGD("CmdHandleUser0Backup Begin"); - int ret = User0OnBackup(); - if (!reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); - } - return BError(BError::Codes::OK); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 24e2a9c11..08f46d26b 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -51,9 +51,9 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" -#include "i_service.h" +#include "service_common.h" #include "sandbox_helper.h" -#include "service_proxy.h" +#include "service_client.h" #include "tar_file.h" #include "b_anony/b_anony.h" @@ -483,7 +483,7 @@ std::function BackupExtExtension::IncOnBackupC HILOGI("Begin get IncOnBackupCallback"); return [obj](ErrCode errCode, std::string errMsg) { HILOGI("App onbackup end"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -525,7 +525,7 @@ std::function BackupExtExtension::IncOnBackupE { HILOGI("Begin get HandleIncBackupEx callback"); return [obj](ErrCode errCode, const std::string backupExRetInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } @@ -575,7 +575,7 @@ std::function BackupExtExtension::IncOnBackupE void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Report app process error, proxy is empty"); return; @@ -739,9 +739,9 @@ void BackupExtExtension::CloseOnProcessTimeOutTimer() void BackupExtExtension::AppIncrementalDone(ErrCode errCode) { HILOGI("Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { - HILOGE("Failed to obtain the ServiceProxy handle"); + HILOGE("Failed to obtain the ServiceClient handle"); DoClear(); return; } @@ -785,7 +785,7 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result) return ERR_OK; } -ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) +ErrCode BackupExtExtension::UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) { try { std::lock_guard lock(updateSendRateLock_); @@ -1173,7 +1173,7 @@ int BackupExtExtension::DoIncrementalBackup(const vector if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { throw BError(errno); } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index c19668973..5973451df 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -25,39 +25,53 @@ namespace OHOS::FileManagement::Backup { class ServiceReverse final : public ServiceReverseStub { public: - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void BackupOnResultReport(std::string result, std::string bundleName) override; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void BackupOnAllBundlesFinished(int32_t errCode) override; - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void BackupOnScanningInfo(std::string scannedInfo) override; + ErrCode BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override; + ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override; + ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode BackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; + ErrCode BackupOnScanningInfo(const std::string &scannedInfo) override; - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void RestoreOnAllBundlesFinished(int32_t errCode) override; - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override; + ErrCode RestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode = 0) override; + ErrCode RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override; + ErrCode IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override; + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override; + ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalBackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; + ErrCode IncrementalBackupOnScanningInfo(const std::string &scannedInfo) override; - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override; + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override; + ErrCode IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode) override; + ErrCode IncrementalRestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override; public: ServiceReverse() = delete; diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h deleted file mode 100644 index 53a4964aa..000000000 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H - -#include - -#include "i_service_reverse.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceReverseStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceReverseStub(); - ~ServiceReverseStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceReverseStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply); - - int32_t CmdIncrementalRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdIncrementalRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply); - void ServiceReverseStubSupplement(); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_STUB_H diff --git a/frameworks/native/backup_kit_inner/src/b_file_info.cpp b/frameworks/native/backup_kit_inner/src/b_file_info.cpp index e068da158..883fe8964 100644 --- a/frameworks/native/backup_kit_inner/src/b_file_info.cpp +++ b/frameworks/native/backup_kit_inner/src/b_file_info.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_file_info.h" +#include "backup_file_info.h" #include "filemgmt_libhilog.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index 97de333ab..a9d589c33 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -18,7 +18,7 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -30,7 +30,7 @@ BIncrementalBackupSession::~BIncrementalBackupSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,14 +46,14 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - - int32_t res = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks))); + sptr reverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitIncrementalBackupSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); @@ -76,13 +76,14 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks try { HILOGI("Init IncrementalBackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr newProxy = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitIncrementalBackupSessionWithErrMsg(newProxy, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +102,7 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks void BIncrementalBackupSession::RegisterBackupServiceDied(function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +112,7 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -122,12 +123,14 @@ void BIncrementalBackupSession::RegisterBackupServiceDied(function funct UniqueFd BIncrementalBackupSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -138,7 +141,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -153,7 +156,7 @@ ErrCode BIncrementalBackupSession::GetBackupDataSize(bool isPreciseScan, vector< ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -174,12 +177,12 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, std::vector infos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + int32_t res = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { @@ -194,7 +197,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle ErrCode BIncrementalBackupSession::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -205,7 +208,7 @@ ErrCode BIncrementalBackupSession::Release() ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp index 571805e51..a0a5b1037 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "filemgmt_libhilog.h" #include "message_parcel.h" diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 97468695a..1bfe24faf 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -18,9 +18,9 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" - +#include "service_common.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -30,7 +30,7 @@ BIncrementalRestoreSession::~BIncrementalRestoreSession() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,13 +46,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks))); + sptr session = sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitRestoreSession(session); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -75,15 +76,16 @@ unique_ptr BIncrementalRestoreSession::Init(Callback try { HILOGI("Init IncrementalRestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { errMsg = "Failed to get backup service"; errCode = BError(BError::Codes::SDK_BROKEN_IPC); HILOGE("Init IncrementalRestoreSession failed, %{public}s", errMsg.c_str()); return nullptr; } - errCode = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr session = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitRestoreSessionWithErrMsg(session, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", errCode); AppRadar::Info info ("", "", "create restore session failed"); @@ -104,12 +106,14 @@ unique_ptr BIncrementalRestoreSession::Init(Callback UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -119,7 +123,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -128,16 +132,17 @@ ErrCode BIncrementalRestoreSession::PublishFile(BFileInfo fileInfo) ErrCode BIncrementalRestoreSession::PublishSAFile(BFileInfo fileInfo, UniqueFd fd) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->PublishSAIncrementalFile(fileInfo, move(fd)); + int fdValue = fd.Get(); + return proxy->PublishSAIncrementalFile(fileInfo, fdValue); } ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -147,11 +152,12 @@ ErrCode BIncrementalRestoreSession::GetFileHandle(const string &bundleName, cons ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -159,19 +165,23 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -179,14 +189,15 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -207,7 +218,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -217,7 +228,7 @@ void BIncrementalRestoreSession::RegisterBackupServiceDied(function func ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 170a50db6..9f2aa0e9d 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -19,7 +19,7 @@ #include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -31,7 +31,7 @@ BIncrementalSessionRestoreAsync::~BIncrementalSessionRestoreAsync() HILOGE("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -47,8 +47,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return nullptr; @@ -60,7 +60,8 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini .onAllBundlesFinished = callbacks.onAllBundlesFinished, .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied}; - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); + sptr reverse = sptr(new ServiceReverse(callbacksTmp)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -79,16 +80,17 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini ErrCode BIncrementalSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } + return proxy->PublishIncrementalFile(fileInfo); } ErrCode BIncrementalSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -102,12 +104,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fdCode, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -125,11 +129,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int fdCode = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fdCode, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -137,24 +144,24 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BIncrementalSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->Release(); } void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -171,7 +178,7 @@ void BIncrementalSessionRestoreAsync::RegisterBackupServiceDied(std::function BSessionBackup::Init(Callbacks callbacks) try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - - int32_t res = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks))); + sptrreverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitBackupSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); @@ -76,13 +76,14 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, try { HILOGI("Init BackupSession Begin"); auto backup = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - errCode = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks)), errMsg); + sptr session = sptr(new ServiceReverse(callbacks)); + errCode = proxy->InitBackupSessionWithErrMsg(session, errMsg); if (errCode != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", errCode); AppRadar::Info info("", "", ""); @@ -101,7 +102,7 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks, void BSessionBackup::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -111,7 +112,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) } auto callback = [functor](const wptr &obj) { - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); HILOGI("Backup service died"); functor(); }; @@ -121,7 +122,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) ErrCode BSessionBackup::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -132,12 +133,14 @@ ErrCode BSessionBackup::Start() UniqueFd BSessionBackup::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -148,7 +151,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) { HILOGI("GetBackupDataSize Begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); @@ -163,7 +166,7 @@ ErrCode BSessionBackup::GetBackupDataSize(bool isPreciseScan, vector bundlesToBackup) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -183,7 +186,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -203,7 +206,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector ErrCode BSessionBackup::Finish() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -213,7 +216,7 @@ ErrCode BSessionBackup::Finish() ErrCode BSessionBackup::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -224,7 +227,7 @@ ErrCode BSessionBackup::Release() ErrCode BSessionBackup::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 21fbc125f..1dbfa2040 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -18,8 +18,9 @@ #include "b_error/b_error.h" #include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -30,7 +31,7 @@ BSessionRestore::~BSessionRestore() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -46,13 +47,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) try { HILOGI("Init RestoreSession Begin"); auto restore = make_unique(); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; } - int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacks)); + sptrreverse=sptr(new ServiceReverse(callbacks)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -72,12 +74,14 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) UniqueFd BSessionRestore::GetLocalCapabilities() { HILOGI("GetLocalCapabilities begin"); - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Failed to get backup service"); return UniqueFd(-EPERM); } - UniqueFd fd = proxy->GetLocalCapabilitiesForBundleInfos(); + int fdvalue = -1; + proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); + UniqueFd fd(static_cast(fdvalue)); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); @@ -87,7 +91,8 @@ UniqueFd BSessionRestore::GetLocalCapabilities() ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("PublishFile begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -96,7 +101,7 @@ ErrCode BSessionRestore::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestore::Start() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -106,7 +111,7 @@ ErrCode BSessionRestore::Start() ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -114,14 +119,18 @@ ErrCode BSessionRestore::GetFileHandle(const string &bundleName, const string &f return proxy->GetFileHandle(bundleName, fileName); } -ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos) +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + std::vector detailInfos) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("AppendBundles begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -129,18 +138,21 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("AppendBundles begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + int32_t remoteCapInt = remoteCap.Get(); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -148,14 +160,16 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestore::Finish() { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("Finish begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -165,7 +179,8 @@ ErrCode BSessionRestore::Finish() ErrCode BSessionRestore::Release() { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("Release begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -175,7 +190,8 @@ ErrCode BSessionRestore::Release() void BSessionRestore::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + HILOGI("RegisterBackupServiceDied begin"); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -186,7 +202,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); - ServiceProxy::InvaildInstance(); + ServiceClient::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); @@ -195,8 +211,9 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) ErrCode BSessionRestore::Cancel(std::string bundleName) { + HILOGI("Cancel begin"); ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index a60c56462..2bbbb4a8b 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -20,7 +20,7 @@ #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" -#include "service_proxy.h" +#include "service_client.h" #include "service_reverse.h" namespace OHOS::FileManagement::Backup { @@ -32,7 +32,7 @@ BSessionRestoreAsync::~BSessionRestoreAsync() HILOGI("Death Recipient is nullptr"); return; } - auto proxy = ServiceProxy::GetServiceProxyPointer(); + auto proxy = ServiceClient::GetServiceProxyPointer(); if (proxy == nullptr) { return; } @@ -48,8 +48,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGI("Failed to get backup service"); return nullptr; @@ -61,7 +61,8 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied, .onProcess = callbacks.onProcess}; - int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); + sptr reverse = sptr(new ServiceReverse(callbacksTmp)); + int32_t res = proxy->InitRestoreSession(reverse); if (res != ERR_OK) { HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); @@ -80,7 +81,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -89,7 +90,7 @@ ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -103,12 +104,14 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, - userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, + restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -126,12 +129,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + int32_t remoteCapInt = remoteCap.Get(); + int32_t restoreTypeInt = static_cast(restoreType); + ErrCode res = + proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -139,14 +145,15 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } return res; } ErrCode BSessionRestoreAsync::Release() { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } @@ -156,7 +163,7 @@ ErrCode BSessionRestoreAsync::Release() void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr || !functor) { return; } @@ -173,7 +180,7 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct ErrCode BSessionRestoreAsync::Cancel(std::string bundleName) { ErrCode result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { HILOGE("Called Cancel, failed to get proxy."); return result; diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp new file mode 100644 index 000000000..5451bd047 --- /dev/null +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + unique_lock getInstanceLock(getInstanceMutex_); + unique_lock lock(proxyMutex_); + if (serviceProxy_ != nullptr) { + return serviceProxy_; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOGE("Get an empty samgr"); + return nullptr; + } + sptr loadCallback = sptr(new ServiceProxyLoadCallback()); + if (loadCallback == nullptr) { + HILOGE("loadCallback is nullptr."); + return nullptr; + } + int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); + if (ret != ERR_OK) { + HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", + FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); + return nullptr; + } + + auto waitStatus = + loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), + [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); + if (!waitStatus) { + HILOGE("Load backup sa timeout"); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceClient::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + BError(BError::Codes::SA_INVAL_ARG).GetCode()); + return nullptr; + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Invalid Instance"); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Load backup sa success, systemAbilityId: %{public}d, remoteObject result:%{public}s", systemAbilityId, + (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + unique_lock lock(proxyMutex_); + std::string remoteDescriptor = Str16ToStr8(remoteObject->GetInterfaceDescriptor()); + HILOGE("GetInterfaceDescriptor result:%{public}s", remoteDescriptor.c_str()); + serviceProxy_ = iface_cast(remoteObject); + if (serviceProxy_ == nullptr) { + HILOGE("serviceProxy_ is nullptr"); + return; + } + auto remoteObj = serviceProxy_->AsObject(); + if (!remoteObj) { + HILOGE("Failed to get remote object"); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + proxyConVar_.notify_one(); + return; + } + + auto callback = [](const wptr &obj) { + ServiceClient::InvaildInstance(); + HILOGE("Backup service died"); + }; + sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); + remoteObj->AddDeathRecipient(deathRecipient); + isLoadSuccess_.store(true); + proxyConVar_.notify_one(); +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; + isLoadSuccess_.store(false); + AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, + static_cast(BError::Codes::SA_INVAL_ARG)); + proxyConVar_.notify_one(); +} +} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp deleted file mode 100644 index bbb503bfa..000000000 --- a/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "service_proxy.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "svc_death_recipient.h" -#include "unique_fd.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::Release() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - if (!WriteParcelableVector(bundleNames, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL), data, reply, - option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - HILOGE("Empty reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - HILOGE("Failed to send the reverse stub"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION), data, - reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!WriteParcelableVector(bundlesToBackup, data)) { - HILOGE("Failed to send the bundleNames"); - return UniqueFd(-EPERM); - } - - if (!data.WriteStringVector(infos)) { - HILOGE("Failed to write infos"); - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - MessageParcel reply; - MessageOption option; - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return BError(BError::Codes::SDK_INVAL_ARG, "Received error when doing IPC").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - if (!data.WriteFileDescriptor(fd)) { - HILOGE("Failed to send the fd"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (fdFlag == true && !data.WriteFileDescriptor(manifestFd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -template -bool ServiceProxy::WriteParcelableVector(const std::vector &parcelableVector, Parcel &data) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!data.WriteUint32(parcelableVector.size())) { - HILOGE("failed to WriteInt32 for parcelableVector.size()"); - return false; - } - - for (const auto &parcelable : parcelableVector) { - if (!data.WriteParcelable(&parcelable)) { - HILOGE("failed to WriteParcelable for parcelable"); - return false; - } - } - - return true; -} - -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!Remote()) { - return BError(BError::Codes::SDK_INVAL_ARG, "Remote is nullptr").GetCode(); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadInt32(result); - HILOGI("ServiceProxy Cancel end, result:%{public}d", result); - - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index 81f6ed9e6..d1f32b5db 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -22,137 +22,162 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) +ErrCode ServiceReverse::IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksIncrementalBackup_.onFileReady(bFileInfo, UniqueFd(fd), UniqueFd(manifestFd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnResultReport(const std::string& result, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksIncrementalBackup_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::IncrementalBackupOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalBackupOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onProcess) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnScanningInfo(std::string scannedInfo) +ErrCode ServiceReverse::IncrementalBackupOnScanningInfo(const std::string& scannedInfo) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBackupSizeReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalBackup_.onBackupSizeReport(scannedInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksIncrementalRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) +ErrCode ServiceReverse::IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) { + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG); + } if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksIncrementalRestore_.onFileReady(bFileInfo, UniqueFd(fd), UniqueFd(manifestFd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) +ErrCode ServiceReverse::IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + ErrCode errCode) { HILOGI("begin incremental restore on result report, bundleName:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalRestoreOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("begin incremental report processInfo, bundleName:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onProcess) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksIncrementalRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BIncrementalBackupSession::Callbacks callbacks) diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp deleted file mode 100644 index 187f69ef7..000000000 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ /dev/null @@ -1,839 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_radar/b_radar.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "system_ability_definition.h" -#include "svc_death_recipient.h" -#include "hitrace_meter.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -ErrCode ServiceProxy::InitRestoreSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } - if (!data.WriteRemoteObject(remote->AsObject().GetRefPtr())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - if (!reply.ReadString(errMsg)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to receive the errMsg").GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Start() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -UniqueFd ServiceProxy::GetLocalCapabilities() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - AppRadar::Info resInfo("", "", ""); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, "ServiceProxy::GetLocalCapabilities", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_GET_LOCAL_CAPABILITIES_FAIL, ret); - return UniqueFd(-ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - return UniqueFd(fd.Release()); -} - -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteParcelable(&fileInfo)) { - HILOGE("Failed to send the fileInfo"); - return -EPIPE; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the filename").GetCode(); - } - bool fdFlag = fd < 0 ? false : true; - data.WriteBool(fdFlag); - if (fdFlag == true && !data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(restoreRetInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the restoreRetInfo").GetCode(); - } - if (!data.WriteInt32(static_cast(scenario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - if (!data.WriteInt32(errCode)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the errCode").GetCode(); - } - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the bundleName").GetCode(); - } - if (!data.WriteString(fileName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fileName").GetCode(); - } - - MessageParcel reply; - MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), data, - reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return ret; -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!detailInfos.empty() && !data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL), data, reply, - option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); - } - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - if (!data.WriteInt32(static_cast(restoreType))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); - } - if (!data.WriteInt32(userId)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &detailInfos) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - - if (!data.WriteStringVector(bundleNames)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); - } - - if (!data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } - - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -ErrCode ServiceProxy::Finish() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return reply.ReadInt32(); -} - -sptr ServiceProxy::GetServiceProxyPointer() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - unique_lock getInstanceLock(getInstanceMutex_); - unique_lock lock(proxyMutex_); - if (serviceProxy_ != nullptr) { - return serviceProxy_; - } - - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { - HILOGE("Get an empty samgr"); - return nullptr; - } - sptr loadCallback = sptr(new ServiceProxyLoadCallback()); - if (loadCallback == nullptr) { - HILOGE("loadCallback is nullptr."); - return nullptr; - } - int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, loadCallback); - if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility, systemAbilityId:%{private}d, ret code:%{public}d", - FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, ret); - return nullptr; - } - - auto waitStatus = - loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), - [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); - if (!waitStatus) { - HILOGE("Load backup sa timeout"); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - BError(BError::Codes::SA_INVAL_ARG).GetCode()); - return nullptr; - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("invalid instance"); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, - (remoteObject != nullptr) ? "true" : "false"); - if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - unique_lock lock(proxyMutex_); - serviceProxy_ = iface_cast(remoteObject); - if (serviceProxy_ == nullptr) { - HILOGD("serviceProxy_ is nullptr"); - return; - } - auto remoteObj = serviceProxy_->AsObject(); - if (!remoteObj) { - HILOGE("Failed to get remote object"); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - proxyConVar_.notify_one(); - return; - } - - auto callback = [](const wptr &obj) { - ServiceProxy::InvaildInstance(); - HILOGE("Backup service died"); - }; - sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); - remoteObj->AddDeathRecipient(deathRecipient); - isLoadSuccess_.store(true); - proxyConVar_.notify_one(); -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); - unique_lock lock(proxyMutex_); - serviceProxy_ = nullptr; - isLoadSuccess_.store(false); - AppRadar::Info info("", "", "\"reason\":\"Load backup sa fail\""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); - proxyConVar_.notify_one(); -} - -ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) -{ - HILOGI("ServiceProxy GetBackupInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadString(result); - HILOGI("ServiceProxy GetBackupInfo end. result = %s", result.c_str()); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) -{ - HILOGI("ServiceProxy UpdateTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteUint32(timeout)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send timeout").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateTimer end. result = %d", result); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) -{ - HILOGD("ServiceProxy UpdateSendRate Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(bundleName)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(sendRate)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(result); - HILOGI("ServiceProxy UpdateSendRate end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) -{ - HILOGD("ServiceProxy NotifyBundleProcessInfo Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteString(processInfo)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); - } - if (!data.WriteInt32(static_cast(sennario))) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the scenario").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()-> SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - HILOGI("ServiceProxy NotifyBundleProcessInfo end. ret = %{public}d", ret); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) -{ - HILOGI("ServiceProxy StartExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStart); - HILOGI("ServiceProxy StartExtTimer end. isExtStart = %d", isExtStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) -{ - HILOGI("ServiceProxy StartFwkTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isFwkStart); - HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) -{ - HILOGI("ServiceProxy StopExtTimer Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - reply.ReadBool(isExtStop); - HILOGI("ServiceProxy StopExtTimer end. isExtStop = %{public}d", isExtStop); - return BError(BError::Codes::OK, "success"); -} - -ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) -{ - HILOGI("ServiceProxy RefreshDatasize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteInt64(totalSize)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write totalSize").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE), - data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - bool result = false; - reply.ReadBool(result); - if (!result) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to Refresh Datasize").GetCode(); - } - return BError(BError::Codes::OK, "success"); -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("ServiceProxy, start GetLocalCapabilitiesForBundleInfos"); - if (Remote() == nullptr) { - HILOGE("Remote is nullptr"); - return UniqueFd(-EPERM); - } - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - HILOGE("Failed to write descriptor"); - return UniqueFd(-EPERM); - } - - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest(static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - } - UniqueFd fd(reply.ReadFileDescriptor()); - HILOGI("ServiceProxy, end GetLocalCapabilitiesForBundleInfos"); - return fd; -} - -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) -{ - HILOGI("ServiceProxy GetBackupDataSize Begin."); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); - } - if (!data.WriteBool(isPreciseScan)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write isPreciseScan").GetCode(); - } - if (!WriteParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write bundleNameList").GetCode(); - } - MessageParcel reply; - MessageOption option; - option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); - int32_t ret = Remote()->SendRequest( - static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE), data, reply, option); - if (ret != NO_ERROR) { - string str = "Failed to send out the request because of " + to_string(ret); - return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); - } - return BError(BError::Codes::OK, "success"); -} -} // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 100a0dd09..b84ceb9b9 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -21,137 +21,156 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksBackup_.onFileReady(bFileInfo, UniqueFd(fd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::BackupOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::BackupOnResultReport(const std::string& result, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::BackupOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksBackup_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::BackupOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::BackupOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onProcess) { HILOGI("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnScanningInfo(std::string scannedInfo) +ErrCode ServiceReverse::BackupOnScanningInfo(const std::string& scannedInfo) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBackupSizeReport) { HILOGE("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksBackup_.onBackupSizeReport(scannedInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleStarted(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleStarted) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleFinished(int32_t errCode, const std::string& bundleName) { if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } HILOGI("errCode = %{public}d, bundleName = %{public}s", errCode, bundleName.c_str()); callbacksRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnAllBundlesFinished(int32_t errCode) +ErrCode ServiceReverse::RestoreOnAllBundlesFinished(int32_t errCode) { HILOGI("errCode = %{public}d", errCode); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onAllBundlesFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) { HILOGD("begin, bundleName is:%{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } BFileInfo bFileInfo(bundleName, fileName, 0); callbacksRestore_.onFileReady(bFileInfo, UniqueFd(fd), errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode) +ErrCode ServiceReverse::RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) { HILOGI("ServiceReverse RestoreOnResultReport bundle %{public}s begin with result: %{public}s", bundleName.c_str(), - result.c_str()); + result.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onResultReport) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleFinished) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::RestoreOnProcessInfo(const std::string& bundleName, const std::string& processInfo) { HILOGI("bundleName = %{public}s", bundleName.c_str()); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onProcess) { HILOGI("Error scenario or callback is nullptr"); - return; + return BError(BError::Codes::SA_BROKEN_IPC); } callbacksRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BSessionBackup::Callbacks callbacks) diff --git a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp deleted file mode 100644 index 2fae0a24a..000000000 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "service_reverse_stub.h" - -#include -#include - -#include "b_error/b_error.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; -int32_t ServiceReverseStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, - MessageParcel &reply, - MessageOption &option) -{ - const std::u16string descriptor = ServiceReverseStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return (this->*(interfaceIndex->second))(data, reply); -} -void ServiceReverseStub::ServiceReverseStubSupplement() -{ - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SCANNED_INFO)] = - &ServiceReverseStub::CmdIncrementalBackupOnScanningInfo; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY)] = - &ServiceReverseStub::CmdIncrementalRestoreOnFileReady; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnBundleStarted; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdIncrementalRestoreOnResultReport; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnBundleFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalRestoreOnAllBundlesFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdIncrementalRestoreOnProcessInfo; -} - -ServiceReverseStub::ServiceReverseStub() -{ - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY)] = - &ServiceReverseStub::CmdBackupOnFileReady; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdBackupOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdBackupOnResultReport; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdBackupOnBundleFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdBackupOnAllBundlesFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdBackupOnProcessInfo; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SCANNED_INFO)] = - &ServiceReverseStub::CmdBackupOnScanningInfo; - - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY)] = - &ServiceReverseStub::CmdRestoreOnFileReady; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdRestoreOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT)] = - &ServiceReverseStub::CmdRestoreOnResultReport; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdRestoreOnBundleFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdRestoreOnAllBundlesFinished; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdRestoreOnProcessInfo; - - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY)] = - &ServiceReverseStub::CmdIncrementalBackupOnFileReady; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED)] = - &ServiceReverseStub::CmdIncrementalBackupOnBundleStarted; - opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT)] - = &ServiceReverseStub::CmdIncrementalBackupOnResultReport; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalBackupOnBundleFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED)] = - &ServiceReverseStub::CmdIncrementalBackupOnAllBundlesFinished; - opToInterfaceMap_[static_cast( - IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO)] = - &ServiceReverseStub::CmdIncrementalBackupOnProcessInfo; - ServiceReverseStubSupplement(); -} - -int32_t ServiceReverseStub::CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - BackupOnFileReady(bundleName, fileName, fd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result = data.ReadString(); - std::string bundleName = data.ReadString(); - BackupOnResultReport(result, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - BackupOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - BackupOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - BackupOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - BackupOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string scannedInfo = data.ReadString(); - BackupOnScanningInfo(scannedInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - RestoreOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - RestoreOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - RestoreOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - RestoreOnFileReady(bundleName, fileName, fd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result; - if (!data.ReadString(result)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read result").GetCode(); - } - std::string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read bundleName").GetCode(); - } - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read errCode").GetCode(); - } - RestoreOnResultReport(result, bundleName, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - RestoreOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - int manifestFd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - manifestFd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalBackupOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string result = data.ReadString(); - std::string bundleName = data.ReadString(); - IncrementalBackupOnResultReport(result, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalBackupOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - IncrementalBackupOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - std::string processInfo = data.ReadString(); - IncrementalBackupOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalBackupOnScanningInfo(MessageParcel &data, MessageParcel &reply) -{ - std::string scannedInfo = data.ReadString(); - IncrementalBackupOnScanningInfo(scannedInfo); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnBundleStarted(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalRestoreOnBundleStarted(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - auto bundleName = data.ReadString(); - IncrementalRestoreOnBundleFinished(errCode, bundleName); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply) -{ - int32_t errCode = data.ReadInt32(); - IncrementalRestoreOnAllBundlesFinished(errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnFileReady(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto fileName = data.ReadString(); - int fd = INVALID_FD; - int manifestFd = INVALID_FD; - bool fdFlag = data.ReadBool(); - if (fdFlag == true) { - fd = data.ReadFileDescriptor(); - manifestFd = data.ReadFileDescriptor(); - } - int32_t errCode = data.ReadInt32(); - IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnResultReport(MessageParcel &data, MessageParcel &reply) -{ - auto result = data.ReadString(); - auto bundleName = data.ReadString(); - ErrCode errCode = data.ReadInt32(); - IncrementalRestoreOnResultReport(result, bundleName, errCode); - return BError(BError::Codes::OK); -} - -int32_t ServiceReverseStub::CmdIncrementalRestoreOnProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - auto bundleName = data.ReadString(); - auto processInfo = data.ReadString(); - IncrementalRestoreOnProcessInfo(bundleName, processInfo); - return BError(BError::Codes::OK); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 45fe3c878..2ceda9e2c 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -11,14 +11,149 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//build/ohos_var.gni") import("//foundation/filemanagement/app_file_service/backup.gni") +idl_gen_interface("backup_idl") { + sources = [ + "IExtension.idl", + "IService.idl", + "IServiceReverse.idl", + ] + sources_common = [ + "ServiceReverseType.idl", + "ExtensionType.idl", + "ServiceReverseInnerType.idl", + ] + hitrace = "HITRACE_TAG_FILEMANAGEMENT" + log_domainid = "0xD004313" + log_tag = "AppFileService" +} + +config("public_idl_config") { + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("backup_kit_inner_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "impl", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_kit_inner_ipc_type") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [] + + sources += filter_include(output_values, [ "*_type.cpp" ]) + + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + +ohos_source_set("backup_kit_inner_ipc_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":backup_idl") + + sources = [ "${target_gen_dir}/service_reverse_stub.cpp" ] + + sources += filter_include(output_values, + [ + "service_reverse_stub.cpp", + "service_reverse_stub.h", + "extension_type.cpp", + ]) + public_configs = [ ":public_idl_config" ] + + deps = [ ":backup_idl" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + include_dirs = [ + ".", + "${target_gen_dir}/", + ] + + part_name = "app_file_service" + + subsystem_name = "filemanagement" +} + config("public_config") { include_dirs = [ ".", "impl", + "${target_gen_dir}/", ] } @@ -52,11 +187,9 @@ ohos_shared_library("backup_kit_inner") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", ] defines = [ @@ -76,7 +209,10 @@ ohos_shared_library("backup_kit_inner") { "samgr:samgr_proxy", ] - deps = [ "${path_backup}/utils:backup_utils" ] + deps = [ + ":backup_kit_inner_ipc", + "${path_backup}/utils:backup_utils", + ] cflags_cc = [ "-fdata-sections", diff --git a/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl b/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl new file mode 100644 index 000000000..6b481aa4e --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ExtensionType.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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/interfaces/inner_api/native/backup_kit_inner/IExtension.idl b/interfaces/inner_api/native/backup_kit_inner/IExtension.idl new file mode 100644 index 000000000..e58f8ab1f --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IExtension.idl @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 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 GetIncrementalFileHandleWithUniqueFdGroup([in] String fileName, [out] UniqueFdGroup fdGroup); + [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 GetIncrementalBackupFileHandleWithUniqueFdGroup([out] UniqueFdGroup fdGroup); + [ipccode 11] void GetBackupInfo([out] String getBackupInfoResult); + [ipccode 12] void UpdateFdSendRate([in] String bundleName, [in] int sendRate); + [ipccode 13] void User0OnBackup(); +} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/IService.idl b/interfaces/inner_api/native/backup_kit_inner/IService.idl new file mode 100644 index 000000000..c6e0a8905 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; +import IServiceReverse; +import ServiceReverseType; +sequenceable BackupFileInfo..OHOS.FileManagement.Backup.BFileInfo; +sequenceable BackupIncrementalData..OHOS.FileManagement.Backup.BIncrementalData; +interface OHOS.FileManagement.Backup.IService{ + [ipccode 39] void InitRestoreSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 1] void InitRestoreSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 2] void InitBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 3] void InitBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, [out] String errMsg); + [ipccode 4] void Start(); + [ipccode 5] void GetLocalCapabilities([out] FileDescriptor fd); + [ipccode 6] void GetLocalCapabilitiesForBundleInfos([out] FileDescriptor fd); + [ipccode 7] void PublishFile([in] BFileInfo fileInfo); + [oneway, ipccode 8] void GetFileHandle([in] String bundleName, [in] String fileName); + [ipccode 9] void AppendBundlesRestoreSessionRestoreDataWaitSend([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] String[] detailInfos, + [in] int restoreType, + [in] int userId); + [ipccode 10] void AppendBundlesRestoreSessionRestoreDataWaitReady([in] FileDescriptor fd, + [in] String[] bundleNames, + [in] int restoreType, + [in] int userId); + [ipccode 11] void AppendBundlesBackupSession([in] String[] bundleNames); + [ipccode 12] void AppendBundlesDetailsBackupSession([in] String[] bundleNames, [in] String[] bundleInfos); + [ipccode 13] void Finish(); + [ipccode 14] void Release(); + [ipccode 15] void Cancel([in] String bundleName, [out] int cancelResult); + [ipccode 16] void GetAppLocalListAndDoIncrementalBackup(); + [ipccode 17] void GetIncrementalFileHandle([in] String bundleName, [in] String fileName); + [ipccode 18] void GetBackupInfo([in] String bundleName, [out] String getBackupInfoResult); + [ipccode 19] void UpdateTimer([in] String bundleName, [in] unsigned int timeout, [out] boolean updateTimerResult); + [ipccode 20] void UpdateSendRate([in] String bundleName, [in] int sendRate, [out] boolean updateSendRateResult); + [ipccode 21] void StartExtTimer([out] boolean isExtStart); + [ipccode 22] void StartFwkTimer([out] boolean isFwkStart); + [ipccode 23] void StopExtTimer([out] boolean isExtStop); + [ipccode 24] void GetLocalCapabilitiesIncremental([in] BIncrementalData[] bundleNames, [out] FileDescriptor fd); + [ipccode 25] void InitIncrementalBackupSession([in] IServiceReverse reverseIpcRemoteObject); + [ipccode 26] void InitIncrementalBackupSessionWithErrMsg([in] IServiceReverse reverseIpcRemoteObject, + [out] String errMsg); + [ipccode 27] void AppendBundlesIncrementalBackupSession([in] BIncrementalData[] bundlesToBackup); + [ipccode 28] void AppendBundlesIncrementalBackupSessionWithBundleInfos([in] BIncrementalData[] bundlesToBackup, + [in]String[] bundleInfos); + [ipccode 29] void PublishIncrementalFile([in] BFileInfo fileInfo); + [ipccode 30] void PublishSAIncrementalFile([in] BFileInfo fileInfo, [in] FileDescriptor fd); + [ipccode 31] void AppIncrementalFileReady([in] String fileName, [in] FileDescriptor fd, [in] FileDescriptor manifestFd, + [in] int appIncrementalFileReadyErrCode); + [ipccode 32] void AppIncrementalDone([in] int appIncrementalDoneErrCode); + [ipccode 33] void ReportAppProcessInfo([in] String processInfo, [in] BackupRestoreScenario scenario); + [ipccode 34] void RefreshDataSize([in] long totalDataSize); + [ipccode 35] void AppDone([in] int appDoneErrCode); + [ipccode 36] void AppFileReady([in]String fileName, [in] FileDescriptor fd, [in] int appFileReadyErrCode); + [ipccode 37] void ServiceResultReport([in]String restoreRetInfo, [in] BackupRestoreScenario sennario, + [in] int serviceResultReportErrCode); + [ipccode 38] void GetBackupDataSize([in] boolean isPreciseScan,[in] BIncrementalData[] bundleNameList); + } \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl b/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl new file mode 100644 index 000000000..bc44d90bc --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/IServiceReverse.idl @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; + +import ServiceReverseType; +import ServiceReverseInnerType; +interface OHOS.FileManagement.Backup.IServiceReverse{ + [ipccode 999] void BackupOnBundleStarted([in] int backupOnBundleStartedErrCode, [in] String bundleName); + [ipccode 1] void BackupOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd, + [in] int backupOnFileReadyErrCode); + [ipccode 2] void BackupOnResultReport([in] String myResult, [in] String bundleName); + [ipccode 3] void BackupOnBundleFinished([in] int backupOnBundleFinishedErrCode, [in] String bundleName); + [ipccode 4] void BackupOnAllBundlesFinished([in] int backupOnAllBundlesFinishedErrCode); + [ipccode 5] void BackupOnProcessInfo([in] String bundleName, [in] String processInfo); + [ipccode 6] void BackupOnScanningInfo([in] String scannedInfo); + [ipccode 7] void RestoreOnBundleStarted([in] int restoreOnBundleStartedErrCode, [in] String bundleName); + [ipccode 8] void RestoreOnFileReady([in] String bundleName, [in] String fileName, [in] FileDescriptor fd, + [in] int restoreOnFileReadyErrCode); + [ipccode 9] void RestoreOnResultReport([in] String myResult, [in] String bundleName, + [in] int restoreOnResultReportErrCode); + [ipccode 10] void RestoreOnBundleFinished([in] int restoreOnBundleFinishedErrCode, [in] String bundleName); + [ipccode 11] void RestoreOnAllBundlesFinished([in] int restoreOnAllBundlesFinishedErrCode); + [ipccode 12] void RestoreOnProcessInfo([in] String bundleName, [in] String processInfo); + + [ipccode 13] void IncrementalBackupOnBundleStarted([in] int incrementalBackupOnBundleStartedErrCode, + [in] String bundleName); + [ipccode 14] void IncrementalBackupOnFileReady([in] String bundleName, + [in] String fileName, [in] FileDescriptor fd, + [in] FileDescriptor manifestFd, [in] int incrementalBackupOnFileReadyErrCode); + [ipccode 15] void IncrementalBackupOnResultReport([in] String myResult, [in] String bundleName); + [ipccode 16] void IncrementalBackupOnBundleFinished([in] int incrementalBackupOnBundleFinishedErrCode, + [in] String bundleName); + [ipccode 17] void IncrementalBackupOnAllBundlesFinished([in] int incrementalBackupOnAllBundlesFinishedErrCode); + [ipccode 18] void IncrementalBackupOnProcessInfo([in] String bundleName, [in] String processInfo); + [ipccode 19] void IncrementalBackupOnScanningInfo([in] String scannedInfo); + + [ipccode 20] void IncrementalRestoreOnBundleStarted([in] int incrementalRestoreOnBundleStartedErrCode, + [in] String bundleName); + [ipccode 21] void IncrementalRestoreOnFileReady([in] String bundleName, + [in] String fileName, + [in] FileDescriptor fd, + [in] FileDescriptor manifestFd, + [in] int incrementalRestoreOnFileReadyErrCode); + [ipccode 22] void IncrementalRestoreOnResultReport([in] String myResult, [in] String bundleName, + [in] int incrementalRestoreOnResultReportErrCode); + [ipccode 23] void IncrementalRestoreOnBundleFinished([in] int incrementalRestoreOnBundleFinishedErrCode, + [in] String bundleName); + [ipccode 24] void IncrementalRestoreOnAllBundlesFinished([in] int incrementalRestoreOnAllBundlesFinishedErrCode); + [ipccode 25] void IncrementalRestoreOnProcessInfo( [in] String bundleName, [in] String processInfo); +} \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl new file mode 100644 index 000000000..85cd436dd --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseInnerType.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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.IServiceReverseType; + +enum Scenario { + UNDEFINED, + BACKUP, + RESTORE, + CLEAN, +}; diff --git a/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl new file mode 100644 index 000000000..3e8910046 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/ServiceReverseType.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.FileManagement.Backup; + +enum BackupRestoreScenario { + FULL_BACKUP = 0, + INCREMENTAL_BACKUP = 1, + FULL_RESTORE = 2, + INCREMENTAL_RESTORE = 3, +}; + diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h index 934cb5593..339c47266 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index 3b0e46a9c..d671cebed 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 50c47bf7b..275df6f21 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -22,9 +22,10 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" -#include "i_service.h" +#include "iservice.h" +#include "service_common.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index 0fbcb4dc2..fb4b06d1a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -20,8 +20,8 @@ #include #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "errors.h" #include "errors.h" #include "svc_death_recipient.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index 7aa5fdcd8..7b916abf1 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -20,7 +20,7 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 64615acb2..02a311601 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -22,9 +22,10 @@ #include #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "errors.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" #include "svc_death_recipient.h" #include "unique_fd.h" diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h similarity index 100% rename from interfaces/inner_api/native/backup_kit_inner/impl/b_file_info.h rename to interfaces/inner_api/native/backup_kit_inner/impl/backup_file_info.h diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h b/interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h similarity index 100% rename from interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_data.h rename to interfaces/inner_api/native/backup_kit_inner/impl/backup_incremental_data.h diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h deleted file mode 100644 index 0108a3437..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_H - -#include -#include - -#include - -#include "b_file_info.h" -#include "b_incremental_data.h" -#include "i_service_ipc_interface_code.h" -#include "i_service_reverse.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -const int DEFAULT_INVAL_VALUE = -1; - -typedef enum TypeRestoreTypeEnum { - RESTORE_DATA_WAIT_SEND = 0, - RESTORE_DATA_READDY = 1, -} RestoreTypeEnum; - -enum BackupRestoreScenario { - FULL_BACKUP = 0, - INCREMENTAL_BACKUP = 1, - FULL_RESTORE = 2, - INCREMENTAL_RESTORE = 3, -}; - -class IService : public IRemoteBroker { -public: - virtual ~IService() = default; - virtual ErrCode InitRestoreSession(sptr remote) = 0; - virtual ErrCode InitRestoreSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode InitBackupSession(sptr remote) = 0; - virtual ErrCode InitBackupSession(sptr remote, std::string &errMsg) = 0; - virtual ErrCode Start() = 0; - virtual UniqueFd GetLocalCapabilities() = 0; - virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; - virtual ErrCode PublishFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) = 0; - virtual ErrCode AppDone(ErrCode errCode) = 0; - virtual ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) = 0; - virtual ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; - virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; - virtual ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) = 0; - virtual ErrCode Finish() = 0; - virtual ErrCode Release() = 0; - virtual ErrCode Cancel(std::string bundleName, int32_t &result) = 0; - virtual UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) = 0; - virtual ErrCode GetAppLocalListAndDoIncrementalBackup() = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse) = 0; - virtual ErrCode InitIncrementalBackupSession(sptr remotse, std::string &errMsg) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) = 0; - virtual ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &bundleInfos) = 0; - - virtual ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) = 0; - virtual ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) = 0; - virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) = 0; - virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; - virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; - virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) = 0; - virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0; - virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0; - virtual ErrCode StartExtTimer(bool &isExtStart) = 0; - virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0; - virtual ErrCode StopExtTimer(bool &isExtStop) = 0; - virtual ErrCode RefreshDataSize(int64_t totalSize) = 0; - virtual ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h deleted file mode 100644 index 4ca5a7621..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H -#define OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H - -#include - -#include "i_service_reverse_ipc_interface_code.h" -#include "iremote_broker.h" - -namespace OHOS::FileManagement::Backup { -class IServiceReverse : public IRemoteBroker { -public: - enum class Scenario { - UNDEFINED, - BACKUP, - RESTORE, - CLEAN, - }; - -public: - virtual ~IServiceReverse() = default; - virtual void BackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; - virtual void BackupOnResultReport(std::string result, std::string bundleName) = 0; - virtual void BackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void BackupOnAllBundlesFinished(int32_t errCode) = 0; - virtual void BackupOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - virtual void BackupOnScanningInfo(std::string scannedInfo) = 0; - - virtual void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; - virtual void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) = 0; - virtual void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void RestoreOnAllBundlesFinished(int32_t errCode) = 0; - virtual void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - - virtual void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) = 0; - virtual void IncrementalBackupOnResultReport(std::string result, std::string bundleName) = 0; - virtual void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalBackupOnAllBundlesFinished(int32_t errCode) = 0; - virtual void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - virtual void IncrementalBackupOnScanningInfo(std::string scannedInfo) = 0; - - virtual void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalRestoreOnFileReady(std::string bundleName, - std::string fileName, - int fd, - int manifestFd, int32_t errCode) = 0; - virtual void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) = 0; - virtual void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) = 0; - virtual void IncrementalRestoreOnProcessInfo(const std::string bundleName, const std::string processInfo) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IServiceReverse") -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h similarity index 35% rename from services/backup_sa/include/module_ipc/svc_extension_proxy.h rename to interfaces/inner_api/native/backup_kit_inner/impl/service_client.h index dd38f936a..86c12f988 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_client.h @@ -13,36 +13,46 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H + +#include +#include +#include +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "system_ability_load_callback_stub.h" -#include "i_extension.h" -#include "iremote_proxy.h" -#include "unique_fd.h" namespace OHOS::FileManagement::Backup { -class SvcExtensionProxy : public IRemoteProxy { -public: - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override; - ErrCode HandleClear() override; - ErrCode HandleBackup(bool isClearData) override; - ErrCode PublishFile(const std::string &fileName) override; - ErrCode HandleRestore(bool isClearData) override; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override; - ErrCode PublishIncrementalFile(const std::string &fileName) override; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; - ErrCode IncrementalOnBackup(bool isClearData) override; - std::tuple GetIncrementalBackupFileHandle() override; - ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; - ErrCode User0OnBackup() override; +class ServiceClient { public: - explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} + static sptr GetServiceProxyPointer(); + static sptr GetInstance(); + static void InvaildInstance(); + bool CheckServiceProxy(); +public: + explicit ServiceClient(); + ~ServiceClient(); +public: + class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + + public: + std::condition_variable proxyConVar_; + std::atomic isLoadSuccess_ = {false}; + }; private: - static inline BrokerDelegator delegator_; + static inline std::mutex proxyMutex_; + static inline std::mutex getInstanceMutex_; + static inline sptr serviceProxy_ = nullptr; }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_CLIENT_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h similarity index 34% rename from interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h rename to interfaces/inner_api/native/backup_kit_inner/impl/service_common.h index 7ce72f1a3..390900866 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_common.h @@ -13,35 +13,17 @@ * limitations under the License. */ -#ifndef OHOS_FILEMGMT_BACKUP_I_EXTENSION_H -#define OHOS_FILEMGMT_BACKUP_I_EXTENSION_H - -#include "errors.h" -#include "i_extension_ipc_interface_code.h" -#include "iremote_broker.h" -#include "unique_fd.h" +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H namespace OHOS::FileManagement::Backup { -class IExtension : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IExtension"); +const int DEFAULT_INVAL_VALUE = -1; + +typedef enum TypeRestoreTypeEnum { + RESTORE_DATA_WAIT_SEND = 0, + RESTORE_DATA_READDY = 1, +} RestoreTypeEnum; -public: - virtual ~IExtension() = default; - virtual UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) = 0; - virtual ErrCode HandleClear() = 0; - virtual ErrCode HandleBackup(bool isClearData) = 0; - virtual ErrCode PublishFile(const std::string &fileName) = 0; - virtual ErrCode HandleRestore(bool isClearData) = 0; - virtual std::tuple GetIncrementalFileHandle(const std::string &fileName) = 0; - virtual ErrCode PublishIncrementalFile(const std::string &fileName) = 0; - virtual ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) = 0; - virtual ErrCode IncrementalOnBackup(bool isClearData) = 0; - virtual std::tuple GetIncrementalBackupFileHandle() = 0; - virtual ErrCode GetBackupInfo(std::string &result) = 0; - virtual ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) = 0; - virtual ErrCode User0OnBackup() = 0; -}; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_I_EXTENSION_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_COMMON_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h deleted file mode 100644 index 4302e07b8..000000000 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H - -#include -#include -#include -#include - -#include "i_service.h" -#include "iremote_proxy.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceProxy : public IRemoteProxy { -public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; - ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; - ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; - ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override; - ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; - ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) override; - ErrCode Finish() override; - ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; - ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; - - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; - ErrCode AppIncrementalDone(ErrCode errCode) override; - ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; - ErrCode StartExtTimer(bool &isExtStart) override; - ErrCode StartFwkTimer(bool &isFwkStart) override; - ErrCode StopExtTimer(bool &isExtStop) override; - ErrCode RefreshDataSize(int64_t totalSize) override; - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) override; -public: - explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceProxy() override {} - -public: - template - bool WriteParcelableVector(const std::vector &parcelableVector, Parcel &data); - static sptr GetServiceProxyPointer(); - static sptr GetInstance(); - static void InvaildInstance(); - -public: - class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { - public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - - public: - std::condition_variable proxyConVar_; - std::atomic isLoadSuccess_ = {false}; - }; - -private: - static inline std::mutex proxyMutex_; - static inline std::mutex getInstanceMutex_; - static inline sptr serviceProxy_ = nullptr; - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H \ No newline at end of file diff --git a/interfaces/kits/js/backup/parse_inc_info_from_js.h b/interfaces/kits/js/backup/parse_inc_info_from_js.h index b3856dddb..461ce8513 100644 --- a/interfaces/kits/js/backup/parse_inc_info_from_js.h +++ b/interfaces/kits/js/backup/parse_inc_info_from_js.h @@ -18,7 +18,7 @@ #include #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" namespace OHOS::FileManagement::Backup { class Parse { diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index e4a1ef547..5aa1c573c 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -15,14 +15,14 @@ #include "prop_n_operation.h" #include "b_error/b_error.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" #include "incremental_backup_data.h" #include "parse_inc_info_from_js.h" -#include "service_proxy.h" +#include "service_client.h" #include "access_token.h" #include "accesstoken_kit.h" #include "ipc_skeleton.h" @@ -39,13 +39,18 @@ static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg) auto fd = make_shared(); auto cbExec = [fd]() -> NError { HILOGI("called LocalCapabilities::AsyncCallback cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncCallback cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilities(); + int fdNum = -1; + HILOGI("called LocalCapabilities::AsyncCallback start fdNum:%{public}d}", fdNum); + proxy->GetLocalCapabilities(fdNum); + HILOGI("called LocalCapabilities::AsyncCallback end fdNum:%{public}d}", fdNum); + UniqueFd fdData(fdNum); + *fd = std::move(fdData); HILOGI("called LocalCapabilities::AsyncCallback cbExec success"); return NError(ERRNO_NOERR); }; @@ -81,15 +86,18 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) } auto fd = make_shared(); - auto cbExec = [fd, bundles { move(bundles) }]() -> NError { + auto cbExec = [fd, bundles {move(bundles)}]() -> NError { HILOGI("called LocalCapabilities::AsyncDataList cbExec"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGI("called LocalCapabilities::AsyncDataList cbExec, failed to get proxy"); return NError(errno); } - *fd = proxy->GetLocalCapabilitiesIncremental(bundles); + int fdValue = -1; + proxy->GetLocalCapabilitiesIncremental(bundles, fdValue); + UniqueFd fdData(fdValue); + *fd = std::move(fdData); return NError(ERRNO_NOERR); }; auto cbCompl = [fd](napi_env env, NError err) -> NVal { @@ -165,8 +173,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info return nullptr; } - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoGetBackupInfo,failed to get proxy"); return nullptr; @@ -191,8 +199,8 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called UpdateSendRate,failed to get proxy"); return result; @@ -208,8 +216,8 @@ bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) { bool result = false; - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); + ServiceClient::InvaildInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { HILOGE("called DoUpdateTimer,failed to get proxy"); return result; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index d3a84c628..5f96544dd 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -20,7 +20,7 @@ #include "b_error/b_error.h" #include "b_filesystem/b_file.h" #include "b_incremental_backup_session.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "backup_kit_inner.h" diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 8c877bed7..f7a2a84f1 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -34,13 +34,8 @@ ohos_shared_library("backup_sa") { "src/module_ipc/sa_backup_connection.cpp", "src/module_ipc/service.cpp", "src/module_ipc/service_incremental.cpp", - "src/module_ipc/service_incremental_reverse_proxy.cpp", - "src/module_ipc/service_reverse_proxy.cpp", - "src/module_ipc/service_stub.cpp", "src/module_ipc/sub_service.cpp", "src/module_ipc/svc_backup_connection.cpp", - "src/module_ipc/svc_extension_incremental_proxy.cpp", - "src/module_ipc/svc_extension_proxy.cpp", "src/module_ipc/svc_restore_deps_manager.cpp", "src/module_ipc/svc_session_manager.cpp", "src/module_notify/notify_work_service.cpp", @@ -59,6 +54,7 @@ ohos_shared_library("backup_sa") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index 13a7be7a1..eba30a79f 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -21,7 +21,7 @@ #include "b_json/b_json_entity_caps.h" #include "bundlemgr/bundle_mgr_interface.h" -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "istorage_manager.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 34a0fb99a..89e95f355 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -23,13 +23,14 @@ #include "b_json/b_json_clear_data_config.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_service_disposal_config.h" -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_stub.h" #include "module_sched/sched_scheduler.h" #include "service_stub.h" #include "svc_session_manager.h" #include "system_ability.h" #include "thread_pool.h" +#include "service_reverse_inner_type.h" namespace OHOS::FileManagement::Backup { struct ExtensionMutexInfo { @@ -48,53 +49,83 @@ class Service : public SystemAbility, public ServiceStub, protected NoCopyable { // 以下都是IPC接口 public: - ErrCode InitRestoreSession(sptr remote) override; - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override; - ErrCode InitBackupSession(sptr remote) override; - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitRestoreSession(const sptr& remote) override; + ErrCode InitRestoreSessionWithErrMsg(const sptr& reverseIpcRemoteObject, + std::string& errMsg) override; + ErrCode InitRestoreSession(const sptr& remote, std::string &errMsg); + ErrCode InitBackupSession(const sptr& remote) override; + ErrCode InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode Start() override; - UniqueFd GetLocalCapabilities() override; - UniqueFd GetLocalCapabilitiesForBundleInfos() override; + ErrCode GetLocalCapabilities(int& fd) override; + UniqueFd GetLocalCapabilities(); + ErrCode GetLocalCapabilitiesForBundleInfos(int& fd) override; + UniqueFd GetLocalCapabilitiesForBundleInfos(); ErrCode PublishFile(const BFileInfo &fileInfo) override; - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) override; + ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode); ErrCode AppDone(ErrCode errCode) override; - ErrCode ServiceResultReport(const std::string restoreRetInfo, + ErrCode ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) override; ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend( + int fd, + const std::vector& bundleNames, + const std::vector& detailInfos, + int32_t restoreType, + int32_t userId) override; + ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady( + int fd, + const std::vector& bundleNames, + int32_t restoreType, + int32_t userId) override; ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, const std::vector &bundleInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + int32_t userId = DEFAULT_INVAL_VALUE); ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) override; + int32_t userId = DEFAULT_INVAL_VALUE); ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; + ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; - ErrCode Cancel(std::string bundleName, int32_t &result) override; - - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override; + ErrCode Cancel(const std::string& bundleName, int32_t &result) override; + ErrCode GetLocalCapabilitiesIncremental( + const std::vector& bundleNames, + int& fd) override; + UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames); ErrCode GetAppLocalListAndDoIncrementalBackup() override; - ErrCode InitIncrementalBackupSession(sptr remote) override; - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override; + ErrCode InitIncrementalBackupSession(const sptr& remote) override; + ErrCode InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override; + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector& bundlesToBackup, + const std::vector& bundleInfos) override; ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override; + const std::vector &infos); ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override; - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override; - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode) override; + ErrCode PublishSAIncrementalFile( + const BFileInfo& fileInfo, + int fd) override; + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); + ErrCode AppIncrementalFileReady( + const std::string& fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; - ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; + ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; + ErrCode UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) override; + ErrCode UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) override; + ErrCode ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; ErrCode StopExtTimer(bool &isExtStop) override; @@ -104,7 +135,7 @@ public: const ErrCode errCode, const BackupRestoreScenario sennario); void StartGetFdTask(std::string bundleName, wptr ptr); - ErrCode GetBackupDataSize(bool isPreciseScan, vector bundleNameList) override; + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) override; // 以下都是非IPC接口 public: @@ -212,7 +243,7 @@ public: * @param bundleName 应用名称 * */ - AAFwk::Want CreateConnectWant (BundleName &bundleName); + AAFwk::Want CreateConnectWant (const BundleName &bundleName); /** * @brief SA backup回调 @@ -242,7 +273,8 @@ public: * @param bundleName 应用名称 * */ - std::function GetBackupInfoConnectDone(wptr obj, std::string &bundleName); + std::function GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName); /** * @brief GetBackupInfo extension死亡回调 @@ -252,7 +284,7 @@ public: * */ std::function GetBackupInfoConnectDied( - wptr obj, std::string &bundleName); + wptr obj, const std::string &bundleName); /** * @brief timeout callback @@ -313,7 +345,7 @@ public: string BundleNameWithUserId(const string& bundleName, const int32_t userId); std::tuple SplitBundleName(const string& bundleNameWithId); void AppendBundles(const std::vector &bundleNames); - void ReportOnBundleStarted(IServiceReverse::Scenario scenario, const std::string &bundleName); + void ReportOnBundleStarted(IServiceReverseType::Scenario scenario, const std::string &bundleName); ErrCode AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode); public: @@ -362,7 +394,7 @@ private: * * @param scenario Scenario状态 */ - ErrCode VerifyCaller(IServiceReverse::Scenario scenario); + ErrCode VerifyCaller(IServiceReverseType::Scenario scenario); /** * @brief 验证调用者并返回名称 @@ -526,7 +558,7 @@ private: * @param result 业务结果出参 * */ - ErrCode GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result); + ErrCode GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result); /** * @brief 添加需要清理的Session @@ -544,7 +576,7 @@ private: */ void SetOccupySession(bool isOccupyingSession); - void ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, + void ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, const std::string &bundleName, const ErrCode ret); void ReleaseOnException(); @@ -561,7 +593,7 @@ private: std::map> &bundleNameDetailMap, std::map &isClearDataFlags); - void TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName); + void TimeoutRadarReport(IServiceReverseType::Scenario scenario, std::string &bundleName); void OnBundleStarted(BError error, sptr session, const BundleName &bundleName); @@ -569,16 +601,16 @@ private: const vector &restoreBundleNames); void BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverseType::Scenario scenario); void OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage); diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h deleted file mode 100644 index 7578aca36..000000000 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H - -#include "i_service_reverse.h" -#include "iremote_proxy.h" - -namespace OHOS::FileManagement::Backup { -class ServiceReverseProxy final : public IRemoteProxy, protected NoCopyable { -public: - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void BackupOnResultReport(std::string result, std::string bundleName) override; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void BackupOnAllBundlesFinished(int32_t errCode) override; - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void BackupOnScanningInfo(std::string scannedInfo) override; - - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void RestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void RestoreOnAllBundlesFinished(int32_t errCode) override; - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; - - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override; - - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override; - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, - ErrCode errCode = 0) override; - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; - -public: - explicit ServiceReverseProxy(const sptr &impl) : IRemoteProxy(impl) {} - ~ServiceReverseProxy() override = default; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_REVERSE_PROXY_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h deleted file mode 100644 index d4484365a..000000000 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H - -#include - -#include "i_service.h" -#include "iremote_stub.h" - -namespace OHOS::FileManagement::Backup { -class ServiceStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -public: - ServiceStub(); - ~ServiceStub() override = default; - -private: - using ServiceInterface = int32_t (ServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdStart(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdResultReport(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdFinish(MessageParcel &data, MessageParcel &reply); - int32_t CmdRelease(MessageParcel &data, MessageParcel &reply); - int32_t CmdCancel(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply); - int32_t CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply); - int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdStopExtTimer(MessageParcel &data, MessageParcel &reply); - int32_t CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply); - int32_t CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply); - void ServiceStubSupplement(); - void ServiceStubSuppAppendBundles(); - -public: - template - bool ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data); -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_backup_connection.h b/services/backup_sa/include/module_ipc/svc_backup_connection.h index 8b6c2477c..33c1c6978 100644 --- a/services/backup_sa/include/module_ipc/svc_backup_connection.h +++ b/services/backup_sa/include/module_ipc/svc_backup_connection.h @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_H #include "ability_connect_callback_stub.h" -#include "i_extension.h" +#include "iextension.h" namespace OHOS::FileManagement::Backup { class SvcBackupConnection : public AAFwk::AbilityConnectionStub { diff --git a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h index cb83798b9..d0a198256 100644 --- a/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h +++ b/services/backup_sa/include/module_ipc/svc_restore_deps_manager.h @@ -22,7 +22,8 @@ #include #include "b_json/b_json_entity_caps.h" -#include "i_service.h" +#include "service_common.h" +#include "iservice.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 98fd49414..3130f4e42 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -29,11 +29,12 @@ #include -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" #include "b_resources/b_constants.h" -#include "i_service.h" -#include "i_service_reverse.h" +#include "service_common.h" +#include "iservice.h" +#include "iservice_reverse.h" #include "module_ipc/svc_backup_connection.h" #include "module_ipc/sa_backup_connection.h" #include "svc_death_recipient.h" @@ -80,7 +81,7 @@ class SvcSessionManager : public virtual RefBase { public: struct Impl { uint32_t clientToken {0}; - IServiceReverse::Scenario scenario {IServiceReverse::Scenario::UNDEFINED}; + IServiceReverseType::Scenario scenario {IServiceReverseType::Scenario::UNDEFINED}; std::map backupExtNameMap; sptr clientProxy; bool isBackupStart {false}; @@ -106,7 +107,7 @@ public: * * @return ErrCode 错误码 */ - ErrCode VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const; + ErrCode VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const; /** * @brief 激活会话 @@ -147,10 +148,10 @@ public: /** * @brief 获取Scenario * - * @return IServiceReverse::Scenario 返回scenario + * @return IServiceReverseType::Scenario 返回scenario * @throw BError::Codes::SA_INVAL_ARG 获取异常 */ - IServiceReverse::Scenario GetScenario(); + IServiceReverseType::Scenario GetScenario(); /** * @brief 获取当前处理事务会话对应的userId @@ -332,7 +333,7 @@ public: * * @param bundleName 应用名称 */ - sptr CreateBackupConnection(BundleName &bundleName); + sptr CreateBackupConnection(const BundleName &bundleName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 12a70dd62..db46d69e7 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -21,7 +21,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_jsonutil/b_jsonutil.h" #include "b_json/b_json_entity_extension_config.h" #include "b_resources/b_constants.h" diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 65a225c97..20d4a6f1b 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -38,11 +38,12 @@ #include #include "ability_manager_client.h" +#include "access_token.h" #include "accesstoken_kit.h" #include "b_anony/b_anony.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_hiaudit/hi_audit.h" #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" @@ -57,7 +58,7 @@ #include "hisysevent.h" #include "hitrace_meter.h" #include "ipc_skeleton.h" -#include "access_token.h" +#include "service_reverse_inner_type.h" #include "tokenid_kit.h" #include "module_app_gallery/app_gallery_dispose_proxy.h" #include "module_external/bms_adapter.h" @@ -118,7 +119,7 @@ void Service::OnStartResRadarReport(const std::vector &bundleNameLi } void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK || errCode == BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()) { return; @@ -132,17 +133,17 @@ void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCod taskInfo.errCode = errCode; UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); } } void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK) { successBundlesNum_++; @@ -160,17 +161,17 @@ void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCod taskInfo.errCode = errCode; UpdateFailedBundles(bundleName, taskInfo); AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleEndRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_EXECU_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleEndRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_EXECU_FAIL, errCode); } } void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (errCode == ERR_OK) { return; @@ -180,17 +181,17 @@ void Service::FileReadyRadarReport(const std::string &bundleName, const std::str } std::string fileNameReport = std::string("fileName:\"") + GetAnonyPath(fileName) + "\""; AppRadar::Info info(bundleName, "", fileNameReport); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::FileReadyRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::FileReadyRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_DO_BACKUP, errCode); } } void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverseType::Scenario scenario) { if (!IsReportBundleExecFail(bundleName)) { return; @@ -199,11 +200,11 @@ void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, con std::stringstream ss; ss << "errCode:" << errCode; AppRadar::Info info(bundleName, "", ss.str()); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::ExtensionConnectFailRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_CONNECT_EXTENSION_FAIL, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::ExtensionConnectFailRadarReport", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_CONNECT_EXTENSION_FAIL, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); @@ -217,25 +218,30 @@ void Service::OnStart() std::vector bundleNameList; if (disposal_ != nullptr) { bundleNameList = disposal_->GetBundleNameFromConfigFile(); + HILOGI("disposal_ !=null"); + } else { + HILOGI("disposal_ ==null"); } std::vector residualBundleNameList; if (clearRecorder_ != nullptr) { residualBundleNameList = clearRecorder_->GetAllClearBundleRecords(); } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { + HILOGI("!bundleNameList.empty() || !residualBundleNameList.empty() !=null"); if (!bundleNameList.empty()) { - OnStartResRadarReport(bundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + HILOGI("bundleNameList !=null"); } if (!residualBundleNameList.empty()) { OnStartResRadarReport(residualBundleNameList, - static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + HILOGI("residualBundleNameList !=null"); } SetOccupySession(true); session_->Active( { .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::CLEAN, + .scenario = IServiceReverseType::Scenario::CLEAN, .clientProxy = nullptr, .userId = GetUserIdDefault(), .callerName = "BackupSA", @@ -274,6 +280,14 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +ErrCode Service::GetLocalCapabilities(int& fd) +{ + UniqueFd fdResult(GetLocalCapabilities()); + fd = fdResult.Release(); + HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -349,7 +363,7 @@ void Service::StopAll(const wptr &obj, bool force) ss << "}"; string resultInfo = ss.str(); AppRadar::StatInfo statInfo("", resultInfo); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); AppRadar::GetInstance().RecordStatisticRes(statInfo, GetUserIdDefault(), scenario, successBundlesNum_.load(), fail_cnt, result); } @@ -362,8 +376,8 @@ void Service::PermissionCheckFailRadar(const std::string &info, const std::strin { std::string funcPos = "Service::"; AppRadar::Info resInfo("", "", info); - AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), - GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } @@ -379,8 +393,8 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) HILOGE("Verify and get caller name failed, Get hap token info failed"); return BError(BError::Codes::SA_INVAL_ARG); } - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, - hapTokenInfo.instIndex); + std::string bundleNameIndexInfo = + BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, hapTokenInfo.instIndex); ErrCode ret = session_->VerifyBundleName(bundleNameIndexInfo); if (ret != ERR_OK) { HILOGE("Verify bundle name failed, bundleNameIndexInfo:%{public}s", bundleNameIndexInfo.c_str()); @@ -450,7 +464,7 @@ ErrCode Service::VerifyCaller() return ret; } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = session_->VerifyCallerAndScenario(IPCSkeleton::GetCallingTokenID(), scenario); @@ -461,7 +475,7 @@ ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) return VerifyCaller(); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -471,7 +485,7 @@ ErrCode Service::InitRestoreSession(sptr remote) } ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::RESTORE, + .scenario = IServiceReverseType::Scenario::RESTORE, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -493,7 +507,7 @@ ErrCode Service::InitRestoreSession(sptr remote) return ret; } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitBackupSession(const sptr &remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -506,7 +520,7 @@ ErrCode Service::InitBackupSession(sptr remote) session_->SetMemParaCurSize(oldSize); ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -531,12 +545,14 @@ ErrCode Service::InitBackupSession(sptr remote) ErrCode Service::Start() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Service Start"); ErrCode ret = VerifyCaller(session_->GetScenario()); if (ret != ERR_OK) { HILOGE("Service start failed, Verify caller failed, ret:%{public}d", ret); return ret; } ret = session_->Start(); + HILOGI("Service Start End"); if (ret != ERR_OK) { HILOGE("Service start failed, session is invalid, ret:%{public}d", ret); return ret; @@ -558,11 +574,11 @@ static bool SpecialVersion(const string &versionName) void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) { - IServiceReverse::Scenario scenario = session->GetScenario(); - if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + IServiceReverseType::Scenario scenario = session->GetScenario(); + if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(error, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); } BundleBeginRadarReport(bundleName, error.GetCode(), scenario); @@ -625,14 +641,15 @@ static vector GetRestoreBundleNames(UniqueFd fd, } void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) + const vector &appendBundleNames, + const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," "restoreBundleNames size:%{public}zu", appendBundleNames.size(), restoreBundleNames.size()); for (const auto &bundleName : appendBundleNames) { auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&bundleName](const auto &obj) { return obj == bundleName; }); + [&bundleName](const auto &obj) { return obj == bundleName; }); if (it == restoreBundleNames.end()) { HILOGE("AppendBundles failed, bundleName = %{public}s.", bundleName.c_str()); OnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), session, bundleName); @@ -641,8 +658,25 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &bundleInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitSend"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(static_cast(fd)); + RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType, + int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); @@ -653,7 +687,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); SetUserIdAndRestoreType(restoreType, userId); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -663,8 +697,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector bundleNamesOnly; std::map isClearDataFlags; std::map> bundleNameDetailMap = - BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - session_->GetSessionUserId(), isClearDataFlags); + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, session_->GetSessionUserId(), + isClearDataFlags); std::string oldBackupVersion; auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); @@ -675,8 +709,8 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("End"); @@ -695,7 +729,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &restoreBundleInfos, - std::vector &restoreBundleNames, RestoreTypeEnum restoreType, std::string &backupVersion) + std::vector &restoreBundleNames, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -706,11 +742,11 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); + restoreInfo.extensionName.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { @@ -731,6 +767,18 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitReady"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(static_cast(fd)); + RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_READDY; + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); +} ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, @@ -745,7 +793,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); SetUserIdAndRestoreType(restoreType, userId); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -779,10 +827,13 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } -void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, +void Service::SetCurrentSessProperties( + std::vector &restoreBundleInfos, std::vector &restoreBundleNames, std::map> &bundleNameDetailMap, - std::map &isClearDataFlags, RestoreTypeEnum restoreType, std::string &backupVersion) + std::map &isClearDataFlags, + RestoreTypeEnum restoreType, + std::string &backupVersion) { HILOGI("Start"); session_->SetOldBackupVersion(backupVersion); @@ -795,7 +846,7 @@ void Service::SetCurrentSessProperties(std::vector }); if (it == restoreBundleNames.end()) { HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), - restoreInfo.appIndex); + restoreInfo.appIndex); continue; } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); @@ -816,14 +867,14 @@ void Service::SetCurrentSessProperties(std::vector } BJsonUtil::BundleDetailInfo broadCastInfo; BJsonUtil::BundleDetailInfo uniCastInfo; - bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, - broadCastInfo); + bool broadCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, broadCastInfo); if (broadCastRet) { bool notifyRet = DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); HILOGI("Publish event end, notify result is:%{public}d", notifyRet); } - bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, - uniCastInfo); + bool uniCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo); if (uniCastRet) { HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); @@ -843,7 +894,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("AppendBundles backup session error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -873,7 +924,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName } ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bundleNames, - const vector &bundleInfos) + const vector &bundleInfos) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -882,7 +933,7 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun return BError(BError::Codes::SA_INVAL_ARG); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("AppendBundles backup session with infos error, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -916,19 +967,20 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun } } -void Service::HandleCurGroupBackupInfos(std::vector &backupInfos, +void Service::HandleCurGroupBackupInfos( + std::vector &backupInfos, std::map> &bundleNameDetailMap, std::map &isClearDataFlags) { for (auto &info : backupInfos) { - HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", - info.name.c_str(), info.extensionName.c_str(), info.appIndex); + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", info.name.c_str(), + info.extensionName.c_str(), info.appIndex); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); BJsonUtil::BundleDetailInfo uniCastInfo; if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) { HILOGI("current bundle:%{public}s, unicast info:%{public}s, unicast info size:%{public}zu", - bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); + bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); @@ -937,12 +989,13 @@ void Service::HandleCurGroupBackupInfos(std::vector } } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("ServiceResultReport restoreRetInfo:%{public}s, sennario:%{public}d, errCode:%{public}d", + restoreRetInfo.c_str(), sennario, errCode); ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { HILOGE("Result report fail, bundleName:%{public}s, ret:%{public}d", callerName.c_str(), ret); @@ -975,14 +1028,16 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } } -ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, - const ErrCode errCode, const BackupRestoreScenario sennario) +ErrCode Service::SAResultReport(const std::string bundleName, + const std::string restoreRetInfo, + const ErrCode errCode, + const BackupRestoreScenario sennario) { SADone(errCode, bundleName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); @@ -991,10 +1046,10 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string } OnAllBundlesFinished(BError(BError::Codes::OK)); if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::RESTORE); } else if (sennario == BackupRestoreScenario::FULL_BACKUP || - sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::BACKUP); + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::BACKUP); } return BError(BError::Codes::OK); } @@ -1003,8 +1058,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore { HILOGI("Begin"); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && - sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { return; } if (session_->OnBundleFileReady(bundleName)) { @@ -1039,7 +1093,7 @@ void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestore ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) { string extInfo = session_->GetBackupExtInfo(bundleName); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); if (SAUtils::IsSABundleName(bundleName)) { auto saBackUpConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = saBackUpConnection.lock(); @@ -1047,9 +1101,9 @@ ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) HILOGE("lock sa connection ptr is nullptr"); return BError(BError::Codes::SA_INVAL_ARG); } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_BACKUP, extInfo); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_RESTORE, extInfo); } } @@ -1059,14 +1113,13 @@ ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("GetFileHandle bundleName:%{public}s,fileName:%{public}s", bundleName.c_str(), fileName.c_str()); try { if (session_ == nullptr) { - HILOGE("GetFileHandle error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { - HILOGE("verify caller failed, bundleName:%{public}s", bundleName.c_str()); return ret; } bool updateRes = SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); @@ -1090,14 +1143,16 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) return BError(BError::Codes::SA_INVAL_ARG); } int32_t errCode = 0; - UniqueFd fd = proxy->GetFileHandle(fileName, errCode); + int32_t fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(static_cast(fdCode)); if (errCode != ERR_OK) { - AppRadar::Info info (bundleName, "", ""); + AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); } else { session_->SetExtFileNameRequest(bundleName, fileName); } @@ -1131,7 +1186,7 @@ void Service::ExtStart(const string &bundleName) void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) { HILOGI("Begin handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("Error, backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); @@ -1144,7 +1199,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) ReportOnBundleStarted(scenario, bundleName); return; } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); @@ -1153,7 +1208,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); } - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); GetOldDeviceBackupVersion(); @@ -1161,7 +1216,9 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (const auto &fileName : fileNameVec) { int32_t errCode = 0; - UniqueFd fd = proxy->GetFileHandle(fileName, errCode); + int fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(static_cast(fdCode)); session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } @@ -1180,18 +1237,19 @@ int Service::Dump(int fd, const vector &args) return 0; } -void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, const ErrCode ret) +void Service::ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, + const std::string &bundleName, + const ErrCode ret) { try { if (session_ == nullptr) { HILOGE("Report extConnectfailed error, session info is empty"); return; } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -1200,10 +1258,10 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, session_->GetBundleUserId(bundleName)); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName, @@ -1219,7 +1277,7 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = IServiceReverse::Scenario::UNDEFINED; + IServiceReverseType::Scenario scenario = IServiceReverseType::Scenario::UNDEFINED; try { HILOGE("begin %{public}s", bundleName.data()); scenario = session_->GetScenario(); @@ -1241,9 +1299,9 @@ void Service::StartRunningTimer(const std::string &bundleName) { auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); auto scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->StartExtTimer(bundleName, timeoutCallback); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->StartFwkTimer(bundleName, timeoutCallback); } } @@ -1317,7 +1375,7 @@ void Service::ClearSessionAndSchedInfo(const string &bundleName) void Service::HandleRestoreDepsBundle(const string &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (session_->GetScenario() != IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() != IServiceReverseType::Scenario::RESTORE) { return; } HILOGI("Begin, bundleName: %{public}s", bundleName.c_str()); @@ -1372,8 +1430,8 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) HILOGI("SA does not need to StartRestore"); return; } - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } int32_t userId = session_->GetBundleUserId(bundleName); @@ -1395,8 +1453,8 @@ void Service::SendEndAppGalleryNotify(const BundleName &bundleName) HILOGI("SA does not need to EndRestore"); return; } - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } int32_t userId = session_->GetBundleUserId(bundleName); @@ -1445,8 +1503,8 @@ void Service::TryToClearDispose(const BundleName &bundleName) void Service::SendErrAppGalleryNotify() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); @@ -1477,8 +1535,8 @@ void Service::ClearDisposalOnSaStart() void Service::DeleteDisConfigFile() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario != IServiceReverse::Scenario::RESTORE) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { return; } vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); @@ -1497,14 +1555,14 @@ void Service::SessionDeactive() try { HILOGI("Begin"); isInRelease_.store(true); - //清理处置状态 + // 清理处置状态 if (session_ == nullptr) { HILOGE("Session deactive error, session is empty"); return; } ErrCode ret = BError(BError::Codes::OK); std::vector bundleNameList; - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE && + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE && session_->CleanAndCheckIfNeedWait(ret, bundleNameList)) { if (ret != ERR_OK) { isRmConfigFile_.store(false); @@ -1547,7 +1605,8 @@ void Service::SessionDeactive() } } -std::function Service::GetBackupInfoConnectDone(wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName) { HILOGI("GetBackupInfoConnectDone, bundleName: %{public}s", bundleName.c_str()); @@ -1560,8 +1619,8 @@ std::function Service::GetBackupInfoConnectDone(wptr }; } -std::function Service::GetBackupInfoConnectDied( - wptr obj, std::string &bundleName) +std::function Service::GetBackupInfoConnectDied(wptr obj, + const std::string &bundleName) { return [obj](const string &&bundleName, bool isCleanCalled) { HILOGI("GetBackupInfoConnectDied, bundleName: %{public}s", bundleName.c_str()); @@ -1598,13 +1657,13 @@ ErrCode Service::ClearResidualBundleData(const std::string &bundleName) } ClearSessionAndSchedInfo(bundleName); // 非清理任务,需要上报 - if (session_->GetScenario() != IServiceReverse::Scenario::CLEAN) { + if (session_->GetScenario() != IServiceReverseType::Scenario::CLEAN) { OnAllBundlesFinished(BError(BError::Codes::OK)); } return res; } -ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result) { if (session_ == nullptr) { HILOGE("Get BackupInfo error, session is empty."); @@ -1650,7 +1709,7 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { @@ -1660,7 +1719,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } try { std::lock_guard lock(getBackupInfoProcLock_); - HILOGI("Service::GetBackupInfo begin."); + HILOGI("Service::GetBackupInfo begin bundleName: %{public}s", bundleName.c_str()); if (session_ == nullptr || isOccupyingSession_.load()) { HILOGE("Get BackupInfo error, session is empty."); return BError(BError::Codes::SA_INVAL_ARG); @@ -1725,7 +1784,7 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { try { HILOGI("Service::UpdateTimer begin."); @@ -1737,7 +1796,8 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { - HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", bundleName.c_str()); + HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", + bundleName.c_str()); result = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return ret; @@ -1754,7 +1814,7 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res } } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); if (session_ == nullptr || isOccupyingSession_.load()) { @@ -1806,7 +1866,7 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool return ret; } -AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +AAFwk::Want Service::CreateConnectWant(const BundleName &bundleName) { BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; AAFwk::Want want; @@ -1819,14 +1879,14 @@ AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) ErrCode Service::BackupSA(std::string bundleName) { HILOGI("BackupSA begin %{public}s", bundleName.c_str()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = backUpConnection.lock(); if (saConnection == nullptr) { HILOGE("lock sa connection ptr is nullptr"); return BError(BError::Codes::SA_INVAL_ARG); } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { auto ret = saConnection->CallBackupSA(); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); @@ -1836,20 +1896,22 @@ ErrCode Service::BackupSA(std::string bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); return BError(ret); } - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); } return BError(BError::Codes::OK); } -void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, - const ErrCode &errCode) +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) { auto task = [bundleName, fd, result, errCode, this]() { HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", - bundleName.c_str(), fd, result.c_str(), errCode); + bundleName.c_str(), fd, result.c_str(), errCode); session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); - FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); + FileReadyRadarReport(bundleName, "", errCode, IServiceReverseType::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); }; threadPool_.AddTask([task]() { @@ -1864,8 +1926,8 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) { auto task = [bundleName, result, errCode, this]() { - HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", - bundleName.c_str(), result.c_str(), errCode); + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", bundleName.c_str(), + result.c_str(), errCode); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); }; threadPool_.AddTask([task]() { @@ -1897,7 +1959,7 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName) } catch (const BError &e) { ReleaseOnException(); return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch(...) { + } catch (...) { HILOGE("Unexpected exception"); ReleaseOnException(); return EPERM; @@ -1906,8 +1968,8 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName) void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is Backup"); session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); auto now = std::chrono::system_clock::now(); @@ -1915,24 +1977,18 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN auto ms = std::chrono::duration_cast(now.time_since_epoch()); std::stringstream strTime; strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "PROC_NAME", "ohos.appfileservice", - "BUNDLENAME", callerName, - "PID", getpid(), - "TIME", strTime.str() - ); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + << (std::setw(INDEX)) << (ms.count() % MS_1000); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str()); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); } BundleEndRadarReport(callerName, errCode, scenario); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -1993,7 +2049,7 @@ void Service::DoTimeout(wptr ptr, std::string bundleName) HILOGE("SessionPtr is nullptr."); return; } - IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + IServiceReverseType::Scenario scenario = sessionPtr->GetScenario(); try { std::shared_ptr mutexPtr = GetExtensionMutex(bundleName); if (mutexPtr == nullptr) { @@ -2057,8 +2113,8 @@ void Service::DelClearBundleRecord(const std::vector &bundleNames) void Service::ReleaseOnException() { if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverseType::Scenario::RESTORE)) { HILOGI("Will execute destory session info"); SessionDeactive(); } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 307b4204b..dab1cc3fa 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -15,6 +15,8 @@ #include "module_ipc/service.h" +#include "extension_type.h" + #include #include #include @@ -67,18 +69,18 @@ const static string UNICAST_TYPE = "unicast"; ErrCode Service::Release() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("KILL"); + HILOGI("Start Release"); if (session_ == nullptr) { HILOGE("Release error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); VerifyCaller(scenario); AppRadar::Info info("", "", "call release"); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); } @@ -112,6 +114,7 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) void Service::CreateDirIfNotExist(const std::string &path) { + HILOGI("Begin CreateDirIfNotExist, path = %{private}s", path.c_str()); if (access(path.c_str(), F_OK) != 0) { bool created = ForceCreateDirectory(path.data()); if (created) { @@ -121,6 +124,15 @@ void Service::CreateDirIfNotExist(const std::string &path) } } } +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin GetLocalCapabilitiesIncremental fd = %{private}d", fd); + UniqueFd fdResult(GetLocalCapabilitiesIncremental(bundleNames)); + fd = fdResult.Release(); + HILOGI("End GetLocalCapabilitiesIncremental fd = %{private}d", fd); + return BError(BError::Codes::OK); // anytime return OK +} UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) { @@ -177,9 +189,9 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector ptr) { + HILOGI("Begin StartGetFdTask bundleName = %{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { - HILOGE("this pointer is null"); return; } auto session = thisPtr->session_; @@ -211,9 +223,11 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); - string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). - append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); - HILOGD("path = %{public}s,bundleName = %{public}s", path.c_str(), bundleName.c_str()); + string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()) + .append(bundleName) + .append("/") + .append(BConstants::BACKUP_STAT_SYMBOL) + .append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { HILOGD("fdLocal open fail, error = %{public}d", errno); @@ -231,6 +245,7 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) void Service::RefreshBundleDataSize(const vector &newBundleInfos, std::string bundleName, wptr ptr) { + HILOGI("Begin RefreshBundleDataSize bundleName = %{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { HILOGE("this pointer is null"); @@ -293,7 +308,7 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() } } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr& remote) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -306,7 +321,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return BError(BError::Codes::SA_INVAL_ARG); } errCode = session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .isIncrementalBackup = true, @@ -328,7 +343,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) return errCode; } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode errCode = VerifyCaller(); @@ -341,7 +356,7 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote, std: return BError(BError::Codes::SA_INVAL_ARG); } errCode = session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .isIncrementalBackup = true, @@ -386,7 +401,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 bundleNames = GetBundleNameByDetails(bundlesToBackup); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("Append bundles incremental session failed, verify caller failed, ret:%{public}d", ret); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -414,6 +429,13 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + return AppendBundlesIncrementalBackupSession(bundlesToBackup, bundleInfos); +} ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, const std::vector &infos) @@ -423,11 +445,11 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorIncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 bundleNames = GetBundleNameByDetails(bundlesToBackup); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::BACKUP); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); if (ret != ERR_OK) { HILOGE("Append bundles incremental session with infos failed, verify caller failed, ret:%{public}d", ret); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); @@ -447,7 +469,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("Failed, errCode = %{public}d", e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -485,7 +507,7 @@ void Service::HandleCurGroupIncBackupInfos(vector & ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("Publish incremental file failed, bundleName:%{public}s", fileInfo.owner.c_str()); return ret; @@ -518,6 +540,13 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) +{ + HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); + UniqueFd uniquedParameter(static_cast(fd)); + return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); +} + ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { std::string bundleName = fileInfo.owner; @@ -529,45 +558,50 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd } if (!SAUtils::IsSABundleName(bundleName)) { HILOGE("Bundle name %{public}s is not sa", bundleName.c_str()); - return BError(BError::Codes::SA_EXT_ERR_CALL); + return BError(BError::Codes::SA_EXT_ERR_CALL).GetCode(); } HILOGI("Bundle name %{public}s is sa, publish sa incremental file", bundleName.c_str()); auto backupConnection = session_->GetSAExtConnection(bundleName); std::shared_ptr saConnection = backupConnection.lock(); if (saConnection == nullptr) { HILOGE("lock sa connection ptr is nullptr"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } return saConnection->CallRestoreSA(move(fd)); } -ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const std::string &fileName, UniqueFd fd, - UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, + const std::string &fileName, + UniqueFd fd, + UniqueFd manifestFd, + int32_t errCode) { + HILOGI("Begin AppIncrementalFileReadybundleName:%{public}s, fileName:%p{ublic}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(bundleName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); - return BError(BError::Codes::OK); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); + return BError(BError::Codes::OK).GetCode(); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(bundleName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); - FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); + move(manifestFd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); if (ret != ERR_OK) { - HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); return ret; } } OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); + return ErrCode((BError::Codes::OK)); } catch (const BError &e) { HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 @@ -577,28 +611,47 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st } } +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + HILOGI("Begin AppIncrementalFileReady:%{public}s, fd:%{public}d, manifestFd:%{public}d, errcode:%{public}d", + fileName.c_str(), fd, manifestFd, appIncrementalFileReadyErrCode); + if (fd < 0 || manifestFd < 0) { + HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); + } + UniqueFd fdUnique(fd); + UniqueFd manifestFdUnique(manifestFd); + return AppIncrementalFileReady(fileName, std::move(fdUnique), std::move(manifestFdUnique), + appIncrementalFileReadyErrCode); +} + ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("Begin AppIncrementalFileReady:%{public}s, errcode:%{public}d", + fileName.c_str(), errCode); string callerName; ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { HILOGE("Verify caller failed, ret:%{public}d", ret); return ret; } - if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::RESTORE); - return BError(BError::Codes::OK); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); + return BError(BError::Codes::OK).GetCode(); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); - FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::BACKUP); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(callerName, fileName)) { ErrCode ret = HandleCurBundleFileReady(callerName, fileName, true); if (ret != ERR_OK) { @@ -608,7 +661,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f } } OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 @@ -667,9 +720,9 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s try { if (session_ == nullptr) { HILOGE("GetIncrementalFileHandle error, session is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("Error, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), GetAnonyPath(fileName).c_str()); @@ -678,24 +731,25 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::UNKNOWN) { HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("GetIncrementalFileHandle failed, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - auto[errCode, fd, reportFd] = proxy->GetIncrementalFileHandle(fileName); - auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); + UniqueFdGroup fdGroup; + proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); + UniqueFd fd(static_cast(fdGroup.fd)); + UniqueFd reportFd(static_cast(fdGroup.reportFd)); + auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (err != ERR_OK) { - HILOGE("Failed to send file handle, bundleName:%{public}s, fileName:%{public}s", - bundleName.c_str(), GetAnonyPath(fileName).c_str()); AppRadar::Info info (bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandle", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, err); @@ -704,7 +758,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); session_->SetExtFileNameRequest(bundleName, fileName); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } catch (const BError &e) { HILOGE("GetIncrementalFileHandle exception, bundleName:%{public}s", bundleName.c_str()); return e.GetCode(); @@ -714,7 +768,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s bool Service::IncrementalBackup(const string &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); @@ -729,17 +783,18 @@ bool Service::IncrementalBackup(const string &bundleName) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); return true; } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { auto ret = proxy->IncrementalOnBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); - BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::BACKUP); + BundleBeginRadarReport(bundleName, ret, IServiceReverseType::Scenario::BACKUP); if (ret) { SendEndAppGalleryNotify(bundleName); ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); } return true; - } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); @@ -747,12 +802,14 @@ bool Service::IncrementalBackup(const string &bundleName) if (oldBackupVersion.empty()) { HILOGE("Failed to get backupVersion of old device"); } - HILOGD("backupVersion of old device = %{public}s", oldBackupVersion.c_str()); - BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::RESTORE); + BundleBeginRadarReport(bundleName, ret, IServiceReverseType::Scenario::RESTORE); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (const auto &fileName : fileNameVec) { - auto[errCode, fd, reportFd] = proxy->GetIncrementalFileHandle(fileName); - ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); + UniqueFdGroup fdGroup; + proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); + UniqueFd fd(static_cast(fdGroup.fd)); + UniqueFd reportFd(static_cast(fdGroup.reportFd)); + ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (ret) { HILOGE("Failed to send file handle %{public}s", GetAnonyString(fileName).c_str()); } @@ -764,8 +821,10 @@ bool Service::IncrementalBackup(const string &bundleName) void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string &callerName) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { + HILOGI("Begin NotifyCallerCurAppIncrementDone errCode = %{public}d, callerName = %{public}s", + errCode, callerName.c_str()); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is incremental backup"); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); @@ -782,7 +841,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string "PROC_NAME", "ohos.appfileservice", "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str() ); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); @@ -791,6 +850,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string void Service::SendUserIdToApp(string &bundleName, int32_t userId) { + HILOGI("Begin SendUserIdToApp bundleName%{public}s, userId%{public}d", bundleName.c_str(), userId); if (session_ == nullptr) { HILOGI("session_ is nullptr"); return; @@ -858,6 +918,7 @@ void Service::SetBundleIncDataInfo(const std::vector& bundlesT void Service::CancelTask(std::string bundleName, wptr ptr) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin CancelTask bundleName%{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { HILOGE("this pointer is null"); @@ -891,9 +952,9 @@ void Service::CancelTask(std::string bundleName, wptr ptr) session->StopExtTimer(bundleName); backUpConnection->DisconnectBackupExtAbility(); thisPtr->ClearSessionAndSchedInfo(bundleName); - IServiceReverse::Scenario scenario = session->GetScenario(); - if ((scenario == IServiceReverse::Scenario::BACKUP && session->GetIsIncrementalBackup()) || - (scenario == IServiceReverse::Scenario::RESTORE && + IServiceReverseType::Scenario scenario = session->GetScenario(); + if ((scenario == IServiceReverseType::Scenario::BACKUP && session->GetIsIncrementalBackup()) || + (scenario == IServiceReverseType::Scenario::RESTORE && session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND))) { thisPtr->NotifyCallerCurAppIncrementDone(BError(BError::Codes::OK), bundleName); } else { @@ -904,7 +965,7 @@ void Service::CancelTask(std::string bundleName, wptr ptr) thisPtr->OnAllBundlesFinished(BError(BError::Codes::OK)); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin, bundle name:%{public}s", bundleName.c_str()); @@ -912,7 +973,7 @@ ErrCode Service::Cancel(std::string bundleName, int32_t &result) HILOGE("Cancel error, session is null"); return BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK); } - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); ErrCode ret = VerifyCaller(scenario); if (ret != ERR_OK) { HILOGE("Verify caller failed, bundleName:%{public}s, scenario:%{public}d", bundleName.c_str(), scenario); diff --git a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp deleted file mode 100644 index 57e412c92..000000000 --- a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "module_ipc/service_reverse_proxy.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" -#include "module_app_gallery/app_gallery_dispose_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = true; - if (fd < 0 || manifestFd < 0) { - fdFlag = false; - } - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || - !data.WriteString(fileName) || !data.WriteBool(fdFlag) || - (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || - !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnResultReport(std::string result, std::string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalBackupOnScanningInfo(std::string scannedInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SCANNED_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED), - data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnResultReport(std::string result, - std::string bundleName, ErrCode errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || - !data.WriteString(bundleName) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || - !data.WriteString(fileName) || !data.WriteBool(fdFlag) || - (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || - !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp deleted file mode 100644 index 2d2dbab36..000000000 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ /dev/null @@ -1,259 +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_reverse_proxy.h" - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "filemgmt_libhilog.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = fd < 0 ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || - !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnResultReport(std::string result, std::string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - }; - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_PROCESS_INFO), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::BackupOnScanningInfo(std::string scannedInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SCANNED_INFO), data, - reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - bool fdFlag = fd < 0 ? false : true; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || - !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode) -{ - HILOGI("ServiceReverseProxy::RestoreOnResultReport Begin with result: %s", result.c_str()); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || - !data.WriteString(bundleName) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), data, reply, - option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} - -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) -{ - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) { - throw BError(BError::Codes::SA_BROKEN_IPC); - } - - MessageParcel reply; - MessageOption option; - if (int err = Remote()->SendRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO), data, reply, option); - err != ERR_OK) { - throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); - } -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp deleted file mode 100644 index ae94248e9..000000000 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ /dev/null @@ -1,858 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * 注意: - * - 注意点1:本文件原则上只处理与IPC模块的IO,具体业务逻辑实现在service.cpp中 - * - 注意点2:所有调用开头处打印 Begin 字样,通过BError返回正常结果/错误码,这是出于防抵赖的目的 - */ - -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_error/b_excep_utils.h" -#include "b_resources/b_constants.h" -#include "filemgmt_libhilog.h" -#include "module_ipc/service_reverse_proxy.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -const int INVALID_FD = -1; - - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER)] = - &ServiceStub::CmdStartExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] = - &ServiceStub::CmdStartFwkTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; -} - -void ServiceStub::ServiceStubSuppAppendBundles() -{ - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; -} - -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT)] = - &ServiceStub::CmdResultReport; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - ServiceStubSuppAppendBundles(); - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_SA_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishSAIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE)] = - &ServiceStub::CmdAppIncrementalDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; - ServiceStubSupplement(); -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::SA_INVAL_ARG, "Invalid remote descriptor"); - } - - HILOGD("Begin to call procedure indexed %{public}u", code); - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - HILOGE("Cannot response request %{public}d : unknown procedure", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return BExcepUltils::ExceptionCatcherLocked( - [&]() { return ErrCode((this->*(interfaceIndex->second))(data, reply)); }); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitRestoreSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitRestoreSession(iremote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int res = InitBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int res = InitBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppFileReady(fileName, move(fd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = AppDone(errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - int32_t scenario; - ErrCode errCode; - if (!data.ReadString(restoreRetInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreRetInfo"); - } - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive scenario"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - if (!data.ReadInt32(errCode)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - int res = ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - HILOGE("Failed to receive bundle detailInfos"); - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - int32_t type; - if (!data.ReadInt32(type)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); - } - RestoreTypeEnum restoreType = static_cast(type); - int32_t userId; - if (!data.ReadInt32(userId)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); - } - - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos, restoreType, userId); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesBackupSession(bundleNames); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!data.ReadStringVector(&bundleNames)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - vector detailInfos; - if (!data.ReadStringVector(&detailInfos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive detailInfos"); - } - - int32_t res = AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - int res = Finish(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdGetBackupInfo Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - string result; - ret = GetBackupInfo(bundleName, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); - } - if (!reply.WriteString(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdGetBackupInfo end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateTimer Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); - } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdUpdateSendRate Begin."); - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateSendRate")); - } - if (!reply.WriteBool(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdUpdateSendRate end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartExtTimer Begin."); - int ret = ERR_OK; - bool isExtStart; - ret = StartExtTimer(isExtStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isExtStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStartFwkTimer Begin."); - int ret = ERR_OK; - bool isFwkStart; - ret = StartFwkTimer(isFwkStart); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer")); - } - if (!reply.WriteBool(isFwkStart)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStartFwkTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - vector bundleNames; - if (!ReadParcelableVector(bundleNames, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - UniqueFd fd(GetLocalCapabilitiesIncremental(bundleNames)); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - int32_t res = GetAppLocalListAndDoIncrementalBackup(); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iremote = iface_cast(remote); - if (!iremote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - - int32_t res = InitIncrementalBackupSession(iremote); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - std::string errMsg; - if (!remote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - auto iRemote = iface_cast(remote); - if (!iRemote) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive the reverse stub"); - } - int32_t res = InitIncrementalBackupSession(iRemote, errMsg); - if (!reply.WriteString(errMsg)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send the errMsg"); - } - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - vector bundlesToBackup; - if (!ReadParcelableVector(bundlesToBackup, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - std::vector infos; - if (!data.ReadStringVector(&infos)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive infos"); - } - int32_t res = AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (!reply.WriteInt32(res)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - int res = PublishIncrementalFile(*fileInfo); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishSAIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - if (!fileInfo) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to receive fileInfo"); - } - UniqueFd fd(data.ReadFileDescriptor()); - int res = PublishSAIncrementalFile(*fileInfo, move(fd)); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName"); - } - bool fdFlag = data.ReadBool(); - UniqueFd fd = UniqueFd(INVALID_FD); - UniqueFd manifestFd = UniqueFd(INVALID_FD); - if (fdFlag == true) { - fd = UniqueFd(data.ReadFileDescriptor()); - if (fd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); - } - - manifestFd = UniqueFd(data.ReadFileDescriptor()); - if (manifestFd < 0) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive manifestFd"); - } - } - int32_t errCode = data.ReadInt32(); - - int res = AppIncrementalFileReady(fileName, move(fd), move(manifestFd), errCode); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply) -{ - int32_t ret; - if (!data.ReadInt32(ret)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bool flag"); - } - int res = AppIncrementalDone(ret); - if (!reply.WriteInt32(res)) { - stringstream ss; - ss << "Failed to send the result " << res; - return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - string fileName; - if (!data.ReadString(fileName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fileName").GetCode(); - } - return GetIncrementalFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - string processInfo; - if (!data.ReadString(processInfo)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int32_t scenario; - if (!data.ReadInt32(scenario)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); - } - BackupRestoreScenario secenrioInfo = static_cast(scenario); - return ReportAppProcessInfo(processInfo, secenrioInfo); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdStopExtTimer Begin."); - bool isExtStop; - auto ret = StopExtTimer(isExtStop); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call StopExtTimer")); - } - if (!reply.WriteBool(isExtStop)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdStopExtTimer end."); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdRefreshDataSize Begin."); - int64_t totalDatasize = 0; - if (!data.ReadInt64(totalDatasize)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive totalDatasize").GetCode(); - } - auto ret = RefreshDataSize(totalDatasize); - if (ret != ERR_OK) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to receive totalDatasize")); - } - bool ifRefreshSuccess = true; - if (!reply.WriteBool(ifRefreshSuccess)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); - } - HILOGI("ServiceStub::CmdRefreshDataSize end."); - return BError(BError::Codes::OK); -} - -template -bool ServiceStub::ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - HILOGE("Failed to read Parcelable size."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < BConstants::MAX_PARCELABLE_VECTOR_NUM) ? infoSize : BConstants::MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadParcelable(); - if (info == nullptr) { - HILOGE("Failed to read Parcelable infos."); - return false; - } - parcelableInfos.emplace_back(move(*info)); - } - - return true; -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub::CmdCancel Begin."); - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName").GetCode(); - } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ErrCode res = Cancel(bundleName, result); - if (!reply.WriteInt32(result)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); - } - return res; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilitiesForBundleInfos()); - if (!reply.WriteFileDescriptor(fd)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to send out the file"); - } - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - HILOGI("ServiceStub CmdGetBackupDataSize Begin."); - bool isPreciseScan = true; - isPreciseScan = data.ReadBool(); - vector bundleNameList; - if (!ReadParcelableVector(bundleNameList, data)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); - } - auto ret = GetBackupDataSize(isPreciseScan, bundleNameList); - HILOGI("ServiceStub GetBackupDataSize End ret = %{public}d", ret); - return ret; -} -} // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b679afd82..1b125b3ea 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -36,7 +36,7 @@ #include "b_anony/b_anony.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_hiaudit/hi_audit.h" #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" @@ -82,11 +82,11 @@ void Service::AppendBundles(const std::vector &bundleNames) } } -void Service::ReportOnBundleStarted(IServiceReverse::Scenario scenario, const std::string &bundleName) +void Service::ReportOnBundleStarted(IServiceReverseType::Scenario scenario, const std::string &bundleName) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), bundleName); } } @@ -163,7 +163,7 @@ bool Service::IsReportFileReadyFail(const std::string &bundleName) return true; } -void Service::TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName) +void Service::TimeoutRadarReport(IServiceReverseType::Scenario scenario, std::string &bundleName) { if (!IsReportBundleExecFail(bundleName)) { return; @@ -173,11 +173,11 @@ void Service::TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string if (session_->GetTimeoutValue(bundleName) == 0) { errCode = BError::BackupErrorCode::E_FORCE_TIMEOUT; } - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::Info info(bundleName, "", "on backup timeout"); AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::TimeOutCallback", GetUserIdDefault(), BizStageBackup::BIZ_STAGE_ON_BACKUP, errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::Info info(bundleName, "", "on restore timeout"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::TimeOutCallback", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_ON_RESTORE, errCode); @@ -216,7 +216,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) HILOGE("PublishFile error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - ErrCode ret = VerifyCaller(IServiceReverse::Scenario::RESTORE); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); if (ret != ERR_OK) { HILOGE("PublishFile error, verify caller by scenario failed, ret:%{public}d", ret); return ret; @@ -243,6 +243,17 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) +{ + HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); + UniqueFd fdUnique(static_cast(fd)); + if (fd < 0) { + HILOGE("Error fd, fd = %{public}d", fd); + return BError(BError::Codes::SA_INVAL_ARG); + } + return AppFileReady(fileName, std::move(fdUnique), errCode); +} + ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -288,6 +299,7 @@ ErrCode Service::AppDone(ErrCode errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("AppDone errCode =%{public}d", errCode); if (session_ == nullptr) { HILOGE("App finish error, session info is empty"); return BError(BError::Codes::SA_INVAL_ARG); @@ -330,17 +342,17 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("begin %{public}s", bundleName.data()); - IServiceReverse::Scenario scenario = session_->GetScenario(); + IServiceReverseType::Scenario scenario = session_->GetScenario(); BConstants::ExtensionAction action; - if (scenario == IServiceReverse::Scenario::BACKUP || scenario == IServiceReverse::Scenario::CLEAN) { + if (scenario == IServiceReverseType::Scenario::BACKUP || scenario == IServiceReverseType::Scenario::CLEAN) { action = BConstants::ExtensionAction::BACKUP; - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { action = BConstants::ExtensionAction::RESTORE; } else { action = BConstants::ExtensionAction::INVALID; HILOGE("Launch current bundle backupExtension failed, action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (SAUtils::IsSABundleName(bundleName)) { return LaunchBackupSAExtension(bundleName); @@ -350,25 +362,25 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("LaunchBackupExtension error, backUpConnection is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } if (backUpConnection->IsExtAbilityConnected() && !backUpConnection->WaitDisconnectDone()) { HILOGE("LaunchBackupExtension error, WaitDisconnectDone failed"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } BConstants::ServiceSchedAction bundleAction = session_->GetServiceSchedAction(bundleName); if (bundleAction == BConstants::ServiceSchedAction::UNKNOWN) { HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId(), bundleAction == BConstants::ServiceSchedAction::CLEAN); if (ret != ERR_OK) { HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); ExtensionConnectFailRadarReport(bundleName, ret, scenario); - return BError(BError::Codes::SA_BOOT_EXT_FAIL); + return BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode(); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } void Service::SetWant(AAFwk::Want &want, const BundleName &bundleName, const BConstants::ExtensionAction &action) @@ -414,7 +426,7 @@ std::vector Service::GetSupportBackupBundleNames(vectorGetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); }; BundleEndRadarReport(bundleName, errCode, scenario); @@ -643,20 +655,20 @@ void Service::OnAllBundlesFinished(ErrCode errCode) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("called begin."); if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverseType::Scenario::RESTORE)) { HILOGI("Will destory session info"); SessionDeactive(); } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE && + } else if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnAllBundlesFinished(errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnAllBundlesFinished(errCode); } if (!BackupPara().GetBackupOverrideBackupSARelease()) { @@ -674,12 +686,12 @@ ErrCode Service::VerifySendRateParam() HILOGE("Update send rate fail, verify caller failed, ret:%{public}d", ret); return ret; } - IServiceReverse::Scenario scenario = session_ -> GetScenario(); - if (scenario != IServiceReverse::Scenario::BACKUP) { + IServiceReverseType::Scenario scenario = session_ -> GetScenario(); + if (scenario != IServiceReverseType::Scenario::BACKUP) { HILOGE("This method is applicable to the backup scenario"); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const std::string &fileName, bool isIncBackup) @@ -687,12 +699,12 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("AppFileReady error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("AppFileReady error, Extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } // 通知extension清空缓存 proxy->HandleClear(); @@ -703,7 +715,7 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s if (isIncBackup) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), bundleName); - BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); + BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverseType::Scenario::BACKUP); } else { session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), bundleName); BundleEndRadarReport(bundleName, BError(BError::Codes::OK), session_->GetScenario()); @@ -711,7 +723,7 @@ ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const s // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(bundleName); - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup) @@ -719,12 +731,12 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("App finish error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("App finish error, extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + return BError(BError::Codes::SA_INVAL_ARG).GetCode(); } proxy->HandleClear(); session_->StopFwkTimer(bundleName); @@ -741,7 +753,7 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName bundleName.c_str(), errCode); NotifyCallerCurAppDone(errCode, bundleName); } - return BError(BError::Codes::OK); + return BError(BError::Codes::OK).GetCode(); } std::string Service::GetCallerName() @@ -775,7 +787,13 @@ std::string Service::GetCallerName() return callerName; } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + HILOGI("Start InitRestoreSessionWithErrMsg,Msg :%{public}s", errMsg.c_str()); + return InitRestoreSession(remote, errMsg); +} + +ErrCode Service::InitRestoreSession(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -785,7 +803,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e } ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::RESTORE, + .scenario = IServiceReverseType::Scenario::RESTORE, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -810,7 +828,7 @@ ErrCode Service::InitRestoreSession(sptr remote, std::string &e return ret; } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); @@ -823,7 +841,7 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er session_->SetMemParaCurSize(oldSize); ret = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, + .scenario = IServiceReverseType::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), .callerName = GetCallerName(), @@ -848,6 +866,14 @@ ErrCode Service::InitBackupSession(sptr remote, std::string &er return ret; } +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + UniqueFd uniqueFd(GetLocalCapabilitiesForBundleInfos()); + HILOGI("get GetLocalCapabilitiesForBundleInfos value"); + fd = uniqueFd.Release(); + return ErrCode(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilitiesForBundleInfos() { try { @@ -920,7 +946,7 @@ void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRes } } -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { HILOGI("start GetBackupDataSize"); @@ -1133,7 +1159,7 @@ void Service::SendScannedInfo(const string&scannendInfos, sptrGetScenario() == IServiceReverse::Scenario::BACKUP && session->GetIsIncrementalBackup()) { + if (session->GetScenario() == IServiceReverseType::Scenario::BACKUP && session->GetIsIncrementalBackup()) { HILOGI("this is incremental backup sending info"); session->GetServiceReverseProxy()->IncrementalBackupOnScanningInfo(scannendInfos); return; diff --git a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp index 7dc6d5eec..58bdb6158 100644 --- a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp @@ -21,7 +21,7 @@ #include "ability_manager_client.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" -#include "module_ipc/svc_extension_proxy.h" +#include "extension_proxy.h" #include "module_ipc/svc_session_manager.h" namespace OHOS::FileManagement::Backup { @@ -40,7 +40,7 @@ void SvcBackupConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &el HILOGE("Failed to ability connect done, remote is nullptr"); return; } - backupProxy_ = iface_cast(remoteObject); + backupProxy_ = iface_cast(remoteObject); if (backupProxy_ == nullptr) { HILOGE("Failed to ability connect done, backupProxy_ is nullptr"); return; diff --git a/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp deleted file mode 100644 index c29b0e72b..000000000 --- a/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "module_ipc/svc_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; - -std::tuple SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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), UniqueFd(-1), UniqueFd(-1)}; - } - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_FILE_HANDLE), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return {ErrCode(ret), UniqueFd(-1), UniqueFd(-1)}; - } - - HILOGD("Successful"); - ErrCode err(reply.ReadInt32()); - UniqueFd fd(reply.ReadFileDescriptor()); - UniqueFd reportFd(reply.ReadFileDescriptor()); - return {err, move(fd), move(reportFd)}; -} - -ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_INCREMENTAL_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::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("Start"); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - data.WriteFileDescriptor(incrementalFd); - data.WriteFileDescriptor(manifestFd); - - MessageParcel reply; - MessageOption option; - int32_t ret = Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_HANDLE_INCREMENTAL_BACKUP), - 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::IncrementalOnBackup(bool isClearData) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_INCREMENTAL_ON_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGD("Successful"); - return BError(BError::Codes::OK); -} - -ErrCode SvcExtensionProxy::User0OnBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_USER_0_BACKUP), - data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - - HILOGD("Successful"); - return reply.ReadInt32(); -} - -tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGD("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_GET_INCREMENTAL_BACKUP_FILE_HANDLE), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return {UniqueFd(-1), UniqueFd(-1)}; - } - - HILOGD("Successful"); - UniqueFd incrementalFd(reply.ReadFileDescriptor()); - UniqueFd manifestFd(reply.ReadFileDescriptor()); - return {move(incrementalFd), move(manifestFd)}; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 ce2bfcc36..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 "module_ipc/svc_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/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index a0aafce1c..fdf175875 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -25,7 +25,7 @@ #include "b_anony/b_anony.h" #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_entity_ext_manage.h" #include "b_radar/b_radar.h" @@ -40,7 +40,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { shared_lock lock(lock_); if (impl_.scenario != scenario) { @@ -88,7 +88,7 @@ ErrCode SvcSessionManager::Active(Impl newImpl, bool isOccupyingSession) HILOGE("Active session fail, No caller token was specified"); return BError(BError::Codes::SA_INVAL_ARG); } - if (!isOccupyingSession && newImpl.scenario == IServiceReverse::Scenario::UNDEFINED) { + if (!isOccupyingSession && newImpl.scenario == IServiceReverseType::Scenario::UNDEFINED) { HILOGE("Active session fail, No scenario was specified"); return BError(BError::Codes::SA_INVAL_ARG); } @@ -124,10 +124,10 @@ ErrCode SvcSessionManager::Deactive(const wptr &remoteInAction, b deathRecipient_ = nullptr; AppRadar::Info info("", "", "deactive session success"); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, BizStageRestore::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); - } else if (impl_.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (impl_.scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, BizStageBackup::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); } @@ -163,12 +163,12 @@ sptr SvcSessionManager::GetServiceReverseProxy() return impl_.clientProxy; } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { shared_lock lock(lock_); if (!impl_.clientToken) { HILOGE("Get scenario failed, No caller token was specified"); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; } return impl_.scenario; } @@ -217,10 +217,10 @@ bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string return false; } // 判断是否结束 通知EXTENTION清理资源 TOOL应用完成备份 - if (impl_.scenario == IServiceReverse::Scenario::RESTORE || SAUtils::IsSABundleName(bundleName)) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE || SAUtils::IsSABundleName(bundleName)) { it->second.isBundleFinished = true; return true; - } else if (impl_.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (impl_.scenario == IServiceReverseType::Scenario::BACKUP) { if (!fileName.empty() && fileName != BConstants::EXT_BACKUP_MANAGE) { auto ret = it->second.fileNameInfo.emplace(fileName); if (!ret.second) { @@ -246,7 +246,7 @@ UniqueFd SvcSessionManager::OnBundleExtManageInfo(const string &bundleName, Uniq HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); return UniqueFd(-EPERM); } - if (impl_.scenario != IServiceReverse::Scenario::BACKUP) { + if (impl_.scenario != IServiceReverseType::Scenario::BACKUP) { HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); return UniqueFd(-EPERM); } @@ -436,10 +436,10 @@ ErrCode SvcSessionManager::InitClient(Impl &newImpl) deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); AppRadar::Info info("", "", "active session success"); - if (newImpl.scenario == IServiceReverse::Scenario::RESTORE) { + if (newImpl.scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, BizStageRestore::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); - } else if (newImpl.scenario == IServiceReverse::Scenario::BACKUP) { + } else if (newImpl.scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, BizStageBackup::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); } @@ -470,7 +470,7 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string return std::set(); } - if (impl_.scenario != IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario != IServiceReverseType::Scenario::RESTORE) { HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); return std::set(); } @@ -682,7 +682,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.isAppendFinish = true; } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { HILOGD("SvcSessionManager::CreateBackupConnection begin."); return GetBackupAbilityExt(bundleName); @@ -718,7 +718,7 @@ bool SvcSessionManager::IsOnAllBundlesFinished() return false; } bool isAllBundlesFinished = !impl_.backupExtNameMap.size(); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isAllBundlesFinished = (isAllBundlesFinished && isAllBundlesRestored); } @@ -748,7 +748,7 @@ bool SvcSessionManager::NeedToUnloadService() return false; } bool isNeedToUnloadService = (!impl_.backupExtNameMap.size() && (sessionCnt_.load() <= 0)); - if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + if (impl_.scenario == IServiceReverseType::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isNeedToUnloadService = (isNeedToUnloadService && isAllBundlesRestored); } diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 5c8b5de7a..ebdf00c28 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -40,16 +40,16 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ExtDiedClearFailRadarReport(const string& bundleName, IServiceReverse::Scenario scenario, ErrCode res) +void ExtDiedClearFailRadarReport(const string& bundleName, IServiceReverseType::Scenario scenario, ErrCode res) { if (res == ERR_OK) { return; } AppRadar::Info info(bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "SchedScheduler::ExecutingQueueTasks", AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "SchedScheduler::ExecutingQueueTasks", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); } @@ -240,7 +240,7 @@ void SchedScheduler::StartExecuteBundleTask(const std::string &bundleName, BCons } else if (action == BConstants::ServiceSchedAction::CLEAN) { HILOGI("Current bundle %{public}s process is cleaning", bundleName.data()); ErrCode res = reversePtr_->ClearResidualBundleData(bundleName); - IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); + IServiceReverseType::Scenario scenario = sessionPtr_->GetScenario(); ExtDiedClearFailRadarReport(bundleName, scenario, res); } } diff --git a/test/fuzztest/backupext_fuzzer/BUILD.gn b/test/fuzztest/backupext_fuzzer/BUILD.gn index 81a738cca..66f9093fd 100644 --- a/test/fuzztest/backupext_fuzzer/BUILD.gn +++ b/test/fuzztest/backupext_fuzzer/BUILD.gn @@ -41,7 +41,6 @@ ohos_fuzztest("BackupExtFuzzTest") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", diff --git a/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp b/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp index 19065f4cc..f2fa08267 100644 --- a/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp +++ b/test/fuzztest/backupext_fuzzer/backupext_fuzzer.cpp @@ -47,7 +47,7 @@ bool OnRemoteRequestFuzzTest(shared_ptr extension, const uin int pos = 0; uint32_t code = TypeCast(data, &pos); - msg.WriteInterfaceToken(ExtExtensionStub::GetDescriptor()); + msg.WriteInterfaceToken(ExtensionStub::GetDescriptor()); msg.WriteBuffer(data + pos, size - pos); msg.RewindRead(0); @@ -160,137 +160,6 @@ bool SetCreatorFuzzTest(shared_ptr backup, const uint8_t *data, size_ backup->SetCreator(creator); return true; } - -bool CmdGetFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdGetFileHandle(msg, reply); - return true; -} - -bool CmdHandleClearFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdHandleClear(msg, reply); - return true; -} - -bool CmdHandleUser0BackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdHandleUser0Backup(msg, reply); - return true; -} - -bool CmdHandleBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdHandleBackup(msg, reply); - return true; -} - -bool CmdPublishFileFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdPublishFile(msg, reply); - return true; -} - -bool CmdHandleRestoreFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdHandleRestore(msg, reply); - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdGetIncrementalFileHandle(msg, reply); - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteString(string(reinterpret_cast(data), size)); - extension->CmdPublishIncrementalFile(msg, reply); - return true; -} - -bool CmdHandleIncrementalBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - int pos = 0; - int incrementalFd = TypeCast(data, &pos); - int manifestFd = TypeCast(data + pos); - msg.WriteFileDescriptor(incrementalFd); - msg.WriteFileDescriptor(manifestFd); - extension->CmdPublishIncrementalFile(msg, reply); - return true; -} - -bool CmdIncrementalOnBackupFuzzTest(shared_ptr extension, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(bool)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - msg.WriteBool(*reinterpret_cast(data)); - extension->CmdIncrementalOnBackup(msg, reply); - return true; -} - -bool CmdGetIncrementalBackupFileHandleFuzzTest(shared_ptr extension, const uint8_t *data, - size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - msg.WriteBuffer(data, size); - extension->CmdGetIncrementalBackupFileHandle(msg, reply); - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -313,22 +182,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::RestoreDataReadyFuzzTest(extBackup, data, size); OHOS::InvokeAppExtMethodFuzzTest(extBackup, data, size); OHOS::SetCreatorFuzzTest(extBackup, data, size); - - try { - OHOS::CmdGetFileHandleFuzzTest(extension, data, size); - OHOS::CmdHandleClearFuzzTest(extension, data, size); - OHOS::CmdHandleUser0BackupFuzzTest(extension, data, size); - OHOS::CmdHandleBackupFuzzTest(extension, data, size); - OHOS::CmdPublishFileFuzzTest(extension, data, size); - OHOS::CmdHandleRestoreFuzzTest(extension, data, size); - OHOS::CmdGetIncrementalFileHandleFuzzTest(extension, data, size); - OHOS::CmdPublishIncrementalFileFuzzTest(extension, data, size); - OHOS::CmdHandleIncrementalBackupFuzzTest(extension, data, size); - OHOS::CmdIncrementalOnBackupFuzzTest(extension, data, size); - OHOS::CmdGetIncrementalBackupFileHandleFuzzTest(extension, data, size); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return 0; } diff --git a/test/fuzztest/backupsa_fuzzer/BUILD.gn b/test/fuzztest/backupsa_fuzzer/BUILD.gn index 2335ebb8f..3db3c922c 100644 --- a/test/fuzztest/backupsa_fuzzer/BUILD.gn +++ b/test/fuzztest/backupsa_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("BackupSaFuzzTest") { deps = [ "${app_file_service_path}/services/backup_sa:backup_sa", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", ] diff --git a/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp b/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp index a811dcc08..e3b108070 100644 --- a/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp +++ b/test/fuzztest/backupsa_fuzzer/backupsa_fuzzer.cpp @@ -19,12 +19,12 @@ #include #include -#include #include "message_parcel.h" -#include "service_stub.h" -#include "service.h" #include "securec.h" +#include "service.h" +#include "service_stub.h" #include "system_ability.h" +#include #include "filemgmt_libhilog.h" @@ -48,13 +48,13 @@ bool BackupSaFuzzTest(const uint8_t *data, size_t size) } sptr service = sptr(new Service(SERVICE_ID)); - uint32_t code = GetU32Data(reinterpret_cast(data)); + uint32_t code = GetU32Data(reinterpret_cast(data)); if (code == 0) { return true; } MessageParcel datas; datas.WriteInterfaceToken(ServiceStub::GetDescriptor()); - datas.WriteBuffer(reinterpret_cast(data + U32_AT_SIZE), size - U32_AT_SIZE); + datas.WriteBuffer(reinterpret_cast(data + U32_AT_SIZE), size - U32_AT_SIZE); datas.RewindRead(0); MessageParcel reply; MessageOption option; diff --git a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp index ca438cd7c..2b1f339e3 100644 --- a/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp +++ b/test/fuzztest/backupsaanother_fuzzer/backupsaanother_fuzzer.cpp @@ -54,7 +54,7 @@ bool CmdGetFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_FILE_HANDLE), datas, reply, option); service = nullptr; return true; @@ -79,7 +79,7 @@ bool CmdAppendBundlesBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -95,7 +95,7 @@ bool CmdReleaseFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_RELEASE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -113,7 +113,7 @@ void GetBundleNamesData(const uint8_t *data, size_t size, vector(data)); - int32_t fd = *(reinterpret_cast(data)); + int fd = *(reinterpret_cast(data)); int32_t priority = *(reinterpret_cast(data + sizeof(int32_t))); string parameters = string(reinterpret_cast(data), size) + to_string(size - i); BIncrementalData incrementaData(name, nTime, fd, parameters, priority); @@ -152,7 +152,7 @@ bool CmdGetLocalCapabilitiesIncrementalFuzzTest(const uint8_t *data, size_t size MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -168,7 +168,7 @@ bool CmdInitIncrementalBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -189,7 +189,7 @@ bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(const uint8_t *data, size_ sptr service(new Service(SERVICE_ID)); uint32_t code = static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); + IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -216,7 +216,7 @@ bool CmdPublishIncrementalFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -242,7 +242,7 @@ bool CmdAppIncrementalFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -261,7 +261,7 @@ bool CmdAppIncrementalDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE), datas, reply, option); service = nullptr; return true; @@ -287,7 +287,7 @@ bool CmdGetIncrementalFileHandleFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp index 2c44b7943..6d94b527d 100644 --- a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -45,7 +45,7 @@ bool CmdInitRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION), datas, reply, option); service = nullptr; return true; @@ -61,7 +61,7 @@ bool CmdInitBackupSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION), datas, reply, option); service = nullptr; return true; @@ -87,7 +87,7 @@ bool CmdPublishFileFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_PUBLISH_FILE), datas, reply, option); service = nullptr; return true; @@ -103,7 +103,7 @@ bool CmdGetLocalCapabilitiesFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -127,7 +127,7 @@ bool CmdAppFileReadyFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - uint32_t code = static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY); + uint32_t code = static_cast(IServiceIpcCode::COMMAND_APP_FILE_READY); service->OnRemoteRequest(code, datas, reply, option); service = nullptr; return true; @@ -145,7 +145,7 @@ bool CmdAppDoneFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APP_DONE), datas, reply, option); service = nullptr; return true; @@ -161,7 +161,7 @@ bool CmdStartFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_START), datas, reply, option); service = nullptr; return true; @@ -177,7 +177,7 @@ bool CmdFinishFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_FINISH), datas, reply, option); service = nullptr; return true; @@ -219,7 +219,7 @@ bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND), datas, reply, option); service = nullptr; return true; diff --git a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp index 2858c657a..11fbc23eb 100644 --- a/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp +++ b/test/fuzztest/backupservicestub_fuzzer/backupservicestub_fuzzer.cpp @@ -17,7 +17,7 @@ #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_session_backup.h" #include "b_session_restore.h" #include "message_parcel.h" @@ -72,547 +72,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd); - } - msg.WriteInt32(errCode); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(scenario); - msg.WriteInt32(errCode); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - msg.WriteFileDescriptor(fd); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - msg.WriteInt32(type); - msg.WriteInt32(userId); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - msg.WriteStringVector(bundleNames); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - msg.WriteStringVector(bundleNames); - msg.WriteStringVector(detailInfos); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundleNames, msg); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), size), 0); - WriteParcelableVector(bundlesToBackup, msg); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 2; - vector bundlesToBackup; - bundlesToBackup.emplace_back(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - infos.emplace_back(string(reinterpret_cast(data + len + len), len)); - WriteParcelableVector(bundlesToBackup, msg); - msg.WriteStringVector(infos); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - msg.WriteParcelable(&info); - msg.WriteFileDescriptor(fd); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool fdFlag = TypeCast(data + pos, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteBool(fdFlag); - if (fdFlag) { - msg.WriteFileDescriptor(fd1); - msg.WriteFileDescriptor(fd2); - } - msg.WriteInt32(errCode); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - msg.WriteInt32(errCode); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - msg.WriteString(string(reinterpret_cast(data), len)); - msg.WriteString(string(reinterpret_cast(data + len), size - len)); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteString(string(reinterpret_cast(data), size)); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t timeout = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(timeout); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - msg.WriteString(string(reinterpret_cast(data + pos), size - pos)); - msg.WriteInt32(sendRate); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -625,32 +84,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index 5b788a6cb..d94bd33ef 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -18,7 +18,7 @@ #include #include -#include "b_incremental_data.h" +#include "backup_incremental_data.h" #include "b_session_backup.h" #include "b_session_restore.h" #include "message_parcel.h" @@ -220,839 +220,6 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t service->OnRemoteRequest(code, msg, reply, option); return true; } - -bool CmdInitRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitRestoreSession(msg, reply); - - BSessionRestore::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitRestoreSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitBackupSession(msg, reply); - - BSessionBackup::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdStartFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdStart(msg, reply); - - ExpectReturn({true}); - service->CmdStart(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetLocalCapabilities(msg, reply); - - ExpectReturn({true}); - service->CmdGetLocalCapabilities(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - service->CmdAppFileReady(msg, reply); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, false}) : ExpectReturn({true, flag, errCode, false}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - - msg.FlushBuffer(); - flag == true ? ExpectReturn({true, flag, fd, errCode, true}) : ExpectReturn({true, flag, errCode, true}); - ExpectArgReturn({fileName}); - service->CmdAppFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdResultReportFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - string restoreRetInfo(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({restoreRetInfo}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({restoreRetInfo, scenario}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, false}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - - ExpectReturn({true, true, true, true}); - ExpectArgReturn({restoreRetInfo, scenario, errCode}); - service->CmdResultReport(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), size - pos)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, type}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true}); - ExpectArgReturn({bundleNames, type, userId}); - service->CmdAppendBundlesRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsRestoreSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(int32_t) + sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd = TypeCast(data, &pos); - int32_t type = TypeCast(data + pos, &pos); - int32_t userId = TypeCast(data + pos, &pos); - int len = (size - pos) >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data + pos), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + pos + len), len)); - - ExpectReturn({fd, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, false}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - - ExpectReturn({fd, true, true, true, true, true}); - ExpectArgReturn({bundleNames, detailInfos, type, userId}); - service->CmdAppendBundlesDetailsRestoreSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), size)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - vector bundleNames; - bundleNames.emplace_back(string(reinterpret_cast(data), len)); - vector detailInfos; - detailInfos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({bundleNames}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleNames, detailInfos}); - service->CmdAppendBundlesDetailsBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdFinishFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdFinish(msg, reply); - - ExpectReturn({true}); - service->CmdFinish(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdReleaseFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - service->CmdRelease(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetLocalCapabilitiesIncrementalFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundleNames(string(reinterpret_cast(data), size), 0); - - int32_t infoSize = 1; - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundleNames); - service->CmdGetLocalCapabilitiesIncremental(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - try { - msg.WriteBuffer(data, size); - ExpectReturn({false}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - - ExpectReturn({true}); - service->CmdGetAppLocalListAndDoIncrementalBackup(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdInitIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - msg.WriteBuffer(data, size); - service->CmdInitIncrementalBackupSession(msg, reply); - - BIncrementalBackupSession::Callbacks callbacks; - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({false}); - service->CmdInitIncrementalBackupSession(msg, reply); - - msg.FlushBuffer(); - msg.WriteRemoteObject(new ServiceReverse(callbacks)); - ExpectReturn({true}); - service->CmdInitIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), size), 0); - - ExpectReturn({false}); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - int32_t infoSize = 1; - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true}); - ExpectArgReturn({infoSize, "", "", 1}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int32_t infoSize = 1; - int len = size >> 1; - BIncrementalData bundlesToBackup(string(reinterpret_cast(data), len), 0); - std::vector infos; - infos.emplace_back(string(reinterpret_cast(data + len), len)); - - ExpectReturn({false}); - ExpectArgReturn({infoSize}); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, false}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - - ExpectReturn({true, true, true, true, true, true, 1, true, true, true, 0, true, true}); - ExpectArgReturn({infoSize, "", "", 1, infos}); - msg.FlushBuffer(); - msg.WriteParcelable(&bundlesToBackup); - service->CmdAppendBundlesDetailsIncrementalBackupSession(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdPublishIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, false}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({1, true, true, true, true}); - ExpectArgReturn({info.owner, info.fileName, info.sn}); - service->CmdPublishIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -[[maybe_unused]] bool CmdPublishSAIncrementalFileFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int) + sizeof(TmpFileSN)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - BFileInfo info; - int fd = TypeCast(data, &pos); - info.sn = TypeCast(data, &pos); - int len = (size - pos) >> 1; - info.owner = string(reinterpret_cast(data + pos), len); - info.fileName = string(reinterpret_cast(data + pos + len), len); - - msg.WriteParcelable(&info); - ExpectReturn({fd, false}); - service->CmdPublishSAIncrementalFile(msg, reply); - - msg.FlushBuffer(); - msg.WriteParcelable(&info); - ExpectReturn({fd, true}); - service->CmdPublishSAIncrementalFile(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalFileReadyFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t) + sizeof(bool) + sizeof(int) + sizeof(int)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int fd1 = TypeCast(data, &pos); - int fd2 = TypeCast(data + pos, &pos); - int32_t errCode = TypeCast(data + pos, &pos); - bool flag = TypeCast(data + pos, &pos); - string fileName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, false}) : - ExpectReturn({true, flag, fd1, fd2, errCode, false}); - } else { - ExpectReturn({true, flag, errCode, false}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - - if (flag) { - fd1 < 0 ? ExpectReturn({true, flag, fd1, errCode, true}) : - ExpectReturn({true, flag, fd1, fd2, errCode, true}); - } else { - ExpectReturn({true, flag, errCode, true}); - } - ExpectArgReturn({fileName}); - service->CmdAppIncrementalFileReady(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdAppIncrementalDoneFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int32_t errCode = TypeCast(data); - - ExpectReturn({false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({errCode}); - service->CmdAppIncrementalDone(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetIncrementalFileHandleFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - MessageParcel msg; - MessageParcel reply; - - try { - int len = size >> 1; - string bundleName(reinterpret_cast(data), len); - string fileName(reinterpret_cast(data + len), size - len); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName, fileName}); - service->CmdGetIncrementalFileHandle(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - string bundleName(reinterpret_cast(data), size); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - - ExpectReturn({true, true}); - ExpectArgReturn({bundleName}); - service->CmdGetBackupInfo(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateTimerFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - uint32_t timeout = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, timeout}); - service->CmdUpdateTimer(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} - -bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return true; - } - - MessageParcel msg; - MessageParcel reply; - - try { - int pos = 0; - int32_t sendRate = TypeCast(data, &pos); - string bundleName(reinterpret_cast(data + pos), size - pos); - - ExpectReturn({false}); - ExpectArgReturn({bundleName}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, false}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - - ExpectReturn({true, true, true}); - ExpectArgReturn({bundleName, sendRate}); - service->CmdUpdateSendRate(msg, reply); - } catch (OHOS::FileManagement::Backup::BError &err) { - // Only filter BError errors, Other results are not expected. - } - return true; -} } // namespace OHOS /* Fuzzer entry point */ @@ -1065,32 +232,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) try { OHOS::OnRemoteRequestFuzzTest(service, data, size); - CmdInitRestoreSessionFuzzTest(service, data, size); - CmdInitBackupSessionFuzzTest(service, data, size); - CmdStartFuzzTest(service, data, size); - CmdGetLocalCapabilitiesFuzzTest(service, data, size); - CmdPublishFileFuzzTest(service, data, size); - CmdAppFileReadyFuzzTest(service, data, size); - CmdAppDoneFuzzTest(service, data, size); - CmdResultReportFuzzTest(service, data, size); - CmdGetFileHandleFuzzTest(service, data, size); - CmdAppendBundlesRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsRestoreSessionFuzzTest(service, data, size); - CmdAppendBundlesBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsBackupSessionFuzzTest(service, data, size); - CmdFinishFuzzTest(service, data, size); - CmdGetLocalCapabilitiesIncrementalFuzzTest(service, data, size); - CmdGetAppLocalListAndDoIncrementalBackupFuzzTest(service, data, size); - CmdInitIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesIncrementalBackupSessionFuzzTest(service, data, size); - CmdAppendBundlesDetailsIncrementalBackupSessionFuzzTest(service, data, size); - CmdPublishIncrementalFileFuzzTest(service, data, size); - CmdAppIncrementalFileReadyFuzzTest(service, data, size); - CmdAppIncrementalDoneFuzzTest(service, data, size); - CmdGetIncrementalFileHandleFuzzTest(service, data, size); - CmdGetBackupInfoFuzzTest(service, data, size); - CmdUpdateTimerFuzzTest(service, data, size); - CmdUpdateSendRateFuzzTest(service, data, size); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. } diff --git a/test/fuzztest/servicereverse_fuzzer/BUILD.gn b/test/fuzztest/servicereverse_fuzzer/BUILD.gn index 83e4237e0..ac3fee62e 100644 --- a/test/fuzztest/servicereverse_fuzzer/BUILD.gn +++ b/test/fuzztest/servicereverse_fuzzer/BUILD.gn @@ -42,6 +42,8 @@ ohos_fuzztest("ServiceReverseFuzzTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", ] diff --git a/tests/mock/backup_ext/include/ext_extension_mock.h b/tests/mock/backup_ext/include/ext_extension_mock.h index 65733f7ad..5d7d2d779 100644 --- a/tests/mock/backup_ext/include/ext_extension_mock.h +++ b/tests/mock/backup_ext/include/ext_extension_mock.h @@ -23,6 +23,7 @@ namespace OHOS::FileManagement::Backup { class BExtExtension { public: + virtual ErrCode GetFileHandleWithUniqueFd(const std::string &fileName, int32_t &getFileHandleErrCode, int &fd) = 0; virtual ErrCode GetIncrementalFileHandle(const string &) = 0; virtual UniqueFd GetFileHandle(const string &, int32_t &) = 0; virtual ErrCode HandleClear() = 0; @@ -45,28 +46,37 @@ public: virtual void AppResultReport(const std::string, BackupRestoreScenario, ErrCode) = 0; virtual void AsyncTaskOnBackup() = 0; virtual ErrCode HandleRestore() = 0; - virtual void PreparaBackupFiles(UniqueFd, UniqueFd, std::vector&, - std::vector&, std::vector&) = 0; + virtual ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) = 0; + virtual ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) = 0; + virtual void PreparaBackupFiles(UniqueFd, + UniqueFd, + std::vector &, + std::vector &, + std::vector &) = 0; + virtual ErrCode HandleIncrementalBackup(int incrementalFd, int manifestFd) = 0; virtual ErrCode HandleIncrementalBackup(UniqueFd, UniqueFd) = 0; virtual ErrCode IncrementalOnBackup() = 0; virtual tuple GetIncrementalBackupFileHandle() = 0; - virtual ErrCode IncrementalBigFileReady(const TarMap&, const std::vector&, - sptr) = 0; + virtual ErrCode IncrementalBigFileReady(const TarMap &, + const std::vector &, + sptr) = 0; virtual void AsyncTaskDoIncrementalBackup(UniqueFd, UniqueFd) = 0; virtual void AsyncTaskOnIncrementalBackup() = 0; - virtual void IncrementalPacket(const std::vector&, TarMap&, sptr) = 0; - virtual int DoIncrementalBackup(const std::vector&, - const std::vector&, const std::vector&) = 0; + virtual void IncrementalPacket(const std::vector &, TarMap &, sptr) = 0; + virtual int DoIncrementalBackup(const std::vector &, + const std::vector &, + const std::vector &) = 0; virtual void AppIncrementalDone(ErrCode) = 0; - virtual ErrCode GetBackupInfo(std::string&) = 0; - virtual ErrCode UpdateFdSendRate(std::string&, int32_t) = 0; + virtual ErrCode GetBackupInfo(std::string &) = 0; + virtual ErrCode UpdateFdSendRate(std::string &, int32_t) = 0; virtual std::function RestoreResultCallbackEx(wptr) = 0; virtual std::function AppDoneCallbackEx(wptr) = 0; virtual std::function IncRestoreResultCallbackEx(wptr) = 0; virtual std::function HandleBackupEx(wptr) = 0; virtual std::function HandleTaskBackupEx(wptr) = 0; - virtual void WaitToSendFd(std::chrono::system_clock::time_point&, int&) = 0; - virtual void RefreshTimeInfo(std::chrono::system_clock::time_point&, int&) = 0; + virtual void WaitToSendFd(std::chrono::system_clock::time_point &, int &) = 0; + virtual void RefreshTimeInfo(std::chrono::system_clock::time_point &, int &) = 0; + public: BExtExtension() = default; virtual ~BExtExtension() = default; @@ -76,8 +86,8 @@ public: class ExtExtensionMock : public BExtExtension { public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const string &, int32_t &)); - MOCK_METHOD(std::tuple, GetIncrementalFileHandle, (const string &)); + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const string &, int32_t &, int32_t &)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const string &, UniqueFdGroup &fdGroup)); MOCK_METHOD(ErrCode, HandleClear, ()); MOCK_METHOD(ErrCode, BigFileReady, (sptr)); MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); @@ -100,9 +110,9 @@ public: MOCK_METHOD(ErrCode, HandleRestore, ()); MOCK_METHOD(void, FillFileInfos, (UniqueFd, UniqueFd, (std::vector&), (std::vector&), (std::vector&))); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); MOCK_METHOD(ErrCode, IncrementalOnBackup, ()); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup& fdGroup)); MOCK_METHOD(ErrCode, IncrementalBigFileReady, (const TarMap&, (const std::vector&), sptr)); MOCK_METHOD(void, AsyncTaskDoIncrementalBackup, (UniqueFd, UniqueFd)); diff --git a/tests/mock/backup_ext/include/ext_extension_stub_mock.h b/tests/mock/backup_ext/include/ext_extension_stub_mock.h index 6cc34071e..089b1cc80 100644 --- a/tests/mock/backup_ext/include/ext_extension_stub_mock.h +++ b/tests/mock/backup_ext/include/ext_extension_stub_mock.h @@ -21,7 +21,7 @@ #include "ext_extension_stub.h" namespace OHOS::FileManagement::Backup { -class ExtExtensionStubMock : public ExtExtensionStub { +class ExtExtensionStubMock : public ExtensionStub { public: MOCK_METHOD(int, OnRemoteRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); MOCK_METHOD(ErrCode, CmdGetFileHandle, (MessageParcel &, MessageParcel &)); diff --git a/tests/mock/backup_ext/src/ext_extension_mock.cpp b/tests/mock/backup_ext/src/ext_extension_mock.cpp index 4c54b88bf..15c541105 100644 --- a/tests/mock/backup_ext/src/ext_extension_mock.cpp +++ b/tests/mock/backup_ext/src/ext_extension_mock.cpp @@ -21,6 +21,26 @@ using namespace std; void BackupExtExtension::VerifyCaller() { } +ErrCode BackupExtExtension::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) +{ + return BExtExtension::extExtension->GetIncrementalBackupFileHandleWithUniqueFdGroup(fdGroup); +} +ErrCode BackupExtExtension::HandleIncrementalBackup(int32_t incrementalFd, int32_t manifestFd) +{ + return BExtExtension::extExtension->HandleIncrementalBackup(incrementalFd, manifestFd); +} +ErrCode BackupExtExtension::GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, + UniqueFdGroup &fdGroup) +{ + return BExtExtension::extExtension->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); +} + +ErrCode BackupExtExtension::GetFileHandleWithUniqueFd(const std::string &fileName, + int32_t &getFileHandleErrCode, + int &fd) +{ + return BExtExtension::extExtension->GetFileHandleWithUniqueFd(fileName, getFileHandleErrCode, fd); +} UniqueFd BackupExtExtension::GetFileHandle(const string &fileName, int32_t &errCode) { diff --git a/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp index 6f9309402..4ab92951c 100644 --- a/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp +++ b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp @@ -16,11 +16,11 @@ #include "ext_extension_stub_mock.h" namespace OHOS::FileManagement::Backup { -ExtExtensionStub::ExtExtensionStub() +ExtensionStub::ExtensionStub() { } -int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, +int32_t ExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return static_cast(this)->OnRemoteRequest(code, data, reply, option); diff --git a/tests/mock/backup_kit_inner/service_client_mock.cpp b/tests/mock/backup_kit_inner/service_client_mock.cpp new file mode 100644 index 000000000..351c5dbc7 --- /dev/null +++ b/tests/mock/backup_kit_inner/service_client_mock.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "iremote_object.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_client.h" +#include "system_ability_definition.h" +#include "svc_death_recipient.h" +#include "hitrace_meter.h" +#include "iservice.h" +#include +#include "backup_file_info.h" +#include "backup_incremental_data.h" +#include "iservice.h" +#include "iremote_object_mock.h" +#include "utils_mock_global_variable.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + if (!GetMockGetInstance()) { + return nullptr; + } + + if (!GetMockLoadSystemAbility()) { + serviceProxy_ = sptr(new ServiceProxy(nullptr)); + } else { + sptr object = new MockIRemoteObject(); + serviceProxy_ = sptr(new ServiceProxy(object)); + } + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() +{ + serviceProxy_ = nullptr; +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index d7ce74b5c..d27050da3 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -31,7 +31,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +int32_t ServiceProxy::InitRestoreSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -39,7 +39,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote) return 0; } -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -47,7 +47,7 @@ int32_t ServiceProxy::InitRestoreSession(sptr remote, std::stri return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote) +int32_t ServiceProxy::InitBackupSession(const sptr& remote) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -55,7 +55,7 @@ int32_t ServiceProxy::InitBackupSession(sptr remote) return 0; } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr& remote, std::string &errMsg) { if (!GetMockInitBackupOrRestoreSession()) { return 1; @@ -68,12 +68,13 @@ ErrCode ServiceProxy::Start() return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { TestManager tm("ServiceProxyMock_GetFd_0100"); string filePath = tm.GetRootDirCurTest().append("tmp"); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - return fd; + UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + fd = fd_OpenData.Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) @@ -81,7 +82,7 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -91,7 +92,7 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, +ErrCode ServiceProxy::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); @@ -102,19 +103,19 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - const vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -125,7 +126,7 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl } ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) + const std::vector &detailInfos) { return BError(BError::Codes::OK); } @@ -140,15 +141,16 @@ ErrCode ServiceProxy::Release() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + fd = UniqueFd(-1).Get(); + return BError(BError::Codes::OK); } ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() @@ -156,23 +158,24 @@ ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr& remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const vector &infos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -182,12 +185,12 @@ ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -202,12 +205,12 @@ ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, co return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } @@ -232,58 +235,23 @@ ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario scenario) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() -{ - return serviceProxy_; -} - -sptr ServiceProxy::GetInstance() -{ - if (!GetMockGetInstance()) { - return nullptr; - } - - if (!GetMockLoadSystemAbility()) { - serviceProxy_ = sptr(new ServiceProxy(nullptr)); - } else { - sptr object = new MockIRemoteObject(); - serviceProxy_ = sptr(new ServiceProxy(object)); - } - return serviceProxy_; -} - -void ServiceProxy::InvaildInstance() -{ - serviceProxy_ = nullptr; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr &remoteObject) +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int& fd) { - return; -} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - return; -} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); + fd=-1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector& bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/mock/module_ipc/extension_proxy_mock.cpp b/tests/mock/module_ipc/extension_proxy_mock.cpp new file mode 100644 index 000000000..6c58a6b73 --- /dev/null +++ b/tests/mock/module_ipc/extension_proxy_mock.cpp @@ -0,0 +1,85 @@ +/* + * 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" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +ErrCode ExtensionProxy::GetFileHandleWithUniqueFd(const string &fileName, int32_t &errCode, int &fd) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleClear() +{ + return 0; +} + +ErrCode ExtensionProxy::HandleBackup(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::PublishFile(const string &fileName) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleRestore(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::GetBackupInfo(std::string &result) +{ + return 0; +} + +ErrCode ExtensionProxy::GetIncrementalFileHandleWithUniqueFdGroup(const string &fileName, UniqueFdGroup &fdGroup) +{ + return 0; +} + +ErrCode ExtensionProxy::PublishIncrementalFile(const string &fileName) +{ + return 0; +} + +ErrCode ExtensionProxy::HandleIncrementalBackup(int incrementalFd, int manifestFd) +{ + return 0; +} + +ErrCode ExtensionProxy::IncrementalOnBackup(bool isClearData) +{ + return 0; +} + +ErrCode ExtensionProxy::UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) +{ + return 0; +} + +ErrCode ExtensionProxy::User0OnBackup() +{ + return 0; +} + +ErrCode ExtensionProxy::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) +{ + return 0; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/extension_type_mock.cpp b/tests/mock/module_ipc/extension_type_mock.cpp new file mode 100644 index 000000000..6876bacb9 --- /dev/null +++ b/tests/mock/module_ipc/extension_type_mock.cpp @@ -0,0 +1,43 @@ +/* + * 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_type.h" + +namespace OHOS { +namespace FileManagement { +namespace Backup { +namespace ExtensionType { + +ErrCode UniqueFdGroupBlockMarshalling(OHOS::MessageParcel& data, const UniqueFdGroup& dataBlock) +{ + if (!data.WriteUnpadBuffer(&dataBlock, sizeof(UniqueFdGroup))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +ErrCode UniqueFdGroupBlockUnmarshalling(OHOS::MessageParcel &data, UniqueFdGroup &dataBlock) +{ + const UniqueFdGroup *dataBlockPtr = + reinterpret_cast(data.ReadUnpadBuffer(sizeof(UniqueFdGroup))); + if (dataBlockPtr == nullptr) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} +} // namespace ExtensionType +} // namespace Backup +} // namespace FileManagement +} // namespace OHOS diff --git a/tests/mock/module_ipc/include/extension_proxy_mock.h b/tests/mock/module_ipc/include/extension_proxy_mock.h new file mode 100644 index 000000000..9e50bddb9 --- /dev/null +++ b/tests/mock/module_ipc/include/extension_proxy_mock.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_EXTENSION_PROXY_MOCK_H +#define OHOS_FILEMGMT_BACKUP_EXTENSION_PROXY_MOCK_H + +#include + +#include "extension_proxy.h" + +namespace OHOS::FileManagement::Backup { +class ExtensionProxyMock : public ExtensionProxy { +public: + ExtensionProxyMock() : ExtensionProxy(nullptr) {}; +public: + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int32_t &)); + MOCK_METHOD(ErrCode, HandleClear, ()); + MOCK_METHOD(ErrCode, HandleBackup, (bool)); + MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleRestore, (bool)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const std::string &, UniqueFdGroup &)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); + MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool)); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup &)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (const std::string &, int32_t)); + MOCK_METHOD(ErrCode, User0OnBackup, ()); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h index fc5c50fe8..55736f3f2 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -18,42 +18,44 @@ #include -#include "i_service_reverse.h" +#include "iservice_reverse.h" #include "iremote_proxy.h" namespace OHOS::FileManagement::Backup { class ServiceReverseProxyMock : public IRemoteProxy { public: - MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); - MOCK_METHOD(void, BackupOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, BackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnResultReport, (std::string, std::string));; - MOCK_METHOD(void, BackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, BackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, BackupOnScanningInfo, (std::string)); - - MOCK_METHOD(void, RestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, RestoreOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, RestoreOnResultReport, (std::string, std::string, ErrCode)); - MOCK_METHOD(void, RestoreOnProcessInfo, (std::string, std::string)); - - MOCK_METHOD(void, IncrementalBackupOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalBackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnResultReport, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalBackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnScanningInfo, (std::string)); - - MOCK_METHOD(void, IncrementalRestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnResultReport, (std::string, std::string, ErrCode));; - MOCK_METHOD(void, IncrementalRestoreOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + MOCK_METHOD(ErrCode, BackupOnFileReady, (const std::string &, const std::string &, int, int32_t)); + MOCK_METHOD(ErrCode, BackupOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnResultReport, (const std::string &, const std::string &)); + ; + MOCK_METHOD(ErrCode, BackupOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, BackupOnProcessInfo, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, BackupOnScanningInfo, (const std::string &)); + + MOCK_METHOD(ErrCode, RestoreOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, RestoreOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, RestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, RestoreOnFileReady, (const std::string &, const std::string &, int32_t, int32_t)); + MOCK_METHOD(ErrCode, RestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); + MOCK_METHOD(ErrCode, RestoreOnProcessInfo, (const std::string &, const std::string &)); + + MOCK_METHOD(ErrCode, IncrementalBackupOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnResultReport, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnProcessInfo, (const std::string &, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalBackupOnScanningInfo, (const std::string &)); + + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleStarted, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleFinished, (int32_t, const std::string &)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); + ; + MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (const std::string &, const std::string &)); public: ServiceReverseProxyMock() : IRemoteProxy(nullptr) {} diff --git a/tests/mock/module_ipc/include/service_stub_mock.h b/tests/mock/module_ipc/include/service_stub_mock.h index 27d151755..565a19e2b 100644 --- a/tests/mock/module_ipc/include/service_stub_mock.h +++ b/tests/mock/module_ipc/include/service_stub_mock.h @@ -17,91 +17,15 @@ #define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H #include - +#include "module_ipc/service_stub.h" namespace OHOS::FileManagement::Backup { -class BServiceStub { -public: - virtual int32_t OnRemoteRequest(uint32_t, MessageParcel&, MessageParcel&, MessageOption&) = 0; - virtual int32_t CmdInitRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdInitBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdStart(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilities(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilitiesForBdInfos(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppFileReady(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppDone(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdResultReport(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetFileHandle(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdFinish(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdRelease(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdCancel(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdInitIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishIncrementalFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdPublishSAIncrementalFile(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppIncrementalFileReady(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdAppIncrementalDone(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetIncrementalFileHandle(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetBackupInfo(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdUpdateTimer(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdUpdateSendRate(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdStopExtTimer(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdRefreshDataSize(MessageParcel&, MessageParcel&) = 0; - virtual int32_t CmdGetBackupDataSize(MessageParcel&, MessageParcel&) = 0; - virtual void ServiceStubSupplement() = 0; - virtual void ServiceStubSuppAppendBundles() = 0; - -public: - BServiceStub() = default; - virtual ~BServiceStub() = default; -public: - static inline std::shared_ptr stub = nullptr; -}; - -class ServiceStubMock : public BServiceStub { +class ServiceStub : public IRemoteStub { public: - MOCK_METHOD(int32_t, OnRemoteRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); - MOCK_METHOD(int32_t, CmdInitRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdInitBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdStart, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilities, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilitiesForBdInfos, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppFileReady, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppDone, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdResultReport, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetFileHandle, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsRestoreSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdFinish, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdRelease, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetLocalCapabilitiesIncremental, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetAppLocalListAndDoIncrementalBackup, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdInitIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppendBundlesDetailsIncrementalBackupSession, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishIncrementalFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdPublishSAIncrementalFile, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppIncrementalFileReady, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdAppIncrementalDone, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetIncrementalFileHandle, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetBackupInfo, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdUpdateTimer, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdUpdateSendRate, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdStopExtTimer, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdRefreshDataSize, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(int32_t, CmdGetBackupDataSize, (MessageParcel&, MessageParcel&)); - MOCK_METHOD(void, ServiceStubSupplement, ()); - MOCK_METHOD(void, ServiceStubSuppAppendBundles, ()); + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H \ No newline at end of file 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 a042be3ab..af46f1d8c 100644 --- a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -25,18 +25,18 @@ class SvcExtensionProxyMock : public SvcExtensionProxy { public: SvcExtensionProxyMock() : SvcExtensionProxy(nullptr) {}; public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const std::string&, int32_t&)); + MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int32_t &)); MOCK_METHOD(ErrCode, HandleClear, ()); MOCK_METHOD(ErrCode, HandleBackup, (bool)); - MOCK_METHOD(ErrCode, PublishFile, (const std::string&)); + MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); MOCK_METHOD(ErrCode, HandleRestore, (bool)); - MOCK_METHOD((std::tuple), GetIncrementalFileHandle, (const std::string&)); - MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string&)); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandleWithUniqueFdGroup, (const std::string &, UniqueFdGroup &)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (int32_t, int32_t)); MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool)); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); - MOCK_METHOD(ErrCode, GetBackupInfo, (std::string&)); - MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string&, int32_t)); + MOCK_METHOD(ErrCode, GetIncrementalBackupFileHandleWithUniqueFdGroup, (UniqueFdGroup &)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string &, int32_t)); MOCK_METHOD(ErrCode, User0OnBackup, ()); }; } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/include/svc_session_manager_mock.h b/tests/mock/module_ipc/include/svc_session_manager_mock.h index 17634813c..83d363ceb 100644 --- a/tests/mock/module_ipc/include/svc_session_manager_mock.h +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -25,7 +25,7 @@ class BSvcSessionManager { public: virtual ErrCode Active(struct SvcSessionManager::Impl, bool) = 0; virtual sptr GetServiceReverseProxy() = 0; - virtual IServiceReverse::Scenario GetScenario() = 0; + virtual IServiceReverseType::Scenario GetScenario() = 0; virtual int32_t GetSessionUserId() = 0; virtual std::string GetSessionCallerName() = 0; virtual std::string GetSessionActiveTime() = 0; @@ -38,7 +38,7 @@ public: virtual bool GetSchedBundleName(std::string&) = 0; virtual std::string GetBackupExtName(const std::string&) = 0; virtual std::string GetBackupExtInfo(const std::string&) = 0; - virtual sptr CreateBackupConnection(BundleName&) = 0; + virtual sptr CreateBackupConnection(const BundleName&) = 0; virtual bool IsOnAllBundlesFinished() = 0; virtual bool IsOnOnStartSched() = 0; virtual bool NeedToUnloadService() = 0; @@ -73,7 +73,7 @@ class SvcSessionManagerMock : public BSvcSessionManager { public: MOCK_METHOD(ErrCode, Active, (struct SvcSessionManager::Impl, bool)); MOCK_METHOD((sptr), GetServiceReverseProxy, ()); - MOCK_METHOD(IServiceReverse::Scenario, GetScenario, ()); + MOCK_METHOD(IServiceReverseType::Scenario, GetScenario, ()); MOCK_METHOD(int32_t, GetSessionUserId, ()); MOCK_METHOD(std::string, GetSessionCallerName, ()); MOCK_METHOD(std::string, GetSessionActiveTime, ()); @@ -86,7 +86,7 @@ public: MOCK_METHOD(bool, GetSchedBundleName, (std::string&)); MOCK_METHOD(std::string, GetBackupExtName, (const std::string&)); MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName&)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName&)); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); MOCK_METHOD(bool, IsOnOnStartSched, ()); MOCK_METHOD(bool, NeedToUnloadService, ()); diff --git a/tests/mock/module_ipc/message_parcel_mock.h b/tests/mock/module_ipc/message_parcel_mock.h index 97984c231..d8b473a86 100644 --- a/tests/mock/module_ipc/message_parcel_mock.h +++ b/tests/mock/module_ipc/message_parcel_mock.h @@ -21,8 +21,8 @@ #include "message_parcel.h" #include "iremote_broker.h" -#include "b_file_info.h" -#include "b_incremental_data.h" +#include "backup_file_info.h" +#include "backup_incremental_data.h" namespace OHOS::FileManagement::Backup { class BackupIfaceCast { diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 547ce2562..740e6b30c 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -35,39 +35,72 @@ void Service::OnStart() {} void Service::OnStop() {} -UniqueFd Service::GetLocalCapabilities() +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -void Service::StopAll(const wptr &obj, bool force) {} +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) +ErrCode Service::GetLocalCapabilities(int &fd) { + fd = -1; return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -82,7 +115,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -92,14 +125,16 @@ ErrCode Service::AppDone(ErrCode errCode) return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) { return BError(BError::Codes::OK); } @@ -118,7 +153,7 @@ ErrCode Service::AppendBundlesBackupSession(const std::vector &bundl } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -168,7 +203,7 @@ ErrCode Service::VerifyCaller() return BError(BError::Codes::OK); } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { return BError(BError::Codes::OK); } @@ -186,15 +221,15 @@ ErrCode Service::Release() return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode Service::GetAppLocalListAndDoIncrementalBackup() @@ -202,12 +237,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote) +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } @@ -218,7 +253,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) + const std::vector &infos) { return BError(BError::Codes::OK); } @@ -228,12 +263,15 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode Service::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } @@ -248,7 +286,7 @@ ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } @@ -273,17 +311,17 @@ ErrCode Service::RefreshDataSize(int64_t totalDatasize) return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -307,26 +345,40 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName return make_shared(bundleName); } -void Service::RemoveExtensionMutex(const BundleName &bundleName) -{ -} +void Service::RemoveExtensionMutex(const BundleName &bundleName) {} void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, const vector &restoreBundleNames) {} + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ +} -void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -359,32 +411,32 @@ void Service::ClearFailedBundles() {} void Service::GetOldDeviceBackupVersion() {} -void Service::CreateDirIfNotExist(const std::string &path) -{ -} - -void Service::StartRunningTimer(const std::string &bundleName) {} +void Service::CreateDirIfNotExist(const std::string &path) {} -std::vector Service::GetSupportBackupBundleNames(vector&, bool, - const vector&) +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) { return {}; } -void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} +void Service::StartRunningTimer(const std::string &bundleName) {} -void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} +void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} + +void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, - ErrCode errCode) {} +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ +} void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } @@ -401,7 +453,7 @@ void Service::DeleteFromList(size_t scannedSize) {} void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} -void Service::SendScannedInfo(const string&scannendInfos, sptr session) {} +void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index ee7e924e0..c794edad3 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -13,64 +13,160 @@ * limitations under the License. */ -#include "module_ipc/service_reverse_proxy.h" +#include "service_reverse_proxy.h" #include "b_error/b_error.h" namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::BackupOnScanningInfo(std::string scannedInfo) {} - -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalBackupOnScanningInfo(std::string scannedInfo) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} +ErrCode ServiceReverseProxy::BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnResultReport(const std::string &result, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnScanningInfo(const std::string &scannedInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnProcessInfo(const std::string &bundleName, + const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnScanningInfo(const std::string &scannedInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnProcessInfo(const std::string &bundleName, + const std::string &processInfo) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 8a3c066a8..07b4d4695 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -13,384 +13,523 @@ * limitations under the License. */ -#include "module_ipc/service_stub.h" - -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" -#include "module_ipc/service_reverse_proxy.h" - +#include "service_stub.h" namespace OHOS::FileManagement::Backup { using namespace std; -ServiceStub::ServiceStub() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RELSEASE_SESSION)] = - &ServiceStub::CmdRelease; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION)] = - &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION)] = - &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES)] = - &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY)] = - &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = - &ServiceStub::CmdPublishFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = - &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = - &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAIL)] = - &ServiceStub::CmdAppendBundlesDetailsRestoreSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = - &ServiceStub::CmdGetLocalCapabilitiesIncremental; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdInitIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_DETAILS)] = - &ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION)] = - &ServiceStub::CmdAppendBundlesIncrementalBackupSession; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_INCREMENTAL_FILE)] = - &ServiceStub::CmdPublishIncrementalFile; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_INCREMENTAL_FILE_READY)] = - &ServiceStub::CmdAppIncrementalFileReady; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = - &ServiceStub::CmdGetIncrementalFileHandle; - ServiceStubSupplement(); - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = - &ServiceStub::CmdStopExtTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = - &ServiceStub::CmdRefreshDataSize; -} - -void ServiceStub::ServiceStubSupplement() -{ - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = - &ServiceStub::CmdGetBackupInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = - &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = - &ServiceStub::CmdUpdateSendRate; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] = - &ServiceStub::CmdReportAppProcessInfo; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION_MSG)] = - &ServiceStub::CmdInitRestoreSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_INCREMENTAL_BACKUP_SESSION_MSG)] = - &ServiceStub::CmdInitIncrementalBackupSessionMsg; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_CANCEL_BUNDLE)] = - &ServiceStub::CmdCancel; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_FOR_BUNDLE_INFOS)] = - &ServiceStub::CmdGetLocalCapabilitiesForBdInfos; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_DATA_SIZE)] = - &ServiceStub::CmdGetBackupDataSize; -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - return BError(BError::Codes::OK); - } - - const std::u16string descriptor = ServiceStub::GetDescriptor(); - const std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - return BError(BError::Codes::OK); - } - return (this->*(interfaceIndex->second))(data, reply); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int32_t res = InitRestoreSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitRestoreSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int32_t res = InitRestoreSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - - int res = InitBackupSession(iremote); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - auto remote = data.ReadRemoteObject(); - auto iremote = iface_cast(remote); - std::string errMsg; - int res = InitBackupSession(iremote, errMsg); - reply.WriteString(errMsg); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - int res = Start(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(GetLocalCapabilities()); - reply.WriteFileDescriptor(fd); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - unique_ptr fileInfo(data.ReadParcelable()); - int res = PublishFile(*fileInfo); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - string fileName; - data.ReadString(fileName); - UniqueFd fd(data.ReadFileDescriptor()); - int res = AppFileReady(fileName, move(fd), 0); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - ErrCode errCode; - data.ReadInt32(errCode); - int res = AppDone(errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - std::string restoreRetInfo; - data.ReadString(restoreRetInfo); - int32_t scenario; - data.ReadInt32(scenario); - ErrCode errCode; - data.ReadInt32(errCode); - BackupRestoreScenario type = static_cast(scenario); - int res = ServiceResultReport(restoreRetInfo, type, errCode); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - string bundleName; - data.ReadString(bundleName); - string fileName; - data.ReadString(fileName); - - return GetFileHandle(bundleName, fileName); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesRestoreSession(move(fd), bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - UniqueFd fd(data.ReadFileDescriptor()); - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - std::vector detailInfos; - data.ReadStringVector(&detailInfos); - int res = AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - std::vector bundleNames; - data.ReadStringVector(&bundleNames); - int res = AppendBundlesBackupSession(bundleNames); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) +int32_t ServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) { - int res = Finish(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - std::string result; - ret = GetBackupInfo(bundleName, result); - return ret; -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - uint32_t timeout; - if (!data.ReadUint32(timeout)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive timeout")); + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; } - bool result; - ret = UpdateTimer(bundleName, timeout, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } - int32_t sendRate; - if (!data.ReadInt32(sendRate)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); - } - bool result; - ret = UpdateSendRate(bundleName, sendRate, result); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - int res = Release(); - reply.WriteInt32(res); - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - int ret = ERR_OK; - string bundleName; - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleName"); + switch (static_cast(code)) { + case IServiceIpcCode::COMMAND_INIT_RESTORE_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitRestoreSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START: { + ErrCode errCode = Start(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES: { + int fd; + ErrCode errCode = GetLocalCapabilities(fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < bundleNamesSize; ++i1) { + std::string value1 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value1); + } + std::vector detailInfos; + int32_t detailInfosSize = data.ReadInt32(); + if (detailInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i2 = 0; i2 < detailInfosSize; ++i2) { + std::string value2 = Str16ToStr8(data.ReadString16()); + detailInfos.push_back(value2); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = + AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_READY: { + int fd = data.ReadFileDescriptor(); + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i3 = 0; i3 < bundleNamesSize; ++i3) { + std::string value3 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value3); + } + int32_t restoreType = data.ReadInt32(); + int32_t userId = data.ReadInt32(); + ErrCode errCode = AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i4 = 0; i4 < bundleNamesSize; ++i4) { + std::string value4 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value4); + } + ErrCode errCode = AppendBundlesBackupSession(bundleNames); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_DETAILS_BACKUP_SESSION: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i5 = 0; i5 < bundleNamesSize; ++i5) { + std::string value5 = Str16ToStr8(data.ReadString16()); + bundleNames.push_back(value5); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i6 = 0; i6 < bundleInfosSize; ++i6) { + std::string value6 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value6); + } + ErrCode errCode = AppendBundlesDetailsBackupSession(bundleNames, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_FINISH: { + ErrCode errCode = Finish(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_RELEASE: { + ErrCode errCode = Release(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_CANCEL: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t cancelResult; + ErrCode errCode = Cancel(bundleName, cancelResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(cancelResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP: { + ErrCode errCode = GetAppLocalListAndDoIncrementalBackup(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_INCREMENTAL_FILE_HANDLE: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = GetIncrementalFileHandle(bundleName, fileName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_BACKUP_INFO: { + std::string bundleName; + std::string getBackupInfoResult; + ErrCode errCode = GetBackupInfo(bundleName, getBackupInfoResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteString16(Str8ToStr16(getBackupInfoResult))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_TIMER: { + std::string bundleName; + uint32_t timeout = data.ReadUint32(); + bool updateTimerResult; + ErrCode errCode = UpdateTimer(bundleName, timeout, updateTimerResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateTimerResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_UPDATE_SEND_RATE: { + std::string bundleName; + int32_t sendRate = data.ReadInt32(); + bool updateSendRateResult; + ErrCode errCode = UpdateSendRate(bundleName, sendRate, updateSendRateResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(updateSendRateResult ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_EXT_TIMER: { + bool isExtStart; + ErrCode errCode = StartExtTimer(isExtStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_START_FWK_TIMER: { + bool isFwkStart; + ErrCode errCode = StartFwkTimer(isFwkStart); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isFwkStart ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_STOP_EXT_TIMER: { + bool isExtStop; + ErrCode errCode = StopExtTimer(isExtStop); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(isExtStop ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_GET_LOCAL_CAPABILITIES_INCREMENTAL: { + std::vector bundleNames; + int32_t bundleNamesSize = data.ReadInt32(); + if (bundleNamesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i7 = 0; i7 < bundleNamesSize; ++i7) { + std::unique_ptr value7(data.ReadParcelable()); + if (!value7) { + return ERR_INVALID_DATA; + } + + bundleNames.push_back(*value7); + } + int fd; + ErrCode errCode = GetLocalCapabilitiesIncremental(bundleNames, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(fd)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION: { + sptr reverseIpcRemoteObject; + ErrCode errCode = InitIncrementalBackupSession(reverseIpcRemoteObject); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (reverseIpcRemoteObject == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(reverseIpcRemoteObject->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i8 = 0; i8 < bundlesToBackupSize; ++i8) { + std::unique_ptr value8(data.ReadParcelable()); + if (!value8) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value8); + } + ErrCode errCode = AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_INCREMENTAL_BACKUP_SESSION_WITH_BUNDLE_INFOS: { + std::vector bundlesToBackup; + int32_t bundlesToBackupSize = data.ReadInt32(); + if (bundlesToBackupSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i9 = 0; i9 < bundlesToBackupSize; ++i9) { + std::unique_ptr value9(data.ReadParcelable()); + if (!value9) { + return ERR_INVALID_DATA; + } + + bundlesToBackup.push_back(*value9); + } + std::vector bundleInfos; + int32_t bundleInfosSize = data.ReadInt32(); + if (bundleInfosSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i10 = 0; i10 < bundleInfosSize; ++i10) { + std::string value10 = Str16ToStr8(data.ReadString16()); + bundleInfos.push_back(value10); + } + ErrCode errCode = AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, bundleInfos); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = PublishIncrementalFile(*fileInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_PUBLISH_S_A_INCREMENTAL_FILE: { + std::unique_ptr fileInfo(data.ReadParcelable()); + if (!fileInfo) { + return ERR_INVALID_DATA; + } + + int fd = data.ReadFileDescriptor(); + ErrCode errCode = PublishSAIncrementalFile(*fileInfo, fd); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t appIncrementalFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalFileReady(fileName, fd, manifestFd, appIncrementalFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_INCREMENTAL_DONE: { + int32_t appIncrementalDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppIncrementalDone(appIncrementalDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REPORT_APP_PROCESS_INFO: { + std::string processInfo = Str16ToStr8(data.ReadString16()); + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + ErrCode errCode = ReportAppProcessInfo(processInfo, scenario); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_REFRESH_DATA_SIZE: { + int64_t totalDataSize = data.ReadInt64(); + ErrCode errCode = RefreshDataSize(totalDataSize); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_DONE: { + int32_t appDoneErrCode = data.ReadInt32(); + ErrCode errCode = AppDone(appDoneErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_SERVICE_RESULT_REPORT: { + std::string restoreRetInfo; + BackupRestoreScenario scenario; + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + return ERR_INVALID_DATA; + } + scenario = static_cast(enumTmp); + } + int32_t serviceResultReportErrCode = data.ReadInt32(); + ErrCode errCode = ServiceResultReport(restoreRetInfo, scenario, serviceResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(restoreRetInfo))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IServiceIpcCode::COMMAND_APP_FILE_READY: { + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t appFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = AppFileReady(fileName, fd, appFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - int result = BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK; - ret = Cancel(bundleName, result); - reply.WriteInt32(result); - return ret; -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSessionMsg(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BError(BError::Codes::OK); + return ERR_TRANSACTION_FAILED; } } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp index 2d46ff3ea..a28229fb3 100644 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -23,162 +23,251 @@ ServiceStub::ServiceStub() { } -void ServiceStub::ServiceStubSupplement() -{ -} - -int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - return BServiceStub::stub->OnRemoteRequest(code, data, reply, option); -} - -int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitBackupSession(data, reply); -} - -int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStart(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilities(data, reply); -} - -int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishFile(data, reply); -} - -int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppFileReady(data, reply); -} - -int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppDone(data, reply); -} - -int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdResultReport(data, reply); -} - -int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetFileHandle(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsRestoreSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesBackupSession(data, reply); -} - -int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdFinish(data, reply); -} - -int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupInfo(data, reply); -} - -int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateTimer(data, reply); -} - -int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdUpdateSendRate(data, reply); -} - -int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRelease(data, reply); -} - -int32_t ServiceStub::CmdCancel(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdCancel(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesIncremental(data, reply); -} - -int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetAppLocalListAndDoIncrementalBackup(data, reply); -} - -int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdInitIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppendBundlesDetailsIncrementalBackupSession(data, reply); -} - -int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdPublishIncrementalFile(data, reply); -} - -int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdAppIncrementalFileReady(data, reply); -} -int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); +int32_t ServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_STARTED: { + int32_t backupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleStarted(backupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t backupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnFileReady(bundleName, fileName, fd, backupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_BUNDLE_FINISHED: { + int32_t backupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnBundleFinished(backupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t backupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = BackupOnAllBundlesFinished(backupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = BackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_STARTED: { + int32_t restoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleStarted(restoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int32_t restoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnFileReady(bundleName, fileName, fd, restoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t restoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnResultReport(myResult, bundleName, restoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_BUNDLE_FINISHED: { + int32_t restoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnBundleFinished(restoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t restoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = RestoreOnAllBundlesFinished(restoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_STARTED: { + int32_t incrementalBackupOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleStarted(incrementalBackupOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalBackupOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, incrementalBackupOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnResultReport(myResult, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_BUNDLE_FINISHED: { + int32_t incrementalBackupOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnBundleFinished(incrementalBackupOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalBackupOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalBackupOnAllBundlesFinished(incrementalBackupOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_BACKUP_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalBackupOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_STARTED: { + int32_t incrementalRestoreOnBundleStartedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleStarted(incrementalRestoreOnBundleStartedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_FILE_READY: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string fileName = Str16ToStr8(data.ReadString16()); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + int32_t incrementalRestoreOnFileReadyErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, + incrementalRestoreOnFileReadyErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_RESULT_REPORT: { + std::string myResult = Str16ToStr8(data.ReadString16()); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t incrementalRestoreOnResultReportErrCode = data.ReadInt32(); + ErrCode errCode = + IncrementalRestoreOnResultReport(myResult, bundleName, incrementalRestoreOnResultReportErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_BUNDLE_FINISHED: { + int32_t incrementalRestoreOnBundleFinishedErrCode = data.ReadInt32(); + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnBundleFinished(incrementalRestoreOnBundleFinishedErrCode, bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_ALL_BUNDLES_FINISHED: { + int32_t incrementalRestoreOnAllBundlesFinishedErrCode = data.ReadInt32(); + ErrCode errCode = IncrementalRestoreOnAllBundlesFinished(incrementalRestoreOnAllBundlesFinishedErrCode); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IServiceReverseIpcCode::COMMAND_INCREMENTAL_RESTORE_ON_PROCESS_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string processInfo = Str16ToStr8(data.ReadString16()); + ErrCode errCode = IncrementalRestoreOnProcessInfo(bundleName, processInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; } -int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdStopExtTimer(data, reply); -} - -int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdRefreshDataSize(data, reply); -} - -int32_t ServiceStub::CmdGetLocalCapabilitiesForBdInfos(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetLocalCapabilitiesForBdInfos(data, reply); -} - -int32_t ServiceStub::CmdGetBackupDataSize(MessageParcel &data, MessageParcel &reply) -{ - return BServiceStub::stub->CmdGetBackupDataSize(data, reply); -} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp index 6c8b88f42..017a8e9b4 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -21,7 +21,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t, IServiceReverse::Scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t, IServiceReverseType::Scenario) const { return BError(BError::Codes::OK); } @@ -46,7 +46,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return BSvcSessionManager::sessionManager->GetServiceReverseProxy(); } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { return BSvcSessionManager::sessionManager->GetScenario(); } @@ -132,7 +132,7 @@ void SvcSessionManager::SetBundleUserId(const string &bundleName, const int32_t void SvcSessionManager::AppendBundles(const vector &, vector &) {} -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BSvcSessionManager::sessionManager->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_backup_connection_mock.cpp b/tests/mock/module_ipc/svc_backup_connection_mock.cpp index 001f3dee2..061ded0a6 100644 --- a/tests/mock/module_ipc/svc_backup_connection_mock.cpp +++ b/tests/mock/module_ipc/svc_backup_connection_mock.cpp @@ -17,7 +17,7 @@ #include -#include "module_ipc/svc_extension_proxy.h" +#include "extension_proxy.h" #include "module_ipc/svc_session_manager.h" namespace OHOS::FileManagement::Backup { diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index a2534d899..d7eadf7dc 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -18,9 +18,9 @@ namespace OHOS::FileManagement::Backup { using namespace std; -UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName, int32_t &errCode) +ErrCode SvcExtensionProxy::GetFileHandleWithUniqueFd(const string &fileName, int32_t &errCode, int &fd) { - return UniqueFd(-1); + return 0; } ErrCode SvcExtensionProxy::HandleClear() @@ -48,9 +48,9 @@ ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) return 0; } -std::tuple SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) +ErrCode SvcExtensionProxy::GetIncrementalFileHandleWithUniqueFdGroup(const string &fileName, UniqueFdGroup &fdGroup) { - return {0, UniqueFd(-1), UniqueFd(-1)}; + return 0; } ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) @@ -58,7 +58,7 @@ ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) return 0; } -ErrCode SvcExtensionProxy::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +ErrCode SvcExtensionProxy::HandleIncrementalBackup(int incrementalFd, int manifestFd) { return 0; } @@ -78,8 +78,8 @@ ErrCode SvcExtensionProxy::User0OnBackup() return 0; } -tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() +ErrCode SvcExtensionProxy::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) { - return {UniqueFd(-1), UniqueFd(-1)}; + return 0; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 749be058a..61a2c2eb7 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -36,7 +36,7 @@ static int32_t g_nFileReadyNum = 0; static int32_t g_nAllBundlesFinished = 0; } // namespace -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { GTEST_LOG_(INFO) << "VerifyCallerAndScenario"; return BError(BError::Codes::OK); @@ -68,7 +68,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return impl_.clientProxy; } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { GTEST_LOG_(INFO) << "GetScenario"; return impl_.scenario; @@ -257,7 +257,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { GTEST_LOG_(INFO) << "CreateBackupConnection"; return GetBackupAbilityExt(bundleName); diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp index b7ac3a85e..fdec296b7 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp @@ -19,7 +19,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const +ErrCode SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceReverseType::Scenario scenario) const { return BackupSvcSessionManager::session->VerifyCallerAndScenario(clientToken, scenario); } @@ -44,7 +44,7 @@ sptr SvcSessionManager::GetServiceReverseProxy() return BackupSvcSessionManager::session->GetServiceReverseProxy(); } -IServiceReverse::Scenario SvcSessionManager::GetScenario() +IServiceReverseType::Scenario SvcSessionManager::GetScenario() { return BackupSvcSessionManager::session->GetScenario(); } @@ -155,7 +155,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames, vec BackupSvcSessionManager::session->AppendBundles(bundleNames, failedBundles); } -sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +sptr SvcSessionManager::CreateBackupConnection(const BundleName &bundleName) { return BackupSvcSessionManager::session->CreateBackupConnection(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.h b/tests/mock/module_ipc/svc_session_manager_throw_mock.h index 455274faa..effea3050 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.h +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.h @@ -27,12 +27,12 @@ class BackupSvcSessionManager { public: virtual ~BackupSvcSessionManager() = default; public: - virtual ErrCode VerifyCallerAndScenario(uint32_t, IServiceReverse::Scenario) = 0; + virtual ErrCode VerifyCallerAndScenario(uint32_t, IServiceReverseType::Scenario) = 0; virtual ErrCode Active(SvcSessionManager::Impl) = 0; virtual ErrCode Deactive(const wptr &, bool) = 0; virtual ErrCode VerifyBundleName(std::string &) = 0; virtual sptr GetServiceReverseProxy() = 0; - virtual IServiceReverse::Scenario GetScenario() = 0; + virtual IServiceReverseType::Scenario GetScenario() = 0; virtual bool OnBundleFileReady(const std::string &, const std::string &) = 0; virtual UniqueFd OnBundleExtManageInfo(const std::string &, UniqueFd) = 0; virtual void RemoveExtInfo(const std::string &) = 0; @@ -53,7 +53,7 @@ public: virtual void SetBackupExtName(const std::string &, const std::string &) = 0; virtual std::weak_ptr GetSAExtConnection(const BundleName &) = 0; virtual void AppendBundles(const std::vector &, std::vector &) = 0; - virtual sptr CreateBackupConnection(BundleName &) = 0; + virtual sptr CreateBackupConnection(const BundleName &) = 0; virtual ErrCode Start() = 0; virtual ErrCode Finish() = 0; virtual bool IsOnAllBundlesFinished() = 0; @@ -104,12 +104,12 @@ public: class SvcSessionManagerMock : public BackupSvcSessionManager { public: - MOCK_METHOD(ErrCode, VerifyCallerAndScenario, (uint32_t, IServiceReverse::Scenario)); + MOCK_METHOD(ErrCode, VerifyCallerAndScenario, (uint32_t, IServiceReverseType::Scenario)); MOCK_METHOD(ErrCode, Active, (SvcSessionManager::Impl)); MOCK_METHOD(ErrCode, Deactive, (const wptr &, bool)); MOCK_METHOD(ErrCode, VerifyBundleName, (std::string &)); MOCK_METHOD(sptr, GetServiceReverseProxy, ()); - MOCK_METHOD(IServiceReverse::Scenario, GetScenario, ()); + MOCK_METHOD(IServiceReverseType::Scenario, GetScenario, ()); MOCK_METHOD(bool, OnBundleFileReady, (const std::string &, const std::string &)); MOCK_METHOD(UniqueFd, OnBundleExtManageInfo, (const std::string &, UniqueFd)); MOCK_METHOD(void, RemoveExtInfo, (const std::string &)); @@ -130,7 +130,7 @@ public: MOCK_METHOD(void, SetBackupExtName, (const std::string &, const std::string &)); MOCK_METHOD(std::weak_ptr, GetSAExtConnection, (const BundleName &)); MOCK_METHOD(void, AppendBundles, (const std::vector &, std::vector &)); - MOCK_METHOD(sptr, CreateBackupConnection, (BundleName &)); + MOCK_METHOD(sptr, CreateBackupConnection, (const BundleName &)); MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, Finish, ()); MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index c3fc260ee..8d19f9adc 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -25,21 +25,22 @@ ohos_unittest("b_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/backup_kit_inner/service_client_mock.cpp", "b_session_backup_test.cpp", "b_session_restore_async_test.cpp", "b_session_restore_test.cpp", ] sources += backup_mock_proxy_src - include_dirs = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner/", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/frameworks/native/backup_kit_inner/include", ] + include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", ] diff --git a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp index a4a5583f2..0afa8e568 100644 --- a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp @@ -16,7 +16,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "backup_kit_inner.h" #include "unique_fd.h" #include "utils_mock_global_variable.h" diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index aa3f5a3ed..66539a9ea 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -20,7 +20,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "b_session_restore_async.h" #include "backup_kit_inner.h" #include "unique_fd.h" diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp index 0c2b9b32c..6c5ff1b3c 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -17,7 +17,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "backup_kit_inner.h" #include "test_manager.h" #include "unique_fd.h" diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 1ef532c62..08046348f 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -53,8 +53,6 @@ ohos_unittest("backup_sa_impl_test") { sources = [ "${path_backup_mock}/system_ability_manager/service_registry_mock.cpp", "${path_backup_mock}/utils_mock/src/utils_mock_global_variable.cpp", - "service_proxy_test.cpp", - "service_reverse_stub_test.cpp", "service_reverse_test.cpp", "svc_death_recipient_test.cpp", ] diff --git a/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp b/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp index 283508801..c8ab0443d 100644 --- a/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp +++ b/tests/unittests/backup_api/backup_impl/b_file_info_test.cpp @@ -15,7 +15,7 @@ #include -#include "b_file_info.h" +#include "backup_file_info.h" #include "parcel.h" namespace OHOS::FileManagement::Backup { 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 3399bc312..778d91488 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 @@ -20,9 +20,9 @@ #include #include #include - +#include "unique_fd.h" #include "b_error/b_error.h" -#include "i_extension.h" +#include "iextension.h" #include "iremote_stub.h" #include "test_manager.h" @@ -51,9 +51,16 @@ public: reply.WriteInt32(0); reply.WriteFileDescriptor(fd); return BError(BError::Codes::OK); - } + }; + + ErrCode GetFileHandleWithUniqueFd(const std::string &fileName, int32_t &getFileHandleErrCode, int &fd) override + { + UniqueFd f = GetFileHandle(fileName, getFileHandleErrCode); + fd = f.Get(); + return getFileHandleErrCode; + }; - UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) override + UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) { GTEST_LOG_(INFO) << "GetFileHandle" << fileName; if (fileName == "testName") { @@ -104,7 +111,11 @@ public: return BError(BError::Codes::OK); }; - std::tuple GetIncrementalFileHandle(const std::string &fileName) override + ErrCode GetIncrementalFileHandleWithUniqueFdGroup(const std::string &fileName, UniqueFdGroup &fdGroup) override + { + return BError(BError::Codes::OK); + } + std::tuple GetIncrementalFileHandle(const std::string &fileName) { return {BError(BError::Codes::OK), UniqueFd(-1), UniqueFd(-1)}; }; @@ -114,7 +125,11 @@ public: return BError(BError::Codes::OK); }; - ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override + ErrCode HandleIncrementalBackup (int incrementalFd, int manifestFd) override + { + return BError(BError::Codes::OK); + }; + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) { return BError(BError::Codes::OK); }; @@ -124,7 +139,12 @@ public: return BError(BError::Codes::OK); }; - std::tuple GetIncrementalBackupFileHandle() override + ErrCode GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup &fdGroup) override + { + return BError(BError::Codes::OK); + }; + + std::tuple GetIncrementalBackupFileHandle() { return {UniqueFd(-1), UniqueFd(-1)}; }; @@ -134,7 +154,7 @@ public: return BError(BError::Codes::OK); }; - ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override + ErrCode UpdateFdSendRate(const std::string &bundleName, int32_t sendRate) override { return BError(BError::Codes::OK); }; diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index d5371dae2..a3890ba0a 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -16,17 +16,17 @@ #ifndef MOCK_I_SERVICE_MOCK_H #define MOCK_I_SERVICE_MOCK_H -#include -#include -#include -#include - #include "b_error/b_error.h" -#include "i_service.h" #include "b_resources/b_constants.h" #include "iremote_stub.h" +#include "service_client.h" +#include "service_common.h" #include "test_manager.h" - +#include "unique_fd.h" +#include +#include +#include +#include namespace OHOS::FileManagement::Backup { class IServiceMock : public IRemoteStub { public: @@ -62,22 +62,22 @@ public: return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr remote) override + ErrCode InitRestoreSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr remote, std::string &errMsg) override + ErrCode InitRestoreSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr remote) override + ErrCode InitBackupSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr remote, std::string &errMsg) override + ErrCode InitBackupSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } @@ -87,33 +87,37 @@ public: return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() override + ErrCode GetLocalCapabilities(int &fd) { - return UniqueFd(-1); + return -1; } - UniqueFd GetLocalCapabilitiesForBundleInfos() override + ErrCode GetLocalCapabilitiesForBundleInfos(int &fd) override { - return UniqueFd(-1); + return -1; + } + + ErrCode PublishFile(const BFileInfo &fileInfo) + { + return BError(BError::Codes::OK); } - ErrCode PublishFile(const BFileInfo &fileInfo) override + ErrCode GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override + ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode errCode) override + ErrCode AppDone(ErrCode errCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) override + ErrCode ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode) { return BError(BError::Codes::OK); } @@ -127,7 +131,7 @@ public: const std::vector &bundleNames, const std::vector &detailInfos, RestoreTypeEnum restoreType, - int32_t userId) override + int32_t userId) { return BError(BError::Codes::OK); } @@ -135,18 +139,18 @@ public: ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, - int32_t userId) override + int32_t userId) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override + ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) { return BError(BError::Codes::OK); } ErrCode AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) override + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -181,7 +185,7 @@ public: return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t totalsize) override + ErrCode RefreshDataSize(int64_t totalsize) { return BError(BError::Codes::OK); } @@ -196,15 +200,15 @@ public: return BError(BError::Codes::OK); } - ErrCode Cancel(std::string bundleName, int32_t &result) override + ErrCode Cancel(const std::string &, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector &bundleNames) override + ErrCode GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } ErrCode GetAppLocalListAndDoIncrementalBackup() override @@ -212,38 +216,38 @@ public: return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr remote) override + ErrCode InitIncrementalBackupSession(sptr &remote) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr remote, std::string &errMsg) override + ErrCode InitIncrementalBackupSessionWithErrMsg(sptr &remote, std::string &errMsg) override { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) override + ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } ErrCode AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) override + const std::vector &infos) { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override + ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override + ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) + ErrCode AppIncrementalFileReady(const std::string &fileName, int fd, int manifestFd, int32_t errCode) { return BError(BError::Codes::OK); } @@ -258,12 +262,35 @@ public: return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) + ErrCode ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) + { + return BError(BError::Codes::OK); + } + + ErrCode AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool isPreciseScan, std::vector bundleNameList) + ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index cd066641e..91ca1af35 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -19,8 +19,8 @@ #include #include "b_error/b_error.h" -#include "i_service_reverse.h" #include "iremote_stub.h" +#include "iservice_reverse.h" namespace OHOS::FileManagement::Backup { class ServiceReverseMock : public IRemoteStub { @@ -36,37 +36,152 @@ public: code_ = code; return BError(BError::Codes::OK); } - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void BackupOnResultReport(std::string result, std::string bundleName) override {}; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void BackupOnAllBundlesFinished(int32_t errCode) override {} - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} - void BackupOnScanningInfo(std::string scannedInfo) override {} - - void RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void RestoreOnAllBundlesFinished(int32_t errCode) override {} - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void RestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {} - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} - - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override {} - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override {} - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override {} - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} - void IncrementalBackupOnScanningInfo(std::string scannedInfo) override {} - - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override {} - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, - int32_t errCode) override {} - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {}; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} + + ErrCode BackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + }; + + ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode BackupOnScanningInfo(const std::string &scannedInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalBackupOnScanningInfo(const std::string &scannedInfo) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnFileReady(const std::string &bundleName, + const std::string &fileName, + int fd, + int manifestFd, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnResultReport(const std::string &result, + const std::string &bundleName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + + ErrCode IncrementalRestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override + { + return BError(BError::Codes::OK); + } }; } // namespace OHOS::FileManagement::Backup #endif // MOCK_SERVICE_REVERSE_MOCK_H \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp deleted file mode 100644 index ee2de7234..000000000 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ /dev/null @@ -1,1444 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "b_file_info.h" -#include "i_service_mock.h" -#include "iremote_object_mock.h" -#include "iservice_registry.h" -#include "service_proxy.h" -#include "service_reverse_mock.h" -#include "unique_fd.h" -#include "utils_mock_global_variable.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -constexpr int32_t SERVICE_ID = 5203; -} // namespace - -class ServiceProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override; - void TearDown() override; - - shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; - sptr remote_ = nullptr; -}; - -void ServiceProxyTest::SetUp() -{ - mock_ = sptr(new IServiceMock()); - proxy_ = make_shared(mock_); - remote_ = sptr(new ServiceReverseMock()); -} - -void ServiceProxyTest::TearDown() -{ - proxy_ = nullptr; - mock_ = nullptr; - remote_ = nullptr; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0100 - * @tc.desc: 测试 InitRestoreSession 注册restore Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.name: SUB_Service_proxy_InitRestoreSession_0200 - * @tc.desc: 测试 InitRestoreSession 注册restore Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitRestoreSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitRestoreSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - int32_t result = proxy_->InitRestoreSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitRestoreSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitBackupSession_0100 - * @tc.desc: 测试 InitBackupSession 注册backup Session接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitBackupSession_0200 - * @tc.desc: 测试 InitBackupSession 注册backup Session with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Start_0100 - * @tc.name: SUB_Service_proxy_Start_0100 - * @tc.desc: 测试 Start 启动备份恢复流程接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Start_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Start_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Start_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->Start(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->Start(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Start_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilities_0100 - * @tc.desc: 测试 GetLocalCapabilities 获取能力文件接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilities_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilities_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - UniqueFd fd = proxy_->GetLocalCapabilities(); - EXPECT_GT(fd, BError(BError::Codes::OK)); - UniqueFd fdErr = proxy_->GetLocalCapabilities(); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilities_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishFile_0100 - * @tc.name: SUB_Service_proxy_PublishFile_0100 - * @tc.desc: 测试 PublishFile 推送接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilities_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->PublishFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppFileReady_0100 - * @tc.name: SUB_Service_proxy_AppFileReady_0100 - * @tc.desc: 测试 AppFileReady 文件就绪调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(3) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppFileReady(bundleName, move(fd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppFileReady(bundleName, move(fdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppFileReady(bundleName, UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppDone_0100 - * @tc.name: SUB_Service_proxy_AppDone_0100 - * @tc.desc: 测试 AppDone ext备份恢复流程结束调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.name: SUB_Service_proxy_ServiceResultReport_0100 - * @tc.desc: 测试 ServiceResultReport - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ServiceResultReport_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ServiceResultReport_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ServiceResultReport_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string restoreRetInfo = "test_restoreRetInfo"; - BackupRestoreScenario scenario = FULL_BACKUP; - int32_t result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ServiceResultReport(restoreRetInfo, scenario, BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ServiceResultReport_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetFileHandle_0100 - * @tc.desc: 测试 GetFileHandle 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0100 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0101 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - std::vector bundleNames; - TestManager tm("BackupSession_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - std::vector detailInfos; - int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0200 - * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesRestoreSession_0200 proxy_ == nullptr"; - return; - } - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesBackupSession_0100 - * @tc.desc: 测试 AppendBundlesBackupSession 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - - int32_t result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->AppendBundlesBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 - * @tc.desc: 测试 AppendBundlesDetailsBackupSession - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector detailInfos; - - int32_t result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Finish_0100 - * @tc.name: SUB_Service_proxy_Finish_0100 - * @tc.desc: 测试 Finish 获取真实文件调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6URNZ - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Finish_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Finish_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Finish_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Finish(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Finish(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Finish_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Release_0100 - * @tc.name: SUB_Service_proxy_Release_0100 - * @tc.desc: 测试 Release 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Release_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Release_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Release_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - int32_t result = proxy_->Release(); - EXPECT_EQ(result, BError(BError::Codes::OK)); - result = proxy_->Release(); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Release_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.name: SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 - * @tc.desc: 测试 GetLocalCapabilitiesIncremental 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - BIncrementalData data("com.example.app2backup", 0); - bundleNames.push_back(data); - UniqueFd fd = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_GT(fd, BError(BError::Codes::OK)); - - UniqueFd fdErr = proxy_->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_LT(fdErr, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetLocalCapabilitiesIncremental_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.name: SUB_Service_proxy_InitIncrementalBackupSession_0200 - * @tc.desc: 测试 InitIncrementalBackupSession with errMsg接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InitIncrementalBackupSession_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InitIncrementalBackupSession_0200"; - std::string errMsg; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InitIncrementalBackupSession_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeMsgSendRequest)); - - int32_t result = proxy_->InitIncrementalBackupSession(remote_, errMsg); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->InitIncrementalBackupSession(nullptr, errMsg); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InitIncrementalBackupSession_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.name: SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101 - * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesIncrementalBackupSession_0101, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - std::vector bundleNames; - std::vector infos; - int32_t result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppendBundlesIncrementalBackupSession(bundleNames, infos); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesDetailsIncrementalBackupSession_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishIncrementalFile_0100 - * @tc.desc: 测试 PublishIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - int32_t result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_EQ(result, BError(BError::Codes::OK)); - fileName = "test"; - result = proxy_->PublishIncrementalFile(fileInfo); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0100 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fd)); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - ret = proxy_->PublishSAIncrementalFile(fileInfo, move(fdErr)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.name: SUB_Service_proxy_PublishSAIncrementalFile_0200 - * @tc.desc: 测试 PublishSAIncrementalFile 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_PublishSAIncrementalFile_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_PublishSAIncrementalFile_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_PublishSAIncrementalFile_0200 proxy_ == nullptr"; - return; - } - - string bundleName = "com.example.app2backup"; - string fileName = ""; - BFileInfo fileInfo(bundleName, fileName, -1); - ErrCode ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - - ret = proxy_->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_PublishSAIncrementalFile_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0100 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_GetFd_0100"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, move(fd), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - TestManager tmErr("AppIncrementalFileReady_GetFd_0200"); - UniqueFd fdErr(open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFdErr( - open(tmErr.GetRootDirCurTest().append(FILE_NAME).data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - result = proxy_->AppIncrementalFileReady(bundleName, move(fdErr), move(manifestFdErr), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0200 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0200"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0200 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Return(0)) - .WillOnce(Return(0)); - - string bundleName = "com.example.app2backup"; - TestManager tm("AppIncrementalFileReady_0200"); - std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - UniqueFd manifestFd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), move(manifestFd), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, move(fd), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0200"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.name: SUB_Service_proxy_AppIncrementalFileReady_0300 - * @tc.desc: 测试 AppIncrementalFileReady 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalFileReady_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalFileReady_0300"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalFileReady_0300 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - - string bundleName = "com.example.app2backup"; - int32_t result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalFileReady(bundleName, UniqueFd(-1), UniqueFd(-1), 0); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalFileReady_0300"; -} - -/** - * @tc.number: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.name: SUB_Service_proxy_AppIncrementalDone_0100 - * @tc.desc: 测试 AppIncrementalDone 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppIncrementalDone_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppIncrementalDone_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_AppIncrementalDone_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->AppIncrementalDone(BError(BError::Codes::OK)); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppIncrementalDone_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.name: SUB_Service_proxy_GetIncrementalFileHandle_0100 - * @tc.desc: 测试 GetIncrementalFileHandle 接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetIncrementalFileHandle_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetIncrementalFileHandle_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - string bundleName = "com.example.app2backup"; - string fileName = "1.tar"; - int32_t result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - int32_t systemAbilityId = 0; - loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 - * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - sptr remoteObject = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, remoteObject); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0103"; -} - -/** - * @tc.number: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.name: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 - * @tc.desc: 测试 OnLoadSystemAbilityFail 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilityFail_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_OnLoadSystemAbilityFail_0100 proxy_ == nullptr"; - return; - } - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - EXPECT_NE(loadCallback, nullptr); - loadCallback->OnLoadSystemAbilityFail(SERVICE_ID); - loadCallback = nullptr; - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilityFail_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetInstance_0100 - * @tc.name: SUB_Service_proxy_GetInstance_0100 - * @tc.desc: 测试 GetInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetInstance_0100 proxy_ == nullptr"; - return; - } - GTEST_LOG_(INFO) << "MockLoadSystemAbility is false"; - SetMockLoadSystemAbility(false); - auto proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "MockLoadSystemAbility is true"; - SetMockLoadSystemAbility(true); - proxy = ServiceProxy::GetInstance(); - EXPECT_EQ(proxy, nullptr); - sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); - sptr object = new MockIRemoteObject(); - loadCallback->OnLoadSystemAbilitySuccess(SERVICE_ID, object); - GTEST_LOG_(INFO) << "GetInstance is ok"; - proxy = ServiceProxy::GetInstance(); - EXPECT_NE(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_InvaildInstance_0100 - * @tc.name: SUB_Service_proxy_InvaildInstance_0100 - * @tc.desc: 测试 InvaildInstance 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InvaildInstance_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_InvaildInstance_0100 proxy_ == nullptr"; - return; - } - ServiceProxy::InvaildInstance(); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.name: SUB_Service_proxy_GetBackupInfo_0100 - * @tc.desc: 测试 GetBackupInfo 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetBackupInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string result; - std::string bundleName = "com.example.app2backup"; - int32_t ret = proxy_->GetBackupInfo(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateTimer_0100 - * @tc.name: SUB_Service_proxy_UpdateTimer_0100 - * @tc.desc: 测试 UpdateTimer 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - uint32_t timeout = 30000; - int32_t ret = proxy_->UpdateTimer(bundleName, timeout, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.name: SUB_Service_proxy_UpdateSendRate_0100 - * @tc.desc: 测试 UpdateSendRate 获取应用信息接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateSendRate_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_UpdateSendRate_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - bool result; - std::string bundleName = "com.example.app2backup"; - int32_t sendRate = 300; - int32_t ret = proxy_->UpdateSendRate(bundleName, sendRate, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.name: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 - * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - int32_t ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0100 - * @tc.desc: 测试 ReportAppProcessInfo 接口成功 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_EQ(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.name: SUB_Service_proxy_ReportAppProcessInfo_0101 - * @tc.desc: 测试 ReportAppProcessInfo 接口失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_ReportAppProcessInfo_0101, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_ReportAppProcessInfo_0101"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_ReportAppProcessInfo_0101 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(4) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)) - .WillOnce(Return(EPERM)); - std::string processInfo = "{\"timeInfo\": \"\", \"resultInfo\": \"\"}"; - int32_t result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - - result = proxy_->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); - EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_ReportAppProcessInfo_0101"; -} - -/** - * @tc.number: SUB_Service_proxy_StartExtTimer_0100 - * @tc.name: SUB_Service_proxy_StartExtTimer_0100 - * @tc.desc: 测试 StartExtTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartExtTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartExtTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartExtTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isExtStart; - int32_t ret = proxy_->StartExtTimer(isExtStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartExtTimer(isExtStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartExtTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.name: SUB_Service_proxy_StartFwkTimer_0100 - * @tc.desc: 测试 StartFwkTimer 执行DoBackup的接口成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_StartFwkTimer_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_StartFwkTimer_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_StartFwkTimer_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - bool isFwkStart; - int32_t ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->StartFwkTimer(isFwkStart); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_StartFwkTimer_0100"; -} - -/** - * @tc.number: SUB_Service_proxy_Cancel_0100 - * @tc.name: SUB_Service_proxy_Cancel_0100 - * @tc.desc: 测试 Cancel 调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZV5 - */ -HWTEST_F(ServiceProxyTest, SUB_Service_proxy_Cancel_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_Cancel_0100"; - if (proxy_ == nullptr) { - GTEST_LOG_(INFO) << "SUB_Service_proxy_Cancel_0100 proxy_ == nullptr"; - return; - } - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)) - .WillOnce(Return(EPERM)); - std::string bundleName; - int result; - ErrCode ret = proxy_->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy_->Cancel(bundleName, result); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_Cancel_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp deleted file mode 100644 index 7c2284f6b..000000000 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ /dev/null @@ -1,889 +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 -#include -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "service_reverse_stub.h" -#include "test_manager.h" -#include "unique_fd.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -namespace { -const string BUNDLE_NAME = "com.example.app2backup"; -const string FILE_NAME = "1.tar"; -const string FILE_NAME_MANIFEST = "1.fr"; -} // namespace - -class MockServiceReverse final : public ServiceReverseStub { -public: - MOCK_METHOD4(BackupOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD2(BackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(BackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(BackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(BackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(BackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_METHOD1(BackupOnScanningInfo, void(std::string scannedInfo)); - - MOCK_METHOD2(RestoreOnBundleStarted, void(int32_t errCode, std::string bundleName)); - MOCK_METHOD2(RestoreOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(RestoreOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD4(RestoreOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD3(RestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(RestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); - - MOCK_METHOD5(IncrementalBackupOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(IncrementalBackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(IncrementalBackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(IncrementalBackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_METHOD1(IncrementalBackupOnScanningInfo, void(std::string scannedInfo)); - - MOCK_METHOD2(IncrementalRestoreOnBundleStarted, void(int32_t errCode, std::string bundleName)); - MOCK_METHOD2(IncrementalRestoreOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(IncrementalRestoreOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD5(IncrementalRestoreOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD3(IncrementalRestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(IncrementalRestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); -}; - -class ServiceReverseStubTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() override {}; - void TearDown() override {}; -}; - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnFileReady_0100 - * @tc.desc: Test function of BackupOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_BackupOnFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnFileReady(_, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0100"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - data.WriteInt32(0); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100 - * @tc.desc: Test function of BackupOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnBundleStarted."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnResultReport_0100 - * @tc.desc: Test function of BackupOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnResultReport(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnResultReport."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100 - * @tc.desc: Test function of BackupOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnBundleFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100 - * @tc.desc: Test function of BackupOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, BackupOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by BackupOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100 - * @tc.desc: Test function of RestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnBundleStarted."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100 - * @tc.desc: Test function of RestoreOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnBundleFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100 - * @tc.desc: Test function of RestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, - reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100 - * @tc.desc: Test function of RestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t errCode = 0; - bool fdFlag = true; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - - TestManager tm("ServiceReverseStub_0200"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - if (fd < 0) { - errCode = BError::GetCodeByErrno(errno); - fdFlag = false; - } - data.WriteBool(fdFlag); - if (fdFlag == true) { - data.WriteFileDescriptor(fd); - } - data.WriteInt32(errCode); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_error_0100 - * @tc.name: SUB_backup_ServiceReverseStub_error_0100 - * @tc.desc: Test function of RestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6F3GV - */ -HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_error_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_error_0100"; - try { - MockServiceReverse service; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_TRUE(data.WriteInterfaceToken(Str8ToStr16("test"))); - - EXPECT_NE(BError(BError::Codes::OK), service.OnRemoteRequest(3333, data, reply, option)); - EXPECT_NE( - BError(BError::Codes::OK), - service.OnRemoteRequest(static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_error_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100 - * @tc.desc: Test function of IncrementalBackupOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0300"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - TestManager tm2("ServiceReverseStub_0301"); - string filePathManifest = tm2.GetRootDirCurTest().append(FILE_NAME_MANIFEST); - UniqueFd fdManifest(open(filePathManifest.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fdManifest); - data.WriteInt32(0); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100 - * @tc.desc: Test function of IncrementalBackupOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnBundleStarted."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100 - * @tc.desc: Test function of IncrementalBackupOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100 - * @tc.desc: Test function of IncrementalBackupOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnBundleFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100 - * @tc.desc: Test function of IncrementalBackupOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ - -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalBackupOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100 - * @tc.desc: Test function of IncrementalRestoreOnBundleStarted interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnBundleStarted."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100 - * @tc.desc: Test function of IncrementalRestoreOnBundleFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnBundleFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100 - * @tc.desc: Test function of IncrementalRestoreOnAllBundlesFinished interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnAllBundlesFinished."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100 - * @tc.desc: Test function of IncrementalRestoreOnFileReady interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteString(FILE_NAME)); - TestManager tm("ServiceReverseStub_0400"); - string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fd); - TestManager tm2("ServiceReverseStub_0401"); - string filePathManifest = tm2.GetRootDirCurTest().append(FILE_NAME_MANIFEST); - UniqueFd fdManifest(open(filePathManifest.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - data.WriteFileDescriptor(fdManifest); - - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by IncrementalRestoreOnFileReady."; - } - GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 - * @tc.desc: Test function of RestoreOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, RestoreOnResultReport(_, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::string resultReport = "result_report"; - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(resultReport)); - EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); - EXPECT_TRUE(data.WriteInt32(0)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; -} - -/** - * @tc.number: SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100 - * @tc.name: SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100 - * @tc.desc: Test function of IncrementalRestoreOnResultReport interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I90ZZX - */ -HWTEST_F(ServiceReverseStubTest, - SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; - try { - MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::string resultReport = "result_report"; - EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); - EXPECT_TRUE(data.WriteString(resultReport)); - EXPECT_TRUE(data.WriteInt32(0)); - - EXPECT_EQ( - BError(BError::Codes::OK), - service.OnRemoteRequest( - static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT), - data, reply, option)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnResultReport."; - } - GTEST_LOG_(INFO) - << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnResultReport_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 98bccfac2..05e4d6c77 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -45,8 +45,8 @@ public: void SetUp() override {}; void TearDown() override; - void Init(IServiceReverse::Scenario scenario, int nType = 0); - void IncrementalInit(IServiceReverse::Scenario scenario, int nType = 0); + void Init(IServiceReverseType::Scenario scenario, int nType = 0); + void IncrementalInit(IServiceReverseType::Scenario scenario, int nType = 0); sptr service_ = nullptr; }; @@ -89,9 +89,9 @@ void ServiceReverseTest::TearDown() service_ = nullptr; } -void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) +void ServiceReverseTest::Init(IServiceReverseType::Scenario scenario, int nType) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { if (nType) { service_ = new ServiceReverse(BSessionBackup::Callbacks {.onFileReady = nullptr, .onBundleStarted = nullptr, @@ -128,9 +128,9 @@ void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) } } -void ServiceReverseTest::IncrementalInit(IServiceReverse::Scenario scenario, int nType) +void ServiceReverseTest::IncrementalInit(IServiceReverseType::Scenario scenario, int nType) { - if (scenario == IServiceReverse::Scenario::BACKUP) { + if (scenario == IServiceReverseType::Scenario::BACKUP) { if (nType) { service_ = new ServiceReverse(BIncrementalBackupSession::Callbacks {.onFileReady = nullptr, .onBundleStarted = nullptr, @@ -179,7 +179,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0100, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0100 service_ == nullptr"; @@ -207,7 +207,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0101, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0101 service_ == nullptr"; @@ -234,7 +234,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0102, t { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnFileReady_0102 service_ == nullptr"; @@ -261,7 +261,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 service_ == nullptr"; @@ -289,7 +289,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0101 service_ == nullptr"; @@ -316,7 +316,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleStarted_0102 service_ == nullptr"; @@ -343,7 +343,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0100 service_ == nullptr"; @@ -371,7 +371,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0101 service_ == nullptr"; @@ -398,7 +398,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnBundleFinished_0102 service_ == nullptr"; @@ -425,7 +425,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100 service_ == nullptr"; @@ -453,7 +453,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101 service_ == nullptr"; @@ -480,7 +480,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102 service_ == nullptr"; @@ -507,7 +507,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0100, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0100 service_ == nullptr"; @@ -535,7 +535,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0101, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0101 service_ == nullptr"; @@ -562,7 +562,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0102, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnFileReady_0102 service_ == nullptr"; @@ -589,7 +589,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 service_ == nullptr"; @@ -617,7 +617,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101 service_ == nullptr"; @@ -644,7 +644,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102 service_ == nullptr"; @@ -671,7 +671,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100 service_ == nullptr"; @@ -699,7 +699,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101 service_ == nullptr"; @@ -726,7 +726,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102 service_ == nullptr"; @@ -753,7 +753,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100 service_ == nullptr"; @@ -781,7 +781,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101 service_ == nullptr"; @@ -808,7 +808,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102 service_ == nullptr"; @@ -835,7 +835,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0100, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0100 service_ == nullptr"; @@ -865,7 +865,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0101, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0101"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0101 service_ == nullptr"; @@ -894,7 +894,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnProcessInfo_0102, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnProcessInfo_0102"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_BackupOnProcessInfo_0102 service_ == nullptr"; @@ -923,7 +923,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0200, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0200"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0200 service_ == nullptr"; @@ -953,7 +953,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0201, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0201"; try { - Init(IServiceReverse::Scenario::RESTORE, 0); + Init(IServiceReverseType::Scenario::RESTORE, 0); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0201 service_ == nullptr"; @@ -983,7 +983,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0300, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0300"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0300 service_ == nullptr"; @@ -1013,7 +1013,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0301, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0301"; try { - Init(IServiceReverse::Scenario::BACKUP, 0); + Init(IServiceReverseType::Scenario::BACKUP, 0); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_0301 service_ == nullptr"; @@ -1043,7 +1043,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100 service_ == nullptr"; @@ -1071,7 +1071,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101 service_ == nullptr"; @@ -1079,7 +1079,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe } service_->IncrementalBackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); } catch (...) { EXPECT_TRUE(false); @@ -1103,7 +1103,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100 service_ == nullptr"; @@ -1133,7 +1133,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0101 service_ == nullptr"; @@ -1141,7 +1141,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1165,7 +1165,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0100 service_ == nullptr"; @@ -1195,7 +1195,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnBundleFinished_0101 service_ == nullptr"; @@ -1203,7 +1203,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1227,7 +1227,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0100 service_ == nullptr"; @@ -1257,7 +1257,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalBackupOnAllBundlesFinished_0101 service_ == nullptr"; @@ -1265,7 +1265,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalBackupOnAllBundlesFinished(BError(BError::Codes::OK)); - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); service_->IncrementalBackupOnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -1289,7 +1289,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0100 service_ == nullptr"; @@ -1319,7 +1319,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0101 service_ == nullptr"; @@ -1327,7 +1327,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1, -1, 0); } catch (...) { EXPECT_TRUE(false); @@ -1351,7 +1351,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100 service_ == nullptr"; @@ -1381,7 +1381,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0101 service_ == nullptr"; @@ -1389,7 +1389,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1413,7 +1413,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0100 service_ == nullptr"; @@ -1443,7 +1443,7 @@ HWTEST_F(ServiceReverseTest, { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnBundleFinished_0101 service_ == nullptr"; @@ -1451,7 +1451,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1476,7 +1476,7 @@ HWTEST_F(ServiceReverseTest, GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0100 service_ == nullptr"; @@ -1507,7 +1507,7 @@ HWTEST_F(ServiceReverseTest, GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0101 service_ == nullptr"; @@ -1515,7 +1515,7 @@ HWTEST_F(ServiceReverseTest, } service_->IncrementalRestoreOnAllBundlesFinished(BError(BError::Codes::OK)); - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); service_->IncrementalRestoreOnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -1537,7 +1537,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0100"; try { - Init(IServiceReverse::Scenario::RESTORE); + Init(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnResultReport_0100 service_ == nullptr"; return; @@ -1565,7 +1565,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_010 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0101"; try { - Init(IServiceReverse::Scenario::RESTORE, 1); + Init(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_RestoreOnResultReport_0101 service_ == nullptr"; return; @@ -1594,14 +1594,14 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalRestoreOnResul { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0100"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE); + IncrementalInit(IServiceReverseType::Scenario::RESTORE); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0100 service_ == nullptr"; return; } std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; - service_->IncrementalRestoreOnResultReport(resultReport, bundleName); + service_->IncrementalRestoreOnResultReport(resultReport, bundleName, 0); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by IncrementalRestoreOnResultReport."; @@ -1623,14 +1623,14 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalRestoreOnResul { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0101"; try { - IncrementalInit(IServiceReverse::Scenario::RESTORE, 1); + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 1); if (service_ == nullptr) { GTEST_LOG_(INFO) << "SUB_backup_ServiceReverse_IncrementalRestoreOnResultReport_0101 service_ == nullptr"; return; } std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; - service_->IncrementalRestoreOnResultReport(resultReport, bundleName); + service_->IncrementalRestoreOnResultReport(resultReport, bundleName, 0); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by IncrementalRestoreOnResultReport."; @@ -1651,7 +1651,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnResultReport_0100 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnResultReport_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1679,7 +1679,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnResultReport_0101 { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnResultReport_0101"; try { - Init(IServiceReverse::Scenario::BACKUP, 1); + Init(IServiceReverseType::Scenario::BACKUP, 1); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1708,7 +1708,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnResult { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnResultReport_0100"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP); + IncrementalInit(IServiceReverseType::Scenario::BACKUP); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { @@ -1737,7 +1737,7 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnResult { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnResultReport_0101"; try { - IncrementalInit(IServiceReverse::Scenario::BACKUP, 1); + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 1); std::string resultReport = "result_report"; std::string bundleName = BUNDLE_NAME; if (service_ == nullptr) { diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index aa8aa1317..7ff525e0a 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -25,11 +25,7 @@ ohos_unittest("ext_extension_test") { module_out_path = path_module_out_tests - sources = [ - "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_proxy.cpp", - "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", - "ext_extension_test.cpp", - ] + sources = [ "ext_extension_test.cpp" ] include_dirs = [ "${path_backup}/frameworks/native/backup_ext/include", @@ -41,6 +37,7 @@ ohos_unittest("ext_extension_test") { ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", "//third_party/googletest:gtest_main", @@ -78,49 +75,6 @@ ohos_unittest("ext_extension_test") { use_exceptions = true } -ohos_unittest("ext_extension_stub_test") { - module_out_path = path_module_out_tests - - sources = [ - "${path_backup_mock}/module_ipc/message_parcel_mock.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", - "ext_extension_stub_test.cpp", - ] - - include_dirs = [ - "${path_backup_mock}/module_ipc", - "${path_backup}/frameworks/native/backup_ext/include", - "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/interfaces/common/include", - "${path_backup}/utils/include", - ] - - deps = [ - "${path_backup}/utils:backup_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] - - cflags = [ "--coverage" ] - ldflags = [ "--coverage" ] - cflags_cc = [ "--coverage" ] - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD004303", - "private=public", - ] - - use_exceptions = true -} - ohos_unittest("tar_file_test") { branch_protector_ret = "pac_ret" sanitize = { @@ -139,7 +93,6 @@ ohos_unittest("tar_file_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", @@ -214,7 +167,6 @@ ohos_unittest("untar_file_sup_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/tests/mock/library_func_mock/library_func_mock.cpp", @@ -290,7 +242,6 @@ ohos_unittest("untar_file_test") { "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", - "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", "${path_backup}/frameworks/native/backup_ext/src/untar_file.cpp", @@ -367,6 +318,7 @@ ohos_unittest("ext_backup_js_test") { ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", "${path_googletest}:gtest_main", @@ -403,6 +355,13 @@ ohos_unittest("ext_backup_js_test") { "private=public", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + use_exceptions = true } @@ -445,7 +404,6 @@ group("backup_ext_test") { if (!use_libfuzzer) { deps = [ ":ext_backup_js_test", - ":ext_extension_stub_test", ":ext_extension_test", ":tar_file_sub_test", ":tar_file_test", diff --git a/tests/unittests/backup_ext/ext_extension_stub_test.cpp b/tests/unittests/backup_ext/ext_extension_stub_test.cpp deleted file mode 100644 index 6e07ddd4d..000000000 --- a/tests/unittests/backup_ext/ext_extension_stub_test.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "b_error/b_error.h" -#include "ext_extension_stub.h" -#include "message_parcel_mock.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -class ExtExtensionStubMock : public ExtExtensionStub { -public: - MOCK_METHOD(UniqueFd, GetFileHandle, (const std::string &fileName, int32_t &errCode)); - MOCK_METHOD(ErrCode, HandleClear, ()); - MOCK_METHOD(ErrCode, HandleBackup, (bool isClearData)); - MOCK_METHOD(ErrCode, PublishFile, (const std::string &fileName)); - MOCK_METHOD(ErrCode, HandleRestore, (bool isClearData)); - MOCK_METHOD((std::tuple), GetIncrementalFileHandle, (const std::string &fileName)); - MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string &fileName)); - MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd incrementalFd, UniqueFd manifestFd)); - MOCK_METHOD(ErrCode, IncrementalOnBackup, (bool isClearData)); - MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); - MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &result)); - MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string &bundleName, int32_t sendRate)); - MOCK_METHOD(ErrCode, User0OnBackup, ()); -}; - -class ExtExtensionStubTest : public testing::Test { -public: - //所有测试用例执行之前执行 - static void SetUpTestCase(void); - //所有测试用例执行之后执行 - static void TearDownTestCase(void); - //每次测试用例执行之前执行 - void SetUp() {}; - //每次测试用例执行之后执行 - void TearDown() {}; -public: - static inline shared_ptr stub = nullptr; - static inline shared_ptr messageParcelMock = nullptr; -}; - -void ExtExtensionStubTest::SetUpTestCase() -{ - stub = make_shared(); - messageParcelMock = make_shared(); - MessageParcelMock::messageParcel = messageParcelMock; -} - -void ExtExtensionStubTest::TearDownTestCase() -{ - stub = nullptr; - MessageParcelMock::messageParcel = nullptr; - messageParcelMock = nullptr; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100 - * @tc.desc: 测试 OnRemoteRequest 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100"; - try { - ASSERT_TRUE(stub != nullptr); - uint32_t code = 0; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(u16string())); - auto err = stub->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - const std::u16string descriptor = ExtExtensionStub::GetDescriptor(); - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(descriptor)); - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - err = stub->OnRemoteRequest(static_cast(IExtensionInterfaceCode::CMD_GET_FILE_HANDLE), - data, reply, option); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadInterfaceToken()).WillOnce(Return(descriptor)); - auto ret = stub->OnRemoteRequest(-1, data, reply, option); - EXPECT_EQ(ret, IPC_STUB_UNKNOW_TRANS_ERR); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by OnRemoteRequest."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_OnRemoteRequest_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100 - * @tc.desc: 测试 CmdGetFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(-1))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(0))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(false)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(0))); - EXPECT_CALL(*messageParcelMock, WriteBool(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)); - err = stub->CmdGetFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetFileHandle."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100 - * @tc.desc: 测试 CmdHandleClear 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, HandleClear()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleClear(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, HandleClear()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleClear(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleClear."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleClear_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100 - * @tc.desc: 测试 CmdHandleBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100 - * @tc.desc: 测试 CmdPublishFile 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdPublishFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdPublishFile."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdPublishFile_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100 - * @tc.desc: 测试 CmdHandleRestore 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleRestore(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleRestore(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, HandleRestore(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleRestore(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleRestore."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleRestore_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100 - * @tc.desc: 测试 CmdGetIncrementalFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - err = stub->CmdGetIncrementalFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetIncrementalFileHandle."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100 - * @tc.desc: 测试 CmdPublishIncrementalFile 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishIncrementalFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, PublishIncrementalFile(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdPublishIncrementalFile(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdPublishIncrementalFile."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdPublishIncrementalFile_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100 - * @tc.desc: 测试 CmdHandleIncrementalBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadFileDescriptor()).WillOnce(Return(0)).WillOnce(Return(0)); - EXPECT_CALL(*stub, HandleIncrementalBackup(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdHandleIncrementalBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadFileDescriptor()).WillOnce(Return(0)).WillOnce(Return(0)); - EXPECT_CALL(*stub, HandleIncrementalBackup(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleIncrementalBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleIncrementalBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdHandleIncrementalBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100 - * @tc.desc: 测试 CmdIncrementalOnBackup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, IncrementalOnBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdIncrementalOnBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadBool()).WillOnce(Return(true)); - EXPECT_CALL(*stub, IncrementalOnBackup(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdIncrementalOnBackup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdIncrementalOnBackup."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdIncrementalOnBackup_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100 - * @tc.desc: 测试 CmdGetIncrementalBackupFileHandle 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << - "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(false)); - auto err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(false)); - err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetIncrementalBackupFileHandle()) - .WillOnce(Return(std::tuple(UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*messageParcelMock, WriteFileDescriptor(_)).WillOnce(Return(true)).WillOnce(Return(true)); - err = stub->CmdGetIncrementalBackupFileHandle(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetIncrementalBackupFileHandle."; - } - GTEST_LOG_(INFO) << - "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetIncrementalBackupFileHandle_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100 - * @tc.desc: 测试 CmdGetBackupInfo 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - auto err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(false)); - err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, GetBackupInfo(_)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); - err = stub->CmdGetBackupInfo(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdGetBackupInfo."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 - * @tc.desc: 测试 CmdUpdateSendRate 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9QWK5 - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; - try { - ASSERT_TRUE(stub != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(false)); - auto err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(false)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_INVAL_ARG)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*messageParcelMock, ReadInt32(_)).WillOnce(Return(true)); - EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdUpdateFdSendRate(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdUpdateSendRate."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; -} - -/** - * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdUser0_0100 - * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdUser0_0100 - * @tc.desc: 测试 CmdHandleUser0Backup 各个分支成功与失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issues - */ -HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdUser0_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdUser0_0100"; - try { - MessageParcel data; - MessageParcel reply; - EXPECT_CALL(*stub, User0OnBackup()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); - EXPECT_TRUE(stub != nullptr); - auto err = stub->CmdHandleUser0Backup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); - - EXPECT_CALL(*stub, User0OnBackup()).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = stub->CmdHandleUser0Backup(data, reply); - EXPECT_EQ(err, BError(BError::Codes::OK)); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdHandleClear."; - } - GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdUser0_0100"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/BUILD.gn b/tests/unittests/backup_sa/BUILD.gn index 5351c84bd..b552944b3 100644 --- a/tests/unittests/backup_sa/BUILD.gn +++ b/tests/unittests/backup_sa/BUILD.gn @@ -19,6 +19,7 @@ group("backup_sa_test") { deps = [ "module_app_gallery:app_gallery_test", + "module_client:service_client_test", "module_external:adapter_test", "module_ipc:backup_sa_ipc_test", "session:session_test", diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn new file mode 100644 index 000000000..9ff89a21a --- /dev/null +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -0,0 +1,87 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") + +ohos_unittest("service_client_test") { + module_out_path = path_module_out_tests + + include_dirs = [ + "${path_backup}/frameworks/native/backup_kit_inner/include", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_notify", + "${path_backup}/utils/include", + "${path_backup}/utils/src", + "${path_backup}/tests/mock/utils_mock/include", + ".", + ] + + sources = [ + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", + "service_client_test.cpp", + ] + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", + "${path_backup}/utils:backup_utils", + ] + + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + defines = [ + "LOG_TAG=\"app_file_service\"", + "LOG_DOMAIN=0xD200000", + "private = public", + "protected = public", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_connect_callback_stub", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] + + use_exceptions = true +} + +group("backup_sa_service_client_test") { + testonly = true + deps = [ ":service_client_test" ] +} diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp new file mode 100644 index 000000000..9352d63b6 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "b_error/b_error.h" +#include "service_client.h" +#include "service_reverse.h" +#include "b_session_restore.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +using namespace testing; + +class ServiceClientTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp() override {}; + void TearDown() override {}; + +public: + static inline sptr proxy = nullptr; +}; + +void ServiceClientTest::SetUpTestCase() +{ + GTEST_LOG_(INFO) << "begin SetUpTestCase"; + proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + GTEST_LOG_(INFO) << "Failed to get ServiceClient instance"; + } +} + +void ServiceClientTest::TearDownTestCase() +{ + if (proxy != nullptr) { + ServiceClient::InvaildInstance(); + proxy = nullptr; + } + ServiceClient::InvaildInstance(); +} + +/** + * @tc.number: SUB_service_client_test_0100 + * @tc.name: SUB_service_client_test_0100 + * @tc.desc: 测试 InitIncrementalBackupSession 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9KPRL + */ +HWTEST_F(ServiceClientTest, SUB_service_client_test_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0100"; + EXPECT_NE(proxy, nullptr); + ServiceClient::InvaildInstance(); + proxy=ServiceClient::serviceProxy_; + EXPECT_EQ(proxy, nullptr); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode ret = proxy->Start(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Finish(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Release(); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->GetAppLocalListAndDoIncrementalBackup(); + EXPECT_NE(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + int32_t result = -1; + ErrCode ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = ""; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = "test"; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + EXPECT_NE(result, 0); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0400"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0400"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0500"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0500"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0600"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = -1; + ErrCode ret = proxy->GetLocalCapabilities(fd); + EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_NE(fd, BError(BError::Codes::OK)); + fd = -2; + ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); + EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_NE(fd, 1); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0700"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + ErrCode ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + fileName = "test"; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0700"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0800"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + bool booleanValue = false; + ErrCode ret = proxy->GetBackupInfo(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_BEF)); + EXPECT_EQ(bundleName, ""); + EXPECT_EQ(fileName, ""); + booleanValue = true; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret,BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bool isExt = true; + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = "test"; + ret = proxy->UpdateTimer(bundleName, 10, isExt); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(isExt, false); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + bundleName = "test"; + ret = proxy->UpdateSendRate(bundleName, 10, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = "name"; + ret = proxy->AppFileReady(fileName, -1, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = "test"; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0900"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string stringVal = ""; + ErrCode ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = "test"; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + int64_t val = -1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + val = 1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize.Level1) +{ + std::string bundleName = ""; + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1000"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + BFileInfo *fileInfo = nullptr; + BFileInfo bf {bundleName, "", 0}; + ErrCode ret = proxy->PublishFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishIncrementalFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); + EXPECT_NE(ret, BError(BError::Codes::OK)); + fileInfo = &bf; + ret = proxy->PublishFile(*fileInfo); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->PublishIncrementalFile(*fileInfo); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1100"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = 0; + int32_t restoreType = -1; + int32_t userid = -1; + std::vector bundleNames; + std::vector detailInfos; + std::vector bundlesToBackup; + ErrCode ret = + proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleNames.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + detailInfos.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + restoreType = 1; + userid = 1; + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + sptr srptr = nullptr; + ErrCode ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + std::string errMsg = ""; + std::string result = "err"; + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + BSessionRestore::Callbacks callback; + srptr = sptr(new ServiceReverse(callback)); + ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file 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..28ba6a6f6 --- /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::AppendBundlesRestoreSessionRestoreDataWaitSend(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::AppendBundlesRestoreSessionRestoreDataWaitReady(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) +{ + 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) +{ + bundleName = "name"; + 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/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 6685f522e..4bceea4fd 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -22,19 +22,12 @@ ohos_unittest("module_ipc_test") { sources = [ "${path_backup_mock}/module_ipc/app_gallery_dispose_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", "${path_backup_mock}/module_ipc/message_parcel_mock.cpp", "${path_backup_mock}/timer/timer_mock.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/service_stub.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_backup_connection.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", - "service_reverse_proxy_test.cpp", - "service_stub_test.cpp", "svc_backup_connection_test.cpp", - "svc_extension_proxy_test.cpp", ] include_dirs = [ @@ -414,16 +407,17 @@ ohos_unittest("backup_service_incremental_test") { "${path_backup_mock}/accesstoken/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/extension_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", "${path_backup_mock}/module_sched/sched_scheduler_mock.cpp", "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_client.cpp", "service_incremental_test.cpp", ] @@ -475,11 +469,13 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/accesstoken/src/accesstoken_kit_mock.cpp", "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/extension_proxy_mock.cpp", + "${path_backup_mock}/module_ipc/extension_type_mock.cpp", + "${path_backup_mock}/module_ipc/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/app_gallery_dispose_proxy_mock.cpp", "${path_backup_mock}/module_ipc/src/ipc_skeleton_mock.cpp", "${path_backup_mock}/module_ipc/src/notify_work_service_mock.cpp", "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", - "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_restore_deps_manager_mock.cpp", "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", @@ -490,8 +486,6 @@ ohos_unittest("backup_service_other_test") { "${path_backup_mock}/utils_mock/src/b_jsonutil_mock.cpp", "${path_backup_mock}/utils_mock/src/b_sa_utils_mock.cpp", "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", - "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", "service_other_test.cpp", ] diff --git a/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp new file mode 100644 index 000000000..767c26153 --- /dev/null +++ b/tests/unittests/backup_sa/module_ipc/extension_proxy_test.cpp @@ -0,0 +1,544 @@ +/* + * 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 "module_ipc/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 diff --git a/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp b/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp index 505e0eb57..788616b82 100644 --- a/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sched_scheduler_test.cpp @@ -42,7 +42,7 @@ public: static void TearDownTestCase(); void SetUp() override {}; void TearDown() override {}; - void Init(IServiceReverse::Scenario scenario); + void Init(IServiceReverseType::Scenario scenario); static inline sptr schedPtr_ = nullptr; static inline sptr sessionManagerPtr_ = nullptr; @@ -63,7 +63,7 @@ void SchedSchedulerTest::TearDownTestCase() sessionManagerPtr_ = nullptr; } -void SchedSchedulerTest::Init(IServiceReverse::Scenario scenario) +void SchedSchedulerTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; map backupExtNameMap; @@ -99,7 +99,7 @@ HWTEST_F(SchedSchedulerTest, SUB_Service_Sched_0100, testing::ext::TestSize.Leve { GTEST_LOG_(INFO) << "SchedSchedulerTest-begin SUB_Service_Sched_0100"; try { - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(schedPtr_ != nullptr); schedPtr_->Sched(); GTEST_LOG_(INFO) << "SchedSchedulerTest-Sched Branches"; diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 4a6ed74b6..63b688ed6 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -23,7 +23,7 @@ #include "sa_backup_connection_mock.h" #include "service_reverse_proxy_mock.h" #include "svc_backup_connection_mock.h" -#include "svc_extension_proxy_mock.h" +#include "extension_proxy_mock.h" #include "svc_session_manager_mock.h" #include "service_incremental.cpp" @@ -35,6 +35,15 @@ void Service::OnStart() {} void Service::OnStop() {} +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + return BError(BError::Codes::OK); +} + UniqueFd Service::GetLocalCapabilities() { return UniqueFd(-1); @@ -47,22 +56,15 @@ ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) return BError(BError::Codes::OK); } -ErrCode Service::InitRestoreSession(sptr remote) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSession(sptr remote, std::string &errMsg) +ErrCode Service::InitRestoreSession(const sptr &remote) { return BError(BError::Codes::OK); } - -ErrCode Service::InitBackupSession(sptr remote) +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } - -ErrCode Service::InitBackupSession(sptr remote, std::string &errMsg) +ErrCode Service::InitBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } @@ -77,43 +79,45 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return BError(BError::Codes::OK); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppDone(ErrCode errCode) +ErrCode Service::AppDone(int32_t appDoneErrCode) { return BError(BError::Codes::OK); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } - ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) { return BError(BError::Codes::OK); } ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } @@ -122,7 +126,10 @@ ErrCode Service::Finish() { return BError(BError::Codes::OK); } - +ErrCode Service::GetLocalCapabilities(int &fd) +{ + return BError(BError::Codes::OK); +} ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { return BError(BError::Codes::OK); @@ -163,7 +170,7 @@ ErrCode Service::VerifyCaller() return BError(BError::Codes::OK); } -ErrCode Service::VerifyCaller(IServiceReverse::Scenario scenario) +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) { return BError(BError::Codes::OK); } @@ -181,17 +188,17 @@ void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} void Service::SessionDeactive() {} -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeOut, bool &result) { return BError(BError::Codes::OK); } -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); } @@ -207,15 +214,11 @@ void Service::OnSARestore(const std::string &bundleName, const std::string &resu void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) {} -void Service::SendEndAppGalleryNotify(const BundleName &bundleName) -{ -} +void Service::SendEndAppGalleryNotify(const BundleName &bundleName) {} -void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) -{ -} +void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) {} -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) { return BError(BError::Codes::OK); } @@ -268,16 +271,16 @@ void Service::HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) {} void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverseType::Scenario scenario) {} void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} @@ -334,7 +337,7 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() } void Service::AppendBundles(const std::vector &bundleNames) {} -ErrCode Service::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { return BError(BError::Codes::OK); } @@ -359,7 +362,7 @@ public: static inline shared_ptr jsonUtil = nullptr; static inline shared_ptr session = nullptr; static inline shared_ptr bms = nullptr; - static inline sptr svcProxy = nullptr; + static inline sptr svcProxy = nullptr; static inline sptr connect = nullptr; static inline shared_ptr saConnect = nullptr; static inline shared_ptr skeleton = nullptr; @@ -376,7 +379,7 @@ void ServiceIncrementalTest::SetUpTestCase(void) BJsonUtilMock::jsonUtil = jsonUtil; session = make_shared(); SvcSessionManagerMock::sessionManager = session; - svcProxy = sptr(new SvcExtensionProxyMock()); + svcProxy = sptr(new ExtensionProxyMock()); bms = make_shared(); BundleMgrAdapterMock::bms = bms; connect = sptr(new SvcBackupConnectionMock()); @@ -386,6 +389,16 @@ void ServiceIncrementalTest::SetUpTestCase(void) skeleton = make_shared(); IPCSkeletonMock::skeleton = skeleton; srProxy = sptr(new ServiceReverseProxyMock()); + EXPECT_NE(service, nullptr); + EXPECT_NE(param, nullptr); + EXPECT_NE(jsonUtil, nullptr); + EXPECT_NE(session, nullptr); + EXPECT_NE(bms, nullptr); + EXPECT_NE(svcProxy, nullptr); + EXPECT_NE(connect, nullptr); + EXPECT_NE(saConnect, nullptr); + EXPECT_NE(skeleton, nullptr); + EXPECT_NE(srProxy, nullptr); } void ServiceIncrementalTest::TearDownTestCase() @@ -425,7 +438,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncr try { auto session_ = service->session_; service->session_ = nullptr; - auto fd = service->GetLocalCapabilitiesIncremental({}); + int fd = -1; + service->GetLocalCapabilitiesIncremental({}, fd); service->session_ = session_; EXPECT_EQ(static_cast(fd), -ENOENT); } catch (...) { @@ -535,13 +549,15 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes try { auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr srPrt = static_cast>(srProxy); + srPrt = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSession(srPrt), BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -565,14 +581,16 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSes std::string errMsg; auto session_ = service->session_; service->session_ = nullptr; - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), - BError(BError::Codes::SA_INVAL_ARG).GetCode()); + sptr reverseNUll = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, Active(_, _)).WillOnce(Return(BError(BError::Codes::OK))); - EXPECT_EQ(service->InitIncrementalBackupSession(nullptr, errMsg), BError(BError::Codes::OK).GetCode()); + EXPECT_EQ(service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg), + BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; @@ -761,26 +779,26 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ try { string fileName; int32_t errCode = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); fileName = BConstants::EXT_BACKUP_MANAGE; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -804,27 +822,27 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ try { string fileName; int32_t errCode = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + auto ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, HandleClear()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(0)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); + ret = service->AppIncrementalFileReady(fileName, 1, 1, errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -900,10 +918,10 @@ 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(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); ret = service->GetIncrementalFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -932,46 +950,46 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0000, GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_IncrementalBackup_0000"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); bool res = service->IncrementalBackup(bundleName); EXPECT_TRUE(res); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); res = service->IncrementalBackup(bundleName); EXPECT_TRUE(res); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); auto ret = service->IncrementalBackup(bundleName); EXPECT_FALSE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); @@ -998,14 +1016,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_IncrementalBackup_0100"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); auto ret = service->IncrementalBackup(bundleName); EXPECT_FALSE(ret); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1014,7 +1032,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_FALSE(ret); set fileNameVec { "fileName" }; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1022,14 +1040,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)) - .WillOnce(Return(make_tuple(BError(BError::Codes::OK).GetCode(), UniqueFd(-1), UniqueFd(-1)))); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -1055,7 +1072,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, try { string bundleName; set fileNameVec { "fileName" }; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); @@ -1063,14 +1080,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)) - .WillOnce(Return(make_tuple(BError(BError::Codes::SA_INVAL_ARG).GetCode(), UniqueFd(-1), UniqueFd(-1)))); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*svcProxy, GetIncrementalFileHandleWithUniqueFdGroup(_, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); auto ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -1096,19 +1112,19 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_NotifyCallerCurAppIncrem try { ErrCode errCode = 0; string callerName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); } catch (...) { @@ -1208,17 +1224,17 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Release_0000, TestSize.L EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); service->session_ = session_; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); ret = service->Release(); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1282,24 +1298,24 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0000, TestSize.Le impl.backupExtNameMap.insert(make_pair(bundleName, info)); int32_t result; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::CLEAN)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::START)); service->Cancel(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index 30ea8f00e..2f0330b99 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -31,7 +31,7 @@ #include "service_reverse_proxy_mock.h" #include "sms_adapter_mock.h" #include "svc_backup_connection_mock.h" -#include "svc_extension_proxy_mock.h" +#include "extension_proxy_mock.h" #include "svc_restore_deps_manager_mock.h" #include "svc_session_manager_mock.h" #include "system_ability_mock.h" @@ -40,20 +40,38 @@ #include "sub_service.cpp" namespace OHOS::FileManagement::Backup { +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + return BError(BError::Codes::OK); +} +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::Release() { return BError(BError::Codes::OK); } -ErrCode Service::Cancel(std::string bundleName, int32_t &result) +ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector&) +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } void Service::StartGetFdTask(std::string, wptr) {} @@ -63,12 +81,12 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr) +ErrCode Service::InitIncrementalBackupSession(const sptr &) { return BError(BError::Codes::OK); } -ErrCode Service::InitIncrementalBackupSession(sptr, std::string &) +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr&, std::string &) { return BError(BError::Codes::OK); } @@ -123,8 +141,12 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode, const std::string&) {} void Service::SendUserIdToApp(string&, int32_t) {} -void Service::SetCurrentBackupSessProperties(const vector&, int32_t, - std::vector&, bool) {} +void Service::SetCurrentBackupSessProperties(const vector &, + int32_t, + std::vector &, + bool) +{ +} std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) { @@ -134,7 +156,7 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName void Service::RemoveExtensionMutex(const BundleName&) {} void Service::CreateDirIfNotExist(const std::string&) {} -} +} // namespace OHOS::FileManagement::Backup class BThreadPool { public: @@ -176,7 +198,7 @@ public: static inline shared_ptr jsonUtil = nullptr; static inline shared_ptr session = nullptr; static inline shared_ptr bms = nullptr; - static inline sptr svcProxy = nullptr; + static inline sptr svcProxy = nullptr; static inline sptr connect = nullptr; static inline shared_ptr saConnect = nullptr; static inline shared_ptr skeleton = nullptr; @@ -203,7 +225,7 @@ void ServiceTest::SetUpTestCase(void) BJsonUtilMock::jsonUtil = jsonUtil; session = make_shared(); SvcSessionManagerMock::sessionManager = session; - svcProxy = sptr(new SvcExtensionProxyMock()); + svcProxy = sptr(new ExtensionProxyMock()); bms = make_shared(); BundleMgrAdapterMock::bms = bms; connect = sptr(new SvcBackupConnectionMock()); @@ -693,30 +715,30 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) BError error(BError::Codes::OK); sptr session_ = service->session_; BundleName bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); } catch (...) { @@ -767,7 +789,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleExceptionOnAppendBundles_0100, TestSize. try { vector appendBundleNames { "bundleName" }; vector restoreBundleNames; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); EXPECT_TRUE(true); @@ -915,7 +937,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleNames.emplace_back("bundleName"); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); EXPECT_TRUE(true); @@ -923,7 +945,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleInfos[0].allToBackup = true; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); @@ -933,7 +955,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0200, TestSize.Level1 restoreBundleInfos[0].versionName = string(BConstants::DEFAULT_VERSION_NAME); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); service->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, backupVersion); @@ -1325,12 +1347,12 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, TestSize.Level1) try { ASSERT_TRUE(service != nullptr); std::string bundleName = ""; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); BJsonUtil::BundleDetailInfo info; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1342,7 +1364,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, TestSize.Level1) ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1378,7 +1400,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) ASSERT_TRUE(service != nullptr); string bundleName = ""; BJsonUtil::BundleDetailInfo info; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1397,7 +1419,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1566,14 +1588,14 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0000, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); ret = service->UpdateSendRate(bundleName, 0, result); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); ret = service->UpdateSendRate(bundleName, 0, result); @@ -1604,7 +1626,7 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, UpdateFdSendRate(_, _)).WillOnce(Return(EPERM)); @@ -1614,7 +1636,7 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateSendRate_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, UpdateFdSendRate(_, _)).WillOnce(Return(NO_ERROR)); @@ -1642,42 +1664,42 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) try { string bundleName; shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); auto ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); sa = make_shared(nullptr, nullptr, nullptr, nullptr); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1718,7 +1740,7 @@ HWTEST_F(ServiceTest, SUB_Service_SADone_0000, TestSize.Level1) EXPECT_CALL(*saConnect, DisconnectBackupSAExt()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SADone(0, ""); @@ -1743,20 +1765,20 @@ HWTEST_F(ServiceTest, SUB_Service_NotifyCallerCurAppDone_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NotifyCallerCurAppDone_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); } catch (...) { @@ -1785,7 +1807,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return(1)); auto ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1794,7 +1816,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1803,7 +1825,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1812,7 +1834,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return(1)); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1876,9 +1898,9 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0000, TestSize.Level1) service->session_ = session_; EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -1890,7 +1912,7 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0000, TestSize.Level1) EXPECT_TRUE(true); shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); @@ -1919,7 +1941,7 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0100, TestSize.Level1) try { string bundleName; shared_ptr sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); @@ -1928,16 +1950,16 @@ HWTEST_F(ServiceTest, SUB_Service_DoTimeout_0100, TestSize.Level1) EXPECT_TRUE(true); sa = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->DoTimeout(service, bundleName); EXPECT_TRUE(true); sa = make_shared(nullptr, nullptr, nullptr, nullptr); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, DisconnectBackupSAExt()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -2028,19 +2050,19 @@ HWTEST_F(ServiceTest, SUB_Service_ReleaseOnException_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); service->isInRelease_ = false; service->ReleaseOnException(); EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); service->isInRelease_ = true; service->ReleaseOnException(); EXPECT_TRUE(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); service->isInRelease_ = true; auto session_ = service->session_; service->session_ = nullptr; diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 48853ff35..63d09d7d7 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -20,7 +20,7 @@ #include #include "b_error/b_error.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "iservice_registry.h" #include "message_parcel_mock.h" #include "module_ipc/service_reverse_proxy.h" @@ -93,7 +93,8 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnFileReady_010 std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, fd, 0); + int fdValue = fd.Get(); + proxy_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, fdValue, 0); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -360,7 +361,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnBundleFinishe .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->BackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + proxy_->BackupOnBundleFinished(BError(BError::Codes::OK).GetCode(), BUNDLE_NAME); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1924,7 +1925,8 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; EXPECT_TRUE(proxy_ != nullptr); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + int32_t code=0; + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1946,11 +1948,12 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport { GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_RestoreOnResultReport_0101"; try { + int32_t code = 0; std::string bundleName = "app01"; try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1959,7 +1962,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1968,7 +1971,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(false)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -1979,7 +1982,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); - proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2012,8 +2015,10 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; + EXPECT_TRUE(proxy_ != nullptr); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + int32_t code = 0; + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -2031,16 +2036,19 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR * @tc.level Level 1 * @tc.require: I9OVHB */ -HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101, - testing::ext::TestSize.Level1) +HWTEST_F(ServiceReverseProxyTest, + SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101, + testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_IncrementalRestoreOnResultReport_0101"; try { + int32_t code = 0; std::string bundleName = "app01"; try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(false)); EXPECT_TRUE(proxy_ != nullptr); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2049,7 +2057,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(false)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2058,7 +2066,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR try { EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(false)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); @@ -2069,7 +2077,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_IncrementalRestoreOnR EXPECT_CALL(*messageParcelMock_, WriteString(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock_, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(-1)); - proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName); + proxy_->IncrementalRestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(false); } catch (BError &err) { EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_BROKEN_IPC); diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index c63b4b11f..2fbd84033 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -25,7 +25,7 @@ #include "b_error/b_error.h" #include "b_resources/b_constants.h" #include "ipc_types.h" -#include "i_service.h" +#include "iservice.h" #include "message_parcel_mock.h" #include "module_ipc/service_stub.h" #include "service_reverse_mock.h" @@ -43,26 +43,27 @@ const string FILE_NAME = "1.tar"; class ServiceMock final : public ServiceStub { public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); MOCK_METHOD3(AppFileReady, ErrCode(const string &fileName, UniqueFd fd, int32_t errCode)); MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD3(ServiceResultReport, + ErrCode(const string &restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode)); MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); - MOCK_METHOD5( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, - RestoreTypeEnum restoreType, int32_t userId)); - MOCK_METHOD4( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD5(AppendBundlesRestoreSessionRestoreDataWaitSend, + ErrCode(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId)); + MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + ErrCode(UniqueFd fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId)); MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD2(AppendBundlesDetailsBackupSession, ErrCode(const std::vector &bundleNames, const std::vector &bundleInfos)); @@ -75,12 +76,12 @@ public: MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode)); MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); MOCK_METHOD2(GetBackupInfo, ErrCode(string &bundleName, string &result)); @@ -1181,7 +1182,7 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitIncrementalBackupSession EXPECT_CALL(*messageParcelMock, ReadRemoteObject()).WillOnce(Return(remote)); EXPECT_CALL(*castMock, iface_cast(_)).WillOnce(Return(remote)); - EXPECT_CALL(*service, InitIncrementalBackupSession(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); err = service->CmdInitIncrementalBackupSessionMsg(data, reply); @@ -1189,7 +1190,7 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitIncrementalBackupSession EXPECT_CALL(*messageParcelMock, ReadRemoteObject()).WillOnce(Return(remote)); EXPECT_CALL(*castMock, iface_cast(_)).WillOnce(Return(remote)); - EXPECT_CALL(*service, InitIncrementalBackupSession(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); auto ret = service->CmdInitIncrementalBackupSessionMsg(data, reply); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index ba99f49ff..7aac06a15 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -44,7 +44,7 @@ public: void SetUp() {}; void TearDown() {}; - ErrCode Init(IServiceReverse::Scenario scenario); + ErrCode Init(IServiceReverseType::Scenario scenario); static inline sptr servicePtr_ = nullptr; static inline sptr remote_ = nullptr; @@ -64,7 +64,7 @@ void ServiceTest::TearDownTestCase() remote_ = nullptr; } -ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) +ErrCode ServiceTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; vector detailInfos; @@ -83,23 +83,25 @@ ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario) detailInfos.emplace_back(json); string errMsg; ErrCode ret = 0; - if (scenario == IServiceReverse::Scenario::RESTORE) { + if (scenario == IServiceReverseType::Scenario::RESTORE) { EXPECT_TRUE(servicePtr_ != nullptr); EXPECT_TRUE(remote_ != nullptr); UniqueFd fd = servicePtr_->GetLocalCapabilities(); EXPECT_GE(fd, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_); + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitRestoreSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitRestoreSession(remote_, errMsg); + ret = servicePtr_->InitRestoreSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->Finish(); EXPECT_EQ(ret, BError(BError::Codes::OK)); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - ret = servicePtr_->InitBackupSession(remote_); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + sptr srptr_=static_cast>(remote_); + ret = servicePtr_->InitBackupSession(srptr_); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->InitBackupSession(remote_, errMsg); + ret = servicePtr_->InitBackupSessionWithErrMsg(srptr_, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->AppendBundlesBackupSession(bundleNames); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -213,7 +215,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0100, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -243,7 +245,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0101, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -273,7 +275,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0102, testing::ext::TestSize.Level { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0102"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); BFileInfo fileInfo {BUNDLE_NAME, "", 0}; EXPECT_TRUE(servicePtr_ != nullptr); @@ -301,11 +303,11 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0100, testing::ext::TestSize.Leve try { string fileName = MANAGE_JSON; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppFileReady Branches"; fileName = "test"; - ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -329,7 +331,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0101, testing::ext::TestSize.Leve try { string fileName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -353,7 +355,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Leve try { string fileName = "manage.json"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0); + auto ret = servicePtr_->AppFileReady(fileName, 1, 0); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -377,16 +379,16 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0100, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_AppDone_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches"; ret = servicePtr_->AppDone(1); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches End"; - ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -410,12 +412,12 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0101, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_AppDone_0101 RESTORE"; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -440,7 +442,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0102, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start"; string bundleName = ""; EXPECT_TRUE(servicePtr_ != nullptr); - auto ret = servicePtr_->AppDone(BError(BError::Codes::OK)); + auto ret = servicePtr_->AppDone(BError(BError::Codes::OK).GetCode()); EXPECT_EQ(ret, BError(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); @@ -500,13 +502,13 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); EXPECT_EQ(ret, BError(BError::Codes::OK)); @@ -531,7 +533,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0101, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0101"; try { GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 UNDEFINED"; - ErrCode ret = Init(IServiceReverse::Scenario::UNDEFINED); + ErrCode ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME); @@ -556,7 +558,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->GetFileHandle(BUNDLE_NAME, FILE_NAME); @@ -581,7 +583,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0101, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; @@ -617,13 +619,13 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0100, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); string bundleName = BUNDLE_NAME; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->OnBackupExtensionDied(move(bundleName)); GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); bundleName = BUNDLE_NAME; servicePtr_->OnBackupExtensionDied(move(bundleName)); @@ -648,7 +650,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0101, testing::ext::Test GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0101"; try { GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); string bundleName = BUNDLE_NAME; SvcSessionManager::Impl impl_; @@ -658,12 +660,12 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0101, testing::ext::Test extInfo.versionName = "0.0.0.0-0.0.0.0"; impl_.restoreDataType = RESTORE_DATA_WAIT_SEND; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->OnBackupExtensionDied(move(bundleName)); GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); impl_.restoreDataType = RESTORE_DATA_READDY; bundleName = "123456789"; @@ -690,14 +692,14 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtStart_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 BACKUP"; - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtStart(BUNDLE_NAME); GTEST_LOG_(INFO) << "ServiceTest-ExtStart BACKUP Branches"; servicePtr_->ExtStart(BUNDLE_NAME); GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 RESTORE"; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); servicePtr_->ExtStart(BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -721,7 +723,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) try { GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0101 BACKUP"; std::string bundleName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtStart(bundleName); @@ -736,16 +738,16 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); extInfo.backUpConnection->backupProxy_ = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::UNDEFINED; - ret = Init(IServiceReverse::Scenario::UNDEFINED); + impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; + ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::UNDEFINED); + ret = Init(IServiceReverseType::Scenario::UNDEFINED); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtStart(BUNDLE_NAME); } catch (...) { @@ -841,19 +843,19 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectFailed_0100, testing::ext::TestSize. GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectFailed_0100"; try { GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 RESTORE"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; impl_.restoreDataType = RESTORE_DATA_READDY; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK)); } catch (...) { @@ -1064,7 +1066,7 @@ HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0101, testing::ext:: { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendStartAppGalleryNotify_0101"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendStartAppGalleryNotify(BUNDLE_NAME); @@ -1112,7 +1114,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0100, testing::ext::TestSize.Lev try { std::string bundleName = "com.example.app2backup"; std::string backupInfo = "backup info"; - auto ret = Init(IServiceReverse::Scenario::BACKUP); + auto ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->GetBackupInfo(bundleName, backupInfo); @@ -1138,7 +1140,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0101, testing::ext::TestSize.Lev try { std::string bundleName = "com.example.app2backup"; std::string result = "ok"; - auto ret = Init(IServiceReverse::Scenario::BACKUP); + auto ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->session_ = nullptr; @@ -1280,7 +1282,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, testing::ext::TestSize.L servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); SvcSessionManager::Impl impl_; impl_.clientToken = 1; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); @@ -1524,7 +1526,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, testing::ext::Tes BackupExtInfo extInfo {}; extInfo.backUpConnection = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->HandleCurBundleEndWork(BUNDLE_NAME, BackupRestoreScenario::FULL_RESTORE); } catch (...) { @@ -1548,7 +1550,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0100, testing::ext::Te GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupSAExtension_0100"; try { std::string bundleName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); ret = servicePtr_->LaunchBackupSAExtension(BUNDLE_NAME); @@ -1571,7 +1573,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0100, testing::ext::Te ret = servicePtr_->LaunchBackupSAExtension(bundleName); EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = servicePtr_->LaunchBackupSAExtension(bundleName); EXPECT_NE(ret, BError(BError::Codes::OK)); @@ -1596,7 +1598,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectDied_0100"; try { std::string callName = "123456"; - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; @@ -1606,7 +1608,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le string bundleNameIndexInfo = "123456789"; extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; - impl_.scenario = IServiceReverse::Scenario::RESTORE; + impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ExtConnectDied(callName); extInfo.backUpConnection->isConnected_.store(true); @@ -1631,19 +1633,19 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, testing::ext::TestSiz { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NoticeClientFinish_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); + ErrCode ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "SUB_Service_NoticeClientFinish_0100 BACKUP"; - ret = Init(IServiceReverse::Scenario::BACKUP); + ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); SvcSessionManager::Impl impl_; impl_.clientToken = 1; impl_.restoreDataType = RESTORE_DATA_READDY; - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK)); } catch (...) { @@ -1666,13 +1668,13 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0100, testing::ext::TestS { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnAllBundlesFinished_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_)); servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK)); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { @@ -1695,12 +1697,12 @@ HWTEST_F(ServiceTest, SUB_Service_SendEndAppGalleryNotify_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendEndAppGalleryNotify_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME); } catch (...) { @@ -1723,12 +1725,12 @@ HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0100, testing::ext::Te { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendErrAppGalleryNotify_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->SendErrAppGalleryNotify(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->SendErrAppGalleryNotify(); } catch (...) { @@ -1751,12 +1753,12 @@ HWTEST_F(ServiceTest, SUB_Service_ClearDisposalOnSaStart_0100, testing::ext::Tes { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ClearDisposalOnSaStart_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->ClearDisposalOnSaStart(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->ClearDisposalOnSaStart(); } catch (...) { @@ -1779,12 +1781,12 @@ HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0100, testing::ext::TestSi { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_DeleteDisConfigFile_0100"; try { - ErrCode ret = Init(IServiceReverse::Scenario::BACKUP); + ErrCode ret = Init(IServiceReverseType::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_TRUE(servicePtr_ != nullptr); servicePtr_->DeleteDisConfigFile(); - ret = Init(IServiceReverse::Scenario::RESTORE); + ret = Init(IServiceReverseType::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); servicePtr_->DeleteDisConfigFile(); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 158372cd2..186592052 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -136,7 +136,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -146,8 +147,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -157,7 +158,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr); + ret = service->InitRestoreSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0100"; } @@ -180,7 +181,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitRestoreSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -190,8 +192,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -201,8 +203,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitRestoreSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -212,7 +214,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0200, testing::e EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitRestoreSession(nullptr, errMsg); + ret = service->InitRestoreSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0200"; } @@ -234,7 +236,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -244,8 +247,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -255,7 +258,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr); + ret = service->InitBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0100"; } @@ -278,7 +281,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -288,8 +292,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -299,8 +303,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -310,7 +314,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0200, testing::ex EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitBackupSession(nullptr, errMsg); + ret = service->InitBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0200"; } @@ -527,7 +531,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -540,7 +545,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::Te .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppFileReady(fileName, UniqueFd(-1), 0); + ret = service->AppFileReady(fileName, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -593,7 +598,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_LaunchBackupExtension_0100, testing try { EXPECT_NE(service, nullptr); BundleName bundleName; - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { @@ -653,8 +658,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing EXPECT_NE(service, nullptr); string bundleName; EXPECT_CALL(*sessionMock, GetScenario()) - .WillOnce(Return(IServiceReverse::Scenario::CLEAN)) - .WillOnce(Return(IServiceReverse::Scenario::CLEAN)); + .WillOnce(Return(IServiceReverseType::Scenario::CLEAN)) + .WillOnce(Return(IServiceReverseType::Scenario::CLEAN)); EXPECT_CALL(*sessionMock, VerifyBundleName(_)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); @@ -692,21 +697,21 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtConnectFailed_0100, testing::ext BundleName bundleName; EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw BError(BError::Codes::EXT_THROW_EXCEPTION); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() { throw "未知错误"; - return IServiceReverse::Scenario::UNDEFINED; + return IServiceReverseType::Scenario::UNDEFINED; })); service->ExtConnectFailed(bundleName, 0); EXPECT_TRUE(true); @@ -734,8 +739,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_NoticeClientFinish_0100, testing::e string bundleName; ErrCode errCode = 0; EXPECT_CALL(*sessionMock, GetScenario()) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, errCode); EXPECT_TRUE(true); @@ -914,22 +919,23 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_010 throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); + int fd = -1; + ErrCode ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->GetLocalCapabilitiesIncremental(bundleNames); - EXPECT_EQ(-ret, EPERM); + ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); + EXPECT_EQ(-fd, EPERM); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilitiesIncremental."; @@ -995,7 +1001,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr); + sptr reverse = nullptr; + auto ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1006,8 +1013,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1019,7 +1026,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr); + ret = service->InitIncrementalBackupSession(reverse); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0100"; } @@ -1042,7 +1049,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - auto ret = service->InitIncrementalBackupSession(nullptr, errMsg); + sptr reverseNUll = nullptr; + auto ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1053,8 +1061,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1065,8 +1073,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::SA_SESSION_CONFLICT))); - EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::SA_SESSION_CONFLICT).GetCode()); EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); @@ -1078,7 +1086,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0200, .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); - ret = service->InitIncrementalBackupSession(nullptr, errMsg); + ret = service->InitIncrementalBackupSessionWithErrMsg(reverseNUll, errMsg); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0200"; } @@ -1138,14 +1146,14 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSessi throw BError(BError::Codes::EXT_THROW_EXCEPTION); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + auto ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw "未知错误"; })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); - ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + ret = service->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, infos); EXPECT_EQ(ret, EPERM); } catch (...) { EXPECT_TRUE(false); @@ -1207,7 +1215,8 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); - auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + int fd = 1; + auto ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0)); @@ -1220,7 +1229,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testi .WillOnce(Return("bundleName")) .WillOnce(Return("bundleName")); EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Return(BError(BError::Codes::SA_REFUSED_ACT))); - ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0); + ret = service->AppIncrementalFileReady(fileName, fd, fd, 0); EXPECT_EQ(ret, BError(BError::Codes::SA_REFUSED_ACT).GetCode()); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index a982e92e2..aabfdfd6f 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -27,12 +27,12 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurGroupBackupInfos_0000, TestSize.Level GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleCurGroupBackupInfos_0000"; try { vector backupInfos = { - {.name = "bundleName", .appIndex = 0, .allToBackup = false, .versionName = ""} }; + {.name = "bundleName", .appIndex = 0, .allToBackup = false, .versionName = ""}}; map> bundleNameDetailMap; map isClearDataFlags; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*jsonUtil, FindBundleInfoByName(_, _, _, _)).WillOnce(Return(false)); @@ -75,7 +75,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -87,7 +87,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -100,7 +100,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(1)); ret = service->ServiceResultReport("", BackupRestoreScenario::FULL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -110,7 +110,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(1)); ret = service->ServiceResultReport("", BackupRestoreScenario::INCREMENTAL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -134,29 +134,29 @@ HWTEST_F(ServiceTest, SUB_Service_SAResultReport_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SAResultReport_0000"; try { EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(1)); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_BACKUP); @@ -183,14 +183,14 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) try { BundleName bundleName; EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); auto ret = service->LaunchBackupSAExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); shared_ptr sa = nullptr; EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->LaunchBackupSAExtension(bundleName); @@ -198,14 +198,14 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) sa = make_shared(nullptr, nullptr, nullptr, nullptr); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); ret = service->LaunchBackupSAExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, ConnectBackupSAExt(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -213,7 +213,7 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0000, TestSize.Level1) EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetBackupExtInfo(_)).WillOnce(Return("")); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, ConnectBackupSAExt(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); @@ -303,9 +303,9 @@ 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, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(-1))); + EXPECT_CALL(*svcProxy, GetFileHandleWithUniqueFd(_, _, _)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(1)); auto ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -316,12 +316,12 @@ 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, GetFileHandle(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(UniqueFd(-1)))); + EXPECT_CALL(*svcProxy, GetFileHandleWithUniqueFd(_, _, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(0))); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(1)); ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,15 +345,16 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0000"; try { service->isOccupyingSession_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->OnBackupExtensionDied("", true); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); @@ -388,9 +389,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -401,9 +403,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -415,9 +418,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0000, TestSize.Level1) EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ExtConnectDied(callName); @@ -445,15 +449,16 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) string callName; shared_ptr sa = make_shared(nullptr, nullptr, nullptr, nullptr); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); service->ExtStart(callName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -461,9 +466,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -472,9 +478,10 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -503,26 +510,27 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) try { string callName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); service->ExtStart(callName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::BACKUP)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -532,13 +540,13 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) set fileNameVec; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); @@ -546,7 +554,6 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtStart."; } GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtStart_0100"; } @@ -593,46 +600,46 @@ HWTEST_F(ServiceTest, SUB_Service_ReportOnExtConnectFailed_0000, TestSize.Level1 string bundleName; auto session_ = service->session_; service->session_ = nullptr; - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::UNDEFINED, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::UNDEFINED, bundleName, 0); service->session_ = session_; EXPECT_TRUE(true); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::UNDEFINED, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::UNDEFINED, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(1)); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(1)); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(1)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); - service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); + service->ReportOnExtConnectFailed(IServiceReverseType::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -656,35 +663,35 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) try { string bundleName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -710,20 +717,20 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) try { string bundleName; EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(1)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -789,13 +796,13 @@ HWTEST_F(ServiceTest, SUB_Service_ClearSessionAndSchedInfo_0000, TestSize.Level1 try { string bundleName; service->isOccupyingSession_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); service->ClearSessionAndSchedInfo(bundleName); EXPECT_TRUE(true); service->isOccupyingSession_ = true; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->ClearSessionAndSchedInfo(bundleName); @@ -803,7 +810,7 @@ HWTEST_F(ServiceTest, SUB_Service_ClearSessionAndSchedInfo_0000, TestSize.Level1 service->failedBundles_.clear(); service->successBundlesNum_ = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); service->ClearSessionAndSchedInfo(bundleName); @@ -829,19 +836,19 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleRestoreDepsBundle_0000"; try { string bundleName; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->HandleRestoreDepsBundle(bundleName); EXPECT_TRUE(true); map bundleMap; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); service->HandleRestoreDepsBundle(bundleName); EXPECT_TRUE(true); bundleMap["bundleName"] = {.fileNames_ = {"name"}}; vector bundleInfos {{.name = "name"}}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); EXPECT_CALL(*depManager, GetAllBundles()).WillOnce(Return(bundleInfos)); service->HandleRestoreDepsBundle(bundleName); @@ -849,7 +856,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) bundleInfos.clear(); bundleInfos = {{.name = "bundleName"}}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*depManager, GetRestoreBundleMap()).WillOnce(Return(bundleMap)); EXPECT_CALL(*depManager, GetAllBundles()).WillOnce(Return(bundleInfos)); service->HandleRestoreDepsBundle(bundleName); @@ -861,7 +868,6 @@ HWTEST_F(ServiceTest, SUB_Service_HandleRestoreDepsBundle_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleRestoreDepsBundle_0000"; } - /** * @tc.number: SUB_Service_OnAllBundlesFinished_0000 * @tc.name: SUB_Service_OnAllBundlesFinished_0000 @@ -881,36 +887,37 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0000, TestSize.Level1) service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(true); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)).WillOnce(Return(true)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -936,32 +943,32 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0100, TestSize.Level1) try { service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -987,17 +994,17 @@ HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0200, TestSize.Level1) try { service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnAllBundlesFinished(_)).WillOnce(Return(1)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(true)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); service->isInRelease_.store(false); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(true)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*param, GetBackupOverrideBackupSARelease()).WillOnce(Return(false)); service->OnAllBundlesFinished(0); EXPECT_TRUE(true); @@ -1054,18 +1061,18 @@ HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0000, TestSize.Level EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendStartAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, IfBundleNameInDisposalConfigFile(_)).WillOnce(Return(false)); service->SendStartAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, IfBundleNameInDisposalConfigFile(_)).WillOnce(Return(true)); EXPECT_CALL(*gallery, StartRestore(_, _)).WillOnce(Return(DisposeErr::OK)); service->SendStartAppGalleryNotify(bundleName); @@ -1096,25 +1103,25 @@ HWTEST_F(ServiceTest, SUB_Service_SendEndAppGalleryNotify_0000, TestSize.Level1) EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::REQUEST_FAIL)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(false)); service->SendEndAppGalleryNotify(bundleName); EXPECT_TRUE(true); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); service->SendEndAppGalleryNotify(bundleName); @@ -1145,7 +1152,8 @@ HWTEST_F(ServiceTest, SUB_Service_TryToClearDispose_0000, TestSize.Level1) service->TryToClearDispose(bundleName); EXPECT_TRUE(true); - EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::REQUEST_FAIL)) + EXPECT_CALL(*gallery, EndRestore(_, _)) + .WillOnce(Return(DisposeErr::REQUEST_FAIL)) .WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(false)); service->TryToClearDispose(bundleName); @@ -1170,18 +1178,18 @@ HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendErrAppGalleryNotify_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SendErrAppGalleryNotify(); EXPECT_TRUE(true); vector bundleNameList; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); service->SendErrAppGalleryNotify(); EXPECT_TRUE(true); bundleNameList.emplace_back("bundleName"); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*gallery, EndRestore(_, _)).WillOnce(Return(DisposeErr::OK)); EXPECT_CALL(*jdConfig, DeleteFromDisposalConfigFile(_)).WillOnce(Return(true)); @@ -1238,24 +1246,24 @@ HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0000, TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_DeleteDisConfigFile_0000"; try { - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); vector bundleNameList {"bundleName"}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); bundleNameList.clear(); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*jdConfig, DeleteConfigFile()).WillOnce(Return(false)); service->DeleteDisConfigFile(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(bundleNameList)); EXPECT_CALL(*jdConfig, DeleteConfigFile()).WillOnce(Return(true)); service->DeleteDisConfigFile(); @@ -1288,27 +1296,29 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0000, TestSize.Level1) auto sched = service->sched_; service->sched_ = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)).WillOnce(Return(false)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)) .WillOnce(DoAll(SetArgReferee<0>(BError(BError::Codes::SA_INVAL_ARG)), Return(true))); service->SessionDeactive(); EXPECT_TRUE(true); vector bundleNameList {"bundleName"}; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*session, CleanAndCheckIfNeedWait(_, _)) .WillOnce(DoAll(SetArgReferee<1>(bundleNameList), Return(true))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -1337,18 +1347,20 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, TestSize.Level1) try { service->failedBundles_.clear(); service->successBundlesNum_ = 0; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); EXPECT_TRUE(true); service->isRmConfigFile_ = true; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*cdConfig, DeleteConfigFile()).WillOnce(Return(false)); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); @@ -1356,9 +1368,10 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, TestSize.Level1) EXPECT_TRUE(true); service->isRmConfigFile_ = false; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); @@ -1388,17 +1401,19 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0200, TestSize.Level1) service->isRmConfigFile_ = false; auto clearRecorder = service->clearRecorder_; service->clearRecorder_ = nullptr; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(0)); service->SessionDeactive(); EXPECT_TRUE(true); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*session, ClearSessionData()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG))); EXPECT_CALL(*session, GetSessionCnt()).WillOnce(Return(-1)); service->SessionDeactive(); @@ -1497,15 +1512,15 @@ HWTEST_F(ServiceTest, SUB_Service_TimeoutRadarReport_0000, TestSize.Level1) string bundleName; EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - service->TimeoutRadarReport(IServiceReverse::Scenario::BACKUP, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::BACKUP, bundleName); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); - service->TimeoutRadarReport(IServiceReverse::Scenario::RESTORE, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::RESTORE, bundleName); EXPECT_TRUE(true); - service->TimeoutRadarReport(IServiceReverse::Scenario::UNDEFINED, bundleName); + service->TimeoutRadarReport(IServiceReverseType::Scenario::UNDEFINED, bundleName); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1528,7 +1543,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetLocalCapabilitiesForBdInfos_0000, TestSize. GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetLocalCapabilitiesForBdInfos_0000"; try { ASSERT_TRUE(service != nullptr); - auto session_ = service->session_; + auto session_ = service->session_; service->session_ = nullptr; EXPECT_EQ(-EPERM, service->GetLocalCapabilitiesForBundleInfos()); @@ -1808,10 +1823,14 @@ HWTEST_F(ServiceTest, SUB_Service_GetPrecisesSize_0100, TestSize.Level1) dataTwo.bundleName = BUNDLE_NAME; dataTwo.lastIncrementalTime = 1; bundleNameListTwo.push_back(dataTwo); - EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)) - .WillOnce(Return(info)).WillOnce(Return(info)); - EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)).WillOnce(Return(0)) - .WillOnce(Return(0)).WillOnce(Return(0)); + EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)) + .WillOnce(Return(info)) + .WillOnce(Return(info)) + .WillOnce(Return(info)); + EXPECT_CALL(*sms, GetBundleStatsForIncrease(_, _, _, _, _)) + .WillOnce(Return(0)) + .WillOnce(Return(0)) + .WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) @@ -1892,16 +1911,12 @@ HWTEST_F(ServiceTest, SUB_Service_GetDataSizeStepByStep_0000, TestSize.Level1) bool isPreciseScan = false; vector bundleNameList; string scanning = ""; - EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { - f(); - }))); + EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { f(); }))); service->GetDataSizeStepByStep(isPreciseScan, bundleNameList, scanning); EXPECT_TRUE(true); isPreciseScan = true; - EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { - f(); - }))); + EXPECT_CALL(*task, AddTask(_)).WillOnce(WithArgs<0>(Invoke([](const ThreadPool::Task &f) { f(); }))); service->GetDataSizeStepByStep(isPreciseScan, bundleNameList, scanning); EXPECT_TRUE(true); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index 54c6a5067..e388a28d1 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -44,7 +44,7 @@ public: static void TearDownTestCase(void); void SetUp() override {}; void TearDown() override {}; - void Init(IServiceReverse::Scenario scenario); + void Init(IServiceReverseType::Scenario scenario); static inline sptr sessionManagerPtr_ = nullptr; static inline sptr remote_ = nullptr; @@ -67,7 +67,7 @@ void SvcSessionManagerTest::TearDownTestCase(void) remote_ = nullptr; } -void SvcSessionManagerTest::Init(IServiceReverse::Scenario scenario) +void SvcSessionManagerTest::Init(IServiceReverseType::Scenario scenario) { vector bundleNames; vector failedBundles; @@ -96,19 +96,19 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_VerifyCallerAndScenario_01 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_VerifyCallerAndScenario_0100"; try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; ErrCode ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, - IServiceReverse::Scenario::RESTORE); + IServiceReverseType::Scenario::RESTORE); EXPECT_TRUE(ret == BError(BError::Codes::SDK_MIXED_SCENARIO).GetCode()); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; sessionManagerPtr_->impl_.clientToken = 0; - ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverse::Scenario::BACKUP); + ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(ret == BError(BError::Codes::SA_REFUSED_ACT).GetCode()); - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverse::Scenario::BACKUP); + ret = sessionManagerPtr_->VerifyCallerAndScenario(CLIENT_TOKEN_ID, IServiceReverseType::Scenario::BACKUP); EXPECT_TRUE(ret == ERR_OK); } catch (...) { EXPECT_TRUE(false); @@ -141,13 +141,13 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Active_0100, testing::ext: EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); newImpl.clientToken = CLIENT_TOKEN_ID; - newImpl.scenario = IServiceReverse::Scenario::UNDEFINED; + newImpl.scenario = IServiceReverseType::Scenario::UNDEFINED; sessionManagerPtr_->impl_.clientToken = 0; res = sessionManagerPtr_->Active(newImpl); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); newImpl.clientToken = CLIENT_TOKEN_ID; - newImpl.scenario = IServiceReverse::Scenario::BACKUP; + newImpl.scenario = IServiceReverseType::Scenario::BACKUP; newImpl.clientProxy = nullptr; sessionManagerPtr_->impl_.clientToken = 0; res = sessionManagerPtr_->Active(newImpl); @@ -282,12 +282,12 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_getscenario_0100, testing: try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = 0; - IServiceReverse::Scenario scenario = sessionManagerPtr_->GetScenario(); - EXPECT_TRUE(scenario == IServiceReverse::Scenario::UNDEFINED); + IServiceReverseType::Scenario scenario = sessionManagerPtr_->GetScenario(); + EXPECT_TRUE(scenario == IServiceReverseType::Scenario::UNDEFINED); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; scenario = sessionManagerPtr_->GetScenario(); - EXPECT_TRUE(scenario == IServiceReverse::Scenario::UNDEFINED); + EXPECT_TRUE(scenario == IServiceReverseType::Scenario::UNDEFINED); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by getscenario."; @@ -320,21 +320,21 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0100, te sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); EXPECT_TRUE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap["123"] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady("123"); EXPECT_TRUE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); EXPECT_FALSE(fileReady); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_onBundlefileready_0100"; @@ -356,21 +356,21 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0101, te sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); EXPECT_FALSE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, "test"); EXPECT_FALSE(fileReady); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, string(BConstants::EXT_BACKUP_MANAGE)); EXPECT_FALSE(fileReady); @@ -402,7 +402,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleExtManageInfo_0100 EXPECT_TRUE(move(ret) == -1); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); EXPECT_TRUE(move(ret) == -1); @@ -583,7 +583,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0102 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0102"; EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); EXPECT_TRUE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0102"; @@ -603,7 +603,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0103 GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0103"; EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); EXPECT_FALSE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0103"; @@ -1009,14 +1009,14 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_NeedToUnloadService_0100, sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; sessionManagerPtr_->impl_.restoreDataType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->NeedToUnloadService(); EXPECT_FALSE(ret); sessionManagerPtr_->impl_.backupExtNameMap.clear(); sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; sessionManagerPtr_->impl_.restoreDataType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::BACKUP; ret = sessionManagerPtr_->NeedToUnloadService(); EXPECT_FALSE(ret); } catch (...) { @@ -1079,7 +1079,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleFileReady_0200, te try { EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->Deactive(nullptr, true); - Init(IServiceReverse::Scenario::BACKUP); + Init(IServiceReverseType::Scenario::BACKUP); bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); EXPECT_FALSE(fileReady); fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); @@ -1470,12 +1470,12 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_IsOnAllBundlesFinished_010 EXPECT_FALSE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::RESTORE; ret = sessionManagerPtr_->IsOnAllBundlesFinished(); EXPECT_FALSE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + sessionManagerPtr_->impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; ret = sessionManagerPtr_->IsOnAllBundlesFinished(); EXPECT_FALSE(ret); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_IsOnAllBundlesFinished_0100"; diff --git a/tests/unittests/backup_sa/session/BUILD.gn b/tests/unittests/backup_sa/session/BUILD.gn index 46b847da7..5b5e76d10 100644 --- a/tests/unittests/backup_sa/session/BUILD.gn +++ b/tests/unittests/backup_sa/session/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") import("//foundation/filemanagement/app_file_service/backup.gni") ohos_unittest("b_incremental_session_test") { @@ -20,6 +21,13 @@ ohos_unittest("b_incremental_session_test") { include_dirs = [ "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_notify", + "${path_backup}/utils/include", + "${path_backup}/utils/src", + "${path_backup}/tests/mock/utils_mock/include", + ".", + "session", ] sources = [ @@ -30,17 +38,26 @@ ohos_unittest("b_incremental_session_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", "b_incremental_session_test.cpp", + "service_client_mock.cpp", "service_proxy_mock.cpp", ] deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_stub", "${path_backup}/utils:backup_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + defines = [ "LOG_TAG=\"app_file_service\"", "LOG_DOMAIN=0xD200000", @@ -49,12 +66,23 @@ ohos_unittest("b_incremental_session_test") { ] external_deps = [ + "ability_base:want", + "ability_runtime:ability_connect_callback_stub", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", "c_utils:utils", + "common_event_service:cesfwk_innerkits", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", + "jsoncpp:jsoncpp", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", ] use_exceptions = true diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index e074a00e0..b04fe944b 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -20,6 +20,7 @@ #include "b_incremental_restore_session.h" #include "b_incremental_session_restore_async.h" #include "service_proxy_mock.h" +#include "service_client.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -45,7 +46,7 @@ void IncrementalSessionTest::SetUpTestCase() restoreSession = make_shared(); BIncrementalSessionRestoreAsync::Callbacks callbacks; restoreAsyncSession = make_shared(callbacks); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; } void IncrementalSessionTest::TearDownTestCase() @@ -53,7 +54,7 @@ void IncrementalSessionTest::TearDownTestCase() backupSession = nullptr; restoreSession = nullptr; restoreAsyncSession = nullptr; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; proxy = nullptr; } @@ -70,14 +71,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks); @@ -103,11 +103,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); backupSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; backupSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -132,14 +132,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -162,13 +162,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -191,14 +191,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks); @@ -224,11 +224,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); restoreSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -253,16 +253,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -285,13 +285,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -314,14 +314,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -345,7 +345,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreSession != nullptr); @@ -353,7 +353,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -376,7 +376,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -384,8 +384,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -408,14 +408,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalSessionRestoreAsync::Callbacks callbacks; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Init(callbacks); EXPECT_EQ(err, nullptr); err = restoreAsyncSession->Init(callbacks); @@ -441,11 +441,11 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); restoreAsyncSession->RegisterBackupServiceDied(nullptr); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; restoreAsyncSession->RegisterBackupServiceDied(nullptr); EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr)); @@ -470,16 +470,16 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1400"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap1; vector bundlesToRestore; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -502,14 +502,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1500, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1500"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->PublishFile(fileInfo); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -533,7 +533,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; string bundleName; string fileName; EXPECT_TRUE(restoreAsyncSession != nullptr); @@ -541,7 +541,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->GetFileHandle(bundleName, fileName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -564,7 +564,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; UniqueFd remoteCap; vector bundlesToRestore; vector detailInfos; @@ -572,8 +572,8 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -596,13 +596,13 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1800, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1800"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, Release()).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Release(); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -625,15 +625,15 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1900, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1900"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; vector bundlesToBackup; vector infos; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSessionWithBundleInfos(_, _)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->AppendBundles(bundlesToBackup, infos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -656,7 +656,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2000"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BFileInfo fileInfo; UniqueFd fd; EXPECT_TRUE(restoreSession != nullptr); @@ -664,7 +664,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::e EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); EXPECT_CALL(*proxy, PublishSAIncrementalFile(_, _)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->PublishSAFile(fileInfo, move(fd)); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -687,14 +687,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2100, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2100"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -717,14 +717,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2200, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2200"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -747,14 +747,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2300, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2300"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; std::string bundleName; EXPECT_TRUE(restoreAsyncSession != nullptr); auto err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); - ServiceProxy::serviceProxy_ = proxy; + ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -779,14 +779,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2400, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalBackupSession::Callbacks callbacks; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitIncrementalBackupSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitIncrementalBackupSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = backupSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = backupSession->Init(callbacks, errMsg, errCode); @@ -813,14 +813,14 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2500, testing::e try { std::string errMsg; ErrCode errCode; - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; BIncrementalRestoreSession::Callbacks callbacks; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); - EXPECT_CALL(*proxy, InitRestoreSession(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); - ServiceProxy::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, InitRestoreSessionWithErrMsg(_, _)).WillOnce(Return(-1)).WillOnce(Return(0)); + ServiceClient::serviceProxy_ = proxy; err = restoreSession->Init(callbacks, errMsg, errCode); EXPECT_EQ(err, nullptr); err = restoreSession->Init(callbacks, errMsg, errCode); @@ -845,17 +845,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2600, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2600"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(backupSession != nullptr); auto err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = backupSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { @@ -878,17 +879,18 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2700, testing::e { GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2700"; try { - ServiceProxy::serviceProxy_ = nullptr; + ServiceClient::serviceProxy_ = nullptr; EXPECT_TRUE(restoreSession != nullptr); auto err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - ServiceProxy::serviceProxy_ = proxy; - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(-1))); + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)).WillOnce(Return(-1)); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), -EPERM); - EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos()).WillOnce(Return(UniqueFd(0))); + EXPECT_CALL(*proxy, GetLocalCapabilitiesForBundleInfos(_)) + .WillOnce(DoAll(testing::SetArgReferee<0>(0), Return(0))); err = restoreSession->GetLocalCapabilities(); EXPECT_EQ(err.Get(), 0); } catch (...) { diff --git a/tests/unittests/backup_sa/session/service_client_mock.cpp b/tests/unittests/backup_sa/session/service_client_mock.cpp new file mode 100644 index 000000000..cf075fbd2 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "service_client.h" +#include "iservice.h" +#include "service_proxy.h" +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool ServiceClient::CheckServiceProxy() +{ + serviceProxy_ = ServiceClient::GetInstance(); + bool isNull = false; + if (serviceProxy_ != nullptr) { + isNull = true; + } + return isNull; +} + +sptr ServiceClient::GetServiceProxyPointer() +{ + return serviceProxy_; +} + +sptr ServiceClient::GetInstance() +{ + return serviceProxy_; +} + +void ServiceClient::InvaildInstance() {} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const OHOS::sptr &remoteObject) +{ +} + +void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} +} \ No newline at end of file diff --git a/tests/unittests/backup_sa/session/service_client_mock.h b/tests/unittests/backup_sa/session/service_client_mock.h new file mode 100644 index 000000000..6aa6d9884 --- /dev/null +++ b/tests/unittests/backup_sa/session/service_client_mock.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_UNITTEST_SERVICE_CLIENT_MOCK_H +#define TEST_UNITTEST_SERVICE_CLIENT_MOCK_H + +#include + +#include "service_client.h" + +namespace OHOS::FileManagement::Backup { +class ServiceClientMock : public ServiceClient { + +public: + MOCK_METHOD0(GetServiceProxyPointer, bool()); + MOCK_METHOD0(GetInstance, sptr()); + MOCK_METHOD0(InvaildInstance, sptr()); + MOCK_METHOD0(InvaildInstance, void()); + MOCK_METHOD0(Start, ErrCode()); +}; +} // End of namespace OHOS::FileManagement::Backup +#endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 41cce333d..765206376 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -16,225 +16,223 @@ #include "service_proxy.h" #include "b_error/b_error.h" - +#include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { using namespace std; -int32_t ServiceProxy::InitRestoreSession(sptr remote) +ErrCode ServiceProxy::AppFileReady(const std::string &fileName, int fd, int32_t appFileReadyErrCode) { - return 0; -} - -int32_t ServiceProxy::InitRestoreSession(sptr remote, std::string &errMsg) -{ - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote) +ErrCode ServiceProxy::AppDone(int32_t appDoneErrCode) { - return 0; + return BError(BError::Codes::OK); } -int32_t ServiceProxy::InitBackupSession(sptr remote, std::string &errMsg) -{ - return 0; -} - -ErrCode ServiceProxy::Start() +ErrCode ServiceProxy::RefreshDataSize(int64_t totalDataSize) { return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilities() +ErrCode ServiceProxy::AppIncrementalDone(int32_t appIncrementalDoneErrCode) { - return UniqueFd(-1); + return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppDone(ErrCode errCode) +ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode) +int32_t ServiceProxy::InitRestoreSession(const sptr &remote) { - return BError(BError::Codes::OK); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) +int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { - return BError(BError::Codes::OK); + return 0; } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode ServiceProxy::Start() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &detailInfos) +ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Finish() +ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &cancelResult) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Release() +ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(std::string bundleName, int32_t &result) +ErrCode ServiceProxy::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario scenario) { - result = BError(BError::Codes::OK); return BError(BError::Codes::OK); } -UniqueFd ServiceProxy::GetLocalCapabilitiesIncremental(const vector &bundleNames) +int32_t ServiceProxy::InitBackupSession(const sptr &remote) { - return UniqueFd(-1); + if (!GetMockInitBackupOrRestoreSession()) { + return 0; + } + return 1; } -ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() +ErrCode ServiceProxy::ServiceResultReport(const std::string &restoreRetInfo, + BackupRestoreScenario scenario, + int32_t serviceResultReportErrCode) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote) +ErrCode ServiceProxy::GetLocalCapabilities(int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::InitIncrementalBackupSession(sptr remote, std::string &errMsg) +ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup) +ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const vector &bundlesToBackup, - const std::vector &infos) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo) +ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) +ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) +ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &detailInfos) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) +ErrCode ServiceProxy::Finish() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) +ErrCode ServiceProxy::Release() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr &remote) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) +ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) +ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::RefreshDataSize(int64_t totalsize) +ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) { return BError(BError::Codes::OK); } -ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) +ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) { return BError(BError::Codes::OK); } -sptr ServiceProxy::GetServiceProxyPointer() +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) { - return serviceProxy_; + return BError(BError::Codes::OK); } -sptr ServiceProxy::GetInstance() +ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) { - return serviceProxy_; + return BError(BError::Codes::OK); } -void ServiceProxy::InvaildInstance() {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t, const OHOS::sptr&) {} - -void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) {} - -UniqueFd ServiceProxy::GetLocalCapabilitiesForBundleInfos() +ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int &fd) { - return UniqueFd(-1); + fd = -1; + return fd; } -ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, vector bundleNameList) +ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector &bundleNameList) { return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index b734c8dac..1b3846170 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -26,48 +26,49 @@ public: explicit ServiceProxyMock(const sptr &impl) : ServiceProxy(impl) {} ~ServiceProxyMock() override {} public: - MOCK_METHOD1(InitRestoreSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitRestoreSession, ErrCode(sptr remote, std::string &errMsg)); - MOCK_METHOD1(InitBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD1(InitRestoreSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitRestoreSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); + MOCK_METHOD1(InitBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitBackupSessionWithErrMsg, ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD0(Start, ErrCode()); MOCK_METHOD0(AsObject, sptr()); - MOCK_METHOD0(GetLocalCapabilities, UniqueFd()); - MOCK_METHOD0(GetLocalCapabilitiesForBundleInfos, UniqueFd()); + MOCK_METHOD1(GetLocalCapabilitiesForBundleInfos, ErrCode(int32_t &)); MOCK_METHOD1(PublishFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd)); - MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, UniqueFd fd, int32_t errCode)); - MOCK_METHOD1(AppDone, ErrCode(ErrCode errCode)); - MOCK_METHOD3(ServiceResultReport, ErrCode(const std::string restoreRetInfo, - BackupRestoreScenario scenario, ErrCode errCode)); + MOCK_METHOD2(AppFileReady, ErrCode(const std::string &fileName, int fd)); + MOCK_METHOD3(AppFileReady, ErrCode(const std::string &fileName, int fd, int32_t errCode)); + MOCK_METHOD1(AppDone, ErrCode(int32_t errCode)); + MOCK_METHOD2(GetFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD5(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId)); - MOCK_METHOD4(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, - RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); - MOCK_METHOD2(Cancel, ErrCode(std::string bundleName, int32_t &result)); - MOCK_METHOD1(GetLocalCapabilitiesIncremental, UniqueFd(const std::vector &bundleNames)); - MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(sptr remote)); - MOCK_METHOD2(InitIncrementalBackupSession, ErrCode(sptr remote, std::string &errMsg)); + MOCK_METHOD2(Cancel, ErrCode(const std::string &bundleName, int32_t &result)); + MOCK_METHOD2(GetLocalCapabilitiesIncremental, ErrCode(const std::vector &bundleNames, int &fd)); + MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(const sptr &remote)); + MOCK_METHOD2(InitIncrementalBackupSessionWithErrMsg, + ErrCode(const sptr &remote, std::string &errMsg)); MOCK_METHOD1(AppendBundlesIncrementalBackupSession, ErrCode(const std::vector &bundlesToBackup)); - MOCK_METHOD2(AppendBundlesIncrementalBackupSession, - ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); + MOCK_METHOD2(AppendBundlesIncrementalBackupSessionWithBundleInfos, + ErrCode(const std::vector &bundlesToBackup, const std::vector &infos)); MOCK_METHOD1(PublishIncrementalFile, ErrCode(const BFileInfo &fileInfo)); - MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); - MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd)); - MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, - int32_t errCode)); - MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); + MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, int fd)); + MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd)); + MOCK_METHOD4(AppIncrementalFileReady, + ErrCode(const std::string &fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD1(AppIncrementalDone, ErrCode(int32_t errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); - MOCK_METHOD2(GetBackupInfo, ErrCode(BundleName &bundleName, std::string &result)); - MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); + MOCK_METHOD2(GetBackupInfo, ErrCode(const BundleName &bundleName, std::string &result)); + MOCK_METHOD3(UpdateTimer, ErrCode(const BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD0(GetAppLocalListAndDoIncrementalBackup, ErrCode()); MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); - MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, std::vector bundleNameList)); + MOCK_METHOD5( + AppendBundlesRestoreSessionRestoreDataWaitSend, + ErrCode(int32_t, const std::vector &, const std::vector &, int32_t, int32_t)); + MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + ErrCode(int32_t, const std::vector &, int32_t, int32_t)); + MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 0a0c1d50a..55f0d5f49 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("backup_tool_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_data.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_backup_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", "${path_backup}/tools/backup_tool/src/tools_op_backup.cpp", @@ -50,6 +49,7 @@ ohos_unittest("backup_tool_test") { include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", @@ -91,7 +91,6 @@ ohos_unittest("backup_tool_restore_test") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.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}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", @@ -108,10 +107,12 @@ ohos_unittest("backup_tool_restore_test") { "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/tools/backup_tool/include", "${path_backup}/tools/backup_tool/src", + "${target_gen_dir}/interfaces/inner_api/native/backup_kit_inner", ] include_dirs += backup_mock_utils_include deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", "${path_googletest}:gmock_main", diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp index 1d3dc5078..13e96ddd2 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp @@ -101,6 +101,7 @@ HWTEST_F(ToolsOpCheckSaTest, SUB_backup_tools_op_check_sa_0200, testing::ext::Te } GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); + CheckSaRegister(); if (matchedOp != opeartions.end()) { ret = matchedOp->Execute(mapArgToVal); EXPECT_NE(ret, 0); diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp index cc797c548..51acb7436 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp @@ -27,7 +27,7 @@ #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "tools_op_restore_async.cpp" namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp index 6244fabf5..de6e6ba91 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp @@ -28,7 +28,7 @@ #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_file_info.h" +#include "backup_file_info.h" #include "tools_op_restore.cpp" namespace OHOS::FileManagement::Backup { diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 745fe725e..d2b6a18d3 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -39,7 +39,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_backup.h" @@ -240,12 +240,13 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; } - BFile::SendFile(fdLocal, proxy->GetLocalCapabilities()); + int fd = -1; + BFile::SendFile(fdLocal, proxy->GetLocalCapabilities(fd)); auto ctx = make_shared(); ctx->session_ = BSessionBackup::Init( diff --git a/tools/backup_tool/src/tools_op_check_sa.cpp b/tools/backup_tool/src/tools_op_check_sa.cpp index 5e781f316..56535dea5 100644 --- a/tools/backup_tool/src/tools_op_check_sa.cpp +++ b/tools/backup_tool/src/tools_op_check_sa.cpp @@ -17,7 +17,7 @@ #include #include "errors.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" #include "tools_op_check_sa.h" @@ -31,7 +31,7 @@ static string GenHelpMsg() static int Exec(map> &mapArgToVal) { - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EFAULT; diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 41a97190c..3e18b7ba7 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -42,7 +42,7 @@ #include "b_resources/b_constants.h" #include "backup_kit_inner.h" #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" -#include "service_proxy.h" +#include "service_client.h" #include "tools_op.h" namespace OHOS::FileManagement::Backup { @@ -273,7 +273,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, fprintf(stderr, "Failed to open file. error: %d %s\n", errno, strerror(errno)); return -EPERM; } - auto proxy = ServiceProxy::GetInstance(); + auto proxy = ServiceClient::GetInstance(); if (!proxy) { fprintf(stderr, "Get an empty backup sa proxy\n"); return -EPERM; @@ -286,11 +286,13 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, ctx->lastIncrementalData.push_back(data); num++; } - UniqueFd fd = proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData); + int fdVal = -1; + proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); + UniqueFd fd(static_cast(fdVal)); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { - BFile::SendFile(fdLocal, fd); + BFile::SendFile(fdLocal, std::move(fd)); } return 0; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 95b58a5ad..0acecd72e 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -84,7 +84,10 @@ ohos_shared_library("backup_utils") { "src/b_utils/b_time.cpp", ] - configs = [ ":utils_private_config" ] + configs = [ + ":utils_private_config", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:public_idl_config", + ] public_configs = [ ":utils_public_config" ] external_deps = [ @@ -106,9 +109,10 @@ ohos_shared_library("backup_utils") { "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/utils/include", ] - + print("utils_public_config include_dirs:", configs) deps = [ ":backup_cxx_cppdeps", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner_ipc_type", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_jsoncpp}:jsoncpp", "//third_party/openssl:libcrypto_shared", diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 16d4a17f4..a90a34b49 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -17,7 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_B_RADAR_H #include #include -#include "i_service_reverse.h" +#include "service_reverse_inner_type.h" namespace OHOS::FileManagement::Backup { enum class BizStageBackup : int32_t { @@ -119,7 +119,7 @@ public: enum BizStageBackup bizStage, int32_t resultCode); void RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId, enum BizStageRestore bizStage, int32_t resultCode); - void RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, + void RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverseType::Scenario scenario, int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode); private: AppRadar() = default; diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 1c7f7ac84..8ab04e149 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -23,7 +23,6 @@ #include "b_resources/b_constants.h" #include "b_utils/b_time.h" #include "hisysevent.h" -#include "i_service_reverse.h" namespace OHOS::FileManagement::Backup { int32_t AppRadar::GetUserId() @@ -49,7 +48,7 @@ void AppRadar::RecordDefaultFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::UNDEFINED), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::UNDEFINED), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, @@ -70,7 +69,7 @@ void AppRadar::RecordBackupFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::BACKUP), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::BACKUP), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, @@ -91,14 +90,14 @@ void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t "PID", getpid(), "FUNC", func, "TIME", TimeUtils::GetCurrentTime(), - "BIZ_SCENE", static_cast(IServiceReverse::Scenario::RESTORE), + "BIZ_SCENE", static_cast(IServiceReverseType::Scenario::RESTORE), "BIZ_STAGE", static_cast(bizStage), "EXEC_STATUS", info.status, "RESULT_CODE", resultCode, "RESULT_INFO", ss.str()); } -void AppRadar::RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, +void AppRadar::RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverseType::Scenario scenario, int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode) { std::stringstream ss; -- Gitee From ac32a10aac6bfc9c8ddca38c998849573eaa7e22 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 20 Feb 2025 15:07:09 +0800 Subject: [PATCH 3/5] code check Signed-off-by: BrainL Change-Id: I821ce26b9e2f35f771a10b66d187c0aa1a1cee9c --- .../src/b_incremental_backup_session.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 2 +- .../backup_kit_inner/src/b_session_backup.cpp | 2 +- .../src/b_session_restore.cpp | 2 +- .../backup_kit_inner/src/service_client.cpp | 3 - services/backup_sa/src/module_ipc/service.cpp | 12 +-- .../src/module_ipc/service_incremental.cpp | 10 +-- .../backup_sa/src/module_ipc/sub_service.cpp | 2 +- .../backupservicestubbranch_fuzzer.cpp | 4 +- .../backupservicestubbranch_fuzzer/service.h | 87 ------------------- .../module_client/service_client_test.cpp | 2 +- .../module_ipc/service_reverse_proxy_test.cpp | 2 +- .../src/tools_op_incremental_backup.cpp | 2 +- 13 files changed, 22 insertions(+), 110 deletions(-) delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index a9d589c33..e46574992 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -130,7 +130,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 1bfe24faf..3d6337145 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -113,7 +113,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index 9185153c5..963a3cd57 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -140,7 +140,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 1dbfa2040..88f9b5b5a 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -81,7 +81,7 @@ UniqueFd BSessionRestore::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp index 5451bd047..31e9cdadd 100644 --- a/frameworks/native/backup_kit_inner/src/service_client.cpp +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -106,8 +106,6 @@ void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t return; } unique_lock lock(proxyMutex_); - std::string remoteDescriptor = Str16ToStr8(remoteObject->GetInterfaceDescriptor()); - HILOGE("GetInterfaceDescriptor result:%{public}s", remoteDescriptor.c_str()); serviceProxy_ = iface_cast(remoteObject); if (serviceProxy_ == nullptr) { HILOGE("serviceProxy_ is nullptr"); @@ -124,7 +122,6 @@ void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t auto callback = [](const wptr &obj) { ServiceClient::InvaildInstance(); - HILOGE("Backup service died"); }; sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 20d4a6f1b..38030bcc5 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -667,8 +667,8 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitSend"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); - UniqueFd fdUnique(static_cast(fd)); - RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); } @@ -775,8 +775,8 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitReady"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); - UniqueFd fdUnique(static_cast(fd)); - RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_READDY; + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); } @@ -1145,7 +1145,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) int32_t errCode = 0; int32_t fdCode = 0; proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); - UniqueFd fd(static_cast(fdCode)); + UniqueFd fd(fdCode); if (errCode != ERR_OK) { AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), @@ -1218,7 +1218,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) int32_t errCode = 0; int fdCode = 0; proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); - UniqueFd fd(static_cast(fdCode)); + UniqueFd fd(fdCode); session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index dab1cc3fa..c8feaf38d 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -543,7 +543,7 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) { HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); - UniqueFd uniquedParameter(static_cast(fd)); + UniqueFd uniquedParameter(fd); return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); } @@ -746,8 +746,8 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s } UniqueFdGroup fdGroup; proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); - UniqueFd fd(static_cast(fdGroup.fd)); - UniqueFd reportFd(static_cast(fdGroup.reportFd)); + UniqueFd fd(fdGroup.fd); + UniqueFd reportFd(fdGroup.reportFd); auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (err != ERR_OK) { AppRadar::Info info (bundleName, "", ""); @@ -807,8 +807,8 @@ bool Service::IncrementalBackup(const string &bundleName) for (const auto &fileName : fileNameVec) { UniqueFdGroup fdGroup; proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); - UniqueFd fd(static_cast(fdGroup.fd)); - UniqueFd reportFd(static_cast(fdGroup.reportFd)); + UniqueFd fd(fdGroup.fd); + UniqueFd reportFd(fdGroup.reportFd); ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (ret) { HILOGE("Failed to send file handle %{public}s", GetAnonyString(fileName).c_str()); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 1b125b3ea..8fadb4e0b 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -246,7 +246,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) { HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); - UniqueFd fdUnique(static_cast(fd)); + UniqueFd fdUnique(fd); if (fd < 0) { HILOGE("Error fd, fd = %{public}d", fd); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index d94bd33ef..81dfe67fe 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -193,6 +193,8 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } +constexpr int32_t SERVICE_ID = 5203; + template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -225,7 +227,7 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); if (service == nullptr) { return 0; } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h deleted file mode 100644 index 6d074c8e3..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_H - -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "iremote_stub.h" -#include "service_stub.h" - -namespace OHOS::FileManagement::Backup { -class Service : public ServiceStub { -public: - ErrCode InitRestoreSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode Start() { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() { return UniqueFd(-1); } - UniqueFd GetLocalCapabilitiesForBundleInfos() { return UniqueFd(-1); } - ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string&, UniqueFd, int32_t) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string, - BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesDetailsBackupSession(const std::vector&, - const std::vector&) { return BError(BError::Codes::OK); } - ErrCode Finish() { return BError(BError::Codes::OK); } - ErrCode Release() { return BError(BError::Codes::OK); } - ErrCode Cancel(std::string, int32_t&) { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector&) { return UniqueFd(-1); } - ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo&, UniqueFd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string&, UniqueFd, UniqueFd, int32_t) - { return BError(BError::Codes::OK); } - ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode GetBackupInfo(BundleName&, std::string&) { return BError(BError::Codes::OK); } - ErrCode UpdateTimer(BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode UpdateSendRate(std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } - - ErrCode SAResultReport(const std::string, const std::string, - const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool, std::vector) { return BError(BError::Codes::OK); } -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 9352d63b6..edb1012b7 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -191,7 +191,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize EXPECT_EQ(fileName, ""); booleanValue = true; ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret,BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); booleanValue = false; ret = proxy->StartExtTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 63d09d7d7..0a62f37c4 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -1925,7 +1925,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; EXPECT_TRUE(proxy_ != nullptr); - int32_t code=0; + int32_t code = 0; proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 3e18b7ba7..3a193166e 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -288,7 +288,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, } int fdVal = -1; proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); - UniqueFd fd(static_cast(fdVal)); + UniqueFd fd(fdVal); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { -- Gitee From df16f02d45ba2381f2e24fbc976598a71e573675 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 20 Feb 2025 19:25:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86IDL=E5=8C=96=20format=20check.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../src/b_incremental_backup_session.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 2 +- .../backup_kit_inner/src/b_session_backup.cpp | 2 +- .../src/b_session_restore.cpp | 2 +- .../backup_kit_inner/src/service_client.cpp | 3 - services/backup_sa/src/module_ipc/service.cpp | 12 +-- .../src/module_ipc/service_incremental.cpp | 10 +-- .../backup_sa/src/module_ipc/sub_service.cpp | 2 +- .../backupservicestubbranch_fuzzer.cpp | 4 +- .../backupservicestubbranch_fuzzer/service.h | 87 ------------------- .../module_client/service_client_test.cpp | 2 +- .../module_ipc/service_reverse_proxy_test.cpp | 2 +- .../src/tools_op_incremental_backup.cpp | 2 +- 13 files changed, 22 insertions(+), 110 deletions(-) delete mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index a9d589c33..e46574992 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -130,7 +130,7 @@ UniqueFd BIncrementalBackupSession::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 1bfe24faf..3d6337145 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -113,7 +113,7 @@ UniqueFd BIncrementalRestoreSession::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index 9185153c5..963a3cd57 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -140,7 +140,7 @@ UniqueFd BSessionBackup::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 1dbfa2040..88f9b5b5a 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -81,7 +81,7 @@ UniqueFd BSessionRestore::GetLocalCapabilities() } int fdvalue = -1; proxy->GetLocalCapabilitiesForBundleInfos(fdvalue); - UniqueFd fd(static_cast(fdvalue)); + UniqueFd fd(fdvalue); if (fd < 0) { HILOGE("Failed to get local capabilities for bundleinfos"); return UniqueFd(-EPERM); diff --git a/frameworks/native/backup_kit_inner/src/service_client.cpp b/frameworks/native/backup_kit_inner/src/service_client.cpp index 5451bd047..31e9cdadd 100644 --- a/frameworks/native/backup_kit_inner/src/service_client.cpp +++ b/frameworks/native/backup_kit_inner/src/service_client.cpp @@ -106,8 +106,6 @@ void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t return; } unique_lock lock(proxyMutex_); - std::string remoteDescriptor = Str16ToStr8(remoteObject->GetInterfaceDescriptor()); - HILOGE("GetInterfaceDescriptor result:%{public}s", remoteDescriptor.c_str()); serviceProxy_ = iface_cast(remoteObject); if (serviceProxy_ == nullptr) { HILOGE("serviceProxy_ is nullptr"); @@ -124,7 +122,6 @@ void ServiceClient::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t auto callback = [](const wptr &obj) { ServiceClient::InvaildInstance(); - HILOGE("Backup service died"); }; sptr deathRecipient = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 20d4a6f1b..38030bcc5 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -667,8 +667,8 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitSend"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); - UniqueFd fdUnique(static_cast(fd)); - RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); } @@ -775,8 +775,8 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitReady"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); - UniqueFd fdUnique(static_cast(fd)); - RestoreTypeEnum restoreTypeEnum = RestoreTypeEnum::RESTORE_DATA_READDY; + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); } @@ -1145,7 +1145,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) int32_t errCode = 0; int32_t fdCode = 0; proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); - UniqueFd fd(static_cast(fdCode)); + UniqueFd fd(fdCode); if (errCode != ERR_OK) { AppRadar::Info info(bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), @@ -1218,7 +1218,7 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) int32_t errCode = 0; int fdCode = 0; proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); - UniqueFd fd(static_cast(fdCode)); + UniqueFd fd(fdCode); session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index dab1cc3fa..c8feaf38d 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -543,7 +543,7 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) ErrCode Service::PublishSAIncrementalFile(const BFileInfo& fileInfo, int fd) { HILOGI("Begin PublishSAIncrementalFile, %{public}d", fd); - UniqueFd uniquedParameter(static_cast(fd)); + UniqueFd uniquedParameter(fd); return PublishSAIncrementalFile(fileInfo, std::move(uniquedParameter)); } @@ -746,8 +746,8 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s } UniqueFdGroup fdGroup; proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); - UniqueFd fd(static_cast(fdGroup.fd)); - UniqueFd reportFd(static_cast(fdGroup.reportFd)); + UniqueFd fd(fdGroup.fd); + UniqueFd reportFd(fdGroup.reportFd); auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (err != ERR_OK) { AppRadar::Info info (bundleName, "", ""); @@ -807,8 +807,8 @@ bool Service::IncrementalBackup(const string &bundleName) for (const auto &fileName : fileNameVec) { UniqueFdGroup fdGroup; proxy->GetIncrementalFileHandleWithUniqueFdGroup(fileName, fdGroup); - UniqueFd fd(static_cast(fdGroup.fd)); - UniqueFd reportFd(static_cast(fdGroup.reportFd)); + UniqueFd fd(fdGroup.fd); + UniqueFd reportFd(fdGroup.reportFd); ret = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), fdGroup.errCode); if (ret) { HILOGE("Failed to send file handle %{public}s", GetAnonyString(fileName).c_str()); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 1b125b3ea..8fadb4e0b 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -246,7 +246,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCode) { HILOGI("fileName =%{public}s, fd = %{public}d, errCode = %{public}d", fileName.c_str(), fd, errCode); - UniqueFd fdUnique(static_cast(fd)); + UniqueFd fdUnique(fd); if (fd < 0) { HILOGE("Error fd, fd = %{public}d", fd); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index d94bd33ef..81dfe67fe 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp @@ -193,6 +193,8 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } +constexpr int32_t SERVICE_ID = 5203; + template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -225,7 +227,7 @@ bool OnRemoteRequestFuzzTest(sptr service, const uint8_t *data, size_t /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); if (service == nullptr) { return 0; } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h deleted file mode 100644 index 6d074c8e3..000000000 --- a/test/fuzztest/backupservicestubbranch_fuzzer/service.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H -#define OHOS_FILEMGMT_BACKUP_SERVICE_H - -#include -#include - -#include "b_error/b_error.h" -#include "i_service_reverse.h" -#include "iremote_stub.h" -#include "service_stub.h" - -namespace OHOS::FileManagement::Backup { -class Service : public ServiceStub { -public: - ErrCode InitRestoreSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitRestoreSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode Start() { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilities() { return UniqueFd(-1); } - UniqueFd GetLocalCapabilitiesForBundleInfos() { return UniqueFd(-1); } - ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode AppFileReady(const std::string&, UniqueFd, int32_t) { return BError(BError::Codes::OK); } - ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode ServiceResultReport(const std::string, - BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSession(UniqueFd, - const std::vector&, - RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesDetailsBackupSession(const std::vector&, - const std::vector&) { return BError(BError::Codes::OK); } - ErrCode Finish() { return BError(BError::Codes::OK); } - ErrCode Release() { return BError(BError::Codes::OK); } - ErrCode Cancel(std::string, int32_t&) { return BError(BError::Codes::OK); } - UniqueFd GetLocalCapabilitiesIncremental(const std::vector&) { return UniqueFd(-1); } - ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr) { return BError(BError::Codes::OK); } - ErrCode InitIncrementalBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode AppendBundlesIncrementalBackupSession(const std::vector&, const std::vector&) - { return BError(BError::Codes::OK); } - ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } - ErrCode PublishSAIncrementalFile(const BFileInfo&, UniqueFd) { return BError(BError::Codes::OK); } - ErrCode AppIncrementalFileReady(const std::string&, UniqueFd, UniqueFd, int32_t) - { return BError(BError::Codes::OK); } - ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } - ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } - ErrCode GetBackupInfo(BundleName&, std::string&) { return BError(BError::Codes::OK); } - ErrCode UpdateTimer(BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode UpdateSendRate(std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } - ErrCode ReportAppProcessInfo(const std::string, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } - ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } - - ErrCode SAResultReport(const std::string, const std::string, - const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } - ErrCode GetBackupDataSize(bool, std::vector) { return BError(BError::Codes::OK); } -}; -} // namespace OHOS::FileManagement::Backup - -#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 9352d63b6..edb1012b7 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -191,7 +191,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize EXPECT_EQ(fileName, ""); booleanValue = true; ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret,BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); booleanValue = false; ret = proxy->StartExtTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 63d09d7d7..0a62f37c4 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -1925,7 +1925,7 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); std::string bundleName = "app01"; EXPECT_TRUE(proxy_ != nullptr); - int32_t code=0; + int32_t code = 0; proxy_->RestoreOnResultReport(RESULT_REPORT, bundleName, code); EXPECT_TRUE(true); } catch (...) { diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 3e18b7ba7..3a193166e 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -288,7 +288,7 @@ static int GetLocalCapabilitiesIncremental(shared_ptr ctx, } int fdVal = -1; proxy->GetLocalCapabilitiesIncremental(ctx->lastIncrementalData, fdVal); - UniqueFd fd(static_cast(fdVal)); + UniqueFd fd(fdVal); if (fd < 0) { fprintf(stderr, "error GetLocalCapabilitiesIncremental"); } else { -- Gitee From 352b8f9b690d7c5a08950d48ee968bad34847e20 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 21 Feb 2025 13:58:51 +0800 Subject: [PATCH 5/5] fixed the test. Signed-off-by: BrainL Change-Id: I758711cc51848389dc2ca9b3c6849c35919efb3d --- .../native/backup_ext/src/ext_extension.cpp | 4 +- .../src/b_incremental_restore_session.cpp | 4 +- .../b_incremental_session_restore_async.cpp | 4 +- .../src/b_session_restore.cpp | 4 +- .../src/b_session_restore_async.cpp | 4 +- .../native/backup_kit_inner/IService.idl | 4 +- .../backup_sa/include/module_ipc/service.h | 4 +- services/backup_sa/src/module_ipc/service.cpp | 8 +- .../src/module_ipc/service_incremental.cpp | 2 - .../backupsaappend_fuzzer.cpp | 2 +- .../backup_kit_inner/service_proxy_mock.cpp | 6 +- tests/mock/module_ipc/service_mock.cpp | 4 +- tests/mock/module_ipc/service_stub_mock.cpp | 8 +- .../backup_impl/include/ext_extension_mock.h | 6 +- .../backup_impl/include/i_service_mock.h | 4 +- .../module_client/service_client_test.cpp | 40 +- .../backup_sa/module_client/service_mock.cpp | 5 +- .../backup_sa/module_ipc/service.cpp | 2133 +++++++++++++++++ .../module_ipc/service_incremental_test.cpp | 4 +- .../module_ipc/service_reverse_proxy_test.cpp | 3 +- .../module_ipc/service_stub_test.cpp | 4 +- .../session/b_incremental_session_test.cpp | 8 +- .../backup_sa/session/service_proxy_mock.cpp | 4 +- .../backup_sa/session/service_proxy_mock.h | 4 +- .../backup_tool/tools_op_check_sa_test.cpp | 1 - 25 files changed, 2198 insertions(+), 76 deletions(-) create mode 100644 tests/unittests/backup_sa/module_ipc/service.cpp diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 03a2f4824..4ea643b90 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1962,8 +1962,8 @@ ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) ErrCode BackupExtExtension::GetIncrementalBackupFileHandleWithUniqueFdGroup(UniqueFdGroup& fdGroup) { auto [fd, reportFd] = GetIncrementalBackupFileHandle(); - fdGroup.fd = fd.Get(); - fdGroup.reportFd = reportFd.Get(); + fdGroup.fd = fd.Release(); + fdGroup.reportFd = reportFd.Release(); return BError(BError::Codes::OK).GetCode(); } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 3d6337145..751ecc9ca 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -157,7 +157,7 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -181,7 +181,7 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, } int32_t remoteCapInt = remoteCap.Get(); ErrCode res = - proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 9f2aa0e9d..05c0374cd 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -110,7 +110,7 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } int fdCode = remoteCap.Get(); int32_t restoreTypeInt = static_cast(restoreType); - ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fdCode, bundlesToRestore, detailInfos, + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(fdCode, bundlesToRestore, detailInfos, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; @@ -136,7 +136,7 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, int fdCode = remoteCap.Get(); int32_t restoreTypeInt = static_cast(restoreType); ErrCode res = - proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fdCode, bundlesToRestore, restoreTypeInt, userId); + proxy->AppendBundlesRestoreSessionData(fdCode, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 88f9b5b5a..7ff6307a3 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -130,7 +130,7 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, } int32_t remoteCapInt = remoteCap.Get(); ErrCode res = - proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); + proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { @@ -152,7 +152,7 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } int32_t remoteCapInt = remoteCap.Get(); - ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, 0, -1); + ErrCode res = proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, 0, -1); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index 2bbbb4a8b..bd88d90a3 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -110,7 +110,7 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, } int32_t remoteCapInt = remoteCap.Get(); int32_t restoreTypeInt = static_cast(restoreType); - ErrCode res = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(remoteCapInt, bundlesToRestore, detailInfos, + ErrCode res = proxy->AppendBundlesRestoreSessionDataByDetail(remoteCapInt, bundlesToRestore, detailInfos, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; @@ -137,7 +137,7 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, int32_t remoteCapInt = remoteCap.Get(); int32_t restoreTypeInt = static_cast(restoreType); ErrCode res = - proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); + proxy->AppendBundlesRestoreSessionData(remoteCapInt, bundlesToRestore, restoreTypeInt, userId); if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToRestore) { diff --git a/interfaces/inner_api/native/backup_kit_inner/IService.idl b/interfaces/inner_api/native/backup_kit_inner/IService.idl index c6e0a8905..88a882242 100644 --- a/interfaces/inner_api/native/backup_kit_inner/IService.idl +++ b/interfaces/inner_api/native/backup_kit_inner/IService.idl @@ -28,12 +28,12 @@ interface OHOS.FileManagement.Backup.IService{ [ipccode 6] void GetLocalCapabilitiesForBundleInfos([out] FileDescriptor fd); [ipccode 7] void PublishFile([in] BFileInfo fileInfo); [oneway, ipccode 8] void GetFileHandle([in] String bundleName, [in] String fileName); - [ipccode 9] void AppendBundlesRestoreSessionRestoreDataWaitSend([in] FileDescriptor fd, + [ipccode 9] void AppendBundlesRestoreSessionDataByDetail([in] FileDescriptor fd, [in] String[] bundleNames, [in] String[] detailInfos, [in] int restoreType, [in] int userId); - [ipccode 10] void AppendBundlesRestoreSessionRestoreDataWaitReady([in] FileDescriptor fd, + [ipccode 10] void AppendBundlesRestoreSessionData([in] FileDescriptor fd, [in] String[] bundleNames, [in] int restoreType, [in] int userId); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 89e95f355..f16fe7a37 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -68,13 +68,13 @@ public: BackupRestoreScenario sennario, ErrCode errCode) override; ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; - ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend( + ErrCode AppendBundlesRestoreSessionDataByDetail( int fd, const std::vector& bundleNames, const std::vector& detailInfos, int32_t restoreType, int32_t userId) override; - ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady( + ErrCode AppendBundlesRestoreSessionData( int fd, const std::vector& bundleNames, int32_t restoreType, diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 38030bcc5..f85793489 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -658,14 +658,14 @@ void Service::HandleExceptionOnAppendBundles(sptr session, } } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitSend"); + HILOGI("Begin AppendBundlesRestoreSessionDataByDetail"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); UniqueFd fdUnique(fd); RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); @@ -767,13 +767,13 @@ void Service::SetCurrentSessProperties(std::vector } HILOGI("End"); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode Service::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Begin AppendBundlesRestoreSessionRestoreDataWaitReady"); + HILOGI("Begin AppendBundlesRestoreSessionData"); HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); UniqueFd fdUnique(fd); RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index c8feaf38d..4267e511f 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -189,7 +189,6 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector ptr) { - HILOGI("Begin StartGetFdTask bundleName = %{public}s", bundleName.c_str()); auto thisPtr = ptr.promote(); if (!thisPtr) { return; @@ -230,7 +229,6 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) .append(to_string(lastTime)); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { - HILOGD("fdLocal open fail, error = %{public}d", errno); throw BError(BError::Codes::SA_INVAL_ARG, "open local Manifest file failed"); } UniqueFd lastManifestFd(session->GetIncrementalManifestFd(bundleName)); diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp index 6d94b527d..73826f873 100644 --- a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -219,7 +219,7 @@ bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) MessageOption option; sptr service(new Service(SERVICE_ID)); - service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND), + service->OnRemoteRequest(static_cast(IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA), datas, reply, option); service = nullptr; return true; diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index d27050da3..f28d93aa2 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -73,7 +73,7 @@ ErrCode ServiceProxy::GetLocalCapabilities(int &fd) TestManager tm("ServiceProxyMock_GetFd_0100"); string filePath = tm.GetRootDirCurTest().append("tmp"); UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); - fd = fd_OpenData.Get(); + fd = fd_OpenData.Release(); return BError(BError::Codes::OK); } @@ -103,7 +103,7 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -112,7 +112,7 @@ ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 740e6b30c..8366cde48 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -49,7 +49,7 @@ ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &rever return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -58,7 +58,7 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode Service::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 07b4d4695..6fdea5bf4 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -102,7 +102,7 @@ int32_t ServiceStub::OnRemoteRequest( } return ERR_NONE; } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_SEND: { + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA_BY_DETAIL: { int fd = data.ReadFileDescriptor(); std::vector bundleNames; int32_t bundleNamesSize = data.ReadInt32(); @@ -125,13 +125,13 @@ int32_t ServiceStub::OnRemoteRequest( int32_t restoreType = data.ReadInt32(); int32_t userId = data.ReadInt32(); ErrCode errCode = - AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userId); + AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userId); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_RESTORE_DATA_WAIT_READY: { + case IServiceIpcCode::COMMAND_APPEND_BUNDLES_RESTORE_SESSION_DATA: { int fd = data.ReadFileDescriptor(); std::vector bundleNames; int32_t bundleNamesSize = data.ReadInt32(); @@ -144,7 +144,7 @@ int32_t ServiceStub::OnRemoteRequest( } int32_t restoreType = data.ReadInt32(); int32_t userId = data.ReadInt32(); - ErrCode errCode = AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userId); + ErrCode errCode = AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userId); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } 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 778d91488..38cae764d 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 @@ -55,9 +55,9 @@ public: ErrCode GetFileHandleWithUniqueFd(const std::string &fileName, int32_t &getFileHandleErrCode, int &fd) override { - UniqueFd f = GetFileHandle(fileName, getFileHandleErrCode); - fd = f.Get(); - return getFileHandleErrCode; + UniqueFd fdResult = GetFileHandle(fileName, getFileHandleErrCode); + fd = fdResult.Release(); + return ERR_OK; }; UniqueFd GetFileHandle(const std::string &fileName, int32_t &errCode) diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index a3890ba0a..c96ad2a6e 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -267,7 +267,7 @@ public: return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, + ErrCode AppendBundlesRestoreSessionRestoreDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -276,7 +276,7 @@ public: return BError(BError::Codes::OK); } - ErrCode AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, + ErrCode AppendBundlesRestoreSession(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) 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 edb1012b7..dc1c5119a 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -148,12 +148,10 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize EXPECT_NE(proxy, nullptr); int fd = -1; ErrCode ret = proxy->GetLocalCapabilities(fd); - EXPECT_NE(ret, BError(BError::Codes::OK)); - EXPECT_NE(fd, BError(BError::Codes::OK)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); fd = -2; ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); - EXPECT_NE(ret, BError(BError::Codes::OK)); - EXPECT_NE(fd, 1); + EXPECT_EQ(ret, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; } @@ -237,7 +235,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize bundleName = "test"; ret = proxy->UpdateSendRate(bundleName, 10, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); EXPECT_TRUE(isExt); bundleName = ""; ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); @@ -247,7 +245,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); bundleName = "test"; ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); fileName = ""; ret = proxy->AppFileReady(fileName, 0, 0); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); @@ -256,7 +254,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); fileName = "name"; ret = proxy->AppFileReady(fileName, -1, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppFileReady(fileName, 0, 0); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); bundleName = ""; @@ -297,10 +295,10 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); stringVal = ""; ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); stringVal = ""; ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; } @@ -312,19 +310,13 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize EXPECT_NE(proxy, nullptr); BFileInfo *fileInfo = nullptr; BFileInfo bf {bundleName, "", 0}; + fileInfo = &bf; ErrCode ret = proxy->PublishFile(*fileInfo); EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->PublishIncrementalFile(*fileInfo); EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); EXPECT_NE(ret, BError(BError::Codes::OK)); - fileInfo = &bf; - ret = proxy->PublishFile(*fileInfo); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->PublishIncrementalFile(*fileInfo); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; } @@ -340,9 +332,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize std::vector detailInfos; std::vector bundlesToBackup; ErrCode ret = - proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); @@ -351,9 +343,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); bundleNames.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); @@ -362,9 +354,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); detailInfos.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); @@ -372,9 +364,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); restoreType = 1; userid = 1; - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitSend(fd, bundleNames, detailInfos, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesRestoreSessionRestoreDataWaitReady(fd, bundleNames, restoreType, userid); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); diff --git a/tests/unittests/backup_sa/module_client/service_mock.cpp b/tests/unittests/backup_sa/module_client/service_mock.cpp index 28ba6a6f6..cf8b3cab0 100644 --- a/tests/unittests/backup_sa/module_client/service_mock.cpp +++ b/tests/unittests/backup_sa/module_client/service_mock.cpp @@ -58,7 +58,7 @@ ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &rever return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -77,7 +77,7 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode Service::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) @@ -315,6 +315,7 @@ ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) { + fd = 1; return BError(BError::Codes::OK); } diff --git a/tests/unittests/backup_sa/module_ipc/service.cpp b/tests/unittests/backup_sa/module_ipc/service.cpp new file mode 100644 index 000000000..f85793489 --- /dev/null +++ b/tests/unittests/backup_sa/module_ipc/service.cpp @@ -0,0 +1,2133 @@ +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * 注意: + * - 注意点1:本文件原则上只处理与IPC无关的业务逻辑 + * - 注意点2:This document, in principle, captures all exceptions. + * Prevent exceptions from spreading to insecure modules. + */ +#include "module_ipc/service.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "ability_manager_client.h" +#include "access_token.h" +#include "accesstoken_kit.h" +#include "b_anony/b_anony.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "backup_file_info.h" +#include "b_hiaudit/hi_audit.h" +#include "b_json/b_json_cached_entity.h" +#include "b_jsonutil/b_jsonutil.h" +#include "b_ohos/startup/backup_para.h" +#include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "b_sa/b_sa_utils.h" +#include "b_utils/b_time.h" +#include "bundle_mgr_client.h" +#include "filemgmt_libhilog.h" +#include "hisysevent.h" +#include "hitrace_meter.h" +#include "ipc_skeleton.h" +#include "service_reverse_inner_type.h" +#include "tokenid_kit.h" +#include "module_app_gallery/app_gallery_dispose_proxy.h" +#include "module_external/bms_adapter.h" +#include "module_external/sms_adapter.h" +#include "module_ipc/svc_backup_connection.h" +#include "module_ipc/svc_restore_deps_manager.h" +#include "module_notify/notify_work_service.h" +#include "parameter.h" +#include "parameters.h" +#include "system_ability_definition.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, false); + +namespace { +constexpr int32_t DEBUG_ID = 100; +constexpr int32_t INDEX = 3; +constexpr int32_t MS_1000 = 1000; +const static string BROADCAST_TYPE = "broadcast"; +const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; +const static string UNICAST_TYPE = "unicast"; +const int32_t CONNECT_WAIT_TIME_S = 15; +const std::string BACKUPSERVICE_WORK_STATUS_KEY = "persist.backupservice.workstatus"; +const std::string BACKUPSERVICE_WORK_STATUS_ON = "true"; +const std::string BACKUPSERVICE_WORK_STATUS_OFF = "false"; +const std::string BACKUP_PERMISSION = "ohos.permission.BACKUP"; +const int32_t MAX_TRY_CLEAR_DISPOSE_NUM = 3; +} // namespace + +/* Shell/Xts user id equal to 0/1, we need set default 100 */ +int32_t Service::GetUserIdDefault() +{ + auto [isDebug, debugId] = BackupPara().GetBackupDebugOverrideAccount(); + if (isDebug && debugId > DEBUG_ID) { + return debugId; + } + auto multiuser = BMultiuser::ParseUid(IPCSkeleton::GetCallingUid()); + HILOGI("GetUserIdDefault userId=%{public}d.", multiuser.userId); + if ((multiuser.userId == BConstants::SYSTEM_UID) || (multiuser.userId == BConstants::XTS_UID)) { + return BConstants::DEFAULT_USER_ID; + } + return multiuser.userId; +} + +void Service::OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) +{ + std::stringstream ss; + ss << "failedBundles:{"; + for (const auto &bundleName : bundleNameList) { + ss << bundleName << ", "; + } + ss << "}"; + AppRadar::Info info("", "", ss.str()); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "Service::OnStart", GetUserIdDefault(), + static_cast(stage), ERR_OK); +} + +void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ + if (errCode == ERR_OK || errCode == BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()) { + return; + } + if (!IsReportBundleExecFail(bundleName)) { + return; + } + UpdateBundleRadarReport(bundleName); + BundleTaskInfo taskInfo; + taskInfo.reportTime = TimeUtils::GetCurrentTime(); + taskInfo.errCode = errCode; + UpdateFailedBundles(bundleName, taskInfo); + AppRadar::Info info(bundleName, "", ""); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } +} + +void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ + if (errCode == ERR_OK) { + successBundlesNum_++; + return; + } + if (!IsReportBundleExecFail(bundleName)) { + return; + } + if (session_->GetTimeoutValue(bundleName) == 0) { + errCode = BError::BackupErrorCode::E_FORCE_TIMEOUT; + } + UpdateBundleRadarReport(bundleName); + BundleTaskInfo taskInfo; + taskInfo.reportTime = TimeUtils::GetCurrentTime(); + taskInfo.errCode = errCode; + UpdateFailedBundles(bundleName, taskInfo); + AppRadar::Info info(bundleName, "", ""); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleEndRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_EXECU_FAIL, errCode); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleEndRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_EXECU_FAIL, errCode); + } +} + +void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ + if (errCode == ERR_OK) { + return; + } + if (!IsReportFileReadyFail(bundleName)) { + return; + } + std::string fileNameReport = std::string("fileName:\"") + GetAnonyPath(fileName) + "\""; + AppRadar::Info info(bundleName, "", fileNameReport); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::FileReadyRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::FileReadyRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_DO_BACKUP, errCode); + } +} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ + if (!IsReportBundleExecFail(bundleName)) { + return; + } + UpdateBundleRadarReport(bundleName); + std::stringstream ss; + ss << "errCode:" << errCode; + AppRadar::Info info(bundleName, "", ss.str()); + if (scenario == IServiceReverseType::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::ExtensionConnectFailRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_CONNECT_EXTENSION_FAIL, + BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::ExtensionConnectFailRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_CONNECT_EXTENSION_FAIL, + BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); + } +} + +void Service::OnStart() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("SA OnStart Begin."); + std::vector bundleNameList; + if (disposal_ != nullptr) { + bundleNameList = disposal_->GetBundleNameFromConfigFile(); + HILOGI("disposal_ !=null"); + } else { + HILOGI("disposal_ ==null"); + } + std::vector residualBundleNameList; + if (clearRecorder_ != nullptr) { + residualBundleNameList = clearRecorder_->GetAllClearBundleRecords(); + } + if (!bundleNameList.empty() || !residualBundleNameList.empty()) { + HILOGI("!bundleNameList.empty() || !residualBundleNameList.empty() !=null"); + if (!bundleNameList.empty()) { + OnStartResRadarReport(bundleNameList, static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + HILOGI("bundleNameList !=null"); + } + if (!residualBundleNameList.empty()) { + OnStartResRadarReport(residualBundleNameList, + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + HILOGI("residualBundleNameList !=null"); + } + SetOccupySession(true); + session_->Active( + { + .clientToken = IPCSkeleton::GetCallingTokenID(), + .scenario = IServiceReverseType::Scenario::CLEAN, + .clientProxy = nullptr, + .userId = GetUserIdDefault(), + .callerName = "BackupSA", + .activeTime = TimeUtils::GetCurrentTime(), + }, + isOccupyingSession_.load()); + HILOGE("SA OnStart, cleaning up backup data"); + } + bool res = SystemAbility::Publish(sptr(this)); + if (sched_ != nullptr) { + sched_->StartTimer(); + } + ClearDisposalOnSaStart(); + auto ret = AppendBundlesClearSession(residualBundleNameList); + if (isOccupyingSession_.load() && ret) { + SetOccupySession(false); + StopAll(nullptr, true); + } + HILOGI("SA OnStart End, res = %{public}d", res); +} + +void Service::SetOccupySession(bool isOccupyingSession) +{ + isOccupyingSession_.store(isOccupyingSession); +} + +void Service::OnStop() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("SA OnStop Begin."); + int32_t oldMemoryParaSize = BConstants::DEFAULT_VFS_CACHE_PRESSURE; + if (session_ != nullptr) { + oldMemoryParaSize = session_->GetMemParaCurSize(); + } + StorageMgrAdapter::UpdateMemPara(oldMemoryParaSize); + HILOGI("SA OnStop End."); +} + +ErrCode Service::GetLocalCapabilities(int& fd) +{ + UniqueFd fdResult(GetLocalCapabilities()); + fd = fdResult.Release(); + HILOGI("get GetLocalCapabilities value fd=%{public}d", fd); + return BError(BError::Codes::OK); +} + +UniqueFd Service::GetLocalCapabilities() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + /* + Only called by restore app before InitBackupSession, + so there must be set init userId. + */ + HILOGI("Begin"); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("GetLocalCapabilities error, session is empty."); + return UniqueFd(-EPERM); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + ErrCode errCode = VerifyCaller(); + if (errCode != ERR_OK) { + HILOGE("Get local abilities failed, Verify caller failed, errCode:%{public}d", errCode); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return UniqueFd(-EPERM); + } + string path = BConstants::GetSaBundleBackupRootDir(GetUserIdDefault()); + BExcepUltils::VerifyPath(path, false); + CreateDirIfNotExist(path); + UniqueFd fd(open(path.data(), O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR)); + if (fd < 0) { + HILOGE("Failed to open config file = %{public}s, err = %{public}d", GetAnonyPath(path).c_str(), errno); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return UniqueFd(-EPERM); + } + BJsonCachedEntity cachedEntity(std::move(fd)); + + auto cache = cachedEntity.Structuralize(); + std::string backupVersion = BJsonUtil::ParseBackupVersion(); + cache.SetBackupVersion(backupVersion); + cache.SetSystemFullName(GetOSFullName()); + cache.SetDeviceType(GetDeviceType()); + auto bundleInfos = BundleMgrAdapter::GetFullBundleInfos(GetUserIdDefault()); + cache.SetBundleInfos(bundleInfos); + cachedEntity.Persist(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("End"); + return move(cachedEntity.GetFd()); + } catch (const BError &e) { + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGE("GetLocalCapabilities failed, errCode = %{public}d", e.GetCode()); + return UniqueFd(-e.GetCode()); + } catch (...) { + HILOGE("Unexpected exception"); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return UniqueFd(-EPERM); + } +} + +void Service::StopAll(const wptr &obj, bool force) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin Stop session"); + std::lock_guard lock(failedBundlesLock_); + uint32_t fail_cnt = failedBundles_.size(); + uint32_t totalBundles = fail_cnt + successBundlesNum_.load(); + if (totalBundles != 0) { + int32_t result = 0; + if (fail_cnt != 0) { + result = BError::BackupErrorCode::E_TASKFAIL; + } + std::stringstream ss; + ss << "successBundleNum:" << successBundlesNum_ << "," << "failedBundleNum:" << + fail_cnt << "," << "failedBundles:{"; + for (const auto &failBundle : failedBundles_) { + ss << "\"" << failBundle.first << "\":" << "{errCode:" << failBundle.second.errCode << "," + << "reportTime:" << failBundle.second.reportTime << "},"; + } + ss << "}"; + string resultInfo = ss.str(); + AppRadar::StatInfo statInfo("", resultInfo); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + AppRadar::GetInstance().RecordStatisticRes(statInfo, GetUserIdDefault(), scenario, + successBundlesNum_.load(), fail_cnt, result); + } + failedBundles_.clear(); + successBundlesNum_ = 0; + session_->Deactive(obj, force); +} + +void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) +{ + std::string funcPos = "Service::"; + AppRadar::Info resInfo("", "", info); + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK_FAIL, + BError(BError::Codes::SA_REFUSED_ACT).GetCode()); +} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); + int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); + if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { + Security::AccessToken::HapTokenInfo hapTokenInfo; + if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenCaller, hapTokenInfo) != 0) { + PermissionCheckFailRadar("Get hap token info failed", "VerifyCallerAndGetCallerName"); + HILOGE("Verify and get caller name failed, Get hap token info failed"); + return BError(BError::Codes::SA_INVAL_ARG); + } + std::string bundleNameIndexInfo = + BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, hapTokenInfo.instIndex); + ErrCode ret = session_->VerifyBundleName(bundleNameIndexInfo); + if (ret != ERR_OK) { + HILOGE("Verify bundle name failed, bundleNameIndexInfo:%{public}s", bundleNameIndexInfo.c_str()); + return ret; + } + bundleName = bundleNameIndexInfo; + return BError(BError::Codes::OK); + } else { + string str = to_string(tokenCaller); + HILOGE("tokenID = %{private}s", GetAnonyString(str).c_str()); + std::string info = string("Invalid token type").append(to_string(tokenType)).append(string("\"}")); + PermissionCheckFailRadar(info, "VerifyCallerAndGetCallerName"); + HILOGE("Verify and get caller name failed, Invalid token type"); + return BError(BError::Codes::SA_INVAL_ARG); + } +} + +ErrCode Service::VerifyCaller() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); + int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); + ErrCode ret = BError(BError::Codes::OK); + switch (tokenType) { + case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: { /* Update Service */ + if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != + Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HILOGE("Permission denied, token type is token native"); + std::string info = "Permission denied, token type is " + to_string(tokenType); + PermissionCheckFailRadar(info, "VerifyCaller"); + ret = BError(BError::Codes::SA_REFUSED_ACT); + } + break; + } + case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { + if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != + Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HILOGE("Permission denied, token type is token hap"); + std::string info = "Permission denied, token type is " + to_string(tokenType); + PermissionCheckFailRadar(info, "VerifyCaller"); + ret = BError(BError::Codes::SA_REFUSED_ACT); + } + uint64_t fullTokenId = OHOS::IPCSkeleton::GetCallingFullTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + HILOGE("Permission denied, token type is token hap, full tokenId is error"); + std::string info = "Permission denied, token type is " + to_string(tokenType); + PermissionCheckFailRadar(info, "VerifyCaller"); + ret = BError(BError::Codes::SA_REFUSED_ACT); + } + break; + } + case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: + if (IPCSkeleton::GetCallingUid() != BConstants::SYSTEM_UID) { + HILOGE("Permission denied, token type is token shell"); + std::string info = "invalid calling uid"; + PermissionCheckFailRadar(info, "VerifyCaller"); + ret = BError(BError::Codes::SA_REFUSED_ACT); + } + break; + default: + std::string info = "Permission denied, token type is " + to_string(tokenType); + PermissionCheckFailRadar(info, "VerifyCaller"); + HILOGE("Permission denied, token type is default"); + ret = BError(BError::Codes::SA_REFUSED_ACT); + break; + } + return ret; +} + +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + ErrCode ret = session_->VerifyCallerAndScenario(IPCSkeleton::GetCallingTokenID(), scenario); + if (ret != ERR_OK) { + HILOGE("Verify bundle by scenario failed, ret:%{public}d", ret); + return ret; + } + return VerifyCaller(); +} + +ErrCode Service::InitRestoreSession(const sptr &remote) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + ErrCode ret = VerifyCaller(); + if (ret != ERR_OK) { + HILOGE("Init restore session failed, verify caller failed"); + return ret; + } + ret = session_->Active({ + .clientToken = IPCSkeleton::GetCallingTokenID(), + .scenario = IServiceReverseType::Scenario::RESTORE, + .clientProxy = remote, + .userId = GetUserIdDefault(), + .callerName = GetCallerName(), + .activeTime = TimeUtils::GetCurrentTime(), + }); + if (ret == ERR_OK) { + ClearFailedBundles(); + successBundlesNum_ = 0; + ClearBundleRadarReport(); + ClearFileReadyRadarReport(); + return ret; + } + if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { + HILOGE("Active restore session error, Already have a session"); + return ret; + } + HILOGE("Active restore session error"); + StopAll(nullptr, true); + return ret; +} + +ErrCode Service::InitBackupSession(const sptr &remote) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + ErrCode ret = VerifyCaller(); + if (ret != ERR_OK) { + HILOGE("Init full backup session fail, verify caller failed"); + return ret; + } + int32_t oldSize = StorageMgrAdapter::UpdateMemPara(BConstants::BACKUP_VFS_CACHE_PRESSURE); + HILOGI("InitBackupSession oldSize %{public}d", oldSize); + session_->SetMemParaCurSize(oldSize); + ret = session_->Active({ + .clientToken = IPCSkeleton::GetCallingTokenID(), + .scenario = IServiceReverseType::Scenario::BACKUP, + .clientProxy = remote, + .userId = GetUserIdDefault(), + .callerName = GetCallerName(), + .activeTime = TimeUtils::GetCurrentTime(), + }); + if (ret == ERR_OK) { + ClearFailedBundles(); + successBundlesNum_ = 0; + ClearBundleRadarReport(); + ClearFileReadyRadarReport(); + return ret; + } + if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { + HILOGE("Active backup session error, Already have a session"); + return ret; + } + HILOGE("Active backup session error"); + StopAll(nullptr, true); + return ret; +} + +ErrCode Service::Start() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Service Start"); + ErrCode ret = VerifyCaller(session_->GetScenario()); + if (ret != ERR_OK) { + HILOGE("Service start failed, Verify caller failed, ret:%{public}d", ret); + return ret; + } + ret = session_->Start(); + HILOGI("Service Start End"); + if (ret != ERR_OK) { + HILOGE("Service start failed, session is invalid, ret:%{public}d", ret); + return ret; + } + OnStartSched(); + return BError(BError::Codes::OK); +} + +static bool SpecialVersion(const string &versionName) +{ + string versionNameFlag = versionName.substr(0, versionName.find_first_of(BConstants::VERSION_NAME_SEPARATOR_CHAR)); + auto iter = find_if(BConstants::DEFAULT_VERSION_NAMES_VEC.begin(), BConstants::DEFAULT_VERSION_NAMES_VEC.end(), + [&versionNameFlag](const auto &version) { return version == versionNameFlag; }); + if (iter != BConstants::DEFAULT_VERSION_NAMES_VEC.end()) { + return true; + } + return false; +} + +void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) +{ + IServiceReverseType::Scenario scenario = session->GetScenario(); + if (scenario == IServiceReverseType::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && + session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { + session->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(error, bundleName); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); + } + BundleBeginRadarReport(bundleName, error.GetCode(), scenario); +} + +static vector GetRestoreBundleNames(UniqueFd fd, + sptr session, + const vector &bundleNames, + std::string &oldBackupVersion) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + // BundleMgrAdapter::GetBundleInfos可能耗时 + auto restoreInfos = BundleMgrAdapter::GetBundleInfos(bundleNames, session->GetSessionUserId()); + BJsonCachedEntity cachedEntity(move(fd)); + auto cache = cachedEntity.Structuralize(); + oldBackupVersion = cache.GetBackupVersion(); + if (oldBackupVersion.empty()) { + HILOGE("backupVersion of old device is empty"); + } + auto bundleInfos = cache.GetBundleInfos(); + if (!bundleInfos.size()) { + throw BError(BError::Codes::SA_INVAL_ARG, "Json entity caps is empty"); + } + HILOGI("restoreInfos size is:%{public}zu", restoreInfos.size()); + vector restoreBundleInfos {}; + for (const auto &restoreInfo : restoreInfos) { + if (SAUtils::IsSABundleName(restoreInfo.name)) { + BJsonEntityCaps::BundleInfo info = {.name = restoreInfo.name, + .appIndex = restoreInfo.appIndex, + .versionCode = restoreInfo.versionCode, + .versionName = restoreInfo.versionName, + .spaceOccupied = restoreInfo.spaceOccupied, + .allToBackup = restoreInfo.allToBackup, + .fullBackupOnly = restoreInfo.fullBackupOnly, + .extensionName = restoreInfo.extensionName, + .restoreDeps = restoreInfo.restoreDeps}; + restoreBundleInfos.emplace_back(info); + continue; + } + auto it = find_if(bundleInfos.begin(), bundleInfos.end(), [&restoreInfo](const auto &obj) { + return obj.name == restoreInfo.name && obj.appIndex == restoreInfo.appIndex; + }); + if (it == bundleInfos.end()) { + HILOGE("Bundle not need restore, bundleName is %{public}s.", restoreInfo.name.c_str()); + continue; + } + BJsonEntityCaps::BundleInfo info = {.name = (*it).name, + .appIndex = (*it).appIndex, + .versionCode = (*it).versionCode, + .versionName = (*it).versionName, + .spaceOccupied = (*it).spaceOccupied, + .allToBackup = (*it).allToBackup, + .fullBackupOnly = (*it).fullBackupOnly, + .extensionName = restoreInfo.extensionName, + .restoreDeps = restoreInfo.restoreDeps}; + restoreBundleInfos.emplace_back(info); + } + HILOGI("restoreBundleInfos size is:%{public}zu", restoreInfos.size()); + return restoreBundleInfos; +} + +void Service::HandleExceptionOnAppendBundles(sptr session, + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ + if (appendBundleNames.size() != restoreBundleNames.size()) { + HILOGE("AppendBundleNames not equal restoreBundleNames, appendBundleNames size:%{public}zu," + "restoreBundleNames size:%{public}zu", appendBundleNames.size(), restoreBundleNames.size()); + for (const auto &bundleName : appendBundleNames) { + auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), + [&bundleName](const auto &obj) { return obj == bundleName; }); + if (it == restoreBundleNames.end()) { + HILOGE("AppendBundles failed, bundleName = %{public}s.", bundleName.c_str()); + OnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), session, bundleName); + } + } + } +} + +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionDataByDetail"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, detailInfos, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + const std::vector &bundleInfos, + RestoreTypeEnum restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin"); + try { + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("AppendBundles restore session with infos error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + SetUserIdAndRestoreType(restoreType, userId); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); + if (ret != ERR_OK) { + HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + std::vector bundleNamesOnly; + std::map isClearDataFlags; + std::map> bundleNameDetailMap = + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, session_->GetSessionUserId(), + isClearDataFlags); + std::string oldBackupVersion; + auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); + auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); + HandleExceptionOnAppendBundles(session_, bundleNames, restoreBundleNames); + if (restoreBundleNames.empty()) { + HILOGE("AppendBundlesRestoreSession failed, restoreBundleNames is empty."); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } + AppendBundles(restoreBundleNames); + SetCurrentSessProperties(restoreInfos, restoreBundleNames, bundleNameDetailMap, isClearDataFlags, restoreType, + oldBackupVersion); + OnStartSched(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("End"); + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Catch exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return e.GetCode(); + } catch (...) { + HILOGE("Unexpected exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, + std::vector &restoreBundleNames, + RestoreTypeEnum restoreType, + std::string &backupVersion) +{ + HILOGI("Start"); + session_->SetOldBackupVersion(backupVersion); + for (const auto &restoreInfo : restoreBundleInfos) { + auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), [&restoreInfo](const auto &bundleName) { + std::string bundleNameIndex = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + return bundleName == bundleNameIndex; + }); + if (it == restoreBundleNames.end()) { + HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), + restoreInfo.appIndex); + continue; + } + HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), + restoreInfo.extensionName.c_str()); + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || + (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { + OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, bundleNameIndexInfo); + session_->RemoveExtInfo(bundleNameIndexInfo); + continue; + } + session_->SetBundleRestoreType(bundleNameIndexInfo, restoreType); + session_->SetBundleVersionCode(bundleNameIndexInfo, restoreInfo.versionCode); + session_->SetBundleVersionName(bundleNameIndexInfo, restoreInfo.versionName); + session_->SetBundleDataSize(bundleNameIndexInfo, restoreInfo.spaceOccupied); + if (BundleMgrAdapter::IsUser0BundleName(bundleNameIndexInfo, session_->GetSessionUserId())) { + SendUserIdToApp(bundleNameIndexInfo, session_->GetSessionUserId()); + } + session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); + session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + session_->SetIsReadyLaunch(bundleNameIndexInfo); + } + HILOGI("End"); +} +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Begin AppendBundlesRestoreSessionData"); + HILOGI("fd = %{public}d,restoreType = %{public}d,userId=%{public}d", fd, restoreType, userId); + UniqueFd fdUnique(fd); + RestoreTypeEnum restoreTypeEnum = static_cast(restoreType); + return AppendBundlesRestoreSession(std::move(fdUnique), bundleNames, restoreTypeEnum, userId); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("AppendBundles restore session error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + SetUserIdAndRestoreType(restoreType, userId); + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); + if (ret != ERR_OK) { + HILOGE("AppendBundles restore session with infos error, verify caller failed, ret:%{public}d", ret); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + std::string oldBackupVersion; + auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames, oldBackupVersion); + auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); + HandleExceptionOnAppendBundles(session_, bundleNames, restoreBundleNames); + if (restoreBundleNames.empty()) { + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGW("RestoreBundleNames is empty."); + return BError(BError::Codes::OK); + } + AppendBundles(restoreBundleNames); + SetCurrentSessProperties(restoreInfos, restoreBundleNames, restoreType, oldBackupVersion); + OnStartSched(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Catch exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return e.GetCode(); + } catch (...) { + HILOGE("Unexpected exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +void Service::SetCurrentSessProperties( + std::vector &restoreBundleInfos, + std::vector &restoreBundleNames, + std::map> &bundleNameDetailMap, + std::map &isClearDataFlags, + RestoreTypeEnum restoreType, + std::string &backupVersion) +{ + HILOGI("Start"); + session_->SetOldBackupVersion(backupVersion); + for (const auto &restoreInfo : restoreBundleInfos) { + auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), + [&restoreInfo](const auto &bundleName) { + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, + restoreInfo.appIndex); + return bundleName == bundleNameIndexInfo; + }); + if (it == restoreBundleNames.end()) { + HILOGE("Can not find current bundle, bundleName:%{public}s, appIndex:%{public}d", restoreInfo.name.c_str(), + restoreInfo.appIndex); + continue; + } + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + if ((!restoreInfo.allToBackup && !SpecialVersion(restoreInfo.versionName)) || + (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { + OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, bundleNameIndexInfo); + session_->RemoveExtInfo(bundleNameIndexInfo); + continue; + } + session_->SetBundleRestoreType(bundleNameIndexInfo, restoreType); + session_->SetBundleVersionCode(bundleNameIndexInfo, restoreInfo.versionCode); + session_->SetBundleVersionName(bundleNameIndexInfo, restoreInfo.versionName); + session_->SetBundleDataSize(bundleNameIndexInfo, restoreInfo.spaceOccupied); + session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); + auto iter = isClearDataFlags.find(bundleNameIndexInfo); + if (iter != isClearDataFlags.end()) { + session_->SetClearDataFlag(bundleNameIndexInfo, iter->second); + } + BJsonUtil::BundleDetailInfo broadCastInfo; + BJsonUtil::BundleDetailInfo uniCastInfo; + bool broadCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, broadCastInfo); + if (broadCastRet) { + bool notifyRet = DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); + HILOGI("Publish event end, notify result is:%{public}d", notifyRet); + } + bool uniCastRet = + BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo); + if (uniCastRet) { + HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); + session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); + } + session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + session_->SetIsReadyLaunch(bundleNameIndexInfo); + } + HILOGI("End"); +} + +ErrCode Service::AppendBundlesBackupSession(const vector &bundleNames) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("AppendBundles backup session error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); + if (ret != ERR_OK) { + HILOGE("AppendBundles backup session error, verify caller failed, ret:%{public}d", ret); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + auto bundleDetails = MakeDetailList(bundleNames); + auto backupInfos = BundleMgrAdapter::GetBundleInfosForAppendBundles(bundleDetails, + session_->GetSessionUserId()); + std::vector supportBackupNames = GetSupportBackupBundleNames(backupInfos, false, bundleNames); + AppendBundles(supportBackupNames); + SetCurrentBackupSessProperties(supportBackupNames, session_->GetSessionUserId(), backupInfos, false); + OnStartSched(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Failed, errCode = %{public}d", e.GetCode()); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return e.GetCode(); + } catch (...) { + HILOGE("Unexpected exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bundleNames, + const vector &bundleInfos) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("AppendBundles backup session with infos error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::BACKUP); + if (ret != ERR_OK) { + HILOGE("AppendBundles backup session with infos error, verify caller failed, ret:%{public}d", ret); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + std::vector bundleNamesOnly; + std::map isClearDataFlags; + std::map> bundleNameDetailMap = + BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + session_->GetSessionUserId(), isClearDataFlags); + auto bundleDetails = MakeDetailList(bundleNames); + auto backupInfos = BundleMgrAdapter::GetBundleInfosForAppendBundles(bundleDetails, + session_->GetSessionUserId()); + std::vector supportBackupNames = GetSupportBackupBundleNames(backupInfos, false, bundleNames); + AppendBundles(supportBackupNames); + HandleCurGroupBackupInfos(backupInfos, bundleNameDetailMap, isClearDataFlags); + OnStartSched(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Failed, errCode = %{public}d", e.GetCode()); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return e.GetCode(); + } catch(...) { + HILOGE("Unexpected exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +void Service::HandleCurGroupBackupInfos( + std::vector &backupInfos, + std::map> &bundleNameDetailMap, + std::map &isClearDataFlags) +{ + for (auto &info : backupInfos) { + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", info.name.c_str(), + info.extensionName.c_str(), info.appIndex); + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); + SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); + BJsonUtil::BundleDetailInfo uniCastInfo; + if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) { + HILOGI("current bundle:%{public}s, unicast info:%{public}s, unicast info size:%{public}zu", + bundleNameIndexInfo.c_str(), GetAnonyString(uniCastInfo.detail).c_str(), uniCastInfo.detail.size()); + session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); + } + session_->SetBundleUserId(bundleNameIndexInfo, session_->GetSessionUserId()); + session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); + session_->SetIsReadyLaunch(bundleNameIndexInfo); + } +} + +ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) +{ + string callerName; + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("ServiceResultReport restoreRetInfo:%{public}s, sennario:%{public}d, errCode:%{public}d", + restoreRetInfo.c_str(), sennario, errCode); + ErrCode ret = VerifyCallerAndGetCallerName(callerName); + if (ret != ERR_OK) { + HILOGE("Result report fail, bundleName:%{public}s, ret:%{public}d", callerName.c_str(), ret); + HandleCurBundleEndWork(callerName, sennario); + CallOnBundleEndByScenario(callerName, sennario, ret); + OnAllBundlesFinished(BError(BError::Codes::OK)); + return ret; + } + SendEndAppGalleryNotify(callerName); + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + HandleCurBundleEndWork(callerName, sennario); + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); + OnAllBundlesFinished(BError(BError::Codes::OK)); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + HandleCurBundleEndWork(callerName, sennario); + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); + OnAllBundlesFinished(BError(BError::Codes::OK)); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, callerName); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, callerName); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Service result report error"); + HandleCurBundleEndWork(callerName, sennario); + CallOnBundleEndByScenario(callerName, sennario, e.GetCode()); + OnAllBundlesFinished(BError(BError::Codes::OK)); + return e.GetCode(); // 任意异常产生,终止监听该任务 + } +} + +ErrCode Service::SAResultReport(const std::string bundleName, + const std::string restoreRetInfo, + const ErrCode errCode, + const BackupRestoreScenario sennario) +{ + SADone(errCode, bundleName); + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName, ERR_OK); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); + } + OnAllBundlesFinished(BError(BError::Codes::OK)); + if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::RESTORE); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP || + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + BundleEndRadarReport(bundleName, errCode, IServiceReverseType::Scenario::BACKUP); + } + return BError(BError::Codes::OK); +} + +void Service::HandleCurBundleEndWork(std::string bundleName, const BackupRestoreScenario sennario) +{ + HILOGI("Begin"); + try { + if (sennario != BackupRestoreScenario::FULL_RESTORE && sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + return; + } + if (session_->OnBundleFileReady(bundleName)) { + std::shared_ptr mutexPtr = GetExtensionMutex(bundleName); + if (mutexPtr == nullptr) { + HILOGE("extension mutex ptr is nullptr"); + return; + } + std::lock_guard lock(mutexPtr->callbackMutex); + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + return; + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Extension backup Proxy is empty, bundle:%{public}s", bundleName.c_str()); + return; + } + proxy->HandleClear(); + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + backUpConnection->DisconnectBackupExtAbility(); + ClearSessionAndSchedInfo(bundleName); + } + RemoveExtensionMutex(bundleName); + } catch (...) { + HILOGE("Unexpected exception"); + } +} + +ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) +{ + string extInfo = session_->GetBackupExtInfo(bundleName); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (SAUtils::IsSABundleName(bundleName)) { + auto saBackUpConnection = session_->GetSAExtConnection(bundleName); + std::shared_ptr saConnection = saBackUpConnection.lock(); + if (saConnection == nullptr) { + HILOGE("lock sa connection ptr is nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (scenario == IServiceReverseType::Scenario::BACKUP) { + return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_BACKUP, extInfo); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + return saConnection->ConnectBackupSAExt(bundleName, BConstants::EXTENSION_RESTORE, extInfo); + } + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("GetFileHandle bundleName:%{public}s,fileName:%{public}s", bundleName.c_str(), fileName.c_str()); + try { + if (session_ == nullptr) { + return BError(BError::Codes::SA_INVAL_ARG); + } + ErrCode ret = VerifyCaller(IServiceReverseType::Scenario::RESTORE); + if (ret != ERR_OK) { + return ret; + } + bool updateRes = SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); + if (updateRes) { + return BError(BError::Codes::OK); + } + auto action = session_->GetServiceSchedAction(bundleName); + if (action == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (action == BConstants::ServiceSchedAction::RUNNING) { + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("GetFileHandle error, Extension backup Proxy is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + int32_t errCode = 0; + int32_t fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(fdCode); + if (errCode != ERR_OK) { + AppRadar::Info info(bundleName, "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + } + session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); + } else { + session_->SetExtFileNameRequest(bundleName, fileName); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + return e.GetCode(); + } +} + +void Service::ExtStart(const string &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGE("begin ExtStart, bundle name:%{public}s", bundleName.data()); + if (SAUtils::IsSABundleName(bundleName)) { + BackupSA(bundleName); + return; + } + if (IncrementalBackup(bundleName)) { + return; + } + StartCurBundleBackupOrRestore(bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + SendEndAppGalleryNotify(bundleName); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); + } +} + +void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) +{ + HILOGI("Begin handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("Error, backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + ReportOnBundleStarted(scenario, bundleName); + return; + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (proxy == nullptr) { + HILOGE("Error, Extension backup Proxy is empty, bundle:%{public}s", bundleName.c_str()); + ReportOnBundleStarted(scenario, bundleName); + return; + } + if (scenario == IServiceReverseType::Scenario::BACKUP) { + auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + if (ret) { + SendEndAppGalleryNotify(bundleName); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); + } + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + GetOldDeviceBackupVersion(); + BundleBeginRadarReport(bundleName, ret, scenario); + auto fileNameVec = session_->GetExtFileNameRequest(bundleName); + for (const auto &fileName : fileNameVec) { + int32_t errCode = 0; + int fdCode = 0; + proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); + UniqueFd fd(fdCode); + session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, scenario); + } + } + HILOGI("End handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); +} + +int Service::Dump(int fd, const vector &args) +{ + if (fd < 0) { + HILOGI("HiDumper handle invalid"); + return -1; + } + + session_->DumpInfo(fd, args); + return 0; +} + +void Service::ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, + const std::string &bundleName, + const ErrCode ret) +{ + try { + if (session_ == nullptr) { + HILOGE("Report extConnectfailed error, session info is empty"); + return; + } + if (scenario == IServiceReverseType::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + } else if (scenario == IServiceReverseType::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && + session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName, + session_->GetBundleUserId(bundleName)); + HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + bundleName.c_str()); + } else if (scenario == IServiceReverseType::Scenario::BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName, + session_->GetBundleUserId(bundleName)); + HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + bundleName.c_str()); + } + } catch (...) { + HILOGE("Report extConnectfailed error"); + } +} + +void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + IServiceReverseType::Scenario scenario = IServiceReverseType::Scenario::UNDEFINED; + try { + HILOGE("begin %{public}s", bundleName.data()); + scenario = session_->GetScenario(); + ReportOnExtConnectFailed(scenario, bundleName, ret); + SendEndAppGalleryNotify(bundleName); + ClearSessionAndSchedInfo(bundleName); + OnAllBundlesFinished(BError(BError::Codes::OK)); + return; + } catch (const BError &e) { + HILOGE("ExtConnectFailed exception, bundleName:%{public}s", bundleName.c_str()); + return; + } catch (...) { + HILOGE("Unexpected exception"); + return; + } +} + +void Service::StartRunningTimer(const std::string &bundleName) +{ + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + auto scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { + session_->StartExtTimer(bundleName, timeoutCallback); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + session_->StartFwkTimer(bundleName, timeoutCallback); + } +} + +void Service::ExtConnectDone(string bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGE("begin %{public}s", bundleName.data()); + BConstants::ServiceSchedAction curSchedAction = session_->GetServiceSchedAction(bundleName); + if (curSchedAction == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("Can not find bundle from this session, bundleName:%{public}s", bundleName.c_str()); + SendEndAppGalleryNotify(bundleName); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_REFUSED_ACT)); + return; + } + if (curSchedAction == BConstants::ServiceSchedAction::CLEAN) { + HILOGI("Current bundle will execute clean task, bundleName:%{public}s", bundleName.c_str()); + sched_->Sched(bundleName); + return; + } + if (curSchedAction == BConstants::ServiceSchedAction::START && + clearRecorder_->FindClearBundleRecord(bundleName)) { + session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::CLEAN); + } else { + session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::RUNNING); + bool needCleanData = session_->GetClearDataFlag(bundleName); + if (needCleanData) { + HILOGI("Current bundle need clean data, bundleName:%{public}s", bundleName.c_str()); + AddClearBundleRecord(bundleName); + } + } + sched_->Sched(bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + SendEndAppGalleryNotify(bundleName); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SDK_INVAL_ARG)); + return; + } +} + +void Service::ClearSessionAndSchedInfo(const string &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("begin %{public}s", bundleName.c_str()); + session_->RemoveExtInfo(bundleName); + sched_->RemoveExtConn(bundleName); + HandleRestoreDepsBundle(bundleName); + DelClearBundleRecord({bundleName}); + if (isOccupyingSession_.load() && session_->IsOnAllBundlesFinished()) { + HILOGI("Cleaning up backup data end."); + SetOccupySession(false); + StopAll(nullptr, true); + return; + } + for (int num = 0; num < BConstants::EXT_CONNECT_MAX_COUNT; num++) { + sched_->Sched(); + } + } catch (const BError &e) { + HILOGE("ClearSessionAndSchedInfo exception"); + return; + } catch (...) { + HILOGE("Unexpected exception"); + return; + } +} + +void Service::HandleRestoreDepsBundle(const string &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + if (session_->GetScenario() != IServiceReverseType::Scenario::RESTORE) { + return; + } + HILOGI("Begin, bundleName: %{public}s", bundleName.c_str()); + SvcRestoreDepsManager::GetInstance().AddRestoredBundles(bundleName); + // 该应用恢复完成,判断依赖hap的前置hap是否全部恢复完成,如果成了,追加该依赖hap + auto restoreBundleMap = SvcRestoreDepsManager::GetInstance().GetRestoreBundleMap(); + if (restoreBundleMap.empty()) { + HILOGI("restoreBundleMap is empty."); + return; + } + // 启动恢复会话 + vector restoreBundleNames {}; + for (const auto &bundle : restoreBundleMap) { + HILOGI("Start restore session, bundle: %{public}s", bundle.first.c_str()); + restoreBundleNames.emplace_back(bundle.first); + } + AppendBundles(restoreBundleNames); + for (const auto &bundle : restoreBundleMap) { + for (const auto &bundleInfo : SvcRestoreDepsManager::GetInstance().GetAllBundles()) { + if (bundle.first != bundleInfo.name) { + continue; + } + SvcRestoreDepsManager::RestoreInfo info = bundle.second; + session_->SetBundleRestoreType(bundleInfo.name, info.restoreType_); + session_->SetBundleVersionCode(bundleInfo.name, bundleInfo.versionCode); + session_->SetBundleVersionName(bundleInfo.name, bundleInfo.versionName); + session_->SetBundleDataSize(bundleInfo.name, bundleInfo.spaceOccupied); + for (const auto &fileName : info.fileNames_) { + session_->SetExtFileNameRequest(bundleInfo.name, fileName); + } + session_->SetBackupExtName(bundleInfo.name, bundleInfo.extensionName); + session_->SetIsReadyLaunch(bundleInfo.name); + } + } + HILOGI("End"); +} + +void Service::OnStartSched() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + if (session_->IsOnOnStartSched()) { + for (int num = 0; num < BConstants::EXT_CONNECT_MAX_COUNT; num++) { + sched_->Sched(); + } + } +} + +void Service::SendStartAppGalleryNotify(const BundleName &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + if (SAUtils::IsSABundleName(bundleName)) { + HILOGI("SA does not need to StartRestore"); + return; + } + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { + return; + } + int32_t userId = session_->GetBundleUserId(bundleName); + std::string bundleNameWithUserId = BundleNameWithUserId(bundleName, userId); + if (!disposal_->IfBundleNameInDisposalConfigFile(bundleNameWithUserId)) { + HILOGE("WriteDisposalConfigFile Failed"); + return; + } + HILOGI("AppendIntoDisposalConfigFile OK, bundleName=%{public}s", bundleNameWithUserId.c_str()); + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->StartRestore(bundleName, userId); + HILOGI("StartRestore, code=%{public}d, bundleName=%{public}s, userId=%{public}d", disposeErr, bundleName.c_str(), + userId); +} + +void Service::SendEndAppGalleryNotify(const BundleName &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + if (SAUtils::IsSABundleName(bundleName)) { + HILOGI("SA does not need to EndRestore"); + return; + } + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { + return; + } + int32_t userId = session_->GetBundleUserId(bundleName); + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName, userId); + HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s, userId=%{public}d", disposeErr, bundleName.c_str(), + userId); + if (disposeErr != DisposeErr::OK) { + HILOGE("Error code=%{public}d, disposal will be clear in the end", disposeErr); + return; + } + std::string bundleNameWithUserId = BundleNameWithUserId(bundleName, userId); + if (!disposal_->DeleteFromDisposalConfigFile(bundleNameWithUserId)) { + HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleNameWithUserId.c_str()); + return; + } + HILOGI("DeleteFromDisposalConfigFile OK, bundleName=%{public}s", bundleNameWithUserId.c_str()); +} + +void Service::TryToClearDispose(const BundleName &bundleName) +{ + auto [bundle, userId] = SplitBundleName(bundleName); + if (bundle.empty() || userId == -1) { + HILOGE("BundleName from disposal config is invalid, bundleName = %{public}s", bundleName.c_str()); + if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { + HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); + } + return; + } + int32_t maxAtt = MAX_TRY_CLEAR_DISPOSE_NUM; + int32_t att = 0; + while (att < maxAtt) { + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundle, userId); + HILOGI("EndRestore, code=%{public}d, bundleName=%{public}s, userId=%{public}d", disposeErr, bundle.c_str(), + userId); + if (disposeErr == DisposeErr::OK) { + break; + } + ++att; + HILOGI("Try to clear dispose, num = %{public}d", att); + } + if (!disposal_->DeleteFromDisposalConfigFile(bundleName)) { + HILOGE("DeleteFromDisposalConfigFile Failed, bundleName=%{public}s", bundleName.c_str()); + } +} + +void Service::SendErrAppGalleryNotify() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { + return; + } + vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); + if (bundleNameList.empty()) { + HILOGI("End, All disposal pasitions have been cleared"); + return; + } + for (vector::iterator it = bundleNameList.begin(); it != bundleNameList.end(); ++it) { + string bundleName = *it; + TryToClearDispose(bundleName); + } +} + +void Service::ClearDisposalOnSaStart() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); + if (!bundleNameList.empty()) { + for (vector::iterator it = bundleNameList.begin(); it != bundleNameList.end(); ++it) { + string bundleName = *it; + HILOGE("dispose has residual, clear now, bundelName =%{public}s", bundleName.c_str()); + TryToClearDispose(bundleName); + } + } + HILOGI("SA start, All Errdisposal pasitions have been cleared"); +} + +void Service::DeleteDisConfigFile() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario != IServiceReverseType::Scenario::RESTORE) { + return; + } + vector bundleNameList = disposal_->GetBundleNameFromConfigFile(); + if (!bundleNameList.empty()) { + HILOGE("DisposalConfigFile is not empty"); + return; + } + if (!disposal_->DeleteConfigFile()) { + HILOGE("DeleteConfigFile failed"); + } +} + +void Service::SessionDeactive() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("Begin"); + isInRelease_.store(true); + // 清理处置状态 + if (session_ == nullptr) { + HILOGE("Session deactive error, session is empty"); + return; + } + ErrCode ret = BError(BError::Codes::OK); + std::vector bundleNameList; + if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE && + session_->CleanAndCheckIfNeedWait(ret, bundleNameList)) { + if (ret != ERR_OK) { + isRmConfigFile_.store(false); + } + if (!bundleNameList.empty()) { + DelClearBundleRecord(bundleNameList); + } + return; + } + isInRelease_.store(false); + if (!bundleNameList.empty()) { + DelClearBundleRecord(bundleNameList); + } + SendErrAppGalleryNotify(); + DeleteDisConfigFile(); + // 结束定时器 + if (sched_ == nullptr) { + HILOGE("Session deactive error, sched is empty"); + return; + } + sched_->ClearSchedulerData(); + // 清除缓存数据 + if (session_ == nullptr) { + HILOGE("Session deactive error, session is empty"); + return; + } + ret = session_->ClearSessionData(); + if (clearRecorder_ != nullptr && !ret && isRmConfigFile_.load()) { + clearRecorder_->DeleteConfigFile(); + } + // close session + StopAll(nullptr, true); + if (session_->GetSessionCnt() <= 0) { + HILOGI("do unload Service."); + sched_->TryUnloadService(); + } + } catch (...) { + HILOGE("Unexpected exception"); + return; + } +} + +std::function Service::GetBackupInfoConnectDone(wptr obj, + const std::string &bundleName) +{ + return [obj](const string &&bundleName) { + HILOGI("GetBackupInfoConnectDone, bundleName: %{public}s", bundleName.c_str()); + auto thisPtr = obj.promote(); + if (!thisPtr) { + HILOGW("this pointer is null."); + return; + } + thisPtr->getBackupInfoCondition_.notify_one(); + }; +} + +std::function Service::GetBackupInfoConnectDied(wptr obj, + const std::string &bundleName) +{ + return [obj](const string &&bundleName, bool isCleanCalled) { + HILOGI("GetBackupInfoConnectDied, bundleName: %{public}s", bundleName.c_str()); + auto thisPtr = obj.promote(); + if (!thisPtr) { + HILOGW("this pointer is null."); + return; + } + thisPtr->isConnectDied_.store(true); + thisPtr->getBackupInfoCondition_.notify_one(); + }; +} + +ErrCode Service::ClearResidualBundleData(const std::string &bundleName) +{ + if (session_ == nullptr) { + return BError(BError::Codes::SA_INVAL_ARG); + } + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("BackUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Extension backup Proxy is empty, bundle:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + // 通知ext清理 + HILOGI("Current bundle will clean extension data, bundleName:%{public}s", bundleName.c_str()); + ErrCode res = proxy->HandleClear(); + if (backUpConnection->IsExtAbilityConnected()) { + backUpConnection->DisconnectBackupExtAbility(); + } + ClearSessionAndSchedInfo(bundleName); + // 非清理任务,需要上报 + if (session_->GetScenario() != IServiceReverseType::Scenario::CLEAN) { + OnAllBundlesFinished(BError(BError::Codes::OK)); + } + return res; +} + +ErrCode Service::GetBackupInfoCmdHandle(const BundleName &bundleName, std::string &result) +{ + if (session_ == nullptr) { + HILOGE("Get BackupInfo error, session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto backupConnection = session_->CreateBackupConnection(bundleName); + if (backupConnection == nullptr) { + HILOGE("backupConnection is null. bundleName: %{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); + auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); + backupConnection->SetCallback(callConnected); + backupConnection->SetCallDied(callDied); + AAFwk::Want want = CreateConnectWant(bundleName); + auto ret = backupConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (ret) { + HILOGE("ConnectBackupExtAbility faild, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BOOT_EXT_FAIL); + } + std::unique_lock lock(getBackupInfoSyncLock_); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); + if (isConnectDied_.load()) { + HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); + isConnectDied_.store(false); + return BError(BError::Codes::EXT_ABILITY_DIED); + } + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Extension backup Proxy is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + ret = proxy->GetBackupInfo(result); + backupConnection->DisconnectBackupExtAbility(); + if (ret != ERR_OK) { + HILOGE("Call Ext GetBackupInfo faild."); + AppRadar::Info info(bundleName, "", "Call Ext GetBackupInfo faild"); + Backup::AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::GetBackupInfoCmdHandle", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_GET_BACKUP_INFO_FAIL, ret); + return BError(BError::Codes::SA_INVAL_ARG); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) +{ + ErrCode errCode = VerifyCaller(); + if (errCode != ERR_OK) { + HILOGE("GetBackupInfo failed, verify caller failed, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); + return errCode; + } + try { + std::lock_guard lock(getBackupInfoProcLock_); + HILOGI("Service::GetBackupInfo begin bundleName: %{public}s", bundleName.c_str()); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Get BackupInfo error, session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (session_->GetImpl().clientToken) { + return BError(BError::Codes::SA_REFUSED_ACT, "Already have an active session"); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + auto ret = GetBackupInfoCmdHandle(bundleName, result); + HILOGI("Service::GetBackupInfo end. result: %{public}s", result.c_str()); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } catch (...) { + HILOGE("Unexpected exception"); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +ErrCode Service::AppendBundlesClearSession(const std::vector &bundleNames) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (bundleNames.empty() || session_ == nullptr) { + HILOGE("AppendBundles clear session error, session is empty"); + return EPERM; + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 + auto backupInfos = BundleMgrAdapter::GetBundleInfos(bundleNames, session_->GetSessionUserId()); + if (backupInfos.empty()) { + if (clearRecorder_ != nullptr) { + clearRecorder_->DeleteConfigFile(); + } + HILOGE("AppendBundles clear session error, backupInfos is empty"); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } + std::vector supportBundleNames; + for (const auto &info : backupInfos) { + std::string bundleNameIndexStr = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); + supportBundleNames.emplace_back(bundleNameIndexStr); + } + AppendBundles(supportBundleNames); + for (const auto &info : backupInfos) { + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); + session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); + session_->SetIsReadyLaunch(bundleNameIndexInfo); + } + OnStartSched(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("Failed, errCode = %{public}d", e.GetCode()); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return e.GetCode(); + } catch (...) { + HILOGE("Unexpected exception"); + HandleExceptionOnAppendBundles(session_, bundleNames, {}); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) +{ + try { + HILOGI("Service::UpdateTimer begin."); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Update Timer error, session is empty."); + result = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + ErrCode ret = VerifyCaller(); + if (ret != ERR_OK) { + HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", + bundleName.c_str()); + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + result = session_->UpdateTimer(bundleName, timeout, timeoutCallback); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + HILOGE("Unexpected exception"); + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return EPERM; + } +} + +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) +{ + HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Update Send Rate error, session is empty."); + result = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + ErrCode ret = VerifySendRateParam(); + if (ret != ERR_OK) { + HILOGE("Verify sendRate param failed, bundleName:%{public}s", bundleName.c_str()); + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } + std::shared_ptr mutexPtr = GetExtensionMutex(bundleName); + if (mutexPtr == nullptr) { + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG, "Extension mutex ptr is null."); + } + do { + std::lock_guard lock(mutexPtr->callbackMutex); + result = true; + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + result = false; + ret = BError(BError::Codes::SA_INVAL_ARG); + break; + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Update send rate fail, extension proxy is empty"); + result = false; + ret = BError(BError::Codes::SA_INVAL_ARG); + break; + } + ret = proxy->UpdateFdSendRate(bundleName, sendRate); + if (ret != NO_ERROR) { + HILOGE("Extension do updateSendRate failed, ret:%{public}d", ret); + result = false; + ret = BError(BError::Codes::EXT_BROKEN_IPC); + break; + } + } while (0); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + RemoveExtensionMutex(bundleName); + return ret; +} + +AAFwk::Want Service::CreateConnectWant(const BundleName &bundleName) +{ + BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; + AAFwk::Want want; + string backupExtName = BundleMgrAdapter::GetExtName(bundleName, session_->GetSessionUserId()); + want.SetElementName(bundleName, backupExtName); + want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); + return want; +} + +ErrCode Service::BackupSA(std::string bundleName) +{ + HILOGI("BackupSA begin %{public}s", bundleName.c_str()); + IServiceReverseType::Scenario scenario = session_->GetScenario(); + auto backUpConnection = session_->GetSAExtConnection(bundleName); + std::shared_ptr saConnection = backUpConnection.lock(); + if (saConnection == nullptr) { + HILOGE("lock sa connection ptr is nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (scenario == IServiceReverseType::Scenario::BACKUP) { + auto ret = saConnection->CallBackupSA(); + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + if (ret) { + HILOGI("BackupSA ret is %{public}d", ret); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); + return BError(ret); + } + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); + } + return BError(BError::Codes::OK); +} + +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) +{ + auto task = [bundleName, fd, result, errCode, this]() { + HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", + bundleName.c_str(), fd, result.c_str(), errCode); + session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); + FileReadyRadarReport(bundleName, "", errCode, IServiceReverseType::Scenario::BACKUP); + SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); + }; + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) +{ + auto task = [bundleName, result, errCode, this]() { + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", bundleName.c_str(), + result.c_str(), errCode); + SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); + }; + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +ErrCode Service::SADone(ErrCode errCode, std::string bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_->OnBundleFileReady(bundleName)) { + auto backupConnection = session_->GetSAExtConnection(bundleName); + std::shared_ptr saConnection = backupConnection.lock(); + if (saConnection == nullptr) { + HILOGE("lock sa connection ptr is nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + saConnection->DisconnectBackupSAExt(); + ClearSessionAndSchedInfo(bundleName); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + ReleaseOnException(); + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (...) { + HILOGE("Unexpected exception"); + ReleaseOnException(); + return EPERM; + } +} + +void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) +{ + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverseType::Scenario::BACKUP) { + HILOGI("will notify clone data, scenario is Backup"); + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + auto ms = std::chrono::duration_cast(now.time_since_epoch()); + std::stringstream strTime; + strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) + << (std::setw(INDEX)) << (ms.count() % MS_1000); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, "PID", getpid(), "TIME", strTime.str()); + } else if (scenario == IServiceReverseType::Scenario::RESTORE) { + HILOGI("will notify clone data, scenario is Restore"); + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); + } + BundleEndRadarReport(callerName, errCode, scenario); +} + +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, BackupRestoreScenario sennario) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + string bundleName; + ErrCode ret = VerifyCallerAndGetCallerName(bundleName); + if (ret != ERR_OK) { + HILOGE("Report app process info failed, Get bundle name failed, ret:%{public}d", ret); + return ret; + } + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnProcessInfo(bundleName, processInfo); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + HILOGE("ReportAppProcessInfo exception"); + return e.GetCode(); + } catch (const exception &e) { + HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } +} + +std::function Service::TimeOutCallback(wptr ptr, std::string bundleName) +{ + return [ptr, bundleName, this]() { + HILOGI("begin timeoutCallback bundleName = %{public}s", bundleName.c_str()); + auto thisPtr = ptr.promote(); + if (!thisPtr) { + HILOGE("ServicePtr is nullptr."); + return; + } + try { + DoTimeout(thisPtr, bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + SendEndAppGalleryNotify(bundleName); + thisPtr->ClearSessionAndSchedInfo(bundleName); + thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + } + }; +} + +void Service::DoTimeout(wptr ptr, std::string bundleName) +{ + auto thisPtr = ptr.promote(); + if (!thisPtr) { + HILOGE("ServicePtr is nullptr."); + return; + } + auto sessionPtr = thisPtr->session_; + if (sessionPtr == nullptr) { + HILOGE("SessionPtr is nullptr."); + return; + } + IServiceReverseType::Scenario scenario = sessionPtr->GetScenario(); + try { + std::shared_ptr mutexPtr = GetExtensionMutex(bundleName); + if (mutexPtr == nullptr) { + HILOGE("extension mutex ptr is nullptr, bundleName:%{public}s", bundleName.c_str()); + return; + } + std::lock_guard lock(mutexPtr->callbackMutex); + if (SAUtils::IsSABundleName(bundleName)) { + auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); + shared_ptr saConnection = sessionConnection.lock(); + if (saConnection == nullptr) { + HILOGE("Error, saConnection is empty, bundleName:%{public}s", bundleName.c_str()); + return; + } + saConnection->DisconnectBackupSAExt(); + } else { + auto sessionConnection = sessionPtr->GetExtConnection(bundleName); + if (sessionConnection == nullptr) { + HILOGE("Error, sessionConnection is empty, bundleName:%{public}s", bundleName.c_str()); + return; + } + sessionConnection->DisconnectBackupExtAbility(); + } + TimeoutRadarReport(scenario, bundleName); + sessionPtr->StopFwkTimer(bundleName); + sessionPtr->StopExtTimer(bundleName); + SendEndAppGalleryNotify(bundleName); + thisPtr->ClearSessionAndSchedInfo(bundleName); + thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + SendEndAppGalleryNotify(bundleName); + thisPtr->ClearSessionAndSchedInfo(bundleName); + thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + } + RemoveExtensionMutex(bundleName); +} + +void Service::AddClearBundleRecord(const std::string &bundleName) +{ + // 添加清理记录 + if (!clearRecorder_->InsertClearBundleRecord(bundleName)) { + HILOGE("Failed to add clear bundle record, bundleName=%{public}s", bundleName.c_str()); + return; + } + HILOGI("Add clear bundle record OK, bundleName=%{public}s", bundleName.c_str()); +} + +void Service::DelClearBundleRecord(const std::vector &bundleNames) +{ + // 删除清理记录 + for (const auto &it : bundleNames) { + if (!clearRecorder_->DeleteClearBundleRecord(it)) { + HILOGE("Failed to delete clear bundle record, bundleName=%{public}s", it.c_str()); + continue; + } + HILOGI("Delete clear bundle record OK, bundleName=%{public}s", it.c_str()); + } +} + +void Service::ReleaseOnException() +{ + if (session_->IsOnAllBundlesFinished()) { + IServiceReverseType::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverseType::Scenario::RESTORE)) { + HILOGI("Will execute destory session info"); + SessionDeactive(); + } + } +} + +void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) +{ + session_->SetImplRestoreType(restoreType); + if (userId != DEFAULT_INVAL_VALUE) { /* multi user scenario */ + session_->SetSessionUserId(userId); + } else { + session_->SetSessionUserId(GetUserIdDefault()); + } +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 63b688ed6..fb92e02aa 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -95,7 +95,7 @@ ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -104,7 +104,7 @@ ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, return BError(BError::Codes::OK); } -ErrCode Service::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode Service::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 0a62f37c4..e8af0933f 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -91,9 +91,8 @@ HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_BackupOnFileReady_010 TestManager tm("ServiceReverseProxyTest_GetFd_0100"); std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); - UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); EXPECT_TRUE(proxy_ != nullptr); - int fdValue = fd.Get(); + int fdValue = open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR) proxy_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, fdValue, 0); EXPECT_TRUE(true); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index 2fbd84033..66289e040 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -56,13 +56,13 @@ public: MOCK_METHOD3(ServiceResultReport, ErrCode(const string &restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode)); MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); - MOCK_METHOD5(AppendBundlesRestoreSessionRestoreDataWaitSend, + MOCK_METHOD5(AppendBundlesRestoreSessionDataByDetail, ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, int32_t userId)); - MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + MOCK_METHOD4(AppendBundlesRestoreSessionData, ErrCode(UniqueFd fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId)); MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD2(AppendBundlesDetailsBackupSession, diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index b04fe944b..ba0252bbe 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -260,7 +260,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::e auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore); @@ -384,7 +384,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::e auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); ServiceClient::serviceProxy_ = proxy; err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); @@ -477,7 +477,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitReady(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionData(_, _, _, _)).WillOnce(Return(0)); UniqueFd remoteCap2; ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore); @@ -572,7 +572,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::e auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); - EXPECT_CALL(*proxy, AppendBundlesRestoreSessionRestoreDataWaitSend(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*proxy, AppendBundlesRestoreSessionDataByDetail(_, _, _, _, _)).WillOnce(Return(0)); ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 765206376..5d4c56f03 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -138,7 +138,7 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, +ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd, const std::vector &bundleNames, const std::vector &detailInfos, int32_t restoreType, @@ -147,7 +147,7 @@ ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitSend(int fd, return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSessionRestoreDataWaitReady(int fd, +ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd, const std::vector &bundleNames, int32_t restoreType, int32_t userId) diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index 1b3846170..85a4e056e 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -64,9 +64,9 @@ public: MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); MOCK_METHOD5( - AppendBundlesRestoreSessionRestoreDataWaitSend, + AppendBundlesRestoreSessionDataByDetail, ErrCode(int32_t, const std::vector &, const std::vector &, int32_t, int32_t)); - MOCK_METHOD4(AppendBundlesRestoreSessionRestoreDataWaitReady, + MOCK_METHOD4(AppendBundlesRestoreSessionData, ErrCode(int32_t, const std::vector &, int32_t, int32_t)); MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); }; diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp index 13e96ddd2..1d3dc5078 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_check_sa_test.cpp @@ -101,7 +101,6 @@ HWTEST_F(ToolsOpCheckSaTest, SUB_backup_tools_op_check_sa_0200, testing::ext::Te } GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); - CheckSaRegister(); if (matchedOp != opeartions.end()) { ret = matchedOp->Execute(mapArgToVal); EXPECT_NE(ret, 0); -- Gitee