diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index 73d64e73181e2126d2339328bf56d177a21d58a1..bf2e48c6b1613bc3a2543c71512778c0343903bb 100644 --- a/frameworks/native/backup_ext/include/ext_backup.h +++ b/frameworks/native/backup_ext/include/ext_backup.h @@ -108,6 +108,13 @@ public: */ virtual bool AllowToBackupRestore() const; + /** + * @brief Get whether FullBackupOnly or not + * + * @return FullBackupOnly ro not + */ + virtual bool UseFullBackupOnly(void) const; + /** * @brief Get the user configure * diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index cf584ce068b64f7790ee38daa39936c1cfc0bc24..127a5ca0833b47a7a4a36224c83ef0680d9b8e3f 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -113,6 +113,19 @@ bool ExtBackup::AllowToBackupRestore() const return false; } +bool ExtBackup::UseFullBackupOnly(void) const +{ + string usrConfig = GetUsrConfig(); + BJsonCachedEntity cachedEntity(usrConfig); + auto cache = cachedEntity.Structuralize(); + if (cache.GetFullBackupOnly()) { + HILOGI("backup use fullBackupOnly."); + return true; + } + HILOGI("backup not use fullBackupOnly."); + return false; +} + BConstants::ExtensionAction ExtBackup::GetExtensionAction() const { return extAction_; diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index ef8cd0e7a80be9c20a7fc2567253f9a7bbc132f9..d2e58a09a154cb596e2c02f11b4129ed8347b1f5 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -223,10 +223,11 @@ ErrCode ExtBackupJs::OnBackup(function callback) BExcepUltils::BAssert(jsObj_, BError::Codes::EXT_BROKEN_FRAMEWORK, "The app does not provide the onRestore interface."); callbackInfo_ = std::make_shared(callback); - auto retParser = [jsRuntime {&jsRuntime_}, callback, callbackInfo {callbackInfo_}](NativeEngine &engine, + auto retParser = [jsRuntime {&jsRuntime_}, callbackInfo {callbackInfo_}](NativeEngine &engine, NativeValue *result) -> bool { if (!CheckPromise(result)) { - return false; + callbackInfo->callback(); + return true; } HILOGI("CheckPromise(JS) OnBackup ok."); return CallPromise(*jsRuntime, result, callbackInfo.get()); @@ -257,10 +258,11 @@ ErrCode ExtBackupJs::OnRestore(function callback) return true; }; callbackInfo_ = std::make_shared(callback); - auto retParser = [jsRuntime {&jsRuntime_}, callback, callbackInfo {callbackInfo_}](NativeEngine &engine, + auto retParser = [jsRuntime {&jsRuntime_}, callbackInfo {callbackInfo_}](NativeEngine &engine, NativeValue *result) -> bool { if (!CheckPromise(result)) { - return false; + callbackInfo->callback(); + return true; } HILOGI("CheckPromise(JS) OnRestore ok."); return CallPromise(*jsRuntime, result, callbackInfo.get()); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 53cdf9bd15c3bc2bf2d063b56c12990ffcf7d08e..1a114693761d6adfd7d7dfd7d1e1ebe6b4673ef2 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -312,7 +312,7 @@ int BackupExtExtension::DoRestore(const string &fileName) string tarName = path + fileName; auto tarballFunc = BTarballFactory::Create("cmdline", tarName); - if (extension_->WasFromSpeicalVersion()) { + if (extension_->WasFromSpeicalVersion() || extension_->UseFullBackupOnly()) { (tarballFunc->untar)(path); } else { (tarballFunc->untar)("/"); 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 b79dd06a35f445112d7579a3d81ecac0deffe2e5..54f00232497c0786ce07ce0718847957bbe5ec51 100644 --- a/utils/include/b_json/b_json_entity_extension_config.h +++ b/utils/include/b_json/b_json_entity_extension_config.h @@ -48,6 +48,13 @@ public: */ bool GetAllowToBackupRestore() const; + /** + * @brief 从JSon对象中获取备份标志 + * + * @return 备份标志: 是否恢复到根目录进行覆盖 + */ + bool GetFullBackupOnly() const; + public: std::string GetJSonSource(std::string_view jsonFromRealWorld, std::any option); @@ -62,4 +69,4 @@ public: }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_JSON_ENTITY_EXTENSION_CONFIG_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_B_JSON_ENTITY_EXTENSION_CONFIG_H 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 39fed928227ffd6a0c3b7eca0da472819fcb11c9..0b63368d975b54b3fa38f57dcddebc2af985e88a 100644 --- a/utils/src/b_json/b_json_entity_extension_config.cpp +++ b/utils/src/b_json/b_json_entity_extension_config.cpp @@ -96,6 +96,16 @@ bool BJsonEntityExtensionConfig::GetAllowToBackupRestore() const return obj_["allowToBackupRestore"].asBool(); } +bool BJsonEntityExtensionConfig::GetFullBackupOnly() const +{ + if (!obj_ || !obj_.isMember("fullBackupOnly") || !obj_["fullBackupOnly"].isBool()) { + HILOGE("Failed to init field fullBackupOnly"); + return false; + } + + return obj_["fullBackupOnly"].asBool(); +} + string BJsonEntityExtensionConfig::GetJSonSource(string_view jsonFromRealWorld, any option) { if (!BackupPara().GetBackupDebugOverrideExtensionConfig()) { @@ -126,4 +136,4 @@ string BJsonEntityExtensionConfig::GetJSonSource(string_view jsonFromRealWorld, append(BConstants::BACKUP_CONFIG_JSON); return BFile::ReadFile(UniqueFd(open(jsonFilePath.c_str(), O_RDONLY))).get(); } -} // namespace OHOS::FileManagement::Backup \ No newline at end of file +} // namespace OHOS::FileManagement::Backup