diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index e41e31346bb35532ea87a6e97c48878a4ecdc20e..6d545f815cdf023a7fbb92f085ed66cf96d22fec 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -239,6 +239,7 @@ private: void CheckTmpDirFileInfos(bool isSpecialVersion = false); std::map GetIdxFileInfos(bool isSpecialVersion = false); tuple> CheckRestoreFileInfos(); + void CheckAppIncrementalFileReadyResult(int32_t ret, std::string packageName, std::string file); /** * @brief extension incremental backup restore is done * diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 4c203535dee20b882871b8123efa20aba8c6204d..ee46dd698d34f3adeb6bcb96fa9c76a7addace8d 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -476,9 +476,9 @@ ErrCode BackupExtExtension::IndexFileReady(const TarMap &pkgInfo, sptr HILOGE("get index size fail err:%{public}d", err); } int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); - ErrCode ret = - proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, - ERR_OK); + ErrCode ret = fdval < 0 ? + proxy->AppFileReadyWithoutFd(string(BConstants::EXT_BACKUP_MANAGE), ERR_OK) : + proxy->AppFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully"); } else { @@ -528,7 +528,8 @@ ErrCode BackupExtExtension::BigFileReady(TarMap &bigFileInfo, sptr pro continue; } } - ret = proxy->AppFileReady(item.first, fdval, errCode); + ret = fdval < 0 ? proxy->AppFileReadyWithoutFd(item.first, errCode) : + proxy->AppFileReady(item.first, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("The application is packaged successfully, package name is %{public}s", item.first.c_str()); } else { @@ -708,7 +709,8 @@ static ErrCode TarFileReady(const TarMap &tarFileInfo, sptr proxy) HILOGE("TarFileReady open file failed, file name is %{public}s, err = %{public}d", tarName.c_str(), errno); errCode = errno; } - int ret = proxy->AppFileReady(tarName, fdval, errCode); + int ret = fdval < 0 ? proxy->AppFileReadyWithoutFd(tarName, errCode) : + proxy->AppFileReady(tarName, fdval, errCode); if (SUCCEEDED(ret)) { HILOGI("TarFileReady: AppFileReady success for %{public}s", tarName.c_str()); // 删除文件 @@ -2089,7 +2091,9 @@ ErrCode BackupExtExtension::IncrementalTarFileReady(const TarMap &bigFileInfo, string tarName = string(INDEX_FILE_INCREMENTAL_BACKUP).append(tarFile); int fd = open(tarName.data(), O_RDONLY); int manifestFd = open(file.data(), O_RDONLY); - ErrCode ret = proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); + ErrCode ret = (fd < 0 || manifestFd < 0) ? + proxy->AppIncrementalFileReadyWithoutFd(tarFile, ERR_OK) : + proxy->AppIncrementalFileReady(tarFile, fd, manifestFd, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalTarFileReady: The application is packaged successfully"); // 删除文件 @@ -2139,12 +2143,14 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); WriteFile(file, bigInfo); int manifestFdval = open(file.data(), O_RDONLY); - ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); - if (SUCCEEDED(ret)) { - HILOGI("IncreBigFileReady: The app is packaged success, package name is %{public}s", item.first.c_str()); - RemoveFile(file); - } else { - HILOGE("IncrementalBigFileReady interface fails to be invoked: %{public}d", ret); + ErrCode ret = (fdval < 0 || manifestFdval < 0) ? proxy->AppIncrementalFileReadyWithoutFd(item.first, errCode) : + proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); + CheckAppIncrementalFileReadyResult(ret, item.first, file); + if (fdval >= 0) { + close(fdval); + } + if (manifestFdval >=0) { + close(manifestFdval); } fdNum += BConstants::FILE_AND_MANIFEST_FD_COUNT; RefreshTimeInfo(startTime, fdNum); @@ -2154,6 +2160,16 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, return ret; } +void BackupExtExtension::CheckAppIncrementalFileReadyResult(int32_t ret, std::string packageName, std::string file) +{ + if (SUCCEEDED(ret)) { + HILOGI("IncreBigFileReady: The app is packaged success, package name is %{public}s", packageName.c_str()); + RemoveFile(file); + } else { + HILOGE("IncrementalBigFileReady interface fails to be invoked: %{public}d", ret); + } +} + ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, const vector &srcFiles, sptr proxy) { @@ -2172,9 +2188,9 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, WriteFile(file, srcFiles); int fdval = open(INDEX_FILE_BACKUP.data(), O_RDONLY); int manifestFdval = open(file.data(), O_RDONLY); - ErrCode ret = - proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, - manifestFdval, ERR_OK); + ErrCode ret = (fdval < 0 || manifestFdval < 0) ? + proxy->AppIncrementalFileReadyWithoutFd(string(BConstants::EXT_BACKUP_MANAGE), ERR_OK) : + proxy->AppIncrementalFileReady(string(BConstants::EXT_BACKUP_MANAGE), fdval, manifestFdval, ERR_OK); if (SUCCEEDED(ret)) { HILOGI("IncrementalAllFileReady successfully"); RemoveFile(file); diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index 90b51874e96a7cad33d6527e1d09c88b759230b2..b6b86b182a46795da94132878f0200a5935bb867 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -32,6 +32,9 @@ public: const std::string &fileName, int fd, int32_t errCode) override; + ErrCode BackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override; ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override; ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; @@ -46,6 +49,9 @@ public: const std::string &fileName, int fd, int32_t errCode) override; + ErrCode RestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override; ErrCode RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode = 0) override; @@ -58,6 +64,9 @@ public: int32_t errCode) override; ErrCode IncrementalSaBackupOnFileReady(const std::string &bundleName, const std::string &fileName, int fd, int32_t errCode) override; + ErrCode IncrementalBackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override; ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override; ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override; ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override; @@ -73,6 +82,9 @@ public: int fd, int manifestFd, int32_t errCode) override; + ErrCode IncrementalRestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override; ErrCode IncrementalRestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) override; diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index a3f98f0b676b5a085b104e9ff9ba7556cc5c6b76..be5413d5d0d0b98c5a53d04c78b008b1b3743bb2 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -202,11 +202,7 @@ ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 2216b47d40a1ce1e324957d8a6d61c44472dddab..78b92c231dd36323d6dd594e662ce6c5e9dbca6d 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -224,11 +224,7 @@ ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index d812f6beef2b95da9ed56c6d1498b331cedd2488..64591a0e2f6157183eefe1029be1ef2cf1f95edd 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -175,11 +175,7 @@ ErrCode BIncrementalSessionRestoreAsync::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index 1a7a1ba5758d1dd4481e51ce5e8751bfa6bb2acd..992125a31fa55a961dd1378d356e66339eeb00c6 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -221,11 +221,7 @@ ErrCode BSessionBackup::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 703ac92ad28470c534c4ec85069edd53a7e86d87..34dfc57c322d5556b26677ea07bbfe614ee65148 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -202,11 +202,7 @@ ErrCode BSessionRestore::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index 8cc600b95df81a125bcc2b91d181641410eac516..22fda54f51e37d418243381869c4436514ef6a9e 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -175,11 +175,7 @@ ErrCode BSessionRestoreAsync::Cancel(std::string bundleName) return result; } - ErrCode errCode = proxy->Cancel(bundleName, result); - if (errCode != 0) { - HILOGE("proxy->Cancel failed, errCode:%{public}d.", errCode); - return result; - } + proxy->CancelForResult(bundleName, result); return result; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index 7cc6458570aac10c339c4031051c59b07a4ce314..d39c070430f9266040567a8cf465c18cc4641c2b 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -49,6 +49,19 @@ ErrCode ServiceReverse::IncrementalSaBackupOnFileReady(const std::string &bundle return BError(BError::Codes::OK); } +ErrCode ServiceReverse::IncrementalBackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) +{ + if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onFileReady) { + HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); + return BError(BError::Codes::OK); + } + BFileInfo bFileInfo(bundleName, fileName, 0); + callbacksIncrementalBackup_.onFileReady(bFileInfo, UniqueFd(INVALID_FD), UniqueFd(INVALID_FD), errCode); + return BError(BError::Codes::OK); +} + ErrCode ServiceReverse::IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksIncrementalBackup_.onBundleStarted) { @@ -150,10 +163,6 @@ ErrCode ServiceReverse::IncrementalRestoreOnFileReady(const std::string &bundleN int manifestFd, int32_t errCode) { - if (fd < 0 || manifestFd < 0) { - HILOGE("Error fd or manifestFd, fd = %{public}d, manifestFd = %{public}d", fd, manifestFd); - return BError(BError::Codes::SA_INVAL_ARG); - } if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReady) { HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); return BError(BError::Codes::OK); @@ -163,6 +172,19 @@ ErrCode ServiceReverse::IncrementalRestoreOnFileReady(const std::string &bundleN return BError(BError::Codes::OK); } +ErrCode ServiceReverse::IncrementalRestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) +{ + if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onFileReady) { + HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); + return BError(BError::Codes::OK); + } + BFileInfo bFileInfo(bundleName, fileName, 0); + callbacksIncrementalRestore_.onFileReady(bFileInfo, UniqueFd(INVALID_FD), UniqueFd(INVALID_FD), errCode); + return BError(BError::Codes::OK); +} + ErrCode ServiceReverse::IncrementalRestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 0db73caec36d071d4a0b7954cfddbf1d1d0dfa0c..a985150d83a0e5c75bbaf6bcfa2d2d328d4c01da 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -35,6 +35,19 @@ ErrCode ServiceReverse::BackupOnFileReady(const std::string &bundleName, return BError(BError::Codes::OK); } +ErrCode ServiceReverse::BackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) +{ + if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onFileReady) { + HILOGE("Error scenario or callback is nullptr, scenario = %{public}d", scenario_); + return BError(BError::Codes::OK); + } + BFileInfo bFileInfo(bundleName, fileName, 0); + callbacksBackup_.onFileReady(bFileInfo, UniqueFd(INVALID_FD), errCode); + return BError(BError::Codes::OK); +} + ErrCode ServiceReverse::BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) { if (scenario_ != Scenario::BACKUP || !callbacksBackup_.onBundleStarted) { @@ -145,6 +158,20 @@ ErrCode ServiceReverse::RestoreOnFileReady(const std::string &bundleName, return BError(BError::Codes::OK); } +ErrCode ServiceReverse::RestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + 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 BError(BError::Codes::OK); + } + BFileInfo bFileInfo(bundleName, fileName, 0); + callbacksRestore_.onFileReady(bFileInfo, UniqueFd(INVALID_FD), errCode); + return BError(BError::Codes::OK); +} + ErrCode ServiceReverse::RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) { HILOGI("ServiceReverse RestoreOnResultReport bundle %{public}s begin with result: %{public}s", bundleName.c_str(), diff --git a/services/backup_sa/IService.idl b/services/backup_sa/IService.idl index 7375331333e311101ee26fe07688049d9b675e81..1fdf7524ec87347cde7aea00878f5df5e3376f31 100644 --- a/services/backup_sa/IService.idl +++ b/services/backup_sa/IService.idl @@ -43,7 +43,7 @@ interface OHOS.FileManagement.Backup.IService{ [ipccode 12] void AppendBundlesDetailsBackupSession([in] String[] bundleNames, [in] String[] bundleInfos); [ipccode 13] void Finish(); [ipccode 14] void Release(); - [ipccode 15] void Cancel([in] String bundleName, [out] int cancelResult); + [ipccode 15] void CancelForResult([in] String bundleName, [out] int cancelResult); [ipccode 16] void GetAppLocalListAndDoIncrementalBackup(); [ipccode 17] void GetIncrementalFileHandle([in] String bundleName, [in] String fileName); [ipccode 18] void GetBackupInfo([in] String bundleName, [out] String getBackupInfoResult); @@ -74,4 +74,6 @@ interface OHOS.FileManagement.Backup.IService{ [ipccode 40] void CleanBundleTempDir([in] String bundleName); [ipccode 41] void HandleExtDisconnect([in] boolean isIncBackup); [ipccode 42] void GetExtOnRelease([out] boolean isExtOnRelease); + [ipccode 43] void AppFileReadyWithoutFd([in]String fileName, [in] int appFileReadyErrCode); + [ipccode 44] void AppIncrementalFileReadyWithoutFd([in] String fileName, [in] int appIncrementalFileReadyErrCode); } \ No newline at end of file diff --git a/services/backup_sa/IServiceReverse.idl b/services/backup_sa/IServiceReverse.idl index 3079109145798c48ca3577b0b650ffb300f6f619..ffbc87bd7dd04220369c0274b34f617beb0eb779 100644 --- a/services/backup_sa/IServiceReverse.idl +++ b/services/backup_sa/IServiceReverse.idl @@ -62,4 +62,14 @@ interface OHOS.FileManagement.Backup.IServiceReverse{ [in] String bundleName); [ipccode 24] void IncrementalRestoreOnAllBundlesFinished([in] int incrementalRestoreOnAllBundlesFinishedErrCode); [ipccode 25] void IncrementalRestoreOnProcessInfo( [in] String bundleName, [in] String processInfo); -} + [ipccode 27] void BackupOnFileReadyWithoutFd([in] String bundleName, [in] String fileName, + [in] int backupOnFileReadyErrCode); + [ipccode 28] void RestoreOnFileReadyWithoutFd([in] String bundleName, [in] String fileName, + [in] int restoreOnFileReadyErrCode); + [ipccode 29] void IncrementalBackupOnFileReadyWithoutFd([in] String bundleName, + [in] String fileName, + [in] int incrementalBackupOnFileReadyErrCode); + [ipccode 30] void IncrementalRestoreOnFileReadyWithoutFd([in] String bundleName, + [in] String fileName, + [in] int incrementalRestoreOnFileReadyErrCode); +} diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 59e6230084e5bb3c93968b2895888923e2424927..4a56703c7cf1f4a3ce60977a9fda353360b357b1 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -65,6 +65,7 @@ public: ErrCode GetLocalCapabilitiesForBundleInfos(int& fd) override; ErrCode PublishFile(const BFileInfo &fileInfo) override; ErrCode AppFileReady(const std::string &fileName, int fd, int32_t errCode) override; + ErrCode AppFileReadyWithoutFd(const std::string &fileName, int32_t errCode) override; ErrCode AppDone(ErrCode errCode) override; ErrCode ServiceResultReport(const std::string& restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) override; @@ -84,7 +85,7 @@ public: const std::vector &bundleInfos) override; ErrCode Finish() override; ErrCode Release() override; - ErrCode Cancel(const std::string& bundleName, int32_t &result) override; + ErrCode CancelForResult(const std::string& bundleName, int32_t &result) override; ErrCode GetLocalCapabilitiesIncremental(const std::vector& bundleNames, int& fd) override; ErrCode GetAppLocalListAndDoIncrementalBackup() override; ErrCode InitIncrementalBackupSession(const sptr& remote) override; @@ -98,6 +99,8 @@ public: ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd); ErrCode AppIncrementalFileReady(const std::string& fileName, int fd, int manifestFd, int32_t appIncrementalFileReadyErrCode) override; + ErrCode AppIncrementalFileReadyWithoutFd(const std::string& fileName, + int32_t appIncrementalFileReadyErrCode) override; ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(const BundleName &bundleName, std::string &result) override; @@ -689,6 +692,7 @@ private: void SetScanningInfo(string &scanning, string name); + ErrCode Cancel(const std::string& bundleName, int32_t &result); void HandleOnReleaseAndDisconnect(sptr sessionPtr, const std::string &bundleName); ErrCode InitRestoreSession(const sptr& remote, std::string &errMsg); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 8c84dc460753182994e1115bb185729eda0a50f0..8f02bc0544d3250e4523aa24f30c481fe3b02829 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1157,7 +1157,9 @@ void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) int fdCode = 0; proxy->GetFileHandleWithUniqueFd(fileName, errCode, fdCode); UniqueFd fd(fdCode); - session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + bool fdFlag = fd < 0 ? true : false; + fdFlag ? session_->GetServiceReverseProxy()->BackupOnFileReadyWithoutFd(bundleName, fileName, errCode) : + session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } } @@ -1856,13 +1858,18 @@ 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); + bool fdFlag = fd < 0 ? true : false; BackupRestoreScenario scenario = BackupRestoreScenario::FULL_BACKUP; if (session_->GetIsIncrementalBackup()) { scenario = BackupRestoreScenario::INCREMENTAL_BACKUP; - session_->GetServiceReverseProxy()->IncrementalSaBackupOnFileReady(bundleName, "", move(fd), errCode); + fdFlag ? session_->GetServiceReverseProxy()->IncrementalBackupOnFileReadyWithoutFd(bundleName, "", + errCode) : + session_->GetServiceReverseProxy()->IncrementalSaBackupOnFileReady(bundleName, "", + move(fd), errCode); } else { scenario = BackupRestoreScenario::FULL_BACKUP; - session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); + fdFlag ? session_->GetServiceReverseProxy()->BackupOnFileReadyWithoutFd(bundleName, "", errCode) : + session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); } FileReadyRadarReport(bundleName, "", errCode, IServiceReverseType::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, scenario); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index ee5cae2954d8c7c21a181434005f33dfe8ecb1ee..7a4a2af69db762a97aa29e18e88d3a7615e96d4c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -126,7 +126,7 @@ ErrCode Service::GetLocalCapabilitiesIncremental(const std::vectorGetScenario() == IServiceReverseType::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); + fdFlag ? session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReadyWithoutFd(bundleName, fileName, + errCode) : + session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(bundleName, fileName, move(fd), + move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); return BError(BError::Codes::OK); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(bundleName, move(fd)); } - session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), - move(manifestFd), errCode); + fdFlag = (fd < 0 || manifestFd < 0) ? true : false; + fdFlag ? session_->GetServiceReverseProxy()->IncrementalBackupOnFileReadyWithoutFd(bundleName, fileName, + errCode) : + session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(bundleName, fileName, move(fd), + move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); @@ -636,6 +642,13 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, int fd, in appIncrementalFileReadyErrCode); } +ErrCode Service::AppIncrementalFileReadyWithoutFd(const std::string &fileName, int32_t appIncrementalFileReadyErrCode) +{ + return AppIncrementalFileReady(fileName, UniqueFd(BConstants::INVALID_FD_NUM), + UniqueFd(BConstants::INVALID_FD_NUM), + appIncrementalFileReadyErrCode); +} + ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -646,17 +659,23 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f HILOGE("Verify caller failed, ret:%{public}d", ret); return ret; } + bool fdFlag = (fd < 0 || manifestFd < 0) ? true : false; if (session_->GetScenario() == IServiceReverseType::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), - move(manifestFd), errCode); + fdFlag ? session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReadyWithoutFd(callerName, fileName, + errCode) : + session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), + move(manifestFd), errCode); FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::RESTORE); return BError(BError::Codes::OK); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } - session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), - move(manifestFd), errCode); + fdFlag = (fd < 0 || manifestFd < 0) ? true : false; + fdFlag ? session_->GetServiceReverseProxy()->IncrementalBackupOnFileReadyWithoutFd(callerName, fileName, + errCode) : + session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), + move(manifestFd), errCode); FileReadyRadarReport(callerName, fileName, errCode, IServiceReverseType::Scenario::BACKUP); if (session_->OnBundleFileReady(callerName, fileName)) { ErrCode ret = HandleCurBundleFileReady(callerName, fileName, true); @@ -1044,6 +1063,15 @@ void Service::CancelTask(std::string bundleName, wptr ptr) thisPtr->OnAllBundlesFinished(BError(BError::Codes::OK)); } +ErrCode Service::CancelForResult(const std::string& bundleName, int32_t &result) +{ + ErrCode errCode = Cancel(bundleName, result); + if (errCode != 0) { + HILOGE("Cancel failed, errCode:%{public}d.", errCode); + } + return BError(BError::Codes::OK); +} + ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b9398edd55f0c477289d9425b3300d6f08a1bc6c..897c9bf1544b2a0e87a49de4240ff99cdeaafe43 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -320,6 +320,11 @@ ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t errCo return AppFileReady(fileName, std::move(fdUnique), errCode); } +ErrCode Service::AppFileReadyWithoutFd(const std::string &fileName, int32_t errCode) +{ + return AppFileReady(fileName, UniqueFd(INVALID_FD), errCode); +} + ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -341,7 +346,9 @@ 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); + bool fdFlag = fd < 0 ? true : false; + fdFlag ? session_->GetServiceReverseProxy()->BackupOnFileReadyWithoutFd(callerName, fileName, errCode) : + session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); FileReadyRadarReport(callerName, fileName, errCode, session_->GetScenario()); if (session_->OnBundleFileReady(callerName, fileName)) { ret = HandleCurBundleFileReady(callerName, fileName, false); diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index b29e0f628fa4b66aae8865aae312516195a7c59f..fe62af42ec069eb39427fcb0da4e4b056feb5d42 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -91,6 +91,11 @@ ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCo return BError(BError::Codes::OK); } +ErrCode ServiceProxy::AppFileReadyWithoutFd(const string &fileName, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::AppDone(ErrCode errCode) { return BError(BError::Codes::OK); @@ -145,7 +150,7 @@ ErrCode ServiceProxy::Release() return BError(BError::Codes::OK); } -ErrCode ServiceProxy::Cancel(const std::string &bundleName, int32_t &result) +ErrCode ServiceProxy::CancelForResult(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); @@ -201,6 +206,11 @@ ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, in return BError(BError::Codes::OK); } +ErrCode ServiceProxy::AppIncrementalFileReadyWithoutFd(const string &fileName, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode) { return BError(BError::Codes::OK); 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 8e6b6b17fa7273d210951476b1443fd95f7ca400..803baebc8466909e88ba41ca2e0ce66319e0f72b 100644 --- a/tests/mock/module_ipc/include/service_reverse_proxy_mock.h +++ b/tests/mock/module_ipc/include/service_reverse_proxy_mock.h @@ -26,6 +26,7 @@ class ServiceReverseProxyMock : public IRemoteProxy { public: MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); MOCK_METHOD(ErrCode, BackupOnFileReady, (const std::string &, const std::string &, int, int32_t)); + MOCK_METHOD(ErrCode, BackupOnFileReadyWithoutFd, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(ErrCode, BackupOnBundleStarted, (int32_t, const std::string &)); MOCK_METHOD(ErrCode, BackupOnResultReport, (const std::string &, const std::string &)); ; @@ -38,11 +39,13 @@ public: MOCK_METHOD(ErrCode, RestoreOnBundleFinished, (int32_t, const std::string &)); MOCK_METHOD(ErrCode, RestoreOnAllBundlesFinished, (int32_t)); MOCK_METHOD(ErrCode, RestoreOnFileReady, (const std::string &, const std::string &, int32_t, int32_t)); + MOCK_METHOD(ErrCode, RestoreOnFileReadyWithoutFd, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(ErrCode, RestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); MOCK_METHOD(ErrCode, RestoreOnProcessInfo, (const std::string &, const std::string &)); MOCK_METHOD(ErrCode, IncrementalBackupOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); MOCK_METHOD(ErrCode, IncrementalSaBackupOnFileReady, (const std::string &, const std::string &, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalBackupOnFileReadyWithoutFd, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(ErrCode, IncrementalBackupOnBundleStarted, (int32_t, const std::string &)); MOCK_METHOD(ErrCode, IncrementalBackupOnResultReport, (const std::string &, const std::string &)); MOCK_METHOD(ErrCode, IncrementalBackupOnBundleFinished, (int32_t, const std::string &)); @@ -54,6 +57,7 @@ public: MOCK_METHOD(ErrCode, IncrementalRestoreOnBundleFinished, (int32_t, const std::string &)); MOCK_METHOD(ErrCode, IncrementalRestoreOnAllBundlesFinished, (int32_t)); MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReady, (const std::string &, const std::string &, int, int, int32_t)); + MOCK_METHOD(ErrCode, IncrementalRestoreOnFileReadyWithoutFd, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(ErrCode, IncrementalRestoreOnResultReport, (const std::string &, const std::string &, ErrCode)); ; MOCK_METHOD(ErrCode, IncrementalRestoreOnProcessInfo, (const std::string &, const std::string &)); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 7ba793b34436416be762f61d4f9e629b39b4ff5a..ed5c558fe6815869cba61c869ec40a487fc135a2 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -91,6 +91,11 @@ ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) return BError(BError::Codes::OK); } +ErrCode Service::AppFileReadyWithoutFd(const string &fileName, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::AppDone(ErrCode errCode) { return BError(BError::Codes::OK); @@ -193,7 +198,7 @@ ErrCode Service::Release() return BError(BError::Codes::OK); } -ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) +ErrCode Service::CancelForResult(const std::string &bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); @@ -251,6 +256,12 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, return BError(BError::Codes::OK); } +ErrCode Service::AppIncrementalFileReadyWithoutFd(const std::string &fileName, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::AppIncrementalDone(ErrCode errCode) { return BError(BError::Codes::OK); diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index bfba0234869306450774c5e72f2965688b082f0a..800d74399ac3a8dc6aff9b429e1b01776014fcd1 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -156,6 +156,13 @@ ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReady(const std::string &bu return BError(BError::Codes::OK); } +ErrCode ServiceReverseProxy::IncrementalRestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceReverseProxy::IncrementalRestoreOnResultReport(const std::string &result, const std::string &bundleName, int32_t errCode) diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 4e786fa2172887797af1d4d740e6bbda48bdbbd7..a6e14bf48dfa6ee92ed4903eff1eb0726621b1ca 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -50,6 +50,11 @@ ohos_unittest("backup_sa_impl_test") { module_out_path = path_module_out_tests + cflags = [ + "-Dprivate = public", + "-Dprotected = public", + ] + sources = [ "${path_backup_mock}/system_ability_manager/service_registry_mock.cpp", "${path_backup_mock}/utils_mock/src/utils_mock_global_variable.cpp", diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index be238cc15966325658fdaf54069542a4e4bb5fb0..7f2c4e24ae912d733a313de1fb38a56a53da273e 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -107,6 +107,11 @@ public: return BError(BError::Codes::OK); } + ErrCode AppFileReadyWithoutFd(const std::string &fileName, int32_t errCode) override + { + return BError(BError::Codes::OK); + } + ErrCode AppDone(ErrCode errCode) override { return BError(BError::Codes::OK); @@ -196,7 +201,7 @@ public: return BError(BError::Codes::OK); } - ErrCode Cancel(std::string bundleName, int32_t &result) override + ErrCode CancelForResult(std::string bundleName, int32_t &result) override { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); @@ -248,6 +253,11 @@ public: return BError(BError::Codes::OK); } + ErrCode AppIncrementalFileReadyWithoutFd(const std::string &fileName, int32_t errCode) + { + return BError(BError::Codes::OK); + } + ErrCode AppIncrementalDone(ErrCode errCode) { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index 3a0474f0ccd6d56e99c1eb716da375decb08f02f..3236dd220ba588ddad4d1889631aad69bf66ac8c 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 @@ -43,6 +43,12 @@ public: { return BError(BError::Codes::OK); } + ErrCode BackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override { @@ -97,6 +103,13 @@ public: return BError(BError::Codes::OK); } + ErrCode RestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + ErrCode RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) override { return BError(BError::Codes::OK); @@ -124,6 +137,13 @@ public: return BError(BError::Codes::OK); } + ErrCode IncrementalBackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override { return BError(BError::Codes::OK); @@ -178,6 +198,13 @@ public: return BError(BError::Codes::OK); } + ErrCode IncrementalRestoreOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, + int32_t errCode) override + { + return BError(BError::Codes::OK); + } + ErrCode IncrementalRestoreOnResultReport(const std::string &result, const std::string &bundleName, int32_t errCode) override diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 1c91772409fd719d5296f0b152fc4bdee1f68540..e9da9db92a36d65dca9a445793e38fd41679ffde 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -248,6 +248,77 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0102, t GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReady_0102"; } +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0100 + * @tc.name: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0100 + * @tc.desc: 测试 BackupOnFileReadyWithoutFd 正常分支(回调非空且场景为BACKUP) + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0100"; + Init(IServiceReverseType::Scenario::BACKUP, 0); + ASSERT_NE(service_, nullptr); + bool called = false; + service_->callbacksBackup_.onFileReady = [&](const BFileInfo&, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->BackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0100"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0101 + * @tc.name: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0101 + * @tc.desc: 测试 BackupOnFileReadyWithoutFd 回调为nullptr分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0101"; + Init(IServiceReverseType::Scenario::BACKUP, 0); + ASSERT_NE(service_, nullptr); + service_->callbacksBackup_.onFileReady = nullptr; + auto ret = service_->BackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0102 + * @tc.name: SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0102 + * @tc.desc: 测试 BackupOnFileReadyWithoutFd 场景非BACKUP分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0102, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0102"; + Init(IServiceReverseType::Scenario::RESTORE, 0); // 场景非BACKUP + ASSERT_NE(service_, nullptr); + bool called = false; + service_->callbacksBackup_.onFileReady = [&](const BFileInfo&, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->BackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_FALSE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReadyWithoutFd_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 @@ -576,6 +647,78 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0102, GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReady_0102"; } + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0100 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0100 + * @tc.desc: 测试 RestoreOnFileReadyWithoutFd 正常分支(回调非空且场景为RESTORE) + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0100"; + Init(IServiceReverseType::Scenario::RESTORE, 0); + ASSERT_NE(service_, nullptr); + bool called = false; + service_->callbacksRestore_.onFileReady = [&](const BFileInfo&, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->RestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0100"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0101 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0101 + * @tc.desc: 测试 RestoreOnFileReadyWithoutFd 回调为nullptr分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0101"; + Init(IServiceReverseType::Scenario::RESTORE, 0); + ASSERT_NE(service_, nullptr); + service_->callbacksRestore_.onFileReady = nullptr; + auto ret = service_->RestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0102 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0102 + * @tc.desc: 测试 RestoreOnFileReadyWithoutFd 场景非RESTORE分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0102, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0102"; + Init(IServiceReverseType::Scenario::BACKUP, 0); // 场景非RESTORE + ASSERT_NE(service_, nullptr); + bool called = false; + service_->callbacksRestore_.onFileReady = [&](const BFileInfo&, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->RestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_FALSE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReadyWithoutFd_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 @@ -1039,7 +1182,8 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0301, testing::ext::TestS * @tc.level Level 1 * @tc.require: I9116W */ -HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100, testing::ext::TestSize.Level1) +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100, + testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0100"; try { @@ -1067,7 +1211,8 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe * @tc.level Level 1 * @tc.require: I9116W */ -HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101, testing::ext::TestSize.Level1) +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101, + testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101"; try { @@ -1088,6 +1233,90 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_IncrementalBackupOnFileRe GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalBackupOnFileReady_0101"; } +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0100 + * @tc.name: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0100 + * @tc.desc: 测试 IncrementalBackupOnFileReadyWithoutFd 正常分支(回调非空且场景为BACKUP) + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0100"; + bool called = false; + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 0); + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + // 设置回调 + service_->callbacksIncrementalBackup_.onFileReady = [&](const BFileInfo&, UniqueFd, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->IncrementalBackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0100"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0101 + * @tc.name: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0101 + * @tc.desc: 测试 IncrementalBackupOnFileReadyWithoutFd 回调为nullptr分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0101"; + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 0); + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + service_->callbacksIncrementalBackup_.onFileReady = nullptr; + auto ret = service_->IncrementalBackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0102 + * @tc.name: SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0102 + * @tc.desc: 测试 IncrementalBackupOnFileReadyWithoutFd 场景非BACKUP分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0102, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0102"; + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 0); // 场景非BACKUP + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + bool called = false; + service_->callbacksIncrementalBackup_.onFileReady = [&](const BFileInfo&, UniqueFd, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->IncrementalBackupOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_FALSE(called); + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalBackupOnFileReadyWithoutFd_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_IncrementalBackupOnBundleStarted_0100 @@ -1336,6 +1565,92 @@ HWTEST_F(ServiceReverseTest, GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalRestoreOnFileReady_0101"; } +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0100 + * @tc.name: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0100 + * @tc.desc: 测试 IncrementalRestoreOnFileReadyWithoutFd 正常分支(回调非空且场景为RESTORE) + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0100"; + bool called = false; + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 0); + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + service_->callbacksIncrementalRestore_.onFileReady = [&](const BFileInfo&, UniqueFd, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->IncrementalRestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(called); + GTEST_LOG_(INFO) << + "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0100"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0101 + * @tc.name: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0101 + * @tc.desc: 测试 IncrementalRestoreOnFileReadyWithoutFd 回调为nullptr分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0101, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0101"; + IncrementalInit(IServiceReverseType::Scenario::RESTORE, 0); + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + service_->callbacksIncrementalRestore_.onFileReady = nullptr; + auto ret = service_->IncrementalRestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << + "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0102 + * @tc.name: SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0102 + * @tc.desc: 测试 IncrementalRestoreOnFileReadyWithoutFd 场景非RESTORE分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ServiceReverseTest, + SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0102, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceReverseTest-begin SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0102"; + IncrementalInit(IServiceReverseType::Scenario::BACKUP, 0); // 场景非RESTORE + if (service_ == nullptr) { + GTEST_LOG_(INFO) << "service_ == nullptr"; + return; + } + bool called = false; + service_->callbacksIncrementalRestore_.onFileReady = [&](const BFileInfo&, UniqueFd, UniqueFd, int32_t) { + called = true; + }; + auto ret = service_->IncrementalRestoreOnFileReadyWithoutFd("bundle", "file", 123); + EXPECT_EQ(ret, 0); + EXPECT_FALSE(called); + GTEST_LOG_(INFO) << + "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalRestoreOnFileReadyWithoutFd_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_IncrementalRestoreOnBundleStarted_0100 diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 3779c0e5e9fb8b052c7949d60ca03763728e371c..ce840db00e8ad26ba98074819f0ee2fd37ff1033 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -95,15 +95,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize EXPECT_NE(proxy, nullptr); std::string bundleName; int32_t result = -1; - ErrCode ret = proxy->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); - bundleName = ""; - ret = proxy->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); bundleName = "test"; - ret = proxy->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); - EXPECT_NE(result, 0); + proxy->CancelForResult(bundleName, result); + EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; } 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 f016aa397084acb129a9b13a73957e03dfe82763..314bcd04772f3ccc5e452a73cc0072cf46f8a8cc 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -42,6 +42,7 @@ public: virtual ErrCode Start() = 0; virtual ErrCode PublishFile(const BFileInfo&) = 0; virtual ErrCode AppFileReady(const std::string &, int, int32_t) = 0; + virtual ErrCode AppFileReadyWithoutFd(const std::string &, int32_t) = 0; virtual ErrCode AppDone(ErrCode) = 0; virtual ErrCode ServiceResultReport(const std::string, BackupRestoreScenario, ErrCode) = 0; virtual ErrCode AppendBundlesRestoreSessionDataByDetail(int, const std::vector&, @@ -100,6 +101,7 @@ public: MOCK_METHOD(ErrCode, Start, ()); MOCK_METHOD(ErrCode, PublishFile, (const BFileInfo&)); MOCK_METHOD(ErrCode, AppFileReady, (const string&, int, int32_t)); + MOCK_METHOD(ErrCode, AppFileReadyWithoutFd, (const string&, int32_t)); MOCK_METHOD(ErrCode, AppDone, (ErrCode)); MOCK_METHOD(ErrCode, ServiceResultReport, (const std::string, BackupRestoreScenario, ErrCode)); MOCK_METHOD(ErrCode, AppendBundlesRestoreSessionDataByDetail, (int, (const std::vector&), @@ -201,6 +203,11 @@ ErrCode Service::AppFileReady(const std::string &fileName, int fd, int32_t appFi return BService::serviceMock->AppFileReady(fileName, fd, appFileReadyErrCode); } +ErrCode Service::AppFileReadyWithoutFd(const std::string &fileName, int32_t appFileReadyErrCode) +{ + return BService::serviceMock->AppFileReadyWithoutFd(fileName, appFileReadyErrCode); +} + ErrCode Service::AppDone(int32_t appDoneErrCode) { return BService::serviceMock->AppDone(appDoneErrCode); @@ -566,7 +573,7 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncr int fd = -1; service->GetLocalCapabilitiesIncremental({}, fd); service->session_ = session_; - EXPECT_EQ(static_cast(fd), -ENOENT); + EXPECT_EQ(static_cast(fd), BConstants::INVALID_FD_NUM); service->isOccupyingSession_ = true; fd = service->GetLocalCapabilitiesIncremental({}); @@ -1261,6 +1268,56 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReady_ GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_AppIncrementalFileReady_0300"; } +/** + * @tc.number: SUB_ServiceIncremental_AppIncrementalFileReadyWithoutFd_0000 + * @tc.name: SUB_ServiceIncremental_AppIncrementalFileReadyWithoutFd_0000 + * @tc.desc: 测试 AppIncrementalFileReady 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalFileReadyWithoutFd_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_AppIncrementalFileReadyWithoutFd_0000"; + try { + string bundleName; + string fileName; + int32_t errCode = 0; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); + EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); + EXPECT_CALL(*srProxy, IncrementalRestoreOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); + auto ret = service->AppIncrementalFileReadyWithoutFd(fileName, errCode); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); + EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); + ret = service->AppIncrementalFileReadyWithoutFd(fileName, errCode); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + + fileName = BConstants::EXT_BACKUP_MANAGE; + EXPECT_CALL(*srvMock, VerifyCallerAndGetCallerName(_)) + .WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::BACKUP)); + EXPECT_CALL(*session, OnBundleExtManageInfo(_, _)).WillOnce(Return(UniqueFd(-1))); + EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)); + ret = service->AppIncrementalFileReadyWithoutFd(fileName, errCode); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by AppIncrementalFileReadyWithoutFd."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_AppIncrementalFileReadyWithoutFd_0000"; +} + /** * @tc.number: SUB_ServiceIncremental_AppIncrementalDone_0000 * @tc.name: SUB_ServiceIncremental_AppIncrementalDone_0000 @@ -1906,20 +1963,10 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0000, TestSize.Le int32_t result; auto session_ = service->session_; - service->session_ = nullptr; - EXPECT_EQ(service->Cancel(bundleName, result), - BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - service->session_ = session_; - - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); - EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::EXT_INVAL_ARG).GetCode())); - auto ret = service->Cancel(bundleName, result); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); - service->Cancel(bundleName, result); + service->CancelForResult(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); impl.backupExtNameMap.insert(make_pair(bundleName, info)); @@ -1927,14 +1974,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0000, TestSize.Le EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::UNKNOWN)); - service->Cancel(bundleName, result); + service->CancelForResult(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::CLEAN)); - service->Cancel(bundleName, result); + service->CancelForResult(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_NO_TASK).GetCode()); } catch (...) { EXPECT_TRUE(false); @@ -1967,14 +2014,14 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_Cancel_0100, TestSize.Le EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::START)); - service->Cancel(bundleName, result); + service->CancelForResult(bundleName, result); EXPECT_EQ(result, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*srvMock, VerifyCaller(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetImpl()).WillOnce(Return(impl)); EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); - service->Cancel(bundleName, result); + service->CancelForResult(bundleName, result); EXPECT_EQ(result, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); 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 d0aaff74c399b09b5ea5c07563f789128193e0ea..8dd2ecd8169adf678ef1a52bfc437663a1a4e1e3 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -58,12 +58,18 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, return BError(BError::Codes::OK); } +ErrCode Service::AppIncrementalFileReadyWithoutFd(const std::string &fileName, + int32_t appIncrementalFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::Release() { return BError(BError::Codes::OK); } -ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) +ErrCode Service::CancelForResult(const std::string& bundleName, int32_t &result) { result = BError(BError::Codes::OK); return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index e1e3c155b740b78eab104536d470e95dee6b7447..db4f1931e95b169b41a632cf1cca63f39072cee3 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -81,6 +81,7 @@ public: MOCK_METHOD2(PublishSAIncrementalFile, ErrCode(const BFileInfo &fileInfo, UniqueFd fd)); MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode)); + MOCK_METHOD2(AppIncrementalFileReadyWithoutFd, ErrCode(const std::string &fileName, int32_t errCode)); MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); MOCK_METHOD2(GetBackupInfo, ErrCode(string &bundleName, string &result)); @@ -832,19 +833,13 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_Cancel_0100, testing::ext::T EXPECT_EQ(err, BError(BError::Codes::SA_INVAL_ARG)); EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*service, Cancel(_, _)).WillOnce(Return(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); - EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); - err = service->CmdCancel(data, reply); - EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); - - EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*service, Cancel(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, CancelForResult(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); err = service->CmdCancel(data, reply); EXPECT_EQ(err, BError(BError::Codes::SA_BROKEN_IPC)); EXPECT_CALL(*messageParcelMock, ReadString(_)).WillOnce(Return(true)); - EXPECT_CALL(*service, Cancel(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*service, CancelForResult(_, _)).WillOnce(Return(0)); EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); err = service->CmdCancel(data, reply); EXPECT_EQ(err, BError(BError::Codes::OK)); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 43fc3037e35c55f8e65598cf98e1a9f297bf3886..3854671616a925426310e2b1513f4ccf9a0c8e65 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -388,6 +388,30 @@ HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0103, testing::ext::TestSize.Leve GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0103"; } +/** + * @tc.number: SUB_Service_AppFileReadyWithoutFd_0100 + * @tc.name: SUB_Service_AppFileReadyWithoutFd_0100 + * @tc.desc: 测试 AppFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceTest, SUB_Service_AppFileReadyWithoutFd_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0103"; + try { + string fileName = "/manage.json"; + EXPECT_TRUE(servicePtr_ != nullptr); + auto ret = servicePtr_->AppFileReadyWithoutFd(fileName, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0103"; +} + /** * @tc.number: SUB_Service_AppDone_0100 * @tc.name: SUB_Service_AppDone_0100 diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 8fa22a9a9e77ae26e911979147804da18740e159..781aa477ba67587339b9a185f59549199f3335e9 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -871,7 +871,7 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_010 EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); int fd = -1; ErrCode ret = service->GetLocalCapabilitiesIncremental(bundleNames, fd); - EXPECT_EQ(-fd, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode()); + EXPECT_EQ(fd, BConstants::INVALID_FD_NUM); EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() { throw runtime_error("运行时错误"); diff --git a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp index 4e93edd35bd295516880ddac88ffefd1b4bddb8c..6cfb25ca466152cf04c04a4d9d4722d6afe078c8 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -694,7 +694,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2100, testing::e auto err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); + EXPECT_CALL(*proxy, CancelForResult(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); ServiceClient::serviceProxy_ = proxy; err = backupSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); @@ -724,7 +724,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2200, testing::e auto err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); + EXPECT_CALL(*proxy, CancelForResult(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); ServiceClient::serviceProxy_ = proxy; err = restoreSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); @@ -754,7 +754,7 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2300, testing::e auto err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK).GetCode()); - EXPECT_CALL(*proxy, Cancel(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); + EXPECT_CALL(*proxy, CancelForResult(_, _)).WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); ServiceClient::serviceProxy_ = proxy; err = restoreAsyncSession->Cancel(bundleName); EXPECT_EQ(err, BError(BError::Codes::OK).GetCode()); diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index 342a934e1be8e0857ae67f38662826eee24db525..19d658f02d9374cfbbb5df88eccc9f2b5890e2b3 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -25,6 +25,11 @@ ErrCode ServiceProxy::AppFileReady(const std::string &fileName, int fd, int32_t return BError(BError::Codes::OK); } +ErrCode ServiceProxy::AppFileReadyWithoutFd(const std::string &fileName, int32_t appFileReadyErrCode) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::AppDone(int32_t appDoneErrCode) { return BError(BError::Codes::OK); @@ -45,6 +50,11 @@ ErrCode ServiceProxy::AppIncrementalFileReady(const std::string &fileName, int f return BError(BError::Codes::OK); } +ErrCode ServiceProxy::AppIncrementalFileReadyWithoutFd(const std::string &fileName, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) { return BError(BError::Codes::OK); @@ -93,7 +103,7 @@ ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); - MOCK_METHOD2(Cancel, ErrCode(const std::string &bundleName, int32_t &result)); + MOCK_METHOD2(CancelForResult, ErrCode(const std::string &bundleName, int32_t &result)); MOCK_METHOD2(GetLocalCapabilitiesIncremental, ErrCode(const std::vector &bundleNames, int &fd)); MOCK_METHOD1(InitIncrementalBackupSession, ErrCode(const sptr &remote)); MOCK_METHOD3(InitIncrementalBackupSessionWithErrMsg, @@ -59,6 +59,8 @@ public: MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd)); MOCK_METHOD4(AppIncrementalFileReady, ErrCode(const std::string &fileName, int fd, int manifestFd, int32_t errCode)); + MOCK_METHOD2(AppIncrementalFileReadyWithoutFd, + ErrCode(const std::string &fileName, int32_t errCode)); MOCK_METHOD1(AppIncrementalDone, ErrCode(int32_t errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); MOCK_METHOD2(GetBackupInfo, ErrCode(const BundleName &bundleName, std::string &result));