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 be5413d5d0d0b98c5a53d04c78b008b1b3743bb2..9f6ef2247c7c2ed817358f12cab8e062ac62a677 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 @@ -215,4 +215,15 @@ ErrCode BIncrementalBackupSession::CleanBundleTempDir(const std::string &bundleN } return proxy->CleanBundleTempDir(bundleName); } + +ErrCode BIncrementalBackupSession::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + HILOGI("BIncrementalBackupSession::GetCompatibilityInfo"); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->GetCompatibilityInfo(bundleName, extInfo, compatInfo); +} } // 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 78b92c231dd36323d6dd594e662ce6c5e9dbca6d..23fc5385edc25c3c86bba19e5623d5b285fc69a8 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 @@ -237,4 +237,15 @@ ErrCode BIncrementalRestoreSession::CleanBundleTempDir(const std::string &bundle } return proxy->CleanBundleTempDir(bundleName); } + +ErrCode BIncrementalRestoreSession::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + HILOGI("BIncrementalRestoreSession::GetCompatibilityInfo"); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->GetCompatibilityInfo(bundleName, extInfo, compatInfo); +} } // 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 992125a31fa55a961dd1378d356e66339eeb00c6..ec93502a96b58bbd3ae52914c1a7b52de3410464 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -234,4 +234,15 @@ ErrCode BSessionBackup::CleanBundleTempDir(const std::string &bundleName) } return proxy->CleanBundleTempDir(bundleName); } + +ErrCode BSessionBackup::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + HILOGI("BSessionBackup::GetCompatibilityInfo"); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->GetCompatibilityInfo(bundleName, extInfo, compatInfo); +} } // 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 34dfc57c322d5556b26677ea07bbfe614ee65148..e2215940cf1eab06e3345fbcf2a97afadfb8fcd4 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -215,4 +215,15 @@ ErrCode BSessionRestore::CleanBundleTempDir(const std::string &bundleName) } return proxy->CleanBundleTempDir(bundleName); } + +ErrCode BSessionRestore::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + HILOGI("BSessionRestore::GetCompatibilityInfo"); + auto proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->GetCompatibilityInfo(bundleName, extInfo, compatInfo); +} } // 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 b32113789cdfe8600b667492ac01aec1179ba9e7..d1bbec06e649ae74c70da064e0dc473ef0a1defd 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 @@ -123,6 +123,16 @@ public: */ ErrCode CleanBundleTempDir(const std::string &bundleName); + /** + * @brief 获取备份或恢复的应用的兼容性信息 + * + * @param bundleName 应用名称 + * @param extInfo 导入给应用的信息 + * @param compatInfo 应用返回的兼容信息 + * @return ErrCode 规范错误码 + */ + ErrCode GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, std::string &compatInfo); + 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 feaadb654955a5a2514c7932a86486a0d03931c8..64855efab2c4025d69aedbaa8daa8680190d2598 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 @@ -145,6 +145,16 @@ public: */ ErrCode CleanBundleTempDir(const std::string &bundleName); + /** + * @brief 获取备份或恢复的应用的兼容性信息 + * + * @param bundleName 应用名称 + * @param extInfo 导入给应用的信息 + * @param compatInfo 应用返回的兼容信息 + * @return ErrCode 规范错误码 + */ + ErrCode GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, std::string &compatInfo); + 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 7f5cd583d69ebc0d36ed1e2d89734d14bda6e024..4382c0d08192aa6ed0522039b9cb98a33fa25d78 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 @@ -138,6 +138,16 @@ public: */ ErrCode CleanBundleTempDir(const std::string &bundleName); + /** + * @brief 获取备份或恢复的应用的兼容性信息 + * + * @param bundleName 应用名称 + * @param extInfo 导入给应用的信息 + * @param compatInfo 应用返回的兼容信息 + * @return ErrCode 规范错误码 + */ + ErrCode GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, std::string &compatInfo); + 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 4dd41dc361152df1629db1199a26bc6b545d07e5..e637a13545e0b8bf535e168838ce2faadcdb43f5 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 @@ -145,6 +145,16 @@ public: */ ErrCode CleanBundleTempDir(const std::string &bundleName); + /** + * @brief 获取备份或恢复的应用的兼容性信息 + * + * @param bundleName 应用名称 + * @param extInfo 导入给应用的信息 + * @param compatInfo 应用返回的兼容信息 + * @return ErrCode 规范错误码 + */ + ErrCode GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, std::string &compatInfo); + 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 bcd5846fc44b4275d0dac20243566eb6ef29214f..5f6ea2927cd57d6f5cbb867d432dbc28a09b8c2e 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -712,6 +712,83 @@ napi_value SessionBackupNExporter::CleanBundleTempDir(napi_env env, napi_callbac return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; } +static NContextCBExec GetCompatibilityInfoCBExec(napi_env env, const NFuncArg &funcArg, string bundleName, + string extInfo, shared_ptr compatInfo) +{ + 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, extInfo, compatInfo]() -> NError { + if (!(entity && (entity->session))) { + return NError(BError(BError::Codes::SDK_INVAL_ARG, "Backup session is nullptr").GetCode()); + } + return NError(entity->session->GetCompatibilityInfo(bundleName, extInfo, *compatInfo)); + }; +} + +static bool ParseCompatInfoParam(napi_env env, NFuncArg &funcArg, string &bundleName, string &extInfo) +{ + if (!funcArg.InitArgs(NARG_CNT::TWO)) { + HILOGE("Number of arguments unmatched"); + return false; + } + NVal jsBundleName(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleNamePtr, sizeStr] = jsBundleName.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + return false; + } + NVal jsExtInfo(env, funcArg[NARG_POS::SECOND]); + auto [succ1, extInfoPtr, sizeStr1] = jsExtInfo.ToUTF8String(); + if (!succ1) { + HILOGE("Second arguments is not string."); + return false; + } + bundleName = string(bundleNamePtr.get()); + extInfo = string(extInfoPtr.get()); + return true; +} + +napi_value SessionBackupNExporter::GetCompatibilityInfo(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionBackupNExporter::GetCompatibilityInfo 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); + string bundleName; + string extInfo; + if (!ParseCompatInfoParam(env, funcArg, bundleName, extInfo)) { + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto compatInfo = std::make_shared(); + auto cbExec = GetCompatibilityInfoCBExec(env, funcArg, bundleName, extInfo, compatInfo); + if (cbExec == nullptr) { + HILOGE("GetCompatibilityInfoCBExec fail!"); + NError(E_GETRESULT).ThrowErr(env); + return nullptr; + } + auto cbCompl = [compatInfo](napi_env env, NError err) -> NVal { + return err ? NVal {env, err.GetNapiErr(env)} : NVal::CreateUTF8String(env, *compatInfo); + }; + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionBackupNExporter::Export() { HILOGD("called SessionBackupNExporter::Export begin"); @@ -722,6 +799,7 @@ bool SessionBackupNExporter::Export() NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), + NVal::DeclareNapiFunction("getCompatibilityInfo", GetCompatibilityInfo), }; 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 708f3b9b714110e8d6bce8848788f324507405e2..92b0c82912aac77f6b4099d6a0cc65c5a97266d8 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.h +++ b/interfaces/kits/js/backup/session_backup_n_exporter.h @@ -32,6 +32,7 @@ public: 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); + static napi_value GetCompatibilityInfo(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 6c7c377fd9611ed8416ba5f361d8b889ac7283d1..c7ecee758013dd14d251f2c235f643f224e5f8c8 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -711,6 +711,84 @@ napi_value SessionIncrementalBackupNExporter::CleanBundleTempDir(napi_env env, n return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; } + +static NContextCBExec GetCompatibilityInfoCBExec(napi_env env, const NFuncArg &funcArg, string bundleName, + string extInfo, shared_ptr compatInfo) +{ + 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, extInfo, compatInfo]() -> NError { + if (!(entity && (entity->session))) { + return NError(BError(BError::Codes::SDK_INVAL_ARG, "Backup session is nullptr").GetCode()); + } + return NError(entity->session->GetCompatibilityInfo(bundleName, extInfo, *compatInfo)); + }; +} + +static bool ParseCompatInfoParam(napi_env env, NFuncArg &funcArg, string &bundleName, string &extInfo) +{ + if (!funcArg.InitArgs(NARG_CNT::TWO)) { + HILOGE("Number of arguments unmatched"); + return false; + } + NVal jsBundleName(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleNamePtr, sizeStr] = jsBundleName.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + return false; + } + NVal jsExtInfo(env, funcArg[NARG_POS::SECOND]); + auto [succ1, extInfoPtr, sizeStr1] = jsExtInfo.ToUTF8String(); + if (!succ1) { + HILOGE("Second arguments is not string."); + return false; + } + bundleName = string(bundleNamePtr.get()); + extInfo = string(extInfoPtr.get()); + return true; +} + +napi_value SessionIncrementalBackupNExporter::GetCompatibilityInfo(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionIncrementalBackupNExporter::GetCompatibilityInfo 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); + string bundleName; + string extInfo; + if (!ParseCompatInfoParam(env, funcArg, bundleName, extInfo)) { + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto compatInfo = std::make_shared(); + auto cbExec = GetCompatibilityInfoCBExec(env, funcArg, bundleName, extInfo, compatInfo); + if (cbExec == nullptr) { + HILOGE("GetCompatibilityInfoCBExec fail!"); + NError(E_GETRESULT).ThrowErr(env); + return nullptr; + } + auto cbCompl = [compatInfo](napi_env env, NError err) -> NVal { + return err ? NVal {env, err.GetNapiErr(env)} : NVal::CreateUTF8String(env, *compatInfo); + }; + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionIncrementalBackupNExporter::Export() { HILOGD("called SessionIncrementalBackupNExporter::Export begin"); @@ -721,6 +799,7 @@ bool SessionIncrementalBackupNExporter::Export() NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), + NVal::DeclareNapiFunction("getCompatibilityInfo", GetCompatibilityInfo), }; 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 7f9547232f0fef20da12c0bdcb05b6fca8b11d1e..6ebba0c6f12c8492b104226a6e95a4f5610dc547 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.h @@ -32,6 +32,7 @@ public: 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); + static napi_value GetCompatibilityInfo(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 b57a9b27107490108e9e05971b4ecbb489e7000d..bf29625ef2ff28066d2ba9a5b0e0fb6a3a2a7069 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -905,6 +905,86 @@ napi_value SessionRestoreNExporter::CleanBundleTempDir(napi_env env, napi_callba return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; } +static NContextCBExec GetCompatibilityInfoCBExec(napi_env env, const NFuncArg &funcArg, string bundleName, + string extInfo, shared_ptr compatInfo) +{ + 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, extInfo, compatInfo]() -> 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->GetCompatibilityInfo(bundleName, extInfo, *compatInfo)); + } + return NError(entity->sessionSheet->GetCompatibilityInfo(bundleName, extInfo, *compatInfo)); + }; +} + +static bool ParseCompatInfoParam(napi_env env, NFuncArg &funcArg, string &bundleName, string &extInfo) +{ + if (!funcArg.InitArgs(NARG_CNT::TWO)) { + HILOGE("Number of arguments unmatched"); + return false; + } + NVal jsBundleName(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundleNamePtr, sizeStr] = jsBundleName.ToUTF8String(); + if (!succ) { + HILOGE("First arguments is not string."); + return false; + } + NVal jsExtInfo(env, funcArg[NARG_POS::SECOND]); + auto [succ1, extInfoPtr, sizeStr1] = jsExtInfo.ToUTF8String(); + if (!succ1) { + HILOGE("Second arguments is not string."); + return false; + } + bundleName = string(bundleNamePtr.get()); + extInfo = string(extInfoPtr.get()); + return true; +} + +napi_value SessionRestoreNExporter::GetCompatibilityInfo(napi_env env, napi_callback_info cbinfo) +{ + HILOGI("Called SessionRestore::GetCompatibilityInfo 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); + string bundleName; + string extInfo; + if (!ParseCompatInfoParam(env, funcArg, bundleName, extInfo)) { + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + + auto compatInfo = std::make_shared(); + auto cbExec = GetCompatibilityInfoCBExec(env, funcArg, bundleName, extInfo, compatInfo); + if (cbExec == nullptr) { + HILOGE("GetCompatibilityInfoCBExec fail!"); + NError(E_GETRESULT).ThrowErr(env); + return nullptr; + } + auto cbCompl = [compatInfo](napi_env env, NError err) -> NVal { + return err ? NVal {env, err.GetNapiErr(env)} : NVal::CreateUTF8String(env, *compatInfo); + }; + + NVal thisVar(env, funcArg.GetThisVar()); + return NAsyncWorkPromise(env, thisVar).Schedule(className, cbExec, cbCompl).val_; +} + bool SessionRestoreNExporter::Export() { HILOGD("called SessionRestoreNExporter::Export begin"); @@ -916,6 +996,7 @@ bool SessionRestoreNExporter::Export() NVal::DeclareNapiFunction("release", Release), NVal::DeclareNapiFunction("cancel", Cancel), NVal::DeclareNapiFunction("cleanBundleTempDir", CleanBundleTempDir), + NVal::DeclareNapiFunction("getCompatibilityInfo", GetCompatibilityInfo), }; 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 12a40fca8a98920d8b466a79b9331e036dbec53b..8924a4dfc8f3baf1bd0bb0e363c4ac9c87cdee89 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.h +++ b/interfaces/kits/js/backup/session_restore_n_exporter.h @@ -36,6 +36,7 @@ public: 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); + static napi_value GetCompatibilityInfo(napi_env env, napi_callback_info cbinfo); SessionRestoreNExporter(napi_env env, napi_value exports); ~SessionRestoreNExporter() override; diff --git a/services/backup_sa/IService.idl b/services/backup_sa/IService.idl index 1fdf7524ec87347cde7aea00878f5df5e3376f31..dda0fe4a09cf303c1dc57b1bce3dd36aaa19a592 100644 --- a/services/backup_sa/IService.idl +++ b/services/backup_sa/IService.idl @@ -76,4 +76,5 @@ interface OHOS.FileManagement.Backup.IService{ [ipccode 42] void GetExtOnRelease([out] boolean isExtOnRelease); [ipccode 43] void AppFileReadyWithoutFd([in]String fileName, [in] int appFileReadyErrCode); [ipccode 44] void AppIncrementalFileReadyWithoutFd([in] String fileName, [in] int appIncrementalFileReadyErrCode); + [ipccode 45] void GetCompatibilityInfo([in] String bundleName, [in] String extInfo, [out] String compatInfo); } \ 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 4a56703c7cf1f4a3ce60977a9fda353360b357b1..3e5052d5ba4830bb34f15953dfc65d9492540ae0 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -120,6 +120,8 @@ public: ErrCode CleanBundleTempDir(const std::string &bundleName) override; ErrCode HandleExtDisconnect(bool isIncBackup) override; ErrCode GetExtOnRelease(bool &isExtOnRelease) override; + ErrCode GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) override; // 以下都是非IPC接口 public: diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index b5b2c0204cf5d1df0a0919c2dd32d9a6e44f27e6..9213633f0098d288d4b9dd5028c8f5f9d75f2519 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -68,7 +68,7 @@ static sptr GetBundleManager() return iface_cast(bundleObj); } -static tuple GetAllowAndExtName( +static tuple GetAllowAndExtName( const vector &extensionInfos) { for (auto &&ext : extensionInfos) { @@ -84,9 +84,9 @@ static tuple GetAllowAndExtName BJsonCachedEntity cachedEntity(out[0], ext.bundleName); auto cache = cachedEntity.Structuralize(); return {cache.GetAllowToBackupRestore(), cache.GetFullBackupOnly(), ext.name, cache.GetRestoreDeps(), - cache.GetSupportScene(), cache.GetExtraInfo()}; + cache.GetSupportScene(), cache.GetExtraInfo(), cache.GetRequireCompatibility()}; } - return {false, false, "", "", "", Json::Value()}; + return {false, false, "", "", "", Json::Value(), false}; } static int64_t GetBundleStats(const string &bundleName, int32_t userId) @@ -135,7 +135,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto HILOGE("Get current extension failed, bundleName:%{public}s", bundleName.c_str()); continue; } - auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = + auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInf, requireCompatibility] = GetAllowAndExtName(bundleExtInfo.extensionInfos_); int64_t dataSize = 0; if (allToBackup) { @@ -143,7 +143,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto } bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {bundleExtInfo.bundleInfo_.name, bundleExtInfo.bundleInfo_.appIndex, bundleExtInfo.bundleInfo_.versionCode, - bundleExtInfo.bundleInfo_.versionName, dataSize, 0, allToBackup, fullBackupOnly, + bundleExtInfo.bundleInfo_.versionName, dataSize, 0, allToBackup, fullBackupOnly, requireCompatibility, extName, restoreDeps, supportScene, extraInfo}); } HILOGI("End, bundleInfos size:%{public}zu", bundleInfos.size()); @@ -184,6 +184,7 @@ static bool GetBackupExtConfig(const vector &e backupPara.extraInfo = cache.GetExtraInfo(); backupPara.includes = cache.GetIncludes(); backupPara.excludes = cache.GetExcludes(); + backupPara.requireCompatibility = cache.GetRequireCompatibility(); return true; } return false; @@ -310,7 +311,8 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {bundleExtInfo.bundleInfo_.name, bundleExtInfo.bundleInfo_.appIndex, bundleExtInfo.bundleInfo_.versionCode, bundleExtInfo.bundleInfo_.versionName, 0, 0, backupPara.allToBackup, backupPara.fullBackupOnly, - backupPara.extensionName, backupPara.restoreDeps, backupPara.supportScene, backupPara.extraInfo}); + backupPara.requireCompatibility, backupPara.extensionName, backupPara.restoreDeps, backupPara.supportScene, + backupPara.extraInfo}); if (bundleExtInfo.bundleInfo_.appIndex > 0) { std::string bundleNameIndex = "+clone-" + std::to_string(bundleExtInfo.bundleInfo_.appIndex) + "+" + bundleExtInfo.bundleInfo_.name; @@ -349,12 +351,12 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } - auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = + auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo, requireCompatibility] = GetAllowAndExtName(installedBundle.extensionInfos); if (!allToBackup) { bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.appIndex, installedBundle.versionCode, installedBundle.versionName, 0, 0, allToBackup, fullBackupOnly, - extName, restoreDeps, supportScene, extraInfo}); + requireCompatibility, extName, restoreDeps, supportScene, extraInfo}); continue; } auto it = std::find_if(extraIncreData.begin(), extraIncreData.end(), @@ -404,13 +406,13 @@ vector BundleMgrAdapter::GetFullBundleInfos(int32_t bundleNames.emplace_back(bundleNameIndexInfo); continue; } - auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = + auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo, requireCompatibility] = GetAllowAndExtName(installedBundle.extensionInfos); if (!allToBackup) { HILOGI("Not allToBackup, bundleName = %{public}s", installedBundle.name.data()); bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.appIndex, - installedBundle.versionCode, installedBundle.versionName, 0, 0, allToBackup, fullBackupOnly, extName, - restoreDeps, supportScene, extraInfo}); + installedBundle.versionCode, installedBundle.versionName, 0, 0, allToBackup, fullBackupOnly, + requireCompatibility, extName, restoreDeps, supportScene, extraInfo}); continue; } bundleNames.emplace_back(installedBundle.name); @@ -464,7 +466,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForSA() HILOGI("GetExtensionSaIds ret: %{public}d", ret); for (const auto &saId : saIds) { saBundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {std::to_string(saId), 0, 0, "", 0, 0, true, false, - "", "", "", ""}); + false, "", "", "", ""}); } return saBundleInfos; } @@ -493,7 +495,8 @@ void BundleMgrAdapter::GetBundleInfoForSA(std::string bundleName, std::vector BundleMgrAdapter::GetBundleInfosForLoca bundleNames.emplace_back(bundleNameIndexInfo); continue; } - auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = + auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo, requireCompatibility] = GetAllowAndExtName(installedBundle.extensionInfos); if (!allToBackup) { HILOGI("Not allToBackup, bundleName = %{public}s, appIndex = %{public}d", @@ -601,7 +604,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForLoca bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo { installedBundle.name, installedBundle.appIndex, installedBundle.versionCode, installedBundle.versionName, - 0, 0, allToBackup, fullBackupOnly, + 0, 0, allToBackup, fullBackupOnly, requireCompatibility, extName, restoreDeps, supportScene, extraInfo}); } auto bundleInfosIndex = GetBundleInfosForIndex(bundleNames, userId); @@ -625,7 +628,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForInde HILOGE("Get current extension failed, bundleName:%{public}s", bundleName.c_str()); continue; } - auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = + auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo, requireCompatibility] = GetAllowAndExtName(bundleExtInfo.extensionInfos_); if (!allToBackup) { HILOGI("Not allToBackup, bundleName = %{public}s, appIndex = %{public}d", @@ -635,7 +638,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForInde bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo { bundleExtInfo.bundleInfo_.name, bundleExtInfo.bundleInfo_.appIndex, bundleExtInfo.bundleInfo_.versionCode, bundleExtInfo.bundleInfo_.versionName, - 0, 0, allToBackup, fullBackupOnly, + 0, 0, allToBackup, fullBackupOnly, requireCompatibility, extName, restoreDeps, supportScene, extraInfo}); } HILOGI("End, bundleInfos size:%{public}zu", bundleInfos.size()); @@ -699,7 +702,8 @@ std::vector BundleMgrAdapter::GetBundleInfosForAppe bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {bundleExtInfo.bundleInfo_.name, bundleExtInfo.bundleInfo_.appIndex, bundleExtInfo.bundleInfo_.versionCode, bundleExtInfo.bundleInfo_.versionName, 0, 0, backupPara.allToBackup, backupPara.fullBackupOnly, - backupPara.extensionName, backupPara.restoreDeps, backupPara.supportScene, backupPara.extraInfo}); + backupPara.requireCompatibility, backupPara.extensionName, backupPara.restoreDeps, backupPara.supportScene, + backupPara.extraInfo}); } for (const auto &info : incrementalDataList) { if (SAUtils::IsSABundleName(info.bundleName)) { diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 897c9bf1544b2a0e87a49de4240ff99cdeaafe43..965e96d14eb5fb8a7a0dd737ac528d63a447918c 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -1532,4 +1532,53 @@ void Service::HandleOnReleaseAndDisconnect(sptr sessionPtr, c proxy->HandleOnRelease(static_cast(sessionPtr->GetScenario())); sessionConnection->DisconnectBackupExtAbility(); } + +ErrCode Service::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + HILOGI("Service::GetCompatibilityInfo begin bundleName: %{public}s", bundleName.c_str()); + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + ErrCode err = VerifyCaller(); + if (err != ERR_OK) { + HILOGE("VerifyCaller failed"); + return err; + } + if (SAUtils::IsSABundleName(bundleName)) { + HILOGE("SA not support"); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("session is empty or busy"); + return BError(BError::Codes::SA_INVAL_ARG); + } + sptr backupConnection; + 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("backupConnection connect timeout"); + 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); + } + //TODO 增加extension侧调用 + backupConnection->DisconnectBackupExtAbility(); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); +} } \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index fe62af42ec069eb39427fcb0da4e4b056feb5d42..e605bfbf5969f432b158313c11d2f2b22fc004e8 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -286,4 +286,10 @@ ErrCode ServiceProxy::GetExtOnRelease(bool &isExtOnRelease) { return BError(BError::Codes::OK); } + +ErrCode ServiceProxy::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_external/bms_adapter_mock.cpp b/tests/mock/module_external/bms_adapter_mock.cpp index 83f98eace9c6da9f8e7640efded5c3e332d45bcd..9694e08bc5ed34dfe9de0bdc76e1296a2fed9345 100644 --- a/tests/mock/module_external/bms_adapter_mock.cpp +++ b/tests/mock/module_external/bms_adapter_mock.cpp @@ -32,7 +32,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -47,7 +47,7 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -57,7 +57,7 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -67,7 +67,7 @@ vector BundleMgrAdapter::GetFullBundleInfos(int32_t { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -87,7 +87,7 @@ vector BundleMgrAdapter::GetBundleInfosForAppend( { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -96,7 +96,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForLoca { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -106,7 +106,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForInde { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } @@ -123,7 +123,7 @@ vector BundleMgrAdapter::GetBundleInfosForAppendBun { vector bundleInfos; bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, + BJsonEntityCaps::BundleInfo {"com.example.app2backup", 0, {}, {}, 0, 0, true, false, false, "com.example.app2backup"}); return bundleInfos; } diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index ed5c558fe6815869cba61c869ec40a487fc135a2..ff713dbb0e65b44b66450b6f4e69148b2343167f 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -450,4 +450,10 @@ ErrCode Service::GetExtOnRelease(bool &isExtOnRelease) { return BError(BError::Codes::OK); } + +ErrCode Service::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup 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 314bcd04772f3ccc5e452a73cc0072cf46f8a8cc..918949c97432deda9e0e93aaf39ada7d2b451bdf 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -81,6 +81,7 @@ public: virtual ErrCode GetExtOnRelease(bool&) = 0; virtual void SetExtOnRelease(const BundleName&, bool) = 0; virtual void RemoveExtOnRelease(const BundleName&) = 0; + virtual ErrCode GetCompatibilityInfo(const std::string&, const std::string&, std::string&) = 0; public: virtual bool UpdateToRestoreBundleMap(const string&, const string&) = 0; public: @@ -141,6 +142,7 @@ public: MOCK_METHOD(ErrCode, GetExtOnRelease, (bool&)); MOCK_METHOD(void, SetExtOnRelease, (const BundleName&, bool)); MOCK_METHOD(void, RemoveExtOnRelease, (const BundleName&)); + MOCK_METHOD(ErrCode, GetCompatibilityInfo, (const std::string&, const std::string&, std::string&)); public: MOCK_METHOD(bool, UpdateToRestoreBundleMap, (const string&, const string&)); }; @@ -478,6 +480,12 @@ void Service::RemoveExtOnRelease(const BundleName &bundleName) { return BService::serviceMock->RemoveExtOnRelease(bundleName); } + +ErrCode Service::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo, + std::string &compatInfo) +{ + return BService::serviceMock->GetCompatibilityInfo(bundleName, extInfo, compatInfo); +} } // namespace OHOS::FileManagement::Backup namespace OHOS::FileManagement::Backup { 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 8dd2ecd8169adf678ef1a52bfc437663a1a4e1e3..57a64d87fd04e16eb4631bdd7eb3d5f24b4f5a39 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -947,7 +947,7 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0100, TestSize.Level1 service->session_ = sptr(new SvcSessionManager(wptr(service))); service->SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); - info = BJsonEntityCaps::BundleInfo{BUNDLE_NAME, 0, {}, {}, 0, 0, true, false, BUNDLE_NAME}; + info = BJsonEntityCaps::BundleInfo {BUNDLE_NAME, 0, {}, {}, 0, 0, true, false, false, BUNDLE_NAME}; isClearDataFlags = {{BUNDLE_NAME, true}}; service->SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo); } catch (...) { diff --git a/utils/include/b_json/b_json_entity_caps.h b/utils/include/b_json/b_json_entity_caps.h index 1321ecde546927b096a41a12f602eda548ea606a..eabbf02ad0373e1a226f223d1137a797417d6966 100644 --- a/utils/include/b_json/b_json_entity_caps.h +++ b/utils/include/b_json/b_json_entity_caps.h @@ -31,6 +31,7 @@ public: int64_t increSpaceOccupied; bool allToBackup; bool fullBackupOnly; + bool requireCompatibility; std::string extensionName; std::string restoreDeps; std::string supportScene; @@ -39,6 +40,7 @@ public: struct BundleBackupConfigPara { bool allToBackup; bool fullBackupOnly; + bool requireCompatibility; std::string extensionName; std::string restoreDeps; std::string supportScene; @@ -84,6 +86,7 @@ public: } arrObj["allToBackup"] = item.allToBackup; arrObj["fullBackupOnly"] = item.fullBackupOnly; + arrObj["requireCompatibility"] = item.requireCompatibility; arrObj["extensionName"] = item.extensionName; arrObj["restoreDeps"] = item.restoreDeps; arrObj["supportScene"] = item.supportScene; @@ -233,6 +236,10 @@ public: if (item.isMember("fullBackupOnly") && item["fullBackupOnly"].isBool()) { fullBackupOnly = item["fullBackupOnly"].asBool(); } + bool requireCompatibility = false; + if (item.isMember("requireCompatibility") && item["requireCompatibility"].isBool()) { + requireCompatibility = item["requireCompatibility"].asBool(); + } int appIndex = 0; if (item.isMember("appIndex") && item["appIndex"].isInt()) { appIndex = item["appIndex"].asInt(); @@ -244,7 +251,7 @@ public: bundleInfos.emplace_back(BundleInfo {item["name"].asString(), appIndex, item["versionCode"].asInt64(), item["versionName"].asString(), item["spaceOccupied"].asInt64(), increSpaceOccupied, item["allToBackup"].asBool(), fullBackupOnly, - item["extensionName"].asString(), + requireCompatibility, item["extensionName"].asString(), restoreDeps, supportScene, extraInfo}); } return bundleInfos; diff --git a/utils/include/b_json/b_json_entity_extension_config.h b/utils/include/b_json/b_json_entity_extension_config.h index 80177038e607849cd379295c1bdc685ad2415a60..8523f2e93a4c27cad138956084fc6954b5d770a4 100644 --- a/utils/include/b_json/b_json_entity_extension_config.h +++ b/utils/include/b_json/b_json_entity_extension_config.h @@ -76,6 +76,13 @@ public: */ Json::Value GetExtraInfo() const; + /** + * @brief 从JSon对象中获取兼容能力标志 + * + * @return 兼容标志: 应用是否要做兼容处理 + */ + bool GetRequireCompatibility() const; + public: std::string GetJSonSource(std::string_view jsonFromRealWorld, std::any option); diff --git a/utils/src/b_json/b_json_entity_extension_config.cpp b/utils/src/b_json/b_json_entity_extension_config.cpp index a6e639d5104766d681d4fa708241c1151eb72d66..6f17cf0dae69f01a5eb6bf13898626a949caa462 100644 --- a/utils/src/b_json/b_json_entity_extension_config.cpp +++ b/utils/src/b_json/b_json_entity_extension_config.cpp @@ -179,4 +179,15 @@ string BJsonEntityExtensionConfig::GetRestoreDeps() const return obj_["restoreDeps"].asString(); } +bool BJsonEntityExtensionConfig::GetRequireCompatibility() const +{ + if (!obj_ || !obj_.isMember("requireCompatibility") || !obj_["requireCompatibility"].isBool()) { + HILOGD("Failed to get field requireCompatibility"); + return false; + } + + return obj_["requireCompatibility"].asBool(); +} + + } // namespace OHOS::FileManagement::Backup