From 57cffc73974eec4f499338a08f6265276a06378f Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Mon, 30 Dec 2024 11:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96,=E5=8E=BBt?= =?UTF-8?q?hrow=20part3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../src/service_incremental_reverse.cpp | 62 +-- .../backup_kit_inner/src/service_reverse.cpp | 62 +-- .../backup_kit_inner/impl/i_service_reverse.h | 48 +-- .../backup_sa/include/module_ipc/service.h | 33 ++ .../module_ipc/service_reverse_proxy.h | 48 +-- .../service_incremental_reverse_proxy.cpp | 163 +++++--- .../src/module_ipc/service_reverse_proxy.cpp | 177 ++++---- .../backup_sa/src/module_ipc/sub_service.cpp | 379 ++++++++++++++++++ .../src/module_ipc/svc_session_manager.cpp | 3 +- 9 files changed, 743 insertions(+), 232 deletions(-) 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 ba1e761c5..6d428b78e 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -22,128 +22,140 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, +ErrCode ServiceReverse::IncrementalBackupOnFileReady(string bundleName, 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_INVAL_ARG); } 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, 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_INVAL_ARG); } callbacksIncrementalBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnResultReport(std::string result, 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_INVAL_ARG); } callbacksIncrementalBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, 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_INVAL_ARG); } 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_INVAL_ARG); } callbacksIncrementalBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalBackupOnProcessInfo(std::string bundleName, 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_INVAL_ARG); } callbacksIncrementalBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleStarted(int32_t errCode, 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_INVAL_ARG); } callbacksIncrementalRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::IncrementalRestoreOnBundleFinished(int32_t errCode, 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_INVAL_ARG); } 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_INVAL_ARG); } callbacksIncrementalRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, +ErrCode ServiceReverse::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode) { if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); - return; + return BError(BError::Codes::SA_INVAL_ARG); } 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(std::string result, 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_INVAL_ARG); } 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_INVAL_ARG); } callbacksIncrementalRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::IncrementalRestoreOnProcessInfo(std::string bundleName, 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_INVAL_ARG); } callbacksIncrementalRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BIncrementalBackupSession::Callbacks callbacks) diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 6328cb70e..b0eff1b02 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -21,128 +21,140 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverse::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::BackupOnFileReady(string bundleName, 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_INVAL_ARG); } 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, 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_INVAL_ARG); } callbacksBackup_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnResultReport(std::string result, std::string bundleName) +ErrCode ServiceReverse::BackupOnResultReport(std::string result, 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_INVAL_ARG); } callbacksBackup_.onResultReport(bundleName, result); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::BackupOnBundleFinished(int32_t errCode, 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_INVAL_ARG); } 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_INVAL_ARG); } callbacksBackup_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::BackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::BackupOnProcessInfo(std::string bundleName, 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_INVAL_ARG); } callbacksBackup_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleStarted(int32_t errCode, 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_INVAL_ARG); } callbacksRestore_.onBundleStarted(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode ServiceReverse::RestoreOnBundleFinished(int32_t errCode, 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_INVAL_ARG); } 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_INVAL_ARG); } callbacksRestore_.onAllBundlesFinished(errCode); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode ServiceReverse::RestoreOnFileReady(string bundleName, 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_INVAL_ARG); } 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(string result, std::string bundleName, ErrCode errCode) { HILOGI("ServiceReverse RestoreOnResultReport bundle %{public}s begin with result: %{public}s", bundleName.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_INVAL_ARG); } 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_INVAL_ARG); } callbacksRestore_.onBundleFinished(errCode, bundleName); + return BError(BError::Codes::OK); } -void ServiceReverse::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode ServiceReverse::RestoreOnProcessInfo(std::string bundleName, 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_INVAL_ARG); } callbacksRestore_.onProcess(bundleName, processInfo); + return BError(BError::Codes::OK); } ServiceReverse::ServiceReverse(BSessionBackup::Callbacks callbacks) 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 52311dde5..7633a9405 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 @@ -33,39 +33,39 @@ public: 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 ErrCode BackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; + virtual ErrCode BackupOnResultReport(std::string result, std::string bundleName) = 0; + virtual ErrCode BackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode BackupOnAllBundlesFinished(int32_t errCode) = 0; + virtual ErrCode BackupOnProcessInfo(std::string bundleName, std::string processInfo) = 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, + virtual ErrCode RestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) = 0; + virtual ErrCode 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 ErrCode RestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode RestoreOnAllBundlesFinished(int32_t errCode) = 0; + virtual ErrCode 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, + virtual ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode 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 ErrCode IncrementalBackupOnResultReport(std::string result, std::string bundleName) = 0; + virtual ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) = 0; + virtual ErrCode IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) = 0; - virtual void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; - virtual void IncrementalRestoreOnFileReady(std::string bundleName, + virtual ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, int32_t errCode) = 0; - virtual void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, + virtual ErrCode 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; + virtual ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; + virtual ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) = 0; + virtual ErrCode IncrementalRestoreOnProcessInfo(const std::string bundleName, const std::string processInfo) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IServiceReverse") }; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index fef2dbdbb..bbe9ad074 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -580,6 +580,39 @@ private: ErrCode HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup); void StartCurBundleBackupOrRestore(const std::string &bundleName); + + sptr GetServiceReverseProxy(); + + ErrCode ReverseBackupOnBundleStarted(int32_t errCode, std::string bundleName); + ErrCode ReverseBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode); + ErrCode ReverseBackupOnResultReport(std::string result, std::string bundleName); + ErrCode ReverseBackupOnBundleFinished(int32_t errCode, std::string bundleName); + ErrCode ReverseBackupOnAllBundlesFinished(int32_t errCode); + ErrCode ReverseBackupOnProcessInfo(std::string bundleName, std::string processInfo); + + ErrCode ReverseRestoreOnBundleStarted(int32_t errCode, std::string bundleName); + ErrCode ReverseRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode); + ErrCode ReverseRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode = 0); + ErrCode ReverseRestoreOnBundleFinished(int32_t errCode, std::string bundleName); + ErrCode ReverseRestoreOnAllBundlesFinished(int32_t errCode); + ErrCode ReverseRestoreOnProcessInfo(std::string bundleName, std::string processInfo); + + ErrCode ReverseIncBackupOnBundleStarted(int32_t errCode, std::string bundleName); + ErrCode ReverseIncBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + int32_t errCode); + ErrCode ReverseIncBackupOnResultReport(std::string result, std::string bundleName); + ErrCode ReverseIncBackupOnBundleFinished(int32_t errCode, std::string bundleName); + ErrCode ReverseIncBackupOnAllBundlesFinished(int32_t errCode); + ErrCode ReverseIncBackupOnProcessInfo(std::string bundleName, std::string processInfo); + + ErrCode ReverseIncRestoreOnBundleStarted(int32_t errCode, std::string bundleName); + ErrCode ReverseIncRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + int32_t errCode); + ErrCode ReverseIncRestoreOnResultReport(std::string result, std::string bundleName, + ErrCode errCode = 0); + ErrCode ReverseIncRestoreOnBundleFinished(int32_t errCode, std::string bundleName); + ErrCode ReverseIncRestoreOnAllBundlesFinished(int32_t errCode); + ErrCode ReverseIncRestoreOnProcessInfo(std::string bundleName, std::string processInfo); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h index 3e6667d8d..a6a199f42 100644 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ b/services/backup_sa/include/module_ipc/service_reverse_proxy.h @@ -22,37 +22,37 @@ 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; + ErrCode BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; + ErrCode BackupOnResultReport(std::string result, std::string bundleName) override; + ErrCode BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode BackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode BackupOnProcessInfo(std::string bundleName, std::string processInfo) 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 RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; + ErrCode 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; + ErrCode RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode 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, + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode 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; + ErrCode IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; + ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode IncrementalRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, int32_t errCode) override; - void IncrementalRestoreOnResultReport(std::string result, std::string bundleName, + ErrCode 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; + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override; + ErrCode IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; public: explicit ServiceReverseProxy(const sptr &impl) : IRemoteProxy(impl) {} 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 index 39a525173..fbece745c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp @@ -23,7 +23,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, +ErrCode ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode) { BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); @@ -36,184 +36,220 @@ void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string !data.WriteString(fileName) || !data.WriteBool(fdFlag) || (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); + HILOGE("Incremental backup fileReady fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup fileReady fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Incremental backup on bundle start fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); }; MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup on bundle start fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), + ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalBackupOnResultReport(std::string result, std::string bundleName) +ErrCode 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); + HILOGE("Incremental backup on result report fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); }; MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup on result report fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), + ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Incremental backup on bundle finish fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup on bundle finish fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), + ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +ErrCode 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); + HILOGE("Incremental backup on all bundle finish fail, Ipc error"); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup on all bundle finish fail, ret:%{public}d", ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode 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); + HILOGE("Incremental backup on process fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental backup on process fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Incremental restore on bundle start fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on bundle start fail, bundleName:%{public}s, ret:%{public}d", + bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Incremental restore on bundle finish fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on bundle finish fail, bundleName:%{public}s, ret:%{public}d", + bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +ErrCode 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); + HILOGE("Incremental restore on all bundle finish fail, Ipc error"); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on all bundle finish fail, ret:%{public}d", ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnResultReport(std::string result, +ErrCode 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); + HILOGE("Incremental restore on result report fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on result report fail, bundleName:%{public}s, ret:%{public}d", + bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, +ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode) { BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); @@ -223,34 +259,41 @@ void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, strin !data.WriteString(fileName) || !data.WriteBool(fdFlag) || (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) || !data.WriteInt32(errCode)) { - throw BError(BError::Codes::SA_BROKEN_IPC); + HILOGE("Incremental restore on file ready fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on file ready fail, bundleName:%{public}s, ret:%{public}d", + bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode 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); + HILOGE("Incremental restore on process fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Incremental restore on process fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } } // 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 index efe357b20..c0c863d49 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -22,220 +22,251 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode 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); + HILOGE("Full backup on fileReady failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Full backup on fileReady failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Full backup on bundle start failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full backup bundle start failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::BackupOnResultReport(std::string result, std::string bundleName) +ErrCode 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); + HILOGE("Full backup on result report failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full backup on result report failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Full backup on bundle finished failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full backup on bundle finish failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) +ErrCode 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); + HILOGE("Full backup on all bundle finished failed, Ipc error"); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Full backup on all bundle finish failed, ret:%{public}d", ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode 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); + HILOGE("Full backup on process failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Full backup on process failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Full restore on bundle start failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full restore on bundle start failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) +ErrCode 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); + HILOGE("Full restore on bundle finish failed, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + option); + if (ret != ERR_OK) { + HILOGE("Full restore on bundle finished failed, bundleName:%{public}s, ret:%{public}d", + bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) +ErrCode 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); + HILOGE("Full restore on all bundle finish failed, Ipc error"); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full restore on all bundle finish failed, ret:%{public}d", ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +ErrCode 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); + HILOGE("Full restore on fileReady fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Full restore on fileReady fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode) +ErrCode 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); + HILOGE("Full restore on result report fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return 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)); + ErrCode ret = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), data, reply, option); + if (ret != ERR_OK) { + HILOGE("Full restore on result report fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) +ErrCode 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); + HILOGE("Full restore on process fail, Ipc error, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_BROKEN_IPC); } MessageParcel reply; MessageOption option; - if (int err = Remote()->SendRequest( + ErrCode ret = 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)); + if (ret != ERR_OK) { + HILOGE("Full restore on process fail, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BROKEN_IPC); } + return BError(BError::Codes::OK); } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 71f25b5ac..08e225762 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -61,6 +61,7 @@ #include "parameter.h" #include "parameters.h" #include "system_ability_definition.h" +#include "service.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -622,4 +623,382 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName } return BError(BError::Codes::OK); } + +sptr Service::GetServiceReverseProxy() +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty"); + return nullptr; + } + return session_->GetServiceReverseProxy(); +} + +ErrCode Service::ReverseBackupOnBundleStarted(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnBundleStarted(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnFileReady(std::string bundleName, std::string fileName, + int fd, int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnFileReady(bundleName, fileName, fd, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, fileName:%{public}s, ret:%{public}d", bundleName.c_str(), + GetAnonyPath(fileName).c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnResultReport(std::string result, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnResultReport(result, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnBundleFinished(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnBundleFinished(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnAllBundlesFinished(int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnAllBundlesFinished(errCode); + if (ret != ERR_OK) { + HILOGE("Error, ret:%{public}d", ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnProcessInfo(std::string bundleName, + std::string processInfo) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->BackupOnProcessInfo(bundleName, processInfo); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnBundleStarted(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnBundleStarted(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnFileReady(std::string bundleName, std::string fileName, + int fd, int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnFileReady(bundleName, fileName, fd, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnResultReport(std::string result, std::string bundleName, + ErrCode errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnResultReport(result, bundleName, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnBundleFinished(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnBundleFinished(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnAllBundlesFinished(int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnAllBundlesFinished(errCode); + if (ret != ERR_OK) { + HILOGE("Error, errCode:%{public}d, ret:%{public}d", errCode, ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnProcessInfo(std::string bundleName, + std::string processInfo) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->RestoreOnProcessInfo(bundleName, processInfo); + if (ret != ERR_OK) { + HILOGE("Error, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +// 增量 +ErrCode Service::ReverseIncBackupOnBundleStarted(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnBundleStarted(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnFileReady(std::string bundleName, std::string fileName, + int fd, int manifestFd, int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnFileReady(bundleName, fileName, fd, manifestFd, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnResultReport(std::string result, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnResultReport(result, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnBundleFinished(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnBundleFinished(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnAllBundlesFinished(int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnAllBundlesFinished(errCode); + if (ret != ERR_OK) { + HILOGE("Error, errCode is:%{public}d, ret:%{public}d", errCode, ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnProcessInfo(std::string bundleName, std::string processInfo) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalBackupOnProcessInfo(bundleName, processInfo); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnBundleStarted(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnBundleStarted(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, + int manifestFd, int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnFileReady(bundleName, fileName, fd, manifestFd, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnResultReport(result, bundleName, errCode); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnBundleFinished(int32_t errCode, std::string bundleName) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnBundleFinished(errCode, bundleName); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnAllBundlesFinished(int32_t errCode) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnAllBundlesFinished(errCode); + if (ret != ERR_OK) { + HILOGE("Error, errCode is:%{public}d, ret:%{public}d", errCode, ret); + return ret; + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +{ + auto reverseProxy = GetServiceReverseProxy(); + if (reverseProxy == nullptr) { + HILOGE("Error, reverse proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto ret = reverseProxy->IncrementalRestoreOnProcessInfo(bundleName, processInfo); + if (ret != ERR_OK) { + HILOGE("Error, bundleName is:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return ret; + } + return BError(BError::Codes::OK); +} } \ No newline at end of file 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 7ea412d1b..28d35a648 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -155,7 +155,8 @@ sptr SvcSessionManager::GetServiceReverseProxy() { unique_lock lock(lock_); if (!impl_.clientProxy) { - throw BError(BError::Codes::SA_REFUSED_ACT, "Try to deactive an empty session"); + HILOGE("Get serviceReverseProxy error, client proxy is empty"); + return nullptr; } return impl_.clientProxy; } -- Gitee