diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 9d7ab287b50aa7165e13750bb09d0f615b673912..0cb3d575d1b52998d57b3cc20dab84a1c6ac44db 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 849fb2b594aeabc3650b6092685d86d965259fd8..6b2280aa568c7ac1c86c5b23770b931d12cce367 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 731e23cdf17a063940fb63225dc28ac998d2e14d..12f5894d4a64978dbe55a39e112c224290e7df91 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 25bcef8131ffaa18dd98ac7b02d30de472700afe..6b25a187817773ca3795672781860e4d5e406f3b 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 863d696d5098672c16def83003596ef783c5e349..38693ecd8f4d79b8a2e326ad3873e022a0569b27 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 3daf19df33ddc3948cbd8824583dda21949283a9..f6ecfe044be88283ee5c35c3d6fc8032e6a9fd6b 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 934cb55932ecd6126b7085ffc6841d1d4097775c..b32113789cdfe8600b667492ac01aec1179ba9e7 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 3b0e46a9c3498b43dd10d39241405d9080a2c92e..feaadb654955a5a2514c7932a86486a0d03931c8 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 0fbcb4dc26fd04246e0c79551af32dcc6da08726..7f5cd583d69ebc0d36ed1e2d89734d14bda6e024 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 7aa5fdcd8fe50ad7082eaa3aefb0b0a3d3e0a4fd..4dd41dc361152df1629db1199a26bc6b545d07e5 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 c04ef6664b89560dfab6604181d2810a8634f504..bf6d7cadb627131d27e87246f61695c8bd9b0ff7 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 5fc20d610966df10727baef4b0d19cb89d5df590..708f3b9b714110e8d6bce8848788f324507405e2 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 05912440e21fbcaa731e510b3b52876f3771fbda..eee4891be23d5e78a0d72c8e7ec2ca300335cda5 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 d2d5ba4758873d32992445c3a038390630f4f1e9..7f9547232f0fef20da12c0bdcb05b6fca8b11d1e 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 ef6ddf6df0e597aaaec74df1e61ffcd9fd0b2dfc..e30fd9beb2b72c59665697af5f4b69daecd3cd2a 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 157f34b4a5ddff950585779220f4593e1a1a6dd7..12a40fca8a98920d8b466a79b9331e036dbec53b 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 d6d37d3d1711bcb7e5ad7eae3ef2c69dd4a0fa43..4dcff5076053d1961f823cbd4ed59ca1295392f7 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 5ecb32295e735de7c6268fb1dde21bbc7f62c6b9..d5cc82be5d7eeeee2875ae5f671cb53e2eb3a03c 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 f68dd45d3752715b69e619f16faddf63b53e4b89..53d3180f7879c1c1f8e560fe969d04af3a9607c7 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 6e421860207f5d8109c9c4a0e3708528ba204fa0..62b37704ab8e4c5595a3c668b85959f677e3f439 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 bd0d8e8a01b1c75a1ae5989e40d6ced0dbb0e411..6882f4c3770c96249dde4c6bc9f7a81b2b9ade6c 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