From 45b9be8d1fbae23bd27542498c6889c481d4a625 Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Sat, 8 Jul 2023 15:59:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3=E7=AE=A1=E6=8E=A7=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- bundle.json | 2 + .../backup_ext/src/ext_extension_stub.cpp | 12 +++-- .../backup_kit_inner/src/service_proxy.cpp | 33 ++++++++----- .../src/service_reverse_stub.cpp | 26 ++++++---- .../backup_kit_inner/impl/i_extension.h | 11 +---- .../impl/i_extension_ipc_interface_code.h | 29 +++++++++++ .../native/backup_kit_inner/impl/i_service.h | 15 +----- .../impl/i_service_ipc_interface_code.h | 36 ++++++++++++++ .../backup_kit_inner/impl/i_service_reverse.h | 13 +---- .../i_service_reverse_ipc_interface_code.h | 34 +++++++++++++ .../src/module_ipc/service_reverse_proxy.cpp | 38 +++++++++++--- .../backup_sa/src/module_ipc/service_stub.cpp | 30 +++++++----- .../src/module_ipc/svc_extension_proxy.cpp | 17 +++++-- tests/mock/module_ipc/service_stub_mock.cpp | 30 +++++++----- .../backup_impl/service_reverse_stub_test.cpp | 42 +++++++++++----- .../module_ipc/service_stub_test.cpp | 49 +++++++++++++------ 16 files changed, 297 insertions(+), 120 deletions(-) create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h diff --git a/bundle.json b/bundle.json index 80107caf9..aa17524b1 100644 --- a/bundle.json +++ b/bundle.json @@ -91,6 +91,8 @@ "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" ] diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp index 4c41179e7..773de8c99 100644 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ b/frameworks/native/backup_ext/src/ext_extension_stub.cpp @@ -27,10 +27,14 @@ using namespace std; ExtExtensionStub::ExtExtensionStub() { - opToInterfaceMap_[CMD_GET_FILE_HANDLE] = &ExtExtensionStub::CmdGetFileHandle; - opToInterfaceMap_[CMD_HANDLE_CLAER] = &ExtExtensionStub::CmdHandleClear; - opToInterfaceMap_[CMD_HANDLE_BACKUP] = &ExtExtensionStub::CmdHandleBackup; - opToInterfaceMap_[CMD_PUBLISH_FILE] = &ExtExtensionStub::CmdPublishFile; + 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; } int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 707a5468a..a230b2344 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -43,7 +43,8 @@ ErrCode ServiceProxy::InitRestoreSession(sptr remote) return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); } - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_INIT_RESTORE_SESSION, data, reply, option); + 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(); @@ -69,7 +70,8 @@ ErrCode ServiceProxy::InitBackupSession(sptr remote) return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the reverse stub").GetCode(); } - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_INIT_BACKUP_SESSION, data, reply, option); + 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(); @@ -88,7 +90,8 @@ ErrCode ServiceProxy::Start() MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_START, data, reply, 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(); @@ -108,7 +111,8 @@ UniqueFd ServiceProxy::GetLocalCapabilities() MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_GET_LOCAL_CAPABILITIES, data, reply, option); + 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); return UniqueFd(-ret); @@ -133,7 +137,8 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_PUBLISH_FILE, data, reply, 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(); @@ -159,7 +164,8 @@ ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd) MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_APP_FILE_READY, data, reply, 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(); @@ -182,7 +188,8 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_APP_DONE, data, reply, 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(); @@ -209,7 +216,8 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file MessageParcel reply; MessageOption option; option.SetFlags(MessageOption::TF_ASYNC); - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_GET_FILE_NAME, data, reply, option); + 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(); @@ -235,7 +243,8 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vectorSendRequest(IService::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, data, reply, option); + 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(); @@ -258,7 +267,8 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); } - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, data, reply, option); + 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(); @@ -277,7 +287,8 @@ ErrCode ServiceProxy::Finish() MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IService::SERVICE_CMD_FINISH, data, reply, 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(); diff --git a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp index b9299c68f..7cfcb79c0 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp @@ -46,15 +46,23 @@ int32_t ServiceReverseStub::OnRemoteRequest(uint32_t code, ServiceReverseStub::ServiceReverseStub() { - opToInterfaceMap_[SERVICER_BACKUP_ON_FILE_READY] = &ServiceReverseStub::CmdBackupOnFileReady; - opToInterfaceMap_[SERVICER_BACKUP_ON_SUB_TASK_STARTED] = &ServiceReverseStub::CmdBackupOnBundleStarted; - opToInterfaceMap_[SERVICER_BACKUP_ON_SUB_TASK_FINISHED] = &ServiceReverseStub::CmdBackupOnBundleFinished; - opToInterfaceMap_[SERVICER_BACKUP_ON_TASK_FINISHED] = &ServiceReverseStub::CmdBackupOnAllBundlesFinished; - - opToInterfaceMap_[SERVICER_RESTORE_ON_SUB_TASK_STARTED] = &ServiceReverseStub::CmdRestoreOnBundleStarted; - opToInterfaceMap_[SERVICER_RESTORE_ON_SUB_TASK_FINISHED] = &ServiceReverseStub::CmdRestoreOnBundleFinished; - opToInterfaceMap_[SERVICER_RESTORE_ON_TASK_FINISHED] = &ServiceReverseStub::CmdRestoreOnAllBundlesFinished; - opToInterfaceMap_[SERVICER_RESTORE_ON_FILE_READY] = &ServiceReverseStub::CmdRestoreOnFileReady; + 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_SUB_TASK_FINISHED)] = + &ServiceReverseStub::CmdBackupOnBundleFinished; + opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED)] = + &ServiceReverseStub::CmdBackupOnAllBundlesFinished; + + opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED)] = + &ServiceReverseStub::CmdRestoreOnBundleStarted; + 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_FILE_READY)] = + &ServiceReverseStub::CmdRestoreOnFileReady; } int32_t ServiceReverseStub::CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply) diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h index 9355df314..ea5657208 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h @@ -16,9 +16,9 @@ #ifndef OHOS_FILEMGMT_BACKUP_I_EXTENSION_H #define OHOS_FILEMGMT_BACKUP_I_EXTENSION_H -#include - #include "errors.h" +#include "i_extension_ipc_interface_code.h" +#include "iremote_broker.h" #include "unique_fd.h" namespace OHOS::FileManagement::Backup { @@ -26,13 +26,6 @@ class IExtension : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IExtension"); - enum { - CMD_GET_FILE_HANDLE = 1, - CMD_HANDLE_CLAER, - CMD_PUBLISH_FILE, - CMD_HANDLE_BACKUP, - }; - public: virtual UniqueFd GetFileHandle(const std::string &fileName) = 0; virtual ErrCode HandleClear() = 0; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h new file mode 100644 index 000000000..4e76c4cc7 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_I_EXTENSION_IPC_INTERFACE_CODE_H +#define OHOS_FILEMGMT_BACKUP_I_EXTENSION_IPC_INTERFACE_CODE_H + +/*SAID: 5203*/ +namespace OHOS::FileManagement::Backup { +enum class IExtensionInterfaceCode { + CMD_GET_FILE_HANDLE = 1, + CMD_HANDLE_CLAER, + CMD_PUBLISH_FILE, + CMD_HANDLE_BACKUP, +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_I_EXTENSION_IPC_INTERFACE_CODE_H \ No newline at end of file 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 index 3e8af262c..5b50dfca9 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -22,26 +22,13 @@ #include #include "b_file_info.h" +#include "i_service_ipc_interface_code.h" #include "i_service_reverse.h" #include "iremote_broker.h" namespace OHOS::FileManagement::Backup { class IService : public IRemoteBroker { public: - enum { - SERVICE_CMD_INIT_RESTORE_SESSION, - SERVICE_CMD_INIT_BACKUP_SESSION, - SERVICE_CMD_GET_LOCAL_CAPABILITIES, - SERVICE_CMD_PUBLISH_FILE, - SERVICE_CMD_APP_FILE_READY, - SERVICE_CMD_APP_DONE, - SERVICE_CMD_START, - SERVICE_CMD_GET_FILE_NAME, - SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, - SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, - SERVICE_CMD_FINISH, - }; - virtual ErrCode InitRestoreSession(sptr remote) = 0; virtual ErrCode InitBackupSession(sptr remote) = 0; virtual ErrCode Start() = 0; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h new file mode 100644 index 000000000..797921043 --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H +#define OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H + +/*SAID: 5203*/ +namespace OHOS::FileManagement::Backup { +enum class IServiceInterfaceCode { + SERVICE_CMD_INIT_RESTORE_SESSION, + SERVICE_CMD_INIT_BACKUP_SESSION, + SERVICE_CMD_GET_LOCAL_CAPABILITIES, + SERVICE_CMD_PUBLISH_FILE, + SERVICE_CMD_APP_FILE_READY, + SERVICE_CMD_APP_DONE, + SERVICE_CMD_START, + SERVICE_CMD_GET_FILE_NAME, + SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, + SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, + SERVICE_CMD_FINISH, +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h index 859773963..0d0f9a7fe 100644 --- 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 @@ -18,6 +18,7 @@ #include +#include "i_service_reverse_ipc_interface_code.h" #include "iremote_broker.h" namespace OHOS::FileManagement::Backup { @@ -29,18 +30,6 @@ public: RESTORE, }; - enum { - SERVICER_BACKUP_ON_FILE_READY, - SERVICER_BACKUP_ON_SUB_TASK_STARTED, - SERVICER_BACKUP_ON_SUB_TASK_FINISHED, - SERVICER_BACKUP_ON_TASK_FINISHED, - - SERVICER_RESTORE_ON_SUB_TASK_STARTED, - SERVICER_RESTORE_ON_SUB_TASK_FINISHED, - SERVICER_RESTORE_ON_TASK_FINISHED, - SERVICER_RESTORE_ON_FILE_READY, - }; - public: virtual void BackupOnFileReady(std::string bundleName, std::string fileName, int fd) = 0; virtual void BackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h new file mode 100644 index 000000000..5fc63b67e --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_IPC_INTERFACE_CODE_H +#define OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_IPC_INTERFACE_CODE_H + +/*SAID: 5203*/ +namespace OHOS::FileManagement::Backup { +enum class IServiceReverseInterfaceCode { + SERVICER_BACKUP_ON_FILE_READY, + SERVICER_BACKUP_ON_SUB_TASK_STARTED, + SERVICER_BACKUP_ON_SUB_TASK_FINISHED, + SERVICER_BACKUP_ON_TASK_FINISHED, + SERVICER_RESTORE_ON_SUB_TASK_STARTED, + SERVICER_RESTORE_ON_SUB_TASK_FINISHED, + SERVICER_RESTORE_ON_TASK_FINISHED, + SERVICER_RESTORE_ON_FILE_READY, +}; + +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_I_SERVICE_REVERSE_IPC_INTERFACE_CODE_H \ 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 index 26cfa7748..6dd0e4100 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -16,6 +16,7 @@ #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 { @@ -24,6 +25,7 @@ using namespace std; void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd) { HILOGI("Begin"); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || !data.WriteFileDescriptor(fd)) { @@ -32,7 +34,8 @@ void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_BACKUP_ON_FILE_READY, data, reply, 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)); } @@ -41,6 +44,7 @@ void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) { HILOGI("Begin"); + 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); @@ -48,7 +52,9 @@ void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleNa MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_BACKUP_ON_SUB_TASK_STARTED, data, reply, 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)); } @@ -57,6 +63,7 @@ void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleNa void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) { HILOGI("Begin"); + 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); @@ -64,7 +71,9 @@ void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleN MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_BACKUP_ON_SUB_TASK_FINISHED, data, reply, 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)); } @@ -73,6 +82,7 @@ void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleN void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) { HILOGI("Begin"); + 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); @@ -80,7 +90,8 @@ void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_BACKUP_ON_TASK_FINISHED, data, reply, 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)); } @@ -89,6 +100,7 @@ void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) { HILOGI("Begin"); + 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); @@ -96,7 +108,9 @@ void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleN MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_RESTORE_ON_SUB_TASK_STARTED, data, reply, 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)); } @@ -105,6 +119,7 @@ void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleN void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) { HILOGI("Begin"); + 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); @@ -112,7 +127,9 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_RESTORE_ON_SUB_TASK_FINISHED, data, reply, 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)); } @@ -121,6 +138,7 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) { HILOGI("Begin"); + 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); @@ -128,7 +146,9 @@ void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_RESTORE_ON_TASK_FINISHED, data, reply, 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)); } @@ -137,6 +157,7 @@ void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd) { HILOGI("Begin"); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) || !data.WriteFileDescriptor(fd)) { @@ -145,7 +166,8 @@ void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest(IServiceReverse::SERVICER_RESTORE_ON_FILE_READY, data, reply, 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)); } diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 5d1ccce4e..7acaf4e84 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -33,17 +33,25 @@ using namespace std; ServiceStub::ServiceStub() { - opToInterfaceMap_[SERVICE_CMD_INIT_RESTORE_SESSION] = &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[SERVICE_CMD_INIT_BACKUP_SESSION] = &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[SERVICE_CMD_GET_LOCAL_CAPABILITIES] = &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[SERVICE_CMD_PUBLISH_FILE] = &ServiceStub::CmdPublishFile; - opToInterfaceMap_[SERVICE_CMD_APP_FILE_READY] = &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[SERVICE_CMD_APP_DONE] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[SERVICE_CMD_START] = &ServiceStub::CmdStart; - opToInterfaceMap_[SERVICE_CMD_GET_FILE_NAME] = &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION] = &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION] = &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[SERVICE_CMD_FINISH] = &ServiceStub::CmdFinish; + 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_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_BACKUP_SESSION)] = + &ServiceStub::CmdAppendBundlesBackupSession; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; } int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 24f535fd3..55cbe9741 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -16,6 +16,7 @@ #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" @@ -26,6 +27,7 @@ using namespace std; UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName) { HILOGI("Start"); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; data.WriteInterfaceToken(GetDescriptor()); @@ -36,7 +38,8 @@ UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName) MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IExtension::CMD_GET_FILE_HANDLE, data, reply, 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); @@ -50,12 +53,14 @@ UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName) ErrCode SvcExtensionProxy::HandleClear() { 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(IExtension::CMD_HANDLE_CLAER, data, reply, 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); @@ -68,12 +73,14 @@ ErrCode SvcExtensionProxy::HandleClear() ErrCode SvcExtensionProxy::HandleBackup() { 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(IExtension::CMD_HANDLE_BACKUP, data, reply, 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); @@ -86,6 +93,7 @@ ErrCode SvcExtensionProxy::HandleBackup() ErrCode SvcExtensionProxy::PublishFile(const string &fileName) { HILOGI("Start"); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; data.WriteInterfaceToken(GetDescriptor()); @@ -96,7 +104,8 @@ ErrCode SvcExtensionProxy::PublishFile(const string &fileName) MessageParcel reply; MessageOption option; - int32_t ret = Remote()->SendRequest(IExtension::CMD_PUBLISH_FILE, data, reply, 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); diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 8581b2cd4..07e131cac 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -25,17 +25,25 @@ using namespace std; ServiceStub::ServiceStub() { - opToInterfaceMap_[SERVICE_CMD_INIT_RESTORE_SESSION] = &ServiceStub::CmdInitRestoreSession; - opToInterfaceMap_[SERVICE_CMD_INIT_BACKUP_SESSION] = &ServiceStub::CmdInitBackupSession; - opToInterfaceMap_[SERVICE_CMD_GET_LOCAL_CAPABILITIES] = &ServiceStub::CmdGetLocalCapabilities; - opToInterfaceMap_[SERVICE_CMD_PUBLISH_FILE] = &ServiceStub::CmdPublishFile; - opToInterfaceMap_[SERVICE_CMD_APP_FILE_READY] = &ServiceStub::CmdAppFileReady; - opToInterfaceMap_[SERVICE_CMD_APP_DONE] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[SERVICE_CMD_START] = &ServiceStub::CmdStart; - opToInterfaceMap_[SERVICE_CMD_GET_FILE_NAME] = &ServiceStub::CmdGetFileHandle; - opToInterfaceMap_[SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION] = &ServiceStub::CmdAppendBundlesRestoreSession; - opToInterfaceMap_[SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION] = &ServiceStub::CmdAppendBundlesBackupSession; - opToInterfaceMap_[SERVICE_CMD_FINISH] = &ServiceStub::CmdFinish; + 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_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_BACKUP_SESSION)] = + &ServiceStub::CmdAppendBundlesBackupSession; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; } int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index 783a5006c..c3f41057d 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -84,8 +84,10 @@ HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_BackupOnFileReady UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); data.WriteFileDescriptor(fd); - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_BACKUP_ON_FILE_READY, data, reply, option)); + 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."; @@ -119,7 +121,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_BACKUP_ON_SUB_TASK_STARTED, data, reply, option)); + 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."; @@ -153,7 +157,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_BACKUP_ON_SUB_TASK_FINISHED, data, reply, option)); + 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."; @@ -186,7 +192,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_BACKUP_ON_TASK_FINISHED, data, reply, option)); + 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."; @@ -220,7 +228,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_RESTORE_ON_SUB_TASK_STARTED, data, reply, option)); + 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."; @@ -254,7 +264,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_RESTORE_ON_SUB_TASK_FINISHED, data, reply, option)); + 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."; @@ -287,7 +299,9 @@ HWTEST_F(ServiceReverseStubTest, EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_RESTORE_ON_TASK_FINISHED, data, reply, option)); + 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."; @@ -323,8 +337,10 @@ HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_RestoreOnFileRead UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); data.WriteFileDescriptor(fd); - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IServiceReverse::SERVICER_RESTORE_ON_FILE_READY, data, reply, option)); + 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."; @@ -352,8 +368,10 @@ HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_error_0100, testi 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(IServiceReverse::SERVICER_RESTORE_ON_FILE_READY, 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."; 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 462f67543..58dc485d8 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -98,8 +98,10 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitRestoreSession_0100, tes sptr remote = sptr(new ServiceReverseMock()); EXPECT_TRUE(data.WriteRemoteObject(remote->AsObject().GetRefPtr())); - EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_INIT_RESTORE_SESSION, data, reply, option)); + EXPECT_EQ( + BError(BError::Codes::OK), + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_RESTORE_SESSION), + data, reply, option)); remote = nullptr; } catch (...) { EXPECT_TRUE(false); @@ -132,7 +134,8 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_InitBackupSession_0100, test EXPECT_TRUE(data.WriteRemoteObject(remote->AsObject().GetRefPtr())); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_INIT_BACKUP_SESSION, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_INIT_BACKUP_SESSION), + data, reply, option)); remote = nullptr; } catch (...) { EXPECT_TRUE(false); @@ -161,7 +164,9 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_Start_0100, testing::ext::Te MessageOption option; EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); - EXPECT_EQ(BError(BError::Codes::OK), service.OnRemoteRequest(IService::SERVICE_CMD_START, data, reply, option)); + EXPECT_EQ(BError(BError::Codes::OK), + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), data, reply, + option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by Start."; @@ -193,15 +198,19 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_GetLocalCapabilities_0100, t EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); - EXPECT_EQ(BError(BError::Codes::OK), - serviceSptr->OnRemoteRequest(IService::SERVICE_CMD_GET_LOCAL_CAPABILITIES, data, reply, option)); + EXPECT_EQ( + BError(BError::Codes::OK), + serviceSptr->OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), data, reply, option)); UniqueFd fd(reply.ReadFileDescriptor()); EXPECT_GT(fd, BError(BError::Codes::OK)); GTEST_LOG_(INFO) << "ServiceStubTest-CmdGetLocalCapabilities Brances"; MessageParcel brances; EXPECT_TRUE(brances.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_NE(BError(BError::Codes::OK), - serviceSptr->OnRemoteRequest(IService::SERVICE_CMD_GET_LOCAL_CAPABILITIES, brances, reply, option)); + serviceSptr->OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES), brances, reply, + option)); serviceSptr = nullptr; } catch (...) { EXPECT_TRUE(false); @@ -233,7 +242,8 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_PublishFile_0100, testing::e EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_TRUE(data.WriteParcelable(&fileInfo)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_PUBLISH_FILE, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE), data, + reply, option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by PublishFile."; @@ -268,13 +278,15 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppFileReady_0100, testing:: EXPECT_TRUE(data.WriteString(FILE_NAME)); EXPECT_TRUE(data.WriteFileDescriptor(fd)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_APP_FILE_READY, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), + data, reply, option)); GTEST_LOG_(INFO) << "ServiceStubTest-begin-CmdAppFileReady Brances"; MessageParcel brances; EXPECT_TRUE(brances.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_TRUE(brances.WriteString(FILE_NAME)); EXPECT_NE(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_APP_FILE_READY, brances, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_FILE_READY), + brances, reply, option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by AppFileReady."; @@ -304,7 +316,8 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppDone_0100, testing::ext:: EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_TRUE(data.WriteInt32(BError(BError::Codes::OK))); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_APP_DONE, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), data, + reply, option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by AppDone."; @@ -336,7 +349,8 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_GetFileHandle_0100, testing: EXPECT_TRUE(data.WriteString(BUNDLE_NAME)); EXPECT_TRUE(data.WriteString(FILE_NAME)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_GET_FILE_NAME, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME), data, + reply, option)); EXPECT_NE(BError(BError::Codes::OK), service.OnRemoteRequest(3333, data, reply, option)); } catch (...) { EXPECT_TRUE(false); @@ -374,7 +388,9 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_ EXPECT_TRUE(data.WriteFileDescriptor(fd)); EXPECT_TRUE(data.WriteStringVector(bundleNames)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, data, reply, option)); + service.OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, + reply, option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by AppendBundlesRestoreSession."; @@ -407,7 +423,9 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppendBundlesBackupSession_0 EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_TRUE(data.WriteStringVector(bundleNames)); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, data, reply, option)); + service.OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION), data, + reply, option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by AppendBundlesBackupSession."; @@ -436,7 +454,8 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_Finish_0100, testing::ext::T EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); EXPECT_EQ(BError(BError::Codes::OK), - service.OnRemoteRequest(IService::SERVICE_CMD_FINISH, data, reply, option)); + service.OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), data, reply, + option)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by Finish."; -- Gitee