diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 5b2434fe8d3672b80f1ca24fdafc8b0227e729d1..b822b23f4baad01c1d4e372b757c0f41afa29562 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -19,12 +19,14 @@ #include #include #include +#include #include "b_json/b_json_entity_extension_config.h" #include "b_resources/b_constants.h" #include "ext_backup_js.h" #include "ext_extension_stub.h" #include "thread_pool.h" +#include "unique_fd.h" namespace OHOS::FileManagement::Backup { class BackupExtExtension : public ExtExtensionStub { @@ -34,6 +36,10 @@ public: ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleBackup() override; ErrCode HandleRestore() override; + ErrCode GetIncrementalFileHandle(const std::string &fileName) override; + ErrCode PublishIncrementalFile(const std::string &fileName) override; + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; + std::tuple GetIncrementalBackupFileHandle() override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h index 806bf85953c11777492c26ed5c51163ff30bd70f..97dabc07c6854d3ea5636703753181ba55ee8c86 100644 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ b/frameworks/native/backup_ext/include/ext_extension_stub.h @@ -36,6 +36,10 @@ private: 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 CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply); private: using ExtensionInterface = int32_t (ExtExtensionStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 2697e0413c6f57f5ea85a3a020d2adcf091c1d58..fad523b7ded160b5134fb1702ec9ea0f2ad13c31 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -126,6 +126,11 @@ UniqueFd BackupExtExtension::GetFileHandle(const string &fileName) } } +ErrCode BackupExtExtension::GetIncrementalFileHandle(const string &fileName) +{ + return ERR_OK; +} + ErrCode BackupExtExtension::HandleClear() { HILOGI("begin clear"); @@ -263,6 +268,11 @@ ErrCode BackupExtExtension::PublishFile(const string &fileName) } } +ErrCode BackupExtExtension::PublishIncrementalFile(const string &fileName) +{ + return ERR_OK; +} + ErrCode BackupExtExtension::HandleBackup() { string usrConfig = extension_->GetUsrConfig(); @@ -811,4 +821,14 @@ ErrCode BackupExtExtension::HandleRestore() return 0; } + +ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +{ + return 0; +} + +tuple BackupExtExtension::GetIncrementalBackupFileHandle() +{ + return {UniqueFd(-1), UniqueFd(-1)}; +} } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp index c98380a376c7e175ddfe1e36ea968c1b96d7a764..888099411b3d69b57fafa7b73e9be5179c5785eb 100644 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ b/frameworks/native/backup_ext/src/ext_extension_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -37,6 +37,14 @@ ExtExtensionStub::ExtExtensionStub() &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; } int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, @@ -128,4 +136,63 @@ ErrCode ExtExtensionStub::CmdHandleRestore(MessageParcel &data, MessageParcel &r } return BError(BError::Codes::OK); } + +ErrCode ExtExtensionStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("Begin"); + string fileName; + if (!data.ReadString(fileName)) { + return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive fileName").GetCode(); + } + + ErrCode res = GetIncrementalFileHandle(fileName); + if (!reply.WriteInt32(res)) { + 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) +{ + HILOGI("Begin"); + 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) +{ + HILOGI("Begin"); + 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::CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("Begin"); + 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); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index f0810e14a037ff8cc44e641e5f05b7274313398f..81707f8b2a6bd5cc1605405b787af7c099a51efc 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -18,6 +18,8 @@ #include "b_session_backup.h" #include "b_session_restore.h" +#include "b_incremental_backup_session.h" +#include "b_incremental_restore_session.h" #include "service_reverse_stub.h" namespace OHOS::FileManagement::Backup { @@ -33,16 +35,30 @@ public: void RestoreOnAllBundlesFinished(int32_t errCode) override; void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) override; + void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override; + void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; + void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; + void IncrementalBackupOnAllBundlesFinished(int32_t errCode) 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) override; + public: ServiceReverse() = delete; explicit ServiceReverse(BSessionRestore::Callbacks callbacks); explicit ServiceReverse(BSessionBackup::Callbacks callbacks); + explicit ServiceReverse(BIncrementalBackupSession::Callbacks callbacks); + explicit ServiceReverse(BIncrementalRestoreSession::Callbacks callbacks); ~ServiceReverse() override = default; private: Scenario scenario_ {Scenario::UNDEFINED}; BSessionBackup::Callbacks callbacksBackup_; BSessionRestore::Callbacks callbacksRestore_; + BIncrementalBackupSession::Callbacks callbacksIncrementalBackup_; + BIncrementalRestoreSession::Callbacks callbacksIncrementalRestore_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h index 5c46907b26353c54ba03bc29d3ffe32c85579ba6..650a7e784da1d050b0cfb004e887cdc9fe78bf66 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -43,6 +43,16 @@ private: int32_t CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); int32_t CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); int32_t CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); + + int32_t CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply); + int32_t CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); + int32_t CmdIncrementalBackupOnBundleFinished(MessageParcel &data, MessageParcel &reply); + int32_t CmdIncrementalBackupOnAllBundlesFinished(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); }; } // namespace OHOS::FileManagement::Backup 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 7cfcb79c0917c3da8e4c8b6e13ca28cea80f60cf..655822064656f6bf6913ffd1eb0db31d21337534 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -63,6 +63,30 @@ ServiceReverseStub::ServiceReverseStub() &ServiceReverseStub::CmdRestoreOnAllBundlesFinished; opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY)] = &ServiceReverseStub::CmdRestoreOnFileReady; + + 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_SUB_TASK_FINISHED)] = + &ServiceReverseStub::CmdIncrementalBackupOnBundleFinished; + opToInterfaceMap_[static_cast( + IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED)] = + &ServiceReverseStub::CmdIncrementalBackupOnAllBundlesFinished; + + opToInterfaceMap_[static_cast( + IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED)] = + &ServiceReverseStub::CmdIncrementalRestoreOnBundleStarted; + 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_FILE_READY)] = + &ServiceReverseStub::CmdIncrementalRestoreOnFileReady; } int32_t ServiceReverseStub::CmdBackupOnFileReady(MessageParcel &data, MessageParcel &reply) @@ -128,4 +152,70 @@ int32_t ServiceReverseStub::CmdRestoreOnFileReady(MessageParcel &data, MessagePa RestoreOnFileReady(bundleName, fileName, fd); return BError(BError::Codes::OK); } + +int32_t ServiceReverseStub::CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply) +{ + auto bundleName = data.ReadString(); + auto fileName = data.ReadString(); + int fd = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd); + 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::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::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 = data.ReadFileDescriptor(); + int manifestFd = data.ReadFileDescriptor(); + IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd); + 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 5d4dcbd28c4ef746e43e5a2c762d272637f4354e..5344759e56f4a2d98bf9d52987d995c53cd52c95 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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 @@ -46,6 +46,7 @@ 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_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", 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 ac9e5c09d6f4ed22293d823251031db80ad6ad99..d5c0d7b358c688e1d9117f845bd4f8642e210402 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -32,6 +32,10 @@ public: virtual ErrCode HandleBackup() = 0; virtual ErrCode PublishFile(const std::string &fileName) = 0; virtual ErrCode HandleRestore() = 0; + virtual ErrCode GetIncrementalFileHandle(const std::string &fileName) = 0; + virtual ErrCode PublishIncrementalFile(const std::string &fileName) = 0; + virtual ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) = 0; + virtual std::tuple GetIncrementalBackupFileHandle() = 0; }; } // namespace OHOS::FileManagement::Backup 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 index 50a8be51a62a99fe311d412127510651e11c1077..81eaf29f576cb3d709ec338026ffc9288cbabbeb 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -24,6 +24,10 @@ enum class IExtensionInterfaceCode { CMD_PUBLISH_FILE, CMD_HANDLE_BACKUP, CMD_HANDLE_RESTORE, + CMD_GET_INCREMENTAL_FILE_HANDLE, + CMD_PUBLISH_INCREMENTAL_FILE, + CMD_HANDLE_INCREMENTAL_BACKUP, + CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE, }; } // namespace OHOS::FileManagement::Backup 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 0d0f9a7fe709cb2bc30f9a2e057b0e444d507784..fbdf2408b961261ecc3d2f4ef48242974f9d9fce 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -41,6 +41,19 @@ public: virtual void RestoreOnAllBundlesFinished(int32_t errCode) = 0; virtual void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) = 0; + virtual void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) = 0; + virtual void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual void IncrementalBackupOnAllBundlesFinished(int32_t errCode) = 0; + + virtual void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual void IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual void IncrementalRestoreOnAllBundlesFinished(int32_t errCode) = 0; + virtual void IncrementalRestoreOnFileReady(std::string bundleName, + std::string fileName, + int fd, + int manifestFd) = 0; + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IServiceReverse") }; } // namespace OHOS::FileManagement::Backup 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 index 5fc63b67ecb9c67535e6bcd870de58d82a731016..b3300a21bb2033446d4e0682a4b4a1baf6797ed6 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -27,6 +27,14 @@ enum class IServiceReverseInterfaceCode { SERVICER_RESTORE_ON_SUB_TASK_FINISHED, SERVICER_RESTORE_ON_TASK_FINISHED, SERVICER_RESTORE_ON_FILE_READY, + SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY, + SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED, + SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED, + SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED, + SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED, + SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED, + SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED, + SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY, }; } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index e89cb1f28dd16d72ad8f3b6427789ec36326b5eb..381f44aa862e042b13079012b6f11927f3d6c594 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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 @@ -30,9 +30,11 @@ ohos_shared_library("backup_sa") { "src/module_external/bms_adapter.cpp", "src/module_external/sms_adapter.cpp", "src/module_ipc/service.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/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", diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h index 5fd75cb57fffe80a8d86cefbf5cf54b4569c2a24..401644b79c28c390ebdd8d2dd46d363a2f92545f 100644 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ b/services/backup_sa/include/module_ipc/service_reverse_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -32,6 +32,16 @@ public: void RestoreOnAllBundlesFinished(int32_t errCode) override; void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) override; + void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override; + void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; + void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; + void IncrementalBackupOnAllBundlesFinished(int32_t errCode) 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) override; + public: explicit ServiceReverseProxy(const sptr &impl) : IRemoteProxy(impl) {} ~ServiceReverseProxy() override = default; diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/services/backup_sa/include/module_ipc/svc_extension_proxy.h index b47ba5ded3853a8a47f9b5256d6056a4cc0e0d9a..f208cb2d487cbbc96fa067bf63d9094846e1343a 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/services/backup_sa/include/module_ipc/svc_extension_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -18,6 +18,7 @@ #include "i_extension.h" #include "iremote_proxy.h" +#include "unique_fd.h" namespace OHOS::FileManagement::Backup { class SvcExtensionProxy : public IRemoteProxy { @@ -27,6 +28,10 @@ public: ErrCode HandleBackup() override; ErrCode PublishFile(const std::string &fileName) override; ErrCode HandleRestore() override; + ErrCode GetIncrementalFileHandle(const std::string &fileName) override; + ErrCode PublishIncrementalFile(const std::string &fileName) override; + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; + std::tuple GetIncrementalBackupFileHandle() override; public: explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index 0f98e5e2e3ee68626493b10faf07cf46fb595abc..3123ee3d74c4c5935222c695dc8bd34ff46f24e1 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -35,4 +35,20 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) {} void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd) {} + +void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd) {} + +void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) {} + +void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) {} + +void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) {} + +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) {} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index 2403f2d2fb8f982329b618a6c61f531e5ab5ee53..a973df624d911706bf5fb3860725619c00952e60 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -42,4 +42,24 @@ ErrCode SvcExtensionProxy::HandleRestore() { return 0; } + +ErrCode SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) +{ + return 0; +} + +ErrCode SvcExtensionProxy::PublishIncrementalFile(const string &fileName) +{ + return 0; +} + +ErrCode SvcExtensionProxy::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +{ + return 0; +} + +tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() +{ + return {UniqueFd(-1), UniqueFd(-1)}; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index 71baea891c54c820e5671e1de93dbbf391f38360..84db4ecaf0eb3742472668d5343c4862fff3228f 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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 @@ -21,6 +21,7 @@ ohos_unittest("b_session_test") { "${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_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", "b_session_backup_test.cpp", 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 bc7ed16ebd3546d087eb513767e36a0a3da40a1c..b24f09103e477d879c262aa6472b98cb34bb9e92 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -97,6 +97,26 @@ public: return BError(BError::Codes::OK); }; + ErrCode GetIncrementalFileHandle(const std::string &fileName) override + { + return BError(BError::Codes::OK); + }; + + ErrCode PublishIncrementalFile(const std::string &fileName) override + { + return BError(BError::Codes::OK); + }; + + ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override + { + return BError(BError::Codes::OK); + }; + + std::tuple GetIncrementalBackupFileHandle() override + { + return {UniqueFd(-1), UniqueFd(-1)}; + }; + private: int32_t nHandleBackupNum_ = 0; }; 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 e4f6e2a2ad631f17f261727abc20b0cf6e0db567..bd08b8ce5c0c44e8af2b6b36624712010f1dea8f 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -45,6 +45,16 @@ public: 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) override {} + + void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override {} + void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} + void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} + void IncrementalBackupOnAllBundlesFinished(int32_t errCode) 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) override {} }; } // 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_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index c3f41057db2354130407f184a9035bcb89f0fa9b..6b2b6452fabb9c440a634a31d8159c2924f9d4ea 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -47,6 +47,14 @@ public: MOCK_METHOD2(RestoreOnBundleFinished, void(int32_t errCode, string bundleName)); MOCK_METHOD1(RestoreOnAllBundlesFinished, void(int32_t errCode)); MOCK_METHOD3(RestoreOnFileReady, void(string bundleName, string fileName, int fd)); + MOCK_METHOD4(IncrementalBackupOnFileReady, void(string bundleName, string fileName, int fd, int manifestFd)); + MOCK_METHOD2(IncrementalBackupOnBundleStarted, void(int32_t errCode, string bundleName)); + MOCK_METHOD2(IncrementalBackupOnBundleFinished, void(int32_t errCode, string bundleName)); + MOCK_METHOD1(IncrementalBackupOnAllBundlesFinished, void(int32_t errCode)); + 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_METHOD4(IncrementalRestoreOnFileReady, void(string bundleName, string fileName, int fd, int manifestFd)); }; class ServiceReverseStubTest : public testing::Test {