diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index 3ecb58eaba5dd9964310ca15013e99b5ab85b291..1767a1c1386347c13bf603a0fddf4333e7e366c6 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -25,37 +25,37 @@ namespace OHOS::FileManagement::Backup { class ServiceReverse final : public ServiceReverseStub { public: - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void BackupOnResultReport(std::string result, std::string bundleName) override; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void BackupOnAllBundlesFinished(int32_t errCode) override; - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; + ErrCode BackupOnBundleStarted(int32_t errCode, std::string bundleName) 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 RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; - void RestoreOnAllBundlesFinished(int32_t errCode) override; - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override; - void RestoreOnResultReport(std::string result, std::string bundleName, + ErrCode RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) 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 RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + ErrCode IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, int32_t errCode) override; - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override; - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override; - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override; - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) 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 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, + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override; + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) 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 IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; + ErrCode IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override; public: ServiceReverse() = delete; 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 ba1e761c5fd39867a97fe704e0efbfacb2b9d283..6d428b78e29868708b9581a76ea65327c4311b0a 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 6328cb70ea63730224ee61a943a8dba13482ed20..b0eff1b02ee50c308dd71c8ef28e90035a6d76b1 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 52311dde514d0a45fab11942877f2722f8c9cb1c..7633a94054a85b83c0e88ff29c0e5d5cbb24a68b 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 c2cdd6afbd8bfcc725ffcfd90e0913e3c9760162..810321f3dd5f9955cba17f6b607647b2b615deff 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -564,10 +564,41 @@ private: void SetBundleIncDataInfo(const std::vector &bundlesToBackup, std::vector &supportBundleNames); - + void CancelTask(std::string bundleName, wptr ptr); void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId); + + 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 3e6667d8d2164de1810494a428131faabc668b52..a6a199f42af5e3864eb686f0126cde8635cb07b2 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.cpp b/services/backup_sa/src/module_ipc/service.cpp index 35059ea9a7a29708a1f91026b57e2e7e2cf59ff0..8e01f1012301921415d6c2b50bf3fe6422544e7a 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -566,9 +566,9 @@ void Service::OnBundleStarted(BError error, sptr session, con IServiceReverse::Scenario scenario = session->GetScenario(); if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { - session->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(error, bundleName); + ReverseIncRestoreOnBundleStarted(error, bundleName); } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); + ReverseRestoreOnBundleStarted(error, bundleName); } BundleBeginRadarReport(bundleName, error.GetCode(), scenario); } @@ -951,15 +951,15 @@ ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, } SendEndAppGalleryNotify(callerName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); + ReverseRestoreOnResultReport(restoreRetInfo, callerName, errCode); NotifyCloneBundleFinish(callerName, sennario); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); + ReverseIncRestoreOnResultReport(restoreRetInfo, callerName, errCode); NotifyCloneBundleFinish(callerName, sennario); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, callerName); + ReverseBackupOnResultReport(restoreRetInfo, callerName); } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, callerName); + ReverseIncBackupOnResultReport(restoreRetInfo, callerName); } return BError(BError::Codes::OK); } catch (const BError &e) { @@ -980,14 +980,14 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string const ErrCode errCode, const BackupRestoreScenario sennario) { if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName); + ReverseRestoreOnResultReport(restoreRetInfo, bundleName); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName); + ReverseIncRestoreOnResultReport(restoreRetInfo, bundleName); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + ReverseBackupOnResultReport(restoreRetInfo, bundleName); + ReverseBackupOnBundleFinished(errCode, bundleName); } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); + ReverseIncBackupOnResultReport(restoreRetInfo, bundleName); } if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); @@ -1091,7 +1091,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetFileHandle", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } - session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + ReverseRestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); } else { session_->SetExtFileNameRequest(bundleName, fileName); @@ -1128,7 +1128,7 @@ void Service::ExtStart(const string &bundleName) } if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + ReverseBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { ClearSessionAndSchedInfo(bundleName); @@ -1140,14 +1140,14 @@ void Service::ExtStart(const string &bundleName) throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); } auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + ReverseRestoreOnBundleStarted(ret, bundleName); GetOldDeviceBackupVersion(); BundleBeginRadarReport(bundleName, ret, scenario); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (auto &fileName : fileNameVec) { int32_t errCode = 0; UniqueFd fd = proxy->GetFileHandle(fileName, errCode); - session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + ReverseRestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } } catch (...) { @@ -1177,21 +1177,21 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, return; } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + ReverseIncBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); + ReverseIncRestoreOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } else if (scenario == IServiceReverse::Scenario::BACKUP) { - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + ReverseBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + ReverseRestoreOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, @@ -1830,7 +1830,7 @@ ErrCode Service::BackupSA(std::string bundleName) } if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = saConnection->CallBackupSA(); - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + ReverseBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { HILOGI("BackupSA ret is %{public}d", ret); @@ -1839,7 +1839,7 @@ ErrCode Service::BackupSA(std::string bundleName) return BError(ret); } } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); + ReverseIncRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); } return BError(BError::Codes::OK); } @@ -1850,7 +1850,7 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std auto task = [bundleName, fd, result, errCode, this]() { HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", bundleName.c_str(), fd, result.c_str(), errCode); - session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); + ReverseBackupOnFileReady(bundleName, "", move(fd), errCode); FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); }; @@ -1916,7 +1916,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is Backup"); - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); + ReverseBackupOnBundleFinished(errCode, callerName); auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); auto ms = std::chrono::duration_cast(now.time_since_epoch()); @@ -1934,7 +1934,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN ); } else if (scenario == IServiceReverse::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); - session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); + ReverseRestoreOnBundleFinished(errCode, callerName); } BundleEndRadarReport(callerName, errCode, scenario); } @@ -1950,13 +1950,13 @@ ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupResto return ret; } if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnProcessInfo(bundleName, processInfo); + ReverseRestoreOnProcessInfo(bundleName, processInfo); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnProcessInfo(bundleName, processInfo); + ReverseIncRestoreOnProcessInfo(bundleName, processInfo); } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnProcessInfo(bundleName, processInfo); + ReverseBackupOnProcessInfo(bundleName, processInfo); } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnProcessInfo(bundleName, processInfo); + ReverseIncBackupOnProcessInfo(bundleName, processInfo); } return BError(BError::Codes::OK); } catch (const BError &e) { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 7a98a2fc38a24b70e145bfc6358a306fe7379368..c786487e10c4be30163b6cec15c3ab82e94179e0 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -524,17 +524,15 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f return ret; } if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), - move(manifestFd), errCode); + ErrCode ret = ReverseIncRestoreOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::RESTORE); - return BError(BError::Codes::OK); + return ret; } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } HILOGD("reverse: Will notify IncrementalBackupOnFileReady"); - session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), - move(manifestFd), errCode); + ErrCode ret = ReverseIncBackupOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::BACKUP); AuditLog auditLog = { false, "Backup File Ready", "ADD", "", 1, "SUCCESS", "AppIncrementalFileReady", callerName, GetAnonyPath(fileName) }; @@ -552,8 +550,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f session_->StopExtTimer(callerName); // 通知TOOL 备份完成 HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished"); - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), - callerName); + ret = ReverseIncBackupOnBundleFinished(BError(BError::Codes::OK), callerName); BundleEndRadarReport(callerName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); // 断开extension backUpConnection->DisconnectBackupExtAbility(); @@ -681,7 +678,7 @@ bool Service::IncrementalBackup(const string &bundleName) } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { auto ret = proxy->IncrementalOnBackup(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + ReverseIncBackupOnBundleStarted(ret, bundleName); BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::BACKUP); if (ret) { ClearSessionAndSchedInfo(bundleName); @@ -691,7 +688,7 @@ bool Service::IncrementalBackup(const string &bundleName) } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); + ReverseIncRestoreOnBundleStarted(ret, bundleName); std::string oldBackupVersion = session_->GetOldBackupVersion(); if (oldBackupVersion.empty()) { HILOGE("Failed to get backupVersion of old device"); @@ -715,7 +712,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is incremental backup"); - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, callerName); + ReverseIncBackupOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); @@ -733,7 +730,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string } else if (scenario == IServiceReverse::Scenario::RESTORE) { HILOGI("will notify clone data, scenario is Restore"); SendEndAppGalleryNotify(callerName); - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName); + ReverseIncRestoreOnBundleFinished(errCode, callerName); BundleEndRadarReport(callerName, errCode, scenario); } } diff --git a/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_incremental_reverse_proxy.cpp index 39a5251735fa091aae44b67af2269334bac5f19a..fbece745c06e9dc986246eee5ac96abe78dd7c75 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 efe357b202253a3788f67a905d1f49d1a625108d..c0c863d494d68addcd1f741c7f3fbb5f45c58281 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 774744f416536156b2bbf2e0e1ba3d7539b8e3d3..ee76d708e025371a383850aa2ebfb8b65bdb1666 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -160,7 +160,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } - session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); + ReverseBackupOnFileReady(callerName, fileName, move(fd), errCode); FileReadyRadarReport(callerName, fileName, errCode, session_->GetScenario()); if (session_->OnBundleFileReady(callerName, fileName)) { auto backUpConnection = session_->GetExtConnection(callerName); @@ -179,7 +179,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo session_->StopFwkTimer(callerName); session_->StopExtTimer(callerName); // 通知TOOL 备份完成 - session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); + ReverseBackupOnBundleFinished(BError(BError::Codes::OK), callerName); BundleEndRadarReport(callerName, BError(BError::Codes::OK), session_->GetScenario()); // 断开extension backUpConnection->DisconnectBackupExtAbility(); @@ -329,11 +329,9 @@ std::vector Service::GetSupportBackupBundleNames(vectorGetServiceReverseProxy()->IncrementalBackupOnBundleStarted( - BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + ReverseIncBackupOnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); } else { - session_->GetServiceReverseProxy()->BackupOnBundleStarted( - BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + ReverseBackupOnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); } BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), IServiceReverse::Scenario::BACKUP); @@ -372,11 +370,9 @@ void Service::HandleNotSupportBundleNames(const std::vector &srcBun } HILOGE("bundleName:%{public}s, can not find from supportBundleNames", bundleName.c_str()); if (isIncBackup) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted( - BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), bundleName); + ReverseIncBackupOnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), bundleName); } else { - session_->GetServiceReverseProxy()->BackupOnBundleStarted( - BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), bundleName); + ReverseBackupOnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), bundleName); } } } @@ -500,4 +496,470 @@ void Service::OnAllBundlesFinished(ErrCode errCode) } HILOGI("called end."); } + +ErrCode Service::ReverseBackupOnBundleStarted(int32_t errCode, std::string bundleName) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, errCode:%{public}d", errCode); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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) +{ + if (session_ == nullptr) { + HILOGE("Error, session is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto reverseProxy = session_->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 0c76366328f2352a4de45ffd70ce0eb39eb0f087..ccd2090b7fce813d720b6e72e5c305bb49fb2957 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 service reverse proxy failed, No caller token was specified"); + return nullptr; } return impl_.clientProxy; } diff --git a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h index 8a74af4bd13a2c7e23aa36fc0d242d850fbc3c8b..ea86bb82c932484b6a83ca09c1b24f507d4ee389 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -25,30 +25,30 @@ namespace OHOS::FileManagement::Backup { class ServiceReverseProxyMock : public IRemoteProxy { public: MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); - MOCK_METHOD(void, BackupOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, BackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnResultReport, (std::string, std::string));; - MOCK_METHOD(void, BackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, BackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, BackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, RestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, RestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, RestoreOnFileReady, (std::string, std::string, int, int32_t)); - MOCK_METHOD(void, RestoreOnResultReport, (std::string, std::string, ErrCode)); - MOCK_METHOD(void, RestoreOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalBackupOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnResultReport, (std::string, std::string)); - MOCK_METHOD(void, IncrementalBackupOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalBackupOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalBackupOnProcessInfo, (std::string, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnBundleStarted, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnBundleFinished, (int32_t, std::string)); - MOCK_METHOD(void, IncrementalRestoreOnAllBundlesFinished, (int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnFileReady, (std::string, std::string, int, int, int32_t)); - MOCK_METHOD(void, IncrementalRestoreOnResultReport, (std::string, std::string, ErrCode));; - MOCK_METHOD(void, IncrementalRestoreOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(ErrCode, BackupOnFileReady, (std::string, std::string, int, int32_t)); + MOCK_METHOD(ErrCode, BackupOnBundleStarted, (int32_t, std::string)); + MOCK_METHOD(ErrCode, BackupOnResultReport, (std::string, std::string));; + MOCK_METHOD(ErrCode, BackupOnBundleFinished, (int32_t, std::string)); + MOCK_METHOD(ErrCode, BackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, BackupOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(ErrCode, RestoreOnBundleStarted, (int32_t, std::string)); + MOCK_METHOD(ErrCode, RestoreOnBundleFinished, (int32_t, std::string)); + MOCK_METHOD(ErrCode, RestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, RestoreOnFileReady, (std::string, std::string, int, int32_t)); + MOCK_METHOD(ErrCode, RestoreOnResultReport, (std::string, std::string, ErrCode)); + MOCK_METHOD(ErrCode, RestoreOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(ErrCode, IncrementalBackupOnFileReady, (std::string, std::string, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleStarted, (int32_t, std::string)); + MOCK_METHOD(ErrCode, IncrementalBackupOnResultReport, (std::string, std::string)); + MOCK_METHOD(ErrCode, IncrementalBackupOnBundleFinished, (int32_t, std::string)); + MOCK_METHOD(ErrCode, IncrementalBackupOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnProcessInfo, (std::string, std::string)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleStarted, (int32_t, std::string)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleFinished, (int32_t, std::string)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnAllBundlesFinished, (int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReady, (std::string, std::string, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnResultReport, (std::string, std::string, ErrCode));; + MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (std::string, std::string)); public: ServiceReverseProxyMock() : IRemoteProxy(nullptr) {} virtual ~ServiceReverseProxyMock() = default; diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 3cdecca0f4c207f92efddf7312b49b907529a813..4911385ebe657a8b4312ddcf3d767f565425dfd0 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -315,5 +315,115 @@ void Service::HandleNotSupportBundleNames(const vector&, vector& void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} +ErrCode Service::ReverseBackupOnBundleStarted(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnResultReport(std::string result, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnBundleFinished(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseBackupOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnBundleStarted(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnBundleFinished(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnBundleStarted(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnResultReport(std::string result, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnBundleFinished(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncBackupOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnBundleStarted(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnBundleFinished(int32_t errCode, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ReverseIncRestoreOnProcessInfo(std::string bundleName, std::string processInfo){ + return BError(BError::Codes::OK); +} void Service::CancelTask(std::string bundleName, wptr ptr) {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index 1b224076d31f04363b8035c384aa14f4a4214132..fb62b6f8f5af4cd38a653386d86878b6e35dbef3 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -20,53 +20,125 @@ namespace OHOS::FileManagement::Backup { using namespace std; -void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) {} - -void ServiceReverseProxy::RestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnResultReport(string result, std::string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) {} - -void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, - int32_t errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnResultReport(string result, string bundleName, ErrCode errCode) {} - -void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) {} +ErrCode ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnResultReport(string result, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnResultReport(string result, string bundleName, ErrCode errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnResultReport(string result, std::string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnResultReport(string result, string bundleName, ErrCode errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 7b1bf2f9b96749795245ae35d3dbf962146f7f45..f3478879c0d14ec1da969f8b0bc664d02e873d04 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 @@ -36,35 +36,35 @@ public: code_ = code; return BError(BError::Codes::OK); } - void BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void BackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void BackupOnResultReport(std::string result, std::string bundleName) override {}; - void BackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void BackupOnAllBundlesFinished(int32_t errCode) override {} - void BackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} + ErrCode BackupOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} + ErrCode BackupOnBundleStarted(int32_t errCode, std::string bundleName) 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 RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void RestoreOnAllBundlesFinished(int32_t errCode) override {} - void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd, int32_t errCode) override {} - void RestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {} - void RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} + ErrCode RestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} + ErrCode RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} + ErrCode RestoreOnAllBundlesFinished(int32_t errCode) 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) override {} + ErrCode RestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} - void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, + ErrCode IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd, int32_t errCode) override {} - void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnResultReport(std::string result, std::string bundleName) override {} - void IncrementalBackupOnBundleFinished(int32_t errCode, std::string bundleName) override {} - void IncrementalBackupOnAllBundlesFinished(int32_t errCode) override {} - void IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo) override {} + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) 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 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, + ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, std::string bundleName) override {} + ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} + ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) 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 errCode) override {}; - void IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) override {} + ErrCode IncrementalRestoreOnResultReport(std::string result, std::string bundleName, ErrCode errCode) override {}; + ErrCode IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo) 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 d5c75557cd2fa4b3e2140081a7e65b87be28b14b..c9a2db6b8bd6a579655bdbaaec35e9a2662d1f75 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 @@ -40,32 +40,32 @@ const string FILE_NAME_MANIFEST = "1.fr"; class MockServiceReverse final : public ServiceReverseStub { public: - MOCK_METHOD4(BackupOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD2(BackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(BackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(BackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(BackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(BackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_METHOD2(RestoreOnBundleStarted, void(int32_t errCode, std::string bundleName)); - MOCK_METHOD2(RestoreOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(RestoreOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD4(RestoreOnFileReady, void(string bundleName, string fileName, int fd, int32_t errCode)); - MOCK_METHOD3(RestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(RestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); + MOCK_METHOD4(BackupOnFileReady, ErrCode(string bundleName, string fileName, int fd, int32_t errCode)); + MOCK_METHOD2(BackupOnBundleStarted, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD2(BackupOnResultReport, ErrCode(string result, std::string bundleName)); + MOCK_METHOD2(BackupOnBundleFinished, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD1(BackupOnAllBundlesFinished, ErrCode(int32_t errCode)); + MOCK_METHOD2(BackupOnProcessInfo, ErrCode(std::string bundleName, std::string processInfo)); + MOCK_METHOD2(RestoreOnBundleStarted, ErrCode(int32_t errCode, std::string bundleName)); + MOCK_METHOD2(RestoreOnBundleFinished, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD1(RestoreOnAllBundlesFinished, ErrCode(int32_t errCode)); + MOCK_METHOD4(RestoreOnFileReady, ErrCode(string bundleName, string fileName, int fd, int32_t errCode)); + MOCK_METHOD3(RestoreOnResultReport, ErrCode(string result, string bundleName, ErrCode errCode)); + MOCK_METHOD2(RestoreOnProcessInfo, ErrCode(std::string bundleName, std::string processInfo)); MOCK_METHOD5(IncrementalBackupOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnBundleStarted, void(int32_t errCode, string bundleName)); - MOCK_METHOD2(IncrementalBackupOnResultReport, void(string result, std::string bundleName)); - MOCK_METHOD2(IncrementalBackupOnBundleFinished, void(int32_t errCode, string bundleName)); - MOCK_METHOD1(IncrementalBackupOnAllBundlesFinished, void(int32_t errCode)); - MOCK_METHOD2(IncrementalBackupOnProcessInfo, void(std::string bundleName, std::string processInfo)); - MOCK_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)); + ErrCode(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD2(IncrementalBackupOnBundleStarted, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD2(IncrementalBackupOnResultReport, ErrCode(string result, std::string bundleName)); + MOCK_METHOD2(IncrementalBackupOnBundleFinished, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD1(IncrementalBackupOnAllBundlesFinished, ErrCode(int32_t errCode)); + MOCK_METHOD2(IncrementalBackupOnProcessInfo, ErrCode(std::string bundleName, std::string processInfo)); + MOCK_METHOD2(IncrementalRestoreOnBundleStarted, ErrCode(int32_t errCode, std::string bundleName)); + MOCK_METHOD2(IncrementalRestoreOnBundleFinished, ErrCode(int32_t errCode, string bundleName)); + MOCK_METHOD1(IncrementalRestoreOnAllBundlesFinished, ErrCode(int32_t errCode)); MOCK_METHOD5(IncrementalRestoreOnFileReady, - void(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); - MOCK_METHOD3(IncrementalRestoreOnResultReport, void(string result, string bundleName, ErrCode errCode)); - MOCK_METHOD2(IncrementalRestoreOnProcessInfo, void(std::string bundleName, std::string processInfo)); + ErrCode(string bundleName, string fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD3(IncrementalRestoreOnResultReport, ErrCode(string result, string bundleName, ErrCode errCode)); + MOCK_METHOD2(IncrementalRestoreOnProcessInfo, ErrCode(std::string bundleName, std::string processInfo)); }; class ServiceReverseStubTest : public testing::Test { @@ -90,7 +90,7 @@ HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_BackupOnFileReady GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnFileReady_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, BackupOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(service, BackupOnFileReady(_, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -131,7 +131,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleStarted_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(service, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -167,7 +167,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnResultReport_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, BackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(service, BackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -202,7 +202,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnBundleFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(service, BackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -238,7 +238,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_BackupOnAllBundlesFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, BackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(service, BackupOnAllBundlesFinished(_)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -273,7 +273,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleStarted_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(service, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -309,7 +309,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnBundleFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(service, RestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -345,7 +345,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnAllBundlesFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, RestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(service, RestoreOnAllBundlesFinished(_)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -378,7 +378,7 @@ HWTEST_F(ServiceReverseStubTest, SUB_backup_ServiceReverseStub_RestoreOnFileRead GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnFileReady_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(service, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -460,7 +460,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnFileReady_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -506,7 +506,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleStarted_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -545,7 +545,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnResultReport_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -583,7 +583,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnBundleFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -623,7 +623,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalBackupOnAllBundlesFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalBackupOnAllBundlesFinished(_)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -660,7 +660,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleStarted_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -699,7 +699,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnBundleFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -738,7 +738,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnAllBundlesFinished_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalRestoreOnAllBundlesFinished(_)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -775,7 +775,7 @@ HWTEST_F(ServiceReverseStubTest, GTEST_LOG_(INFO) << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -820,7 +820,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(service, RestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; @@ -860,7 +860,7 @@ HWTEST_F(ServiceReverseStubTest, << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; try { MockServiceReverse service; - EXPECT_CALL(service, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(service, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); MessageParcel data; MessageParcel reply; MessageOption option; diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index a96d7c782bb42c7aac29538e685d1a9ada60a815..639431630f672f4aa24f0cb130a6df4aecda3e9d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -260,6 +260,117 @@ std::vector Service::GetSupportBackupBundleNames(vectorAppendBundlesIncrementalBackupSession({}), BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -663,13 +774,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ int32_t errCode = 0; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -678,7 +789,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -706,7 +817,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ int32_t errCode = 0; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); @@ -715,14 +826,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, HandleClear()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, StopFwkTimer(_)).WillOnce(Return(true)); EXPECT_CALL(*session, StopExtTimer(_)).WillOnce(Return(true)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -865,7 +976,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0000, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(0)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -876,7 +987,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0000, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, IncrementalOnBackup(_)).WillOnce(Return(1)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->IncrementalBackup(bundleName); EXPECT_TRUE(ret); @@ -931,7 +1042,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0100, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); ret = service->IncrementalBackup(bundleName); @@ -966,7 +1077,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_IncrementalBackup_0200, EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); @@ -1000,13 +1111,13 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_NotifyCallerCurAppIncrem EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->NotifyCallerCurAppIncrementDone(errCode, callerName); EXPECT_TRUE(true); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index c329924e44dc87782ca012da2763a383b380f4fa..ea45a9c53cdcd6b0601914dc8c0f0bdd08f58735 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -666,7 +666,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); @@ -674,7 +674,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); @@ -682,7 +682,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); } catch (...) { @@ -1623,7 +1623,7 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1633,7 +1633,7 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -1643,7 +1643,7 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetSAExtConnection(_)).WillOnce(Return(sa)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -1715,13 +1715,13 @@ HWTEST_F(ServiceTest, SUB_Service_NotifyCallerCurAppDone_0000, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->NotifyCallerCurAppDone(0, ""); EXPECT_TRUE(true); } catch (...) { @@ -1750,7 +1750,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnProcessInfo(_, _)).WillOnce(Return(BError(BError::Codes::OK))); auto ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1759,7 +1759,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnProcessInfo(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1768,7 +1768,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnProcessInfo(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1777,7 +1777,7 @@ HWTEST_F(ServiceTest, SUB_Service_ReportAppProcessInfo_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnProcessInfo(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->ReportAppProcessInfo(processInfo, BackupRestoreScenario::INCREMENTAL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index 80f110bdba21b162581b1c7614e2eea6cbdb924d..aa503ffe7aee3d5797014a2671d5207eac054aec 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -32,7 +32,7 @@ HWTEST_F(ServiceTest, SUB_Service_HandleCurGroupBackupInfos_0000, TestSize.Level map isClearDataFlags; EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*jsonUtil, FindBundleInfoByName(_, _, _, _)).WillOnce(Return(false)); @@ -75,7 +75,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -87,7 +87,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); @@ -100,7 +100,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->ServiceResultReport("", BackupRestoreScenario::FULL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -110,7 +110,7 @@ HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, TestSize.Level1) EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("")); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->ServiceResultReport("", BackupRestoreScenario::INCREMENTAL_BACKUP, 0); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -134,29 +134,29 @@ HWTEST_F(ServiceTest, SUB_Service_SAResultReport_0000, TestSize.Level1) GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SAResultReport_0000"; try { EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); auto ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnResultReport(_, _, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return()); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::FULL_BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnResultReport(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->SAResultReport("", "", 0, BackupRestoreScenario::INCREMENTAL_BACKUP); @@ -305,7 +305,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, TestSize.Level1) EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, GetFileHandle(_, _)).WillOnce(Return(UniqueFd(-1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); auto ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -321,7 +321,7 @@ HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, TestSize.Level1) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnFileReady(_, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); ret = service->GetFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { @@ -509,7 +509,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->ExtStart(callName); EXPECT_TRUE(true); @@ -522,7 +522,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleBackup(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(true)); @@ -538,7 +538,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, TestSize.Level1) EXPECT_CALL(*session, GetClearDataFlag(_)).WillOnce(Return(false)); EXPECT_CALL(*svcProxy, HandleRestore(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*session, GetExtFileNameRequest(_)).WillOnce(Return(fileNameVec)); @@ -602,20 +602,20 @@ HWTEST_F(ServiceTest, SUB_Service_ReportOnExtConnectFailed_0000, TestSize.Level1 EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); service->ReportOnExtConnectFailed(IServiceReverse::Scenario::BACKUP, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*gallery, EndRestore(_)).WillOnce(Return(DisposeErr::OK)); service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); @@ -623,14 +623,14 @@ HWTEST_F(ServiceTest, SUB_Service_ReportOnExtConnectFailed_0000, TestSize.Level1 EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*gallery, EndRestore(_)).WillOnce(Return(DisposeErr::OK)); service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*gallery, EndRestore(_)).WillOnce(Return(DisposeErr::OK)); service->ReportOnExtConnectFailed(IServiceReverse::Scenario::RESTORE, bundleName, 0); EXPECT_TRUE(true); @@ -665,7 +665,7 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -675,7 +675,7 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -684,7 +684,7 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0000, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetIsIncrementalBackup()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, BackupOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -714,7 +714,7 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(true)); EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true); @@ -723,7 +723,7 @@ HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, TestSize.Level1) EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return()); + EXPECT_CALL(*srProxy, RestoreOnBundleFinished(_, _)).WillOnce(Return(BError(BError::Codes::OK))); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); service->NoticeClientFinish(bundleName, 0); EXPECT_TRUE(true);