From 9da5a9433b5f90d07d20cf88b53aef77dc73a2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Wed, 14 May 2025 16:22:27 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../native/backup_ext/include/ext_extension.h | 2 + .../native/backup_ext/src/ext_extension.cpp | 24 +++++++ .../src/b_incremental_backup_session.cpp | 10 +++ .../src/b_incremental_restore_session.cpp | 10 +++ .../backup_kit_inner/src/b_session_backup.cpp | 10 +++ .../src/b_session_restore.cpp | 10 +++ .../impl/b_incremental_backup_session.h | 8 +++ .../impl/b_incremental_restore_session.h | 8 +++ .../backup_kit_inner/impl/b_session_backup.h | 8 +++ .../backup_kit_inner/impl/b_session_restore.h | 8 +++ .../js/backup/session_backup_n_exporter.cpp | 59 ++++++++++++++++++ .../js/backup/session_backup_n_exporter.h | 1 + .../session_incremental_backup_n_exporter.cpp | 59 ++++++++++++++++++ .../session_incremental_backup_n_exporter.h | 1 + .../js/backup/session_restore_n_exporter.cpp | 62 +++++++++++++++++++ .../js/backup/session_restore_n_exporter.h | 1 + services/backup_sa/IExtension.idl | 1 + services/backup_sa/IService.idl | 1 + .../backup_sa/include/module_ipc/service.h | 1 + services/backup_sa/src/module_ipc/service.cpp | 47 ++++++++++++++ .../src/module_ipc/svc_extension_proxy.cpp | 20 ++++++ 21 files changed, 351 insertions(+) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 9d7ab287b..0cb3d575d 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -63,6 +63,8 @@ public: void AsyncTaskIncrementalRestoreForUpgrade(void); ErrCode User0OnBackup() override; ErrCode UpdateDfxInfo(int64_t uniqId, uint32_t extConnectSpend, const std::string &bundleName) override; + ErrCode CleanBundleTempDir() override; + public: explicit BackupExtExtension(const std::shared_ptr &extension, const std::string &bundleName) : extension_(extension) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 849fb2b59..6b2280aa5 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -2207,4 +2207,28 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, } return ret; } + +ErrCode BackupExtExtension::CleanBundleTempDir() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("BackupExtExtension::CleanBundleTempDir begin"); + if (extension_ == nullptr) { + HILOGE("Failed to CleanBundleTempDir, extension is nullptr"); + return BError(BError::Codes::EXT_INVAL_ARG, "Extension is nullptr").GetCode(); + } + if (extension_->GetExtensionAction() == BConstants::ExtensionAction::INVALID) { + return BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid").GetCode(); + } + VerifyCaller(); + bool isClearFlag = isClearData_; + isClearData_ = true; + DoClear(); + isClearData_ = isClearFlag; + return ERR_OK; + } catch (...) { + HILOGE("Failed to CleanBundleTempDir"); + return BError(BError::Codes::EXT_BROKEN_IPC).GetCode(); + } +} } // namespace OHOS::FileManagement::Backup 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 731e23cdf..12f5894d4 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 @@ -209,4 +209,14 @@ ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) } return result; } + +ErrCode BIncrementalBackupSession::CleanBundleTempDir(const std::string &bundleName) +{ + HILOGI("CleanBundleTempDir"); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->CleanBundleTempDir(bundleName); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 25bcef813..6b25a1878 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 @@ -231,4 +231,14 @@ ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) } return result; } + +ErrCode BIncrementalRestoreSession::CleanBundleTempDir(const std::string &bundleName) +{ + HILOGI("CleanBundleTempDir."); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->CleanBundleTempDir(bundleName); +} } // 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 863d696d5..38693ecd8 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -228,4 +228,14 @@ ErrCode BSessionBackup::Cancel(std::string bundleName) } return result; } + +ErrCode BSessionBackup::CleanBundleTempDir(const std::string &bundleName) +{ + HILOGI("CleanBundleTempDir."); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->CleanBundleTempDir(bundleName); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 3daf19df3..f6ecfe044 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -209,4 +209,14 @@ ErrCode BSessionRestore::Cancel(std::string bundleName) } return result; } + +ErrCode BSessionRestore::CleanBundleTempDir(const std::string &bundleName) +{ + HILOGI("CleanBundleTempDir."); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->CleanBundleTempDir(bundleName); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h index 934cb5593..b32113789 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h @@ -115,6 +115,14 @@ public: */ void RegisterBackupServiceDied(std::function functor); + /** + * @brief 备份或者恢复任务结束后,用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据 + * + * @param bundleName 应用名称 + * @return ErrCode 规范错误码 + */ + ErrCode CleanBundleTempDir(const std::string &bundleName); + public: ~BIncrementalBackupSession(); diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index 3b0e46a9c..feaadb654 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -137,6 +137,14 @@ public: */ void RegisterBackupServiceDied(std::function functor); + /** + * @brief 备份或者恢复任务结束后,用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据 + * + * @param bundleName 应用名称 + * @return ErrCode 规范错误码 + */ + ErrCode CleanBundleTempDir(const std::string &bundleName); + public: ~BIncrementalRestoreSession(); diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index 0fbcb4dc2..7f5cd583d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -130,6 +130,14 @@ public: */ void RegisterBackupServiceDied(std::function functor); + /** + * @brief 备份或者恢复任务结束后,用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据 + * + * @param bundleName 应用名称 + * @return ErrCode 规范错误码 + */ + ErrCode CleanBundleTempDir(const std::string &bundleName); + public: ~BSessionBackup(); diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index 7aa5fdcd8..4dd41dc36 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -137,6 +137,14 @@ public: */ void RegisterBackupServiceDied(std::function functor); + /** + * @brief 备份或者恢复任务结束后,用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据 + * + * @param bundleName 应用名称 + * @return ErrCode 规范错误码 + */ + ErrCode CleanBundleTempDir(const std::string &bundleName); + public: ~BSessionRestore(); diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index c04ef6664..bf6d7cadb 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -655,6 +655,64 @@ napi_value SessionBackupNExporter::Cancel(napi_env env, napi_callback_info info) return nResult; } +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +{ + auto backupEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); + if (!(backupEntity && (backupEntity->session))) { + HILOGE("Failed to get BackupSession entity."); + NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to get BackupSession entity.").GetCode()).ThrowErr(env); + return nullptr; + } + return [entity {backupEntity}, bundleName {std::string(bundleName.get())}]() -> NError { + if (!(entity && (entity->session))) { + return NError(BError(BError::Codes::SDK_INVAL_ARG, "Backup session is nullptr").GetCode()); + } + return NError(entity->session->CleanBundleTempDir(bundleName)); + }; +} + +napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionBackupNExporter::CleanBundleTempDir begin."); + if (!SAUtils::CheckBackupPermission()) { + HILOGE("Has not permission!"); + NError(E_PERMISSION).ThrowErr(env); + return nullptr; + } + if (!SAUtils::IsSystemApp()) { + HILOGE("System App check fail!"); + NError(E_PERMISSION_SYS).ThrowErr(env); + return nullptr; + } + NFuncArg funcArg(env, cbinfo); + //校验参数格式是否是1 + if (!funcArg.InitArgs(NARG_CNT::ONE)) { + HILOGE("Number of arguments unmatched"); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + NVal jsBundleStr(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleName, sizeStr] = jsBundleStr.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto cbExec = CleanBundleTempDirCBExec(env, funcArg, std::move(bundleName)); + if (cbExec == nullptr) { + HILOGE("CleanBundleTempDirCBExec fail!"); + return nullptr; + } + auto cbCompl = [](napi_env env, NError err) -> NVal { + return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + }; + HILOGD("Called SessionBackupNExporter::CleanBundleTempDir end."); + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionBackupNExporter::Export() { HILOGD("called SessionBackupNExporter::Export begin"); @@ -664,6 +722,7 @@ bool SessionBackupNExporter::Export() NVal::DeclareNapiFunction("appendBundles", AppendBundles), NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), + NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), }; auto [succ, classValue] = NClass::DefineClass(exports_.env_, className, Constructor, std::move(props)); diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.h b/interfaces/kits/js/backup/session_backup_n_exporter.h index 5fc20d610..708f3b9b7 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.h +++ b/interfaces/kits/js/backup/session_backup_n_exporter.h @@ -31,6 +31,7 @@ public: static napi_value AppendBundles(napi_env env, napi_callback_info cbinfo); static napi_value Release(napi_env env, napi_callback_info cbinfo); static napi_value Cancel(napi_env env, napi_callback_info cbinfo); + static napi_value CleanBundleTempDir(napi_env env, napi_callback_info cbinfo); SessionBackupNExporter(napi_env env, napi_value exports); ~SessionBackupNExporter() override; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index 05912440e..eee4891be 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -654,6 +654,64 @@ napi_value SessionIncrementalBackupNExporter::Cancel(napi_env env, napi_callback return nResult; } +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +{ + auto backupEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); + if (!(backupEntity && (backupEntity->session))) { + HILOGE("Failed to get BackupSession entity."); + NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to get BackupSession entity.").GetCode()).ThrowErr(env); + return nullptr; + } + return [entity {backupEntity}, bundleName {std::string(bundleName.get())}]() -> NError { + if (!(entity && (entity->session))) { + return NError(BError(BError::Codes::SDK_INVAL_ARG, "Backup session is nullptr").GetCode()); + } + return NError(entity->session->CleanBundleTempDir(bundleName)); + }; +} + +napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionIncrementalBackupNExporter::CleanBundleTempDir begin."); + if (!SAUtils::CheckBackupPermission()) { + HILOGE("Has not permission!"); + NError(E_PERMISSION).ThrowErr(env); + return nullptr; + } + if (!SAUtils::IsSystemApp()) { + HILOGE("System App check fail!"); + NError(E_PERMISSION_SYS).ThrowErr(env); + return nullptr; + } + NFuncArg funcArg(env, cbinfo); + //校验参数格式是否是1 + if (!funcArg.InitArgs(NARG_CNT::ONE)) { + HILOGE("Number of arguments unmatched"); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + NVal jsBundleStr(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleName, sizeStr] = jsBundleStr.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto cbExec = CleanBundleTempDirCBExec(env, funcArg, std::move(bundleName)); + if (cbExec == nullptr) { + HILOGE("CleanBundleTempDirCBExec fail!"); + return nullptr; + } + auto cbCompl = [](napi_env env, NError err) -> NVal { + return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + }; + HILOGD("Called SessionIncrementalBackupNExporter::CleanBundleTempDir end."); + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionIncrementalBackupNExporter::Export() { HILOGD("called SessionIncrementalBackupNExporter::Export begin"); @@ -663,6 +721,7 @@ bool SessionIncrementalBackupNExporter::Export() NVal::DeclareNapiFunction("appendBundles", AppendBundles), NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), + NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), }; auto [succ, classValue] = NClass::DefineClass(exports_.env_, className, Constructor, std::move(props)); diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h index d2d5ba475..7f9547232 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h @@ -31,6 +31,7 @@ public: static napi_value AppendBundles(napi_env env, napi_callback_info cbinfo); static napi_value Release(napi_env env, napi_callback_info cbinfo); static napi_value Cancel(napi_env env, napi_callback_info cbinfo); + static napi_value CleanBundleTempDir(napi_env env, napi_callback_info cbinfo); SessionIncrementalBackupNExporter(napi_env env, napi_value exports); ~SessionIncrementalBackupNExporter() override; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index ef6ddf6df..e30fd9beb 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -841,6 +841,67 @@ napi_value SessionRestoreNExporter::Cancel(napi_env env, napi_callback_info info return nResult; } +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +{ + auto restoreEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); + if (!(restoreEntity && (restoreEntity->sessionWhole || restoreEntity->sessionSheet))) { + HILOGE("Failed to get RestoreSession entity."); + NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to get RestoreSession entity.").GetCode()).ThrowErr(env); + return nullptr; + } + return [entity {restoreEntity}, bundleName {string(bundleName.get())}]() -> NError { + if (!(entity && (entity->sessionWhole || entity->sessionSheet))) { + return NError(BError(BError::Codes::SDK_INVAL_ARG, "restore session is nullptr").GetCode()); + } + if (entity->sessionWhole) { + return NError(entity->sessionWhole->CleanBundleTempDir(bundleName)); + } + return NError(entity->sessionSheet->CleanBundleTempDir(bundleName)); + }; +} + +napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionRestore::CleanBundleTempDir begin."); + if (!SAUtils::CheckBackupPermission()) { + HILOGE("Has not permission!"); + NError(E_PERMISSION).ThrowErr(env); + return nullptr; + } + if (!SAUtils::IsSystemApp()) { + HILOGE("System App check fail!"); + NError(E_PERMISSION_SYS).ThrowErr(env); + return nullptr; + } + NFuncArg funcArg(env, cbinfo); + //校验参数格式是否是1 + if (!funcArg.InitArgs(NARG_CNT::ONE)) { + HILOGE("Number of arguments unmatched"); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + NVal jsBundleStr(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleName, sizeStr] = jsBundleStr.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto cbExec = CleanBundleTempDirCBExec(env, funcArg, std::move(bundleName)); + if (cbExec == nullptr) { + HILOGE("CleanBundleTempDirCBExec fail!"); + return nullptr; + } + auto cbCompl = [](napi_env env, NError err) -> NVal { + return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + }; + HILOGD("Called SessionRestore::CleanBundleTempDir end."); + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionRestoreNExporter::Export() { HILOGD("called SessionRestoreNExporter::Export begin"); @@ -851,6 +912,7 @@ bool SessionRestoreNExporter::Export() NVal::DeclareNapiFunction("getFileHandle", GetFileHandle), NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), + NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), }; auto [succ, classValue] = NClass::DefineClass(exports_.env_, className, Constructor, std::move(props)); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.h b/interfaces/kits/js/backup/session_restore_n_exporter.h index 157f34b4a..12a40fca8 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.h +++ b/interfaces/kits/js/backup/session_restore_n_exporter.h @@ -35,6 +35,7 @@ public: static napi_value GetFileHandle(napi_env env, napi_callback_info cbinfo); static napi_value Release(napi_env env, napi_callback_info cbinfo); static napi_value Cancel(napi_env env, napi_callback_info cbinfo); + static napi_value CleanBundleTempDir(napi_env env, napi_callback_info cbinfo); SessionRestoreNExporter(napi_env env, napi_value exports); ~SessionRestoreNExporter() override; diff --git a/services/backup_sa/IExtension.idl b/services/backup_sa/IExtension.idl index d6d37d3d1..4dcff5076 100644 --- a/services/backup_sa/IExtension.idl +++ b/services/backup_sa/IExtension.idl @@ -29,4 +29,5 @@ interface OHOS.FileManagement.Backup.IExtension{ [ipccode 12] void UpdateFdSendRate([in] String bundleName, [in] int sendRate); [ipccode 13] void User0OnBackup(); [ipccode 14] void UpdateDfxInfo([in] long uniqId, [in] unsigned int extConnectSpend, [in] String bundleName); + [ipccode 15] void CleanBundleTempDir(); } \ No newline at end of file diff --git a/services/backup_sa/IService.idl b/services/backup_sa/IService.idl index 5ecb32295..d5cc82be5 100644 --- a/services/backup_sa/IService.idl +++ b/services/backup_sa/IService.idl @@ -69,4 +69,5 @@ interface OHOS.FileManagement.Backup.IService{ [ipccode 37] void ServiceResultReport([in]String restoreRetInfo, [in] BackupRestoreScenario sennario, [in] int serviceResultReportErrCode); [ipccode 38] void GetBackupDataSize([in] boolean isPreciseScan,[in] BIncrementalData[] bundleNameList); + [ipccode 40] void CleanBundleTempDir([in] String bundleName); } \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index f68dd45d3..53d3180f7 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -110,6 +110,7 @@ public: void StartGetFdTask(std::string bundleName, wptr ptr); ErrCode GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) override; + ErrCode CleanBundleTempDir(const std::string &bundleName) override; // 以下都是非IPC接口 public: diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 6e4218602..62b37704a 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -2080,4 +2080,51 @@ void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userI session_->SetSessionUserId(GetUserIdDefault()); } } + +ErrCode Service::CleanBundleTempDir(const string &callerName) +{ + HILOGI("CleanBundleTempDir."); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + + if (session_ == nullptr) { + HILOGE("Get BackupInfo error, session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + std::string bundleName = callerName; + auto backupConnection = session_->CreateBackupConnection(bundleName); + if (backupConnection == nullptr) { + HILOGE("backupConnection is null. bundleName: %{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); + auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); + backupConnection->SetCallback(callConnected); + backupConnection->SetCallDied(callDied); + AAFwk::Want want = CreateConnectWant(bundleName); + auto ret = backupConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (ret) { + HILOGE("CleanBundleTempDir error, ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + return BError(BError::Codes::SA_BOOT_EXT_FAIL); + } + std::unique_lock lock(getBackupInfoSyncLock_); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); + if (isConnectDied_.load()) { + HILOGE("CleanBundleTempDir error, GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); + isConnectDied_.store(false); + return BError(BError::Codes::EXT_ABILITY_DIED); + } + + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("CleanBundleTempDir error, Extension backup Proxy is empty."); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + proxy->CleanBundleTempDir(); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index bd0d8e8a0..6882f4c37 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -212,4 +212,24 @@ ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int32_t sen HILOGI("SvcExtensionProxy::UpdateFdSendRate end."); return ret; } + +ErrCode SvcExtensionProxy::CleanBundleTempDir() +{ + HILOGD("CleanBundleTempDir start"); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + data.WriteInterfaceToken(GetDescriptor()); + + MessageParcel reply; + MessageOption option; + int32_t ret = + Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_CLEAN_BUNDLE_TEMP_DIR), data, reply, option); + if (ret != NO_ERROR) { + HILOGE("Received error %{public}d when doing IPC", ret); + return ErrCode(ret); + } + HILOGD("CleanBundleTempDir end"); + return reply.ReadInt32(); +} } // namespace OHOS::FileManagement::Backup -- Gitee From 2bd3b115c3299f09d21e101dec4b77f4b006dc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Wed, 14 May 2025 17:12:01 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- interfaces/kits/js/backup/session_backup_n_exporter.cpp | 2 +- .../kits/js/backup/session_incremental_backup_n_exporter.cpp | 2 +- interfaces/kits/js/backup/session_restore_n_exporter.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index bf6d7cadb..626d47a3c 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -705,7 +705,7 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + return err ==? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionBackupNExporter::CleanBundleTempDir end."); diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index eee4891be..cca5e021e 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -704,7 +704,7 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionIncrementalBackupNExporter::CleanBundleTempDir end."); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index e30fd9beb..84a277eb6 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -894,7 +894,7 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, false); + return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionRestore::CleanBundleTempDir end."); -- Gitee From c7c00e59c2586b95b4257b71cc22a06db14669a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Wed, 14 May 2025 18:14:49 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- interfaces/kits/js/backup/session_backup_n_exporter.cpp | 2 +- .../kits/js/backup/session_incremental_backup_n_exporter.cpp | 2 +- interfaces/kits/js/backup/session_restore_n_exporter.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index 626d47a3c..79013d985 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -705,7 +705,7 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err ==? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); + return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionBackupNExporter::CleanBundleTempDir end."); diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index cca5e021e..a617744fe 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -704,7 +704,7 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); + return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionIncrementalBackupNExporter::CleanBundleTempDir end."); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 84a277eb6..8e8e389a4 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -894,7 +894,7 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba return nullptr; } auto cbCompl = [](napi_env env, NError err) -> NVal { - return err? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); + return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; HILOGD("Called SessionRestore::CleanBundleTempDir end."); -- Gitee From 4aa92066e1ca432c03e1d5770eb5424174142fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Sun, 18 May 2025 21:51:44 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../native/backup_ext/src/ext_extension.cpp | 18 +++--- .../src/b_incremental_backup_session.cpp | 2 +- .../src/b_incremental_restore_session.cpp | 2 +- .../backup_kit_inner/src/b_session_backup.cpp | 2 +- .../src/b_session_restore.cpp | 2 +- .../js/backup/session_backup_n_exporter.cpp | 2 - .../session_incremental_backup_n_exporter.cpp | 2 - .../js/backup/session_restore_n_exporter.cpp | 2 - .../backup_sa/include/module_ipc/service.h | 9 +++ services/backup_sa/src/module_ipc/service.cpp | 59 ++++++++++++------- .../backup_kit_inner/service_proxy_mock.cpp | 5 ++ tests/mock/module_ipc/service_mock.cpp | 5 ++ .../backup_impl/include/ext_extension_mock.h | 5 ++ .../backup_impl/include/i_service_mock.h | 5 ++ .../module_ipc/service_incremental_test.cpp | 7 +++ .../backup_sa/session/service_proxy_mock.cpp | 5 ++ .../backup_sa/session/service_proxy_mock.h | 1 + 17 files changed, 94 insertions(+), 39 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 6b2280aa5..baff90264 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -2210,16 +2210,16 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, ErrCode BackupExtExtension::CleanBundleTempDir() { - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("BackupExtExtension::CleanBundleTempDir begin"); + if (extension_ == nullptr) { + HILOGE("Failed to CleanBundleTempDir, extension is nullptr"); + return BError(BError::Codes::EXT_INVAL_ARG, "Extension is nullptr").GetCode(); + } + if (extension_->GetExtensionAction() == BConstants::ExtensionAction::INVALID) { + return BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid").GetCode(); + } try { - HILOGI("BackupExtExtension::CleanBundleTempDir begin"); - if (extension_ == nullptr) { - HILOGE("Failed to CleanBundleTempDir, extension is nullptr"); - return BError(BError::Codes::EXT_INVAL_ARG, "Extension is nullptr").GetCode(); - } - if (extension_->GetExtensionAction() == BConstants::ExtensionAction::INVALID) { - return BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid").GetCode(); - } VerifyCaller(); bool isClearFlag = isClearData_; isClearData_ = true; 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 12f5894d4..69b84aa79 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 @@ -212,7 +212,7 @@ ErrCode BIncrementalBackupSession::Cancel(std::string bundleName) ErrCode BIncrementalBackupSession::CleanBundleTempDir(const std::string &bundleName) { - HILOGI("CleanBundleTempDir"); + HILOGI("BIncrementalBackupSession::CleanBundleTempDir"); auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); 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 6b25a1878..5c9864eef 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 @@ -234,7 +234,7 @@ ErrCode BIncrementalRestoreSession::Cancel(std::string bundleName) ErrCode BIncrementalRestoreSession::CleanBundleTempDir(const std::string &bundleName) { - HILOGI("CleanBundleTempDir."); + HILOGI("BIncrementalRestoreSession::CleanBundleTempDir"); auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); 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 38693ecd8..8378cf28a 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -231,7 +231,7 @@ ErrCode BSessionBackup::Cancel(std::string bundleName) ErrCode BSessionBackup::CleanBundleTempDir(const std::string &bundleName) { - HILOGI("CleanBundleTempDir."); + HILOGI("BSessionBackup::CleanBundleTempDir"); auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); 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 f6ecfe044..703ac92ad 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -212,7 +212,7 @@ ErrCode BSessionRestore::Cancel(std::string bundleName) ErrCode BSessionRestore::CleanBundleTempDir(const std::string &bundleName) { - HILOGI("CleanBundleTempDir."); + HILOGI("BSessionRestore::CleanBundleTempDir"); auto proxy = ServiceClient::GetInstance(); if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index 79013d985..16cb2b472 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -685,7 +685,6 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac return nullptr; } NFuncArg funcArg(env, cbinfo); - //校验参数格式是否是1 if (!funcArg.InitArgs(NARG_CNT::ONE)) { HILOGE("Number of arguments unmatched"); NError(E_PARAMS).ThrowErr(env); @@ -707,7 +706,6 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac auto cbCompl = [](napi_env env, NError err) -> NVal { return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; - HILOGD("Called SessionBackupNExporter::CleanBundleTempDir end."); NVal thisVar(env, funcArg.GetThisVar()); return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index a617744fe..7500113c7 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -684,7 +684,6 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n return nullptr; } NFuncArg funcArg(env, cbinfo); - //校验参数格式是否是1 if (!funcArg.InitArgs(NARG_CNT::ONE)) { HILOGE("Number of arguments unmatched"); NError(E_PARAMS).ThrowErr(env); @@ -706,7 +705,6 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n auto cbCompl = [](napi_env env, NError err) -> NVal { return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; - HILOGD("Called SessionIncrementalBackupNExporter::CleanBundleTempDir end."); NVal thisVar(env, funcArg.GetThisVar()); return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 8e8e389a4..5dee375ec 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -874,7 +874,6 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba return nullptr; } NFuncArg funcArg(env, cbinfo); - //校验参数格式是否是1 if (!funcArg.InitArgs(NARG_CNT::ONE)) { HILOGE("Number of arguments unmatched"); NError(E_PARAMS).ThrowErr(env); @@ -896,7 +895,6 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba auto cbCompl = [](napi_env env, NError err) -> NVal { return err ? NVal::CreateBool(env, false) : NVal::CreateBool(env, true); }; - HILOGD("Called SessionRestore::CleanBundleTempDir end."); NVal thisVar(env, funcArg.GetThisVar()); return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 53d3180f7..cf9346037 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -567,6 +567,15 @@ private: */ void SetOccupySession(bool isOccupyingSession); + /** + * @brief 尝试拉起某个应用的extension + * + * @param bundleName 目标应用 + * @param extConnection 框架和应用的连接 + * + */ + ErrCode TryToConnectExt(const std::string& bundleName, sptr& extConnection); + void ReportOnExtConnectFailed(const IServiceReverseType::Scenario scenario, const std::string &bundleName, const ErrCode ret); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 62b37704a..4d5cef0d8 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1471,7 +1471,7 @@ void Service::ClearDisposalOnSaStart() if (!bundleNameList.empty()) { for (vector::iterator it = bundleNameList.begin(); it != bundleNameList.end(); ++it) { string bundleName = *it; - HILOGE("dispose has residual, clear now, bundelName =%{public}s", bundleName.c_str()); + HILOGE("dispose has residual, clear now, bundleName =%{public}s", bundleName.c_str()); TryToClearDispose(bundleName); } } @@ -2081,43 +2081,62 @@ void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userI } } -ErrCode Service::CleanBundleTempDir(const string &callerName) +ErrCode Service::TryToConnectExt(const std::string& bundleName, sptr& extConnection) { - HILOGI("CleanBundleTempDir."); - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - - if (session_ == nullptr) { - HILOGE("Get BackupInfo error, session is empty."); - return BError(BError::Codes::SA_INVAL_ARG); + extConnection = session_->GetExtConnection(bundleName); + if (extConnection != nullptr && extConnection->IsExtAbilityConnected()) { + return BError(BError::Codes::OK); } - std::string bundleName = callerName; - auto backupConnection = session_->CreateBackupConnection(bundleName); - if (backupConnection == nullptr) { - HILOGE("backupConnection is null. bundleName: %{public}s", bundleName.c_str()); + if (extConnection == nullptr) { + extConnection = session_->CreateBackupConnection(bundleName); + } + if (extConnection == nullptr) { + HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); return BError(BError::Codes::SA_INVAL_ARG); } auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); - backupConnection->SetCallback(callConnected); - backupConnection->SetCallDied(callDied); + extConnection->SetCallback(callConnected); + extConnection->SetCallDied(callDied); AAFwk::Want want = CreateConnectWant(bundleName); - auto ret = backupConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); - if (ret) { - HILOGE("CleanBundleTempDir error, ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); - return BError(BError::Codes::SA_BOOT_EXT_FAIL); + auto err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (err) { + HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); + return BError(BError::Codes::SA_BOOT_EXT_FAIL);; } + return BError(BError::Codes::OK); +} + +ErrCode Service::CleanBundleTempDir(const string &bundleName) +{ + HILOGI("Service::CleanBundleTempDir"); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + + if (session_ == nullptr) { + HILOGE("session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + sptr backupConnection; + ErrCode err = TryToConnectExt(bundleName, backupConnection); + if (err) {return err;} + std::unique_lock lock(getBackupInfoSyncLock_); getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); if (isConnectDied_.load()) { - HILOGE("CleanBundleTempDir error, GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); + HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); isConnectDied_.store(false); return BError(BError::Codes::EXT_ABILITY_DIED); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + if (backupConnection == nullptr) { + HILOGE("backupConnection is empty."); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } auto proxy = backupConnection->GetBackupExtProxy(); if (!proxy) { - HILOGE("CleanBundleTempDir error, Extension backup Proxy is empty."); + HILOGE("Extension backup Proxy is empty."); backupConnection->DisconnectBackupExtAbility(); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 5abdac177..d521ebec5 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -255,4 +255,9 @@ ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector bundleNameList, string &scanning) {} void Service::GetPresumablySize(vector bundleNameList, string &scanning) {} diff --git a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h index be0b0d4c8..34aaef2ae 100644 --- a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h @@ -168,6 +168,11 @@ public: { return ERR_OK; }; + + ErrCode CleanBundleTempDir() override + { + return BError(BError::Codes::OK); + }; private: int32_t nHandleBackupNum_ = 0; }; 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 8694c8f4d..be238cc15 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 @@ -267,6 +267,11 @@ public: { return BError(BError::Codes::OK); } + + ErrCode CleanBundleTempDir(const std::string &bundleName) override + { + return BError(BError::Codes::OK); + }; }; } // namespace OHOS::FileManagement::Backup #endif // MOCK_I_SERVICE_MOCK_H \ No newline at end of file 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 405223861..708919917 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -75,6 +75,7 @@ public: virtual ErrCode HandleCurAppDone(ErrCode, const std::string&, bool) = 0; virtual UniqueFd GetLocalCapabilitiesForBundleInfos() = 0; virtual ErrCode GetBackupDataSize(bool, const std::vector&) = 0; + virtual ErrCode CleanBundleTempDir(const std::string& bundleName) = 0; public: virtual bool UpdateToRestoreBundleMap(const string&, const string&) = 0; public: @@ -129,6 +130,7 @@ public: MOCK_METHOD(ErrCode, HandleCurAppDone, (ErrCode, const std::string&, bool)); MOCK_METHOD(UniqueFd, GetLocalCapabilitiesForBundleInfos, ()); MOCK_METHOD(ErrCode, GetBackupDataSize, (bool, const std::vector&)); + MOCK_METHOD(ErrCode, CleanBundleTempDir, (const std::string&)); public: MOCK_METHOD(bool, UpdateToRestoreBundleMap, (const string&, const string&)); }; @@ -433,6 +435,11 @@ ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vectorGetBackupDataSize(isPreciseScan, bundleNameList); } + +ErrCode Service::CleanBundleTempDir(const std::string& bundleName) +{ + return BService::serviceMock->CleanBundleTempDir(bundleName); +} } // namespace OHOS::FileManagement::Backup namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index bfdd210af..2c0faa543 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -229,4 +229,9 @@ ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector &, int32_t, int32_t)); MOCK_METHOD2(GetBackupDataSize, ErrCode(bool isPreciseScan, const std::vector &bundleNameList)); + MOCK_METHOD1(CleanBundleTempDir, ErrCode(const std::string &bundleName)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H -- Gitee From 17fb56983ef4aa39ba4429336a5b1cfc91dffc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Mon, 19 May 2025 09:27:06 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- tests/mock/module_ipc/service_mock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 2c5915f5a..6a945c4ba 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -396,7 +396,7 @@ ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector Date: Mon, 19 May 2025 15:38:11 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../backup_ext/include/ext_extension_mock.h | 1 + .../backup_ext/src/ext_extension_mock.cpp | 5 + .../include/svc_extension_proxy_mock.h | 1 + .../module_ipc/svc_extension_proxy_mock.cpp | 5 + .../b_session_backup_test.cpp | 34 +++++ .../module_ipc/service_other_test.cpp | 132 ++++++++++++++++++ .../module_ipc/svc_extension_proxy_test.cpp | 32 +++++ .../session/b_incremental_session_test.cpp | 34 +++++ 8 files changed, 244 insertions(+) diff --git a/tests/mock/backup_ext/include/ext_extension_mock.h b/tests/mock/backup_ext/include/ext_extension_mock.h index 65733f7ad..c57e10ae2 100644 --- a/tests/mock/backup_ext/include/ext_extension_mock.h +++ b/tests/mock/backup_ext/include/ext_extension_mock.h @@ -120,6 +120,7 @@ public: MOCK_METHOD((std::function), HandleTaskBackupEx, (wptr)); MOCK_METHOD(void, WaitToSendFd, ((std::chrono::system_clock::time_point&), int&)); MOCK_METHOD(void, RefreshTimeInfo, ((std::chrono::system_clock::time_point&), int&)); + MOCK_METHOD(ErrCode, CleanBundleTempDir, ()); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_MOCK_H \ No newline at end of file diff --git a/tests/mock/backup_ext/src/ext_extension_mock.cpp b/tests/mock/backup_ext/src/ext_extension_mock.cpp index 4c54b88bf..f5bf98f34 100644 --- a/tests/mock/backup_ext/src/ext_extension_mock.cpp +++ b/tests/mock/backup_ext/src/ext_extension_mock.cpp @@ -217,4 +217,9 @@ void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &sta void BackupExtExtension::RefreshTimeInfo(std::chrono::system_clock::time_point &startTime, int &fdSendNum) { } + +ErrCode BackupExtExtension::CleanBundleTempDir() +{ + return BExtExtension::extExtension->CleanBundleTempDir(); +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h index a41f5f27a..429f8b618 100644 --- a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -39,6 +39,7 @@ MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &)); MOCK_METHOD(ErrCode, UpdateFdSendRate, (const std::string &, int32_t)); MOCK_METHOD(ErrCode, User0OnBackup, ()); MOCK_METHOD(ErrCode, UpdateDfxInfo, (int64_t, uint32_t, const std::string &)); +MOCK_METHOD(ErrCode, CleanBundleTempDir, ()); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index 63eacdcff..d9e0e8c94 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -87,4 +87,9 @@ ErrCode ExtensionProxy::UpdateDfxInfo(int64_t uniqId, uint32_t extConnectSpend, { return 0; } + +ErrCode ExtensionProxy::CleanBundleTempDir() +{ + return 0; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp index eae6c10ed..11e9deaf0 100644 --- a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp @@ -475,4 +475,38 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_1200, testing::ext::Tes } GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_1200"; } + +/** + * @tc.number: SUB_backup_b_session_backup_1300 + * @tc.name: SUB_backup_b_session_backup_1300 + * @tc.desc: 测试 CleanBundleTempDir 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9KPRL + */ +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_1300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_1300"; + try { + if (backupPtr_ == nullptr) { + GTEST_LOG_(INFO) << "SUB_backup_b_session_backup_1300 backupPtr_ == nullptr"; + return; + } + GTEST_LOG_(INFO) << "GetInstance is false"; + std::string bundleName; + SetMockGetInstance(false); + auto err = backupPtr_->CleanBundleTempDir(bundleName); + EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); + + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + err = backupPtr_->CleanBundleTempDir(bundleName); + EXPECT_EQ(err, ERR_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by CleanBundleTempDir."; + } + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_1300"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 5c80651bf..777a1209d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -2322,4 +2322,136 @@ HWTEST_F(ServiceTest, SUB_Service_GetSupportBackupBundleNames_0100, testing::ext } GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetSupportBackupBundleNames_0100"; } + +/** + * @tc.number: SUB_Service_TryToConnectExt_0000 + * @tc.name: SUB_Service_TryToConnectExt_0000 + * @tc.desc: 测试 TryToConnectExt 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TryToConnectExt_0000"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + auto res = service->TryToConnectExt(bundleName, extConnection); + EXPECT_EQ(res, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TryToConnectExt."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TryToConnectExt_0000"; +} + +/** + * @tc.number: SUB_Service_TryToConnectExt_0100 + * @tc.name: SUB_Service_TryToConnectExt_0100 + * @tc.desc: 测试 TryToConnectExt 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TryToConnectExt_0100"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::EXT_INVAL_ARG).GetCode())); + auto res = service->TryToConnectExt(bundleName, extConnection); + EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TryToConnectExt."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TryToConnectExt_0100"; +} + +/** + * @tc.number: SUB_Service_CleanBundleTempDir_0000 + * @tc.name: SUB_Service_CleanBundleTempDir_0000 + * @tc.desc: 测试 CleanBundleTempDir 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_CleanBundleTempDir_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_CleanBundleTempDir_0000"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + auto res = service->CleanBundleTempDir(bundleName); + EXPECT_EQ(res, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by CleanBundleTempDir."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_CleanBundleTempDir_0000"; +} + +/** + * @tc.number: SUB_Service_CleanBundleTempDir_0100 + * @tc.name: SUB_Service_CleanBundleTempDir_0100 + * @tc.desc: 测试 CleanBundleTempDir 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_CleanBundleTempDir_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_CleanBundleTempDir_0100"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) + .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + auto res = service->CleanBundleTempDir(bundleName); + EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by CleanBundleTempDir."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_CleanBundleTempDir_0100"; +} } \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp index 75782d0a6..b4f762448 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp @@ -541,4 +541,36 @@ HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetIncrementalBackupFile } GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100"; } + +/** + * @tc.number: SUB_Ext_Extension_proxy_CleanBundleTempDir_0100 + * @tc.name: SUB_Ext_Extension_proxy_CleanBundleTempDir_0100 + * @tc.desc: 测试 CleanBundleTempDir 接口调用成功和失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_CleanBundleTempDir_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_CleanBundleTempDir_0100"; + try { + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); + EXPECT_TRUE(proxy_ != nullptr); + ErrCode ret = proxy_->CleanBundleTempDir(); + EXPECT_EQ(EPERM, ret); + + EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); + ret = proxy_->CleanBundleTempDir(); + EXPECT_EQ(BError(BError::Codes::OK), ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by CleanBundleTempDir."; + } + GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_CleanBundleTempDir_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file 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 cd176ce50..47852f950 100644 --- a/tests/unittests/backup_sa/session/b_incremental_session_test.cpp +++ b/tests/unittests/backup_sa/session/b_incremental_session_test.cpp @@ -935,4 +935,38 @@ HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2800, testing::e } GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_2800"; } + +/** + * @tc.number: SUB_b_incremental_session_test_2900 + * @tc.name: SUB_b_incremental_session_test_2900 + * @tc.desc: 测试 CleanBundleTempDir 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2900"; + try { + std::string bundleName; + ServiceClient::serviceProxy_ = nullptr; + ASSERT_TRUE(backupSession != nullptr); + auto err = backupSession->CleanBundleTempDir(bundleName); + EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); + + ServiceClient::serviceProxy_ = proxy; + EXPECT_CALL(*proxy, CleanBundleTempDir(_)).WillOnce(Return(BError(BError::Codes::SDK_BROKEN_IPC).GetCode())); + err = backupSession->CleanBundleTempDir(bundleName); + EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode()); + + EXPECT_CALL(*proxy, CleanBundleTempDir(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + err = backupSession->CleanBundleTempDir(bundleName); + EXPECT_EQ(err, ERR_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by CleanBundleTempDir."; + } + GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_2900"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 9e08d8a7e134a6a1367a6d19732d788f68b95d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Mon, 19 May 2025 15:43:18 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- tests/moduletests/backup_kit_inner/b_session_backup_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp index 11e9deaf0..727593169 100644 --- a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp @@ -483,7 +483,7 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_1200, testing::ext::Tes * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 - * @tc.require: issuesI9KPRL + * @tc.require: IC7RHQ */ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_1300, testing::ext::TestSize.Level1) { -- Gitee From d69ac2e44eb6a28950240c4419272ad06946f3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Wed, 21 May 2025 16:00:56 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- services/backup_sa/src/module_ipc/service.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 4d5cef0d8..c412346d9 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -2089,18 +2089,18 @@ ErrCode Service::TryToConnectExt(const std::string& bundleName, sptrCreateBackupConnection(bundleName); - } - if (extConnection == nullptr) { - HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); + if (extConnection == nullptr) { + HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } } auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); extConnection->SetCallback(callConnected); extConnection->SetCallDied(callDied); AAFwk::Want want = CreateConnectWant(bundleName); - auto err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); - if (err) { + ErrCode err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (err != BError(BError::Codes::OK)) { HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); return BError(BError::Codes::SA_BOOT_EXT_FAIL);; } @@ -2118,7 +2118,7 @@ ErrCode Service::CleanBundleTempDir(const string &bundleName) } sptr backupConnection; ErrCode err = TryToConnectExt(bundleName, backupConnection); - if (err) {return err;} + if (err != BError(BError::Codes::OK)) {return err;} std::unique_lock lock(getBackupInfoSyncLock_); getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); -- Gitee From 18c8f296b6e16256e001c481fe81178c79ad2923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Thu, 22 May 2025 11:41:34 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../module_ipc/service_other_test.cpp | 93 +++++++++++++++---- 1 file changed, 75 insertions(+), 18 deletions(-) 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 777a1209d..a7902d27f 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -2342,10 +2342,7 @@ HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0000, testing::ext::TestSize.L EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_CALL(*session, GetScenario()) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); auto res = service->TryToConnectExt(bundleName, extConnection); EXPECT_EQ(res, BError(BError::Codes::OK).GetCode()); @@ -2371,14 +2368,12 @@ HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0100, testing::ext::TestSize.L try { BundleName bundleName; sptr extConnection; - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); + EXPECT_CALL(*session, CreateBackupConnection(_)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_CALL(*session, GetScenario()) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::EXT_INVAL_ARG).GetCode())); auto res = service->TryToConnectExt(bundleName, extConnection); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); @@ -2389,6 +2384,74 @@ HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0100, testing::ext::TestSize.L GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TryToConnectExt_0100"; } +/** + * @tc.number: SUB_Service_TryToConnectExt_0200 + * @tc.name: SUB_Service_TryToConnectExt_0200 + * @tc.desc: 测试 TryToConnectExt 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TryToConnectExt_0200"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); + EXPECT_CALL(*session, GetSessionUserId()).WillRepeatedly(Return(0)); + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillRepeatedly(Return(make_pair(true, DEBUG_ID + 1))); + EXPECT_CALL(*skeleton, GetCallingUid()).WillRepeatedly(Return(BConstants::XTS_UID)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + auto res = service->TryToConnectExt(bundleName, extConnection); + EXPECT_EQ(res, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TryToConnectExt."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TryToConnectExt_0200"; +} + +/** + * @tc.number: SUB_Service_TryToConnectExt_0300 + * @tc.name: SUB_Service_TryToConnectExt_0300 + * @tc.desc: 测试 TryToConnectExt 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: IC7RHQ + */ +HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TryToConnectExt_0300"; + try { + BundleName bundleName; + sptr extConnection; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); + EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(false)); + EXPECT_CALL(*session, GetSessionUserId()).WillRepeatedly(Return(0)); + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillRepeatedly(Return(make_pair(true, DEBUG_ID + 1))); + EXPECT_CALL(*skeleton, GetCallingUid()).WillRepeatedly(Return(BConstants::XTS_UID)); + EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); + auto res = service->TryToConnectExt(bundleName, extConnection); + EXPECT_EQ(res, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TryToConnectExt."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TryToConnectExt_0300"; +} + /** * @tc.number: SUB_Service_CleanBundleTempDir_0000 * @tc.name: SUB_Service_CleanBundleTempDir_0000 @@ -2408,10 +2471,7 @@ HWTEST_F(ServiceTest, SUB_Service_CleanBundleTempDir_0000, testing::ext::TestSiz EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_CALL(*session, GetScenario()) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); auto res = service->CleanBundleTempDir(bundleName); EXPECT_EQ(res, BError(BError::Codes::OK).GetCode()); @@ -2441,10 +2501,7 @@ HWTEST_F(ServiceTest, SUB_Service_CleanBundleTempDir_0100, testing::ext::TestSiz EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); EXPECT_CALL(*connect, IsExtAbilityConnected()).WillOnce(Return(true)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); - EXPECT_CALL(*session, GetScenario()) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)) - .WillOnce(Return(IServiceReverseType::Scenario::UNDEFINED)); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); auto res = service->CleanBundleTempDir(bundleName); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); -- Gitee From 5e0e21c1abc0fc500f119b05a625b3bbd3e946ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Fri, 23 May 2025 17:35:47 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../native/backup_ext/src/ext_extension.cpp | 2 +- .../js/backup/session_backup_n_exporter.cpp | 5 +- .../session_incremental_backup_n_exporter.cpp | 3 +- .../js/backup/session_restore_n_exporter.cpp | 3 +- services/backup_sa/src/module_ipc/service.cpp | 66 ------------------- .../src/module_ipc/service_incremental.cpp | 66 +++++++++++++++++++ .../backup_sa/src/module_ipc/sub_service.cpp | 66 +++++++++++++++++++ .../module_ipc/service_other_test.cpp | 6 +- 8 files changed, 144 insertions(+), 73 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index baff90264..9d78d41ba 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -2210,7 +2210,7 @@ ErrCode BackupExtExtension::IncrementalAllFileReady(const TarMap &pkgInfo, ErrCode BackupExtExtension::CleanBundleTempDir() { - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("BackupExtExtension::CleanBundleTempDir begin"); if (extension_ == nullptr) { HILOGE("Failed to CleanBundleTempDir, extension is nullptr"); diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index 16cb2b472..bcd5846fc 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -655,7 +655,8 @@ napi_value SessionBackupNExporter::Cancel(napi_env env, napi_callback_info info) return nResult; } -static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, + const NFuncArg &funcArg, std::unique_ptr bundleName) { auto backupEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); if (!(backupEntity && (backupEntity->session))) { @@ -677,7 +678,7 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac if (!SAUtils::CheckBackupPermission()) { HILOGE("Has not permission!"); NError(E_PERMISSION).ThrowErr(env); - return nullptr; + return nullptr; } if (!SAUtils::IsSystemApp()) { HILOGE("System App check fail!"); diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index 7500113c7..a7d45d0ea 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -654,7 +654,8 @@ napi_value SessionIncrementalBackupNExporter::Cancel(napi_env env, napi_callback return nResult; } -static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, + std::unique_ptr bundleName) { auto backupEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); if (!(backupEntity && (backupEntity->session))) { diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 5dee375ec..dcbe0c97d 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -841,7 +841,8 @@ napi_value SessionRestoreNExporter::Cancel(napi_env env, napi_callback_info info return nResult; } -static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, std::unique_ptr bundleName) +static NContextCBExec CleanBundleTempDirCBExec(napi_env env, const NFuncArg &funcArg, + std::unique_ptr bundleName) { auto restoreEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); if (!(restoreEntity && (restoreEntity->sessionWhole || restoreEntity->sessionSheet))) { diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index c412346d9..b99c31699 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -2080,70 +2080,4 @@ void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userI session_->SetSessionUserId(GetUserIdDefault()); } } - -ErrCode Service::TryToConnectExt(const std::string& bundleName, sptr& extConnection) -{ - extConnection = session_->GetExtConnection(bundleName); - if (extConnection != nullptr && extConnection->IsExtAbilityConnected()) { - return BError(BError::Codes::OK); - } - if (extConnection == nullptr) { - extConnection = session_->CreateBackupConnection(bundleName); - if (extConnection == nullptr) { - HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); - } - } - auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); - auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); - extConnection->SetCallback(callConnected); - extConnection->SetCallDied(callDied); - AAFwk::Want want = CreateConnectWant(bundleName); - ErrCode err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); - if (err != BError(BError::Codes::OK)) { - HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); - return BError(BError::Codes::SA_BOOT_EXT_FAIL);; - } - return BError(BError::Codes::OK); -} - -ErrCode Service::CleanBundleTempDir(const string &bundleName) -{ - HILOGI("Service::CleanBundleTempDir"); - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - - if (session_ == nullptr) { - HILOGE("session is empty."); - return BError(BError::Codes::SA_INVAL_ARG); - } - sptr backupConnection; - ErrCode err = TryToConnectExt(bundleName, backupConnection); - if (err != BError(BError::Codes::OK)) {return err;} - - std::unique_lock lock(getBackupInfoSyncLock_); - getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); - if (isConnectDied_.load()) { - HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); - isConnectDied_.store(false); - return BError(BError::Codes::EXT_ABILITY_DIED); - } - - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - if (backupConnection == nullptr) { - HILOGE("backupConnection is empty."); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::SA_INVAL_ARG); - } - auto proxy = backupConnection->GetBackupExtProxy(); - if (!proxy) { - HILOGE("Extension backup Proxy is empty."); - backupConnection->DisconnectBackupExtAbility(); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::SA_INVAL_ARG); - } - proxy->CleanBundleTempDir(); - backupConnection->DisconnectBackupExtAbility(); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); -} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index f0bac2704..b3e38dab3 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -1041,4 +1041,70 @@ ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) } return BError(BError::Codes::OK); } + +ErrCode Service::TryToConnectExt(const std::string& bundleName, sptr& extConnection) +{ + extConnection = session_->GetExtConnection(bundleName); + if (extConnection != nullptr && extConnection->IsExtAbilityConnected()) { + return BError(BError::Codes::OK); + } + if (extConnection == nullptr) { + extConnection = session_->CreateBackupConnection(bundleName); + if (extConnection == nullptr) { + HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + } + auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); + auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); + extConnection->SetCallback(callConnected); + extConnection->SetCallDied(callDied); + AAFwk::Want want = CreateConnectWant(bundleName); + ErrCode err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (err != BError(BError::Codes::OK)) { + HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); + return BError(BError::Codes::SA_BOOT_EXT_FAIL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::CleanBundleTempDir(const string &bundleName) +{ + HILOGI("Service::CleanBundleTempDir"); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + + if (session_ == nullptr) { + HILOGE("session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + sptr backupConnection; + ErrCode err = TryToConnectExt(bundleName, backupConnection); + if (err != BError(BError::Codes::OK)) {return err;} + + std::unique_lock lock(getBackupInfoSyncLock_); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); + if (isConnectDied_.load()) { + HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); + isConnectDied_.store(false); + return BError(BError::Codes::EXT_ABILITY_DIED); + } + + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + if (backupConnection == nullptr) { + HILOGE("backupConnection is empty."); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Extension backup Proxy is empty."); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + proxy->CleanBundleTempDir(); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index af34f0b6f..3fe2a899d 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -1320,4 +1320,70 @@ ErrCode Service::StartFwkTimer(bool &isFwkStart) return EPERM; } } + +ErrCode Service::TryToConnectExt(const std::string& bundleName, sptr& extConnection) +{ + extConnection = session_->GetExtConnection(bundleName); + if (extConnection != nullptr && extConnection->IsExtAbilityConnected()) { + return BError(BError::Codes::OK); + } + if (extConnection == nullptr) { + extConnection = session_->CreateBackupConnection(bundleName); + if (extConnection == nullptr) { + HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + } + auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); + auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); + extConnection->SetCallback(callConnected); + extConnection->SetCallDied(callDied); + AAFwk::Want want = CreateConnectWant(bundleName); + ErrCode err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); + if (err != BError(BError::Codes::OK)) { + HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); + return BError(BError::Codes::SA_BOOT_EXT_FAIL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::CleanBundleTempDir(const string &bundleName) +{ + HILOGI("Service::CleanBundleTempDir"); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + + if (session_ == nullptr) { + HILOGE("session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + sptr backupConnection; + ErrCode err = TryToConnectExt(bundleName, backupConnection); + if (err != BError(BError::Codes::OK)) {return err;} + + std::unique_lock lock(getBackupInfoSyncLock_); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); + if (isConnectDied_.load()) { + HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); + isConnectDied_.store(false); + return BError(BError::Codes::EXT_ABILITY_DIED); + } + + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + if (backupConnection == nullptr) { + HILOGE("backupConnection is empty."); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("Extension backup Proxy is empty."); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + proxy->CleanBundleTempDir(); + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); +} } \ No newline at end of file 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 a7902d27f..ef69344b3 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -2374,7 +2374,8 @@ HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0100, testing::ext::TestSize.L EXPECT_CALL(*session, CreateBackupConnection(_)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); - EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::EXT_INVAL_ARG).GetCode())); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)) + .WillOnce(Return(BError(BError::Codes::EXT_INVAL_ARG).GetCode())); auto res = service->TryToConnectExt(bundleName, extConnection); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); } catch (...) { @@ -2442,7 +2443,8 @@ HWTEST_F(ServiceTest, SUB_Service_TryToConnectExt_0300, testing::ext::TestSize.L EXPECT_CALL(*skeleton, GetCallingUid()).WillRepeatedly(Return(BConstants::XTS_UID)); EXPECT_CALL(*connect, DisconnectBackupExtAbility()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::UNDEFINED)); - EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)).WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); + EXPECT_CALL(*connect, ConnectBackupExtAbility(_, _, _)) + .WillOnce(Return(BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode())); auto res = service->TryToConnectExt(bundleName, extConnection); EXPECT_EQ(res, BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); } catch (...) { -- Gitee From 2cc1a70c27e6501e3fae3184d061774dad278b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Fri, 23 May 2025 18:04:18 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../src/module_ipc/service_incremental.cpp | 66 ------------------- .../backup_sa/src/module_ipc/sub_service.cpp | 1 + 2 files changed, 1 insertion(+), 66 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index b3e38dab3..f0bac2704 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -1041,70 +1041,4 @@ ErrCode Service::Cancel(const std::string& bundleName, int32_t &result) } return BError(BError::Codes::OK); } - -ErrCode Service::TryToConnectExt(const std::string& bundleName, sptr& extConnection) -{ - extConnection = session_->GetExtConnection(bundleName); - if (extConnection != nullptr && extConnection->IsExtAbilityConnected()) { - return BError(BError::Codes::OK); - } - if (extConnection == nullptr) { - extConnection = session_->CreateBackupConnection(bundleName); - if (extConnection == nullptr) { - HILOGE("backupConnection is null, bundleName: %{public}s", bundleName.c_str()); - return BError(BError::Codes::SA_INVAL_ARG); - } - } - auto callConnected = GetBackupInfoConnectDone(wptr(this), bundleName); - auto callDied = GetBackupInfoConnectDied(wptr(this), bundleName); - extConnection->SetCallback(callConnected); - extConnection->SetCallDied(callDied); - AAFwk::Want want = CreateConnectWant(bundleName); - ErrCode err = extConnection->ConnectBackupExtAbility(want, GetUserIdDefault(), false); - if (err != BError(BError::Codes::OK)) { - HILOGE("ConnectBackupExtAbility failed, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), err); - return BError(BError::Codes::SA_BOOT_EXT_FAIL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::CleanBundleTempDir(const string &bundleName) -{ - HILOGI("Service::CleanBundleTempDir"); - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - - if (session_ == nullptr) { - HILOGE("session is empty."); - return BError(BError::Codes::SA_INVAL_ARG); - } - sptr backupConnection; - ErrCode err = TryToConnectExt(bundleName, backupConnection); - if (err != BError(BError::Codes::OK)) {return err;} - - std::unique_lock lock(getBackupInfoSyncLock_); - getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); - if (isConnectDied_.load()) { - HILOGE("GetBackupInfoConnectDied, please check bundleName: %{public}s", bundleName.c_str()); - isConnectDied_.store(false); - return BError(BError::Codes::EXT_ABILITY_DIED); - } - - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - if (backupConnection == nullptr) { - HILOGE("backupConnection is empty."); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::SA_INVAL_ARG); - } - auto proxy = backupConnection->GetBackupExtProxy(); - if (!proxy) { - HILOGE("Extension backup Proxy is empty."); - backupConnection->DisconnectBackupExtAbility(); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::SA_INVAL_ARG); - } - proxy->CleanBundleTempDir(); - backupConnection->DisconnectBackupExtAbility(); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); -} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 3fe2a899d..a60292565 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -72,6 +72,7 @@ namespace { const int32_t MAX_FILE_READY_REPORT_TIME = 2; const int32_t WAIT_SCANNING_INFO_SEND_TIME = 5; const int ERR_SIZE = -1; +const int32_t CONNECT_WAIT_TIME_S = 15; } // namespace void Service::AppendBundles(const std::vector &bundleNames) -- Gitee From fff2b75ab708b5e192390c83a66bd145f7117ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Fri, 23 May 2025 19:47:10 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../session_incremental_backup_n_exporter.cpp | 2 +- .../js/backup/session_restore_n_exporter.cpp | 2 +- .../backup_sa/include/module_ipc/service.h | 1 + services/backup_sa/src/module_ipc/service.cpp | 1 - .../backup_sa/src/module_ipc/sub_service.cpp | 1 - .../src/module_ipc/svc_extension_proxy.cpp | 20 ------------------- 6 files changed, 3 insertions(+), 24 deletions(-) diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index a7d45d0ea..6c7c377fd 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -677,7 +677,7 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n if (!SAUtils::CheckBackupPermission()) { HILOGE("Has not permission!"); NError(E_PERMISSION).ThrowErr(env); - return nullptr; + return nullptr; } if (!SAUtils::IsSystemApp()) { HILOGE("System App check fail!"); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index dcbe0c97d..fc133f104 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -867,7 +867,7 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba if (!SAUtils::CheckBackupPermission()) { HILOGE("Has not permission!"); NError(E_PERMISSION).ThrowErr(env); - return nullptr; + return nullptr; } if (!SAUtils::IsSystemApp()) { HILOGE("System App check fail!"); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index cf9346037..d3e961eba 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -45,6 +45,7 @@ struct BundleTaskInfo { ErrCode errCode; }; const int INVALID_FD = -1; +constexpr const int32_t CONNECT_WAIT_TIME_S = 15; class Service : public SystemAbility, public ServiceStub, protected NoCopyable { DECLARE_SYSTEM_ABILITY(Service); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b99c31699..ecced7d84 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -81,7 +81,6 @@ constexpr int32_t MS_1000 = 1000; const static string BROADCAST_TYPE = "broadcast"; const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; const static string UNICAST_TYPE = "unicast"; -const int32_t CONNECT_WAIT_TIME_S = 15; const std::string BACKUPSERVICE_WORK_STATUS_KEY = "persist.backupservice.workstatus"; const std::string BACKUPSERVICE_WORK_STATUS_ON = "true"; const std::string BACKUPSERVICE_WORK_STATUS_OFF = "false"; diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index a60292565..3fe2a899d 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -72,7 +72,6 @@ namespace { const int32_t MAX_FILE_READY_REPORT_TIME = 2; const int32_t WAIT_SCANNING_INFO_SEND_TIME = 5; const int ERR_SIZE = -1; -const int32_t CONNECT_WAIT_TIME_S = 15; } // namespace void Service::AppendBundles(const std::vector &bundleNames) diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 6882f4c37..bd0d8e8a0 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -212,24 +212,4 @@ ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int32_t sen HILOGI("SvcExtensionProxy::UpdateFdSendRate end."); return ret; } - -ErrCode SvcExtensionProxy::CleanBundleTempDir() -{ - HILOGD("CleanBundleTempDir start"); - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - - MessageParcel reply; - MessageOption option; - int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_CLEAN_BUNDLE_TEMP_DIR), data, reply, option); - if (ret != NO_ERROR) { - HILOGE("Received error %{public}d when doing IPC", ret); - return ErrCode(ret); - } - HILOGD("CleanBundleTempDir end"); - return reply.ReadInt32(); -} } // namespace OHOS::FileManagement::Backup -- Gitee From 56e04720be6d0d4d335f9379330deab27da7a865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Fri, 23 May 2025 20:00:53 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../module_ipc/svc_extension_proxy_test.cpp | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp index b4f762448..75782d0a6 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp @@ -541,36 +541,4 @@ HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetIncrementalBackupFile } GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetIncrementalBackupFileHandle_0100"; } - -/** - * @tc.number: SUB_Ext_Extension_proxy_CleanBundleTempDir_0100 - * @tc.name: SUB_Ext_Extension_proxy_CleanBundleTempDir_0100 - * @tc.desc: 测试 CleanBundleTempDir 接口调用成功和失败 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: IC7RHQ - */ -HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_CleanBundleTempDir_0100, - testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_CleanBundleTempDir_0100"; - try { - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(EPERM)); - EXPECT_TRUE(proxy_ != nullptr); - ErrCode ret = proxy_->CleanBundleTempDir(); - EXPECT_EQ(EPERM, ret); - - EXPECT_CALL(*messageParcelMock_, WriteInterfaceToken(_)).WillOnce(Return(true)); - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(0)); - EXPECT_CALL(*messageParcelMock_, ReadInt32()).WillOnce(Return(0)); - ret = proxy_->CleanBundleTempDir(); - EXPECT_EQ(BError(BError::Codes::OK), ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-an exception occurred by CleanBundleTempDir."; - } - GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_CleanBundleTempDir_0100"; -} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 81e6ea5c4be20945dc47699fadb58a41eb6082ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E4=BC=9F1?= Date: Sat, 24 May 2025 10:17:50 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E2=80=9C=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=A1=86=E6=9E=B6=E6=94=AF=E6=8C=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=BB=E5=8A=A8=E6=B8=85=E7=90=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李世伟1 --- .../native/backup_ext/include/ext_extension.h | 3 +++ frameworks/native/backup_ext/src/ext_extension.cpp | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 0cb3d575d..88ae32c43 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -123,6 +123,9 @@ private: /** @brief clear backup restore data */ void DoClear(); + /** @brief inner of doing clear backup restore data */ + void DoClearInner(); + /** * @brief extension 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 9d78d41ba..073f35e7d 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1768,6 +1768,15 @@ void BackupExtExtension::DoClear() HILOGI("configured not clear data."); return; } + DoClearInner(); + } catch (...) { + HILOGE("Failed to clear"); + } +} + +void BackupExtExtension::DoClearInner() +{ + try { string backupCache = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string restoreCache = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); string specialRestoreCache = GetRestoreTempPath(bundleName_); @@ -2221,10 +2230,7 @@ ErrCode BackupExtExtension::CleanBundleTempDir() } try { VerifyCaller(); - bool isClearFlag = isClearData_; - isClearData_ = true; - DoClear(); - isClearData_ = isClearFlag; + DoClearInner(); return ERR_OK; } catch (...) { HILOGE("Failed to CleanBundleTempDir"); -- Gitee