diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 940961200433214bcee2f44005c3d6ff747c196c..fee000ebfe0e2e0415b0f6512658bb2cb48fa13c 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -35,6 +35,7 @@ #include "napi_remote_object.h" #include "unique_fd.h" +#include "b_anony/b_anony.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" #include "b_json/b_json_cached_entity.h" @@ -839,7 +840,7 @@ std::function &argv)> ExtBackupJs::Pa auto onBackupExFun = [backupExtInfo(backupExtInfo_)](napi_env env, vector &argv) -> bool { napi_value backupExtInfoVal = nullptr; napi_create_object(env, &backupExtInfoVal); - HILOGI("backupExtInfo is:%{public}s", backupExtInfo.c_str()); + HILOGI("backupExtInfo is:%{public}s", GetAnonyString(backupExtInfo).c_str()); napi_create_string_utf8(env, backupExtInfo.c_str(), backupExtInfo.size(), &backupExtInfoVal); argv.push_back(backupExtInfoVal); return true; @@ -851,7 +852,7 @@ std::function &argv)> ExtBackupJs::Pa { auto onRestoreExFun = [appVersionCode(appVersionCode_), appVersionStr(appVersionStr_), restoreExtInfo(restoreExtInfo_)](napi_env env, vector &argv) -> bool { - HILOGI("restoreExtInfo is:%{public}s", restoreExtInfo.c_str()); + HILOGI("restoreExtInfo is:%{public}s", GetAnonyString(restoreExtInfo).c_str()); napi_value objValue = nullptr; napi_value restoreRetValue = nullptr; napi_create_object(env, &objValue); diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index 751054b9a6c0a685d914be3da6b1d6f9a3beaa7c..fcdce2a6d028357c851337441e9d82cb11533332 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -413,48 +413,29 @@ bool OHOS::FileManagement::Backup::BJsonUtil::BuildOnProcessErrInfo(std::string return true; } -bool OHOS::FileManagement::Backup::BJsonUtil::BuildBundleInfoJson(int32_t userId, string &detailInfo) +bool BJsonUtil::BuildBundleInfoJson(int32_t userId, string &detailInfo) { - cJSON *root = cJSON_CreateObject(); - if (root == nullptr) { - return false; - } cJSON *infos = cJSON_CreateArray(); if (infos == nullptr) { - cJSON_Delete(root); return false; } - cJSON_AddItemToObject(root, "infos", infos); cJSON *info = cJSON_CreateObject(); if (info == nullptr) { - cJSON_Delete(root); - return false; - } - cJSON_AddStringToObject(info, "type", "unicast"); - cJSON_AddItemToArray(infos, info); - cJSON *details = cJSON_CreateArray(); - if (details == nullptr) { - cJSON_Delete(root); - return false; - } - cJSON_AddItemToObject(info, "details", details); - cJSON *detail = cJSON_CreateObject(); - if (detail == nullptr) { - cJSON_Delete(root); + cJSON_Delete(infos); return false; } string userIdstr = to_string(userId); const char *const zeroUserId = userIdstr.c_str(); - cJSON_AddStringToObject(detail, "type", "userId"); - cJSON_AddStringToObject(detail, "detail", zeroUserId); - cJSON_AddItemToArray(details, detail); - char *jsonStr = cJSON_Print(root); + cJSON_AddStringToObject(info, "type", "userId"); + cJSON_AddStringToObject(info, "detail", zeroUserId); + cJSON_AddItemToArray(infos, info); + char *jsonStr = cJSON_Print(infos); if (jsonStr == nullptr) { - cJSON_Delete(root); + cJSON_Delete(infos); return false; } detailInfo = string(jsonStr); - cJSON_Delete(root); + cJSON_Delete(infos); free(jsonStr); return true; }