From 8438fe2820371e0f2496565fd962322fcd4ed9b2 Mon Sep 17 00:00:00 2001 From: zhouaoteng Date: Tue, 26 Mar 2024 22:21:16 +0800 Subject: [PATCH] fix:add supportSence Signed-off-by: zhouaoteng --- .../src/module_external/bms_adapter.cpp | 26 ++++++++++------- services/backup_sa/src/module_ipc/service.cpp | 3 +- utils/include/b_json/b_json_entity_caps.h | 28 +++++++++++++++++-- .../b_json/b_json_entity_extension_config.h | 7 +++++ .../b_json/b_json_entity_extension_config.cpp | 10 +++++++ 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index bb12e6627..9325a7c04 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -63,7 +63,7 @@ static sptr GetBundleManager() return iface_cast(bundleObj); } -static tuple GetAllowAndExtName( +static tuple GetAllowAndExtName( const vector &extensionInfos) { for (auto &&ext : extensionInfos) { @@ -77,10 +77,11 @@ static tuple GetAllowAndExtName( } BJsonCachedEntity cachedEntity(out[0], ext.bundleName); auto cache = cachedEntity.Structuralize(); - return {cache.GetAllowToBackupRestore(), ext.name, cache.GetRestoreDeps(), cache.GetSupportScene()}; + return {cache.GetAllowToBackupRestore(), ext.name, cache.GetRestoreDeps(), cache.GetSupportScene(), + cache.GetExtraInfo()}; } HILOGI("No backup extension ability found"); - return {false, "", "", ""}; + return {false, "", "", "", Json::Value()}; } static int64_t GetBundleStats(const string &bundleName, int32_t userId) @@ -120,14 +121,15 @@ vector BundleMgrAdapter::GetBundleInfos(int32_t use HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } - auto [allToBackup, extName, restoreDeps, supportScene] = GetAllowAndExtName(installedBundle.extensionInfos); + auto [allToBackup, extName, restoreDeps, supportScene, extraInfo] = + GetAllowAndExtName(installedBundle.extensionInfos); int64_t dataSize = 0; if (allToBackup) { dataSize = GetBundleStats(installedBundle.name, userId); } bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, - extName, restoreDeps, supportScene}); + extName, restoreDeps, supportScene, extraInfo}); } return bundleInfos; } @@ -147,14 +149,15 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } - auto [allToBackup, extName, restoreDeps, supportScene] = GetAllowAndExtName(installedBundle.extensionInfos); + auto [allToBackup, extName, restoreDeps, supportScene, extraInfo] = + GetAllowAndExtName(installedBundle.extensionInfos); int64_t dataSize = 0; if (allToBackup) { dataSize = GetBundleStats(installedBundle.name, userId); } bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, - extName, restoreDeps, supportScene}); + extName, restoreDeps, supportScene, extraInfo}); } return bundleInfos; } @@ -191,6 +194,7 @@ static bool GetBackupExtConfig(const vector &e backupPara.extensionName = ext.name; backupPara.restoreDeps = cache.GetRestoreDeps(); backupPara.supportScene = cache.GetSupportScene(); + backupPara.extraInfo = cache.GetExtraInfo(); backupPara.includes = cache.GetIncludes(); backupPara.excludes = cache.GetExcludes(); return true; @@ -262,7 +266,8 @@ static bool GenerateBundleStatsIncrease(int32_t userId, const vector &bu .allToBackup = bundleInfos[i].allToBackup, .extensionName = bundleInfos[i].extensionName, .restoreDeps = bundleInfos[i].restoreDeps, - .supportScene = bundleInfos[i].supportScene}; + .supportScene = bundleInfos[i].supportScene, + .extraInfo = bundleInfos[i].extraInfo}; newBundleInfos.emplace_back(newBundleInfo); } return true; @@ -295,7 +300,7 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, 0, backupPara.allToBackup, backupPara.extensionName, backupPara.restoreDeps, - backupPara.supportScene}); + backupPara.supportScene, backupPara.extraInfo}); if (!CreateIPCInteractionFiles(userId, bundleName, bundleNameTime.lastIncrementalTime, backupPara.includes, backupPara.excludes)) { HILOGE("Failed to write include/exclude files, name : %{private}s", installedBundle.name.data()); @@ -329,7 +334,8 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } - auto [allToBackup, extName, restoreDeps, supportScene] = GetAllowAndExtName(installedBundle.extensionInfos); + auto [allToBackup, extName, restoreDeps, supportScene, extraInfo] = + GetAllowAndExtName(installedBundle.extensionInfos); if (allToBackup) { bundleNames.emplace_back(BIncrementalData {installedBundle.name, 0}); } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 7043f60e7..dcf1c3ab6 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -302,7 +302,8 @@ static vector GetRestoreBundleNames(UniqueFd fd, .spaceOccupied = (*it).spaceOccupied, .allToBackup = (*it).allToBackup, .extensionName = restoreInfo.extensionName, - .restoreDeps = restoreInfo.restoreDeps}; + .restoreDeps = restoreInfo.restoreDeps, + .extraInfo = restoreInfo.extraInfo}; restoreBundleInfos.emplace_back(info); } return restoreBundleInfos; diff --git a/utils/include/b_json/b_json_entity_caps.h b/utils/include/b_json/b_json_entity_caps.h index ef7ce2309..65cd9557b 100644 --- a/utils/include/b_json/b_json_entity_caps.h +++ b/utils/include/b_json/b_json_entity_caps.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,12 +31,14 @@ public: std::string extensionName; std::string restoreDeps; std::string supportScene; + Json::Value extraInfo; }; struct BundleBackupConfigPara { bool allToBackup; std::string extensionName; std::string restoreDeps; std::string supportScene; + Json::Value extraInfo; std::vector includes; std::vector excludes; }; @@ -66,6 +68,13 @@ public: arrObj["extensionName"] = item.extensionName; arrObj["restoreDeps"] = item.restoreDeps; arrObj["supportScene"] = item.supportScene; + Json::Value extraInfo; + if (item.extraInfo.empty()) { + extraInfo[""] = ""; + } else { + extraInfo = item.extraInfo; + } + arrObj["extraInfo"] = extraInfo; obj_["bundleInfos"].append(arrObj); } } @@ -110,6 +119,16 @@ public: return obj_["supportScene"].asString(); } + Json::Value GetExtraInfo() + { + if (!obj_ || !obj_.isMember("extraInfo") || !obj_["extraInfo"].isObject()) { + HILOGE("Failed to get field extraInfo"); + return Json::Value(); + } + + return obj_["extraInfo"]; + } + std::vector GetBundleInfos() { if (!obj_ || !obj_.isMember("bundleInfos") || !obj_["bundleInfos"].isArray()) { @@ -132,10 +151,15 @@ public: if (item.isMember("supportScene") && item["supportScene"].isString()) { restoreDeps = item["supportScene"].asString(); } + Json::Value extraInfo; + if (item.isMember("extraInfo") || item["extraInfo"].isObject()) { + HILOGI("Failed to get field extraInfo"); + extraInfo = item["extraInfo"]; + } bundleInfos.emplace_back(BundleInfo {item["name"].asString(), item["versionCode"].asUInt(), item["versionName"].asString(), item["spaceOccupied"].asInt64(), item["allToBackup"].asBool(), item["extensionName"].asString(), - restoreDeps, supportScene}); + 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 f1aedeba0..1143327c0 100644 --- a/utils/include/b_json/b_json_entity_extension_config.h +++ b/utils/include/b_json/b_json_entity_extension_config.h @@ -69,6 +69,13 @@ public: */ std::string GetSupportScene() const; + /** + * @brief Get the ExtraInfo object + * + * @return Json::Value + */ + Json::Value GetExtraInfo() 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 d3f907ee5..f7277c937 100644 --- a/utils/src/b_json/b_json_entity_extension_config.cpp +++ b/utils/src/b_json/b_json_entity_extension_config.cpp @@ -116,6 +116,16 @@ string BJsonEntityExtensionConfig::GetSupportScene() const return obj_["supportScene"].asString(); } +Json::Value BJsonEntityExtensionConfig::GetExtraInfo() const +{ + if (!obj_ || !obj_.isMember("extraInfo") || !obj_["extraInfo"].isObject()) { + HILOGI("Failed to init field extraInfo"); + return Json::Value(); + } + + return obj_["extraInfo"]; +} + string BJsonEntityExtensionConfig::GetJSonSource(string_view jsonFromRealWorld, any option) { if (!BackupPara().GetBackupDebugOverrideExtensionConfig()) { -- Gitee