diff --git a/frameworks/js/napi/ability_constant/BUILD.gn b/frameworks/js/napi/ability_constant/BUILD.gn index 9e63bee0e48785e65866f851e1f6da26a88bf0aa..2123acb96d97466d363ac7b9d91fc1b306cdd7a8 100644 --- a/frameworks/js/napi/ability_constant/BUILD.gn +++ b/frameworks/js/napi/ability_constant/BUILD.gn @@ -29,7 +29,6 @@ ohos_shared_library("abilityconstant_napi") { "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] public_external_deps = [ "ability_base:want" ] @@ -53,7 +52,6 @@ ohos_shared_library("abilityconstant") { "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] public_external_deps = [ "ability_base:want" ] diff --git a/frameworks/js/napi/auto_fill_manager/BUILD.gn b/frameworks/js/napi/auto_fill_manager/BUILD.gn index ed838eb05339758ecaeb2b607f7e27c312bf7190..e4be3b0f20b546eeb4f819b3599183209b8919e8 100644 --- a/frameworks/js/napi/auto_fill_manager/BUILD.gn +++ b/frameworks/js/napi/auto_fill_manager/BUILD.gn @@ -43,7 +43,6 @@ ohos_shared_library("autofillmanager_napi") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index f1975653555ee860867cdae640ab7f8b76481fcb..b4a700c9a4a1af356b9b7f9aad20ba991fa0a9cf 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -60,7 +60,6 @@ ohos_shared_library("napi_common") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "libuv:uv", "napi:ace_napi", "samgr:samgr_proxy", diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp index ec80d58af69b7d9214bddab74f73ea605bdc65d3..8bf2356a55f0bc80bc9a504c4587d21720791bf5 100644 --- a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp @@ -85,40 +85,49 @@ napi_value CreateFormInfoForQuery(napi_env env, const FormInfoForQuery &info) return objValue; } -napi_value CreateInsightIntentInfoWithJson(napi_env env, const nlohmann::json &jsonObject) +napi_value CreateInsightIntentInfoWithJson(napi_env env, const cJSON *jsonObject) { - if (jsonObject.is_object()) { + if (cJSON_IsObject(jsonObject)) { napi_value objValue = nullptr; napi_create_object(env, &objValue); - for (const auto &it: jsonObject.items()) { - if (it.value().is_object() || it.value().is_array()) { + cJSON *childItem = jsonObject->child; + while (childItem != nullptr) { + std::string key = childItem->string == nullptr ? "" : childItem->string; + if (cJSON_IsObject(childItem) || cJSON_IsArray(childItem)) { napi_set_named_property( - env, objValue, it.key().c_str(), CreateInsightIntentInfoWithJson(env, it.value())); - } else if (it.value().is_string()) { - napi_set_named_property( - env, objValue, it.key().c_str(), CreateJsValue(env, it.value().get())); - } else if (it.value().is_boolean()) { - napi_set_named_property( - env, objValue, it.key().c_str(), CreateJsValue(env, it.value().get())); - } else if (it.value().is_number()) { - napi_set_named_property( - env, objValue, it.key().c_str(), CreateJsValue(env, it.value().get())); + env, objValue, key.c_str(), CreateInsightIntentInfoWithJson(env, childItem)); + } else if (cJSON_IsString(childItem)) { + std::string value = childItem->valuestring; + napi_set_named_property(env, objValue, key.c_str(), CreateJsValue(env, value)); + } else if (cJSON_IsBool(childItem)) { + bool value = childItem->type == cJSON_True ? true : false; + napi_set_named_property(env, objValue, key.c_str(), CreateJsValue(env, value)); + } else if (cJSON_IsNumber(childItem)) { + napi_set_named_property(env, objValue, key.c_str(), CreateJsValue(env, childItem->valuedouble)); } + childItem = childItem->next; } return objValue; - } else if (jsonObject.is_array()) { + } else if (cJSON_IsArray(jsonObject)) { napi_value arrayValue = nullptr; - napi_create_array_with_length(env, jsonObject.size(), &arrayValue); + int size = cJSON_GetArraySize(jsonObject); + napi_create_array_with_length(env, size, &arrayValue); uint32_t index = 0; - for (const auto &it: jsonObject) { - if (it.is_object() || it.is_array()) { - napi_set_element(env, arrayValue, index++, CreateInsightIntentInfoWithJson(env, it)); - } else if (it.is_string()) { - napi_set_element(env, arrayValue, index++, CreateJsValue(env, it.get())); - } else if (it.is_boolean()) { - napi_set_element(env, arrayValue, index++, CreateJsValue(env, it.get())); - } else if (it.is_number()) { - napi_set_element(env, arrayValue, index++, CreateJsValue(env, it.get())); + for (int i = 0; i < size; i++) { + cJSON *item = cJSON_GetArrayItem(jsonObject, i); + if (item == nullptr) { + continue; + } + if (cJSON_IsObject(item) || cJSON_IsArray(item)) { + napi_set_element(env, arrayValue, index++, CreateInsightIntentInfoWithJson(env, item)); + } else if (cJSON_IsString(item)) { + std::string value = item->valuestring; + napi_set_element(env, arrayValue, index++, CreateJsValue(env, value)); + } else if (cJSON_IsBool(item)) { + bool value = item->type == cJSON_True ? true : false; + napi_set_element(env, arrayValue, index++, CreateJsValue(env, value)); + } else if (cJSON_IsNumber(item)) { + napi_set_element(env, arrayValue, index++, CreateJsValue(env, item->valuedouble)); } } return arrayValue; @@ -133,12 +142,14 @@ napi_value CreateInsightIntentInfoParam(napi_env env, const std::string ¶mSt TAG_LOGD(AAFwkTag::INTENT, "paramStr empty"); return nullptr; } - nlohmann::json jsonObject = nlohmann::json::parse(paramStr, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(paramStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::INTENT, "Parse param str fail"); return nullptr; } - return CreateInsightIntentInfoWithJson(env, jsonObject); + napi_value result = CreateInsightIntentInfoWithJson(env, jsonObject); + cJSON_Delete(jsonObject); + return result; } napi_value CreateInsightIntentInfoResult(napi_env env, const std::string &resultStr) @@ -147,12 +158,14 @@ napi_value CreateInsightIntentInfoResult(napi_env env, const std::string &result TAG_LOGD(AAFwkTag::INTENT, "resultStr empty"); return nullptr; } - nlohmann::json jsonObject = nlohmann::json::parse(resultStr, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(resultStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::INTENT, "Parse result str fail"); return nullptr; } - return CreateInsightIntentInfoWithJson(env, jsonObject); + napi_value result = CreateInsightIntentInfoWithJson(env, jsonObject); + cJSON_Delete(jsonObject); + return result; } napi_value CreateInsightIntentInfoForQuery(napi_env env, const InsightIntentInfoForQuery &info) diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h index 6eff220acad6c179b602b12df2c8486f1445b54d..4f3f807b10067b646afa1e3da424acdb39c290ff 100644 --- a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h @@ -29,7 +29,7 @@ napi_value CreatePageInfoForQuery(napi_env env, const PageInfoForQuery &info); napi_value CreateEntryInfoForQuery(napi_env env, const EntryInfoForQuery &info); napi_value CreateFunctionInfoForQuery(napi_env env, const FunctionInfoForQuery &info); napi_value CreateFormInfoForQuery(napi_env env, const FormInfoForQuery &info); -napi_value CreateInsightIntentInfoWithJson(napi_env env, const nlohmann::json &jsonObject); +napi_value CreateInsightIntentInfoWithJson(napi_env env, const cJSON *jsonObject); napi_value CreateInsightIntentInfoParam(napi_env env, const std::string ¶mStr); napi_value CreateInsightIntentInfoResult(napi_env env, const std::string &resultStr); napi_value CreateInsightIntentInfoForQuery(napi_env env, const InsightIntentInfoForQuery &info); diff --git a/frameworks/js/napi/js_dialog_session/js_dialog_session_utils.cpp b/frameworks/js/napi/js_dialog_session/js_dialog_session_utils.cpp index 9b1d01a5673f754eef5b4f758817952435b7c43e..8ca1c262e0132a155e9f5f7997aa2300bb3d9a0b 100644 --- a/frameworks/js/napi/js_dialog_session/js_dialog_session_utils.cpp +++ b/frameworks/js/napi/js_dialog_session/js_dialog_session_utils.cpp @@ -15,7 +15,6 @@ #include "js_dialog_session_utils.h" -#include "json/json.h" #include "napi_common_ability.h" #include "napi_common_want.h" #include "napi_common_util.h" diff --git a/frameworks/js/napi/particleAbility/BUILD.gn b/frameworks/js/napi/particleAbility/BUILD.gn index ff36e4f04aa34bf2b912b2c6e209fa65d99792f1..ae27de9e1f91a56895bd1cf454e96c557ac20e8c 100644 --- a/frameworks/js/napi/particleAbility/BUILD.gn +++ b/frameworks/js/napi/particleAbility/BUILD.gn @@ -55,7 +55,6 @@ ohos_shared_library("particleability") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "jsoncpp:jsoncpp", "libuv:uv", "napi:ace_napi", "node:node_header_notice", diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index e4f5a06ba62307af4ddfb2c27d0920d222498807..d8be2184b7b4f8a50d1fb7c9a5eb1a4499af0ab0 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -75,6 +75,7 @@ ohos_shared_library("ability_context_native") { "${ability_runtime_native_path}/ability/native:dialog_request_callback", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", + "${ability_runtime_services_path}/common:app_util", ] external_deps = [ diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index 07ee28e0361c6547bcea207f90cfa0b3cc1f8163..e23ce71f2a8da326430b72a168510416a7a72383 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -268,10 +268,15 @@ ErrCode AbilityContextImpl::StartAbilityForResult(const AAFwk::Want& want, const TAG_LOGE(AAFwkTag::CONTEXT, "ret=%{public}d", err); OnAbilityResultInner(requestCode, err, want); if (!startOptions.requestId_.empty()) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, "Failed to call startAbilityForResult" }, - }; - OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create jsonObject failed"); + return ERR_INVALID_VALUE; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), "Failed to call startAbilityForResult"); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonStr); } } return err; @@ -289,10 +294,16 @@ ErrCode AbilityContextImpl::StartAbilityForResultWithAccount( TAG_LOGE(AAFwkTag::CONTEXT, "ret=%{public}d", err); OnAbilityResultInner(requestCode, err, want); if (!startOptions.requestId_.empty()) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, "Failed to call startAbilityForResultWithAccount" }, - }; - OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create jsonObject failed"); + return ERR_INVALID_VALUE; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), + "Failed to call startAbilityForResultWithAccount"); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonStr); } } return err; diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 3f3cf0514d059135f6ffe853fb8cdd623bd9acf7..60c4d072107fd596ae9e1393a57c82f3f52e392f 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -187,7 +187,6 @@ ohos_shared_library("abilitykit_utils") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] @@ -259,8 +258,6 @@ ohos_shared_library("configuration_helper") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "resource_management:global_resmgr", ] @@ -383,7 +380,6 @@ ohos_shared_library("abilitykit_native") { "ipc:ipc_core", "ipc:ipc_napi", "ipc:rpc", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", @@ -402,7 +398,6 @@ ohos_shared_library("abilitykit_native") { "ability_base:session_info", "accessibility:accessibility_common", "bundle_framework:appexecfwk_core", - "jsoncpp:jsoncpp", "libuv:uv", "napi:ace_napi", ] @@ -597,7 +592,6 @@ ohos_shared_library("extensionkit_native") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", ] @@ -606,7 +600,6 @@ ohos_shared_library("extensionkit_native") { public_external_deps = [ "ability_base:session_info", "bundle_framework:appexecfwk_core", - "jsoncpp:jsoncpp", ] if (ability_runtime_graphics) { @@ -768,6 +761,7 @@ ohos_shared_library("uiabilitykit_native") { "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", "${ability_runtime_path}/utils/global/time/include", + "${ability_runtime_services_path}/common/include", ] sources = [ @@ -803,6 +797,7 @@ ohos_shared_library("uiabilitykit_native") { "${ability_runtime_native_path}/appkit:appkit_delegator", "${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext", "${ability_runtime_path}/utils/global/freeze:freeze_util", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", ] @@ -820,7 +815,6 @@ ohos_shared_library("uiabilitykit_native") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "resource_management:global_resmgr", "samgr:samgr_proxy", ] @@ -1018,7 +1012,6 @@ ohos_shared_library("form_extension_module") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "window_manager:libwm", ] @@ -1357,7 +1350,6 @@ ohos_shared_library("continuation_ipc") { "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "resource_management:global_resmgr", ] public_external_deps = [] @@ -1404,7 +1396,6 @@ ohos_shared_library("data_ability_helper") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_single", - "json:nlohmann_json_static", "relational_store:native_dataability", "relational_store:rdb_data_ability_adapter", "window_manager:libwm", @@ -1452,7 +1443,6 @@ ohos_shared_library("service_extension_module") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index dd7389583f50c260119ec8c2aa152a5c2264c54f..2c6ab1acec5e58ecca7327fd5f494ebd2a0a52ad 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -576,10 +576,17 @@ napi_value JsAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info return; } if (!startOptions.requestId_.empty()) { + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } std::string errMsg = want.GetBoolParam(Want::PARAM_RESV_START_RECENT, false) ? "Failed to call startRecentAbility" : "Failed to call startAbility"; - nlohmann::json jsonObject = nlohmann::json { { JSON_KEY_ERR_MSG, errMsg } }; - context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonObject.dump()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), errMsg.c_str()); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonStr); } }; @@ -987,10 +994,15 @@ napi_value JsAbilityContext::OnStartAbilityAsCallerInner(napi_env env, NapiCallb return; } if (!startOptions.requestId_.empty()) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, "Failed to call startAbilityAsCaller" } - }; - context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGW(AAFwkTag::CONTEXT, "create json object failed"); + return; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), "Failed to call startAbilityAsCaller"); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonStr); } }; @@ -1105,10 +1117,15 @@ napi_value JsAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbac return; } if (!startOptions.requestId_.empty()) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, "Failed to call startAbilityWithAccount" } - }; - context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGW(AAFwkTag::CONTEXT, "create json object failed"); + return; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), "Failed to call startAbilityWithAccount"); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + context->OnRequestFailure(startOptions.requestId_, want.GetElement(), jsonStr); } }; napi_value lastParam = (info.argc > unwrapArgc) ? info.argv[unwrapArgc] : nullptr; diff --git a/frameworks/native/ability/native/extension_config_mgr.cpp b/frameworks/native/ability/native/extension_config_mgr.cpp index 7551514e1d6e44cfc2f9528cea9dae354dc6cdb0..69e2cb4ffbfdecd78b0fa950f22390083b4be5b1 100644 --- a/frameworks/native/ability/native/extension_config_mgr.cpp +++ b/frameworks/native/ability/native/extension_config_mgr.cpp @@ -16,9 +16,9 @@ #include "extension_config_mgr.h" #include -#include #include "app_module_checker.h" +#include "cJSON.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" @@ -31,7 +31,6 @@ void ExtensionConfigMgr::Init() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::EXT, "Init begin"); - // clear cached data blocklistConfig_.clear(); extensionBlocklist_.clear(); @@ -42,31 +41,45 @@ void ExtensionConfigMgr::Init() TAG_LOGE(AAFwkTag::EXT, "read extension config error"); return; } - nlohmann::json extensionConfig; - inFile >> extensionConfig; - if (extensionConfig.is_discarded()) { - TAG_LOGE(AAFwkTag::EXT, "extension config json discarded error"); - inFile.close(); + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + + cJSON *extensionConfig = cJSON_Parse(fileContent.c_str()); + if (extensionConfig == nullptr) { + TAG_LOGE(AAFwkTag::EXT, "extension config json parse error"); return; } - if (!extensionConfig.contains(ExtensionConfigItem::ITEM_NAME_BLOCKLIST)) { + cJSON *blockListItem = cJSON_GetObjectItem(extensionConfig, ExtensionConfigItem::ITEM_NAME_BLOCKLIST); + if (blockListItem == nullptr) { TAG_LOGE(AAFwkTag::EXT, "extension config file have no blocklist node"); - inFile.close(); + cJSON_Delete(extensionConfig); + return; + } + if (!cJSON_IsArray(blockListItem)) { + TAG_LOGE(AAFwkTag::EXT, "blocklist node is not array"); + cJSON_Delete(extensionConfig); return; } - auto blackList = extensionConfig.at(ExtensionConfigItem::ITEM_NAME_BLOCKLIST); std::unordered_set currentBlockList; - for (const auto& item : blackList.items()) { - if (!blackList[item.key()].is_array()) { + int blockListSize = cJSON_GetArraySize(blockListItem); + for (int i = 0; i < blockListSize; i++) { + cJSON *blockItem = cJSON_GetArrayItem(blockListItem, i); + if (blockItem == nullptr || !cJSON_IsArray(blockItem)) { continue; } - for (const auto& value : blackList[item.key()]) { - currentBlockList.emplace(value.get()); + int blockSize = cJSON_GetArraySize(blockItem); + for (int j = 0; j < blockSize; j++) { + cJSON *item = cJSON_GetArrayItem(blockItem, j); + if (item != nullptr && cJSON_IsString(item)) { + std::string value = item->valuestring; + currentBlockList.emplace(value); + } } - blocklistConfig_.emplace(item.key(), std::move(currentBlockList)); + std::string key = blockItem->string; + blocklistConfig_.emplace(key, std::move(currentBlockList)); currentBlockList.clear(); } - inFile.close(); + cJSON_Delete(extensionConfig); TAG_LOGD(AAFwkTag::EXT, "Init end"); } diff --git a/frameworks/native/ability/native/ui_ability_impl.cpp b/frameworks/native/ability/native/ui_ability_impl.cpp index 011effb71c2ec5a6b021728269dcc50869e98a66..ccd28cf090786a9335e92f6933e1edd2c54b3ba3 100644 --- a/frameworks/native/ability/native/ui_ability_impl.cpp +++ b/frameworks/native/ability/native/ui_ability_impl.cpp @@ -956,10 +956,15 @@ void UIAbilityImpl::ScheduleAbilityRequestSuccess(const std::string &requestId, TAG_LOGE(AAFwkTag::UIABILITY, "null ability_"); return; } - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, "Succeeded" }, - }; - ability_->OnAbilityRequestSuccess(requestId, element, jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), "Succeeded"); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + ability_->OnAbilityRequestSuccess(requestId, element, jsonStr); } } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index a04288c9beca320e600d512e98ab7e09ac7b4596..ea88e63b5397270ecf43d13bfc379246c2681b07 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -203,7 +203,6 @@ ohos_shared_library("appkit_native") { "ipc:ipc_core", "ipc:ipc_napi", "ipc:ipc_single", - "json:nlohmann_json_static", "libxml2:libxml2", "napi:ace_napi", "preferences:native_preferences", @@ -357,7 +356,6 @@ ohos_shared_library("app_context") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", @@ -429,7 +427,6 @@ ohos_shared_library("app_context_utils") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "resource_management:resmgr_napi_core", @@ -502,7 +499,6 @@ ohos_shared_library("appkit_delegator") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "samgr:samgr_proxy", ] @@ -575,7 +571,6 @@ ohos_shared_library("appkit_manager_helper") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "json:nlohmann_json_static", "samgr:samgr_proxy", ] diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 6f4c1ae42aee99b63a746e716731c4e7c7a8ece8..2ff943f93857e3e1169f0490a79c140816bba714 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -42,6 +42,7 @@ #include "child_main_thread.h" #include "child_process_manager.h" #endif // SUPPORT_CHILD_PROCESS +#include "cJSON.h" #include "configuration_convertor.h" #include "common_event_manager.h" #include "global_constant.h" @@ -79,7 +80,6 @@ #include "cj_runtime.h" #endif #include "native_lib_util.h" -#include "nlohmann/json.hpp" #include "ohos_application.h" #include "overlay_module_info.h" #include "parameters.h" @@ -3846,34 +3846,31 @@ void MainThread::ParseAppConfigurationParams(const std::string configuration, Co return; } TAG_LOGI(AAFwkTag::APPKIT, "ParseAppConfigurationParams config:%{public}s", appConfig.GetName().c_str()); - nlohmann::json configurationJson = nlohmann::json::parse(configuration, nullptr, false); - if (configurationJson.is_discarded()) { + cJSON *configurationJson = cJSON_Parse(configuration.c_str()); + if (configurationJson == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "discarded error"); return; } - if (!configurationJson.contains(JSON_KEY_APP_CONFIGURATION)) { + cJSON *jsonObject = cJSON_GetObjectItem(configurationJson, JSON_KEY_APP_CONFIGURATION.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "app config not exist"); + cJSON_Delete(configurationJson); return; } - nlohmann::json jsonObject = configurationJson.at(JSON_KEY_APP_CONFIGURATION).get(); - if (jsonObject.empty()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null app config"); - return; - } - if (jsonObject.contains(JSON_KEY_APP_FONT_SIZE_SCALE) - && jsonObject[JSON_KEY_APP_FONT_SIZE_SCALE].is_string()) { - std::string configFontSizeScal = jsonObject.at(JSON_KEY_APP_FONT_SIZE_SCALE).get(); - appConfig.AddItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE, - jsonObject.at(JSON_KEY_APP_FONT_SIZE_SCALE).get()); + cJSON *fontSizeScaleItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_APP_FONT_SIZE_SCALE.c_str()); + if (fontSizeScaleItem != nullptr && cJSON_IsString(fontSizeScaleItem)) { + std::string configFontSizeScal = fontSizeScaleItem->valuestring; + appConfig.AddItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE, configFontSizeScal); } - if (jsonObject.contains(JSON_KEY_APP_FONT_MAX_SCALE) - && jsonObject[JSON_KEY_APP_FONT_MAX_SCALE].is_string()) { - std::string appFontMaxScale = jsonObject.at(JSON_KEY_APP_FONT_MAX_SCALE).get(); + cJSON *fontMaxScaleItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_APP_FONT_MAX_SCALE.c_str()); + if (fontMaxScaleItem != nullptr && cJSON_IsString(fontMaxScaleItem)) { + std::string appFontMaxScale = fontMaxScaleItem->valuestring; const std::regex INTEGER_REGEX("^[-+]?([0-9]+)([.]([0-9]+))?$"); if (std::regex_match(appFontMaxScale, INTEGER_REGEX)) { appConfig.AddItem(AAFwk::GlobalConfigurationKey::APP_FONT_MAX_SCALE, appFontMaxScale); } } + cJSON_Delete(configurationJson); TAG_LOGD(AAFwkTag::APPKIT, "configuration_: %{public}s", appConfig.GetName().c_str()); } diff --git a/frameworks/native/appkit/app_startup/startup_manager.cpp b/frameworks/native/appkit/app_startup/startup_manager.cpp index 6b550263b83d6c0c649d0eb5718df0838fe09023..1287bf6c6bd2d6b8fb5c01e2b07dc76a69f3be0d 100644 --- a/frameworks/native/appkit/app_startup/startup_manager.cpp +++ b/frameworks/native/appkit/app_startup/startup_manager.cpp @@ -16,11 +16,11 @@ #include "startup_manager.h" #include -#include #include "app_startup_task_matcher.h" #include "event_report.h" #include "hilog_tag_wrapper.h" +#include "json_utils.h" #include "extractor.h" #include "hitrace_meter.h" #include "native_startup_task.h" @@ -906,8 +906,8 @@ int32_t StartupManager::GetStartupConfigString(const ModuleStartupConfigInfo &in return ERR_STARTUP_CONFIG_PATH_ERROR; } std::string configData(startupConfig.get(), startupConfig.get() + len); - nlohmann::json profileJson = nlohmann::json::parse(configData, nullptr, false); - if (profileJson.is_discarded()) { + cJSON *profileJson = cJSON_Parse(configData.c_str()); + if (profileJson == nullptr) { TAG_LOGE(AAFwkTag::STARTUP, "bad profile file"); eventInfo.errCode = ERR_STARTUP_CONFIG_PARSE_ERROR; eventInfo.errReason = "bad profile file"; @@ -915,7 +915,8 @@ int32_t StartupManager::GetStartupConfigString(const ModuleStartupConfigInfo &in AAFwk::EventName::STARTUP_TASK_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_STARTUP_CONFIG_PARSE_ERROR; } - config = profileJson.dump(); + config = AAFwk::JsonUtils::GetInstance().ToString(profileJson); + cJSON_Delete(profileJson); return ERR_OK; } @@ -928,40 +929,55 @@ bool StartupManager::AnalyzeStartupConfig(const ModuleStartupConfigInfo& info, c return false; } - nlohmann::json startupConfigJson = nlohmann::json::parse(startupConfig, nullptr, false); - if (startupConfigJson.is_discarded()) { + cJSON *startupConfigJson = cJSON_Parse(startupConfig.c_str()); + if (startupConfigJson == nullptr) { TAG_LOGE(AAFwkTag::STARTUP, "Failed to parse json string"); return false; } if (info.moduleType_ == AppExecFwk::ModuleType::ENTRY || info.moduleType_ == AppExecFwk::ModuleType::FEATURE) { - if (!(startupConfigJson.contains(CONFIG_ENTRY) && startupConfigJson[CONFIG_ENTRY].is_string())) { + cJSON *configEntryItem = cJSON_GetObjectItem(startupConfigJson, CONFIG_ENTRY); + if (configEntryItem == nullptr || !cJSON_IsString(configEntryItem)) { TAG_LOGE(AAFwkTag::STARTUP, "no config entry."); + cJSON_Delete(startupConfigJson); return false; } - pendingConfigEntry = startupConfigJson.at(CONFIG_ENTRY).get(); + pendingConfigEntry = configEntryItem->valuestring; if (pendingConfigEntry.empty()) { TAG_LOGE(AAFwkTag::STARTUP, "startup config empty."); + cJSON_Delete(startupConfigJson); return false; } } if (!AnalyzeAppStartupTask(info, startupConfigJson, pendingStartupTaskInfos)) { + cJSON_Delete(startupConfigJson); return false; } if (!AnalyzePreloadSoStartupTask(info, startupConfigJson, preloadSoStartupTasks)) { + cJSON_Delete(startupConfigJson); return false; } + cJSON_Delete(startupConfigJson); return true; } -bool StartupManager::AnalyzeAppStartupTask(const ModuleStartupConfigInfo& info, nlohmann::json &startupConfigJson, +bool StartupManager::AnalyzeAppStartupTask(const ModuleStartupConfigInfo& info, cJSON *startupConfigJson, std::vector& pendingStartupTaskInfos) { - if (startupConfigJson.contains(STARTUP_TASKS) && startupConfigJson[STARTUP_TASKS].is_array()) { - for (const auto& module : startupConfigJson.at(STARTUP_TASKS).get()) { - if (!module.contains(SRC_ENTRY) || !module[SRC_ENTRY].is_string() || - !module.contains(NAME) || !module[NAME].is_string()) { + cJSON *startupTasksItem = cJSON_GetObjectItem(startupConfigJson, STARTUP_TASKS); + if (startupTasksItem != nullptr && cJSON_IsArray(startupTasksItem)) { + int size = cJSON_GetArraySize(startupTasksItem); + for (int i = 0; i < size; i++) { + cJSON *module = cJSON_GetArrayItem(startupTasksItem, i); + if (module == nullptr || !cJSON_IsObject(module)) { + TAG_LOGE(AAFwkTag::STARTUP, "Invalid module data"); + return false; + } + cJSON *srcEntryItem = cJSON_GetObjectItem(module, SRC_ENTRY); + cJSON *nameItem = cJSON_GetObjectItem(module, NAME); + if ((srcEntryItem == nullptr || !cJSON_IsString(srcEntryItem)) || + (nameItem == nullptr || !cJSON_IsString(nameItem))) { TAG_LOGE(AAFwkTag::STARTUP, "Invalid module data"); return false; } @@ -970,18 +986,26 @@ bool StartupManager::AnalyzeAppStartupTask(const ModuleStartupConfigInfo& info, return false; } } - return true; } return true; } -bool StartupManager::AnalyzePreloadSoStartupTask(const ModuleStartupConfigInfo& info, nlohmann::json &startupConfigJson, +bool StartupManager::AnalyzePreloadSoStartupTask(const ModuleStartupConfigInfo& info, cJSON *startupConfigJson, std::map>& preloadSoStartupTasks) { - if (startupConfigJson.contains(PRELOAD_STARTUP_TASKS) && startupConfigJson[PRELOAD_STARTUP_TASKS].is_array()) { - for (const auto& module : startupConfigJson.at(PRELOAD_STARTUP_TASKS).get()) { - if (!module.contains(SRC_ENTRY) || !module[SRC_ENTRY].is_string() || - !module.contains(NAME) || !module[NAME].is_string()) { + cJSON *startupTasksItem = cJSON_GetObjectItem(startupConfigJson, PRELOAD_STARTUP_TASKS); + if (startupTasksItem != nullptr && cJSON_IsArray(startupTasksItem)) { + int size = cJSON_GetArraySize(startupTasksItem); + for (int i = 0; i < size; i++) { + cJSON *module = cJSON_GetArrayItem(startupTasksItem, i); + if (module == nullptr || !cJSON_IsObject(module)) { + TAG_LOGE(AAFwkTag::STARTUP, "Invalid module data"); + return false; + } + cJSON *srcEntryItem = cJSON_GetObjectItem(module, SRC_ENTRY); + cJSON *nameItem = cJSON_GetObjectItem(module, NAME); + if ((srcEntryItem == nullptr || !cJSON_IsString(srcEntryItem)) || + (nameItem == nullptr || !cJSON_IsString(nameItem))) { TAG_LOGE(AAFwkTag::STARTUP, "Invalid module data"); return false; } @@ -990,17 +1014,18 @@ bool StartupManager::AnalyzePreloadSoStartupTask(const ModuleStartupConfigInfo& return false; } } - return true; } return true; } bool StartupManager::AnalyzeAppStartupTaskInner(const ModuleStartupConfigInfo& info, - const nlohmann::json& startupTaskJson, + const cJSON *startupTaskJson, std::vector& pendingStartupTaskInfos) { - if (!startupTaskJson.contains(SRC_ENTRY) || !startupTaskJson[SRC_ENTRY].is_string() || - !startupTaskJson.contains(NAME) || !startupTaskJson[NAME].is_string()) { + cJSON *srcEntryItem = cJSON_GetObjectItem(startupTaskJson, SRC_ENTRY); + cJSON *nameItem = cJSON_GetObjectItem(startupTaskJson, NAME); + if ((srcEntryItem == nullptr || !cJSON_IsString(srcEntryItem)) || + (nameItem == nullptr || !cJSON_IsString(nameItem))) { TAG_LOGE(AAFwkTag::STARTUP, "Invalid startupTaskJson data"); return false; } @@ -1009,8 +1034,8 @@ bool StartupManager::AnalyzeAppStartupTaskInner(const ModuleStartupConfigInfo& i startupTaskInfo.hapPath = info.hapPath_; startupTaskInfo.esModule = info.esModule_; - startupTaskInfo.name = startupTaskJson.at(NAME).get(); - startupTaskInfo.srcEntry = startupTaskJson.at(SRC_ENTRY).get(); + startupTaskInfo.name = nameItem->valuestring; + startupTaskInfo.srcEntry = srcEntryItem->valuestring; if (startupTaskInfo.name.empty()) { TAG_LOGE(AAFwkTag::STARTUP, "startup task name is empty"); return false; @@ -1025,17 +1050,19 @@ bool StartupManager::AnalyzeAppStartupTaskInner(const ModuleStartupConfigInfo& i } bool StartupManager::AnalyzePreloadSoStartupTaskInner(const ModuleStartupConfigInfo& info, - const nlohmann::json &preloadStartupTaskJson, + const cJSON *preloadStartupTaskJson, std::map>& preloadSoStartupTasks) { - if (!preloadStartupTaskJson.contains(NAME) || !preloadStartupTaskJson[NAME].is_string() || - !preloadStartupTaskJson.contains(OHMURL) || !preloadStartupTaskJson[OHMURL].is_string()) { + cJSON *nameItem = cJSON_GetObjectItem(preloadStartupTaskJson, NAME); + cJSON *ohmUrlItem = cJSON_GetObjectItem(preloadStartupTaskJson, OHMURL); + if ((nameItem == nullptr || !cJSON_IsString(nameItem)) || + (ohmUrlItem == nullptr || !cJSON_IsString(ohmUrlItem))) { TAG_LOGE(AAFwkTag::STARTUP, "Invalid startupTaskJson data"); return false; } - std::string name = preloadStartupTaskJson.at(NAME).get(); - std::string ohmUrl = preloadStartupTaskJson.at(OHMURL).get(); + std::string name = nameItem->valuestring; + std::string ohmUrl = ohmUrlItem->valuestring; std::string path = bundleName_ + "/" + info.name_; auto task = std::make_shared(name, ohmUrl, path); @@ -1044,19 +1071,23 @@ bool StartupManager::AnalyzePreloadSoStartupTaskInner(const ModuleStartupConfigI return true; } -void StartupManager::SetOptionalParameters(const nlohmann::json& module, AppExecFwk::ModuleType moduleType, +void StartupManager::SetOptionalParameters(const cJSON *module, AppExecFwk::ModuleType moduleType, StartupTaskInfo& startupTaskInfo) { - if (module.contains(DEPENDENCIES) && module[DEPENDENCIES].is_array()) { - for (const auto& dependency : module.at(DEPENDENCIES)) { - if (dependency.is_string()) { - startupTaskInfo.dependencies.push_back(dependency.get()); + cJSON *dependenciesItem = cJSON_GetObjectItem(module, DEPENDENCIES); + if (dependenciesItem != nullptr && cJSON_IsArray(dependenciesItem)) { + int size = cJSON_GetArraySize(dependenciesItem); + for (int i = 0; i < size; i++) { + cJSON *dependencyItem = cJSON_GetArrayItem(dependenciesItem, i); + if (dependencyItem != nullptr && cJSON_IsString(dependencyItem)) { + startupTaskInfo.dependencies.push_back(std::string(dependencyItem->valuestring)); } } } - if (module.contains(RUN_ON_THREAD) && module[RUN_ON_THREAD].is_string()) { - std::string profileName = module.at(RUN_ON_THREAD).get(); + cJSON *runOnThreadItem = cJSON_GetObjectItem(module, RUN_ON_THREAD); + if (runOnThreadItem != nullptr && cJSON_IsString(runOnThreadItem)) { + std::string profileName = runOnThreadItem->valuestring; if (profileName == TASK_POOL || profileName == TASK_POOL_LOWER) { startupTaskInfo.callCreateOnMainThread = false; } else { @@ -1064,22 +1095,26 @@ void StartupManager::SetOptionalParameters(const nlohmann::json& module, AppExec } } - if (module.contains(WAIT_ON_MAIN_THREAD) && module[WAIT_ON_MAIN_THREAD].is_boolean()) { - startupTaskInfo.waitOnMainThread = module.at(WAIT_ON_MAIN_THREAD).get(); + cJSON *waitOnMainThreadItem = cJSON_GetObjectItem(module, WAIT_ON_MAIN_THREAD); + if (waitOnMainThreadItem != nullptr && cJSON_IsBool(waitOnMainThreadItem)) { + startupTaskInfo.waitOnMainThread = waitOnMainThreadItem->type == cJSON_True ? true : false; } else { startupTaskInfo.waitOnMainThread = true; } - if (module.contains(OHMURL) && module[OHMURL].is_string()) { - startupTaskInfo.ohmUrl = module.at(OHMURL).get(); + cJSON *ohmUrlItem = cJSON_GetObjectItem(module, OHMURL); + if (ohmUrlItem != nullptr && cJSON_IsString(ohmUrlItem)) { + startupTaskInfo.ohmUrl = ohmUrlItem->valuestring; } if (moduleType != AppExecFwk::ModuleType::ENTRY && moduleType != AppExecFwk::ModuleType::FEATURE) { startupTaskInfo.excludeFromAutoStart = true; return; } - if (module.contains(EXCLUDE_FROM_AUTO_START) && module[EXCLUDE_FROM_AUTO_START].is_boolean()) { - startupTaskInfo.excludeFromAutoStart = module.at(EXCLUDE_FROM_AUTO_START).get(); + + cJSON *excludeFromAutoStartItem = cJSON_GetObjectItem(module, EXCLUDE_FROM_AUTO_START); + if (excludeFromAutoStartItem != nullptr && cJSON_IsBool(excludeFromAutoStartItem)) { + startupTaskInfo.excludeFromAutoStart = excludeFromAutoStartItem->type == cJSON_True ? true : false; } else { startupTaskInfo.excludeFromAutoStart = false; } @@ -1087,7 +1122,7 @@ void StartupManager::SetOptionalParameters(const nlohmann::json& module, AppExec SetMatchRules(module, startupTaskInfo.matchRules); } -void StartupManager::SetOptionalParameters(const nlohmann::json &module, AppExecFwk::ModuleType moduleType, +void StartupManager::SetOptionalParameters(const cJSON *module, AppExecFwk::ModuleType moduleType, std::shared_ptr &task) { if (task == nullptr) { @@ -1102,8 +1137,10 @@ void StartupManager::SetOptionalParameters(const nlohmann::json &module, AppExec task->SetIsExcludeFromAutoStart(true); return; } - if (module.contains(EXCLUDE_FROM_AUTO_START) && module[EXCLUDE_FROM_AUTO_START].is_boolean()) { - task->SetIsExcludeFromAutoStart(module.at(EXCLUDE_FROM_AUTO_START).get()); + + cJSON *excludeFromAutoStartItem = cJSON_GetObjectItem(module, EXCLUDE_FROM_AUTO_START); + if (excludeFromAutoStartItem != nullptr && cJSON_IsBool(excludeFromAutoStartItem)) { + task->SetIsExcludeFromAutoStart(excludeFromAutoStartItem->type == cJSON_True ? true : false); } else { task->SetIsExcludeFromAutoStart(false); } @@ -1113,13 +1150,12 @@ void StartupManager::SetOptionalParameters(const nlohmann::json &module, AppExec task->SetMatchRules(matchRules); } -void StartupManager::SetMatchRules(const nlohmann::json &module, StartupTaskMatchRules &matchRules) +void StartupManager::SetMatchRules(const cJSON *module, StartupTaskMatchRules &matchRules) { - if (!module.contains(MATCH_RULES) || !module.at(MATCH_RULES).is_object()) { + cJSON *matchRulesJson = cJSON_GetObjectItem(module, MATCH_RULES); + if (matchRulesJson == nullptr || !cJSON_IsObject(matchRulesJson)) { return; } - - const nlohmann::json &matchRulesJson = module.at(MATCH_RULES); StartupUtils::ParseJsonStringArray(matchRulesJson, URIS, matchRules.uris); StartupUtils::ParseJsonStringArray(matchRulesJson, INSIGHT_INTENTS, matchRules.insightIntents); StartupUtils::ParseJsonStringArray(matchRulesJson, ACTIONS, matchRules.actions); diff --git a/frameworks/native/appkit/app_startup/startup_utils.cpp b/frameworks/native/appkit/app_startup/startup_utils.cpp index 2f5a729d60f7f3188008903ecc06cf1c5a398929..2451fcb8fe503f0ffaae7018d7181898d24a1b14 100644 --- a/frameworks/native/appkit/app_startup/startup_utils.cpp +++ b/frameworks/native/appkit/app_startup/startup_utils.cpp @@ -39,16 +39,18 @@ std::string StartupUtils::GetErrorMessage(int32_t errCode) return iter->second; } -bool StartupUtils::ParseJsonStringArray(const nlohmann::json &json, const std::string key, - std::vector &arr) +bool StartupUtils::ParseJsonStringArray(const cJSON *json, const std::string key, std::vector &arr) { - if (!json.contains(key) || !json[key].is_array()) { + cJSON *jsonObject = cJSON_GetObjectItem(json, key.c_str()); + if (jsonObject == nullptr || !cJSON_IsArray(jsonObject)) { return false; } - - for (const auto &item : json.at(key)) { - if (item.is_string()) { - arr.push_back(item.get()); + int size = cJSON_GetArraySize(jsonObject); + for (int i = 0; i < size; i++) { + cJSON *item = cJSON_GetArrayItem(jsonObject, i); + if (item != nullptr && cJSON_IsString(item)) { + std::string jsonStr = item->valuestring; + arr.push_back(jsonStr); } } return true; diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 4b04f031c12904c7d98a7d13b749f99b2dd9f16b..f56511199f16ddaf457462f20b63576bbb68ed10 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -1667,7 +1667,6 @@ std::string JsRuntime::GetSystemKitPath() std::vector JsRuntime::GetSystemKitsMap(uint32_t version) { std::vector systemKitsMap; - nlohmann::json jsonBuf; std::string configPath = GetSystemKitPath(); if (configPath == "" || access(configPath.c_str(), F_OK) != 0) { return systemKitsMap; @@ -1690,32 +1689,44 @@ std::vector JsRuntime::GetSystemKitsMap(uint32_t version) } in.seekg(0, std::ios::beg); - jsonBuf = nlohmann::json::parse(in, nullptr, false); + std::string fileContent((std::istreambuf_iterator(in)), std::istreambuf_iterator()); in.close(); - if (jsonBuf.is_discarded()) { + + cJSON *jsonBuf = cJSON_Parse(fileContent.c_str()); + if (jsonBuf == nullptr) { return systemKitsMap; } - - if (!jsonBuf.contains(SYSTEM_KITS)) { + cJSON *systemKitsItem = cJSON_GetObjectItem(jsonBuf, SYSTEM_KITS.c_str()); + if (systemKitsItem == nullptr || !cJSON_IsArray(systemKitsItem)) { + cJSON_Delete(jsonBuf); return systemKitsMap; } - for (auto &item : jsonBuf.at(SYSTEM_KITS).items()) { - nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(NAMESPACE) || !jsonObject.at(NAMESPACE).is_string() || - !jsonObject.contains(TARGET_OHM) || !jsonObject.at(TARGET_OHM).is_string() || - !jsonObject.contains(SINCE_VERSION) || !jsonObject.at(SINCE_VERSION).is_number()) { + + int arraySize = cJSON_GetArraySize(systemKitsItem); + for (int i = 0; i < arraySize; i++) { + cJSON *jsonObject = cJSON_GetArrayItem(systemKitsItem, i); + if (jsonObject == nullptr || !cJSON_IsObject(jsonObject)) { + continue; + } + cJSON *nameSpaceItem = cJSON_GetObjectItem(jsonObject, NAMESPACE.c_str()); + cJSON *targetOhmItem = cJSON_GetObjectItem(jsonObject, TARGET_OHM.c_str()); + cJSON *sinceVerItem = cJSON_GetObjectItem(jsonObject, SINCE_VERSION.c_str()); + if (nameSpaceItem == nullptr || !cJSON_IsString(nameSpaceItem) || + targetOhmItem == nullptr || !cJSON_IsString(targetOhmItem) || + sinceVerItem == nullptr || !cJSON_IsNumber(sinceVerItem)) { continue; } - uint32_t sinceVersion = jsonObject.at(SINCE_VERSION).get(); + uint32_t sinceVersion = static_cast(sinceVerItem->valuedouble); if (version >= sinceVersion) { panda::HmsMap hmsMap = { - .originalPath = jsonObject.at(NAMESPACE).get(), - .targetPath = jsonObject.at(TARGET_OHM).get(), + .originalPath = nameSpaceItem->valuestring, + .targetPath = targetOhmItem->valuestring, .sinceVersion = sinceVersion }; systemKitsMap.emplace_back(hmsMap); } } + cJSON_Delete(jsonBuf); TAG_LOGD(AAFwkTag::JSRUNTIME, "The size of the map is %{public}zu", systemKitsMap.size()); return systemKitsMap; } diff --git a/frameworks/native/runtime/js_runtime_lite.cpp b/frameworks/native/runtime/js_runtime_lite.cpp index ddab9ebf171c702666d86a2e109810afc795b23e..f042563526dfa9fd9f2ffbbbee8601acdd8815ae 100644 --- a/frameworks/native/runtime/js_runtime_lite.cpp +++ b/frameworks/native/runtime/js_runtime_lite.cpp @@ -472,66 +472,79 @@ void JsRuntimeLite::GetPkgContextInfoListMap(const std::mapfirst.c_str()); continue; } - auto jsonObject = nlohmann::json::parse(data.get(), data.get() + dataLen, nullptr, false); - if (jsonObject.is_discarded()) { + std::string jsonStr(reinterpret_cast(data.get(), dataLen)); + cJSON *jsonObject = cJSON_Parse(jsonStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::JSRUNTIME, "moduleName: %{public}s parse json error", it->first.c_str()); continue; } ParsePkgContextInfoJson(jsonObject, pkgContextInfoList, pkgAliasMap); + cJSON_Delete(jsonObject); TAG_LOGI(AAFwkTag::JSRUNTIME, "moduleName: %{public}s parse json success", it->first.c_str()); pkgContextInfoMap[it->first] = pkgContextInfoList; } } -void JsRuntimeLite::ParsePkgContextInfoJson(nlohmann::json &jsonObject, +void JsRuntimeLite::ParsePkgContextInfoJson(cJSON *jsonObject, std::vector> &pkgContextInfoList, std::map &pkgAliasMap) { - for (nlohmann::json::iterator jsonIt = jsonObject.begin(); jsonIt != jsonObject.end(); jsonIt++) { + cJSON *childItem = jsonObject->child; + while (childItem != nullptr) { std::vector items; - items.emplace_back(jsonIt.key()); - nlohmann::json itemObject = jsonIt.value(); + std::string key = childItem->string == nullptr ? "" : childItem->string; + items.emplace_back(key); + std::string pkgName = ""; items.emplace_back(PACKAGE_NAME); - if (itemObject[PACKAGE_NAME].is_null() || !itemObject[PACKAGE_NAME].is_string()) { + cJSON *packageNameItem = cJSON_GetObjectItem(childItem, PACKAGE_NAME.c_str()); + if (packageNameItem == nullptr || !cJSON_IsString(packageNameItem)) { items.emplace_back(pkgName); } else { - pkgName = itemObject[PACKAGE_NAME].get(); + pkgName = packageNameItem->valuestring; items.emplace_back(pkgName); } - ParsePkgContextInfoJsonString(itemObject, BUNDLE_NAME, items); - ParsePkgContextInfoJsonString(itemObject, MODULE_NAME, items); - ParsePkgContextInfoJsonString(itemObject, VERSION, items); - ParsePkgContextInfoJsonString(itemObject, ENTRY_PATH, items); + ParsePkgContextInfoJsonString(childItem, BUNDLE_NAME, items); + ParsePkgContextInfoJsonString(childItem, MODULE_NAME, items); + ParsePkgContextInfoJsonString(childItem, VERSION, items); + ParsePkgContextInfoJsonString(childItem, ENTRY_PATH, items); + items.emplace_back(IS_SO); - if (itemObject[IS_SO].is_null() || !itemObject[IS_SO].is_boolean()) { + cJSON *isSoItem = cJSON_GetObjectItem(childItem, IS_SO.c_str()); + if (isSoItem == nullptr || !cJSON_IsBool(isSoItem)) { items.emplace_back("false"); } else { - bool isSo = itemObject[IS_SO].get(); + bool isSo = isSoItem->type == cJSON_True ? true : false; if (isSo) { items.emplace_back("true"); } else { items.emplace_back("false"); } } - if (!itemObject[DEPENDENCY_ALIAS].is_null() && itemObject[DEPENDENCY_ALIAS].is_string()) { - std::string pkgAlias = itemObject[DEPENDENCY_ALIAS].get(); + + cJSON *aliasItem = cJSON_GetObjectItem(childItem, DEPENDENCY_ALIAS.c_str()); + if (aliasItem != nullptr && cJSON_IsString(aliasItem)) { + std::string pkgAlias = aliasItem->valuestring; if (!pkgAlias.empty()) { pkgAliasMap[pkgAlias] = pkgName; } } + pkgContextInfoList.emplace_back(items); + + childItem = childItem->next; } } void JsRuntimeLite::ParsePkgContextInfoJsonString( - const nlohmann::json &itemObject, const std::string &key, std::vector &items) + const cJSON *itemObject, const std::string &key, std::vector &items) { items.emplace_back(key); - if (itemObject[key].is_null() || !itemObject[key].is_string()) { + cJSON *item = cJSON_GetObjectItem(itemObject, key.c_str()); + if (item == nullptr || !cJSON_IsString(item)) { items.emplace_back(""); } else { - items.emplace_back(itemObject[key].get()); + items.emplace_back(std::string(item->valuestring)); } } } // namespace AbilityRuntime diff --git a/frameworks/simulator/ability_simulator/BUILD.gn b/frameworks/simulator/ability_simulator/BUILD.gn index 348edd58a1404c78be4d34cdb7d73610c4aa78c7..c0f0a38a5053cc3755b0bcf379d192ba17fca491 100644 --- a/frameworks/simulator/ability_simulator/BUILD.gn +++ b/frameworks/simulator/ability_simulator/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("ability_simulator_inner") { "src/bundle_parser/extension_ability_info.cpp", "src/bundle_parser/hap_module_info.cpp", "src/bundle_parser/inner_bundle_info.cpp", + "src/bundle_parser/json_util.cpp", "src/bundle_parser/module_info.cpp", "src/bundle_parser/module_profile.cpp", "src/bundle_parser/overlay_bundle_info.cpp", @@ -100,12 +101,11 @@ ohos_shared_library("ability_simulator_inner") { external_deps = [ "ability_base:string_utils", + "cJSON:cjson", "ets_runtime:libark_jsruntime", "ets_utils:console", "ets_utils:timer", "hilog:libhilog", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp_static", "napi:ace_napi", "previewer:ide_extension", "resource_management:resmgr_napi_core_preview", diff --git a/frameworks/simulator/ability_simulator/include/bundle_parser/common_profile.h b/frameworks/simulator/ability_simulator/include/bundle_parser/common_profile.h index 3fb5877127714d834c56dea22829d135031c0e3f..29add70075fcb50252d8d55830ddd0b594028b9a 100644 --- a/frameworks/simulator/ability_simulator/include/bundle_parser/common_profile.h +++ b/frameworks/simulator/ability_simulator/include/bundle_parser/common_profile.h @@ -18,8 +18,6 @@ #include -#include "nlohmann/json_fwd.hpp" - namespace OHOS { namespace AppExecFwk { namespace ProfileReader { diff --git a/frameworks/simulator/ability_simulator/include/bundle_parser/inner_bundle_info.h b/frameworks/simulator/ability_simulator/include/bundle_parser/inner_bundle_info.h index 5a6c08cdbffa18dbe06146069daa269deda197ba..50f94b05a3808a469d52ef298696caa232ecc13b 100644 --- a/frameworks/simulator/ability_simulator/include/bundle_parser/inner_bundle_info.h +++ b/frameworks/simulator/ability_simulator/include/bundle_parser/inner_bundle_info.h @@ -112,13 +112,13 @@ public: * @param jsonObject Indicates the obtained json object. * @return */ - void ToJson(nlohmann::json &jsonObject) const; + bool ToJson(cJSON *jsonObject) const; /** * @brief Transform the json object to InnerBundleInfo object. * @param jsonObject Indicates the obtained json object. * @return Returns 0 if the json object parsed successfully; returns error code otherwise. */ - int32_t FromJson(const nlohmann::json &jsonObject); + int32_t FromJson(const cJSON *jsonObject); /** * @brief Find hap module info by module package. * @param modulePackage Indicates the module package. @@ -268,8 +268,11 @@ private: int32_t overlayType_ = NON_OVERLAY_TYPE; }; -void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info); -void from_json(const nlohmann::json &jsonObject, Distro &distro); +bool to_json(cJSON *jsonObject, const Distro &distro); +bool to_json(cJSON *jsonObject, const InnerModuleInfo &info); + +void from_json(const cJSON *jsonObject, InnerModuleInfo &info); +void from_json(const cJSON *jsonObject, Distro &distro); } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_SIMULATOR_INNER_BUNDLE_INFO_H diff --git a/frameworks/simulator/ability_simulator/include/bundle_parser/json_serializer.h b/frameworks/simulator/ability_simulator/include/bundle_parser/json_serializer.h index 80aa463d00ee1c98a3d7d4323aced842b7017379..fc1e42f1933f8a98caec8f414cd574a5ee6513a1 100644 --- a/frameworks/simulator/ability_simulator/include/bundle_parser/json_serializer.h +++ b/frameworks/simulator/ability_simulator/include/bundle_parser/json_serializer.h @@ -19,10 +19,10 @@ #include "ability_info.h" #include "application_info.h" #include "bundle_info.h" +#include "cJSON.h" #include "extension_ability_info.h" #include "hap_module_info.h" #include "module_info.h" -#include "nlohmann/json.hpp" namespace OHOS { namespace AppExecFwk { @@ -30,59 +30,190 @@ namespace AppExecFwk { * form_json and to_json is global static overload method, which need callback by json library, * and can not rename this function, so don't named according UpperCamelCase style */ -void to_json(nlohmann::json &jsonObject, const CustomizeData &customizeData); -void to_json(nlohmann::json &jsonObject, const MetaData &metaData); -void to_json(nlohmann::json &jsonObject, const Metadata &metadata); -void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo); -void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData); -void from_json(const nlohmann::json &jsonObject, MetaData &metaData); -void from_json(const nlohmann::json &jsonObject, Metadata &metadata); -void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo); -void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInfo); -void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo); -void from_json(const nlohmann::json &jsonObject, Resource &resource); -void to_json(nlohmann::json &jsonObject, const Resource &resource); -void from_json(const nlohmann::json &jsonObject, HapModuleInfo &hapModuleInfo); -void to_json(nlohmann::json &jsonObject, const HapModuleInfo &hapModuleInfo); -void from_json(const nlohmann::json &jsonObject, ProxyData &proxyData); -void to_json(nlohmann::json &jsonObject, const ProxyData &proxyData); -void from_json(const nlohmann::json &jsonObject, Dependency &dependency); -void to_json(nlohmann::json &jsonObject, const Dependency &dependency); -void from_json(const nlohmann::json &jsonObject, PreloadItem &preloadItem); -void to_json(nlohmann::json &jsonObject, const PreloadItem &preloadItem); -void from_json(const nlohmann::json &jsonObject, ModuleInfo &moduleInfo); -void to_json(nlohmann::json &jsonObject, const ModuleInfo &moduleInfo); -void from_json(const nlohmann::json &jsonObject, ExtensionAbilityInfo &extensionInfo); -void to_json(nlohmann::json &jsonObject, const ExtensionAbilityInfo &extensionInfo); -void from_json(const nlohmann::json &jsonObject, HnpPackage &hnpPackage); -void to_json(nlohmann::json &jsonObject, const HnpPackage &hnpPackage); -void from_json(const nlohmann::json &jsonObject, MultiAppModeData &multiAppMode); -void to_json(nlohmann::json &jsonObject, const MultiAppModeData &multiAppMode); -void from_json(const nlohmann::json &jsonObject, ApplicationEnvironment &applicationEnvironment); -void to_json(nlohmann::json &jsonObject, const ApplicationEnvironment &applicationEnvironment); -void from_json(const nlohmann::json &jsonObject, HqfInfo &hqfInfo); -void to_json(nlohmann::json &jsonObject, const HqfInfo &hqfInfo); -void from_json(const nlohmann::json &jsonObject, AppqfInfo &appqfInfo); -void to_json(nlohmann::json &jsonObject, const AppqfInfo &appqfInfo); -void from_json(const nlohmann::json &jsonObject, AppQuickFix &appQuickFix); -void to_json(nlohmann::json &jsonObject, const AppQuickFix &appQuickFix); -void from_json(const nlohmann::json &jsonObject, StartWindowResource &startWindowResource); -void to_json(nlohmann::json &jsonObject, const StartWindowResource &startWindowResource); -void from_json(const nlohmann::json &jsonObject, OverlayModuleInfo &overlayModuleInfo); -void to_json(nlohmann::json &jsonObject, const OverlayModuleInfo &overlayModuleInfo); -void from_json(const nlohmann::json &jsonObject, RouterItem &routerItem); -void to_json(nlohmann::json &jsonObject, const RouterItem &routerItem); -void from_json(const nlohmann::json &jsonObject, AppEnvironment &appEnvironment); -void to_json(nlohmann::json &jsonObject, const AppEnvironment &appEnvironment); -void to_json(nlohmann::json &jsonObject, const BundleInfo &bundleInfo); -void from_json(const nlohmann::json &jsonObject, BundleInfo &bundleInfo); -void to_json(nlohmann::json &jsonObject, const OverlayBundleInfo &overlayBundleInfo); -void from_json(const nlohmann::json &jsonObject, OverlayBundleInfo &overlayBundleInfo); -void to_json(nlohmann::json &jsonObject, const RequestPermissionUsedScene &usedScene); -void from_json(const nlohmann::json &jsonObject, RequestPermissionUsedScene &usedScene); -void to_json(nlohmann::json &jsonObject, const RequestPermission &requestPermission); -void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission); -void to_json(nlohmann::json &jsonObject, const SignatureInfo &signatureInfo); +bool to_json(cJSON *jsonObject, const std::string &value); +bool to_json(cJSON *jsonObject, const bool &value); +bool to_json(cJSON *jsonObject, const OHOS::AppExecFwk::SupportWindowMode &value); + +template +bool to_json(cJSON *jsonObject, const std::vector &values) +{ + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + for (auto& value : values) { + cJSON *valueItem = nullptr; + if (!to_json(valueItem, value)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToArray(jsonObject, valueItem); + } + return true; +} + +template +bool to_json(cJSON *jsonObject, const std::unordered_set &values) +{ + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + for (auto& value : values) { + cJSON *valueItem = nullptr; + if (!to_json(valueItem, value)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToArray(jsonObject, valueItem); + } + return true; +} + +template +bool to_json(cJSON *jsonObject, const std::map &valueMap) +{ + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + for (const auto& [key, values] : valueMap) { + cJSON *valuesObject = cJSON_CreateObject(); + cJSON *valuesItem = nullptr; + if (!to_json(valuesItem, values)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + cJSON_AddItemToObject(valuesObject, key.c_str(), valuesObject); + cJSON_AddItemToArray(jsonObject, valuesObject); + } + return true; +} + +void from_json(const cJSON *jsonObject, std::string &value); + +void from_json(const cJSON *jsonObject, bool &value); + +template +void from_json(const cJSON *jsonObject, std::vector &values) +{ + if (jsonObject == nullptr || !cJSON_IsArray(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not array"); + return; + } + int size = cJSON_GetArraySize(jsonObject); + for (int i = 0; i < size; i++) { + cJSON *valueItem = cJSON_GetArrayItem(jsonObject, i); + if (valueItem != nullptr) { + T value; + from_json(valueItem, value); + values.push_back(value); + } + } +} + +template +void from_json(const cJSON *jsonObject, std::unordered_set &values) +{ + if (jsonObject == nullptr || !cJSON_IsArray(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not array"); + return; + } + int size = cJSON_GetArraySize(jsonObject); + for (int i = 0; i < size; i++) { + cJSON *valueItem = cJSON_GetArrayItem(jsonObject, i); + if (valueItem != nullptr) { + T value; + from_json(valueItem, value); + values.emplace(value); + } + } +} + +// ability_info +bool to_json(cJSON *jsonObject, const CustomizeData &customizeData); +bool to_json(cJSON *jsonObject, const MetaData &metaData); +bool to_json(cJSON *jsonObject, const Metadata &metadata); +bool to_json(cJSON *jsonObject, const StartWindowResource &startWindowResource); +bool to_json(cJSON *jsonObject, const AbilityInfo &abilityInfo); + +void from_json(const cJSON *jsonObject, CustomizeData &customizeData); +void from_json(const cJSON *jsonObject, MetaData &metaData); +void from_json(const cJSON *jsonObject, Metadata &metadata); +void from_json(const cJSON *jsonObject, StartWindowResource &startWindowResource); +void from_json(const cJSON *jsonObject, AbilityInfo &abilityInfo); + +// application_info +bool to_json(cJSON *jsonObject, const Resource &resource); +bool to_json(cJSON *jsonObject, const HnpPackage &hnpPackage); +bool to_json(cJSON *jsonObject, const MultiAppModeData &multiAppMode); +bool to_json(cJSON *jsonObject, const ApplicationEnvironment &applicationEnvironment); +bool to_json(cJSON *jsonObject, const HqfInfo &hqfInfo); +bool to_json(cJSON *jsonObject, const AppqfInfo &appqfInfo); +bool to_json(cJSON *jsonObject, const AppQuickFix &appQuickFix); +bool to_json(cJSON *jsonObject, const ApplicationInfo &applicationInfo); + +void from_json(const cJSON *jsonObject, Resource &resource); +void from_json(const cJSON *jsonObject, HnpPackage &hnpPackage); +void from_json(const cJSON *jsonObject, MultiAppModeData &multiAppMode); +void from_json(const cJSON *jsonObject, ApplicationEnvironment &applicationEnvironment); +void from_json(const cJSON *jsonObject, HqfInfo &hqfInfo); +void from_json(const cJSON *jsonObject, AppqfInfo &appqfInfo); +void from_json(const cJSON *jsonObject, AppQuickFix &appQuickFix); +void from_json(const cJSON *jsonObject, ApplicationInfo &applicationInfo); + +// extension_ability_info +bool to_json(cJSON *jsonObject, const ExtensionAbilityInfo &extensionInfo); + +void from_json(const cJSON *jsonObject, ExtensionAbilityInfo &extensionInfo); + +// inner_bundle_info +bool to_json(cJSON *jsonObject, const Dependency &dependency); + +void from_json(const cJSON *jsonObject, Dependency &dependency); + +// module_info +bool to_json(cJSON *jsonObject, const ModuleInfo &moduleInfo); + +void from_json(const cJSON *jsonObject, ModuleInfo &moduleInfo); + +// hap_module_info +bool to_json(cJSON *jsonObject, const PreloadItem &preloadItem); +bool to_json(cJSON *jsonObject, const ProxyData &proxyData); +bool to_json(cJSON *jsonObject, const OverlayModuleInfo &overlayModuleInfo); +bool to_json(cJSON *jsonObject, const RouterItem &routerItem); +bool to_json(cJSON *jsonObject, const AppEnvironment &appEnvironment); +bool to_json(cJSON *jsonObject, const HapModuleInfo &hapModuleInfo); + +void from_json(const cJSON *jsonObject, PreloadItem &preloadItem); +void from_json(const cJSON *jsonObject, ProxyData &proxyData); +void from_json(const cJSON *jsonObject, OverlayModuleInfo &overlayModuleInfo); +void from_json(const cJSON *jsonObject, RouterItem &routerItem); +void from_json(const cJSON *jsonObject, AppEnvironment &appEnvironment); +void from_json(const cJSON *jsonObject, HapModuleInfo &hapModuleInfo); + +// bundle_info +bool to_json(cJSON *jsonObject, const RequestPermissionUsedScene &usedScene); +bool to_json(cJSON *jsonObject, const RequestPermission &requestPermission); +bool to_json(cJSON *jsonObject, const SignatureInfo &signatureInfo); +bool to_json(cJSON *jsonObject, const BundleInfo &bundleInfo); + +void from_json(const cJSON *jsonObject, RequestPermissionUsedScene &usedScene); +void from_json(const cJSON *jsonObject, RequestPermission &requestPermission); +void from_json(const cJSON *jsonObject, SignatureInfo &signatureInfo); +void from_json(const cJSON *jsonObject, BundleInfo &bundleInfo); + +// overlay_bundle_info +bool to_json(cJSON *jsonObject, const OverlayBundleInfo &overlayBundleInfo); + +void from_json(const cJSON *jsonObject, OverlayBundleInfo &overlayBundleInfo); + + } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_SIMULATOR_JSON_SERIALIZER_H diff --git a/frameworks/simulator/ability_simulator/include/bundle_parser/json_util.h b/frameworks/simulator/ability_simulator/include/bundle_parser/json_util.h index b09d56c29cac99bb1c104f4c8ca8d500aab42cf3..9afcb0444921a2558677e3eacf55417b306177ee 100644 --- a/frameworks/simulator/ability_simulator/include/bundle_parser/json_util.h +++ b/frameworks/simulator/ability_simulator/include/bundle_parser/json_util.h @@ -16,178 +16,235 @@ #ifndef OHOS_ABILITY_RUNTIME_SIMULATOR_JSON_UTIL_H #define OHOS_ABILITY_RUNTIME_SIMULATOR_JSON_UTIL_H +#include #include +#include #include "appexecfwk_errors.h" #include "bundle_constants.h" +#include "cJSON.h" #include "hilog_tag_wrapper.h" #include "json_serializer.h" namespace OHOS { namespace AppExecFwk { -enum class JsonType { - NULLABLE, - BOOLEAN, - NUMBER, - OBJECT, - ARRAY, - STRING, -}; - -enum class ArrayType { - NUMBER, - OBJECT, - STRING, - NOT_ARRAY, -}; - -template -void CheckArrayType( - const nlohmann::json &jsonObject, const std::string &key, dataType &data, ArrayType arrayType, int32_t &parseResult) +std::string JsonToString(const cJSON *jsonObject); + +void GetStringValueIfFindKey(const cJSON *jsonObject, + const std::string &key, std::string &data, + bool isNecessary, int32_t &parseResult); + +void GetStringValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult); + +void GetUnorderedSetValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::unordered_set &data, + bool isNecessary, int32_t &parseResult); + +template +void GetNumberValueIfFindKey(const cJSON *jsonObject, + const std::string &key, T &data, + bool isNecessary, int32_t &parseResult) { - auto arrays = jsonObject.at(key); - if (arrays.empty()) { - return; - } - if (arrays.size() > Constants::MAX_JSON_ARRAY_LENGTH) { - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR; - return; - } - switch (arrayType) { - case ArrayType::STRING: - for (const auto &array : arrays) { - if (!array.is_string()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "array %{public}s not string", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - } - } - if (parseResult == ERR_OK) { - data = jsonObject.at(key).get(); - } - break; - case ArrayType::OBJECT: - for (const auto &array : arrays) { - if (!array.is_object()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "array %{public}s not object", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - } - if (parseResult == ERR_OK) { - data = jsonObject.at(key).get(); - } - break; - case ArrayType::NUMBER: - for (const auto &array : arrays) { - if (!array.is_number()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "array %{public}s not number", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - } - } - if (parseResult == ERR_OK) { - data = jsonObject.at(key).get(); - } - break; - case ArrayType::NOT_ARRAY: - TAG_LOGD(AAFwkTag::ABILITY_SIM, "array %{public}s not string", key.c_str()); - break; - default: - TAG_LOGD(AAFwkTag::ABILITY_SIM, "array %{public}s type error", key.c_str()); - break; + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsNumber(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not number", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; } + data = static_cast(item->valuedouble); } -template -void GetValueIfFindKey(const nlohmann::json &jsonObject, const nlohmann::detail::iter_impl &end, - const std::string &key, dataType &data, JsonType jsonType, bool isNecessary, int32_t &parseResult, - ArrayType arrayType) +template +void GetNumberValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) { if (parseResult) { return; } - if (jsonObject.find(key) != end) { - switch (jsonType) { - case JsonType::BOOLEAN: - if (!jsonObject.at(key).is_boolean()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - data = jsonObject.at(key).get(); - break; - case JsonType::NUMBER: - if (!jsonObject.at(key).is_number()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not number", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - data = jsonObject.at(key).get(); - break; - case JsonType::OBJECT: - if (!jsonObject.at(key).is_object()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - data = jsonObject.at(key).get(); - break; - case JsonType::ARRAY: - if (!jsonObject.at(key).is_array()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - CheckArrayType(jsonObject, key, data, arrayType, parseResult); - break; - case JsonType::STRING: - if (!jsonObject.at(key).is_string()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not string", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; - break; - } - data = jsonObject.at(key).get(); - if (jsonObject.at(key).get().length() > Constants::MAX_JSON_ELEMENT_LENGTH) { - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR; - } - break; - case JsonType::NULLABLE: - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s is nullable", key.c_str()); - break; - default: - TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not jsonType", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; } return; } - if (isNecessary) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); - parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsNumber(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not number list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + T value = static_cast(childItem->valuedouble); + data.push_back(value); } } +void GetBoolValueIfFindKey(const cJSON *jsonObject, + const std::string &key, bool &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult); + template -const std::string GetJsonStrFromInfo(T &t) +void GetObjectValueIfFindKey(const cJSON *jsonObject, + const std::string &key, T &data, + bool isNecessary, int32_t &parseResult) { - nlohmann::json json = t; - return json.dump(); + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsObject(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + from_json(jsonObject, data); } template -bool ParseInfoFromJsonStr(const char *data, T &t) +void GetObjectValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) { - if (data == nullptr) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "null data"); - return false; + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + T value; + from_json(childItem, value); + data.push_back(value); + } +} - nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "discarded data"); - return false; +template +void GetObjectValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + T value; + std::string key = childItem->string == nullptr ? "" : childItem->string; + from_json(childItem, value); + data.emplace(key, value); + } +} - t = jsonObject.get(); - return true; +template +void GetObjectValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + std::vector value; + from_json(childItem, value); + data.emplace(key, value); + } } } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/ability_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/ability_info.cpp index 4cc16b9af4327365596462ea77bc1ed0dcfb36aa..02d972c3db6dec8b27bef5a94861b05976966909 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/ability_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/ability_info.cpp @@ -23,7 +23,6 @@ #include "bundle_constants.h" #include "hilog_tag_wrapper.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -120,901 +119,454 @@ const std::string START_WINDOW_BACKGROUND_COLOR_ID = "startWindowBackgroundColor const std::string START_WINDOW_BACKGROUND_IMAGE_ID = "startWindowBackgroundImageId"; const std::string START_WINDOW_BACKGROUND_IMAGE_FIT = "startWindowBackgroundImageFit"; } // namespace -void to_json(nlohmann::json &jsonObject, const CustomizeData &customizeData) +bool to_json(cJSON *jsonObject, const std::string &value) { - jsonObject = nlohmann::json { - {JSON_KEY_NAME, customizeData.name}, - {JSON_KEY_META_VALUE, customizeData.value}, - {JSON_KEY_META_EXTRA, customizeData.extra} - }; + jsonObject = cJSON_CreateString(value.c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create string json failed"); + return false; + } + return true; +} + +bool to_json(cJSON *jsonObject, const bool &value) +{ + jsonObject = cJSON_CreateBool(value); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create bool json failed"); + return false; + } + return true; +} + +bool to_json(cJSON *jsonObject, const OHOS::AppExecFwk::SupportWindowMode &value) +{ + jsonObject = cJSON_CreateNumber(static_cast(value)); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create number json failed"); + return false; + } + return true; +} + +void from_json(const cJSON *jsonObject, std::string &value) +{ + if (jsonObject == nullptr || !cJSON_IsString(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not string"); + return; + } + if (std::string(jsonObject->valuestring).length() > Constants::MAX_JSON_ELEMENT_LENGTH) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "string length over"); + return; + } + value = jsonObject->valuestring; +} + +void from_json(const cJSON *jsonObject, bool &value) +{ + if (jsonObject == nullptr || !cJSON_IsBool(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not bool"); + return; + } + value = jsonObject->type == cJSON_True ? true : false; } -void to_json(nlohmann::json &jsonObject, const MetaData &metaData) +bool to_json(cJSON *jsonObject, const CustomizeData &customizeData) { - jsonObject = nlohmann::json { - {JSON_KEY_CUSTOMIZE_DATA, metaData.customizeData} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_NAME.c_str(), customizeData.name.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_META_VALUE.c_str(), customizeData.value.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_META_EXTRA.c_str(), customizeData.extra.c_str()); + return true; } -void to_json(nlohmann::json &jsonObject, const Metadata &metadata) +bool to_json(cJSON *jsonObject, const MetaData &metaData) { - jsonObject = nlohmann::json { - {META_DATA_VALUEID, metadata.valueId}, - {META_DATA_NAME, metadata.name}, - {META_DATA_VALUE, metadata.value}, - {META_DATA_RESOURCE, metadata.resource} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON *customizeDatasItem = nullptr; + if (!to_json(customizeDatasItem, metaData.customizeData)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json customizeData failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_CUSTOMIZE_DATA.c_str(), customizeDatasItem); + return true; } -void to_json(nlohmann::json &jsonObject, const StartWindowResource &startWindowResource) +bool to_json(cJSON *jsonObject, const Metadata &metadata) { - jsonObject = nlohmann::json { - {START_WINDOW_APP_ICON_ID, startWindowResource.startWindowAppIconId}, - {START_WINDOW_ILLUSTRATION_ID, startWindowResource.startWindowIllustrationId}, - {START_WINDOW_BRANDING_IMAGE_ID, startWindowResource.startWindowBrandingImageId}, - {START_WINDOW_BACKGROUND_COLOR_ID, startWindowResource.startWindowBackgroundColorId}, - {START_WINDOW_BACKGROUND_IMAGE_ID, startWindowResource.startWindowBackgroundImageId}, - {START_WINDOW_BACKGROUND_IMAGE_FIT, startWindowResource.startWindowBackgroundImageFit} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddNumberToObject(jsonObject, META_DATA_VALUEID.c_str(), metadata.valueId); + cJSON_AddStringToObject(jsonObject, META_DATA_NAME.c_str(), metadata.name.c_str()); + cJSON_AddStringToObject(jsonObject, META_DATA_VALUE.c_str(), metadata.value.c_str()); + cJSON_AddStringToObject(jsonObject, META_DATA_RESOURCE.c_str(), metadata.resource.c_str()); + return true; } -void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo) +bool to_json(cJSON *jsonObject, const StartWindowResource &startWindowResource) +{ + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddNumberToObject(jsonObject, START_WINDOW_APP_ICON_ID.c_str(), + static_cast(startWindowResource.startWindowAppIconId)); + cJSON_AddNumberToObject(jsonObject, START_WINDOW_ILLUSTRATION_ID.c_str(), + static_cast(startWindowResource.startWindowIllustrationId)); + cJSON_AddNumberToObject(jsonObject, START_WINDOW_BRANDING_IMAGE_ID.c_str(), + static_cast(startWindowResource.startWindowBrandingImageId)); + cJSON_AddNumberToObject(jsonObject, START_WINDOW_BACKGROUND_COLOR_ID.c_str(), + static_cast(startWindowResource.startWindowBackgroundColorId)); + cJSON_AddNumberToObject(jsonObject, START_WINDOW_BACKGROUND_IMAGE_ID.c_str(), + static_cast(startWindowResource.startWindowBackgroundImageId)); + cJSON_AddStringToObject(jsonObject, START_WINDOW_BACKGROUND_IMAGE_FIT.c_str(), + startWindowResource.startWindowBackgroundImageFit.c_str()); + return true; +} + +bool to_json(cJSON *jsonObject, const AbilityInfo &abilityInfo) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "called"); - jsonObject = nlohmann::json { - {JSON_KEY_NAME, abilityInfo.name}, - {JSON_KEY_LABEL, abilityInfo.label}, - {JSON_KEY_DESCRIPTION, abilityInfo.description}, - {JSON_KEY_ICON_PATH, abilityInfo.iconPath}, - {JSON_KEY_LABEL_ID, abilityInfo.labelId}, - {JSON_KEY_DESCRIPTION_ID, abilityInfo.descriptionId}, - {JSON_KEY_ICON_ID, abilityInfo.iconId}, - {JSON_KEY_THEME, abilityInfo.theme}, - {JSON_KEY_VISIBLE, abilityInfo.visible}, - {JSON_KEY_KIND, abilityInfo.kind}, - {JSON_KEY_TYPE, abilityInfo.type}, - {JSON_KEY_EXTENSION_ABILITY_TYPE, abilityInfo.extensionAbilityType}, - {JSON_KEY_ORIENTATION, abilityInfo.orientation}, - {JSON_KEY_LAUNCH_MODE, abilityInfo.launchMode}, - {JSON_KEY_SRC_PATH, abilityInfo.srcPath}, - {JSON_KEY_SRC_LANGUAGE, abilityInfo.srcLanguage}, - {JSON_KEY_PERMISSIONS, abilityInfo.permissions}, - {JSON_KEY_PROCESS, abilityInfo.process}, - {JSON_KEY_DEVICE_TYPES, abilityInfo.deviceTypes}, - {JSON_KEY_DEVICE_CAPABILITIES, abilityInfo.deviceCapabilities}, - {JSON_KEY_URI, abilityInfo.uri}, - {JSON_KEY_TARGET_ABILITY, abilityInfo.targetAbility}, - {JSON_KEY_IS_LAUNCHER_ABILITY, abilityInfo.isLauncherAbility}, - {JSON_KEY_IS_NATIVE_ABILITY, abilityInfo.isNativeAbility}, - {JSON_KEY_ENABLED, abilityInfo.enabled}, - {JSON_KEY_SUPPORT_PIP_MODE, abilityInfo.supportPipMode}, - {JSON_KEY_FORM_ENABLED, abilityInfo.formEnabled}, - {JSON_KEY_READ_PERMISSION, abilityInfo.readPermission}, - {JSON_KEY_WRITE_PERMISSION, abilityInfo.writePermission}, - {JSON_KEY_CONFIG_CHANGES, abilityInfo.configChanges}, - {JSON_KEY_FORM_ENTITY, abilityInfo.formEntity}, - {JSON_KEY_MIN_FORM_HEIGHT, abilityInfo.minFormHeight}, - {JSON_KEY_DEFAULT_FORM_HEIGHT, abilityInfo.defaultFormHeight}, - {JSON_KEY_MIN_FORM_WIDTH, abilityInfo.minFormWidth}, - {JSON_KEY_DEFAULT_FORM_WIDTH, abilityInfo.defaultFormWidth}, - {JSON_KEY_META_DATA, abilityInfo.metaData}, - {JSON_KEY_BACKGROUND_MODES, abilityInfo.backgroundModes}, - {JSON_KEY_PACKAGE, abilityInfo.package}, - {Constants::BUNDLE_NAME, abilityInfo.bundleName}, - {Constants::MODULE_NAME, abilityInfo.moduleName}, - {JSON_KEY_APPLICATION_NAME, abilityInfo.applicationName}, - {JSON_KEY_CODE_PATH, abilityInfo.codePath}, - {JSON_KEY_RESOURCE_PATH, abilityInfo.resourcePath}, - {Constants::HAP_PATH, abilityInfo.hapPath}, - {SRC_ENTRANCE, abilityInfo.srcEntrance}, - {META_DATA, abilityInfo.metadata}, - {IS_MODULE_JSON, abilityInfo.isModuleJson}, - {IS_STAGE_BASED_MODEL, abilityInfo.isStageBasedModel}, - {CONTINUABLE, abilityInfo.continuable}, - {PRIORITY, abilityInfo.priority}, - {JSON_KEY_START_WINDOW, abilityInfo.startWindow}, - {JSON_KEY_START_WINDOW_ICON, abilityInfo.startWindowIcon}, - {JSON_KEY_START_WINDOW_ICON_ID, abilityInfo.startWindowIconId}, - {JSON_KEY_START_WINDOW_BACKGROUND, abilityInfo.startWindowBackground}, - {JSON_KEY_START_WINDOW_BACKGROUND_ID, abilityInfo.startWindowBackgroundId}, - {JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE, abilityInfo.removeMissionAfterTerminate}, - {JSON_KEY_COMPILE_MODE, abilityInfo.compileMode}, - {JOSN_KEY_SUPPORT_WINDOW_MODE, abilityInfo.windowModes}, - {JOSN_KEY_MAX_WINDOW_WIDTH, abilityInfo.maxWindowWidth}, - {JOSN_KEY_MIN_WINDOW_WIDTH, abilityInfo.minWindowWidth}, - {JOSN_KEY_MAX_WINDOW_HEIGHT, abilityInfo.maxWindowHeight}, - {JOSN_KEY_MIN_WINDOW_HEIGHT, abilityInfo.minWindowHeight}, - {JOSN_KEY_UID, abilityInfo.uid}, - {JOSN_KEY_EXCLUDE_FROM_MISSIONS, abilityInfo.excludeFromMissions}, - {JOSN_KEY_UNCLEARABLE_MISSION, abilityInfo.unclearableMission}, - {JSON_KEY_RECOVERABLE, abilityInfo.recoverable}, - {JSON_KEY_SUPPORT_EXT_NAMES, abilityInfo.supportExtNames}, - {JSON_KEY_SUPPORT_MIME_TYPES, abilityInfo.supportMimeTypes}, - {JSON_KEY_ISOLATION_PROCESS, abilityInfo.isolationProcess}, - {JSON_KEY_CONTINUE_TYPE, abilityInfo.continueType}, - {JSON_KEY_CONTINUE_BUNDLE_NAME, abilityInfo.continueBundleNames}, - {JSON_KEY_APP_INDEX, abilityInfo.appIndex}, - {JSON_KEY_ORIENTATION_ID, abilityInfo.orientationId}, - {JSON_KEY_START_WINDOW_RESOURCE, abilityInfo.startWindowResource} - }; - if (abilityInfo.maxWindowRatio == 0) { - // maxWindowRatio in json string will be 0 instead of 0.0 - jsonObject[JOSN_KEY_MAX_WINDOW_RATIO] = 0; - } else { - jsonObject[JOSN_KEY_MAX_WINDOW_RATIO] = abilityInfo.maxWindowRatio; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; } + cJSON_AddStringToObject(jsonObject, JSON_KEY_NAME.c_str(), abilityInfo.name.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_LABEL.c_str(), abilityInfo.label.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_DESCRIPTION.c_str(), abilityInfo.description.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_ICON_PATH.c_str(), abilityInfo.iconPath.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_LABEL_ID.c_str(), static_cast(abilityInfo.labelId)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_DESCRIPTION_ID.c_str(), + static_cast(abilityInfo.descriptionId)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_ICON_ID.c_str(), static_cast(abilityInfo.iconId)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_THEME.c_str(), abilityInfo.theme.c_str()); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_VISIBLE.c_str(), abilityInfo.visible); + cJSON_AddStringToObject(jsonObject, JSON_KEY_KIND.c_str(), abilityInfo.kind.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_TYPE.c_str(), static_cast(abilityInfo.type)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_EXTENSION_ABILITY_TYPE.c_str(), + static_cast(abilityInfo.extensionAbilityType)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_ORIENTATION.c_str(), static_cast(abilityInfo.orientation)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_LAUNCH_MODE.c_str(), static_cast(abilityInfo.launchMode)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_SRC_PATH.c_str(), abilityInfo.srcPath.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_SRC_LANGUAGE.c_str(), abilityInfo.srcLanguage.c_str()); - if (abilityInfo.minWindowRatio == 0) { - jsonObject[JOSN_KEY_MIN_WINDOW_RATIO] = 0; - } else { - jsonObject[JOSN_KEY_MIN_WINDOW_RATIO] = abilityInfo.minWindowRatio; + cJSON *permissionsItem = nullptr; + if (!to_json(permissionsItem, abilityInfo.permissions)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json permissions failed"); + cJSON_Delete(jsonObject); + return false; } + cJSON_AddItemToObject(jsonObject, JSON_KEY_PERMISSIONS.c_str(), permissionsItem); + + cJSON_AddStringToObject(jsonObject, JSON_KEY_PROCESS.c_str(), abilityInfo.process.c_str()); + + cJSON *deviceTypesItem = nullptr; + if (!to_json(deviceTypesItem, abilityInfo.deviceTypes)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deviceTypes failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_DEVICE_TYPES.c_str(), deviceTypesItem); + + cJSON *deviceCapabilitiesItem = nullptr; + if (!to_json(deviceCapabilitiesItem, abilityInfo.deviceCapabilities)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deviceCapabilities failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_DEVICE_CAPABILITIES.c_str(), deviceCapabilitiesItem); + + cJSON_AddStringToObject(jsonObject, JSON_KEY_URI.c_str(), abilityInfo.uri.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_TARGET_ABILITY.c_str(), abilityInfo.targetAbility.c_str()); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_IS_LAUNCHER_ABILITY.c_str(), abilityInfo.isLauncherAbility); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_IS_NATIVE_ABILITY.c_str(), abilityInfo.isNativeAbility); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_ENABLED.c_str(), abilityInfo.enabled); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_SUPPORT_PIP_MODE.c_str(), abilityInfo.supportPipMode); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_FORM_ENABLED.c_str(), abilityInfo.formEnabled); + cJSON_AddStringToObject(jsonObject, JSON_KEY_READ_PERMISSION.c_str(), abilityInfo.readPermission.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_WRITE_PERMISSION.c_str(), abilityInfo.writePermission.c_str()); + + cJSON *configChangesItem = nullptr; + if (!to_json(configChangesItem, abilityInfo.configChanges)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json configChanges failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_CONFIG_CHANGES.c_str(), configChangesItem); + + cJSON_AddNumberToObject(jsonObject, JSON_KEY_FORM_ENTITY.c_str(), static_cast(abilityInfo.formEntity)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_MIN_FORM_HEIGHT.c_str(), + static_cast(abilityInfo.minFormHeight)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_DEFAULT_FORM_HEIGHT.c_str(), + static_cast(abilityInfo.defaultFormHeight)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_MIN_FORM_WIDTH.c_str(), static_cast(abilityInfo.minFormWidth)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_DEFAULT_FORM_WIDTH.c_str(), + static_cast(abilityInfo.defaultFormWidth)); + + cJSON *metaDataItem = nullptr; + if (!to_json(metaDataItem, abilityInfo.metaData)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metaData failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_META_DATA.c_str(), metaDataItem); + + cJSON_AddNumberToObject(jsonObject, JSON_KEY_BACKGROUND_MODES.c_str(), + static_cast(abilityInfo.backgroundModes)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_PACKAGE.c_str(), abilityInfo.package.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, abilityInfo.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, abilityInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_APPLICATION_NAME.c_str(), abilityInfo.applicationName.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_CODE_PATH.c_str(), abilityInfo.codePath.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_RESOURCE_PATH.c_str(), abilityInfo.resourcePath.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::HAP_PATH, abilityInfo.hapPath.c_str()); + cJSON_AddStringToObject(jsonObject, SRC_ENTRANCE.c_str(), abilityInfo.srcEntrance.c_str()); + + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, abilityInfo.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, META_DATA.c_str(), metadataItem); + + cJSON_AddBoolToObject(jsonObject, IS_MODULE_JSON.c_str(), abilityInfo.isModuleJson); + cJSON_AddBoolToObject(jsonObject, IS_STAGE_BASED_MODEL.c_str(), abilityInfo.isStageBasedModel); + cJSON_AddBoolToObject(jsonObject, CONTINUABLE.c_str(), abilityInfo.continuable); + cJSON_AddNumberToObject(jsonObject, PRIORITY.c_str(), static_cast(abilityInfo.priority)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_START_WINDOW.c_str(), abilityInfo.startWindow.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_START_WINDOW_ICON.c_str(), abilityInfo.startWindowIcon.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_START_WINDOW_ICON_ID.c_str(), + static_cast(abilityInfo.startWindowIconId)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_START_WINDOW_BACKGROUND.c_str(), + abilityInfo.startWindowBackground.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_START_WINDOW_BACKGROUND_ID.c_str(), + static_cast(abilityInfo.startWindowBackgroundId)); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE.c_str(), + abilityInfo.removeMissionAfterTerminate); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_COMPILE_MODE.c_str(), static_cast(abilityInfo.compileMode)); + + cJSON *windowModesItem = nullptr; + if (!to_json(windowModesItem, abilityInfo.windowModes)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json windowModes failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JOSN_KEY_SUPPORT_WINDOW_MODE.c_str(), windowModesItem); + + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MAX_WINDOW_WIDTH.c_str(), + static_cast(abilityInfo.maxWindowWidth)); + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MIN_WINDOW_WIDTH.c_str(), + static_cast(abilityInfo.minWindowWidth)); + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MAX_WINDOW_HEIGHT.c_str(), + static_cast(abilityInfo.maxWindowHeight)); + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MIN_WINDOW_HEIGHT.c_str(), + static_cast(abilityInfo.minWindowHeight)); + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_UID.c_str(), static_cast(abilityInfo.uid)); + cJSON_AddBoolToObject(jsonObject, JOSN_KEY_EXCLUDE_FROM_MISSIONS.c_str(), abilityInfo.excludeFromMissions); + cJSON_AddBoolToObject(jsonObject, JOSN_KEY_UNCLEARABLE_MISSION.c_str(), abilityInfo.unclearableMission); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_RECOVERABLE.c_str(), abilityInfo.recoverable); + + cJSON *supportExtNamesItem = nullptr; + if (!to_json(supportExtNamesItem, abilityInfo.supportExtNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json supportExtNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_SUPPORT_EXT_NAMES.c_str(), supportExtNamesItem); + + cJSON *supportMimeTypesItem = nullptr; + if (!to_json(supportMimeTypesItem, abilityInfo.supportMimeTypes)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json supportMimeTypes failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_SUPPORT_MIME_TYPES.c_str(), supportMimeTypesItem); + + cJSON_AddBoolToObject(jsonObject, JSON_KEY_ISOLATION_PROCESS.c_str(), abilityInfo.isolationProcess); + + cJSON *continueTypeItem = nullptr; + if (!to_json(continueTypeItem, abilityInfo.continueType)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json continueType failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_CONTINUE_TYPE.c_str(), continueTypeItem); + + cJSON *continueBundleNamesItem = nullptr; + if (!to_json(continueBundleNamesItem, abilityInfo.continueBundleNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json continueBundleNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_CONTINUE_BUNDLE_NAME.c_str(), continueBundleNamesItem); + + cJSON_AddNumberToObject(jsonObject, JSON_KEY_APP_INDEX.c_str(), static_cast(abilityInfo.appIndex)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_ORIENTATION_ID.c_str(), + static_cast(abilityInfo.orientationId)); + + cJSON *startWindowResourceItem = nullptr; + if (!to_json(startWindowResourceItem, abilityInfo.startWindowResource)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json startWindowResource failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_START_WINDOW_RESOURCE.c_str(), startWindowResourceItem); + + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MAX_WINDOW_RATIO.c_str(), + static_cast(abilityInfo.maxWindowRatio == 0 ? 0 : abilityInfo.maxWindowRatio)); + cJSON_AddNumberToObject(jsonObject, JOSN_KEY_MIN_WINDOW_RATIO.c_str(), + static_cast(abilityInfo.minWindowRatio == 0 ? 0 : abilityInfo.minWindowRatio)); } -void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData) +void from_json(const cJSON *jsonObject, CustomizeData &customizeData) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_NAME, - customizeData.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_META_VALUE, - customizeData.value, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_META_EXTRA, - customizeData.extra, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, JSON_KEY_NAME, customizeData.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_META_VALUE, customizeData.value, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_META_EXTRA, customizeData.extra, false, parseResult); } -void from_json(const nlohmann::json &jsonObject, MetaData &metaData) +void from_json(const cJSON *jsonObject, MetaData &metaData) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_CUSTOMIZE_DATA, - metaData.customizeData, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); + GetObjectValuesIfFindKey(jsonObject, JSON_KEY_CUSTOMIZE_DATA, metaData.customizeData, false, parseResult); } -void from_json(const nlohmann::json &jsonObject, Metadata &metadata) +void from_json(const cJSON *jsonObject, Metadata &metadata) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_VALUEID, - metadata.valueId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_NAME, - metadata.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_VALUE, - metadata.value, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_RESOURCE, - metadata.resource, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetNumberValueIfFindKey(jsonObject, META_DATA_VALUEID, metadata.valueId, false, parseResult); + GetStringValueIfFindKey(jsonObject, META_DATA_NAME, metadata.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, META_DATA_VALUE, metadata.value, false, parseResult); + GetStringValueIfFindKey(jsonObject, META_DATA_RESOURCE, metadata.resource, false, parseResult); if (parseResult != ERR_OK) { - TAG_LOGD( - AAFwkTag::ABILITY_SIM, "read Ability Metadata error:%{public}d", parseResult); + TAG_LOGD(AAFwkTag::ABILITY_SIM, "read Ability Metadata error:%{public}d", parseResult); } } -void from_json(const nlohmann::json &jsonObject, StartWindowResource &startWindowResource) +void from_json(const cJSON *jsonObject, StartWindowResource &startWindowResource) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_APP_ICON_ID, - startWindowResource.startWindowAppIconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_ILLUSTRATION_ID, - startWindowResource.startWindowIllustrationId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_BRANDING_IMAGE_ID, - startWindowResource.startWindowBrandingImageId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_BACKGROUND_COLOR_ID, - startWindowResource.startWindowBackgroundColorId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_BACKGROUND_IMAGE_ID, - startWindowResource.startWindowBackgroundImageId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - START_WINDOW_BACKGROUND_IMAGE_FIT, - startWindowResource.startWindowBackgroundImageFit, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - if (parseResult != ERR_OK) { - TAG_LOGD(AAFwkTag::ABILITY_SIM, "read Resource error:%{public}d", parseResult); - } + GetNumberValueIfFindKey(jsonObject, START_WINDOW_APP_ICON_ID, + startWindowResource.startWindowAppIconId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, START_WINDOW_ILLUSTRATION_ID, + startWindowResource.startWindowIllustrationId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, START_WINDOW_BRANDING_IMAGE_ID, + startWindowResource.startWindowBrandingImageId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, START_WINDOW_BACKGROUND_COLOR_ID, + startWindowResource.startWindowBackgroundColorId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, START_WINDOW_BACKGROUND_IMAGE_ID, + startWindowResource.startWindowBackgroundImageId, false, parseResult); + GetStringValueIfFindKey(jsonObject, START_WINDOW_BACKGROUND_IMAGE_FIT, + startWindowResource.startWindowBackgroundImageFit, false, parseResult); } -void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo) +void from_json(const cJSON *jsonObject, AbilityInfo &abilityInfo) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "called"); - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_NAME, - abilityInfo.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_LABEL, - abilityInfo.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_DESCRIPTION, - abilityInfo.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ICON_PATH, - abilityInfo.iconPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_LABEL_ID, - abilityInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_DESCRIPTION_ID, - abilityInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ICON_ID, - abilityInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_THEME, - abilityInfo.theme, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_VISIBLE, - abilityInfo.visible, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_KIND, - abilityInfo.kind, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_TYPE, - abilityInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_EXTENSION_ABILITY_TYPE, - abilityInfo.extensionAbilityType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ORIENTATION, - abilityInfo.orientation, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_LAUNCH_MODE, - abilityInfo.launchMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_SRC_PATH, - abilityInfo.srcPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_SRC_LANGUAGE, - abilityInfo.srcLanguage, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_PERMISSIONS, - abilityInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_PROCESS, - abilityInfo.process, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_DEVICE_TYPES, - abilityInfo.deviceTypes, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_DEVICE_CAPABILITIES, - abilityInfo.deviceCapabilities, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_URI, - abilityInfo.uri, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_TARGET_ABILITY, - abilityInfo.targetAbility, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_IS_LAUNCHER_ABILITY, - abilityInfo.isLauncherAbility, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_IS_NATIVE_ABILITY, - abilityInfo.isNativeAbility, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ENABLED, - abilityInfo.enabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_SUPPORT_PIP_MODE, - abilityInfo.supportPipMode, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_FORM_ENABLED, - abilityInfo.formEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_READ_PERMISSION, - abilityInfo.readPermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_WRITE_PERMISSION, - abilityInfo.writePermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_CONFIG_CHANGES, - abilityInfo.configChanges, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_FORM_ENTITY, - abilityInfo.formEntity, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_MIN_FORM_HEIGHT, - abilityInfo.minFormHeight, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_DEFAULT_FORM_HEIGHT, - abilityInfo.defaultFormHeight, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_MIN_FORM_WIDTH, - abilityInfo.minFormWidth, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_DEFAULT_FORM_WIDTH, - abilityInfo.defaultFormWidth, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_META_DATA, - abilityInfo.metaData, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_BACKGROUND_MODES, - abilityInfo.backgroundModes, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_PACKAGE, - abilityInfo.package, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - abilityInfo.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - abilityInfo.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_APPLICATION_NAME, - abilityInfo.applicationName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_CODE_PATH, - abilityInfo.codePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_RESOURCE_PATH, - abilityInfo.resourcePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::HAP_PATH, - abilityInfo.hapPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - abilityInfo.srcEntrance, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - abilityInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - IS_MODULE_JSON, - abilityInfo.isModuleJson, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - IS_STAGE_BASED_MODEL, - abilityInfo.isStageBasedModel, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - CONTINUABLE, - abilityInfo.continuable, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - abilityInfo.priority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_ICON, - abilityInfo.startWindowIcon, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_ICON_ID, - abilityInfo.startWindowIconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_BACKGROUND, - abilityInfo.startWindowBackground, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_BACKGROUND_ID, - abilityInfo.startWindowBackgroundId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE, - abilityInfo.removeMissionAfterTerminate, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_COMPILE_MODE, - abilityInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JOSN_KEY_SUPPORT_WINDOW_MODE, - abilityInfo.windowModes, - JsonType::ARRAY, - false, - parseResult, - ArrayType::NUMBER); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MAX_WINDOW_RATIO, - abilityInfo.maxWindowRatio, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MIN_WINDOW_RATIO, - abilityInfo.minWindowRatio, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MAX_WINDOW_WIDTH, - abilityInfo.maxWindowWidth, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MIN_WINDOW_WIDTH, - abilityInfo.minWindowWidth, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MAX_WINDOW_HEIGHT, - abilityInfo.maxWindowHeight, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_MIN_WINDOW_HEIGHT, - abilityInfo.minWindowHeight, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_UID, - abilityInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_EXCLUDE_FROM_MISSIONS, - abilityInfo.excludeFromMissions, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JOSN_KEY_UNCLEARABLE_MISSION, - abilityInfo.unclearableMission, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_RECOVERABLE, - abilityInfo.recoverable, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_SUPPORT_EXT_NAMES, - abilityInfo.supportExtNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_SUPPORT_MIME_TYPES, - abilityInfo.supportMimeTypes, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ISOLATION_PROCESS, - abilityInfo.isolationProcess, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_CONTINUE_TYPE, - abilityInfo.continueType, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_CONTINUE_BUNDLE_NAME, - abilityInfo.continueBundleNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_APP_INDEX, - abilityInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ORIENTATION_ID, - abilityInfo.orientationId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW, - abilityInfo.startWindow, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_ID, - abilityInfo.startWindowId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_START_WINDOW_RESOURCE, - abilityInfo.startWindowResource, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, JSON_KEY_NAME, abilityInfo.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_LABEL, abilityInfo.label, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_DESCRIPTION, abilityInfo.description, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_ICON_PATH, abilityInfo.iconPath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_LABEL_ID, abilityInfo.labelId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_DESCRIPTION_ID, abilityInfo.descriptionId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_ICON_ID, abilityInfo.iconId, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_THEME, abilityInfo.theme, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_VISIBLE, abilityInfo.visible, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_KIND, abilityInfo.kind, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_TYPE, abilityInfo.type, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_EXTENSION_ABILITY_TYPE, abilityInfo.extensionAbilityType, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_ORIENTATION, abilityInfo.orientation, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_LAUNCH_MODE, abilityInfo.launchMode, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_SRC_PATH, abilityInfo.srcPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_SRC_LANGUAGE, abilityInfo.srcLanguage, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_PERMISSIONS, abilityInfo.permissions, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_PROCESS, abilityInfo.process, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_DEVICE_TYPES, abilityInfo.deviceTypes, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_DEVICE_CAPABILITIES, abilityInfo.deviceCapabilities, false, + parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_URI, abilityInfo.uri, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_TARGET_ABILITY, abilityInfo.targetAbility, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_IS_LAUNCHER_ABILITY, abilityInfo.isLauncherAbility, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_IS_NATIVE_ABILITY, abilityInfo.isNativeAbility, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_ENABLED, abilityInfo.enabled, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_SUPPORT_PIP_MODE, abilityInfo.supportPipMode, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_FORM_ENABLED, abilityInfo.formEnabled, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_READ_PERMISSION, abilityInfo.readPermission, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_WRITE_PERMISSION, abilityInfo.writePermission, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_CONFIG_CHANGES, abilityInfo.configChanges, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_FORM_ENTITY, abilityInfo.formEntity, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_MIN_FORM_HEIGHT, abilityInfo.minFormHeight, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_DEFAULT_FORM_HEIGHT, abilityInfo.defaultFormHeight, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_MIN_FORM_WIDTH, abilityInfo.minFormWidth, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_DEFAULT_FORM_WIDTH, abilityInfo.defaultFormWidth, false, parseResult); + GetObjectValueIfFindKey(jsonObject, JSON_KEY_META_DATA, abilityInfo.metaData, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_BACKGROUND_MODES, abilityInfo.backgroundModes, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_PACKAGE, abilityInfo.package, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, abilityInfo.bundleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, abilityInfo.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_APPLICATION_NAME, abilityInfo.applicationName, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_CODE_PATH, abilityInfo.codePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_RESOURCE_PATH, abilityInfo.resourcePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::HAP_PATH, abilityInfo.hapPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, SRC_ENTRANCE, abilityInfo.srcEntrance, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, META_DATA, abilityInfo.metadata, false, parseResult); + GetBoolValueIfFindKey(jsonObject, IS_MODULE_JSON, abilityInfo.isModuleJson, false, parseResult); + GetBoolValueIfFindKey(jsonObject, IS_STAGE_BASED_MODEL, abilityInfo.isStageBasedModel, false, parseResult); + GetBoolValueIfFindKey(jsonObject, CONTINUABLE, abilityInfo.continuable, false, parseResult); + GetNumberValueIfFindKey(jsonObject, PRIORITY, abilityInfo.priority, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_ICON, abilityInfo.startWindowIcon, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_ICON_ID, abilityInfo.startWindowIconId, false, + parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_BACKGROUND, abilityInfo.startWindowBackground, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_BACKGROUND_ID, abilityInfo.startWindowBackgroundId, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE, abilityInfo.removeMissionAfterTerminate, + false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_COMPILE_MODE, abilityInfo.compileMode, false, parseResult); + GetNumberValuesIfFindKey(jsonObject, JOSN_KEY_SUPPORT_WINDOW_MODE, abilityInfo.windowModes, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MAX_WINDOW_RATIO, abilityInfo.maxWindowRatio, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MIN_WINDOW_RATIO, abilityInfo.minWindowRatio, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MAX_WINDOW_WIDTH, abilityInfo.maxWindowWidth, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MIN_WINDOW_WIDTH, abilityInfo.minWindowWidth, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MAX_WINDOW_HEIGHT, abilityInfo.maxWindowHeight, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_MIN_WINDOW_HEIGHT, abilityInfo.minWindowHeight, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JOSN_KEY_UID, abilityInfo.uid, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JOSN_KEY_EXCLUDE_FROM_MISSIONS, abilityInfo.excludeFromMissions, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, JOSN_KEY_UNCLEARABLE_MISSION, abilityInfo.unclearableMission, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_RECOVERABLE, abilityInfo.recoverable, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_SUPPORT_EXT_NAMES, abilityInfo.supportExtNames, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_SUPPORT_MIME_TYPES, abilityInfo.supportMimeTypes, false, parseResult); + GetBoolValueIfFindKey(jsonObject, JSON_KEY_ISOLATION_PROCESS, abilityInfo.isolationProcess, false, parseResult); + GetStringValuesIfFindKey(jsonObject, JSON_KEY_CONTINUE_TYPE, abilityInfo.continueType, false, parseResult); + GetUnorderedSetValuesIfFindKey(jsonObject, JSON_KEY_CONTINUE_BUNDLE_NAME, abilityInfo.continueBundleNames, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_APP_INDEX, abilityInfo.appIndex, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_ORIENTATION_ID, abilityInfo.orientationId, false, parseResult); + GetStringValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW, abilityInfo.startWindow, false, parseResult); + GetNumberValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_ID, abilityInfo.startWindowId, false, parseResult); + GetObjectValueIfFindKey(jsonObject, JSON_KEY_START_WINDOW_RESOURCE, abilityInfo.startWindowResource, false, + parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "AbilityInfo from_json error:%{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/application_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/application_info.cpp index 9c6a7be51a8fba309ed7b2b9fd0b4e1954bda30f..86949c906ae60359a810f54ef459e136057fbd26 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/application_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/application_info.cpp @@ -25,7 +25,6 @@ #include "hilog_tag_wrapper.h" #include "json_serializer.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -153,1246 +152,608 @@ const std::string HQF_INFO_TYPE = "type"; const std::string HQF_INFO_CPU_ABI = "cpuAbi"; const std::string HQF_INFO_NATIVE_LIBRARY_PATH = "nativeLibraryPath"; } -void to_json(nlohmann::json &jsonObject, const Resource &resource) + +bool to_json(cJSON *jsonObject, const Resource &resource) { - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, resource.bundleName}, - {Constants::MODULE_NAME, resource.moduleName}, - {RESOURCE_ID, resource.id} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, resource.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, resource.moduleName.c_str()); + cJSON_AddNumberToObject(jsonObject, RESOURCE_ID.c_str(), static_cast(resource.id)); + return true; } -void from_json(const nlohmann::json &jsonObject, Resource &resource) +void from_json(const cJSON *jsonObject, Resource &resource) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - resource.bundleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - resource.moduleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - RESOURCE_ID, - resource.id, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, resource.bundleName, true, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, resource.moduleName, true, parseResult); + GetNumberValueIfFindKey(jsonObject, RESOURCE_ID, resource.id, true, parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read Resource from database error,:%{public}d", parseResult); } } - -void to_json(nlohmann::json &jsonObject, const HnpPackage &hnpPackage) +bool to_json(cJSON *jsonObject, const HnpPackage &hnpPackage) { - jsonObject = nlohmann::json { - {APPLICATION_HNP_PACKAGES_PACKAGE, hnpPackage.package}, - {APPLICATION_HNP_PACKAGES_TYPE, hnpPackage.type}, - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, APPLICATION_HNP_PACKAGES_PACKAGE.c_str(), hnpPackage.package.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_HNP_PACKAGES_TYPE.c_str(), hnpPackage.type.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, HnpPackage &hnpPackage) +void from_json(const cJSON *jsonObject, HnpPackage &hnpPackage) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_HNP_PACKAGES_PACKAGE, - hnpPackage.package, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_HNP_PACKAGES_TYPE, - hnpPackage.type, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, APPLICATION_HNP_PACKAGES_PACKAGE, hnpPackage.package, true, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_HNP_PACKAGES_TYPE, hnpPackage.type, true, parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read Resource error %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const MultiAppModeData &multiAppMode) +bool to_json(cJSON *jsonObject, const MultiAppModeData &multiAppMode) { - jsonObject = nlohmann::json { - {APPLICATION_MULTI_APP_MODE_TYPE, multiAppMode.multiAppModeType}, - {APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER, multiAppMode.maxCount}, - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddNumberToObject(jsonObject, APPLICATION_MULTI_APP_MODE_TYPE.c_str(), + static_cast(multiAppMode.multiAppModeType)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER.c_str(), + static_cast(multiAppMode.maxCount)); + return true; } -void from_json(const nlohmann::json &jsonObject, MultiAppModeData &multiAppMode) +void from_json(const cJSON *jsonObject, MultiAppModeData &multiAppMode) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, jsonObjectEnd, APPLICATION_MULTI_APP_MODE_TYPE, - multiAppMode.multiAppModeType, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, jsonObjectEnd, APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER, - multiAppMode.maxCount, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY); + GetNumberValueIfFindKey(jsonObject, APPLICATION_MULTI_APP_MODE_TYPE, multiAppMode.multiAppModeType, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER, multiAppMode.maxCount, false, + parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "from_json error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const ApplicationEnvironment &applicationEnvironment) +bool to_json(cJSON *jsonObject, const ApplicationEnvironment &applicationEnvironment) { - jsonObject = nlohmann::json { - {APP_ENVIRONMENTS_NAME, applicationEnvironment.name}, - {APP_ENVIRONMENTS_VALUE, applicationEnvironment.value} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, APP_ENVIRONMENTS_NAME.c_str(), applicationEnvironment.name.c_str()); + cJSON_AddStringToObject(jsonObject, APP_ENVIRONMENTS_VALUE.c_str(), applicationEnvironment.value.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, ApplicationEnvironment &applicationEnvironment) +void from_json(const cJSON *jsonObject, ApplicationEnvironment &applicationEnvironment) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ENVIRONMENTS_NAME, - applicationEnvironment.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ENVIRONMENTS_VALUE, - applicationEnvironment.value, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, APP_ENVIRONMENTS_NAME, applicationEnvironment.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_ENVIRONMENTS_VALUE, applicationEnvironment.value, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read database error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const HqfInfo &hqfInfo) +bool to_json(cJSON *jsonObject, const HqfInfo &hqfInfo) { - jsonObject = nlohmann::json { - {Constants::MODULE_NAME, hqfInfo.moduleName}, - {HQF_INFO_HAP_SHA256, hqfInfo.hapSha256}, - {HQF_INFO_HQF_FILE_PATH, hqfInfo.hqfFilePath}, - {HQF_INFO_TYPE, hqfInfo.type}, - {HQF_INFO_CPU_ABI, hqfInfo.cpuAbi}, - {HQF_INFO_NATIVE_LIBRARY_PATH, hqfInfo.nativeLibraryPath} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, hqfInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, HQF_INFO_HAP_SHA256.c_str(), hqfInfo.hapSha256.c_str()); + cJSON_AddStringToObject(jsonObject, HQF_INFO_HQF_FILE_PATH.c_str(), hqfInfo.hqfFilePath.c_str()); + cJSON_AddNumberToObject(jsonObject, HQF_INFO_TYPE.c_str(), static_cast(hqfInfo.type)); + cJSON_AddStringToObject(jsonObject, HQF_INFO_CPU_ABI.c_str(), hqfInfo.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, HQF_INFO_NATIVE_LIBRARY_PATH.c_str(), hqfInfo.nativeLibraryPath.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, HqfInfo &hqfInfo) +void from_json(const cJSON *jsonObject, HqfInfo &hqfInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - hqfInfo.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HQF_INFO_HAP_SHA256, - hqfInfo.hapSha256, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HQF_INFO_HQF_FILE_PATH, - hqfInfo.hqfFilePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HQF_INFO_TYPE, - hqfInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HQF_INFO_CPU_ABI, - hqfInfo.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HQF_INFO_NATIVE_LIBRARY_PATH, - hqfInfo.nativeLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, hqfInfo.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, HQF_INFO_HAP_SHA256, hqfInfo.hapSha256, false, parseResult); + GetStringValueIfFindKey(jsonObject, HQF_INFO_HQF_FILE_PATH, hqfInfo.hqfFilePath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HQF_INFO_TYPE, hqfInfo.type, false, parseResult); + GetStringValueIfFindKey(jsonObject, HQF_INFO_CPU_ABI, hqfInfo.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, HQF_INFO_NATIVE_LIBRARY_PATH, hqfInfo.nativeLibraryPath, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module hqfInfo from jsonObject error, error code : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const AppqfInfo &appqfInfo) +bool to_json(cJSON *jsonObject, const AppqfInfo &appqfInfo) { - jsonObject = nlohmann::json { - {APP_QF_INFO_VERSION_CODE, appqfInfo.versionCode}, - {APP_QF_INFO_VERSION_NAME, appqfInfo.versionName}, - {APP_QF_INFO_CPU_ABI, appqfInfo.cpuAbi}, - {APP_QF_INFO_NATIVE_LIBRARY_PATH, appqfInfo.nativeLibraryPath}, - {APP_QF_INFO_TYPE, appqfInfo.type}, - {APP_QF_INFO_HQF_INFOS, appqfInfo.hqfInfos} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddNumberToObject(jsonObject, APP_QF_INFO_VERSION_CODE.c_str(), static_cast(appqfInfo.versionCode)); + cJSON_AddStringToObject(jsonObject, APP_QF_INFO_VERSION_NAME.c_str(), appqfInfo.versionName.c_str()); + cJSON_AddStringToObject(jsonObject, APP_QF_INFO_CPU_ABI.c_str(), appqfInfo.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, APP_QF_INFO_NATIVE_LIBRARY_PATH.c_str(), appqfInfo.nativeLibraryPath.c_str()); + cJSON_AddNumberToObject(jsonObject, APP_QF_INFO_TYPE.c_str(), static_cast(appqfInfo.type)); + cJSON *hqfInfosItem = nullptr; + if (!to_json(hqfInfosItem, appqfInfo.hqfInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json hqfInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APP_QF_INFO_HQF_INFOS.c_str(), hqfInfosItem); + return true; } -void from_json(const nlohmann::json &jsonObject, AppqfInfo &appqfInfo) +void from_json(const cJSON *jsonObject, AppqfInfo &appqfInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QF_INFO_VERSION_CODE, - appqfInfo.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QF_INFO_VERSION_NAME, - appqfInfo.versionName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QF_INFO_CPU_ABI, - appqfInfo.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QF_INFO_NATIVE_LIBRARY_PATH, - appqfInfo.nativeLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QF_INFO_TYPE, - appqfInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APP_QF_INFO_HQF_INFOS, - appqfInfo.hqfInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); + GetNumberValueIfFindKey(jsonObject, APP_QF_INFO_VERSION_CODE, appqfInfo.versionCode, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_QF_INFO_VERSION_NAME, appqfInfo.versionName, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_QF_INFO_CPU_ABI, appqfInfo.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_QF_INFO_NATIVE_LIBRARY_PATH, appqfInfo.nativeLibraryPath, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APP_QF_INFO_TYPE, appqfInfo.type, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, APP_QF_INFO_HQF_INFOS, appqfInfo.hqfInfos, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module appqfInfo from jsonObject error, error code : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const AppQuickFix &appQuickFix) +bool to_json(cJSON *jsonObject, const AppQuickFix &appQuickFix) { - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, appQuickFix.bundleName}, - {APP_QUICK_FIX_VERSION_CODE, appQuickFix.versionCode}, - {APP_QUICK_FIX_VERSION_NAME, appQuickFix.versionName}, - {APP_QUICK_FIX_DEPLOYED_APP_QF_INFO, appQuickFix.deployedAppqfInfo}, - {APP_QUICK_FIX_DEPLOYING_APP_QF_INFO, appQuickFix.deployingAppqfInfo} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, appQuickFix.bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, APP_QUICK_FIX_VERSION_CODE.c_str(), + static_cast(appQuickFix.versionCode)); + cJSON_AddStringToObject(jsonObject, APP_QUICK_FIX_VERSION_NAME.c_str(), appQuickFix.versionName.c_str()); + + cJSON *deployedAppqfInfoItem = nullptr; + if (!to_json(deployedAppqfInfoItem, appQuickFix.deployedAppqfInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deployedAppqfInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APP_QUICK_FIX_DEPLOYED_APP_QF_INFO.c_str(), deployedAppqfInfoItem); + + cJSON *deployingAppqfInfoItem = nullptr; + if (!to_json(deployingAppqfInfoItem, appQuickFix.deployingAppqfInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deployingAppqfInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APP_QUICK_FIX_DEPLOYING_APP_QF_INFO.c_str(), deployingAppqfInfoItem); + return true; } -void from_json(const nlohmann::json &jsonObject, AppQuickFix &appQuickFix) +void from_json(const cJSON *jsonObject, AppQuickFix &appQuickFix) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - appQuickFix.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QUICK_FIX_VERSION_CODE, - appQuickFix.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QUICK_FIX_VERSION_NAME, - appQuickFix.versionName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QUICK_FIX_DEPLOYED_APP_QF_INFO, - appQuickFix.deployedAppqfInfo, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_QUICK_FIX_DEPLOYING_APP_QF_INFO, - appQuickFix.deployingAppqfInfo, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, appQuickFix.bundleName, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APP_QUICK_FIX_VERSION_CODE, appQuickFix.versionCode, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_QUICK_FIX_VERSION_NAME, appQuickFix.versionName, false, parseResult); + GetObjectValueIfFindKey(jsonObject, APP_QUICK_FIX_DEPLOYED_APP_QF_INFO, appQuickFix.deployedAppqfInfo, false, + parseResult); + GetObjectValueIfFindKey(jsonObject, APP_QUICK_FIX_DEPLOYING_APP_QF_INFO, appQuickFix.deployingAppqfInfo, false, + parseResult); if (parseResult != ERR_OK) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module appQuickFix from jsonObject error, error code : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo) +bool to_json(cJSON *jsonObject, const ApplicationInfo &applicationInfo) { - jsonObject = nlohmann::json { - {APPLICATION_NAME, applicationInfo.name}, - {Constants::BUNDLE_NAME, applicationInfo.bundleName}, - {APPLICATION_VERSION_CODE, applicationInfo.versionCode}, - {APPLICATION_VERSION_NAME, applicationInfo.versionName}, - {APPLICATION_MIN_COMPATIBLE_VERSION_CODE, applicationInfo.minCompatibleVersionCode}, - {APPLICATION_API_COMPATIBLE_VERSION, applicationInfo.apiCompatibleVersion}, - {APPLICATION_API_TARGET_VERSION, applicationInfo.apiTargetVersion}, - {APPLICATION_ICON_PATH, applicationInfo.iconPath}, - {APPLICATION_ICON_ID, applicationInfo.iconId}, - {APPLICATION_LABEL, applicationInfo.label}, - {APPLICATION_LABEL_ID, applicationInfo.labelId}, - {APPLICATION_DESCRIPTION, applicationInfo.description}, - {APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId}, - {APPLICATION_KEEP_ALIVE, applicationInfo.keepAlive}, - {APPLICATION_REMOVABLE, applicationInfo.removable}, - {APPLICATION_SINGLETON, applicationInfo.singleton}, - {APPLICATION_USER_DATA_CLEARABLE, applicationInfo.userDataClearable}, - {ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED, applicationInfo.allowAppRunWhenDeviceFirstLocked}, - {APPLICATION_ACCESSIBLE, applicationInfo.accessible}, - {APPLICATION_IS_SYSTEM_APP, applicationInfo.isSystemApp}, - {APPLICATION_IS_LAUNCHER_APP, applicationInfo.isLauncherApp}, - {APPLICATION_IS_FREEINSTALL_APP, applicationInfo.isFreeInstallApp}, - {APPLICATION_RUNNING_RESOURCES_APPLY, applicationInfo.runningResourcesApply}, - {APPLICATION_ASSOCIATED_WAKE_UP, applicationInfo.associatedWakeUp}, - {APPLICATION_HIDE_DESKTOP_ICON, applicationInfo.hideDesktopIcon}, - {APPLICATION_FORM_VISIBLE_NOTIFY, applicationInfo.formVisibleNotify}, - {APPLICATION_ALLOW_COMMON_EVENT, applicationInfo.allowCommonEvent}, - {APPLICATION_CODE_PATH, applicationInfo.codePath}, - {APPLICATION_DATA_DIR, applicationInfo.dataDir}, - {APPLICATION_DATA_BASE_DIR, applicationInfo.dataBaseDir}, - {APPLICATION_CACHE_DIR, applicationInfo.cacheDir}, - {APPLICATION_ENTRY_DIR, applicationInfo.entryDir}, - {APPLICATION_API_RELEASETYPE, applicationInfo.apiReleaseType}, - {APPLICATION_DEBUG, applicationInfo.debug}, - {APPLICATION_DEVICE_ID, applicationInfo.deviceId}, - {APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, applicationInfo.distributedNotificationEnabled}, - {APPLICATION_INSTALLED_FOR_ALL_USER, applicationInfo.installedForAllUser}, - {APPLICATION_ALLOW_ENABLE_NOTIFICATION, applicationInfo.allowEnableNotification}, - {APPLICATION_ENTITY_TYPE, applicationInfo.entityType}, - {APPLICATION_PROCESS, applicationInfo.process}, - {APPLICATION_SUPPORTED_MODES, applicationInfo.supportedModes}, - {APPLICATION_VENDOR, applicationInfo.vendor}, - {APPLICATION_PRIVILEGE_LEVEL, applicationInfo.appPrivilegeLevel}, - {APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId}, - {APPLICATION_ACCESSTOKEN_ID_EX, applicationInfo.accessTokenIdEx}, - {APPLICATION_ENABLED, applicationInfo.enabled}, - {APPLICATION_UID, applicationInfo.uid}, - {APPLICATION_PERMISSIONS, applicationInfo.permissions}, - {APPLICATION_MODULE_SOURCE_DIRS, applicationInfo.moduleSourceDirs}, - {APPLICATION_MODULE_INFOS, applicationInfo.moduleInfos}, - {APPLICATION_META_DATA_CONFIG_JSON, applicationInfo.metaData}, - {APPLICATION_META_DATA_MODULE_JSON, applicationInfo.metadata}, - {APPLICATION_FINGERPRINT, applicationInfo.fingerprint}, - {APPLICATION_ICON, applicationInfo.icon}, - {APPLICATION_FLAGS, applicationInfo.flags}, - {APPLICATION_ENTRY_MODULE_NAME, applicationInfo.entryModuleName}, - {APPLICATION_NATIVE_LIBRARY_PATH, applicationInfo.nativeLibraryPath}, - {APPLICATION_CPU_ABI, applicationInfo.cpuAbi}, - {APPLICATION_ARK_NATIVE_FILE_PATH, applicationInfo.arkNativeFilePath}, - {APPLICATION_ARK_NATIVE_FILE_ABI, applicationInfo.arkNativeFileAbi}, - {APPLICATION_IS_COMPRESS_NATIVE_LIBS, applicationInfo.isCompressNativeLibs}, - {APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey}, - {APPLICATION_TARGETBUNDLELIST, applicationInfo.targetBundleList}, - {APPLICATION_APP_DISTRIBUTION_TYPE, applicationInfo.appDistributionType}, - {APPLICATION_APP_PROVISION_TYPE, applicationInfo.appProvisionType}, - {APPLICATION_ICON_RESOURCE, applicationInfo.iconResource}, - {APPLICATION_LABEL_RESOURCE, applicationInfo.labelResource}, - {APPLICATION_DESCRIPTION_RESOURCE, applicationInfo.descriptionResource}, - {APPLICATION_MULTI_PROJECTS, applicationInfo.multiProjects}, - {APPLICATION_CROWDTEST_DEADLINE, applicationInfo.crowdtestDeadline}, - {APPLICATION_NEED_APP_DETAIL, applicationInfo.needAppDetail}, - {APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH, applicationInfo.appDetailAbilityLibraryPath}, - {APPLICATION_APP_TARGET_BUNDLE_NAME, applicationInfo.targetBundleName}, - {APPLICATION_APP_TARGET_PRIORITY, applicationInfo.targetPriority}, - {APPLICATION_APP_OVERLAY_STATE, applicationInfo.overlayState}, - {APPLICATION_ASAN_ENABLED, applicationInfo.asanEnabled}, - {APPLICATION_ASAN_LOG_PATH, applicationInfo.asanLogPath}, - {APPLICATION_APP_TYPE, applicationInfo.bundleType}, - {APPLICATION_COMPILE_SDK_VERSION, applicationInfo.compileSdkVersion}, - {APPLICATION_COMPILE_SDK_TYPE, applicationInfo.compileSdkType}, - {APPLICATION_RESOURCES_APPLY, applicationInfo.resourcesApply}, - {APPLICATION_GWP_ASAN_ENABLED, applicationInfo.gwpAsanEnabled}, - {APPLICATION_HWASAN_ENABLED, applicationInfo.hwasanEnabled}, - {APPLICATION_RESERVED_FLAG, applicationInfo.applicationReservedFlag}, - {APPLICATION_TSAN_ENABLED, applicationInfo.tsanEnabled}, - {APPLICATION_APP_ENVIRONMENTS, applicationInfo.appEnvironments}, - {APPLICATION_ORGANIZATION, applicationInfo.organization}, - {APPLICATION_MULTI_APP_MODE, applicationInfo.multiAppMode}, - {APPLICATION_MAX_CHILD_PROCESS, applicationInfo.maxChildProcess}, - {APPLICATION_APP_INDEX, applicationInfo.appIndex}, - {APPLICATION_INSTALL_SOURCE, applicationInfo.installSource}, - {APPLICATION_CONFIGURATION, applicationInfo.configuration}, - {APPLICATION_CLOUD_FILE_SYNC_ENABLED, applicationInfo.cloudFileSyncEnabled}, - {APPLICATION_APPLICATION_FLAGS, applicationInfo.applicationFlags}, - {APPLICATION_UBSAN_ENABLED, applicationInfo.ubsanEnabled}, - {APPLICATION_ALLOW_MULTI_PROCESS, applicationInfo.allowMultiProcess}, - {APPLICATION_ASSET_ACCESS_GROUPS, applicationInfo.assetAccessGroups}, - {APPLICATION_HAS_PLUGIN, applicationInfo.hasPlugin} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, APPLICATION_NAME.c_str(), applicationInfo.name.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, applicationInfo.bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_VERSION_CODE.c_str(), + static_cast(applicationInfo.versionCode)); + cJSON_AddStringToObject(jsonObject, APPLICATION_VERSION_NAME.c_str(), applicationInfo.versionName.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_MIN_COMPATIBLE_VERSION_CODE.c_str(), + static_cast(applicationInfo.minCompatibleVersionCode)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_API_COMPATIBLE_VERSION.c_str(), + static_cast(applicationInfo.apiCompatibleVersion)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_API_TARGET_VERSION.c_str(), + static_cast(applicationInfo.apiTargetVersion)); + cJSON_AddStringToObject(jsonObject, APPLICATION_ICON_PATH.c_str(), applicationInfo.iconPath.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_ICON_ID.c_str(), static_cast(applicationInfo.iconId)); + cJSON_AddStringToObject(jsonObject, APPLICATION_LABEL.c_str(), applicationInfo.label.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_LABEL_ID.c_str(), static_cast(applicationInfo.labelId)); + cJSON_AddStringToObject(jsonObject, APPLICATION_DESCRIPTION.c_str(), applicationInfo.description.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_DESCRIPTION_ID.c_str(), + static_cast(applicationInfo.descriptionId)); + cJSON_AddBoolToObject(jsonObject, APPLICATION_KEEP_ALIVE.c_str(), applicationInfo.keepAlive); + cJSON_AddBoolToObject(jsonObject, APPLICATION_REMOVABLE.c_str(), applicationInfo.removable); + cJSON_AddBoolToObject(jsonObject, APPLICATION_SINGLETON.c_str(), applicationInfo.singleton); + cJSON_AddBoolToObject(jsonObject, APPLICATION_USER_DATA_CLEARABLE.c_str(), applicationInfo.userDataClearable); + cJSON_AddBoolToObject(jsonObject, ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED.c_str(), + applicationInfo.allowAppRunWhenDeviceFirstLocked); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ACCESSIBLE.c_str(), applicationInfo.accessible); + cJSON_AddBoolToObject(jsonObject, APPLICATION_IS_SYSTEM_APP.c_str(), applicationInfo.isSystemApp); + cJSON_AddBoolToObject(jsonObject, APPLICATION_IS_LAUNCHER_APP.c_str(), applicationInfo.isLauncherApp); + cJSON_AddBoolToObject(jsonObject, APPLICATION_IS_FREEINSTALL_APP.c_str(), applicationInfo.isFreeInstallApp); + cJSON_AddBoolToObject(jsonObject, APPLICATION_RUNNING_RESOURCES_APPLY.c_str(), + applicationInfo.runningResourcesApply); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ASSOCIATED_WAKE_UP.c_str(), applicationInfo.associatedWakeUp); + cJSON_AddBoolToObject(jsonObject, APPLICATION_HIDE_DESKTOP_ICON.c_str(), applicationInfo.hideDesktopIcon); + cJSON_AddBoolToObject(jsonObject, APPLICATION_FORM_VISIBLE_NOTIFY.c_str(), applicationInfo.formVisibleNotify); + + cJSON *allowCommonEventItem = nullptr; + if (!to_json(allowCommonEventItem, applicationInfo.allowCommonEvent)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json allowCommonEvent failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_ALLOW_COMMON_EVENT.c_str(), allowCommonEventItem); + + cJSON_AddStringToObject(jsonObject, APPLICATION_CODE_PATH.c_str(), applicationInfo.codePath.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_DATA_DIR.c_str(), applicationInfo.dataDir.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_DATA_BASE_DIR.c_str(), applicationInfo.dataBaseDir.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_CACHE_DIR.c_str(), applicationInfo.cacheDir.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_ENTRY_DIR.c_str(), applicationInfo.entryDir.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_API_RELEASETYPE.c_str(), applicationInfo.apiReleaseType.c_str()); + cJSON_AddBoolToObject(jsonObject, APPLICATION_DEBUG.c_str(), applicationInfo.debug); + cJSON_AddStringToObject(jsonObject, APPLICATION_DEVICE_ID.c_str(), applicationInfo.deviceId.c_str()); + cJSON_AddBoolToObject(jsonObject, APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED.c_str(), + applicationInfo.distributedNotificationEnabled); + cJSON_AddBoolToObject(jsonObject, APPLICATION_INSTALLED_FOR_ALL_USER.c_str(), applicationInfo.installedForAllUser); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ALLOW_ENABLE_NOTIFICATION.c_str(), + applicationInfo.allowEnableNotification); + cJSON_AddStringToObject(jsonObject, APPLICATION_ENTITY_TYPE.c_str(), applicationInfo.entityType.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_PROCESS.c_str(), applicationInfo.process.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_SUPPORTED_MODES.c_str(), + static_cast(applicationInfo.supportedModes)); + cJSON_AddStringToObject(jsonObject, APPLICATION_VENDOR.c_str(), applicationInfo.vendor.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_PRIVILEGE_LEVEL.c_str(), applicationInfo.appPrivilegeLevel.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_ACCESSTOKEN_ID.c_str(), + static_cast(applicationInfo.accessTokenId)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_ACCESSTOKEN_ID_EX.c_str(), + static_cast(applicationInfo.accessTokenIdEx)); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ENABLED.c_str(), applicationInfo.enabled); + cJSON_AddNumberToObject(jsonObject, APPLICATION_UID.c_str(), static_cast(applicationInfo.uid)); + + cJSON *permissionsItem = nullptr; + if (!to_json(permissionsItem, applicationInfo.permissions)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json permissions failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_PERMISSIONS.c_str(), permissionsItem); + + cJSON *moduleSourceDirsItem = nullptr; + if (!to_json(moduleSourceDirsItem, applicationInfo.moduleSourceDirs)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleSourceDirs failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_MODULE_SOURCE_DIRS.c_str(), moduleSourceDirsItem); + + cJSON *moduleInfosItem = nullptr; + if (!to_json(moduleInfosItem, applicationInfo.moduleInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_MODULE_INFOS.c_str(), moduleInfosItem); + + cJSON *metaDataItem = nullptr; + if (!to_json(metaDataItem, applicationInfo.metaData)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metaData failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_META_DATA_CONFIG_JSON.c_str(), metaDataItem); + + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, applicationInfo.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_META_DATA_MODULE_JSON.c_str(), metadataItem); + + cJSON_AddStringToObject(jsonObject, APPLICATION_FINGERPRINT.c_str(), applicationInfo.fingerprint.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_ICON.c_str(), applicationInfo.icon.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_FLAGS.c_str(), static_cast(applicationInfo.flags)); + cJSON_AddStringToObject(jsonObject, APPLICATION_ENTRY_MODULE_NAME.c_str(), applicationInfo.entryModuleName.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_NATIVE_LIBRARY_PATH.c_str(), + applicationInfo.nativeLibraryPath.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_CPU_ABI.c_str(), applicationInfo.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_ARK_NATIVE_FILE_PATH.c_str(), + applicationInfo.arkNativeFilePath.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_ARK_NATIVE_FILE_ABI.c_str(), + applicationInfo.arkNativeFileAbi.c_str()); + cJSON_AddBoolToObject(jsonObject, APPLICATION_IS_COMPRESS_NATIVE_LIBS.c_str(), + applicationInfo.isCompressNativeLibs); + cJSON_AddStringToObject(jsonObject, APPLICATION_SIGNATURE_KEY.c_str(), applicationInfo.signatureKey.c_str()); + + cJSON *targetBundleListItem = nullptr; + if (!to_json(targetBundleListItem, applicationInfo.targetBundleList)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json targetBundleList failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_TARGETBUNDLELIST.c_str(), targetBundleListItem); + + cJSON_AddStringToObject(jsonObject, APPLICATION_APP_DISTRIBUTION_TYPE.c_str(), + applicationInfo.appDistributionType.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_APP_PROVISION_TYPE.c_str(), + applicationInfo.appProvisionType.c_str()); + + cJSON *iconResourceItem = nullptr; + if (!to_json(iconResourceItem, applicationInfo.iconResource)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json iconResource failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_ICON_RESOURCE.c_str(), iconResourceItem); + + cJSON *labelResourceItem = nullptr; + if (!to_json(labelResourceItem, applicationInfo.labelResource)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json labelResource failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_LABEL_RESOURCE.c_str(), labelResourceItem); + + cJSON *descriptionResourceItem = nullptr; + if (!to_json(descriptionResourceItem, applicationInfo.descriptionResource)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json descriptionResource failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_DESCRIPTION_RESOURCE.c_str(), descriptionResourceItem); + + cJSON_AddBoolToObject(jsonObject, APPLICATION_MULTI_PROJECTS.c_str(), applicationInfo.multiProjects); + cJSON_AddNumberToObject(jsonObject, APPLICATION_CROWDTEST_DEADLINE.c_str(), + static_cast(applicationInfo.crowdtestDeadline)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_NEED_APP_DETAIL.c_str(), + static_cast(applicationInfo.needAppDetail)); + cJSON_AddStringToObject(jsonObject, APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH.c_str(), + applicationInfo.appDetailAbilityLibraryPath.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_APP_TARGET_BUNDLE_NAME.c_str(), + applicationInfo.targetBundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_APP_TARGET_PRIORITY.c_str(), + static_cast(applicationInfo.targetPriority)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_APP_OVERLAY_STATE.c_str(), + static_cast(applicationInfo.overlayState)); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ASAN_ENABLED.c_str(), applicationInfo.asanEnabled); + cJSON_AddStringToObject(jsonObject, APPLICATION_ASAN_LOG_PATH.c_str(), applicationInfo.asanLogPath.c_str()); + cJSON_AddNumberToObject(jsonObject, APPLICATION_APP_TYPE.c_str(), static_cast(applicationInfo.bundleType)); + cJSON_AddStringToObject(jsonObject, APPLICATION_COMPILE_SDK_VERSION.c_str(), + applicationInfo.compileSdkVersion.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_COMPILE_SDK_TYPE.c_str(), applicationInfo.compileSdkType.c_str()); + + cJSON *resourcesApplyItem = nullptr; + if (!to_json(resourcesApplyItem, applicationInfo.resourcesApply)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json resourcesApply failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_RESOURCES_APPLY.c_str(), resourcesApplyItem); + + cJSON_AddBoolToObject(jsonObject, APPLICATION_GWP_ASAN_ENABLED.c_str(), applicationInfo.gwpAsanEnabled); + cJSON_AddBoolToObject(jsonObject, APPLICATION_HWASAN_ENABLED.c_str(), applicationInfo.hwasanEnabled); + cJSON_AddNumberToObject(jsonObject, APPLICATION_RESERVED_FLAG.c_str(), + static_cast(applicationInfo.applicationReservedFlag)); + cJSON_AddBoolToObject(jsonObject, APPLICATION_TSAN_ENABLED.c_str(), applicationInfo.tsanEnabled); + + cJSON *appEnvironmentsItem = nullptr; + if (!to_json(appEnvironmentsItem, applicationInfo.appEnvironments)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json appEnvironments failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_APP_ENVIRONMENTS.c_str(), appEnvironmentsItem); + + cJSON_AddStringToObject(jsonObject, APPLICATION_ORGANIZATION.c_str(), applicationInfo.organization.c_str()); + + cJSON *multiAppModeItem = nullptr; + if (!to_json(multiAppModeItem, applicationInfo.multiAppMode)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json multiAppMode failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_MULTI_APP_MODE.c_str(), multiAppModeItem); + + cJSON_AddNumberToObject(jsonObject, APPLICATION_MAX_CHILD_PROCESS.c_str(), + static_cast(applicationInfo.maxChildProcess)); + cJSON_AddNumberToObject(jsonObject, APPLICATION_APP_INDEX.c_str(), static_cast(applicationInfo.appIndex)); + cJSON_AddStringToObject(jsonObject, APPLICATION_INSTALL_SOURCE.c_str(), applicationInfo.installSource.c_str()); + cJSON_AddStringToObject(jsonObject, APPLICATION_CONFIGURATION.c_str(), applicationInfo.configuration.c_str()); + cJSON_AddBoolToObject(jsonObject, APPLICATION_CLOUD_FILE_SYNC_ENABLED.c_str(), + applicationInfo.cloudFileSyncEnabled); + cJSON_AddNumberToObject(jsonObject, APPLICATION_APPLICATION_FLAGS.c_str(), + static_cast(applicationInfo.applicationFlags)); + cJSON_AddBoolToObject(jsonObject, APPLICATION_UBSAN_ENABLED.c_str(), applicationInfo.ubsanEnabled); + cJSON_AddBoolToObject(jsonObject, APPLICATION_ALLOW_MULTI_PROCESS.c_str(), applicationInfo.allowMultiProcess); + + cJSON *assetAccessGroupsItem = nullptr; + if (!to_json(assetAccessGroupsItem, applicationInfo.assetAccessGroups)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json assetAccessGroups failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, APPLICATION_ASSET_ACCESS_GROUPS.c_str(), assetAccessGroupsItem); + + cJSON_AddBoolToObject(jsonObject, APPLICATION_HAS_PLUGIN.c_str(), applicationInfo.hasPlugin); + + return true; } -void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInfo) +void from_json(const cJSON *jsonObject, ApplicationInfo &applicationInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_NAME, - applicationInfo.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - applicationInfo.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_VERSION_CODE, - applicationInfo.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_VERSION_NAME, - applicationInfo.versionName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_MIN_COMPATIBLE_VERSION_CODE, - applicationInfo.minCompatibleVersionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_API_COMPATIBLE_VERSION, - applicationInfo.apiCompatibleVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_API_TARGET_VERSION, - applicationInfo.apiTargetVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ICON_PATH, - applicationInfo.iconPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ICON_ID, - applicationInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_LABEL, - applicationInfo.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_LABEL_ID, - applicationInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DESCRIPTION, - applicationInfo.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DESCRIPTION_ID, - applicationInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_KEEP_ALIVE, - applicationInfo.keepAlive, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_REMOVABLE, - applicationInfo.removable, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_SINGLETON, - applicationInfo.singleton, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_USER_DATA_CLEARABLE, - applicationInfo.userDataClearable, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED, - applicationInfo.allowAppRunWhenDeviceFirstLocked, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ACCESSIBLE, - applicationInfo.accessible, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_IS_SYSTEM_APP, - applicationInfo.isSystemApp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_IS_LAUNCHER_APP, - applicationInfo.isLauncherApp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_IS_FREEINSTALL_APP, - applicationInfo.isFreeInstallApp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_RUNNING_RESOURCES_APPLY, - applicationInfo.runningResourcesApply, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ASSOCIATED_WAKE_UP, - applicationInfo.associatedWakeUp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_HIDE_DESKTOP_ICON, - applicationInfo.hideDesktopIcon, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_FORM_VISIBLE_NOTIFY, - applicationInfo.formVisibleNotify, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_ALLOW_COMMON_EVENT, - applicationInfo.allowCommonEvent, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CODE_PATH, - applicationInfo.codePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DATA_DIR, - applicationInfo.dataDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DATA_BASE_DIR, - applicationInfo.dataBaseDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CACHE_DIR, - applicationInfo.cacheDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ENTRY_DIR, - applicationInfo.entryDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_API_RELEASETYPE, - applicationInfo.apiReleaseType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DEBUG, - applicationInfo.debug, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DEVICE_ID, - applicationInfo.deviceId, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, - applicationInfo.distributedNotificationEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_INSTALLED_FOR_ALL_USER, - applicationInfo.installedForAllUser, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ALLOW_ENABLE_NOTIFICATION, - applicationInfo.allowEnableNotification, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ENTITY_TYPE, - applicationInfo.entityType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_PROCESS, - applicationInfo.process, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_SUPPORTED_MODES, - applicationInfo.supportedModes, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_VENDOR, - applicationInfo.vendor, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_PRIVILEGE_LEVEL, - applicationInfo.appPrivilegeLevel, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ACCESSTOKEN_ID, - applicationInfo.accessTokenId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ACCESSTOKEN_ID_EX, - applicationInfo.accessTokenIdEx, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ENABLED, - applicationInfo.enabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_UID, - applicationInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_PERMISSIONS, - applicationInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_MODULE_SOURCE_DIRS, - applicationInfo.moduleSourceDirs, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_MODULE_INFOS, - applicationInfo.moduleInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>>(jsonObject, - jsonObjectEnd, - APPLICATION_META_DATA_CONFIG_JSON, - applicationInfo.metaData, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>>(jsonObject, - jsonObjectEnd, - APPLICATION_META_DATA_MODULE_JSON, - applicationInfo.metadata, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_FINGERPRINT, - applicationInfo.fingerprint, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ICON, - applicationInfo.icon, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_FLAGS, - applicationInfo.flags, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ENTRY_MODULE_NAME, - applicationInfo.entryModuleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_NATIVE_LIBRARY_PATH, - applicationInfo.nativeLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CPU_ABI, - applicationInfo.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ARK_NATIVE_FILE_PATH, - applicationInfo.arkNativeFilePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ARK_NATIVE_FILE_ABI, - applicationInfo.arkNativeFileAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_IS_COMPRESS_NATIVE_LIBS, - applicationInfo.isCompressNativeLibs, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_SIGNATURE_KEY, - applicationInfo.signatureKey, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_TARGETBUNDLELIST, - applicationInfo.targetBundleList, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_DISTRIBUTION_TYPE, - applicationInfo.appDistributionType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_PROVISION_TYPE, - applicationInfo.appProvisionType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ICON_RESOURCE, - applicationInfo.iconResource, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_LABEL_RESOURCE, - applicationInfo.labelResource, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_DESCRIPTION_RESOURCE, - applicationInfo.descriptionResource, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_MULTI_PROJECTS, - applicationInfo.multiProjects, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CROWDTEST_DEADLINE, - applicationInfo.crowdtestDeadline, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_QUICK_FIX, - applicationInfo.appQuickFix, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_NEED_APP_DETAIL, - applicationInfo.needAppDetail, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH, - applicationInfo.appDetailAbilityLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_TARGET_BUNDLE_NAME, - applicationInfo.targetBundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_TARGET_PRIORITY, - applicationInfo.targetPriority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_OVERLAY_STATE, - applicationInfo.overlayState, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ASAN_ENABLED, - applicationInfo.asanEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ASAN_LOG_PATH, - applicationInfo.asanLogPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_TYPE, - applicationInfo.bundleType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_COMPILE_SDK_VERSION, - applicationInfo.compileSdkVersion, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_COMPILE_SDK_TYPE, - applicationInfo.compileSdkType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_RESOURCES_APPLY, - applicationInfo.resourcesApply, - JsonType::ARRAY, - false, - parseResult, - ArrayType::NUMBER); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_GWP_ASAN_ENABLED, - applicationInfo.gwpAsanEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_RESERVED_FLAG, - applicationInfo.applicationReservedFlag, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_TSAN_ENABLED, - applicationInfo.tsanEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ORGANIZATION, - applicationInfo.organization, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_APP_ENVIRONMENTS, - applicationInfo.appEnvironments, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_MULTI_APP_MODE, - applicationInfo.multiAppMode, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APP_INDEX, - applicationInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_MAX_CHILD_PROCESS, - applicationInfo.maxChildProcess, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_INSTALL_SOURCE, - applicationInfo.installSource, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_HWASAN_ENABLED, - applicationInfo.hwasanEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CONFIGURATION, - applicationInfo.configuration, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_CLOUD_FILE_SYNC_ENABLED, - applicationInfo.cloudFileSyncEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_APPLICATION_FLAGS, - applicationInfo.applicationFlags, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_UBSAN_ENABLED, - applicationInfo.ubsanEnabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_ALLOW_MULTI_PROCESS, - applicationInfo.allowMultiProcess, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPLICATION_ASSET_ACCESS_GROUPS, - applicationInfo.assetAccessGroups, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APPLICATION_HAS_PLUGIN, - applicationInfo.hasPlugin, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, APPLICATION_NAME, applicationInfo.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, applicationInfo.bundleName, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_VERSION_CODE, applicationInfo.versionCode, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_VERSION_NAME, applicationInfo.versionName, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_MIN_COMPATIBLE_VERSION_CODE, + applicationInfo.minCompatibleVersionCode, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_API_COMPATIBLE_VERSION, + applicationInfo.apiCompatibleVersion, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_API_TARGET_VERSION, + applicationInfo.apiTargetVersion, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ICON_PATH, applicationInfo.iconPath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_ICON_ID, applicationInfo.iconId, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_LABEL, applicationInfo.label, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_LABEL_ID, applicationInfo.labelId, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_DESCRIPTION, applicationInfo.description, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_KEEP_ALIVE, applicationInfo.keepAlive, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_REMOVABLE, applicationInfo.removable, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_SINGLETON, applicationInfo.singleton, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_USER_DATA_CLEARABLE, + applicationInfo.userDataClearable, false, parseResult); + GetBoolValueIfFindKey(jsonObject, ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED, + applicationInfo.allowAppRunWhenDeviceFirstLocked, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ACCESSIBLE, applicationInfo.accessible, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_IS_SYSTEM_APP, applicationInfo.isSystemApp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_IS_LAUNCHER_APP, applicationInfo.isLauncherApp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_IS_FREEINSTALL_APP, + applicationInfo.isFreeInstallApp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_RUNNING_RESOURCES_APPLY, + applicationInfo.runningResourcesApply, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ASSOCIATED_WAKE_UP, + applicationInfo.associatedWakeUp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_HIDE_DESKTOP_ICON, + applicationInfo.hideDesktopIcon, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_FORM_VISIBLE_NOTIFY, + applicationInfo.formVisibleNotify, false, parseResult); + GetStringValuesIfFindKey(jsonObject, APPLICATION_ALLOW_COMMON_EVENT, + applicationInfo.allowCommonEvent, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_CODE_PATH, applicationInfo.codePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_DATA_DIR, applicationInfo.dataDir, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_DATA_BASE_DIR, applicationInfo.dataBaseDir, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_CACHE_DIR, applicationInfo.cacheDir, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ENTRY_DIR, applicationInfo.entryDir, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_API_RELEASETYPE, applicationInfo.apiReleaseType, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_DEBUG, applicationInfo.debug, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_DEVICE_ID, applicationInfo.deviceId, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, + applicationInfo.distributedNotificationEnabled, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_INSTALLED_FOR_ALL_USER, applicationInfo.installedForAllUser, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ALLOW_ENABLE_NOTIFICATION, applicationInfo.allowEnableNotification, + false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ENTITY_TYPE, applicationInfo.entityType, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_PROCESS, applicationInfo.process, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_SUPPORTED_MODES, applicationInfo.supportedModes, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_VENDOR, applicationInfo.vendor, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_PRIVILEGE_LEVEL, applicationInfo.appPrivilegeLevel, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_ACCESSTOKEN_ID_EX, applicationInfo.accessTokenIdEx, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ENABLED, applicationInfo.enabled, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_UID, applicationInfo.uid, false, parseResult); + GetStringValuesIfFindKey(jsonObject, APPLICATION_PERMISSIONS, applicationInfo.permissions, false, parseResult); + GetStringValuesIfFindKey(jsonObject, APPLICATION_MODULE_SOURCE_DIRS, applicationInfo.moduleSourceDirs, false, + parseResult); + GetObjectValuesIfFindKey(jsonObject, APPLICATION_MODULE_INFOS, applicationInfo.moduleInfos, false, parseResult); + GetObjectValuesMapIfFindKey(jsonObject, APPLICATION_META_DATA_CONFIG_JSON, applicationInfo.metaData, false, + parseResult); + GetObjectValuesMapIfFindKey(jsonObject, APPLICATION_META_DATA_MODULE_JSON, applicationInfo.metadata, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_FINGERPRINT, applicationInfo.fingerprint, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ICON, applicationInfo.icon, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_FLAGS, applicationInfo.flags, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ENTRY_MODULE_NAME, applicationInfo.entryModuleName, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_NATIVE_LIBRARY_PATH, applicationInfo.nativeLibraryPath, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_CPU_ABI, applicationInfo.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ARK_NATIVE_FILE_PATH, applicationInfo.arkNativeFilePath, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ARK_NATIVE_FILE_ABI, applicationInfo.arkNativeFileAbi, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_IS_COMPRESS_NATIVE_LIBS, applicationInfo.isCompressNativeLibs, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey, false, parseResult); + GetStringValuesIfFindKey(jsonObject, APPLICATION_TARGETBUNDLELIST, applicationInfo.targetBundleList, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_APP_DISTRIBUTION_TYPE, applicationInfo.appDistributionType, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_APP_PROVISION_TYPE, applicationInfo.appProvisionType, false, + parseResult); + GetObjectValueIfFindKey(jsonObject, APPLICATION_ICON_RESOURCE, applicationInfo.iconResource, false, parseResult); + GetObjectValueIfFindKey(jsonObject, APPLICATION_LABEL_RESOURCE, applicationInfo.labelResource, false, parseResult); + GetObjectValueIfFindKey(jsonObject, APPLICATION_DESCRIPTION_RESOURCE, applicationInfo.descriptionResource, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_MULTI_PROJECTS, applicationInfo.multiProjects, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_CROWDTEST_DEADLINE, applicationInfo.crowdtestDeadline, false, + parseResult); + GetObjectValueIfFindKey(jsonObject, APPLICATION_APP_QUICK_FIX, applicationInfo.appQuickFix, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_NEED_APP_DETAIL, applicationInfo.needAppDetail, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH, + applicationInfo.appDetailAbilityLibraryPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_APP_TARGET_BUNDLE_NAME, applicationInfo.targetBundleName, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_APP_TARGET_PRIORITY, applicationInfo.targetPriority, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_APP_OVERLAY_STATE, applicationInfo.overlayState, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ASAN_ENABLED, applicationInfo.asanEnabled, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ASAN_LOG_PATH, applicationInfo.asanLogPath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_APP_TYPE, applicationInfo.bundleType, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_COMPILE_SDK_VERSION, applicationInfo.compileSdkVersion, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_COMPILE_SDK_TYPE, applicationInfo.compileSdkType, false, + parseResult); + GetNumberValuesIfFindKey(jsonObject, APPLICATION_RESOURCES_APPLY, applicationInfo.resourcesApply, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_GWP_ASAN_ENABLED, applicationInfo.gwpAsanEnabled, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_RESERVED_FLAG, applicationInfo.applicationReservedFlag, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_TSAN_ENABLED, applicationInfo.tsanEnabled, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_ORGANIZATION, applicationInfo.organization, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, APPLICATION_APP_ENVIRONMENTS, applicationInfo.appEnvironments, false, + parseResult); + GetObjectValueIfFindKey(jsonObject, APPLICATION_MULTI_APP_MODE, applicationInfo.multiAppMode, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_APP_INDEX, applicationInfo.appIndex, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_MAX_CHILD_PROCESS, applicationInfo.maxChildProcess, false, + parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_INSTALL_SOURCE, applicationInfo.installSource, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_HWASAN_ENABLED, applicationInfo.hwasanEnabled, false, parseResult); + GetStringValueIfFindKey(jsonObject, APPLICATION_CONFIGURATION, applicationInfo.configuration, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_CLOUD_FILE_SYNC_ENABLED, applicationInfo.cloudFileSyncEnabled, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, APPLICATION_APPLICATION_FLAGS, applicationInfo.applicationFlags, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_UBSAN_ENABLED, applicationInfo.ubsanEnabled, false, parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_ALLOW_MULTI_PROCESS, applicationInfo.allowMultiProcess, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, APPLICATION_ASSET_ACCESS_GROUPS, applicationInfo.assetAccessGroups, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, APPLICATION_HAS_PLUGIN, applicationInfo.hasPlugin, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "from_json error:%{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_container.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_container.cpp index dc3532b245973d735407d3cb93a7c8e9e17d2621..3977d6098f676ba891f599e63c527c854d3c2648 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_container.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_container.cpp @@ -15,8 +15,6 @@ #include "bundle_container.h" -#include - #include "hilog_tag_wrapper.h" #include "json_serializer.h" #include "module_profile.h" diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_info.cpp index 2bbc4b0d856f7bcc43569a49f4348e2b62377346..f33b4b9482080391648c5099ac4363544dcde743 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/bundle_info.cpp @@ -88,597 +88,333 @@ const char* BUNDLE_INFO_HAS_PLUGIN = "hasPlugin"; const uint32_t BUNDLE_CAPACITY = 204800; // 200K } -void to_json(nlohmann::json &jsonObject, const RequestPermissionUsedScene &usedScene) +bool to_json(cJSON *jsonObject, const RequestPermissionUsedScene &usedScene) { - jsonObject = nlohmann::json { - {REQUESTPERMISSION_ABILITIES, usedScene.abilities}, - {REQUESTPERMISSION_WHEN, usedScene.when} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON *abilitiesItem = nullptr; + if (!to_json(abilitiesItem, usedScene.abilities)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json abilities failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, REQUESTPERMISSION_ABILITIES, abilitiesItem); + cJSON_AddStringToObject(jsonObject, REQUESTPERMISSION_WHEN, usedScene.when.c_str()); + return true; } -void to_json(nlohmann::json &jsonObject, const RequestPermission &requestPermission) +bool to_json(cJSON *jsonObject, const RequestPermission &requestPermission) { - jsonObject = nlohmann::json { - {REQUESTPERMISSION_NAME, requestPermission.name}, - {REQUESTPERMISSION_REASON, requestPermission.reason}, - {REQUESTPERMISSION_REASON_ID, requestPermission.reasonId}, - {REQUESTPERMISSION_USEDSCENE, requestPermission.usedScene}, - {REQUESTPERMISSION_MODULE_NAME, requestPermission.moduleName} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, REQUESTPERMISSION_NAME, requestPermission.name.c_str()); + cJSON_AddStringToObject(jsonObject, REQUESTPERMISSION_REASON, requestPermission.reason.c_str()); + cJSON_AddNumberToObject(jsonObject, REQUESTPERMISSION_REASON_ID, requestPermission.reasonId); + cJSON *usedSceneItem = nullptr; + if (!to_json(usedSceneItem, requestPermission.usedScene)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json usedScene failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, REQUESTPERMISSION_USEDSCENE, usedSceneItem); + cJSON_AddStringToObject(jsonObject, REQUESTPERMISSION_MODULE_NAME, requestPermission.moduleName.c_str()); + return true; } -void to_json(nlohmann::json &jsonObject, const SignatureInfo &signatureInfo) +bool to_json(cJSON *jsonObject, const SignatureInfo &signatureInfo) { - jsonObject = nlohmann::json { - {SIGNATUREINFO_APPID, signatureInfo.appId}, - {SIGNATUREINFO_FINGERPRINT, signatureInfo.fingerprint}, - {APP_IDENTIFIER, signatureInfo.appIdentifier} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, SIGNATUREINFO_APPID, signatureInfo.appId.c_str()); + cJSON_AddStringToObject(jsonObject, SIGNATUREINFO_FINGERPRINT, signatureInfo.fingerprint.c_str()); + cJSON_AddStringToObject(jsonObject, APP_IDENTIFIER, signatureInfo.appIdentifier.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, RequestPermissionUsedScene &usedScene) +void from_json(const cJSON *jsonObject, RequestPermissionUsedScene &usedScene) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_ABILITIES, - usedScene.abilities, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_ABILITY, - usedScene.abilities, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_WHEN, - usedScene.when, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValuesIfFindKey(jsonObject, REQUESTPERMISSION_ABILITIES, usedScene.abilities, false, parseResult); + GetStringValuesIfFindKey(jsonObject, REQUESTPERMISSION_ABILITY, usedScene.abilities, false, parseResult); + GetStringValueIfFindKey(jsonObject, REQUESTPERMISSION_WHEN, usedScene.when, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read RequestPermissionUsedScene error : %{public}d", parseResult); } } -void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission) +void from_json(const cJSON *jsonObject, RequestPermission &requestPermission) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_NAME, - requestPermission.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_REASON, - requestPermission.reason, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_REASON_ID, - requestPermission.reasonId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_USEDSCENE, - requestPermission.usedScene, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - REQUESTPERMISSION_MODULE_NAME, - requestPermission.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, REQUESTPERMISSION_NAME, requestPermission.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, REQUESTPERMISSION_REASON, requestPermission.reason, false, parseResult); + GetNumberValueIfFindKey(jsonObject, REQUESTPERMISSION_REASON_ID, requestPermission.reasonId, false, parseResult); + GetObjectValueIfFindKey(jsonObject, REQUESTPERMISSION_USEDSCENE, requestPermission.usedScene, false, parseResult); + GetStringValueIfFindKey(jsonObject, REQUESTPERMISSION_MODULE_NAME, requestPermission.moduleName, false, + parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read RequestPermission error : %{public}d", parseResult); } } -void from_json(const nlohmann::json &jsonObject, SignatureInfo &signatureInfo) +void from_json(const cJSON *jsonObject, SignatureInfo &signatureInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SIGNATUREINFO_APPID, - signatureInfo.appId, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SIGNATUREINFO_FINGERPRINT, - signatureInfo.fingerprint, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_IDENTIFIER, - signatureInfo.appIdentifier, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, SIGNATUREINFO_APPID, signatureInfo.appId, false, parseResult); + GetStringValueIfFindKey(jsonObject, SIGNATUREINFO_FINGERPRINT, signatureInfo.fingerprint, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_IDENTIFIER, signatureInfo.appIdentifier, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read SignatureInfo error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const BundleInfo &bundleInfo) +bool to_json(cJSON *jsonObject, const BundleInfo &bundleInfo) { - jsonObject = nlohmann::json { - {BUNDLE_INFO_NAME, bundleInfo.name}, {BUNDLE_INFO_LABEL, bundleInfo.label}, - {BUNDLE_INFO_DESCRIPTION, bundleInfo.description}, {BUNDLE_INFO_VENDOR, bundleInfo.vendor}, - {BUNDLE_INFO_IS_KEEP_ALIVE, bundleInfo.isKeepAlive}, {BUNDLE_INFO_IS_NATIVE_APP, bundleInfo.isNativeApp}, - {BUNDLE_INFO_IS_PREINSTALL_APP, bundleInfo.isPreInstallApp}, - {BUNDLE_INFO_IS_DIFFERENT_NAME, bundleInfo.isDifferentName}, - {BUNDLE_INFO_ABILITY_INFOS, bundleInfo.abilityInfos}, - {BUNDLE_INFO_HAP_MODULE_INFOS, bundleInfo.hapModuleInfos}, - {BUNDLE_INFO_EXTENSION_ABILITY_INFOS, bundleInfo.extensionInfos}, - {BUNDLE_INFO_JOINT_USERID, bundleInfo.jointUserId}, - {BUNDLE_INFO_VERSION_CODE, bundleInfo.versionCode}, - {BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, bundleInfo.minCompatibleVersionCode}, - {BUNDLE_INFO_VERSION_NAME, bundleInfo.versionName}, - {BUNDLE_INFO_MIN_SDK_VERSION, bundleInfo.minSdkVersion}, - {BUNDLE_INFO_MAX_SDK_VERSION, bundleInfo.maxSdkVersion}, - {BUNDLE_INFO_MAIN_ENTRY, bundleInfo.mainEntry}, - {BUNDLE_INFO_CPU_ABI, bundleInfo.cpuAbi}, - {BUNDLE_INFO_APPID, bundleInfo.appId}, - {BUNDLE_INFO_COMPATIBLE_VERSION, bundleInfo.compatibleVersion}, - {BUNDLE_INFO_TARGET_VERSION, bundleInfo.targetVersion}, - {BUNDLE_INFO_RELEASE_TYPE, bundleInfo.releaseType}, - {BUNDLE_INFO_UID, bundleInfo.uid}, - {BUNDLE_INFO_GID, bundleInfo.gid}, - {BUNDLE_INFO_SEINFO, bundleInfo.seInfo}, - {BUNDLE_INFO_INSTALL_TIME, bundleInfo.installTime}, - {BUNDLE_INFO_UPDATE_TIME, bundleInfo.updateTime}, - {BUNDLE_INFO_FIRST_INSTALL_TIME, bundleInfo.firstInstallTime}, - {BUNDLE_INFO_ENTRY_MODULE_NAME, bundleInfo.entryModuleName}, - {BUNDLE_INFO_ENTRY_INSTALLATION_FREE, bundleInfo.entryInstallationFree}, - {BUNDLE_INFO_REQ_PERMISSIONS, bundleInfo.reqPermissions}, - {BUNDLE_INFO_REQ_PERMISSION_STATES, bundleInfo.reqPermissionStates}, - {BUNDLE_INFO_REQ_PERMISSION_DETAILS, bundleInfo.reqPermissionDetails}, - {BUNDLE_INFO_DEF_PERMISSIONS, bundleInfo.defPermissions}, - {BUNDLE_INFO_HAP_MODULE_NAMES, bundleInfo.hapModuleNames}, - {BUNDLE_INFO_MODULE_NAMES, bundleInfo.moduleNames}, - {BUNDLE_INFO_MODULE_PUBLIC_DIRS, bundleInfo.modulePublicDirs}, - {BUNDLE_INFO_MODULE_DIRS, bundleInfo.moduleDirs}, - {BUNDLE_INFO_MODULE_RES_PATHS, bundleInfo.moduleResPaths}, - {BUNDLE_INFO_SINGLETON, bundleInfo.singleton}, - {BUNDLE_INFO_APP_INDEX, bundleInfo.appIndex}, - {BUNDLE_INFO_SIGNATURE_INFO, bundleInfo.signatureInfo}, - {OVERLAY_TYPE, bundleInfo.overlayType}, - {OVERLAY_BUNDLE_INFO, bundleInfo.overlayBundleInfos}, - {BUNDLE_INFO_OLD_APPIDS, bundleInfo.oldAppIds}, - {BUNDLE_INFO_ROUTER_ARRAY, bundleInfo.routerArray}, - {BUNDLE_INFO_IS_NEW_VERSION, bundleInfo.isNewVersion}, - {BUNDLE_INFO_HAS_PLUGIN, bundleInfo.hasPlugin} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_NAME, bundleInfo.name.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_LABEL, bundleInfo.label.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_DESCRIPTION, bundleInfo.description.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_VENDOR, bundleInfo.vendor.c_str()); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_IS_KEEP_ALIVE, bundleInfo.isKeepAlive); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_IS_NATIVE_APP, bundleInfo.isNativeApp); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_IS_PREINSTALL_APP, bundleInfo.isPreInstallApp); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_IS_DIFFERENT_NAME, bundleInfo.isDifferentName); + + cJSON *abilityInfosItem = nullptr; + if (!to_json(abilityInfosItem, bundleInfo.abilityInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json abilityInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_ABILITY_INFOS, abilityInfosItem); + + cJSON *hapModuleInfosItem = nullptr; + if (!to_json(hapModuleInfosItem, bundleInfo.hapModuleInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json hapModuleInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_HAP_MODULE_INFOS, hapModuleInfosItem); + + cJSON *extensionInfosItem = nullptr; + if (!to_json(extensionInfosItem, bundleInfo.extensionInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json extensionInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_EXTENSION_ABILITY_INFOS, extensionInfosItem); + + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_JOINT_USERID, bundleInfo.jointUserId.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_VERSION_CODE, static_cast(bundleInfo.versionCode)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, + static_cast(bundleInfo.minCompatibleVersionCode)); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_VERSION_NAME, bundleInfo.versionName.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_MIN_SDK_VERSION, static_cast(bundleInfo.minSdkVersion)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_MAX_SDK_VERSION, static_cast(bundleInfo.maxSdkVersion)); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_MAIN_ENTRY, bundleInfo.mainEntry.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_CPU_ABI, bundleInfo.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_APPID, bundleInfo.appId.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_COMPATIBLE_VERSION, + static_cast(bundleInfo.compatibleVersion)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_TARGET_VERSION, static_cast(bundleInfo.targetVersion)); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_RELEASE_TYPE, bundleInfo.releaseType.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_UID, static_cast(bundleInfo.uid)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_GID, static_cast(bundleInfo.gid)); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_SEINFO, bundleInfo.seInfo.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_INSTALL_TIME, static_cast(bundleInfo.installTime)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_UPDATE_TIME, static_cast(bundleInfo.updateTime)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_FIRST_INSTALL_TIME, + static_cast(bundleInfo.firstInstallTime)); + cJSON_AddStringToObject(jsonObject, BUNDLE_INFO_ENTRY_MODULE_NAME, bundleInfo.entryModuleName.c_str()); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_ENTRY_INSTALLATION_FREE, bundleInfo.entryInstallationFree); + + cJSON *reqPermissionsItem = nullptr; + if (!to_json(reqPermissionsItem, bundleInfo.reqPermissions)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json reqPermissions failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_REQ_PERMISSIONS, reqPermissionsItem); + + cJSON *reqPermissionStatesItem = nullptr; + if (!to_json(reqPermissionStatesItem, bundleInfo.reqPermissionStates)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json reqPermissionStates failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_REQ_PERMISSION_STATES, reqPermissionStatesItem); + + cJSON *reqPermissionDetailsItem = nullptr; + if (!to_json(reqPermissionDetailsItem, bundleInfo.reqPermissionDetails)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json reqPermissionDetails failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_REQ_PERMISSION_DETAILS, reqPermissionDetailsItem); + + cJSON *defPermissionsItem = nullptr; + if (!to_json(defPermissionsItem, bundleInfo.defPermissions)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json defPermissions failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_DEF_PERMISSIONS, defPermissionsItem); + + cJSON *hapModuleNamesItem = nullptr; + if (!to_json(hapModuleNamesItem, bundleInfo.hapModuleNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json hapModuleNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_HAP_MODULE_NAMES, hapModuleNamesItem); + + cJSON *moduleNamesItem = nullptr; + if (!to_json(moduleNamesItem, bundleInfo.moduleNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_MODULE_NAMES, moduleNamesItem); + + cJSON *modulePublicDirsItem = nullptr; + if (!to_json(modulePublicDirsItem, bundleInfo.modulePublicDirs)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json modulePublicDirs failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_MODULE_PUBLIC_DIRS, modulePublicDirsItem); + + cJSON *moduleDirsItem = nullptr; + if (!to_json(moduleDirsItem, bundleInfo.moduleDirs)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleDirs failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_MODULE_DIRS, moduleDirsItem); + + cJSON *moduleResPathsItem = nullptr; + if (!to_json(moduleResPathsItem, bundleInfo.moduleResPaths)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleResPaths failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_MODULE_RES_PATHS, moduleResPathsItem); + + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_SINGLETON, bundleInfo.singleton); + cJSON_AddNumberToObject(jsonObject, BUNDLE_INFO_APP_INDEX, static_cast(bundleInfo.appIndex)); + + cJSON *signatureInfoItem = nullptr; + if (!to_json(signatureInfoItem, bundleInfo.signatureInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json signatureInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_SIGNATURE_INFO, signatureInfoItem); + + cJSON_AddNumberToObject(jsonObject, OVERLAY_TYPE, static_cast(bundleInfo.overlayType)); + + cJSON *overlayBundleInfosItem = nullptr; + if (!to_json(overlayBundleInfosItem, bundleInfo.overlayBundleInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json overlayBundleInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, OVERLAY_BUNDLE_INFO, overlayBundleInfosItem); + + cJSON *oldAppIdsItem = nullptr; + if (!to_json(oldAppIdsItem, bundleInfo.oldAppIds)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json oldAppIds failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_OLD_APPIDS, oldAppIdsItem); + + cJSON *routerArrayItem = nullptr; + if (!to_json(routerArrayItem, bundleInfo.routerArray)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json routerArray failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_INFO_OLD_APPIDS, routerArrayItem); + + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_IS_NEW_VERSION, bundleInfo.isNewVersion); + cJSON_AddBoolToObject(jsonObject, BUNDLE_INFO_HAS_PLUGIN, bundleInfo.hasPlugin); + + return true; } -void from_json(const nlohmann::json &jsonObject, BundleInfo &bundleInfo) +void from_json(const cJSON *jsonObject, BundleInfo &bundleInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_NAME, - bundleInfo.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_LABEL, - bundleInfo.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_DESCRIPTION, - bundleInfo.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_VENDOR, - bundleInfo.vendor, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_IS_KEEP_ALIVE, - bundleInfo.isKeepAlive, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_IS_NATIVE_APP, - bundleInfo.isNativeApp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_IS_PREINSTALL_APP, - bundleInfo.isPreInstallApp, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_IS_DIFFERENT_NAME, - bundleInfo.isDifferentName, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_ABILITY_INFOS, - bundleInfo.abilityInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_HAP_MODULE_INFOS, - bundleInfo.hapModuleInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_VERSION_CODE, - bundleInfo.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, - bundleInfo.minCompatibleVersionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_VERSION_NAME, - bundleInfo.versionName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_JOINT_USERID, - bundleInfo.jointUserId, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MIN_SDK_VERSION, - bundleInfo.minSdkVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MAX_SDK_VERSION, - bundleInfo.maxSdkVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MAIN_ENTRY, - bundleInfo.mainEntry, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_CPU_ABI, - bundleInfo.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_APPID, - bundleInfo.appId, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_COMPATIBLE_VERSION, - bundleInfo.compatibleVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_TARGET_VERSION, - bundleInfo.targetVersion, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_RELEASE_TYPE, - bundleInfo.releaseType, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_UID, - bundleInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_GID, - bundleInfo.gid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_SEINFO, - bundleInfo.seInfo, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_INSTALL_TIME, - bundleInfo.installTime, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_UPDATE_TIME, - bundleInfo.updateTime, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_FIRST_INSTALL_TIME, - bundleInfo.firstInstallTime, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_ENTRY_MODULE_NAME, - bundleInfo.entryModuleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_ENTRY_INSTALLATION_FREE, - bundleInfo.entryInstallationFree, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_REQ_PERMISSIONS, - bundleInfo.reqPermissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_REQ_PERMISSION_STATES, - bundleInfo.reqPermissionStates, - JsonType::ARRAY, - false, - parseResult, - ArrayType::NUMBER); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_REQ_PERMISSION_DETAILS, - bundleInfo.reqPermissionDetails, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_DEF_PERMISSIONS, - bundleInfo.defPermissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_HAP_MODULE_NAMES, - bundleInfo.hapModuleNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MODULE_NAMES, - bundleInfo.moduleNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MODULE_PUBLIC_DIRS, - bundleInfo.modulePublicDirs, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MODULE_DIRS, - bundleInfo.moduleDirs, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_MODULE_RES_PATHS, - bundleInfo.moduleResPaths, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_SINGLETON, - bundleInfo.singleton, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_EXTENSION_ABILITY_INFOS, - bundleInfo.extensionInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_APP_INDEX, - bundleInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_SIGNATURE_INFO, - bundleInfo.signatureInfo, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - OVERLAY_TYPE, - bundleInfo.overlayType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - OVERLAY_BUNDLE_INFO, - bundleInfo.overlayBundleInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_OLD_APPIDS, - bundleInfo.oldAppIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_ROUTER_ARRAY, - bundleInfo.routerArray, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_IS_NEW_VERSION, - bundleInfo.isNewVersion, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_INFO_HAS_PLUGIN, - bundleInfo.hasPlugin, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_NAME, bundleInfo.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_LABEL, bundleInfo.label, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_DESCRIPTION, bundleInfo.description, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_VENDOR, bundleInfo.vendor, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_IS_KEEP_ALIVE, bundleInfo.isKeepAlive, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_IS_NATIVE_APP, bundleInfo.isNativeApp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_IS_PREINSTALL_APP, bundleInfo.isPreInstallApp, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_IS_DIFFERENT_NAME, bundleInfo.isDifferentName, false, parseResult); + GetObjectValueIfFindKey(jsonObject, BUNDLE_INFO_ABILITY_INFOS, bundleInfo.abilityInfos, false, parseResult); + GetObjectValueIfFindKey(jsonObject, BUNDLE_INFO_HAP_MODULE_INFOS, bundleInfo.hapModuleInfos, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_VERSION_CODE, bundleInfo.versionCode, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, bundleInfo.minCompatibleVersionCode, + false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_VERSION_NAME, bundleInfo.versionName, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_JOINT_USERID, bundleInfo.jointUserId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_MIN_SDK_VERSION, bundleInfo.minSdkVersion, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_MAX_SDK_VERSION, bundleInfo.maxSdkVersion, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_MAIN_ENTRY, bundleInfo.mainEntry, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_CPU_ABI, bundleInfo.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_APPID, bundleInfo.appId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_COMPATIBLE_VERSION, bundleInfo.compatibleVersion, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_TARGET_VERSION, bundleInfo.targetVersion, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_RELEASE_TYPE, bundleInfo.releaseType, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_UID, bundleInfo.uid, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_GID, bundleInfo.gid, false, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_SEINFO, bundleInfo.seInfo, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_INSTALL_TIME, bundleInfo.installTime, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_UPDATE_TIME, bundleInfo.updateTime, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_FIRST_INSTALL_TIME, bundleInfo.firstInstallTime, false, + parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_INFO_ENTRY_MODULE_NAME, bundleInfo.entryModuleName, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_ENTRY_INSTALLATION_FREE, bundleInfo.entryInstallationFree, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_REQ_PERMISSIONS, bundleInfo.reqPermissions, false, parseResult); + GetNumberValuesIfFindKey(jsonObject, BUNDLE_INFO_REQ_PERMISSION_STATES, bundleInfo.reqPermissionStates, false, + parseResult); + GetObjectValuesIfFindKey(jsonObject, BUNDLE_INFO_REQ_PERMISSION_DETAILS, bundleInfo.reqPermissionDetails, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_DEF_PERMISSIONS, bundleInfo.defPermissions, false, parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_HAP_MODULE_NAMES, bundleInfo.hapModuleNames, false, parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_MODULE_NAMES, bundleInfo.moduleNames, false, parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_MODULE_PUBLIC_DIRS, bundleInfo.modulePublicDirs, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_MODULE_DIRS, bundleInfo.moduleDirs, false, parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_MODULE_RES_PATHS, bundleInfo.moduleResPaths, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_SINGLETON, bundleInfo.singleton, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, BUNDLE_INFO_EXTENSION_ABILITY_INFOS, bundleInfo.extensionInfos, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_INFO_APP_INDEX, bundleInfo.appIndex, false, parseResult); + GetObjectValueIfFindKey(jsonObject, BUNDLE_INFO_SIGNATURE_INFO, bundleInfo.signatureInfo, false, parseResult); + GetNumberValueIfFindKey(jsonObject, OVERLAY_TYPE, bundleInfo.overlayType, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, OVERLAY_BUNDLE_INFO, bundleInfo.overlayBundleInfos, false, parseResult); + GetStringValuesIfFindKey(jsonObject, BUNDLE_INFO_OLD_APPIDS, bundleInfo.oldAppIds, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, BUNDLE_INFO_ROUTER_ARRAY, bundleInfo.routerArray, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_IS_NEW_VERSION, bundleInfo.isNewVersion, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_INFO_HAS_PLUGIN, bundleInfo.hasPlugin, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "BundleInfo from_json error %{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/extension_ability_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/extension_ability_info.cpp index 625aa557f21f52c1bc63b65dfc5fbebe04c0e4d7..d650ef2de73ee2a85cd3a71504f6fb7725040b38 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/extension_ability_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/extension_ability_info.cpp @@ -22,7 +22,6 @@ #include "bundle_constants.h" #include "hilog_tag_wrapper.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -50,234 +49,86 @@ const std::string PROCESS = "process"; const std::string COMPILE_MODE = "compileMode"; const std::string UID = "uid"; }; // namespace -void to_json(nlohmann::json &jsonObject, const ExtensionAbilityInfo &extensionInfo) + +bool to_json(cJSON *jsonObject, const ExtensionAbilityInfo &extensionInfo) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "called"); - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, extensionInfo.bundleName}, - {Constants::MODULE_NAME, extensionInfo.moduleName}, - {NAME, extensionInfo.name}, - {SRC_ENTRANCE, extensionInfo.srcEntrance}, - {ICON, extensionInfo.icon}, - {ICON_ID, extensionInfo.iconId}, - {LABEL, extensionInfo.label}, - {LABEL_ID, extensionInfo.labelId}, - {DESCRIPTION, extensionInfo.description}, - {DESCRIPTION_ID, extensionInfo.descriptionId}, - {PRIORITY, extensionInfo.priority}, - {TYPE, extensionInfo.type}, - {READ_PERMISSION, extensionInfo.readPermission}, - {WRITE_PERMISSION, extensionInfo.writePermission}, - {URI, extensionInfo.uri}, - {PERMISSIONS, extensionInfo.permissions}, - {VISIBLE, extensionInfo.visible}, - {META_DATA, extensionInfo.metadata}, - {RESOURCE_PATH, extensionInfo.resourcePath}, - {Constants::HAP_PATH, extensionInfo.hapPath}, - {ENABLED, extensionInfo.enabled}, - {PROCESS, extensionInfo.process}, - {COMPILE_MODE, extensionInfo.compileMode}, - {UID, extensionInfo.uid} - }; + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, extensionInfo.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, extensionInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, NAME.c_str(), extensionInfo.name.c_str()); + cJSON_AddStringToObject(jsonObject, SRC_ENTRANCE.c_str(), extensionInfo.srcEntrance.c_str()); + cJSON_AddStringToObject(jsonObject, ICON.c_str(), extensionInfo.icon.c_str()); + cJSON_AddNumberToObject(jsonObject, ICON_ID.c_str(), static_cast(extensionInfo.iconId)); + cJSON_AddStringToObject(jsonObject, LABEL.c_str(), extensionInfo.label.c_str()); + cJSON_AddNumberToObject(jsonObject, LABEL_ID.c_str(), static_cast(extensionInfo.labelId)); + cJSON_AddStringToObject(jsonObject, DESCRIPTION.c_str(), extensionInfo.description.c_str()); + cJSON_AddNumberToObject(jsonObject, DESCRIPTION_ID.c_str(), static_cast(extensionInfo.descriptionId)); + cJSON_AddNumberToObject(jsonObject, PRIORITY.c_str(), static_cast(extensionInfo.priority)); + cJSON_AddNumberToObject(jsonObject, TYPE.c_str(), static_cast(extensionInfo.type)); + cJSON_AddStringToObject(jsonObject, READ_PERMISSION.c_str(), extensionInfo.readPermission.c_str()); + cJSON_AddStringToObject(jsonObject, WRITE_PERMISSION.c_str(), extensionInfo.writePermission.c_str()); + cJSON_AddStringToObject(jsonObject, URI.c_str(), extensionInfo.uri.c_str()); + + cJSON *permissionsItem = nullptr; + if (!to_json(permissionsItem, extensionInfo.permissions)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json permissions failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, PERMISSIONS.c_str(), permissionsItem); + + cJSON_AddBoolToObject(jsonObject, VISIBLE.c_str(), extensionInfo.visible); + + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, extensionInfo.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, META_DATA.c_str(), metadataItem); + + cJSON_AddStringToObject(jsonObject, RESOURCE_PATH.c_str(), extensionInfo.resourcePath.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::HAP_PATH, extensionInfo.hapPath.c_str()); + cJSON_AddBoolToObject(jsonObject, ENABLED.c_str(), extensionInfo.enabled); + cJSON_AddStringToObject(jsonObject, PROCESS.c_str(), extensionInfo.process.c_str()); + cJSON_AddNumberToObject(jsonObject, COMPILE_MODE.c_str(), static_cast(extensionInfo.compileMode)); + cJSON_AddNumberToObject(jsonObject, UID.c_str(), static_cast(extensionInfo.uid)); + return true; } -void from_json(const nlohmann::json &jsonObject, ExtensionAbilityInfo &extensionInfo) +void from_json(const cJSON *jsonObject, ExtensionAbilityInfo &extensionInfo) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "called"); - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - extensionInfo.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - extensionInfo.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - NAME, - extensionInfo.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - extensionInfo.srcEntrance, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - extensionInfo.icon, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - extensionInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - extensionInfo.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - extensionInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - extensionInfo.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - extensionInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - extensionInfo.priority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - TYPE, - extensionInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - READ_PERMISSION, - extensionInfo.readPermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - WRITE_PERMISSION, - extensionInfo.writePermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - URI, - extensionInfo.uri, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - extensionInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - extensionInfo.visible, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - extensionInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - RESOURCE_PATH, - extensionInfo.resourcePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::HAP_PATH, - extensionInfo.hapPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ENABLED, - extensionInfo.enabled, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PROCESS, - extensionInfo.process, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_MODE, - extensionInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UID, - extensionInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, extensionInfo.bundleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, extensionInfo.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, NAME, extensionInfo.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, SRC_ENTRANCE, extensionInfo.srcEntrance, false, parseResult); + GetStringValueIfFindKey(jsonObject, ICON, extensionInfo.icon, false, parseResult); + GetNumberValueIfFindKey(jsonObject, ICON_ID, extensionInfo.iconId, false, parseResult); + GetStringValueIfFindKey(jsonObject, LABEL, extensionInfo.label, false, parseResult); + GetNumberValueIfFindKey(jsonObject, LABEL_ID, extensionInfo.labelId, false, parseResult); + GetStringValueIfFindKey(jsonObject, DESCRIPTION, extensionInfo.description, false, parseResult); + GetNumberValueIfFindKey(jsonObject, DESCRIPTION_ID, extensionInfo.descriptionId, false, parseResult); + GetNumberValueIfFindKey(jsonObject, PRIORITY, extensionInfo.priority, false, parseResult); + GetNumberValueIfFindKey(jsonObject, TYPE, extensionInfo.type, false, parseResult); + GetStringValueIfFindKey(jsonObject, READ_PERMISSION, extensionInfo.readPermission, false, parseResult); + GetStringValueIfFindKey(jsonObject, WRITE_PERMISSION, extensionInfo.writePermission, false, parseResult); + GetStringValueIfFindKey(jsonObject, URI, extensionInfo.uri, false, parseResult); + GetStringValuesIfFindKey(jsonObject, PERMISSIONS, extensionInfo.permissions, false, parseResult); + GetBoolValueIfFindKey(jsonObject, VISIBLE, extensionInfo.visible, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, META_DATA, extensionInfo.metadata, false, parseResult); + GetStringValueIfFindKey(jsonObject, RESOURCE_PATH, extensionInfo.resourcePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::HAP_PATH, extensionInfo.hapPath, false, parseResult); + GetBoolValueIfFindKey(jsonObject, ENABLED, extensionInfo.enabled, false, parseResult); + GetStringValueIfFindKey(jsonObject, PROCESS, extensionInfo.process, false, parseResult); + GetNumberValueIfFindKey(jsonObject, COMPILE_MODE, extensionInfo.compileMode, false, parseResult); + GetNumberValueIfFindKey(jsonObject, UID, extensionInfo.uid, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "ExtensionAbilityInfo error:%{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/hap_module_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/hap_module_info.cpp index dafed2a151e371d8d8144b0967524da476416167..a54d13c57fd757c26b698705adc160ba983c9264 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/hap_module_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/hap_module_info.cpp @@ -18,7 +18,6 @@ #include "bundle_constants.h" #include "hilog_tag_wrapper.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -109,811 +108,430 @@ const std::string MODULE_OVERLAY_PRIORITY = "priority"; const std::string MODULE_OVERLAY_STATE = "state"; const std::string MODULE_TARGET_MODULE_NAME = "targetModuleName"; } -void to_json(nlohmann::json &jsonObject, const PreloadItem &preloadItem) + +bool to_json(cJSON *jsonObject, const PreloadItem &preloadItem) { - jsonObject = nlohmann::json { - {PRELOAD_ITEM_MODULE_NAME, preloadItem.moduleName} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, PRELOAD_ITEM_MODULE_NAME.c_str(), preloadItem.moduleName.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, PreloadItem &preloadItem) +void from_json(const cJSON *jsonObject, PreloadItem &preloadItem) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRELOAD_ITEM_MODULE_NAME, - preloadItem.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, PRELOAD_ITEM_MODULE_NAME, preloadItem.moduleName, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read PreloadItem error:%{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const ProxyData &proxyData) +bool to_json(cJSON *jsonObject, const ProxyData &proxyData) { - jsonObject = nlohmann::json { - {PROXY_DATA_URI, proxyData.uri}, - {PROXY_DATA_REQUIRED_READ_PERMISSION, proxyData.requiredReadPermission}, - {PROXY_DATA_REQUIRED_WRITE_PERMISSION, proxyData.requiredWritePermission}, - {PROXY_DATA_METADATA, proxyData.metadata} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, PROXY_DATA_URI.c_str(), proxyData.uri.c_str()); + cJSON_AddStringToObject(jsonObject, PROXY_DATA_REQUIRED_READ_PERMISSION.c_str(), + proxyData.requiredReadPermission.c_str()); + cJSON_AddStringToObject(jsonObject, PROXY_DATA_REQUIRED_WRITE_PERMISSION.c_str(), + proxyData.requiredWritePermission.c_str()); + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, proxyData.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, PROXY_DATA_METADATA.c_str(), metadataItem); + return true; } -void from_json(const nlohmann::json &jsonObject, ProxyData &proxyData) +void from_json(const cJSON *jsonObject, ProxyData &proxyData) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PROXY_DATA_URI, - proxyData.uri, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PROXY_DATA_REQUIRED_READ_PERMISSION, - proxyData.requiredReadPermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PROXY_DATA_REQUIRED_WRITE_PERMISSION, - proxyData.requiredWritePermission, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PROXY_DATA_METADATA, - proxyData.metadata, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, PROXY_DATA_URI, proxyData.uri, false, parseResult); + GetStringValueIfFindKey(jsonObject, PROXY_DATA_REQUIRED_READ_PERMISSION, proxyData.requiredReadPermission, false, + parseResult); + GetStringValueIfFindKey(jsonObject, PROXY_DATA_REQUIRED_WRITE_PERMISSION, proxyData.requiredWritePermission, false, + parseResult); + GetObjectValueIfFindKey(jsonObject, PROXY_DATA_METADATA, proxyData.metadata, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read ProxyData from database error:%{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const OverlayModuleInfo &overlayModuleInfo) +bool to_json(cJSON *jsonObject, const OverlayModuleInfo &overlayModuleInfo) { - jsonObject = nlohmann::json { - {MODULE_OVERLAY_BUNDLE_NAME, overlayModuleInfo.bundleName}, - {MODULE_OVERLAY_MODULE_NAME, overlayModuleInfo.moduleName}, - {MODULE_TARGET_MODULE_NAME, overlayModuleInfo.targetModuleName}, - {MODULE_OVERLAY_HAP_PATH, overlayModuleInfo.hapPath}, - {MODULE_OVERLAY_PRIORITY, overlayModuleInfo.priority}, - {MODULE_OVERLAY_STATE, overlayModuleInfo.state} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, MODULE_OVERLAY_BUNDLE_NAME.c_str(), overlayModuleInfo.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_OVERLAY_MODULE_NAME.c_str(), overlayModuleInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_TARGET_MODULE_NAME.c_str(), overlayModuleInfo.targetModuleName.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_OVERLAY_HAP_PATH.c_str(), overlayModuleInfo.hapPath.c_str()); + cJSON_AddNumberToObject(jsonObject, MODULE_OVERLAY_PRIORITY.c_str(), + static_cast(overlayModuleInfo.priority)); + cJSON_AddNumberToObject(jsonObject, MODULE_OVERLAY_STATE.c_str(), static_cast(overlayModuleInfo.state)); + return true; } -void from_json(const nlohmann::json &jsonObject, OverlayModuleInfo &overlayModuleInfo) +void from_json(const cJSON *jsonObject, OverlayModuleInfo &overlayModuleInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_OVERLAY_BUNDLE_NAME, - overlayModuleInfo.bundleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_OVERLAY_MODULE_NAME, - overlayModuleInfo.moduleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TARGET_MODULE_NAME, - overlayModuleInfo.targetModuleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_OVERLAY_HAP_PATH, - overlayModuleInfo.hapPath, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_OVERLAY_PRIORITY, - overlayModuleInfo.priority, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_OVERLAY_STATE, - overlayModuleInfo.state, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, MODULE_OVERLAY_BUNDLE_NAME, overlayModuleInfo.bundleName, true, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_OVERLAY_MODULE_NAME, overlayModuleInfo.moduleName, true, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_TARGET_MODULE_NAME, overlayModuleInfo.targetModuleName, true, + parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_OVERLAY_HAP_PATH, overlayModuleInfo.hapPath, true, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_OVERLAY_PRIORITY, overlayModuleInfo.priority, true, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_OVERLAY_STATE, overlayModuleInfo.state, true, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "overlayModuleInfo from_json error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const RouterItem &routerItem) +bool to_json(cJSON *jsonObject, const RouterItem &routerItem) { - jsonObject = nlohmann::json { - {ROUTER_ITEM_KEY_NAME, routerItem.name}, - {ROUTER_ITEM_KEY_PAGE_SOURCE_FILE, routerItem.pageSourceFile}, - {ROUTER_ITEM_KEY_BUILD_FUNCTION, routerItem.buildFunction}, - {ROUTER_ITEM_KEY_DATA, routerItem.data}, - {ROUTER_ITEM_KEY_CUSTOM_DATA, routerItem.customData}, - {ROUTER_ITEM_KEY_OHMURL, routerItem.ohmurl}, - {ROUTER_ITEM_KEY_BUNDLE_NAME, routerItem.bundleName}, - {ROUTER_ITEM_KEY_MODULE_NAME, routerItem.moduleName} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_NAME.c_str(), routerItem.name.c_str()); + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_PAGE_SOURCE_FILE.c_str(), routerItem.pageSourceFile.c_str()); + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_BUILD_FUNCTION.c_str(), routerItem.buildFunction.c_str()); + + cJSON *dataItem = nullptr; + if (!to_json(dataItem, routerItem.data)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json data failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, ROUTER_ITEM_KEY_DATA.c_str(), dataItem); + + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_CUSTOM_DATA.c_str(), routerItem.customData.c_str()); + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_OHMURL.c_str(), routerItem.ohmurl.c_str()); + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_BUNDLE_NAME.c_str(), routerItem.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, ROUTER_ITEM_KEY_MODULE_NAME.c_str(), routerItem.moduleName.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, RouterItem &routerItem) +void from_json(const cJSON *jsonObject, RouterItem &routerItem) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_NAME, - routerItem.name, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_PAGE_SOURCE_FILE, - routerItem.pageSourceFile, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_BUILD_FUNCTION, - routerItem.buildFunction, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_OHMURL, - routerItem.ohmurl, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_BUNDLE_NAME, - routerItem.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_MODULE_NAME, - routerItem.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - ROUTER_ITEM_KEY_DATA, - routerItem.data, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_NAME.c_str(), routerItem.name, true, parseResult); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_PAGE_SOURCE_FILE.c_str(), routerItem.pageSourceFile, true, + parseResult); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_BUILD_FUNCTION.c_str(), routerItem.buildFunction, true, + parseResult); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_OHMURL.c_str(), routerItem.ohmurl, false, parseResult); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_BUNDLE_NAME.c_str(), routerItem.bundleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, ROUTER_ITEM_KEY_MODULE_NAME.c_str(), routerItem.moduleName, false, parseResult); + GetObjectValueMapIfFindKey(jsonObject, ROUTER_ITEM_KEY_DATA.c_str(), routerItem.data, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read RouterItem jsonObject error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const AppEnvironment &appEnvironment) +bool to_json(cJSON *jsonObject, const AppEnvironment &appEnvironment) { - jsonObject = nlohmann::json { - {APP_ENVIRONMENTS_NAME, appEnvironment.name}, - {APP_ENVIRONMENTS_VALUE, appEnvironment.value} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, APP_ENVIRONMENTS_NAME.c_str(), appEnvironment.name.c_str()); + cJSON_AddStringToObject(jsonObject, APP_ENVIRONMENTS_VALUE.c_str(), appEnvironment.value.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, AppEnvironment &appEnvironment) +void from_json(const cJSON *jsonObject, AppEnvironment &appEnvironment) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ENVIRONMENTS_NAME, - appEnvironment.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ENVIRONMENTS_VALUE, - appEnvironment.value, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, APP_ENVIRONMENTS_NAME, appEnvironment.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, APP_ENVIRONMENTS_VALUE, appEnvironment.value, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "read AppEnvironment error : %{public}d", parseResult); } } -void to_json(nlohmann::json &jsonObject, const HapModuleInfo &hapModuleInfo) +bool to_json(cJSON *jsonObject, const HapModuleInfo &hapModuleInfo) { - jsonObject = nlohmann::json { - {HAP_MODULE_INFO_NAME, hapModuleInfo.name}, {HAP_MODULE_INFO_PACKAGE, hapModuleInfo.package}, - {Constants::MODULE_NAME, hapModuleInfo.moduleName}, {HAP_MODULE_INFO_DESCRIPTION, hapModuleInfo.description}, - {HAP_MODULE_INFO_DESCRIPTION_ID, hapModuleInfo.descriptionId}, - {HAP_MODULE_INFO_ICON_PATH, hapModuleInfo.iconPath}, {HAP_MODULE_INFO_ICON_ID, hapModuleInfo.iconId}, - {HAP_MODULE_INFO_LABEL, hapModuleInfo.label}, {HAP_MODULE_INFO_LABEL_ID, hapModuleInfo.labelId}, - {HAP_MODULE_INFO_BACKGROUND_IMG, hapModuleInfo.backgroundImg}, - {HAP_MODULE_INFO_MAIN_ABILITY, hapModuleInfo.mainAbility}, - {HAP_MODULE_INFO_SRC_PATH, hapModuleInfo.srcPath}, {HAP_MODULE_INFO_HASH_VALUE, hapModuleInfo.hashValue}, - {HAP_MODULE_INFO_HAP_PATH, hapModuleInfo.hapPath}, - {HAP_MODULE_INFO_SUPPORTED_MODES, hapModuleInfo.supportedModes}, - {HAP_MODULE_INFO_REQ_CAPABILITIES, hapModuleInfo.reqCapabilities}, - {HAP_MODULE_INFO_DEVICE_TYPES, hapModuleInfo.deviceTypes}, - {HAP_MODULE_INFO_ABILITY_INFOS, hapModuleInfo.abilityInfos}, - {HAP_MODULE_INFO_COLOR_MODE, hapModuleInfo.colorMode}, {Constants::BUNDLE_NAME, hapModuleInfo.bundleName}, - {HAP_MODULE_INFO_MAIN_ELEMENTNAME, hapModuleInfo.mainElementName}, {HAP_MODULE_INFO_PAGES, hapModuleInfo.pages}, - {HAP_MODULE_INFO_SYSTEM_THEME, hapModuleInfo.systemTheme}, - {HAP_MODULE_INFO_PROCESS, hapModuleInfo.process}, {HAP_MODULE_INFO_RESOURCE_PATH, hapModuleInfo.resourcePath}, - {HAP_MODULE_INFO_SRC_ENTRANCE, hapModuleInfo.srcEntrance}, {HAP_MODULE_INFO_UI_SYNTAX, hapModuleInfo.uiSyntax}, - {HAP_MODULE_INFO_VIRTUAL_MACHINE, hapModuleInfo.virtualMachine}, - {HAP_MODULE_INFO_DELIVERY_WITH_INSTALL, hapModuleInfo.deliveryWithInstall}, - {HAP_MODULE_INFO_INSTALLATION_FREE, hapModuleInfo.installationFree}, - {HAP_MODULE_INFO_IS_MODULE_JSON, hapModuleInfo.isModuleJson}, - {HAP_MODULE_INFO_IS_STAGE_BASED_MODEL, hapModuleInfo.isStageBasedModel}, - {HAP_MODULE_INFO_IS_REMOVABLE, hapModuleInfo.isRemovable}, - {HAP_MODULE_INFO_UPGRADE_FLAG, hapModuleInfo.upgradeFlag}, - {HAP_MODULE_INFO_MODULE_TYPE, hapModuleInfo.moduleType}, - {HAP_MODULE_INFO_EXTENSION_INFOS, hapModuleInfo.extensionInfos}, - {HAP_MODULE_INFO_META_DATA, hapModuleInfo.metadata}, - {HAP_MODULE_INFO_DEPENDENCIES, hapModuleInfo.dependencies}, - {HAP_MODULE_INFO_COMPILE_MODE, hapModuleInfo.compileMode}, - {HAP_MODULE_INFO_IS_LIB_ISOLATED, hapModuleInfo.isLibIsolated}, - {HAP_MODULE_INFO_NATIVE_LIBRARY_PATH, hapModuleInfo.nativeLibraryPath}, - {HAP_MODULE_INFO_CPU_ABI, hapModuleInfo.cpuAbi}, - {HAP_MODULE_INFO_MODULE_SOURCE_DIR, hapModuleInfo.moduleSourceDir}, - {HAP_OVERLAY_MODULE_INFO, hapModuleInfo.overlayModuleInfos}, - {HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE, hapModuleInfo.atomicServiceModuleType}, - {HAP_MODULE_INFO_PRELOADS, hapModuleInfo.preloads}, - {HAP_MODULE_INFO_PROXY_DATAS, hapModuleInfo.proxyDatas}, - {HAP_MODULE_INFO_BUILD_HASH, hapModuleInfo.buildHash}, - {HAP_MODULE_INFO_ISOLATION_MODE, hapModuleInfo.isolationMode}, - {HAP_MODULE_INFO_AOT_COMPILE_STATUS, hapModuleInfo.aotCompileStatus}, - {HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, hapModuleInfo.compressNativeLibs}, - {HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, hapModuleInfo.nativeLibraryFileNames}, - {HAP_MODULE_INFO_FILE_CONTEXT_MENU, hapModuleInfo.fileContextMenu}, - {HAP_MODULE_INFO_ROUTER_MAP, hapModuleInfo.routerMap}, - {HAP_MODULE_INFO_ROUTER_ARRAY, hapModuleInfo.routerArray}, - {HAP_MODULE_INFO_APP_ENVIRONMENTS, hapModuleInfo.appEnvironments}, - {HAP_MODULE_INFO_PACKAGE_NAME, hapModuleInfo.packageName}, - {HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR, hapModuleInfo.abilitySrcEntryDelegator}, - {HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR, hapModuleInfo.abilityStageSrcEntryDelegator}, - {HAP_MODULE_INFO_APP_STARTUP, hapModuleInfo.appStartup} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_NAME.c_str(), hapModuleInfo.name.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_PACKAGE.c_str(), hapModuleInfo.package.c_str()); + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, hapModuleInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_DESCRIPTION.c_str(), hapModuleInfo.description.c_str()); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_DESCRIPTION_ID.c_str(), + static_cast(hapModuleInfo.descriptionId)); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_ICON_PATH.c_str(), hapModuleInfo.iconPath.c_str()); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_ICON_ID.c_str(), static_cast(hapModuleInfo.iconId)); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_LABEL.c_str(), hapModuleInfo.label.c_str()); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_LABEL_ID.c_str(), static_cast(hapModuleInfo.labelId)); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_BACKGROUND_IMG.c_str(), hapModuleInfo.backgroundImg.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_MAIN_ABILITY.c_str(), hapModuleInfo.mainAbility.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_SRC_PATH.c_str(), hapModuleInfo.srcPath.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_HASH_VALUE.c_str(), hapModuleInfo.hashValue.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_HAP_PATH.c_str(), hapModuleInfo.hapPath.c_str()); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_SUPPORTED_MODES.c_str(), + static_cast(hapModuleInfo.supportedModes)); + + cJSON *reqCapabilitiesItem = nullptr; + if (!to_json(reqCapabilitiesItem, hapModuleInfo.reqCapabilities)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json reqCapabilities failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_REQ_CAPABILITIES.c_str(), reqCapabilitiesItem); + + cJSON *deviceTypesItem = nullptr; + if (!to_json(deviceTypesItem, hapModuleInfo.deviceTypes)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deviceTypes failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_DEVICE_TYPES.c_str(), deviceTypesItem); + + cJSON *abilityInfosItem = nullptr; + if (!to_json(abilityInfosItem, hapModuleInfo.abilityInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json abilityInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_ABILITY_INFOS.c_str(), abilityInfosItem); + + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_COLOR_MODE.c_str(), + static_cast(hapModuleInfo.colorMode)); + cJSON_AddStringToObject(jsonObject, Constants::BUNDLE_NAME, hapModuleInfo.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_MAIN_ELEMENTNAME.c_str(), + hapModuleInfo.mainElementName.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_PAGES.c_str(), hapModuleInfo.pages.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_SYSTEM_THEME.c_str(), hapModuleInfo.systemTheme.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_PROCESS.c_str(), hapModuleInfo.process.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_RESOURCE_PATH.c_str(), hapModuleInfo.resourcePath.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_SRC_ENTRANCE.c_str(), hapModuleInfo.srcEntrance.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_UI_SYNTAX.c_str(), hapModuleInfo.uiSyntax.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_VIRTUAL_MACHINE.c_str(), hapModuleInfo.virtualMachine.c_str()); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_DELIVERY_WITH_INSTALL.c_str(), hapModuleInfo.deliveryWithInstall); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_INSTALLATION_FREE.c_str(), hapModuleInfo.installationFree); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_IS_MODULE_JSON.c_str(), hapModuleInfo.isModuleJson); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_IS_STAGE_BASED_MODEL.c_str(), hapModuleInfo.isStageBasedModel); + + cJSON *isRemovableItem = nullptr; + if (!to_json(isRemovableItem, hapModuleInfo.isRemovable)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json isRemovable failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_IS_REMOVABLE.c_str(), isRemovableItem); + + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_UPGRADE_FLAG.c_str(), + static_cast(hapModuleInfo.upgradeFlag)); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_MODULE_TYPE.c_str(), + static_cast(hapModuleInfo.moduleType)); + + cJSON *extensionInfosItem = nullptr; + if (!to_json(extensionInfosItem, hapModuleInfo.extensionInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json extensionInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_EXTENSION_INFOS.c_str(), extensionInfosItem); + + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, hapModuleInfo.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_META_DATA.c_str(), metadataItem); + + cJSON *dependenciesItem = nullptr; + if (!to_json(dependenciesItem, hapModuleInfo.dependencies)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json dependencies failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_DEPENDENCIES.c_str(), dependenciesItem); + + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_COMPILE_MODE.c_str(), + static_cast(hapModuleInfo.compileMode)); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_IS_LIB_ISOLATED.c_str(), hapModuleInfo.isLibIsolated); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_NATIVE_LIBRARY_PATH.c_str(), + hapModuleInfo.nativeLibraryPath.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_CPU_ABI.c_str(), hapModuleInfo.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_MODULE_SOURCE_DIR.c_str(), + hapModuleInfo.moduleSourceDir.c_str()); + + cJSON *overlayModuleInfosItem = nullptr; + if (!to_json(overlayModuleInfosItem, hapModuleInfo.overlayModuleInfos)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json overlayModuleInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_OVERLAY_MODULE_INFO.c_str(), overlayModuleInfosItem); + + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE.c_str(), + static_cast(hapModuleInfo.atomicServiceModuleType)); + + cJSON *preloadsItem = nullptr; + if (!to_json(preloadsItem, hapModuleInfo.preloads)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json preloads failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_PRELOADS.c_str(), preloadsItem); + + cJSON *proxyDatasItem = nullptr; + if (!to_json(proxyDatasItem, hapModuleInfo.proxyDatas)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json proxyDatas failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_PROXY_DATAS.c_str(), proxyDatasItem); + + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_BUILD_HASH.c_str(), hapModuleInfo.buildHash.c_str()); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_ISOLATION_MODE.c_str(), + static_cast(hapModuleInfo.isolationMode)); + cJSON_AddNumberToObject(jsonObject, HAP_MODULE_INFO_AOT_COMPILE_STATUS.c_str(), + static_cast(hapModuleInfo.aotCompileStatus)); + cJSON_AddBoolToObject(jsonObject, HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS.c_str(), hapModuleInfo.compressNativeLibs); + + cJSON *nativeLibraryFileNamesItem = nullptr; + if (!to_json(nativeLibraryFileNamesItem, hapModuleInfo.nativeLibraryFileNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json nativeLibraryFileNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES.c_str(), nativeLibraryFileNamesItem); + + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_FILE_CONTEXT_MENU.c_str(), + hapModuleInfo.fileContextMenu.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_ROUTER_MAP.c_str(), hapModuleInfo.routerMap.c_str()); + + cJSON *routerArrayItem = nullptr; + if (!to_json(routerArrayItem, hapModuleInfo.routerArray)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json routerArray failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_ROUTER_ARRAY.c_str(), routerArrayItem); + + cJSON *appEnvironmentsItem = nullptr; + if (!to_json(appEnvironmentsItem, hapModuleInfo.appEnvironments)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json appEnvironments failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, HAP_MODULE_INFO_APP_ENVIRONMENTS.c_str(), appEnvironmentsItem); + + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_PACKAGE_NAME.c_str(), hapModuleInfo.packageName.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR.c_str(), + hapModuleInfo.abilitySrcEntryDelegator.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR.c_str(), + hapModuleInfo.abilityStageSrcEntryDelegator.c_str()); + cJSON_AddStringToObject(jsonObject, HAP_MODULE_INFO_APP_STARTUP.c_str(), hapModuleInfo.appStartup.c_str()); + + return true; } -void from_json(const nlohmann::json &jsonObject, HapModuleInfo &hapModuleInfo) +void from_json(const cJSON *jsonObject, HapModuleInfo &hapModuleInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_NAME, - hapModuleInfo.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PACKAGE, - hapModuleInfo.package, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - hapModuleInfo.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_DESCRIPTION, - hapModuleInfo.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_DESCRIPTION_ID, - hapModuleInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ICON_PATH, - hapModuleInfo.iconPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ICON_ID, - hapModuleInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_LABEL, - hapModuleInfo.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_LABEL_ID, - hapModuleInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_BACKGROUND_IMG, - hapModuleInfo.backgroundImg, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_MAIN_ABILITY, - hapModuleInfo.mainAbility, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_SRC_PATH, - hapModuleInfo.srcPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_HASH_VALUE, - hapModuleInfo.hashValue, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_HAP_PATH, - hapModuleInfo.hapPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_SUPPORTED_MODES, - hapModuleInfo.supportedModes, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_REQ_CAPABILITIES, - hapModuleInfo.reqCapabilities, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_DEVICE_TYPES, - hapModuleInfo.deviceTypes, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ABILITY_INFOS, - hapModuleInfo.abilityInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_COLOR_MODE, - hapModuleInfo.colorMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - hapModuleInfo.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_MAIN_ELEMENTNAME, - hapModuleInfo.mainElementName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PAGES, - hapModuleInfo.pages, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_SYSTEM_THEME, - hapModuleInfo.systemTheme, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PROCESS, - hapModuleInfo.process, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_RESOURCE_PATH, - hapModuleInfo.resourcePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_SRC_ENTRANCE, - hapModuleInfo.srcEntrance, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_UI_SYNTAX, - hapModuleInfo.uiSyntax, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_VIRTUAL_MACHINE, - hapModuleInfo.virtualMachine, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_DELIVERY_WITH_INSTALL, - hapModuleInfo.deliveryWithInstall, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_INSTALLATION_FREE, - hapModuleInfo.installationFree, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_IS_MODULE_JSON, - hapModuleInfo.isModuleJson, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_IS_STAGE_BASED_MODEL, - hapModuleInfo.isStageBasedModel, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_IS_REMOVABLE, - hapModuleInfo.isRemovable, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_UPGRADE_FLAG, - hapModuleInfo.upgradeFlag, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_MODULE_TYPE, - hapModuleInfo.moduleType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_EXTENSION_INFOS, - hapModuleInfo.extensionInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_META_DATA, - hapModuleInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_DEPENDENCIES, - hapModuleInfo.dependencies, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_COMPILE_MODE, - hapModuleInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_HQF_INFO, - hapModuleInfo.hqfInfo, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_IS_LIB_ISOLATED, - hapModuleInfo.isLibIsolated, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_NATIVE_LIBRARY_PATH, - hapModuleInfo.nativeLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_CPU_ABI, - hapModuleInfo.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_MODULE_SOURCE_DIR, - hapModuleInfo.moduleSourceDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_OVERLAY_MODULE_INFO, - hapModuleInfo.overlayModuleInfos, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE, - hapModuleInfo.atomicServiceModuleType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PRELOADS, - hapModuleInfo.preloads, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PROXY_DATAS, - hapModuleInfo.proxyDatas, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_BUILD_HASH, - hapModuleInfo.buildHash, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ISOLATION_MODE, - hapModuleInfo.isolationMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_AOT_COMPILE_STATUS, - hapModuleInfo.aotCompileStatus, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, - hapModuleInfo.compressNativeLibs, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, - hapModuleInfo.nativeLibraryFileNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_FILE_CONTEXT_MENU, - hapModuleInfo.fileContextMenu, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ROUTER_MAP, - hapModuleInfo.routerMap, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_ROUTER_ARRAY, - hapModuleInfo.routerArray, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_APP_ENVIRONMENTS, - hapModuleInfo.appEnvironments, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_PACKAGE_NAME, - hapModuleInfo.packageName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR, - hapModuleInfo.abilitySrcEntryDelegator, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR, - hapModuleInfo.abilityStageSrcEntryDelegator, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - HAP_MODULE_INFO_APP_STARTUP, - hapModuleInfo.appStartup, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_NAME, hapModuleInfo.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_PACKAGE, hapModuleInfo.package, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, hapModuleInfo.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_DESCRIPTION, hapModuleInfo.description, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_DESCRIPTION_ID, hapModuleInfo.descriptionId, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_ICON_PATH, hapModuleInfo.iconPath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_ICON_ID, hapModuleInfo.iconId, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_LABEL, hapModuleInfo.label, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_LABEL_ID, hapModuleInfo.labelId, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_BACKGROUND_IMG, hapModuleInfo.backgroundImg, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_MAIN_ABILITY, hapModuleInfo.mainAbility, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_SRC_PATH, hapModuleInfo.srcPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_HASH_VALUE, hapModuleInfo.hashValue, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_HAP_PATH, hapModuleInfo.hapPath, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_SUPPORTED_MODES, hapModuleInfo.supportedModes, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, HAP_MODULE_INFO_REQ_CAPABILITIES, hapModuleInfo.reqCapabilities, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, HAP_MODULE_INFO_DEVICE_TYPES, hapModuleInfo.deviceTypes, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_ABILITY_INFOS, hapModuleInfo.abilityInfos, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_COLOR_MODE, hapModuleInfo.colorMode, false, parseResult); + GetStringValueIfFindKey(jsonObject, Constants::BUNDLE_NAME, hapModuleInfo.bundleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_MAIN_ELEMENTNAME, hapModuleInfo.mainElementName, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_PAGES, hapModuleInfo.pages, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_SYSTEM_THEME, hapModuleInfo.systemTheme, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_PROCESS, hapModuleInfo.process, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_RESOURCE_PATH, hapModuleInfo.resourcePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_SRC_ENTRANCE, hapModuleInfo.srcEntrance, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_UI_SYNTAX, hapModuleInfo.uiSyntax, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_VIRTUAL_MACHINE, hapModuleInfo.virtualMachine, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_DELIVERY_WITH_INSTALL, hapModuleInfo.deliveryWithInstall, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_INSTALLATION_FREE, hapModuleInfo.installationFree, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_IS_MODULE_JSON, hapModuleInfo.isModuleJson, false, parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_IS_STAGE_BASED_MODEL, hapModuleInfo.isStageBasedModel, false, + parseResult); + GetBoolValueMapIfFindKey(jsonObject, HAP_MODULE_INFO_IS_REMOVABLE, hapModuleInfo.isRemovable, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_UPGRADE_FLAG, hapModuleInfo.upgradeFlag, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_MODULE_TYPE, hapModuleInfo.moduleType, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_EXTENSION_INFOS, hapModuleInfo.extensionInfos, false, + parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_META_DATA, hapModuleInfo.metadata, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_DEPENDENCIES, hapModuleInfo.dependencies, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_COMPILE_MODE, hapModuleInfo.compileMode, false, parseResult); + GetObjectValueIfFindKey(jsonObject, HAP_MODULE_INFO_HQF_INFO, hapModuleInfo.hqfInfo, false, parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_IS_LIB_ISOLATED, hapModuleInfo.isLibIsolated, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_NATIVE_LIBRARY_PATH, hapModuleInfo.nativeLibraryPath, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_CPU_ABI, hapModuleInfo.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_MODULE_SOURCE_DIR, hapModuleInfo.moduleSourceDir, false, + parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_OVERLAY_MODULE_INFO, hapModuleInfo.overlayModuleInfos, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE, + hapModuleInfo.atomicServiceModuleType, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_PRELOADS, hapModuleInfo.preloads, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_PROXY_DATAS, hapModuleInfo.proxyDatas, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_BUILD_HASH, hapModuleInfo.buildHash, false, parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_ISOLATION_MODE, hapModuleInfo.isolationMode, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, HAP_MODULE_INFO_AOT_COMPILE_STATUS, hapModuleInfo.aotCompileStatus, false, + parseResult); + GetBoolValueIfFindKey(jsonObject, HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, hapModuleInfo.compressNativeLibs, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, + hapModuleInfo.nativeLibraryFileNames, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_FILE_CONTEXT_MENU, hapModuleInfo.fileContextMenu, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_ROUTER_MAP, hapModuleInfo.routerMap, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_ROUTER_ARRAY, hapModuleInfo.routerArray, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, HAP_MODULE_INFO_APP_ENVIRONMENTS, hapModuleInfo.appEnvironments, false, + parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_PACKAGE_NAME, hapModuleInfo.packageName, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR, hapModuleInfo.abilitySrcEntryDelegator, + false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR, + hapModuleInfo.abilityStageSrcEntryDelegator, false, parseResult); + GetStringValueIfFindKey(jsonObject, HAP_MODULE_INFO_APP_STARTUP, hapModuleInfo.appStartup, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "HapModuleInfo error:%{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/inner_bundle_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/inner_bundle_info.cpp index 4a997d02b2827e1b24efceaa9d9ec7cb56d7398c..f56d8ef67aff382d17790d776027efda7f45b06e 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/inner_bundle_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/inner_bundle_info.cpp @@ -22,6 +22,7 @@ #include "common_profile.h" #include "hilog_tag_wrapper.h" +#include "json_serializer.h" #include "string_ex.h" namespace OHOS { @@ -177,738 +178,376 @@ InnerBundleInfo::~InnerBundleInfo() TAG_LOGD(AAFwkTag::ABILITY_SIM, "instance destroyed"); } -void to_json(nlohmann::json &jsonObject, const Distro &distro) +bool to_json(cJSON *jsonObject, const Distro &distro) { - jsonObject = nlohmann::json { - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddBoolToObject(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, + distro.deliveryWithInstall); + cJSON_AddStringToObject(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, + distro.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, + distro.moduleType.c_str()); + cJSON_AddBoolToObject(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, + distro.installationFree); + return true; } -void to_json(nlohmann::json &jsonObject, const Dependency &dependency) +bool to_json(cJSON *jsonObject, const Dependency &dependency) { - jsonObject = nlohmann::json { - {Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName}, - {Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName}, - {Profile::APP_VERSION_CODE, dependency.versionCode} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, Profile::APP_VERSION_CODE, static_cast(dependency.versionCode)); + return true; } -void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) +bool to_json(cJSON *jsonObject, const InnerModuleInfo &info) { - jsonObject = nlohmann::json { - {NAME, info.name}, - {MODULE_PACKAGE, info.modulePackage}, - {MODULE_NAME, info.moduleName}, - {MODULE_PATH, info.modulePath}, - {MODULE_DATA_DIR, info.moduleDataDir}, - {MODULE_RES_PATH, info.moduleResPath}, - {MODULE_IS_ENTRY, info.isEntry}, - {MODULE_METADATA, info.metaData}, - {MODULE_COLOR_MODE, info.colorMode}, - {MODULE_DISTRO, info.distro}, - {MODULE_DESCRIPTION, info.description}, - {MODULE_DESCRIPTION_ID, info.descriptionId}, - {MODULE_ICON, info.icon}, - {MODULE_ICON_ID, info.iconId}, - {MODULE_LABEL, info.label}, - {MODULE_LABEL_ID, info.labelId}, - {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree}, - {MODULE_IS_REMOVABLE, info.isRemovable}, - {MODULE_UPGRADE_FLAG, info.upgradeFlag}, - {MODULE_REQ_CAPABILITIES, info.reqCapabilities}, - {MODULE_ABILITY_KEYS, info.abilityKeys}, - {MODULE_MAIN_ABILITY, info.mainAbility}, - {MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey}, - {MODULE_SRC_PATH, info.srcPath}, - {MODULE_HASH_VALUE, info.hashValue}, - {MODULE_PROCESS, info.process}, - {MODULE_SRC_ENTRANCE, info.srcEntrance}, - {MODULE_DEVICE_TYPES, info.deviceTypes}, - {MODULE_VIRTUAL_MACHINE, info.virtualMachine}, - {MODULE_UI_SYNTAX, info.uiSyntax}, - {MODULE_PAGES, info.pages}, - {MODULE_META_DATA, info.metadata}, - {MODULE_EXTENSION_KEYS, info.extensionKeys}, - {MODULE_IS_MODULE_JSON, info.isModuleJson}, - {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel}, - {MODULE_DEPENDENCIES, info.dependencies}, - {MODULE_IS_LIB_ISOLATED, info.isLibIsolated}, - {MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath}, - {MODULE_CPU_ABI, info.cpuAbi}, - {MODULE_HAP_PATH, info.hapPath}, - {MODULE_COMPILE_MODE, info.compileMode}, - {MODULE_TARGET_MODULE_NAME, info.targetModuleName}, - {MODULE_TARGET_PRIORITY, info.targetPriority}, - {MODULE_ATOMIC_SERVICE_MODULE_TYPE, info.atomicServiceModuleType}, - {MODULE_PRELOADS, info.preloads}, - {MODULE_BUNDLE_TYPE, info.bundleType}, - {MODULE_VERSION_CODE, info.versionCode}, - {MODULE_VERSION_NAME, info.versionName}, - {MODULE_PROXY_DATAS, info.proxyDatas}, - {MODULE_BUILD_HASH, info.buildHash}, - {MODULE_ISOLATION_MODE, info.isolationMode}, - {MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs}, - {MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames}, - {MODULE_AOT_COMPILE_STATUS, info.aotCompileStatus}, - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + + cJSON_AddStringToObject(jsonObject, NAME.c_str(), info.name.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_PACKAGE.c_str(), info.modulePackage.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_NAME.c_str(), info.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_PATH.c_str(), info.modulePath.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_DATA_DIR.c_str(), info.moduleDataDir.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_RES_PATH.c_str(), info.moduleResPath.c_str()); + cJSON_AddBoolToObject(jsonObject, MODULE_IS_ENTRY.c_str(), info.isEntry); + + cJSON *metaDataItem = nullptr; + if (!to_json(metaDataItem, info.metaData)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metaData failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_METADATA.c_str(), metaDataItem); + + cJSON_AddNumberToObject(jsonObject, MODULE_COLOR_MODE.c_str(), static_cast(info.colorMode)); + + cJSON *distroItem = nullptr; + if (!to_json(distroItem, info.distro)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json distro failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_DISTRO.c_str(), distroItem); + + cJSON_AddStringToObject(jsonObject, MODULE_DESCRIPTION.c_str(), info.description.c_str()); + cJSON_AddNumberToObject(jsonObject, MODULE_DESCRIPTION_ID.c_str(), static_cast(info.descriptionId)); + cJSON_AddStringToObject(jsonObject, MODULE_ICON.c_str(), info.icon.c_str()); + cJSON_AddNumberToObject(jsonObject, MODULE_ICON_ID.c_str(), static_cast(info.iconId)); + cJSON_AddStringToObject(jsonObject, MODULE_LABEL.c_str(), info.label.c_str()); + cJSON_AddNumberToObject(jsonObject, MODULE_LABEL_ID.c_str(), static_cast(info.labelId)); + cJSON_AddBoolToObject(jsonObject, MODULE_DESCRIPTION_INSTALLATION_FREE.c_str(), info.installationFree); + + cJSON *isRemovableItem = nullptr; + if (!to_json(isRemovableItem, info.isRemovable)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json isRemovable failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_IS_REMOVABLE.c_str(), isRemovableItem); + + cJSON_AddNumberToObject(jsonObject, MODULE_UPGRADE_FLAG.c_str(), static_cast(info.upgradeFlag)); + + cJSON *reqCapabilitiesItem = nullptr; + if (!to_json(reqCapabilitiesItem, info.reqCapabilities)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json reqCapabilities failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_REQ_CAPABILITIES.c_str(), reqCapabilitiesItem); + + cJSON *abilityKeysItem = nullptr; + if (!to_json(abilityKeysItem, info.abilityKeys)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json abilityKeys failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_ABILITY_KEYS.c_str(), abilityKeysItem); + + cJSON_AddStringToObject(jsonObject, MODULE_MAIN_ABILITY.c_str(), info.mainAbility.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_ENTRY_ABILITY_KEY.c_str(), info.entryAbilityKey.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_SRC_PATH.c_str(), info.srcPath.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_HASH_VALUE.c_str(), info.hashValue.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_PROCESS.c_str(), info.process.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_SRC_ENTRANCE.c_str(), info.srcEntrance.c_str()); + + cJSON *deviceTypesItem = nullptr; + if (!to_json(deviceTypesItem, info.deviceTypes)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json deviceTypes failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_DEVICE_TYPES.c_str(), deviceTypesItem); + + cJSON_AddStringToObject(jsonObject, MODULE_VIRTUAL_MACHINE.c_str(), info.virtualMachine.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_UI_SYNTAX.c_str(), info.uiSyntax.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_PAGES.c_str(), info.pages.c_str()); + + cJSON *metadataItem = nullptr; + if (!to_json(metadataItem, info.metadata)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json metadata failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_META_DATA.c_str(), metadataItem); + + cJSON *extensionKeysItem = nullptr; + if (!to_json(extensionKeysItem, info.extensionKeys)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json extensionKeys failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_EXTENSION_KEYS.c_str(), extensionKeysItem); + + cJSON_AddBoolToObject(jsonObject, MODULE_IS_MODULE_JSON.c_str(), info.isModuleJson); + cJSON_AddBoolToObject(jsonObject, MODULE_IS_STAGE_BASED_MODEL.c_str(), info.isStageBasedModel); + + cJSON *dependenciesItem = nullptr; + if (!to_json(dependenciesItem, info.dependencies)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json dependencies failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_DEPENDENCIES.c_str(), dependenciesItem); + + cJSON_AddBoolToObject(jsonObject, MODULE_IS_LIB_ISOLATED.c_str(), info.isLibIsolated); + cJSON_AddStringToObject(jsonObject, MODULE_NATIVE_LIBRARY_PATH.c_str(), info.nativeLibraryPath.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_CPU_ABI.c_str(), info.cpuAbi.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_HAP_PATH.c_str(), info.hapPath.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_COMPILE_MODE.c_str(), info.compileMode.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_TARGET_MODULE_NAME.c_str(), info.targetModuleName.c_str()); + cJSON_AddNumberToObject(jsonObject, MODULE_TARGET_PRIORITY.c_str(), static_cast(info.targetPriority)); + cJSON_AddNumberToObject(jsonObject, MODULE_ATOMIC_SERVICE_MODULE_TYPE.c_str(), + static_cast(info.atomicServiceModuleType)); + + cJSON *preloadsItem = nullptr; + if (!to_json(preloadsItem, info.preloads)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json preloads failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_PRELOADS.c_str(), preloadsItem); + + cJSON_AddNumberToObject(jsonObject, MODULE_BUNDLE_TYPE.c_str(), static_cast(info.bundleType)); + cJSON_AddNumberToObject(jsonObject, MODULE_VERSION_CODE.c_str(), static_cast(info.versionCode)); + cJSON_AddStringToObject(jsonObject, MODULE_VERSION_NAME.c_str(), info.versionName.c_str()); + + cJSON *proxyDatasItem = nullptr; + if (!to_json(proxyDatasItem, info.proxyDatas)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json proxyDatas failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_PROXY_DATAS.c_str(), proxyDatasItem); + + cJSON_AddStringToObject(jsonObject, MODULE_BUILD_HASH.c_str(), info.buildHash.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_ISOLATION_MODE.c_str(), info.isolationMode.c_str()); + cJSON_AddBoolToObject(jsonObject, MODULE_COMPRESS_NATIVE_LIBS.c_str(), info.compressNativeLibs); + + cJSON *nativeLibraryFileNamesItem = nullptr; + if (!to_json(nativeLibraryFileNamesItem, info.nativeLibraryFileNames)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json nativeLibraryFileNames failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_NATIVE_LIBRARY_FILE_NAMES.c_str(), nativeLibraryFileNamesItem); + + cJSON_AddNumberToObject(jsonObject, MODULE_AOT_COMPILE_STATUS.c_str(), static_cast(info.aotCompileStatus)); + return true; } -void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const +bool InnerBundleInfo::ToJson(cJSON *jsonObject) const { - jsonObject[APP_TYPE] = appType_; - jsonObject[BUNDLE_STATUS] = bundleStatus_; - jsonObject[ALLOWED_ACLS] = allowedAcls_; - jsonObject[BASE_APPLICATION_INFO] = *baseApplicationInfo_; - jsonObject[BASE_BUNDLE_INFO] = *baseBundleInfo_; - jsonObject[BASE_ABILITY_INFO] = baseAbilityInfos_; - jsonObject[INNER_MODULE_INFO] = innerModuleInfos_; - jsonObject[USER_ID] = userId_; - jsonObject[APP_FEATURE] = appFeature_; - jsonObject[BUNDLE_IS_NEW_VERSION] = isNewVersion_; - jsonObject[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_; - jsonObject[APP_INDEX] = appIndex_; - jsonObject[BUNDLE_IS_SANDBOX_APP] = isSandboxApp_; - jsonObject[OVERLAY_TYPE] = overlayType_; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddNumberToObject(jsonObject, APP_TYPE.c_str(), static_cast(appType_)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_STATUS.c_str(), static_cast(bundleStatus_)); + + cJSON *allowedAclsItem = nullptr; + if (!to_json(allowedAclsItem, allowedAcls_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json allowedAcls failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, ALLOWED_ACLS.c_str(), allowedAclsItem); + + cJSON *baseApplicationInfoItem = nullptr; + if (!to_json(baseApplicationInfoItem, *baseApplicationInfo_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json baseApplicationInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BASE_APPLICATION_INFO.c_str(), baseApplicationInfoItem); + + cJSON *baseBundleInfoItem = nullptr; + if (!to_json(baseBundleInfoItem, *baseBundleInfo_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json baseBundleInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BASE_BUNDLE_INFO.c_str(), baseBundleInfoItem); + + cJSON *baseAbilityInfosItem = nullptr; + if (!to_json(baseAbilityInfosItem, baseAbilityInfos_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json baseAbilityInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BASE_ABILITY_INFO.c_str(), baseAbilityInfosItem); + + cJSON *innerModuleInfosItem = nullptr; + if (!to_json(innerModuleInfosItem, innerModuleInfos_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json innerModuleInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INNER_MODULE_INFO.c_str(), innerModuleInfosItem); + + cJSON_AddNumberToObject(jsonObject, USER_ID.c_str(), static_cast(userId_)); + cJSON_AddStringToObject(jsonObject, APP_FEATURE.c_str(), appFeature_.c_str()); + cJSON_AddBoolToObject(jsonObject, BUNDLE_IS_NEW_VERSION.c_str(), isNewVersion_); + + cJSON *baseExtensionInfosItem = nullptr; + if (!to_json(baseExtensionInfosItem, baseExtensionInfos_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json baseExtensionInfos failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, BUNDLE_BASE_EXTENSION_INFOS.c_str(), baseExtensionInfosItem); + + cJSON_AddNumberToObject(jsonObject, APP_INDEX.c_str(), static_cast(appIndex_)); + cJSON_AddBoolToObject(jsonObject, BUNDLE_IS_SANDBOX_APP.c_str(), isSandboxApp_); + cJSON_AddNumberToObject(jsonObject, OVERLAY_TYPE.c_str(), static_cast(overlayType_)); + return true; } -void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info) +void from_json(const cJSON *jsonObject, InnerModuleInfo &info) { // these are not required fields. - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - NAME, - info.name, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PACKAGE, - info.modulePackage, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_NAME, - info.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PATH, - info.modulePath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DATA_DIR, - info.moduleDataDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_HAP_PATH, - info.hapPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_RES_PATH, - info.moduleResPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_IS_ENTRY, - info.isEntry, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_METADATA, - info.metaData, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_COLOR_MODE, - info.colorMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DISTRO, - info.distro, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DESCRIPTION, - info.description, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DESCRIPTION_ID, - info.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ICON, - info.icon, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ICON_ID, - info.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_LABEL, - info.label, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_LABEL_ID, - info.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_MAIN_ABILITY, - info.mainAbility, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ENTRY_ABILITY_KEY, - info.entryAbilityKey, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_SRC_PATH, - info.srcPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_HASH_VALUE, - info.hashValue, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DESCRIPTION_INSTALLATION_FREE, - info.installationFree, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_IS_REMOVABLE, - info.isRemovable, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_UPGRADE_FLAG, - info.upgradeFlag, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_REQ_CAPABILITIES, - info.reqCapabilities, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_ABILITY_KEYS, - info.abilityKeys, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PROCESS, - info.process, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_SRC_ENTRANCE, - info.srcEntrance, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_DEVICE_TYPES, - info.deviceTypes, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_VIRTUAL_MACHINE, - info.virtualMachine, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_UI_SYNTAX, - info.uiSyntax, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PAGES, - info.pages, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_META_DATA, - info.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_EXTENSION_KEYS, - info.extensionKeys, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_IS_MODULE_JSON, - info.isModuleJson, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_IS_STAGE_BASED_MODEL, - info.isStageBasedModel, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_DEPENDENCIES, - info.dependencies, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_COMPILE_MODE, - info.compileMode, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_IS_LIB_ISOLATED, - info.isLibIsolated, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_NATIVE_LIBRARY_PATH, - info.nativeLibraryPath, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_CPU_ABI, - info.cpuAbi, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TARGET_MODULE_NAME, - info.targetModuleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TARGET_PRIORITY, - info.targetPriority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ATOMIC_SERVICE_MODULE_TYPE, - info.atomicServiceModuleType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_PRELOADS, - info.preloads, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_BUNDLE_TYPE, - info.bundleType, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_VERSION_CODE, - info.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_VERSION_NAME, - info.versionName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_PROXY_DATAS, - info.proxyDatas, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_BUILD_HASH, - info.buildHash, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ISOLATION_MODE, - info.isolationMode, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_COMPRESS_NATIVE_LIBS, - info.compressNativeLibs, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_NATIVE_LIBRARY_FILE_NAMES, - info.nativeLibraryFileNames, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_AOT_COMPILE_STATUS, - info.aotCompileStatus, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, NAME, info.name, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PACKAGE, info.modulePackage, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_NAME, info.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PATH, info.modulePath, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_DATA_DIR, info.moduleDataDir, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_HAP_PATH, info.hapPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_RES_PATH, info.moduleResPath, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_IS_ENTRY, info.isEntry, false, parseResult); + GetObjectValueIfFindKey(jsonObject, MODULE_METADATA, info.metaData, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_COLOR_MODE, info.colorMode, false, parseResult); + GetObjectValueIfFindKey(jsonObject, MODULE_DISTRO, info.distro, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_DESCRIPTION, info.description, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_DESCRIPTION_ID, info.descriptionId, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_ICON, info.icon, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_ICON_ID, info.iconId, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_LABEL, info.label, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_LABEL_ID, info.labelId, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_MAIN_ABILITY, info.mainAbility, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_SRC_PATH, info.srcPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_HASH_VALUE, info.hashValue, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree, false, parseResult); + GetBoolValueMapIfFindKey(jsonObject, MODULE_IS_REMOVABLE, info.isRemovable, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_UPGRADE_FLAG, info.upgradeFlag, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_REQ_CAPABILITIES, info.reqCapabilities, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_ABILITY_KEYS, info.abilityKeys, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PROCESS, info.process, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_SRC_ENTRANCE, info.srcEntrance, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_DEVICE_TYPES, info.deviceTypes, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_VIRTUAL_MACHINE, info.virtualMachine, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_UI_SYNTAX, info.uiSyntax, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PAGES, info.pages, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_META_DATA, info.metadata, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_EXTENSION_KEYS, info.extensionKeys, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_IS_MODULE_JSON, info.isModuleJson, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_DEPENDENCIES, info.dependencies, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_COMPILE_MODE, info.compileMode, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_IS_LIB_ISOLATED, info.isLibIsolated, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_CPU_ABI, info.cpuAbi, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_TARGET_MODULE_NAME, info.targetModuleName, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_TARGET_PRIORITY, info.targetPriority, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_ATOMIC_SERVICE_MODULE_TYPE, info.atomicServiceModuleType, false, + parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_PRELOADS, info.preloads, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_BUNDLE_TYPE, info.bundleType, false, parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_VERSION_CODE, info.versionCode, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_VERSION_NAME, info.versionName, false, parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_PROXY_DATAS, info.proxyDatas, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_BUILD_HASH, info.buildHash, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_ISOLATION_MODE, info.isolationMode, false, parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames, false, + parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_AOT_COMPILE_STATUS, info.aotCompileStatus, false, parseResult); if (parseResult != ERR_OK) { - TAG_LOGE( - AAFwkTag::ABILITY_SIM, "read InnerModuleInfo from database error:%{public}d", parseResult); + TAG_LOGE(AAFwkTag::ABILITY_SIM, "read InnerModuleInfo from database error:%{public}d", parseResult); } } -void from_json(const nlohmann::json &jsonObject, Dependency &dependency) +void from_json(const cJSON *jsonObject, Dependency &dependency) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Profile::DEPENDENCIES_MODULE_NAME, - dependency.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Profile::DEPENDENCIES_BUNDLE_NAME, - dependency.bundleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Profile::APP_VERSION_CODE, - dependency.versionCode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName, false, parseResult); + GetNumberValueIfFindKey(jsonObject, Profile::APP_VERSION_CODE, dependency.versionCode, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "Dependency error:%{public}d", parseResult); } } -void from_json(const nlohmann::json &jsonObject, Distro &distro) +void from_json(const cJSON *jsonObject, Distro &distro) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "called"); - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, - distro.deliveryWithInstall, - JsonType::BOOLEAN, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, - distro.moduleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, - distro.moduleType, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); + GetBoolValueIfFindKey(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, + distro.deliveryWithInstall, true, parseResult); + GetStringValueIfFindKey(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName, true, + parseResult); + GetStringValueIfFindKey(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType, true, + parseResult); // mustFlag decide by distro.moduleType - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, - distro.installationFree, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetBoolValueIfFindKey(jsonObject, ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, + distro.installationFree, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "Distro error:%{public}d", parseResult); } } -int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject) +int32_t InnerBundleInfo::FromJson(const cJSON *jsonObject) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TYPE, - appType_, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - ALLOWED_ACLS, - allowedAcls_, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_STATUS, - bundleStatus_, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BASE_BUNDLE_INFO, - *baseBundleInfo_, - JsonType::OBJECT, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BASE_APPLICATION_INFO, - *baseApplicationInfo_, - JsonType::OBJECT, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BASE_ABILITY_INFO, - baseAbilityInfos_, - JsonType::OBJECT, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INNER_MODULE_INFO, - innerModuleInfos_, - JsonType::OBJECT, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - USER_ID, - userId_, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_FEATURE, - appFeature_, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_IS_NEW_VERSION, - isNewVersion_, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - BUNDLE_BASE_EXTENSION_INFOS, - baseExtensionInfos_, - JsonType::OBJECT, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_INDEX, - appIndex_, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_IS_SANDBOX_APP, - isSandboxApp_, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - OVERLAY_TYPE, - overlayType_, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); + GetNumberValueIfFindKey(jsonObject, APP_TYPE, appType_, true, parseResult); + GetStringValuesIfFindKey(jsonObject, ALLOWED_ACLS, allowedAcls_, false, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_STATUS, bundleStatus_, true, parseResult); + GetObjectValueIfFindKey(jsonObject, BASE_BUNDLE_INFO, *baseBundleInfo_, true, parseResult); + GetObjectValueIfFindKey(jsonObject, BASE_APPLICATION_INFO, *baseApplicationInfo_, true, parseResult); + GetObjectValueMapIfFindKey(jsonObject, BASE_ABILITY_INFO, baseAbilityInfos_, true, parseResult); + GetObjectValueMapIfFindKey(jsonObject, INNER_MODULE_INFO, innerModuleInfos_, true, parseResult); + GetNumberValueIfFindKey(jsonObject, USER_ID, userId_, true, parseResult); + GetStringValueIfFindKey(jsonObject, APP_FEATURE, appFeature_, true, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_IS_NEW_VERSION, isNewVersion_, false, parseResult); + GetObjectValueMapIfFindKey(jsonObject, BUNDLE_BASE_EXTENSION_INFOS, baseExtensionInfos_, false, parseResult); + GetNumberValueIfFindKey(jsonObject, APP_INDEX, appIndex_, false, parseResult); + GetBoolValueIfFindKey(jsonObject, BUNDLE_IS_SANDBOX_APP, isSandboxApp_, false, parseResult); + GetNumberValueIfFindKey(jsonObject, OVERLAY_TYPE, overlayType_, false, parseResult); if (parseResult != ERR_OK) { TAG_LOGE( AAFwkTag::ABILITY_SIM, "read InnerBundleInfo from database error:%{public}d", parseResult); @@ -1055,9 +694,14 @@ ErrCode InnerBundleInfo::FindAbilityInfo( std::string InnerBundleInfo::ToString() const { - nlohmann::json j; - ToJson(j); - return j.dump(); + cJSON *jsonObject = nullptr; + if (!ToJson(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ToJson failed"); + return {}; + } + std::string jsonStr = JsonToString(jsonObject); + cJSON_Delete(jsonObject); + return jsonStr; } void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/json_util.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/json_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..593afb1c0bf993a991f232f7692e067d13760540 --- /dev/null +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/json_util.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2023-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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "json_util.h" + +namespace OHOS { +namespace AppExecFwk { + +std::string JsonToString(const cJSON *jsonObject) +{ + if (jsonObject == nullptr) { + return {}; + } + char *str = cJSON_PrintUnformatted(jsonObject); + if (str == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json string failed"); + return {}; + } + std::string jsonStr(str); + cJSON_free(str); + return jsonStr; +} + +void GetStringValueIfFindKey(const cJSON *jsonObject, + const std::string &key, std::string &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsString(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not string", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + if (std::string(item->valuestring).length() > Constants::MAX_JSON_ELEMENT_LENGTH) { + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR; + return; + } + data = item->valuestring; +} + +void GetStringValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsString(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not string list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + if (std::string(item->valuestring).length() > Constants::MAX_JSON_ELEMENT_LENGTH) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s string length error", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR; + return; + } + std::string value = childItem->valuestring; + data.push_back(value); + } +} + +void GetUnorderedSetValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::unordered_set &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsString(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not string list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + if (std::string(item->valuestring).length() > Constants::MAX_JSON_ELEMENT_LENGTH) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s string length error", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR; + return; + } + std::string value = childItem->valuestring; + data.emplace(value); + } +} + +void GetBoolValueIfFindKey(const cJSON *jsonObject, + const std::string &key, bool &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsBool(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + data = item->type == cJSON_True ? true : false; +} + +void GetBoolValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + bool value = childItem->type == cJSON_True ? true : false; + data.push_back(value); + } +} + +void GetBoolValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + bool value = childItem->type == cJSON_True ? true : false; + data.emplace(key, value); + } +} + +void GetBoolValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + std::vector value; + from_json(childItem, value); + data.emplace(key, value); + } +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/module_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/module_info.cpp index 93ec5e8c8075696e9f41d94ed03aedd7f714e3e5..4155e0c1503e0f9ad7bee677cd8875b843ae64ff 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/module_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/module_info.cpp @@ -17,7 +17,6 @@ #include "hilog_tag_wrapper.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -26,46 +25,35 @@ namespace { const std::string MODULE_INFO_MODULE_SOURCE_DIR = "moduleSourceDir"; const std::string MODULE_INFO_PRELOADS = "preloads"; } -void to_json(nlohmann::json &jsonObject, const ModuleInfo &moduleInfo) + +bool to_json(cJSON *jsonObject, const ModuleInfo &moduleInfo) { - jsonObject = nlohmann::json { - {Constants::MODULE_NAME, moduleInfo.moduleName}, - {MODULE_INFO_MODULE_SOURCE_DIR, moduleInfo.moduleSourceDir}, - {MODULE_INFO_PRELOADS, moduleInfo.preloads} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, Constants::MODULE_NAME, moduleInfo.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, MODULE_INFO_MODULE_SOURCE_DIR.c_str(), moduleInfo.moduleSourceDir.c_str()); + + cJSON *preloadsItem = nullptr; + if (!to_json(preloadsItem, moduleInfo.preloads)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json preloads failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, MODULE_INFO_PRELOADS.c_str(), preloadsItem); + return true; } -void from_json(const nlohmann::json &jsonObject, ModuleInfo &moduleInfo) +void from_json(const cJSON *jsonObject, ModuleInfo &moduleInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - moduleInfo.moduleName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_INFO_MODULE_SOURCE_DIR, - moduleInfo.moduleSourceDir, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_INFO_PRELOADS, - moduleInfo.preloads, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); + GetStringValueIfFindKey(jsonObject, Constants::MODULE_NAME, moduleInfo.moduleName, false, parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_INFO_MODULE_SOURCE_DIR, moduleInfo.moduleSourceDir, false, parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_INFO_PRELOADS, moduleInfo.preloads, false, parseResult); if (parseResult != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITY_SIM, - "read module moduleInfo error:%{public}d", parseResult); + TAG_LOGE(AAFwkTag::ABILITY_SIM, "read module moduleInfo error:%{public}d", parseResult); } } } // namespace AppExecFwk diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/module_profile.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/module_profile.cpp index 340281e1c58608dbaf996d62e1e35687cf9991b7..a5632365105320abc6b8fbbb92606962eb788d17 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/module_profile.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/module_profile.cpp @@ -286,1095 +286,262 @@ struct ModuleJson { Module module; }; -void from_json(const nlohmann::json &jsonObject, Metadata &metadata) +void from_json(const cJSON *jsonObject, Metadata &metadata) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read metadata tag from module.json"); - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_NAME, - metadata.name, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_VALUE, - metadata.value, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - META_DATA_RESOURCE, - metadata.resource, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, META_DATA_NAME, metadata.name, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, META_DATA_VALUE, metadata.value, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, META_DATA_RESOURCE, metadata.resource, false, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, Ability &ability) +void from_json(const cJSON *jsonObject, Ability &ability) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read ability tag from module.json"); - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_NAME, - ability.name, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, ABILITY_NAME, ability.name, true, g_parseResult); // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority - if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRY, - ability.srcEntrance, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); + cJSON *srcEntryItem = cJSON_GetObjectItem(jsonObject, SRC_ENTRY); + if (srcEntryItem != nullptr) { + GetStringValueIfFindKey(jsonObject, SRC_ENTRY, ability.srcEntrance, true, g_parseResult); } else { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - ability.srcEntrance, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - } - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_LAUNCH_TYPE, - ability.launchType, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - ability.description, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - ability.descriptionId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - ability.icon, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - ability.iconId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - ability.label, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - ability.labelId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - ability.priority, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - ability.permissions, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - ability.metadata, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); + GetStringValueIfFindKey(jsonObject, SRC_ENTRANCE, ability.srcEntrance, true, g_parseResult); + } + GetStringValueIfFindKey(jsonObject, ABILITY_LAUNCH_TYPE, ability.launchType, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, DESCRIPTION, ability.description, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, DESCRIPTION_ID, ability.descriptionId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, ICON, ability.icon, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ICON_ID, ability.iconId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, LABEL, ability.label, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, LABEL_ID, ability.labelId, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, PRIORITY, ability.priority, false, g_parseResult); + GetStringValuesIfFindKey(jsonObject, PERMISSIONS, ability.permissions, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, META_DATA, ability.metadata, false, g_parseResult); // both exported and visible can be configured, but exported has higher priority - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - ability.visible, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXPORTED, - ability.visible, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_CONTINUABLE, - ability.continuable, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - ABILITY_BACKGROUNDMODES, - ability.backgroundModes, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_START_WINDOW_ICON, - ability.startWindowIcon, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_START_WINDOW_ICON_ID, - ability.startWindowIconId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_START_WINDOW_BACKGROUND, - ability.startWindowBackground, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_START_WINDOW_BACKGROUND_ID, - ability.startWindowBackgroundId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_REMOVE_MISSION_AFTER_TERMINATE, - ability.removeMissionAfterTerminate, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_ORIENTATION, - ability.orientation, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - ABILITY_SUPPORT_WINDOW_MODE, - ability.windowModes, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MAX_WINDOW_RATIO, - ability.maxWindowRatio, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MIN_WINDOW_RATIO, - ability.minWindowRatio, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MAX_WINDOW_WIDTH, - ability.maxWindowWidth, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MIN_WINDOW_WIDTH, - ability.minWindowWidth, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MAX_WINDOW_HEIGHT, - ability.maxWindowHeight, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_MIN_WINDOW_HEIGHT, - ability.minWindowHeight, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_EXCLUDE_FROM_MISSIONS, - ability.excludeFromMissions, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_RECOVERABLE, - ability.recoverable, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ABILITY_UNCLEARABLE_MISSION, - ability.unclearableMission, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetBoolValueIfFindKey(jsonObject, VISIBLE, ability.visible, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, EXPORTED, ability.visible, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, ABILITY_CONTINUABLE, ability.continuable, false, g_parseResult); + GetStringValuesIfFindKey(jsonObject, ABILITY_BACKGROUNDMODES, ability.backgroundModes, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, ABILITY_START_WINDOW_ICON, ability.startWindowIcon, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_START_WINDOW_ICON_ID, ability.startWindowIconId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, ABILITY_START_WINDOW_BACKGROUND, ability.startWindowBackground, false, + g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_START_WINDOW_BACKGROUND_ID, ability.startWindowBackgroundId, false, + g_parseResult); + GetBoolValueIfFindKey(jsonObject, ABILITY_REMOVE_MISSION_AFTER_TERMINATE, ability.removeMissionAfterTerminate, + false, g_parseResult); + GetStringValueIfFindKey(jsonObject, ABILITY_ORIENTATION, ability.orientation, false, g_parseResult); + GetStringValuesIfFindKey(jsonObject, ABILITY_SUPPORT_WINDOW_MODE, ability.windowModes, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MAX_WINDOW_RATIO, ability.maxWindowRatio, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MIN_WINDOW_RATIO, ability.minWindowRatio, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MAX_WINDOW_WIDTH, ability.maxWindowWidth, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MIN_WINDOW_WIDTH, ability.minWindowWidth, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MAX_WINDOW_HEIGHT, ability.maxWindowHeight, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ABILITY_MIN_WINDOW_HEIGHT, ability.minWindowHeight, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, ABILITY_EXCLUDE_FROM_MISSIONS, ability.excludeFromMissions, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, ABILITY_RECOVERABLE, ability.recoverable, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, ABILITY_UNCLEARABLE_MISSION, ability.unclearableMission, false, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, Extension &extension) +void from_json(const cJSON *jsonObject, Extension &extension) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read extension tag from module.json"); - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_ABILITY_NAME, - extension.name, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "jsonObject is null"); + return false; + } + GetStringValueIfFindKey(jsonObject, EXTENSION_ABILITY_NAME, extension.name, true, g_parseResult); // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority - if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRY, - extension.srcEntrance, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); + cJSON *srcEntryItem = cJSON_GetObjectItem(jsonObject, SRC_ENTRY); + if (srcEntryItem != nullptr) { + GetStringValueIfFindKey(jsonObject, SRC_ENTRY, extension.srcEntrance, true, g_parseResult); } else { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - extension.srcEntrance, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - } - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - extension.icon, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - extension.iconId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - extension.label, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - extension.labelId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - extension.description, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - extension.descriptionId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - extension.priority, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_ABILITY_TYPE, - extension.type, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_ABILITY_READ_PERMISSION, - extension.readPermission, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_ABILITY_WRITE_PERMISSION, - extension.writePermission, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_URI, - extension.uri, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - extension.permissions, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); + GetStringValueIfFindKey(jsonObject, SRC_ENTRANCE, extension.srcEntrance, true, g_parseResult); + } + GetStringValueIfFindKey(jsonObject, ICON, extension.icon, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ICON_ID, extension.iconId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, LABEL, extension.label, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, LABEL_ID, extension.labelId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, DESCRIPTION, extension.description, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, DESCRIPTION_ID, extension.descriptionId, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, PRIORITY, extension.priority, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, EXTENSION_ABILITY_TYPE, extension.type, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, EXTENSION_ABILITY_READ_PERMISSION, extension.readPermission, false, + g_parseResult); + GetStringValueIfFindKey(jsonObject, EXTENSION_ABILITY_WRITE_PERMISSION, extension.writePermission, false, + g_parseResult); + GetStringValueIfFindKey(jsonObject, EXTENSION_URI, extension.uri, false, g_parseResult); + GetStringValuesIfFindKey(jsonObject, PERMISSIONS, extension.permissions, false, g_parseResult); // both exported and visible can be configured, but exported has higher priority - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - extension.visible, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXPORTED, - extension.visible, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - extension.metadata, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); + GetBoolValueIfFindKey(jsonObject, VISIBLE, extension.visible, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, EXPORTED, extension.visible, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, META_DATA, extension.metadata, false, g_parseResult); + if (g_parseResult != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "g_parseResult:%{public}d", g_parseResult); + return false; + } + return true; } -void from_json(const nlohmann::json &jsonObject, DeviceConfig &deviceConfig) +void from_json(const cJSON *jsonObject, DeviceConfig &deviceConfig) { - const auto &jsonObjectEnd = jsonObject.end(); - if (jsonObject.find(MIN_API_VERSION) != jsonObjectEnd) { + cJSON *minApiVersionItem = cJSON_GetObjectItem(jsonObject, MIN_API_VERSION); + if (minApiVersionItem != nullptr) { deviceConfig.minAPIVersion.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MIN_API_VERSION, - deviceConfig.minAPIVersion.second, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - if (jsonObject.find(DEVICE_CONFIG_KEEP_ALIVE) != jsonObjectEnd) { + GetNumberValueIfFindKey(jsonObject, MIN_API_VERSION, deviceConfig.minAPIVersion.second, false, g_parseResult); + } + cJSON *deviceConfigKeepAliveItem = cJSON_GetObjectItem(jsonObject, DEVICE_CONFIG_KEEP_ALIVE); + if (deviceConfigKeepAliveItem != nullptr) { deviceConfig.keepAlive.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DEVICE_CONFIG_KEEP_ALIVE, - deviceConfig.keepAlive.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - if (jsonObject.find(DEVICE_CONFIG_REMOVABLE) != jsonObjectEnd) { + GetBoolValueIfFindKey(jsonObject, DEVICE_CONFIG_KEEP_ALIVE, deviceConfig.keepAlive.second, false, + g_parseResult); + } + cJSON *deviceConfigRemovableItem = cJSON_GetObjectItem(jsonObject, DEVICE_CONFIG_REMOVABLE); + if (deviceConfigRemovableItem != nullptr) { deviceConfig.removable.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DEVICE_CONFIG_REMOVABLE, - deviceConfig.removable.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - if (jsonObject.find(DEVICE_CONFIG_SINGLETON) != jsonObjectEnd) { + GetBoolValueIfFindKey(jsonObject, DEVICE_CONFIG_REMOVABLE, deviceConfig.removable.second, false, g_parseResult); + } + cJSON *deviceConfigSingletonItem = cJSON_GetObjectItem(jsonObject, DEVICE_CONFIG_SINGLETON); + if (deviceConfigSingletonItem != nullptr) { deviceConfig.singleton.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DEVICE_CONFIG_SINGLETON, - deviceConfig.singleton.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - if (jsonObject.find(DEVICE_CONFIG_USER_DATA_CLEARABLE) != jsonObjectEnd) { + GetBoolValueIfFindKey(jsonObject, DEVICE_CONFIG_SINGLETON, deviceConfig.singleton.second, false, g_parseResult); + } + cJSON *deviceConfigUserDataClearableItem = cJSON_GetObjectItem(jsonObject, DEVICE_CONFIG_USER_DATA_CLEARABLE); + if (deviceConfigUserDataClearableItem != nullptr) { deviceConfig.userDataClearable.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DEVICE_CONFIG_USER_DATA_CLEARABLE, - deviceConfig.userDataClearable.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - if (jsonObject.find(DEVICE_CONFIG_ACCESSIBLE) != jsonObjectEnd) { + GetBoolValueIfFindKey(jsonObject, DEVICE_CONFIG_USER_DATA_CLEARABLE, deviceConfig.userDataClearable.second, + false, g_parseResult); + } + cJSON *deviceConfigAccessibleItem = cJSON_GetObjectItem(jsonObject, DEVICE_CONFIG_ACCESSIBLE); + if (deviceConfigAccessibleItem != nullptr) { deviceConfig.accessible.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DEVICE_CONFIG_ACCESSIBLE, - deviceConfig.accessible.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetBoolValueIfFindKey(jsonObject, DEVICE_CONFIG_ACCESSIBLE, deviceConfig.accessible.second, false, + g_parseResult); } } -void from_json(const nlohmann::json &jsonObject, App &app) +void from_json(const cJSON *jsonObject, App &app) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read app tag from module.json"); - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_BUNDLE_NAME, - app.bundleName, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - app.icon, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - app.label, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_VERSION_CODE, - app.versionCode, - JsonType::NUMBER, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_VERSION_NAME, - app.versionName, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_MIN_API_VERSION, - app.minAPIVersion, - JsonType::NUMBER, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TARGET_API_VERSION, - app.targetAPIVersion, - JsonType::NUMBER, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_DEBUG, - app.debug, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - app.iconId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - app.labelId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - app.description, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - app.descriptionId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_VENDOR, - app.vendor, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_MIN_COMPATIBLE_VERSION_CODE, - app.minCompatibleVersionCode, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_API_RELEASETYPE, - app.apiReleaseType, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_KEEP_ALIVE, - app.keepAlive, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APP_TARGETBUNDLELIST, - app.targetBundleList, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); - if (jsonObject.find(APP_REMOVABLE) != jsonObject.end()) { + GetStringValueIfFindKey(jsonObject, APP_BUNDLE_NAME, app.bundleName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, ICON, app.icon, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, LABEL, app.label, true, g_parseResult); + GetNumberValueIfFindKey(jsonObject, APP_VERSION_CODE, app.versionCode, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, APP_VERSION_NAME, app.versionName, true, g_parseResult); + GetNumberValueIfFindKey(jsonObject, APP_MIN_API_VERSION, app.minAPIVersion, true, g_parseResult); + GetNumberValueIfFindKey(jsonObject, APP_TARGET_API_VERSION, app.targetAPIVersion, true, g_parseResult); + GetBoolValueIfFindKey(jsonObject, APP_DEBUG, app.debug, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, ICON_ID, app.iconId, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, LABEL_ID, app.labelId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, DESCRIPTION, app.description, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, DESCRIPTION_ID, app.descriptionId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, APP_VENDOR, app.vendor, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, APP_MIN_COMPATIBLE_VERSION_CODE, app.minCompatibleVersionCode, false, + g_parseResult); + GetStringValueIfFindKey(jsonObject, APP_API_RELEASETYPE, app.apiReleaseType, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, APP_KEEP_ALIVE, app.keepAlive, false, g_parseResult); + cJSON *appRemovableItem = cJSON_GetObjectItem(jsonObject, APP_REMOVABLE); + if (appRemovableItem != nullptr) { app.removable.first = true; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_REMOVABLE, - app.removable.second, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_SINGLETON, - app.singleton, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_USER_DATA_CLEARABLE, - app.userDataClearable, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ACCESSIBLE, - app.accessible, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ASAN_ENABLED, - app.asanEnabled, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_TYPE, - app.bundleType, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - if (jsonObject.find(APP_PHONE) != jsonObjectEnd) { + GetBoolValueIfFindKey(jsonObject, APP_REMOVABLE, app.removable.second, false, g_parseResult); + } + GetBoolValueIfFindKey(jsonObject, APP_SINGLETON, app.singleton, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, APP_USER_DATA_CLEARABLE, app.userDataClearable, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, APP_ACCESSIBLE, app.accessible, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, APP_ASAN_ENABLED, app.asanEnabled, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_TYPE, app.bundleType, false, g_parseResult); + cJSON *appPhoneItem = cJSON_GetObjectItem(jsonObject, APP_PHONE); + if (appPhoneItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_PHONE, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_PHONE, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_PHONE] = deviceConfig; } - if (jsonObject.find(APP_TABLET) != jsonObjectEnd) { + cJSON *appTableItem = cJSON_GetObjectItem(jsonObject, APP_TABLET); + if (appTableItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TABLET, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_TABLET, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_TABLET] = deviceConfig; } - if (jsonObject.find(APP_TV) != jsonObjectEnd) { + cJSON *appTvItem = cJSON_GetObjectItem(jsonObject, APP_TV); + if (appTvItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TV, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_TV, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_TV] = deviceConfig; } - if (jsonObject.find(APP_WEARABLE) != jsonObjectEnd) { + cJSON *appWearableItem = cJSON_GetObjectItem(jsonObject, APP_WEARABLE); + if (appWearableItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_WEARABLE, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_WEARABLE, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_WEARABLE] = deviceConfig; } - if (jsonObject.find(APP_LITE_WEARABLE) != jsonObjectEnd) { + cJSON *appLiteWearableItem = cJSON_GetObjectItem(jsonObject, APP_LITE_WEARABLE); + if (appLiteWearableItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_LITE_WEARABLE, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_LITE_WEARABLE, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_LITE_WEARABLE] = deviceConfig; } - if (jsonObject.find(APP_CAR) != jsonObjectEnd) { + cJSON *appCarItem = cJSON_GetObjectItem(jsonObject, APP_CAR); + if (appCarItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_CAR, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_CAR, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_CAR] = deviceConfig; } - if (jsonObject.find(APP_SMART_VISION) != jsonObjectEnd) { + cJSON *appSmartVersionItem = cJSON_GetObjectItem(jsonObject, APP_SMART_VISION); + if (appSmartVersionItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_SMART_VISION, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_SMART_VISION, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_SMART_VISION] = deviceConfig; } - if (jsonObject.find(APP_ROUTER) != jsonObjectEnd) { + cJSON *appRouterItem = cJSON_GetObjectItem(jsonObject, APP_ROUTER); + if (appRouterItem != nullptr) { DeviceConfig deviceConfig; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_ROUTER, - deviceConfig, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP_ROUTER, deviceConfig, false, g_parseResult); app.deviceConfigs[APP_ROUTER] = deviceConfig; } - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_MULTI_PROJECTS, - app.multiProjects, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TARGET_BUNDLE_NAME, - app.targetBundle, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_TARGET_PRIORITY, - app.targetPriority, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_SDK_VERSION, - app.compileSdkVersion, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_SDK_TYPE, - app.compileSdkType, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetBoolValueIfFindKey(jsonObject, APP_MULTI_PROJECTS, app.multiProjects, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, APP_TARGET_BUNDLE_NAME, app.targetBundle, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, APP_TARGET_PRIORITY, app.targetPriority, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, COMPILE_SDK_VERSION, app.compileSdkVersion, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, COMPILE_SDK_TYPE, app.compileSdkType, false, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, Module &module) +void from_json(const cJSON *jsonObject, Module &module) { TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module tag from module.json"); - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_NAME, - module.name, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TYPE, - module.type, - JsonType::STRING, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_DEVICE_TYPES, - module.deviceTypes, - JsonType::ARRAY, - true, - g_parseResult, - ArrayType::STRING); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_DELIVERY_WITH_INSTALL, - module.deliveryWithInstall, - JsonType::BOOLEAN, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PAGES, - module.pages, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, MODULE_NAME, module.name, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_TYPE, module.type, true, g_parseResult); + GetStringValuesIfFindKey(jsonObject, MODULE_DEVICE_TYPES, module.deviceTypes, true, g_parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_DELIVERY_WITH_INSTALL, module.deliveryWithInstall, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PAGES, module.pages, false, g_parseResult); // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority - if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRY, - module.srcEntrance, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + cJSON *srcEntryItem = cJSON_GetObjectItem(jsonObject, SRC_ENTRY); + if (srcEntryItem != nullptr) { + GetStringValueIfFindKey(jsonObject, SRC_ENTRY, module.srcEntrance, false, g_parseResult); } else { - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - module.srcEntrance, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - } - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - module.description, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - module.descriptionId, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_PROCESS, - module.process, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_MAIN_ELEMENT, - module.mainElement, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_INSTALLATION_FREE, - module.installationFree, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_VIRTUAL_MACHINE, - module.virtualMachine, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - module.metadata, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_ABILITIES, - module.abilities, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_EXTENSION_ABILITIES, - module.extensionAbilities, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_DEPENDENCIES, - module.dependencies, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_COMPILE_MODE, - module.compileMode, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_IS_LIB_ISOLATED, - module.isLibIsolated, - JsonType::BOOLEAN, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TARGET_MODULE_NAME, - module.targetModule, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_TARGET_PRIORITY, - module.targetPriority, - JsonType::NUMBER, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_PROXY_DATAS, - module.proxyDatas, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - MODULE_PROXY_DATA, - module.proxyData, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_BUILD_HASH, - module.buildHash, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE_ISOLATION_MODE, - module.isolationMode, - JsonType::STRING, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, SRC_ENTRANCE, module.srcEntrance, false, g_parseResult); + } + GetStringValueIfFindKey(jsonObject, DESCRIPTION, module.description, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, DESCRIPTION_ID, module.descriptionId, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_PROCESS, module.process, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_MAIN_ELEMENT, module.mainElement, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_INSTALLATION_FREE, module.installationFree, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_VIRTUAL_MACHINE, module.virtualMachine, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, META_DATA, module.metadata, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_ABILITIES, module.abilities, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_EXTENSION_ABILITIES, module.extensionAbilities, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_DEPENDENCIES, module.dependencies, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_COMPILE_MODE, module.compileMode, false, g_parseResult); + GetBoolValueIfFindKey(jsonObject, MODULE_IS_LIB_ISOLATED, module.isLibIsolated, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_TARGET_MODULE_NAME, module.targetModule, false, g_parseResult); + GetNumberValueIfFindKey(jsonObject, MODULE_TARGET_PRIORITY, module.targetPriority, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_PROXY_DATAS, module.proxyDatas, false, g_parseResult); + GetObjectValuesIfFindKey(jsonObject, MODULE_PROXY_DATA, module.proxyData, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_BUILD_HASH, module.buildHash, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, MODULE_ISOLATION_MODE, module.isolationMode, false, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, ModuleJson &moduleJson) +void from_json(const cJSON *jsonObject, ModuleJson &moduleJson) { - const auto &jsonObjectEnd = jsonObject.end(); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP, - moduleJson.app, - JsonType::OBJECT, - true, - g_parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - MODULE, - moduleJson.module, - JsonType::OBJECT, - true, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, APP, moduleJson.app, true, g_parseResult); + GetObjectValueIfFindKey(jsonObject, MODULE, moduleJson.module, true, g_parseResult); } } // namespace Profile @@ -1827,59 +994,90 @@ bool ToInnerBundleInfo(const Profile::ModuleJson &moduleJson, InnerBundleInfo &i return true; } -bool ParserAtomicModuleConfig(const nlohmann::json &jsonObject, InnerBundleInfo &innerBundleInfo) +bool ParseAtomicServicePreloads(const cJSON *jsonObject, std::vector &preloads) { - nlohmann::json moduleJson = jsonObject.at(Profile::MODULE); + if (!cJSON_IsArray(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "jsonObject not array"); + return false; + } + int size = cJSON_GetArraySize(jsonObject); + if (size == 0) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "jsonObject is empty"); + return true; + } + if (size > Constants::MAX_JSON_ARRAY_LENGTH) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads config in module.json is oversize"); + return false; + } + for (int i = 0; i < size; i++) { + cJSON *preloadItem = cJSON_GetArrayItem(jsonObject, i); + if (preloadItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads is null"); + return false; + } + cJSON *preloadsModuleNameItem = cJSON_GetObjectItem(preloadItem, Profile::PRELOADS_MODULE_NAME); + if (preloadsModuleNameItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads must have moduleName"); + return false; + } + std::string preloadName = preloadsModuleNameItem->valuestring; + preloads.emplace_back(preloadName); + } + return true; +} + +bool ParserAtomicModuleConfig(const cJSON *jsonObject, InnerBundleInfo &innerBundleInfo) +{ + cJSON *moduleJson = cJSON_GetObjectItem(jsonObject, Profile::MODULE); + if (moduleJson == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "get module json failed"); + return false; + } + cJSON *moduleNameItem = cJSON_GetObjectItem(moduleJson, Profile::MODULE_NAME); + if (moduleNameItem == nullptr || !cJSON_IsString(moduleNameItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "get module name failed"); + return false; + } + std::string moduleName = moduleNameItem->valuestring; std::vector preloads; - std::string moduleName = moduleJson.at(Profile::MODULE_NAME); - if (moduleJson.contains(Profile::ATOMIC_SERVICE)) { - nlohmann::json moduleAtomicObj = moduleJson.at(Profile::ATOMIC_SERVICE); - if (moduleAtomicObj.contains(Profile::MODULE_ATOMIC_SERVICE_PRELOADS)) { - nlohmann::json preloadObj = moduleAtomicObj.at(Profile::MODULE_ATOMIC_SERVICE_PRELOADS); - if (preloadObj.empty()) { - TAG_LOGE(AAFwkTag::ABILITY_SIM, "reloadObj is empty"); - return true; - } - if (preloadObj.size() > Constants::MAX_JSON_ARRAY_LENGTH) { - TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads config in module.json is oversize"); + cJSON *moduleAtomicObj = cJSON_GetObjectItem(moduleJson, Profile::ATOMIC_SERVICE); + if (moduleAtomicObj != nullptr) { + cJSON *preloadObj = cJSON_GetObjectItem(moduleAtomicObj, Profile::MODULE_ATOMIC_SERVICE_PRELOADS); + if (preloadObj != nullptr) { + if (!ParseAtomicServicePreloads(preloadObj, preloads)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "reloadObj not array"); return false; } - for (const auto &preload : preloadObj) { - if (preload.contains(Profile::PRELOADS_MODULE_NAME)) { - std::string preloadName = preload.at(Profile::PRELOADS_MODULE_NAME); - preloads.emplace_back(preloadName); - } else { - TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads must have moduleName"); - return false; - } - } } } innerBundleInfo.SetInnerModuleAtomicPreload(moduleName, preloads); return true; } -bool ParserAtomicConfig(const nlohmann::json &jsonObject, InnerBundleInfo &innerBundleInfo) +bool ParserAtomicConfig(const cJSON *jsonObject, InnerBundleInfo &innerBundleInfo) { - if (!jsonObject.contains(Profile::MODULE) || !jsonObject.contains(Profile::APP)) { + cJSON *moduleJson = cJSON_GetObjectItem(jsonObject, Profile::MODULE); + cJSON *appJson = cJSON_GetObjectItem(jsonObject, Profile::APP); + if (moduleJson == nullptr || appJson == nullptr) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "ParserAtomicConfig failed due to bad module.json"); return false; } - nlohmann::json appJson = jsonObject.at(Profile::APP); - nlohmann::json moduleJson = jsonObject.at(Profile::MODULE); - if (!moduleJson.is_object() || !appJson.is_object()) { + + if (!cJSON_IsObject(moduleJson) || !cJSON_IsObject(appJson)) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "module.json file lacks of invalid module or app properties"); return false; } BundleType bundleType = BundleType::APP; - if (appJson.contains(Profile::BUNDLE_TYPE)) { - if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_ATOMIC_SERVICE) { + cJSON *bundleTypeItem = cJSON_GetObjectItem(appJson, Profile::BUNDLE_TYPE); + if (bundleTypeItem != nullptr && cJSON_IsString(bundleTypeItem)) { + std::string type = bundleTypeItem->valuestring; + if (type == Profile::BUNDLE_TYPE_ATOMIC_SERVICE) { bundleType = BundleType::ATOMIC_SERVICE; - } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_SHARED) { + } else if (type == Profile::BUNDLE_TYPE_SHARED) { bundleType = BundleType::SHARED; - } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_APP_SERVICE_FWK) { + } else if (type == Profile::BUNDLE_TYPE_APP_SERVICE_FWK) { bundleType = BundleType::APP_SERVICE_FWK; - } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_PLUGIN) { + } else if (type == Profile::BUNDLE_TYPE_PLUGIN) { bundleType = BundleType::APP_PLUGIN; } } @@ -1898,13 +1096,16 @@ ErrCode ModuleProfile::TransformTo(const std::vector &buf, InnerBundleI TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform module.json stream to InnerBundleInfo"); std::vector buffer = buf; buffer.push_back('\0'); - nlohmann::json jsonObject = nlohmann::json::parse(buffer.data(), nullptr, false); - if (jsonObject.is_discarded()) { + std::string dataStr(buffer.begin(), buffer.end()); + cJSON *jsonObject = cJSON_Parse(dataStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "bad profile"); return ERR_APPEXECFWK_PARSE_BAD_PROFILE; } - Profile::ModuleJson moduleJson = jsonObject.get(); + Profile::ModuleJson moduleJson; + from_json(jsonObject, moduleJson); + cJSON_Delete(jsonObject); if (Profile::g_parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "g_parseResult:%{public}d", Profile::g_parseResult); int32_t ret = Profile::g_parseResult; diff --git a/frameworks/simulator/ability_simulator/src/bundle_parser/overlay_bundle_info.cpp b/frameworks/simulator/ability_simulator/src/bundle_parser/overlay_bundle_info.cpp index 0ea15bda3a1f16e77c58d5bc18f3a37ef4388afb..81099dd6d783e052871083478d27c37761e816ce 100644 --- a/frameworks/simulator/ability_simulator/src/bundle_parser/overlay_bundle_info.cpp +++ b/frameworks/simulator/ability_simulator/src/bundle_parser/overlay_bundle_info.cpp @@ -18,7 +18,6 @@ #include "bundle_constants.h" #include "hilog_tag_wrapper.h" #include "json_util.h" -#include "nlohmann/json.hpp" #include "string_ex.h" namespace OHOS { @@ -30,52 +29,27 @@ const char* BUNDLE_OVERLAY_BUNDLE_STATE = "state"; const char* BUNDLE_OVERLAY_BUNDLE_PRIORITY = "priority"; } // namespace -void to_json(nlohmann::json &jsonObject, const OverlayBundleInfo &overlayBundleInfo) +bool to_json(cJSON *jsonObject, const OverlayBundleInfo &overlayBundleInfo) { - jsonObject = nlohmann::json { - {BUNDLE_OVERLAY_BUNDLE_NAME, overlayBundleInfo.bundleName}, - {BUNDLE_OVERLAY_BUNDLE_DIR, overlayBundleInfo.bundleDir}, - {BUNDLE_OVERLAY_BUNDLE_STATE, overlayBundleInfo.state}, - {BUNDLE_OVERLAY_BUNDLE_PRIORITY, overlayBundleInfo.priority} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, BUNDLE_OVERLAY_BUNDLE_NAME, overlayBundleInfo.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, BUNDLE_OVERLAY_BUNDLE_DIR, overlayBundleInfo.bundleDir.c_str()); + cJSON_AddNumberToObject(jsonObject, BUNDLE_OVERLAY_BUNDLE_STATE, static_cast(overlayBundleInfo.state)); + cJSON_AddNumberToObject(jsonObject, BUNDLE_OVERLAY_BUNDLE_PRIORITY, static_cast(overlayBundleInfo.priority)); + return true; } -void from_json(const nlohmann::json &jsonObject, OverlayBundleInfo &overlayBundleInfo) +void from_json(const cJSON *jsonObject, OverlayBundleInfo &overlayBundleInfo) { - const auto &jsonObjectEnd = jsonObject.end(); int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_OVERLAY_BUNDLE_NAME, - overlayBundleInfo.bundleName, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_OVERLAY_BUNDLE_DIR, - overlayBundleInfo.bundleDir, - JsonType::STRING, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_OVERLAY_BUNDLE_STATE, - overlayBundleInfo.state, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - BUNDLE_OVERLAY_BUNDLE_PRIORITY, - overlayBundleInfo.priority, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); + GetStringValueIfFindKey(jsonObject, BUNDLE_OVERLAY_BUNDLE_NAME, overlayBundleInfo.bundleName, true, parseResult); + GetStringValueIfFindKey(jsonObject, BUNDLE_OVERLAY_BUNDLE_DIR, overlayBundleInfo.bundleDir, true, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_OVERLAY_BUNDLE_STATE, overlayBundleInfo.state, true, parseResult); + GetNumberValueIfFindKey(jsonObject, BUNDLE_OVERLAY_BUNDLE_PRIORITY, overlayBundleInfo.priority, true, parseResult); if (parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITY_SIM, "overlayBundleInfo from_json error : %{public}d", parseResult); } diff --git a/frameworks/simulator/ability_simulator/src/simulator.cpp b/frameworks/simulator/ability_simulator/src/simulator.cpp index c1d66661d95e78015a2572e2de31ab1d65c55c5a..f47ae08331610e47155edc985c396416d36df1fd 100644 --- a/frameworks/simulator/ability_simulator/src/simulator.cpp +++ b/frameworks/simulator/ability_simulator/src/simulator.cpp @@ -160,7 +160,7 @@ private: void GetPkgContextInfoListMap(const std::map &contextInfoMap, std::map>> &pkgContextInfoMap, std::map &pkgAliasMap); - void GetPkgContextInfoListInner(nlohmann::json &itemObject, std::vector &items, + void GetPkgContextInfoListInner(cJSON *itemObject, std::vector &items, std::map &pkgAliasMap, std::string &pkgName); }; @@ -288,9 +288,14 @@ bool SimulatorImpl::ParseBundleAndModuleInfo() TAG_LOGE(AAFwkTag::ABILITY_SIM, "appinfo parse failed"); return false; } - nlohmann::json appInfoJson; - to_json(appInfoJson, *appInfo_); - std::cout << "appinfo : " << appInfoJson.dump() << std::endl; + cJSON *appInfoJson = nullptr; + if (!to_json(appInfoJson, *appInfo_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json appInfo failed"); + return false; + } + std::string appInfoJsonStr = AppExecFwk::JsonToString(appInfoJson); + cJSON_Delete(appInfoJson); + std::cout << "appinfo : " << appInfoJsonStr << std::endl; AppExecFwk::BundleContainer::GetInstance().LoadDependencyHspInfo(appInfo_->bundleName, options_.dependencyHspInfos); AppExecFwk::BundleContainer::GetInstance().SetBundleCodeDir(options_.previewPath); @@ -314,9 +319,14 @@ bool SimulatorImpl::ParseBundleAndModuleInfo() TAG_LOGE(AAFwkTag::ABILITY_SIM, "module info parse failed"); return false; } - nlohmann::json moduleInfoJson; - to_json(moduleInfoJson, *moduleInfo_); - std::cout << "moduleInfo : " << moduleInfoJson.dump() << std::endl; + cJSON *moduleInfoJson = nullptr; + if (!to_json(moduleInfoJson, *moduleInfo_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json moduleInfo failed"); + return false; + } + std::string moduleInfoJsonStr = AppExecFwk::JsonToString(moduleInfoJson); + cJSON_Delete(moduleInfoJson); + std::cout << "moduleInfo : " << moduleInfoJsonStr << std::endl; options_.pageProfile = moduleInfo_->pages; options_.enablePartialUpdate = true; @@ -345,9 +355,13 @@ bool SimulatorImpl::ParseAbilityInfo(const std::string &abilitySrcPath, const st TAG_LOGE(AAFwkTag::ABILITY_SIM, "ability info parse failed"); return false; } - nlohmann::json json; - to_json(json, *abilityInfo_); - std::cout << "abilityInfo : " << json.dump() << std::endl; + cJSON *jsonObject = nullptr; + if (!to_json(jsonObject, *abilityInfo_)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json abilityInfo failed"); + return false; + } + std::string jsonStr = AppExecFwk::JsonToString(jsonObject); + std::cout << "abilityInfo : " << jsonStr << std::endl; options_.labelId = abilityInfo_->labelId; return true; @@ -957,76 +971,85 @@ void SimulatorImpl::GetPkgContextInfoListMap(const std::map> pkgContextInfoList; - auto jsonObject = nlohmann::json::parse(it->second); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(it->second.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::JSRUNTIME, "moduleName: %{public}s parse json error", it->first.c_str()); continue; } - for (nlohmann::json::iterator jsonIt = jsonObject.begin(); jsonIt != jsonObject.end(); jsonIt++) { + cJSON *childItem = jsonObject->child; + while (childItem != nullptr) { std::vector items; - items.emplace_back(jsonIt.key()); - nlohmann::json itemObject = jsonIt.value(); + std::string key = childItem->string == nullptr ? "" : childItem->string; + items.emplace_back(key); + std::string pkgName = ""; items.emplace_back(PACKAGE_NAME); - if (itemObject[PACKAGE_NAME].is_null() || !itemObject[PACKAGE_NAME].is_string()) { - items.emplace_back(pkgName); - } else { - pkgName = itemObject[PACKAGE_NAME].get(); - items.emplace_back(pkgName); + cJSON *packageNameItem = cJSON_GetObjectItem(childItem, PACKAGE_NAME.c_str()); + if (packageNameItem != nullptr && cJSON_IsString(packageNameItem)) { + pkgName = packageNameItem->valuestring; } + items.emplace_back(pkgName); + std::string bundleName = ""; items.emplace_back(BUNDLE_NAME); - if (itemObject[BUNDLE_NAME].is_null() || !itemObject[BUNDLE_NAME].is_string()) { - items.emplace_back(""); - } else { - items.emplace_back(itemObject[BUNDLE_NAME].get()); + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME.c_str()); + if (bundleNameItem != nullptr && cJSON_IsString(bundleNameItem)) { + bundleName = bundleNameItem->valuestring; } + items.emplace_back(bundleName); + std::string moduleName = ""; items.emplace_back(MODULE_NAME); - if (itemObject[MODULE_NAME].is_null() || !itemObject[MODULE_NAME].is_string()) { - items.emplace_back(""); - } else { - items.emplace_back(itemObject[MODULE_NAME].get()); + cJSON *moduleNameItem = cJSON_GetObjectItem(childItem, MODULE_NAME.c_str()); + if (moduleNameItem != nullptr && cJSON_IsString(moduleNameItem)) { + moduleName = moduleNameItem->valuestring; } + items.emplace_back(moduleName); - GetPkgContextInfoListInner(itemObject, items, pkgAliasMap, pkgName); + GetPkgContextInfoListInner(childItem, items, pkgAliasMap, pkgName); pkgContextInfoList.emplace_back(items); + + childItem = childItem->next; } + cJSON_Delete(jsonObject); TAG_LOGI(AAFwkTag::JSRUNTIME, "moduleName: %{public}s parse json success", it->first.c_str()); pkgContextInfoMap[it->first] = pkgContextInfoList; } } -void SimulatorImpl::GetPkgContextInfoListInner(nlohmann::json &itemObject, std::vector &items, +void SimulatorImpl::GetPkgContextInfoListInner(cJSON *itemObject, std::vector &items, std::map &pkgAliasMap, std::string &pkgName) { items.emplace_back(VERSION); - if (itemObject[VERSION].is_null() || !itemObject[VERSION].is_string()) { + cJSON *versionItem = cJSON_GetObjectItem(itemObject, VERSION.c_str()); + if (versionItem == nullptr || !cJSON_IsString(versionItem)) { items.emplace_back(""); } else { - items.emplace_back(itemObject[VERSION].get()); + std::string version = versionItem->valuestring; + items.emplace_back(version); } items.emplace_back(ENTRY_PATH); - if (itemObject[ENTRY_PATH].is_null() || !itemObject[ENTRY_PATH].is_string()) { + cJSON *entryPathItem = cJSON_GetObjectItem(itemObject, ENTRY_PATH.c_str()); + if (entryPathItem == nullptr || !cJSON_IsString(entryPathItem)) { items.emplace_back(""); } else { - items.emplace_back(itemObject[ENTRY_PATH].get()); + std::string entryPath = entryPathItem->valuestring; + items.emplace_back(entryPath); } items.emplace_back(IS_SO); - if (itemObject[IS_SO].is_null() || !itemObject[IS_SO].is_boolean()) { + cJSON *isSoItem = cJSON_GetObjectItem(itemObject, IS_SO.c_str()); + if (isSoItem == nullptr || !cJSON_IsBool(isSoItem)) { items.emplace_back("false"); } else { - bool isSo = itemObject[IS_SO].get(); - if (isSo) { - items.emplace_back("true"); - } else { - items.emplace_back("false"); - } + std::string isSo = isSoItem->type == cJSON_True ? "true" : "false"; + items.emplace_back(isSo); } - if (!itemObject[DEPENDENCY_ALIAS].is_null() && itemObject[DEPENDENCY_ALIAS].is_string()) { - std::string pkgAlias = itemObject[DEPENDENCY_ALIAS].get(); + + cJSON *dependencyAliasItem = cJSON_GetObjectItem(itemObject, DEPENDENCY_ALIAS.c_str()); + if (dependencyAliasItem != nullptr && cJSON_IsString(dependencyAliasItem)) { + std::string pkgAlias = dependencyAliasItem->valuestring; if (!pkgAlias.empty()) { pkgAliasMap[pkgAlias] = pkgName; } diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 8bb1055efa0185b2c06da59016a9a25776c4c803..815c5baa284510a7ab41c81c458216e7f57fb647 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -89,6 +89,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_param.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/intent_exemption_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/keep_alive/keep_alive_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/last_exit_detail_info.cpp", @@ -143,6 +144,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_services_path}/abilitymgr:wantagent_manager", + "${ability_runtime_services_path}/common:app_util", ] external_deps = [ @@ -155,7 +157,6 @@ ohos_shared_library("ability_manager") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", - "jsoncpp:jsoncpp", "relational_store:native_dataability", "samgr:samgr_proxy", ] @@ -174,7 +175,6 @@ ohos_shared_library("ability_manager") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "init:libbegetutil", - "jsoncpp:jsoncpp", "relational_store:native_dataability", "relational_store:native_rdb", ] @@ -266,7 +266,6 @@ ohos_shared_library("mission_info") { "ability_base:zuri", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "jsoncpp:jsoncpp", ] if (ability_runtime_graphics) { external_deps += [ "image_framework:image_native" ] @@ -313,7 +312,6 @@ ohos_shared_library("ability_start_setting") { "ability_base:zuri", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] if (ability_runtime_graphics) { diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 39ea4c18d2406607ef95399cddcc6f7b36e5eaa3..76369987d6c167a2d12c23c2834dc7af6f791827 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -152,7 +152,6 @@ ohos_shared_library("app_manager") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "samgr:samgr_proxy", ] public_external_deps = [ diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_process_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_process_data.cpp index 4888aa7333a00210ccef1401ce0d8a1ca146a80f..a35cfe0970ed16e886b36765ac7ab531a3c0f33c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_process_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_process_data.cpp @@ -17,7 +17,6 @@ #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" #include "string_ex.h" #include "parcel_macro_base.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/background_app_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/background_app_info.cpp index fb595e481420cb244675a550546d8ea560b2a4cc..1f0da6063c4f46d3cde3f96a972b10eadd8f5316 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/background_app_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/background_app_info.cpp @@ -15,7 +15,6 @@ #include "background_app_info.h" #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" #include "parcel_macro_base.h" #include "string_ex.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp index eadf4b493b6213860858c9ff4f5f90245adc7fb0..c3fc678db84c4e9eae3c95665d3031a1255fe467 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/child_process_info.cpp @@ -16,7 +16,6 @@ #include "child_process_info.h" #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" #include "parcel_macro_base.h" #include "string_ex.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp index 43ec5d4d419ee52810ec9dc4688e237d2933def8..96bf8b6982c47511d3dd5a257ad89932ae95570c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp @@ -15,7 +15,6 @@ #include "fault_data.h" -#include "nlohmann/json.hpp" #include "string_ex.h" #include "hilog_tag_wrapper.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/render_process_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/render_process_info.cpp index 399fb6c9c738f9aeb4e2207bba73963c3b98ea05..d83f50cb827b42e69ee49f26cbbfee666c3a03d9 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/render_process_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/render_process_info.cpp @@ -15,7 +15,6 @@ #include "render_process_info.h" -#include "nlohmann/json.hpp" #include "string_ex.h" #include "hilog_tag_wrapper.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp index 0203439de2829209b5262901630a9ca33d366c5e..8dc1bae4f0c26438a66a092d8290882fac834c47 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp @@ -15,7 +15,6 @@ #include "running_multi_info.h" -#include "nlohmann/json.hpp" #include "string_ex.h" #include "hilog_tag_wrapper.h" diff --git a/interfaces/inner_api/app_manager/src/appmgr/running_process_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/running_process_info.cpp index 496197617cd366f2583e498060d49ccec9d79741..250e047ecae5683af215885586e8f1e124e6dcfa 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/running_process_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/running_process_info.cpp @@ -15,7 +15,6 @@ #include "running_process_info.h" -#include "nlohmann/json.hpp" #include "string_ex.h" #include "hilog_tag_wrapper.h" diff --git a/interfaces/inner_api/runtime/BUILD.gn b/interfaces/inner_api/runtime/BUILD.gn index 92cb0dda4fa6e65c3dd2f5b67a9009c57de8ac1d..a3afe70a157a2e24a437b033e6e2a33af97c8ee0 100644 --- a/interfaces/inner_api/runtime/BUILD.gn +++ b/interfaces/inner_api/runtime/BUILD.gn @@ -117,8 +117,6 @@ ohos_shared_library("runtime") { "i18n:intl_register", "init:syscap_ts", "ipc:ipc_core", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", diff --git a/interfaces/inner_api/runtime/include/js_runtime_lite.h b/interfaces/inner_api/runtime/include/js_runtime_lite.h index 66557c579a6d706febe7c2577fd5d8fa407ec09e..6ae888798b07cfe9fe3148aed2a5b2d3dc0bb365 100644 --- a/interfaces/inner_api/runtime/include/js_runtime_lite.h +++ b/interfaces/inner_api/runtime/include/js_runtime_lite.h @@ -21,10 +21,10 @@ #include #include +#include "cJSON.h" #include "js_environment.h" #include "native_engine/native_engine.h" #include "runtime.h" -#include using Options = OHOS::AbilityRuntime::Runtime::Options; namespace OHOS { @@ -57,11 +57,10 @@ private: void SetRequestAotCallback(const std::shared_ptr& jsEnv); bool InitLoop(const std::shared_ptr& jsEnv); void InitWorkerModule(const Options& options, const std::shared_ptr& jsEnv); - void ParsePkgContextInfoJson( - nlohmann::json &pkgJson, std::vector> &pkgContextInfoList, + void ParsePkgContextInfoJson(cJSON *pkgJson, std::vector> &pkgContextInfoList, std::map &pkgAliasMap); - void ParsePkgContextInfoJsonString( - const nlohmann::json &itemObject, const std::string &key, std::vector &items); + void ParsePkgContextInfoJsonString(const cJSON *itemObject, const std::string &key, + std::vector &items); void SetChildOptions(const Options& options); std::unordered_map> envMap_; std::unordered_set threadIds_; diff --git a/interfaces/inner_api/wantagent/BUILD.gn b/interfaces/inner_api/wantagent/BUILD.gn index a9f3008821ce8144f55e241721e9ab01b90077d1..00a7c4493f95c49d7db8ba903b480d0a23c82197 100644 --- a/interfaces/inner_api/wantagent/BUILD.gn +++ b/interfaces/inner_api/wantagent/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("wantagent_innerkits") { "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util", "${ability_runtime_services_path}/abilitymgr:wantagent_manager", + "${ability_runtime_services_path}/common:app_util", ] external_deps = [ diff --git a/interfaces/inner_api/wantagent/include/want_agent_helper.h b/interfaces/inner_api/wantagent/include/want_agent_helper.h index 5e838b02b60ac1de04f5bb704750b7f5fa605198..46f647558316470c7c974f727c93a189e4d58669 100644 --- a/interfaces/inner_api/wantagent/include/want_agent_helper.h +++ b/interfaces/inner_api/wantagent/include/want_agent_helper.h @@ -18,11 +18,11 @@ #include #include +#include "cJSON.h" #include "context/application_context.h" #include "completed_callback.h" #include "completed_dispatcher.h" #include "event_handler.h" -#include "nlohmann/json.hpp" #include "trigger_info.h" #include "want.h" #include "want_agent.h" @@ -196,7 +196,7 @@ private: static unsigned int FlagsTransformer(const std::vector &flags); - static std::vector ParseFlags(nlohmann::json jsonObject); + static std::vector ParseFlags(cJSON *jsonObject); }; } // namespace OHOS::AbilityRuntime::WantAgent #endif // OHOS_ABILITY_RUNTIME_WANT_AGENT_HELPER_H diff --git a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp index fbe194df57df074eed4208b73e262a9890a45850..5aed03f5eaa42129735c5b2bc05e5f516273157c 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp @@ -18,6 +18,7 @@ #include "ability_runtime_error_util.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" +#include "json_utils.h" #include "want_params_wrapper.h" #include "pending_want.h" #include "want_agent_client.h" @@ -343,39 +344,63 @@ std::string WantAgentHelper::ToString(const std::shared_ptr &agent) { if (agent == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); - return ""; + return {}; } std::shared_ptr pendingWant = agent->GetPendingWant(); if (pendingWant == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); - return ""; + return {}; } std::shared_ptr info = pendingWant->GetWantSenderInfo(pendingWant->GetTarget()); if (info == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid param"); - return ""; + return {}; } - nlohmann::json jsonObject; - jsonObject["requestCode"] = (*info.get()).requestCode; - jsonObject["operationType"] = (*info.get()).type; - jsonObject["flags"] = (*info.get()).flags; - nlohmann::json wants = nlohmann::json::array(); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "create json object failed"); + return {}; + } + + cJSON_AddNumberToObject(jsonObject, "requestCode", static_cast((*info.get()).requestCode)); + cJSON_AddNumberToObject(jsonObject, "operationType", static_cast((*info.get()).type)); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast((*info.get()).flags)); + + cJSON *wants = cJSON_CreateArray(); + if (wants == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "create wants object failed"); + cJSON_Delete(jsonObject); + return {}; + } for (auto &wantInfo : (*info.get()).allWants) { - wants.emplace_back(wantInfo.want.ToString()); + cJSON *wantItem = cJSON_CreateString(wantInfo.want.ToString().c_str()); + if (wantItem == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "create want object failed"); + cJSON_Delete(jsonObject); + cJSON_Delete(wants); + return {}; + } + cJSON_AddItemToArray(wants, wantItem); } - jsonObject["wants"] = wants; + cJSON_AddItemToObject(jsonObject, "wants", wants); if ((*info.get()).allWants.size() > 0) { - nlohmann::json paramsObj; + cJSON *paramsObj = cJSON_CreateObject(); + if (paramsObj == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "create params object failed"); + cJSON_Delete(jsonObject); + return {}; + } AAFwk::WantParamWrapper wWrapper((*info.get()).allWants[0].want.GetParams()); - paramsObj["extraInfoValue"] = wWrapper.ToString(); - jsonObject["extraInfo"] = paramsObj; + cJSON_AddStringToObject(paramsObj, "extraInfoValue", wWrapper.ToString().c_str()); + cJSON_AddItemToObject(jsonObject, "extraInfo", paramsObj); } - - return jsonObject.dump(); + std::string jsonStr = OHOS::AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + return jsonStr; } std::shared_ptr WantAgentHelper::FromString(const std::string &jsonString, int32_t uid) @@ -383,55 +408,64 @@ std::shared_ptr WantAgentHelper::FromString(const std::string &jsonSt if (jsonString.empty()) { return nullptr; } - nlohmann::json jsonObject = nlohmann::json::parse(jsonString); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(jsonString.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "Failed to parse json string"); return nullptr; } int requestCode = -1; - if (jsonObject.contains("requestCode") && jsonObject["requestCode"].is_number_integer()) { - requestCode = jsonObject.at("requestCode").get(); + cJSON *requestCodeItem = cJSON_GetObjectItem(jsonObject, "requestCode"); + if (requestCodeItem != nullptr && cJSON_IsNumber(requestCodeItem)) { + requestCode = static_cast(requestCodeItem->valuedouble); } WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::UNKNOWN_TYPE; - if (jsonObject.contains("operationType") && jsonObject["operationType"].is_number_integer()) { - operationType = static_cast(jsonObject.at("operationType").get()); + cJSON *operationTypeItem = cJSON_GetObjectItem(jsonObject, "operationType"); + if (operationTypeItem != nullptr && cJSON_IsNumber(operationTypeItem)) { + operationType = static_cast(static_cast(operationTypeItem->valuedouble)); } std::vector flagsVec = ParseFlags(jsonObject); std::vector> wants = {}; - if (jsonObject.contains("wants") && jsonObject["wants"].is_array()) { - for (auto &wantObj : jsonObject.at("wants")) { - if (wantObj.is_string()) { - auto wantString = wantObj.get(); + cJSON *wantsItem = cJSON_GetObjectItem(jsonObject, "wants"); + if (wantsItem != nullptr && cJSON_IsArray(wantsItem)) { + int size = cJSON_GetArraySize(wantsItem); + for (int i = 0; i < size; i++) { + cJSON *wantItem = cJSON_GetArrayItem(wantsItem, i); + if (wantItem != nullptr && cJSON_IsString(wantItem)) { + std::string wantString = wantItem->valuestring; wants.emplace_back(std::make_shared(*Want::FromString(wantString))); } } } std::shared_ptr extraInfo = nullptr; - if (jsonObject.contains("extraInfo") && jsonObject["extraInfo"].is_object()) { - auto extraInfoObj = jsonObject.at("extraInfo"); - if (extraInfoObj.contains("extraInfoValue") && extraInfoObj["extraInfoValue"].is_string()) { - auto pwWrapper = AAFwk::WantParamWrapper::Parse(extraInfoObj.at("extraInfoValue").get()); + cJSON *extraInfoItem = cJSON_GetObjectItem(jsonObject, "extraInfo"); + if (extraInfoItem != nullptr && cJSON_IsObject(extraInfoItem)) { + cJSON *extraInfoValueItem = cJSON_GetObjectItem(extraInfoItem, "extraInfoValue"); + if (extraInfoValueItem != nullptr && cJSON_IsString(extraInfoValueItem)) { + std::string extraInfoValue = extraInfoValueItem->valuestring; + auto pwWrapper = AAFwk::WantParamWrapper::Parse(extraInfoValue); AAFwk::WantParams params; if (pwWrapper->GetValue(params) == ERR_OK) { extraInfo = std::make_shared(params); } } } + cJSON_Delete(jsonObject); WantAgentInfo info(requestCode, operationType, flagsVec, wants, extraInfo); return GetWantAgent(info, INVLID_WANT_AGENT_USER_ID, uid); } -std::vector WantAgentHelper::ParseFlags(nlohmann::json jsonObject) +std::vector WantAgentHelper::ParseFlags(cJSON *jsonObject) { int flags = -1; std::vector flagsVec = {}; - if (jsonObject.contains("flags") && jsonObject.at("flags").is_number_integer()) { - flags = jsonObject.at("flags").get(); + cJSON *flagsItem = cJSON_GetObjectItem(jsonObject, "flags"); + if (flagsItem != nullptr && cJSON_IsNumber(flagsItem)) { + flags = static_cast(flagsItem->valuedouble); } if (flags < 0) { diff --git a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h index 90f28af40f0724e19328610a5286426e9006c134..0220e949088447678c06f8f7faf20db1bd6d957f 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h @@ -25,7 +25,6 @@ #include "configuration.h" #include "js_startup_task.h" #include "resource_manager.h" -#include "nlohmann/json.hpp" #include "native_engine/native_value.h" class NativeReference; diff --git a/interfaces/kits/native/appkit/app_startup/startup_manager.h b/interfaces/kits/native/appkit/app_startup/startup_manager.h index 04dafddf4c62c6eb1dca874b49b9e40943a0176a..68bb0e9acf9d7a51899a2db71eec251ed8b09bf1 100644 --- a/interfaces/kits/native/appkit/app_startup/startup_manager.h +++ b/interfaces/kits/native/appkit/app_startup/startup_manager.h @@ -26,6 +26,7 @@ #include "app_startup_task_matcher.h" #include "bundle_info.h" #include "app_launch_data.h" +#include "cJSON.h" #include "native_startup_task.h" #include "preload_so_startup_task.h" #include "singleton.h" @@ -170,21 +171,19 @@ private: bool AnalyzeStartupConfig(const ModuleStartupConfigInfo& info, const std::string& startupConfig, std::map>& preloadSoStartupTasks, std::vector& pendingStartupTaskInfos, std::string& pendingConfigEntry); - static bool AnalyzeAppStartupTask(const ModuleStartupConfigInfo& info, nlohmann::json &startupConfigJson, + static bool AnalyzeAppStartupTask(const ModuleStartupConfigInfo& info, cJSON *startupConfigJson, std::vector& pendingStartupTaskInfos); - bool AnalyzePreloadSoStartupTask(const ModuleStartupConfigInfo& info, nlohmann::json &startupConfigJson, + bool AnalyzePreloadSoStartupTask(const ModuleStartupConfigInfo& info, cJSON *startupConfigJson, std::map>& preloadSoStartupTasks); - static bool AnalyzeAppStartupTaskInner(const ModuleStartupConfigInfo& info, - const nlohmann::json &startupTaskJson, + static bool AnalyzeAppStartupTaskInner(const ModuleStartupConfigInfo& info, const cJSON *startupTaskJson, std::vector& pendingStartupTaskInfos); - bool AnalyzePreloadSoStartupTaskInner(const ModuleStartupConfigInfo& info, - const nlohmann::json &preloadStartupTaskJson, + bool AnalyzePreloadSoStartupTaskInner(const ModuleStartupConfigInfo& info, const cJSON *preloadStartupTaskJson, std::map>& preloadSoStartupTasks); - static void SetOptionalParameters(const nlohmann::json& module, AppExecFwk::ModuleType moduleType, + static void SetOptionalParameters(const cJSON *module, AppExecFwk::ModuleType moduleType, StartupTaskInfo& startupTaskInfo); - static void SetOptionalParameters(const nlohmann::json &module, AppExecFwk::ModuleType moduleType, + static void SetOptionalParameters(const cJSON *module, AppExecFwk::ModuleType moduleType, std::shared_ptr &task); - static void SetMatchRules(const nlohmann::json &module, StartupTaskMatchRules &matchRules); + static void SetMatchRules(const cJSON *module, StartupTaskMatchRules &matchRules); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/appkit/app_startup/startup_utils.h b/interfaces/kits/native/appkit/app_startup/startup_utils.h index c367a7a380d53f8e8909b6392aabcd8fcf549bee..48aeac03a68cf14c27a163289f3ebd02de8b0d4c 100644 --- a/interfaces/kits/native/appkit/app_startup/startup_utils.h +++ b/interfaces/kits/native/appkit/app_startup/startup_utils.h @@ -16,9 +16,9 @@ #ifndef OHOS_ABILITY_RUNTIME_STARTUP_UTILS_H #define OHOS_ABILITY_RUNTIME_STARTUP_UTILS_H -#include #include +#include "cJSON.h" #include "errors.h" namespace OHOS { @@ -41,7 +41,7 @@ enum { class StartupUtils { public: static std::string GetErrorMessage(int32_t errCode); - static bool ParseJsonStringArray(const nlohmann::json &json, const std::string key, std::vector &arr); + static bool ParseJsonStringArray(const cJSON *json, const std::string key, std::vector &arr); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 237513c55a1ef8f845bad13e4c29453c579192f3..42a1554e39887209926447d227a80865047051b6 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -166,6 +166,7 @@ ohos_shared_library("abilityms") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bundle_framework:libappexecfwk_common", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", @@ -182,7 +183,6 @@ ohos_shared_library("abilityms") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "qos_manager:concurrent_task_client", @@ -469,7 +469,6 @@ ohos_shared_library("mission_list") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "relational_store:native_appdatafwk", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 2205acc6e586d35825dfe18645ff80524f410c61..9d494b3410cbf5bced814f4aba4bbb43ac1e3ff3 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -129,6 +129,7 @@ abilityms_files = [ "src/insight_intent/insight_intent_db_cache.cpp", "src/insight_intent/insight_intent_execute_manager.cpp", "src/insight_intent/insight_intent_execute_result.cpp", + "src/insight_intent/insight_intent_json_util.cpp", "src/insight_intent/insight_intent_profile.cpp", "src/insight_intent/insight_intent_rdb_data_mgr.cpp", "src/insight_intent/insight_intent_rdb_storage_mgr.cpp", diff --git a/services/abilitymgr/include/ability_auto_startup_data_manager.h b/services/abilitymgr/include/ability_auto_startup_data_manager.h index fd4342f0d0ef60f1ec25c734eef71279d2a37d26..7757e5a8346d7aa4e1e3f8c76675d677e6a155a3 100644 --- a/services/abilitymgr/include/ability_auto_startup_data_manager.h +++ b/services/abilitymgr/include/ability_auto_startup_data_manager.h @@ -21,7 +21,6 @@ #include "auto_startup_info.h" #include "distributed_kv_data_manager.h" -#include "nlohmann/json.hpp" #include "singleton.h" namespace OHOS { diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index bf37333b3c80583cb5038ec43801dee1651e1a6d..c0df6d439c9a34cc87d86fb1e270e16a1437aaa7 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2715,11 +2715,11 @@ private: std::string GetConfigFileAbsolutePath(const std::string &relativePath); - int32_t ParseJsonValueFromFile(nlohmann::json &value, const std::string& fullPath); + int32_t ParseJsonValueFromFile(cJSON *value, const std::string& fullPath); bool ConvertFullPath(const std::string& partialPath, std::string& fullPath); - bool GetJsonFromFile(const char *filePath, Json::Value &root); + bool GetJsonFromFile(const char *filePath, cJSON *root); bool ParseJsonFromBoot(const std::string &relativePath); diff --git a/services/abilitymgr/include/ams_configuration_parameter.h b/services/abilitymgr/include/ams_configuration_parameter.h index 752a252b5a33c719b6016ddc8335ddf7746f8246..69444a03f9480f8c6b48c5e819571e8168b6190e 100644 --- a/services/abilitymgr/include/ams_configuration_parameter.h +++ b/services/abilitymgr/include/ams_configuration_parameter.h @@ -18,7 +18,8 @@ #include #include -#include + +#include "cJSON.h" #include "nocopyable.h" #include "parameters.h" @@ -128,12 +129,12 @@ public: /** * set picker json object. */ - void SetPickerJsonObject(nlohmann::json jsonObject); + void SetPickerJsonObject(cJSON *jsonObject); /** * get picker json object. */ - nlohmann::json GetPickerJsonObject() const; + cJSON *GetPickerJsonObject() const; int MultiUserType() const; @@ -148,18 +149,18 @@ private: * */ int LoadAmsConfiguration(const std::string &filePath); - int LoadAppConfigurationForStartUpService(nlohmann::json& Object); - int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object); - int LoadSystemConfiguration(nlohmann::json& Object); - void LoadPickerConfiguration(nlohmann::json& Object); - bool CheckServiceConfigEnable(nlohmann::json& Object, const std::string &configName, JsonValueType type); - void UpdateStartUpServiceConfigInteger(nlohmann::json& Object, const std::string &configName, int32_t &value); - void UpdateStartUpServiceConfigString(nlohmann::json& Object, const std::string &configName, std::string &value); - void UpdatePickerConfigurationString(nlohmann::json& Object, const std::string &configName, std::string &value); + int LoadAppConfigurationForStartUpService(cJSON *Object); + int LoadAppConfigurationForMemoryThreshold(cJSON *Object); + int LoadSystemConfiguration(cJSON *Object); + void LoadPickerConfiguration(cJSON *Object); + bool CheckServiceConfigEnable(cJSON *Object, const std::string &configName, JsonValueType type); + void UpdateStartUpServiceConfigInteger(cJSON *Object, const std::string &configName, int32_t &value); + void UpdateStartUpServiceConfigString(cJSON *Object, const std::string &configName, std::string &value); + void UpdatePickerConfigurationString(cJSON *Object, const std::string &configName, std::string &value); void LoadUIExtensionPickerConfig(const std::string &filePath); - int32_t LoadBackToCallerConfig(nlohmann::json& Object); - int32_t LoadSupportAAKillWithReasonConfig(nlohmann::json& Object); - int32_t LoadSupportSCBCrashRebootConfig(nlohmann::json& Object); + int32_t LoadBackToCallerConfig(cJSON *Object); + int32_t LoadSupportAAKillWithReasonConfig(cJSON *Object); + int32_t LoadSupportSCBCrashRebootConfig(cJSON *Object); private: bool nonConfigFile_ {false}; @@ -182,7 +183,7 @@ private: std::string abilityName_ {""}; std::string pickerType_ {""}; std::map picker_; - nlohmann::json pickerJsonObject_ = nlohmann::json::object(); + cJSON *pickerJsonObject_ = nullptr; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/app_exit_reason_data_manager.h b/services/abilitymgr/include/app_exit_reason_data_manager.h index dd12043f6eabbf22b4a40d5cc60f3989ff2207df..ae1815851cb2301610c35b5b1b2c5a81086c110a 100644 --- a/services/abilitymgr/include/app_exit_reason_data_manager.h +++ b/services/abilitymgr/include/app_exit_reason_data_manager.h @@ -83,7 +83,7 @@ private: void ConvertAppExitReasonInfoFromValue(const DistributedKv::Value &value, AAFwk::ExitReason &exitReason, int64_t &time_stamp, std::vector &abilityList, AppExecFwk::RunningProcessInfo &processInfo, bool &withKillMsg); - void ConvertReasonFromValue(const nlohmann::json &jsonObject, AAFwk::ExitReason &exitReason, bool &withKillMsg); + void ConvertReasonFromValue(const cJSON *jsonObject, AAFwk::ExitReason &exitReason, bool &withKillMsg); void ConvertAccessTokenIdFromValue(const DistributedKv::Value &value, uint32_t &accessTokenId); void InnerDeleteAppExitReason(const std::string &keyName); void InnerDeleteSessionId(const int32_t sessionId); diff --git a/services/abilitymgr/include/deeplink_reserve/deeplink_reserve_config.h b/services/abilitymgr/include/deeplink_reserve/deeplink_reserve_config.h index 942ee5f2e249ccaf0320ae01fde6daf262753912..9f554dc7ae7005e2266ddc86a329fa54bf67dada 100644 --- a/services/abilitymgr/include/deeplink_reserve/deeplink_reserve_config.h +++ b/services/abilitymgr/include/deeplink_reserve/deeplink_reserve_config.h @@ -16,10 +16,10 @@ #ifndef OHOS_ABILITY_RUNTIME_DEEPLINK_RESERVE_CONFIG_H #define OHOS_ABILITY_RUNTIME_DEEPLINK_RESERVE_CONFIG_H -#include #include #include +#include "cJSON.h" #include "singleton.h" namespace OHOS { @@ -49,10 +49,10 @@ public: private: std::string GetConfigPath(); - bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); - bool LoadReservedUriList(const nlohmann::json &object); + bool ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf); + bool LoadReservedUriList(const cJSON *object); bool IsUriMatched(const ReserveUri &reservedUri, const std::string &link); - void LoadReservedUrilItem(const nlohmann::json &jsonUriObject, std::vector &uriList); + void LoadReservedUrilItem(const cJSON *jsonUriObject, std::vector &uriList); DeepLinkReserveConfig() = default; DISALLOW_COPY_AND_MOVE(DeepLinkReserveConfig); diff --git a/services/abilitymgr/include/extension_config.h b/services/abilitymgr/include/extension_config.h index 9ff548ee9edabf7912768c4f366e408204638e57..fc451c5b3076c1dc9f98d2919057a3cd079e27a1 100644 --- a/services/abilitymgr/include/extension_config.h +++ b/services/abilitymgr/include/extension_config.h @@ -18,11 +18,11 @@ #include #include -#include #include #include #include +#include "cJSON.h" #include "extension_ability_info.h" #include "singleton.h" @@ -71,17 +71,17 @@ public: bool IsExtensionNetworkEnable(const std::string &extensionTypeName); bool IsExtensionSAEnable(const std::string &extensionTypeName); private: - void LoadExtensionConfig(const nlohmann::json &object); - bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); + void LoadExtensionConfig(const cJSON *object); + bool ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf); std::string GetExtensionConfigPath() const; - void LoadExtensionAutoDisconnectTime(const nlohmann::json &object, const std::string &extensionTypeName); - void LoadExtensionThirdPartyAppBlockedList(const nlohmann::json &object, std::string extensionTypeName); - void LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeNameobject); - void LoadExtensionNetworkEnable(const nlohmann::json &object, const std::string &extensionTypeName); - void LoadExtensionSAEnable(const nlohmann::json &object, const std::string &extensionTypeName); - bool LoadExtensionAbilityAccess(const nlohmann::json &object, const std::string &extensionTypeName); - void LoadExtensionAllowOrBlockedList(const nlohmann::json &object, const std::string &key, + void LoadExtensionAutoDisconnectTime(const cJSON *object, const std::string &extensionTypeName); + void LoadExtensionThirdPartyAppBlockedList(const cJSON *object, std::string extensionTypeName); + void LoadExtensionServiceBlockedList(const cJSON *object, std::string extensionTypeNameobject); + void LoadExtensionNetworkEnable(const cJSON *object, const std::string &extensionTypeName); + void LoadExtensionSAEnable(const cJSON *object, const std::string &extensionTypeName); + bool LoadExtensionAbilityAccess(const cJSON *object, const std::string &extensionTypeName); + void LoadExtensionAllowOrBlockedList(const cJSON *object, const std::string &key, std::unordered_set &list); std::optional GetSingleAccessFlag(const std::string &extensionTypeName, diff --git a/services/abilitymgr/include/inner_mission_info.h b/services/abilitymgr/include/inner_mission_info.h index fe4bab58d9eaeaecaa31f87fff86daac259fcf95..7de4f3ec72126991222bafebee758a8709b52def 100644 --- a/services/abilitymgr/include/inner_mission_info.h +++ b/services/abilitymgr/include/inner_mission_info.h @@ -54,7 +54,7 @@ struct InnerMissionInfo { MissionInfo missionInfo; bool FromJsonStr(const std::string &jsonStr); void Dump(std::vector &info) const; - bool CheckJsonNode(nlohmann::json &value, const std::string &node, JsonType jsonType); + bool CheckJsonNode(cJSON *value, const std::string &node, JsonType jsonType); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h b/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h index 7e55c07f6163b616ea7f6ac51eefa8ae54416d41..c2a5054d7fe87c74c387d325e31a027e70b5a30b 100644 --- a/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h +++ b/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h @@ -19,6 +19,7 @@ #include #include +#include "cJSON.h" #include "insight_intent_execute_param.h" namespace OHOS { @@ -212,7 +213,7 @@ struct ExtractInsightIntentProfileInfoVec { class ExtractInsightIntentProfile { public: static bool TransformTo(const std::string &profileStr, ExtractInsightIntentProfileInfoVec &infos); - static bool ToJson(const ExtractInsightIntentProfileInfo &info, nlohmann::json &jsonObject); + static bool ToJson(const ExtractInsightIntentProfileInfo &info, cJSON *jsonObject); static bool ProfileInfoFormat(const ExtractInsightIntentProfileInfo &insightIntent, ExtractInsightIntentInfo &info); }; } // namespace AbilityRuntime diff --git a/services/abilitymgr/include/insight_intent/insight_intent_json_util.h b/services/abilitymgr/include/insight_intent/insight_intent_json_util.h new file mode 100644 index 0000000000000000000000000000000000000000..71f6fe919ee514054db8ce8dd0b28574b30633d4 --- /dev/null +++ b/services/abilitymgr/include/insight_intent/insight_intent_json_util.h @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2023-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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_JSON_UTIL_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_JSON_UTIL_H + +#include +#include +#include + +#include "appexecfwk_errors.h" +#include "bundle_constants.h" +#include "cJSON.h" +#include "hilog_tag_wrapper.h" +#include "json_serializer.h" + +namespace OHOS { +namespace AbilityRuntime { + +bool to_json(cJSON *jsonObject, const std::string &value); +bool to_json(cJSON *jsonObject, const int &value); +bool to_json(cJSON *jsonObject, const bool &value); + +template +bool to_json(cJSON *jsonObject, const std::vector &values) +{ + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + for (auto& value : values) { + cJSON *valueItem = nullptr; + if (!to_json(valueItem, value)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToArray(jsonObject, valueItem); + } + return true; +} + +template +bool to_json(cJSON *jsonObject, const std::map &valueMap) +{ + jsonObject = cJSON_CreateArray(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + for (const auto& [key, values] : valueMap) { + cJSON *valuesObject = cJSON_CreateObject(); + cJSON *valuesItem = nullptr; + if (!to_json(valuesItem, values)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json array failed"); + return false; + } + cJSON_AddItemToObject(valuesObject, key.c_str(), valuesObject); + cJSON_AddItemToArray(jsonObject, valuesObject); + } + return true; +} + +void from_json(const cJSON *jsonObject, std::string &value); + +void from_json(const cJSON *jsonObject, int &value); + +void from_json(const cJSON *jsonObject, bool &value); + +template +void from_json(const cJSON *jsonObject, std::vector &values) +{ + if (jsonObject == nullptr || !cJSON_IsArray(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not array"); + return; + } + int size = cJSON_GetArraySize(jsonObject); + for (int i = 0; i < size; i++) { + cJSON *valueItem = cJSON_GetArrayItem(jsonObject, i); + if (valueItem != nullptr) { + T value; + from_json(valueItem, value); + values.push_back(value); + } + } +} + +void GetStringValueIfFindKey(const cJSON *jsonObject, + const std::string &key, std::string &data, + bool isNecessary, int32_t &parseResult); + +void GetStringValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult); + +template +void GetNumberValueIfFindKey(const cJSON *jsonObject, + const std::string &key, T &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsNumber(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not number", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + data = static_cast(item->valuedouble); +} + +template +void GetNumberValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsNumber(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not number list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + T value = static_cast(childItem->valuedouble); + data.push_back(value); + } +} + +void GetBoolValueIfFindKey(const cJSON *jsonObject, + const std::string &key, bool &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult); + +void GetBoolValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult); + +template +void GetObjectValueIfFindKey(const cJSON *jsonObject, + const std::string &key, T &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsObject(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + from_json(jsonObject, data); +} + +template +void GetObjectValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + T value; + from_json(childItem, value); + data.push_back(value); + } +} + +template +void GetObjectValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + T value; + from_json(childItem, value); + data.emplace(key, value); + } +} + +template +void GetObjectValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsObject(childItem)) { + TAG_LOGD(AAFwkTag::ABILITY_SIM, "type:%{public}s not object list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + std::vector value; + from_json(childItem, value); + data.emplace(key, value); + } +} +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_JSON_UTIL_H \ No newline at end of file diff --git a/services/abilitymgr/include/keep_alive/ability_keep_alive_data_manager.h b/services/abilitymgr/include/keep_alive/ability_keep_alive_data_manager.h index dd103bcca27aa5686b6386eb052c22e394a0ef6d..57bb4894b42bee270f4bb16c733331290091a782 100644 --- a/services/abilitymgr/include/keep_alive/ability_keep_alive_data_manager.h +++ b/services/abilitymgr/include/keep_alive/ability_keep_alive_data_manager.h @@ -21,7 +21,6 @@ #include "distributed_kv_data_manager.h" #include "keep_alive_info.h" -#include "nlohmann/json.hpp" #include "singleton.h" namespace OHOS { diff --git a/services/abilitymgr/include/rdb/parser_util.h b/services/abilitymgr/include/rdb/parser_util.h index e949b830c7cdd0ca41105c5cdce935dbeb50d728..2110707e4e936d17299ce1f7c560dc78493e487b 100644 --- a/services/abilitymgr/include/rdb/parser_util.h +++ b/services/abilitymgr/include/rdb/parser_util.h @@ -16,10 +16,11 @@ #ifndef OHOS_ABILITY_RUNTIME_RDB_PARSER_UTIL_H #define OHOS_ABILITY_RUNTIME_RDB_PARSER_UTIL_H -#include #include #include +#include "cJSON.h" + namespace OHOS { namespace AbilityRuntime { /* This class is used to parse the resident process information section in files(install_list_capability.json) */ @@ -32,9 +33,8 @@ private: void ParsePreInstallAbilityConfig( const std::string &filePath, std::vector> &list); void GetPreInstallRootDirList(std::vector &rootDirList); - bool ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf); - bool FilterInfoFromJson( - nlohmann::json &jsonBuf, std::vector> &list); + bool ReadFileIntoJson(const std::string &filePath, cJSON *jsonBuf); + bool FilterInfoFromJson(cJSON *jsonBuf, std::vector> &list); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index c045fda5138863c713d535c038216b44a1faa4e3..c144fbb32a0a8aadebf8790e5d5deb782f015e4f 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -20,6 +20,7 @@ #include "accesstoken_kit.h" #include "hilog_tag_wrapper.h" #include "json_utils.h" +#include "insight_intent_json_util.h" #include "os_account_manager_wrapper.h" namespace OHOS { @@ -422,12 +423,19 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( DistributedKv::Value AbilityAutoStartupDataManager::ConvertAutoStartupStatusToValue( bool isAutoStartup, bool isEdmForce, const std::string &abilityTypeName) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_IS_AUTO_STARTUP, isAutoStartup }, - { JSON_KEY_IS_EDM_FORCE, isEdmForce }, - { JSON_KEY_TYPE_NAME, abilityTypeName }, - }; - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "create jsonObject failed"); + return DistributedKv::Value(); + } + + cJSON_AddBoolToObject(jsonObject, JSON_KEY_IS_AUTO_STARTUP.c_str(), isAutoStartup); + cJSON_AddBoolToObject(jsonObject, JSON_KEY_IS_EDM_FORCE.c_str(), isEdmForce); + cJSON_AddStringToObject(jsonObject, JSON_KEY_TYPE_NAME.c_str(), abilityTypeName.c_str()); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); TAG_LOGD(AAFwkTag::AUTO_STARTUP, "value: %{public}s", value.ToString().c_str()); return value; } @@ -435,30 +443,38 @@ DistributedKv::Value AbilityAutoStartupDataManager::ConvertAutoStartupStatusToVa void AbilityAutoStartupDataManager::ConvertAutoStartupStatusFromValue( const DistributedKv::Value &value, bool &isAutoStartup, bool &isEdmForce) { - nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject fail"); + cJSON *jsonObject = cJSON_Parse(value.ToString().c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject failed"); return; } - if (jsonObject.contains(JSON_KEY_IS_AUTO_STARTUP) && jsonObject[JSON_KEY_IS_AUTO_STARTUP].is_boolean()) { - isAutoStartup = jsonObject.at(JSON_KEY_IS_AUTO_STARTUP).get(); + cJSON *isAutoStartupItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_IS_AUTO_STARTUP.c_str()); + if (isAutoStartupItem != nullptr && cJSON_IsBool(isAutoStartupItem)) { + isAutoStartup = isAutoStartupItem->type == cJSON_True ? true : false; } - if (jsonObject.contains(JSON_KEY_IS_EDM_FORCE) && jsonObject[JSON_KEY_IS_EDM_FORCE].is_boolean()) { - isEdmForce = jsonObject.at(JSON_KEY_IS_EDM_FORCE).get(); + cJSON *isEdmForceItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_IS_EDM_FORCE.c_str()); + if (isEdmForceItem != nullptr && cJSON_IsBool(isEdmForceItem)) { + isEdmForce = isEdmForceItem->type == cJSON_True ? true : false; } + cJSON_Delete(jsonObject); } DistributedKv::Key AbilityAutoStartupDataManager::ConvertAutoStartupDataToKey(const AutoStartupInfo &info) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_BUNDLE_NAME, info.bundleName }, - { JSON_KEY_MODULE_NAME, info.moduleName }, - { JSON_KEY_ABILITY_NAME, info.abilityName }, - { JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex }, - { JSON_KEY_ACCESS_TOKENID, info.accessTokenId }, - { JSON_KEY_USERID, info.userId }, - }; - DistributedKv::Key key(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "create jsonObject failed"); + return DistributedKv::Key(); + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_BUNDLE_NAME.c_str(), info.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_MODULE_NAME.c_str(), info.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_ABILITY_NAME.c_str(), info.abilityName.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_APP_CLONE_INDEX.c_str(), static_cast(info.appCloneIndex)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_ACCESS_TOKENID.c_str(), info.accessTokenId.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_USERID.c_str(), static_cast(info.userId)); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Key key(jsonStr); TAG_LOGD(AAFwkTag::AUTO_STARTUP, "key: %{public}s", key.ToString().c_str()); return key; } @@ -467,53 +483,62 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV const DistributedKv::Key &key, const DistributedKv::Value &value) { AutoStartupInfo info; - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject fail"); return info; } - if (jsonObject.contains(JSON_KEY_BUNDLE_NAME) && jsonObject[JSON_KEY_BUNDLE_NAME].is_string()) { - info.bundleName = jsonObject.at(JSON_KEY_BUNDLE_NAME).get(); + cJSON *bundleNameItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_BUNDLE_NAME.c_str()); + if (bundleNameItem != nullptr && cJSON_IsString(bundleNameItem)) { + info.bundleName = bundleNameItem->valuestring; } - if (jsonObject.contains(JSON_KEY_MODULE_NAME) && jsonObject[JSON_KEY_MODULE_NAME].is_string()) { - info.moduleName = jsonObject.at(JSON_KEY_MODULE_NAME).get(); + cJSON *moduleNameItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_MODULE_NAME.c_str()); + if (moduleNameItem != nullptr && cJSON_IsString(moduleNameItem)) { + info.moduleName = moduleNameItem->valuestring; } - if (jsonObject.contains(JSON_KEY_ABILITY_NAME) && jsonObject[JSON_KEY_ABILITY_NAME].is_string()) { - info.abilityName = jsonObject.at(JSON_KEY_ABILITY_NAME).get(); + cJSON *abilityNameItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_ABILITY_NAME.c_str()); + if (abilityNameItem != nullptr && cJSON_IsString(abilityNameItem)) { + info.abilityName = abilityNameItem->valuestring; } - if (jsonObject.contains(JSON_KEY_APP_CLONE_INDEX) && jsonObject[JSON_KEY_APP_CLONE_INDEX].is_number()) { - info.appCloneIndex = jsonObject.at(JSON_KEY_APP_CLONE_INDEX).get(); + cJSON *appCloneIndexItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_APP_CLONE_INDEX.c_str()); + if (appCloneIndexItem != nullptr && cJSON_IsNumber(appCloneIndexItem)) { + info.appCloneIndex = static_cast(appCloneIndexItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { - info.accessTokenId = jsonObject.at(JSON_KEY_ACCESS_TOKENID).get(); + cJSON *accessTokenIdItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_ACCESS_TOKENID.c_str()); + if (accessTokenIdItem != nullptr && cJSON_IsString(accessTokenIdItem)) { + info.accessTokenId = accessTokenIdItem->valuestring; } - if (jsonObject.contains(JSON_KEY_USERID) && jsonObject[JSON_KEY_USERID].is_number()) { - info.userId = jsonObject.at(JSON_KEY_USERID).get(); + cJSON *userIdItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_USERID.c_str()); + if (userIdItem != nullptr && cJSON_IsNumber(userIdItem)) { + info.userId = static_cast(userIdItem->valuedouble); } + cJSON_Delete(jsonObject); - nlohmann::json jsonValueObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonValueObject.is_discarded()) { + cJSON *jsonValueObject = cJSON_Parse(value.ToString().c_str()); + if (jsonValueObject == nullptr) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonValueObject fail"); return info; } - if (jsonValueObject.contains(JSON_KEY_TYPE_NAME) && jsonValueObject[JSON_KEY_TYPE_NAME].is_string()) { - info.abilityTypeName = jsonValueObject.at(JSON_KEY_TYPE_NAME).get(); + cJSON *typeNameItem = cJSON_GetObjectItem(jsonValueObject, JSON_KEY_TYPE_NAME.c_str()); + if (typeNameItem != nullptr && cJSON_IsString(typeNameItem)) { + info.abilityTypeName = typeNameItem->valuestring; } + cJSON_Delete(jsonValueObject); return info; } bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info) { - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject fail"); + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject failed"); return false; } @@ -523,40 +548,48 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const || !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex) || !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_ACCESS_TOKENID, info.accessTokenId) || !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_USERID, info.userId)) { + cJSON_Delete(jsonObject); return false; } + cJSON_Delete(jsonObject); return true; } bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId) { - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject fail"); return false; } - if (jsonObject.contains(JSON_KEY_ACCESS_TOKENID) && jsonObject[JSON_KEY_ACCESS_TOKENID].is_string()) { - if (accessTokenId == jsonObject.at(JSON_KEY_ACCESS_TOKENID).get()) { + cJSON *itemObject = cJSON_GetObjectItem(jsonObject, JSON_KEY_ACCESS_TOKENID.c_str()); + if (itemObject != nullptr && cJSON_IsString(itemObject)) { + if (accessTokenId == std::string(itemObject->valuestring)) { + cJSON_Delete(jsonObject); return true; } } + cJSON_Delete(jsonObject); return false; } bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, int32_t userId) { - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse jsonObject fail"); return false; } - if (jsonObject.contains(JSON_KEY_USERID) && jsonObject[JSON_KEY_USERID].is_number()) { - if (userId == jsonObject.at(JSON_KEY_USERID).get()) { + cJSON *itemObject = cJSON_GetObjectItem(jsonObject, JSON_KEY_USERID.c_str()); + if (itemObject != nullptr && cJSON_IsNumber(itemObject)) { + if (userId == static_cast(itemObject->valuedouble)) { + cJSON_Delete(jsonObject); return true; } } + cJSON_Delete(jsonObject); return false; } } // namespace AbilityRuntime diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index e88256cbe73962d254997a93752353d99d671f11..e53cd211d0008f22a0dca89edf01201196322dcf 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -13021,31 +13021,43 @@ bool AbilityManagerService::IsInWhiteList(const std::string &callerBundleName, c bool AbilityManagerService::ParseJsonFromBoot(const std::string &relativePath) { - nlohmann::json jsonObj; + cJSON *jsonObj = nullptr; std::string absolutePath = GetConfigFileAbsolutePath(relativePath); if (ParseJsonValueFromFile(jsonObj, absolutePath) != ERR_OK) { return false; } std::lock_guard locker(whiteListMutex_); - nlohmann::json whiteListJsonList = jsonObj[WHITE_LIST]; - for (const auto& [key, value] : whiteListJsonList.items()) { - if (!value.is_array()) { + cJSON *whiteListJsonList = cJSON_GetObjectItem(jsonObj, WHITE_LIST); + cJSON *childItem = whiteListJsonList->child; + while (childItem != nullptr) { + std::string key = childItem->string == nullptr ? "" : childItem->string; + if (!cJSON_IsArray(childItem)) { continue; } whiteListMap_.emplace(key, std::list()); - for (const auto& it : value) { - if (it.is_string()) { - whiteListMap_[key].push_back(it); + int size = cJSON_GetArraySize(childItem); + for (int i = 0; i < size; i++) { + cJSON *valueItem = cJSON_GetArrayItem(childItem, i); + if (valueItem != nullptr && cJSON_IsString(valueItem)) { + std::string value = valueItem->valuestring; + whiteListMap_[key].push_back(value); } } + + childItem = childItem->next; } - if (!jsonObj.contains("exposed_white_list")) { + + cJSON *exposedWhiteListItem = cJSON_GetObjectItem(jsonObj, "exposed_white_list"); + if (exposedWhiteListItem == nullptr || !cJSON_IsArray(exposedWhiteListItem)) { + cJSON_Delete(jsonObj); return false; } - nlohmann::json exportWhiteJsonList = jsonObj["exposed_white_list"]; - for (const auto& it : exportWhiteJsonList) { - if (it.is_string()) { - exportWhiteList_.push_back(it); + int size = cJSON_GetArraySize(exposedWhiteListItem); + for (int i = 0; i < size; i++) { + cJSON *exposedWhiteItem = cJSON_GetArrayItem(exposedWhiteListItem, i); + if (exposedWhiteItem != nullptr && cJSON_IsString(exposedWhiteItem)) { + std::string exportWhiteStr = exposedWhiteItem->valuestring; + exportWhiteList_.push_back(exportWhiteStr); } } return true; @@ -13067,7 +13079,7 @@ std::string AbilityManagerService::GetConfigFileAbsolutePath(const std::string & return std::string(absolutePath); } -int32_t AbilityManagerService::ParseJsonValueFromFile(nlohmann::json &value, const std::string &filePath) +int32_t AbilityManagerService::ParseJsonValueFromFile(cJSON *value, const std::string &filePath) { std::ifstream fin; std::string realPath; @@ -13086,8 +13098,10 @@ int32_t AbilityManagerService::ParseJsonValueFromFile(nlohmann::json &value, con os << buffer; } const std::string data = os.str(); - value = nlohmann::json::parse(data, nullptr, false); - if (value.is_discarded()) { + fin.close(); + + value = cJSON_Parse(data.c_str()); + if (value == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed due data discarded"); return ERR_INVALID_VALUE; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 4800d8feb5105d25dbb12aafa9d3bd72d01d4c7a..2bd313be1a2ca0376bd247b8c699b1794d57b6f1 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -3845,10 +3845,15 @@ void AbilityRecord::NotifyAbilityRequestFailure(const std::string &requestId, co const std::string &message) { CHECK_POINTER(lifecycleDeal_); - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ERR_MSG, message }, - }; - lifecycleDeal_->NotifyAbilityRequestFailure(requestId, element, jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_ERR_MSG.c_str(), message.c_str()); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + lifecycleDeal_->NotifyAbilityRequestFailure(requestId, element, jsonStr); } void AbilityRecord::NotifyAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp index f2ba18455108a3104956bce07d27c1212cf054cd..e398485ec33d6a59588253ba741958a132d548ec 100644 --- a/services/abilitymgr/src/ams_configuration_parameter.cpp +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -34,8 +34,6 @@ AmsConfigurationParameter &AmsConfigurationParameter::GetInstance() return amsConfiguration; } -using json = nlohmann::json; - void AmsConfigurationParameter::Parse() { auto ref = LoadAmsConfiguration(AmsConfig::AMS_CONFIG_FILE_PATH); @@ -98,14 +96,15 @@ int AmsConfigurationParameter::GetAppStartTimeoutTime() const return timeoutUnitTime_ * AppUtils::GetInstance().GetTimeoutUnitTimeRatio(); } -void AmsConfigurationParameter::SetPickerJsonObject(nlohmann::json Object) +void AmsConfigurationParameter::SetPickerJsonObject(cJSON *jsonObject) { - if (Object.contains(AmsConfig::PICKER_CONFIGURATION)) { - pickerJsonObject_ = Object.at(AmsConfig::PICKER_CONFIGURATION); + cJSON *pickerConfigurationItem = cJSON_GetObjectItem(jsonObject, AmsConfig::PICKER_CONFIGURATION); + if (jsonObject != nullptr) { + pickerJsonObject_ = cJSON_Duplicate(pickerConfigurationItem, true); } } -nlohmann::json AmsConfigurationParameter::GetPickerJsonObject() const +cJSON *AmsConfigurationParameter::GetPickerJsonObject() const { return pickerJsonObject_; } @@ -133,44 +132,52 @@ void AmsConfigurationParameter::LoadUIExtensionPickerConfig(const std::string &f TAG_LOGE(AAFwkTag::ABILITYMGR, "read picker config error"); return; } - - json pickerJson; - inFile >> pickerJson; + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); inFile.close(); - if (pickerJson.is_discarded()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "json discarded error"); - return; - } - if (pickerJson.is_null() || pickerJson.empty()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid jsonObj"); + cJSON *pickerJson = cJSON_Parse(fileContent.c_str()); + if (pickerJson == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "json parse error"); return; } - if (!pickerJson.contains(AmsConfig::UIEATENSION)) { + cJSON *uieatensionItem = cJSON_GetObjectItem(pickerJson, AmsConfig::UIEATENSION); + if (uieatensionItem == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "json config not contains the key"); + cJSON_Delete(pickerJson); return; } - - if (pickerJson[AmsConfig::UIEATENSION].is_null() || !pickerJson[AmsConfig::UIEATENSION].is_array() - || pickerJson[AmsConfig::UIEATENSION].empty()) { + if (!cJSON_IsArray(uieatensionItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid obj"); + cJSON_Delete(pickerJson); + return; + } + int size = cJSON_GetArraySize(uieatensionItem); + if (size == 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid obj"); + cJSON_Delete(pickerJson); return; } - for (auto extension : pickerJson[AmsConfig::UIEATENSION]) { - if (extension[AmsConfig::UIEATENSION_TYPE].is_null() || !extension[AmsConfig::UIEATENSION_TYPE].is_string() - || extension[AmsConfig::UIEATENSION_TYPE_PICKER].is_null() - || !extension[AmsConfig::UIEATENSION_TYPE_PICKER].is_string()) { + for (int i = 0; i < size; i++) { + cJSON *extensionItem = cJSON_GetArrayItem(uieatensionItem, i); + if (extensionItem == nullptr || !cJSON_IsObject(extensionItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid obj"); + continue; + } + cJSON *uieatensionTypeItem = cJSON_GetObjectItem(extensionItem, AmsConfig::UIEATENSION_TYPE); + cJSON *uieatensionTypePickerItem = cJSON_GetObjectItem(extensionItem, AmsConfig::UIEATENSION_TYPE_PICKER); + if (uieatensionTypeItem == nullptr || !cJSON_IsString(uieatensionTypeItem) || + uieatensionTypePickerItem == nullptr || !cJSON_IsString(uieatensionTypePickerItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid key or value"); continue; } - std::string type = extension[AmsConfig::UIEATENSION_TYPE].get(); - std::string typePicker = extension[AmsConfig::UIEATENSION_TYPE_PICKER].get(); + std::string type = uieatensionTypeItem->valuestring; + std::string typePicker = uieatensionTypePickerItem->valuestring; TAG_LOGI(AAFwkTag::ABILITYMGR, "type: %{public}s, typePicker: %{public}s", type.c_str(), typePicker.c_str()); picker_[type] = typePicker; } - pickerJson.clear(); + cJSON_Delete(pickerJson); TAG_LOGI(AAFwkTag::ABILITYMGR, "read config success"); } @@ -194,12 +201,13 @@ int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) return READ_FAIL; } - json amsJson; - inFile >> amsJson; - if (amsJson.is_discarded()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "json discarded error ..."); + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + + cJSON *amsJson = cJSON_Parse(fileContent.c_str()); + if (amsJson == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "json parse error"); nonConfigFile_ = true; - inFile.close(); return READ_JSON_FAIL; } @@ -218,8 +226,7 @@ int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) LoadSupportSCBCrashRebootConfig(amsJson); LoadSupportAAKillWithReasonConfig(amsJson); SetPickerJsonObject(amsJson); - amsJson.clear(); - inFile.close(); + cJSON_Delete(amsJson); for (const auto& i : ret) { if (i != 0) { @@ -232,27 +239,29 @@ int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) return READ_OK; } -int AmsConfigurationParameter::LoadAppConfigurationForStartUpService(nlohmann::json& Object) +int AmsConfigurationParameter::LoadAppConfigurationForStartUpService(cJSON *jsonObject) { - if (!Object.contains(AmsConfig::SERVICE_ITEM_AMS)) { + cJSON *amsItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SERVICE_ITEM_AMS); + if (amsItem == nullptr) { return LOAD_CONFIGURATION_FAILED; } - UpdateStartUpServiceConfigInteger(Object, AmsConfig::MISSION_SAVE_TIME, missionSaveTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME, anrTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::AMS_TIMEOUT_TIME, amsTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::ROOT_LAUNCHER_RESTART_MAX, maxRootLauncherRestartNum_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::RESIDENT_RESTART_MAX, maxResidentRestartNum_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::RESTART_INTERVAL_TIME, restartIntervalTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::BOOT_ANIMATION_TIMEOUT_TIME, bootAnimationTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::TIMEOUT_UNIT_TIME, timeoutUnitTime_); - UpdateStartUpServiceConfigInteger(Object, AmsConfig::MULTI_USER_TYPE, multiUserType_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::MISSION_SAVE_TIME, missionSaveTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME, anrTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::AMS_TIMEOUT_TIME, amsTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::ROOT_LAUNCHER_RESTART_MAX, maxRootLauncherRestartNum_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::RESIDENT_RESTART_MAX, maxResidentRestartNum_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::RESTART_INTERVAL_TIME, restartIntervalTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::BOOT_ANIMATION_TIMEOUT_TIME, bootAnimationTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::TIMEOUT_UNIT_TIME, timeoutUnitTime_); + UpdateStartUpServiceConfigInteger(jsonObject, AmsConfig::MULTI_USER_TYPE, multiUserType_); return LOAD_CONFIGURATION_SUCCESS; } -int AmsConfigurationParameter::LoadAppConfigurationForMemoryThreshold(nlohmann::json &Object) +int AmsConfigurationParameter::LoadAppConfigurationForMemoryThreshold(cJSON *jsonObject) { int ret = 0; - if (!Object.contains("memorythreshold")) { + cJSON *memorythresholdItem = cJSON_GetObjectItem(jsonObject, "memorythreshold"); + if (memorythresholdItem == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "LoadAppConfigurationForMemoryThreshold return error"); ret = -1; } @@ -260,36 +269,37 @@ int AmsConfigurationParameter::LoadAppConfigurationForMemoryThreshold(nlohmann:: return ret; } -int AmsConfigurationParameter::LoadSystemConfiguration(nlohmann::json& Object) +int AmsConfigurationParameter::LoadSystemConfiguration(cJSON *jsonObject) { - if (Object.contains(AmsConfig::SYSTEM_CONFIGURATION) && - Object.at(AmsConfig::SYSTEM_CONFIGURATION).contains(AmsConfig::SYSTEM_ORIENTATION) && - Object.at(AmsConfig::SYSTEM_CONFIGURATION).at(AmsConfig::SYSTEM_ORIENTATION).is_string()) { - orientation_ = Object.at(AmsConfig::SYSTEM_CONFIGURATION).at(AmsConfig::SYSTEM_ORIENTATION).get(); - return READ_OK; + cJSON *systemConfigurationItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SYSTEM_CONFIGURATION); + if (systemConfigurationItem != nullptr) { + cJSON *systemOrientationItem = cJSON_GetObjectItem(systemConfigurationItem, AmsConfig::SYSTEM_ORIENTATION); + if (systemOrientationItem != nullptr && cJSON_IsString(systemOrientationItem)) { + orientation_ = systemOrientationItem->valuestring; + return READ_OK; + } } - return READ_FAIL; } -int32_t AmsConfigurationParameter::LoadBackToCallerConfig(nlohmann::json& Object) +int32_t AmsConfigurationParameter::LoadBackToCallerConfig(cJSON *jsonObject) { TAG_LOGI(AAFwkTag::ABILITYMGR, "load backTocaller config"); - if (Object.contains(AmsConfig::SUPPORT_BACK_TO_CALLER) && - Object.at(AmsConfig::SUPPORT_BACK_TO_CALLER).is_boolean()) { - supportBackToCaller_ = Object.at(AmsConfig::SUPPORT_BACK_TO_CALLER).get(); + cJSON *supportBackToCallerItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SUPPORT_BACK_TO_CALLER); + if (supportBackToCallerItem != nullptr && cJSON_IsBool(supportBackToCallerItem)) { + supportBackToCaller_ = supportBackToCallerItem->type == cJSON_True ? true : false; return READ_OK; } TAG_LOGE(AAFwkTag::ABILITYMGR, "load backTocaller failed"); return READ_FAIL; } -int32_t AmsConfigurationParameter::LoadSupportAAKillWithReasonConfig(nlohmann::json& Object) +int32_t AmsConfigurationParameter::LoadSupportAAKillWithReasonConfig(cJSON *jsonObject) { TAG_LOGI(AAFwkTag::ABILITYMGR, "load SupportAAKillWithReason config"); - if (Object.contains(AmsConfig::SUPPORT_AA_KILL_WITH_REASON) && - Object.at(AmsConfig::SUPPORT_AA_KILL_WITH_REASON).is_boolean()) { - supportAAKillWithReason_ = Object.at(AmsConfig::SUPPORT_AA_KILL_WITH_REASON).get(); + cJSON *supportAAKillWithReasonItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SUPPORT_AA_KILL_WITH_REASON); + if (supportAAKillWithReasonItem != nullptr && cJSON_IsBool(supportAAKillWithReasonItem)) { + supportAAKillWithReason_ = supportAAKillWithReasonItem->type == cJSON_True ? true : false; return READ_OK; } TAG_LOGE(AAFwkTag::ABILITYMGR, "load SupportAAKillWithReason failed"); @@ -306,12 +316,12 @@ bool AmsConfigurationParameter::IsSupportAAKillWithReason() const return supportAAKillWithReason_; } -int32_t AmsConfigurationParameter::LoadSupportSCBCrashRebootConfig(nlohmann::json& Object) +int32_t AmsConfigurationParameter::LoadSupportSCBCrashRebootConfig(cJSON *jsonObject) { TAG_LOGI(AAFwkTag::ABILITYMGR, "load scb_crash_reboot_config config"); - if (Object.contains(AmsConfig::SUPPORT_SCB_CRASH_REBOOT) && - Object.at(AmsConfig::SUPPORT_SCB_CRASH_REBOOT).is_boolean()) { - supportSceneboardCrashReboot_ = Object.at(AmsConfig::SUPPORT_SCB_CRASH_REBOOT).get(); + cJSON *suportScbCrashRebootItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SUPPORT_SCB_CRASH_REBOOT); + if (suportScbCrashRebootItem != nullptr && cJSON_IsBool(suportScbCrashRebootItem)) { + supportSceneboardCrashReboot_ = suportScbCrashRebootItem->type == cJSON_True ? true : false; return READ_OK; } TAG_LOGE(AAFwkTag::ABILITYMGR, "load scb_crash_reboot_config failed"); @@ -323,20 +333,24 @@ bool AmsConfigurationParameter::IsSupportSCBCrashReboot() const return supportSceneboardCrashReboot_; } -bool AmsConfigurationParameter::CheckServiceConfigEnable(nlohmann::json& Object, const std::string &configName, +bool AmsConfigurationParameter::CheckServiceConfigEnable(cJSON *jsonObject, const std::string &configName, JsonValueType type) { - if (Object.contains(AmsConfig::SERVICE_ITEM_AMS) && - Object.at(AmsConfig::SERVICE_ITEM_AMS).contains(configName)) { + cJSON *amsItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SERVICE_ITEM_AMS); + if (amsItem != nullptr) { + cJSON *configItem = cJSON_GetObjectItem(amsItem, configName.c_str()); + if (configItem == nullptr) { + return false; + } switch (type) { case JsonValueType::NUMBER: { - return Object.at(AmsConfig::SERVICE_ITEM_AMS).at(configName).is_number(); + return cJSON_IsNumber(configItem); } case JsonValueType::STRING: { - return Object.at(AmsConfig::SERVICE_ITEM_AMS).at(configName).is_string(); + return cJSON_IsString(configItem); } case JsonValueType::BOOLEAN: { - return Object.at(AmsConfig::SERVICE_ITEM_AMS).at(configName).is_boolean(); + return cJSON_IsBool(configItem); } default: { return false; @@ -346,19 +360,27 @@ bool AmsConfigurationParameter::CheckServiceConfigEnable(nlohmann::json& Object, return false; } -void AmsConfigurationParameter::UpdateStartUpServiceConfigInteger(nlohmann::json& Object, +void AmsConfigurationParameter::UpdateStartUpServiceConfigInteger(cJSON *jsonObject, const std::string &configName, int32_t &value) { - if (CheckServiceConfigEnable(Object, configName, JsonValueType::NUMBER)) { - value = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(configName).get(); + cJSON *amsItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SERVICE_ITEM_AMS); + if (amsItem != nullptr) { + cJSON *configItem = cJSON_GetObjectItem(amsItem, configName.c_str()); + if (configItem != nullptr && cJSON_IsNumber(configItem)) { + value = static_cast(configItem->valuedouble); + } } } -void AmsConfigurationParameter::UpdateStartUpServiceConfigString(nlohmann::json& Object, +void AmsConfigurationParameter::UpdateStartUpServiceConfigString(cJSON *jsonObject, const std::string &configName, std::string &value) { - if (CheckServiceConfigEnable(Object, configName, JsonValueType::STRING)) { - value = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(configName).get(); + cJSON *amsItem = cJSON_GetObjectItem(jsonObject, AmsConfig::SERVICE_ITEM_AMS); + if (amsItem != nullptr && cJSON_IsObject(amsItem)) { + cJSON *configItem = cJSON_GetObjectItem(amsItem, configName.c_str()); + if (configItem != nullptr && cJSON_IsString(configItem)) { + value = configItem->valuestring; + } } } diff --git a/services/abilitymgr/src/app_exit_reason_data_manager.cpp b/services/abilitymgr/src/app_exit_reason_data_manager.cpp index 869b921d6cbc0893a765cfca5474c968eff6e4c7..fc01c7d0c404ee829eff140c06f99ceed2043ba6 100644 --- a/services/abilitymgr/src/app_exit_reason_data_manager.cpp +++ b/services/abilitymgr/src/app_exit_reason_data_manager.cpp @@ -20,6 +20,8 @@ #include "ability_manager_errors.h" #include "accesstoken_kit.h" #include "exit_info_data_manager.h" +#include "insight_intent_json_util.h" +#include "json_utils.h" #include "os_account_manager_wrapper.h" namespace OHOS { @@ -327,21 +329,33 @@ DistributedKv::Value AppExitReasonDataManager::ConvertAppExitReasonInfoToValue( if (withKillMsg) { killMsg = exitReason.exitMsg; } - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_PID, processInfo.pid_ }, - { JSON_KEY_UID, processInfo.uid_ }, - { JSON_KEY_REASON, exitReason.reason }, - { JSON_KEY_SUB_KILL_REASON, exitReason.subReason }, - { JSON_KEY_EXIT_MSG, exitMsg }, - { JSON_KEY_KILL_MSG, killMsg }, - { JSON_KEY_RSS_VALUE, processInfo.rssValue }, - { JSON_KEY_PSS_VALUE, processInfo.pssValue }, - { JSON_KEY_PROCESS_NAME, processInfo.processName_ }, - { JSON_KEY_TIME_STAMP, nowMs.count() }, - { JSON_KEY_ABILITY_LIST, abilityList }, - { JSON_KEY_PROSESS_STATE, processInfo.state_ }, - }; - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return DistributedKv::Value(); + } + cJSON_AddNumberToObject(jsonObject, JSON_KEY_PID.c_str(), static_cast(processInfo.pid_)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_UID.c_str(), static_cast(processInfo.uid_)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_REASON.c_str(), static_cast(exitReason.reason)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SUB_KILL_REASON.c_str(), static_cast(exitReason.subReason)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_EXIT_MSG.c_str(), exitMsg.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_KILL_MSG.c_str(), killMsg.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_RSS_VALUE.c_str(), static_cast(processInfo.rssValue)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_PSS_VALUE.c_str(), static_cast(processInfo.pssValue)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_PROCESS_NAME.c_str(), processInfo.processName_.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_TIME_STAMP.c_str(), static_cast(nowMs.count())); + cJSON *abilityListItem = nullptr; + if (!to_json(abilityListItem, abilityList)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "to_json abilityList failed"); + cJSON_Delete(jsonObject); + return DistributedKv::Value(); + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_ABILITY_LIST.c_str(), abilityListItem); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_PROSESS_STATE.c_str(), static_cast(processInfo.state_)); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); return value; } @@ -349,59 +363,73 @@ void AppExitReasonDataManager::ConvertAppExitReasonInfoFromValue(const Distribut AAFwk::ExitReason &exitReason, int64_t &time_stamp, std::vector &abilityList, AppExecFwk::RunningProcessInfo &processInfo, bool &withKillMsg) { - nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(value.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "parse json sting failed"); return; } - if (jsonObject.contains(JSON_KEY_PID) && jsonObject[JSON_KEY_PID].is_number_integer()) { - processInfo.pid_ = jsonObject.at(JSON_KEY_PID).get(); + cJSON *pidItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_PID.c_str()); + if (pidItem != nullptr && cJSON_IsNumber(pidItem)) { + processInfo.pid_ = static_cast(pidItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_UID) && jsonObject[JSON_KEY_UID].is_number_integer()) { - processInfo.uid_ = jsonObject.at(JSON_KEY_UID).get(); + cJSON *uidItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_UID.c_str()); + if (uidItem != nullptr && cJSON_IsNumber(uidItem)) { + processInfo.uid_ = static_cast(uidItem->valuedouble); } ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); - if (jsonObject.contains(JSON_KEY_RSS_VALUE) && jsonObject[JSON_KEY_RSS_VALUE].is_number_integer()) { - processInfo.rssValue = jsonObject.at(JSON_KEY_RSS_VALUE).get(); + cJSON *rssValueItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_RSS_VALUE.c_str()); + if (rssValueItem != nullptr && cJSON_IsNumber(rssValueItem)) { + processInfo.rssValue = static_cast(rssValueItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_PSS_VALUE) && jsonObject[JSON_KEY_PSS_VALUE].is_number_integer()) { - processInfo.pssValue = jsonObject.at(JSON_KEY_PSS_VALUE).get(); + cJSON *pssValueItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_PSS_VALUE.c_str()); + if (pssValueItem != nullptr && cJSON_IsNumber(pssValueItem)) { + processInfo.pssValue = static_cast(pssValueItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_PROCESS_NAME) && jsonObject[JSON_KEY_PROCESS_NAME].is_string()) { - processInfo.processName_ = jsonObject.at(JSON_KEY_PROCESS_NAME).get(); + cJSON *processNameItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_PROCESS_NAME.c_str()); + if (processNameItem != nullptr && cJSON_IsString(processNameItem)) { + processInfo.processName_ = processNameItem->valuestring; } - if (jsonObject.contains(JSON_KEY_TIME_STAMP) && jsonObject[JSON_KEY_TIME_STAMP].is_number_integer()) { - time_stamp = jsonObject.at(JSON_KEY_TIME_STAMP).get(); + cJSON *timeStampItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_TIME_STAMP.c_str()); + if (timeStampItem != nullptr && cJSON_IsNumber(timeStampItem)) { + time_stamp = static_cast(timeStampItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_PROSESS_STATE) && jsonObject[JSON_KEY_PROSESS_STATE].is_number_integer()) { - processInfo.state_ = static_cast( - jsonObject.at(JSON_KEY_PROSESS_STATE).get()); + cJSON *processStateItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_PROSESS_STATE.c_str()); + if (processStateItem != nullptr && cJSON_IsNumber(processStateItem)) { + processInfo.state_ = static_cast(processStateItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_ABILITY_LIST) && jsonObject[JSON_KEY_ABILITY_LIST].is_array()) { + cJSON *abilityListItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_ABILITY_LIST.c_str()); + if (abilityListItem != nullptr && cJSON_IsArray(abilityListItem)) { abilityList.clear(); - auto size = jsonObject[JSON_KEY_ABILITY_LIST].size(); - for (size_t i = 0; i < size; i++) { - if (jsonObject[JSON_KEY_ABILITY_LIST][i].is_string()) { - abilityList.emplace_back(jsonObject[JSON_KEY_ABILITY_LIST][i]); + int size = cJSON_GetArraySize(abilityListItem); + for (int i = 0; i < size; i++) { + cJSON *abilityItem = cJSON_GetArrayItem(abilityListItem, i); + if (abilityItem != nullptr && cJSON_IsString(abilityItem)) { + std::string ability = abilityItem->valuestring; + abilityList.emplace_back(ability); } } } + cJSON_Delete(jsonObject); } -void AppExitReasonDataManager::ConvertReasonFromValue(const nlohmann::json &jsonObject, AAFwk::ExitReason &exitReason, +void AppExitReasonDataManager::ConvertReasonFromValue(const cJSON *jsonObject, AAFwk::ExitReason &exitReason, bool &withKillMsg) { - if (jsonObject.contains(JSON_KEY_REASON) && jsonObject[JSON_KEY_REASON].is_number_integer()) { - exitReason.reason = jsonObject.at(JSON_KEY_REASON).get(); + cJSON *reasonItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_REASON.c_str()); + if (reasonItem != nullptr && cJSON_IsNumber(reasonItem)) { + exitReason.reason = static_cast(reasonItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_SUB_KILL_REASON) && jsonObject[JSON_KEY_SUB_KILL_REASON].is_number_integer()) { - exitReason.subReason = jsonObject.at(JSON_KEY_SUB_KILL_REASON).get(); + cJSON *subReasonItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_SUB_KILL_REASON.c_str()); + if (subReasonItem != nullptr && cJSON_IsNumber(subReasonItem)) { + exitReason.subReason = static_cast(subReasonItem->valuedouble); } - if (jsonObject.contains(JSON_KEY_EXIT_MSG) && jsonObject[JSON_KEY_EXIT_MSG].is_string()) { - exitReason.exitMsg = jsonObject.at(JSON_KEY_EXIT_MSG).get(); + cJSON *exitMsgItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_EXIT_MSG.c_str()); + if (exitMsgItem != nullptr && cJSON_IsString(exitMsgItem)) { + exitReason.exitMsg = exitMsgItem->valuestring; } - if (jsonObject.contains(JSON_KEY_KILL_MSG) && jsonObject[JSON_KEY_KILL_MSG].is_string()) { - auto killMsg = jsonObject.at(JSON_KEY_KILL_MSG).get(); + cJSON *killMsgItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_KILL_MSG.c_str()); + if (killMsgItem != nullptr && cJSON_IsString(killMsgItem)) { + std::string killMsg = killMsgItem->valuestring; if (!killMsg.empty()) { exitReason.exitMsg = killMsg; withKillMsg = true; @@ -783,11 +811,30 @@ void AppExitReasonDataManager::UpdateAbilityRecoverInfo(uint32_t accessTokenId, DistributedKv::Value AppExitReasonDataManager::ConvertAbilityRecoverInfoToValue( const std::vector &recoverInfoList, const std::vector &sessionIdList) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_RECOVER_INFO_LIST, recoverInfoList }, - { JSON_KEY_SESSION_ID_LIST, sessionIdList }, - }; - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return DistributedKv::Value(); + } + cJSON *recoverInfoListItem = nullptr; + if (!to_json(recoverInfoListItem, recoverInfoList)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "to json recoverInfoList failed"); + cJSON_Delete(jsonObject); + return DistributedKv::Value(); + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_RECOVER_INFO_LIST.c_str(), recoverInfoListItem); + + cJSON *sessionIdListItem = nullptr; + if (!to_json(sessionIdListItem, sessionIdList)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "to json sessionIdList failed"); + cJSON_Delete(jsonObject); + return DistributedKv::Value(); + } + cJSON_AddItemToObject(jsonObject, JSON_KEY_SESSION_ID_LIST.c_str(), sessionIdListItem); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); TAG_LOGI(AAFwkTag::ABILITYMGR, "ConvertAbilityRecoverInfoToValue value: %{public}s", value.ToString().c_str()); return value; } @@ -795,44 +842,33 @@ DistributedKv::Value AppExitReasonDataManager::ConvertAbilityRecoverInfoToValue( void AppExitReasonDataManager::ConvertAbilityRecoverInfoFromValue(const DistributedKv::Value &value, std::vector &recoverInfoList, std::vector &sessionIdList) { - nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(value.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "parse json sting failed"); return; } - if (jsonObject.contains(JSON_KEY_RECOVER_INFO_LIST) - && jsonObject[JSON_KEY_RECOVER_INFO_LIST].is_array()) { - recoverInfoList.clear(); - auto size = jsonObject[JSON_KEY_RECOVER_INFO_LIST].size(); - for (size_t i = 0; i < size; i++) { - if (jsonObject[JSON_KEY_RECOVER_INFO_LIST][i].is_string()) { - recoverInfoList.emplace_back(jsonObject[JSON_KEY_RECOVER_INFO_LIST][i]); - } - } - } - if (jsonObject.contains(JSON_KEY_SESSION_ID_LIST) - && jsonObject[JSON_KEY_SESSION_ID_LIST].is_array()) { - sessionIdList.clear(); - auto size = jsonObject[JSON_KEY_SESSION_ID_LIST].size(); - for (size_t i = 0; i < size; i++) { - if (jsonObject[JSON_KEY_SESSION_ID_LIST][i].is_number_integer()) { - sessionIdList.emplace_back(jsonObject[JSON_KEY_SESSION_ID_LIST][i]); - } - } - } + cJSON *recoverInfoListItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_RECOVER_INFO_LIST.c_str()); + from_json(recoverInfoListItem, recoverInfoList); + + cJSON *sessionIdListItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_SESSION_ID_LIST.c_str()); + from_json(sessionIdListItem, sessionIdList); + + cJSON_Delete(jsonObject); } void AppExitReasonDataManager::ConvertAccessTokenIdFromValue(const DistributedKv::Value &value, uint32_t &accessTokenId) { - nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(value.ToString().c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "parse json sting failed"); return; } - if (jsonObject.contains(JSON_KEY_ACCESSTOKENId)) { - accessTokenId=jsonObject[JSON_KEY_ACCESSTOKENId]; + cJSON *accessTokenIdItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_ACCESSTOKENId.c_str()); + if (accessTokenIdItem != nullptr && cJSON_IsNumber(accessTokenIdItem)) { + accessTokenId = static_cast(accessTokenIdItem->valuedouble); } + cJSON_Delete(jsonObject); } void AppExitReasonDataManager::InnerDeleteAbilityRecoverInfo(uint32_t accessTokenId) @@ -902,13 +938,19 @@ DistributedKv::Key AppExitReasonDataManager::GetSessionIdKey(const int sessionId { return DistributedKv::Key(KEY_RECOVER_INFO_PREFIX + std::to_string(sessionId)); } - + DistributedKv::Value AppExitReasonDataManager::ConvertAccessTokenIdToValue(uint32_t accessTokenId) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_ACCESSTOKENId, accessTokenId }, - }; - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return DistributedKv::Value(); + } + cJSON_AddNumberToObject(jsonObject, JSON_KEY_ACCESSTOKENId.c_str(), static_cast(accessTokenId)); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); TAG_LOGI(AAFwkTag::ABILITYMGR, "ConvertAccessTokenIdToValue value: %{public}s", value.ToString().c_str()); return value; } @@ -925,21 +967,26 @@ DistributedKv::Value AppExitReasonDataManager::ConvertAppExitReasonInfoToValueOf if (withKillMsg) { killMsg = exitReason.exitMsg; } - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_PID, processInfo.pid_ }, - { JSON_KEY_UID, processInfo.uid_ }, - { JSON_KEY_REASON, exitReason.reason }, - { JSON_KEY_SUB_KILL_REASON, exitReason.subReason }, - { JSON_KEY_EXIT_MSG, exitMsg }, - { JSON_KEY_KILL_MSG, killMsg }, - { JSON_KEY_RSS_VALUE, processInfo.rssValue }, - { JSON_KEY_PSS_VALUE, processInfo.pssValue }, - { JSON_KEY_PROCESS_NAME, processInfo.processName_ }, - { JSON_KEY_TIME_STAMP, nowMs.count() }, - { JSON_KEY_EXTENSION_NAME, extensionListName }, - }; - - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return DistributedKv::Value(); + } + cJSON_AddNumberToObject(jsonObject, JSON_KEY_PID.c_str(), static_cast(processInfo.pid_)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_UID.c_str(), static_cast(processInfo.uid_)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_REASON.c_str(), static_cast(exitReason.reason)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SUB_KILL_REASON.c_str(), static_cast(exitReason.subReason)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_EXIT_MSG.c_str(), exitMsg.c_str()); + cJSON_AddStringToObject(jsonObject, JSON_KEY_KILL_MSG.c_str(), killMsg.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_RSS_VALUE.c_str(), static_cast(processInfo.rssValue)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_PSS_VALUE.c_str(), static_cast(processInfo.pssValue)); + cJSON_AddStringToObject(jsonObject, JSON_KEY_PROCESS_NAME.c_str(), processInfo.processName_.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_TIME_STAMP.c_str(), static_cast(nowMs.count())); + cJSON_AddStringToObject(jsonObject, JSON_KEY_EXTENSION_NAME.c_str(), extensionListName.c_str()); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); TAG_LOGI(AAFwkTag::ABILITYMGR, "value: %{public}s", value.ToString().c_str()); return value; } diff --git a/services/abilitymgr/src/assert_fault_proxy.cpp b/services/abilitymgr/src/assert_fault_proxy.cpp index 246be12e3ef652030140dc0ebff976629e3a0057..3b90ebe18da135dc14340bd2b568df0c2d634671 100644 --- a/services/abilitymgr/src/assert_fault_proxy.cpp +++ b/services/abilitymgr/src/assert_fault_proxy.cpp @@ -15,6 +15,7 @@ #include "ability_manager_client.h" #include "assert_fault_proxy.h" #include "hilog_tag_wrapper.h" +#include "json_utils.h" #include "scene_board_judgement.h" #include "task_handler_wrap.h" @@ -204,12 +205,19 @@ void ModalSystemAssertUIExtension::AssertDialogConnection::OnAbilityConnectDone( data.WriteString16(u"abilityName"); data.WriteString16(Str8ToStr16(want_.GetElement().GetAbilityName())); data.WriteString16(u"parameters"); - nlohmann::json param; - param[UIEXTENSION_TYPE_KEY] = want_.GetStringParam(UIEXTENSION_TYPE_KEY); - param[ASSERT_FAULT_DETAIL] = want_.GetStringParam(ASSERT_FAULT_DETAIL); - param[AAFwk::Want::PARAM_ASSERT_FAULT_SESSION_ID] = - want_.GetStringParam(AAFwk::Want::PARAM_ASSERT_FAULT_SESSION_ID); - std::string paramStr = param.dump(); + + cJSON *param = cJSON_CreateObject(); + if (param == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } + cJSON_AddStringToObject(param, UIEXTENSION_TYPE_KEY, want_.GetStringParam(UIEXTENSION_TYPE_KEY).c_str()); + cJSON_AddStringToObject(param, ASSERT_FAULT_DETAIL, want_.GetStringParam(ASSERT_FAULT_DETAIL).c_str()); + cJSON_AddStringToObject(param, AAFwk::Want::PARAM_ASSERT_FAULT_SESSION_ID.c_str(), + want_.GetStringParam(AAFwk::Want::PARAM_ASSERT_FAULT_SESSION_ID).c_str()); + + std::string paramStr = AAFwk::JsonUtils::GetInstance().ToString(param); + cJSON_Delete(param); data.WriteString16(Str8ToStr16(paramStr)); uint32_t code = !Rosen::SceneBoardJudgement::IsSceneBoardEnabled() ? COMMAND_START_DIALOG : AAFwk::IAbilityConnection::ON_ABILITY_CONNECT_DONE; diff --git a/services/abilitymgr/src/deeplink_reserve/deeplink_reserve_config.cpp b/services/abilitymgr/src/deeplink_reserve/deeplink_reserve_config.cpp index 88f01b055e20b10ea9296320f0050839ba6d216e..5e98d1ff2c5a2c932bed5713267885372a56ec0a 100644 --- a/services/abilitymgr/src/deeplink_reserve/deeplink_reserve_config.cpp +++ b/services/abilitymgr/src/deeplink_reserve/deeplink_reserve_config.cpp @@ -59,18 +59,22 @@ bool DeepLinkReserveConfig::LoadConfiguration() TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); std::string configPath = GetConfigPath(); TAG_LOGD(AAFwkTag::ABILITYMGR, "Deeplink reserve config path is: %{public}s", configPath.c_str()); - nlohmann::json jsonBuf; + cJSON *jsonBuf = nullptr; if (!ReadFileInfoJson(configPath, jsonBuf)) { return false; } + if (jsonBuf == nullptr) { + return false; + } if (!LoadReservedUriList(jsonBuf)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load fail"); + cJSON_Delete(jsonBuf); return false; } - + cJSON_Delete(jsonBuf); return true; } - + bool DeepLinkReserveConfig::IsLinkReserved(const std::string &linkString, std::string &bundleName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); @@ -174,46 +178,54 @@ bool DeepLinkReserveConfig::IsUriMatched(const ReserveUri &reservedUri, const st return false; } -void DeepLinkReserveConfig::LoadReservedUrilItem(const nlohmann::json &jsonUriObject, std::vector &uriList) +void DeepLinkReserveConfig::LoadReservedUrilItem(const cJSON *jsonUriObject, std::vector &uriList) { ReserveUri reserveUri; - if (jsonUriObject.contains(SCHEME_NAME) && jsonUriObject.at(SCHEME_NAME).is_string()) { - std::string schemeName = jsonUriObject.at(SCHEME_NAME).get(); + cJSON *schemeNameItem = cJSON_GetObjectItem(jsonUriObject, SCHEME_NAME.c_str()); + if (schemeNameItem != nullptr && cJSON_IsString(schemeNameItem)) { + std::string schemeName = schemeNameItem->valuestring; reserveUri.scheme = schemeName; TAG_LOGD(AAFwkTag::ABILITYMGR, "scheme:%{public}s", reserveUri.scheme.c_str()); } - if (jsonUriObject.contains(HOST_NAME) && jsonUriObject.at(HOST_NAME).is_string()) { - std::string hostName = jsonUriObject.at(HOST_NAME).get(); + cJSON *hostNameItem = cJSON_GetObjectItem(jsonUriObject, HOST_NAME.c_str()); + if (hostNameItem != nullptr && cJSON_IsString(hostNameItem)) { + std::string hostName = hostNameItem->valuestring; reserveUri.host = hostName; TAG_LOGD(AAFwkTag::ABILITYMGR, "host:%{public}s", reserveUri.host.c_str()); } - if (jsonUriObject.contains(PORT_NAME) && jsonUriObject.at(PORT_NAME).is_string()) { - std::string portName = jsonUriObject.at(PORT_NAME).get(); + cJSON *portNameItem = cJSON_GetObjectItem(jsonUriObject, PORT_NAME.c_str()); + if (portNameItem != nullptr && cJSON_IsString(portNameItem)) { + std::string portName = portNameItem->valuestring; reserveUri.port = portName; TAG_LOGD(AAFwkTag::ABILITYMGR, "port:%{public}s", reserveUri.port.c_str()); } - if (jsonUriObject.contains(PATH_NAME) && jsonUriObject.at(PATH_NAME).is_string()) { - std::string pathName = jsonUriObject.at(PATH_NAME).get(); + cJSON *pathNameItem = cJSON_GetObjectItem(jsonUriObject, PATH_NAME.c_str()); + if (pathNameItem != nullptr && cJSON_IsString(pathNameItem)) { + std::string pathName = pathNameItem->valuestring; reserveUri.path = PATH_NAME; TAG_LOGD(AAFwkTag::ABILITYMGR, "path:%{public}s", reserveUri.path.c_str()); } - if (jsonUriObject.contains(PATH_START_WITH_NAME) && jsonUriObject.at(PATH_START_WITH_NAME).is_string()) { - std::string pathStartWithName = jsonUriObject.at(PATH_START_WITH_NAME).get(); - reserveUri.pathStartWith = pathStartWithName; + cJSON *pathStartWithItem = cJSON_GetObjectItem(jsonUriObject, PATH_START_WITH_NAME.c_str()); + if (pathStartWithItem != nullptr && cJSON_IsString(pathStartWithItem)) { + std::string pathStartWith = pathStartWithItem->valuestring; + reserveUri.pathStartWith = pathStartWith; TAG_LOGD(AAFwkTag::ABILITYMGR, "pathStartWith:%{public}s", reserveUri.pathStartWith.c_str()); } - if (jsonUriObject.contains(PATH_REGEX_NAME) && jsonUriObject.at(PATH_REGEX_NAME).is_string()) { - std::string pathRegexName = jsonUriObject.at(PATH_REGEX_NAME).get(); + cJSON *pathRegexNameItem = cJSON_GetObjectItem(jsonUriObject, PATH_REGEX_NAME.c_str()); + if (pathRegexNameItem != nullptr && cJSON_IsString(pathRegexNameItem)) { + std::string pathRegexName = pathRegexNameItem->valuestring; reserveUri.pathRegex = pathRegexName; TAG_LOGD(AAFwkTag::ABILITYMGR, "pathRegex:%{public}s", reserveUri.pathRegex.c_str()); } - if (jsonUriObject.contains(TYPE_NAME) && jsonUriObject.at(TYPE_NAME).is_string()) { - std::string typeName = jsonUriObject.at(TYPE_NAME).get(); + cJSON *typeNameItem = cJSON_GetObjectItem(jsonUriObject, TYPE_NAME.c_str()); + if (typeNameItem != nullptr && cJSON_IsString(typeNameItem)) { + std::string typeName = typeNameItem->valuestring; reserveUri.type = typeName; TAG_LOGD(AAFwkTag::ABILITYMGR, "type:%{public}s", reserveUri.type.c_str()); } - if (jsonUriObject.contains(UTD_NAME) && jsonUriObject.at(UTD_NAME).is_string()) { - std::string utdName = jsonUriObject.at(UTD_NAME).get(); + cJSON *utdNameItem = cJSON_GetObjectItem(jsonUriObject, UTD_NAME.c_str()); + if (utdNameItem != nullptr && cJSON_IsString(utdNameItem)) { + std::string utdName = utdNameItem->valuestring; reserveUri.utd = utdName; TAG_LOGD(AAFwkTag::ABILITYMGR, "utd:%{public}s", reserveUri.utd.c_str()); } @@ -221,35 +233,43 @@ void DeepLinkReserveConfig::LoadReservedUrilItem(const nlohmann::json &jsonUriOb uriList.emplace_back(reserveUri); } -bool DeepLinkReserveConfig::LoadReservedUriList(const nlohmann::json &object) +bool DeepLinkReserveConfig::LoadReservedUriList(const cJSON *object) { - if (!object.contains(DEEPLINK_RESERVED_URI_NAME) || !object.at(DEEPLINK_RESERVED_URI_NAME).is_array()) { + cJSON *uriNameItems = cJSON_GetObjectItem(object, DEEPLINK_RESERVED_URI_NAME.c_str()); + if (uriNameItems == nullptr || !cJSON_IsArray(uriNameItems)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "uri config absent"); return false; } - - for (auto &item : object.at(DEEPLINK_RESERVED_URI_NAME).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + int size = cJSON_GetArraySize(uriNameItems); + for (int i = 0; i < size; i++) { + cJSON *uriNameItem = cJSON_GetArrayItem(uriNameItems, i); + if (uriNameItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + return false; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(uriNameItem, BUNDLE_NAME.c_str()); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "reserve bundleName fail"); return false; } - if (!jsonObject.contains(URIS_NAME) || !jsonObject.at(URIS_NAME).is_array()) { + cJSON *urisNameItems = cJSON_GetObjectItem(uriNameItem, URIS_NAME.c_str()); + if (urisNameItems == nullptr || !cJSON_IsArray(urisNameItems)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "reserve uris fail"); return false; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; std::vector uriList; - for (auto &uriItem : jsonObject.at(URIS_NAME).items()) { - const nlohmann::json& jsonUriObject = uriItem.value(); - LoadReservedUrilItem(jsonUriObject, uriList); + int uriSize = cJSON_GetArraySize(urisNameItems); + for (int j = 0; j < uriSize; j++) { + cJSON *urisNameItem = cJSON_GetArrayItem(urisNameItems, j); + LoadReservedUrilItem(urisNameItem, uriList); } deepLinkReserveUris_.insert(std::make_pair(bundleName, uriList)); } return true; } -bool DeepLinkReserveConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool DeepLinkReserveConfig::ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf) { if (access(filePath.c_str(), F_OK) != 0) { TAG_LOGE(AAFwkTag::ABILITYMGR, "reserve config absent"); @@ -286,9 +306,11 @@ bool DeepLinkReserveConfig::ReadFileInfoJson(const std::string &filePath, nlohma } in.seekg(0, std::ios::beg); - jsonBuf = nlohmann::json::parse(in, nullptr, false); + std::string fileContent((std::istreambuf_iterator(in)), std::istreambuf_iterator()); in.close(); - if (jsonBuf.is_discarded()) { + + jsonBuf = cJSON_Parse(fileContent.c_str()); + if (jsonBuf == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bad profile file"); return false; } diff --git a/services/abilitymgr/src/extension_config.cpp b/services/abilitymgr/src/extension_config.cpp index 2ced894adaa1b88bae23a0b3330ec682d9eface4..585db9f496028a28724cc9dba4d7804f95b0b01d 100644 --- a/services/abilitymgr/src/extension_config.cpp +++ b/services/abilitymgr/src/extension_config.cpp @@ -60,13 +60,15 @@ std::string ExtensionConfig::GetExtensionConfigPath() const void ExtensionConfig::LoadExtensionConfiguration() { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); - nlohmann::json jsonBuf; + cJSON *jsonBuf = nullptr; if (!ReadFileInfoJson(GetExtensionConfigPath().c_str(), jsonBuf)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "parse file failed"); return; } LoadExtensionConfig(jsonBuf); + + cJSON_Delete(jsonBuf); } int32_t ExtensionConfig::GetExtensionAutoDisconnectTime(const std::string &extensionTypeName) @@ -110,20 +112,22 @@ bool ExtensionConfig::IsExtensionStartServiceEnable(const std::string &extension return EXTENSION_START_SERVICE_ENABLE_FLAG_DEFAULT; } -void ExtensionConfig::LoadExtensionConfig(const nlohmann::json &object) +void ExtensionConfig::LoadExtensionConfig(const cJSON *object) { - if (!object.contains(EXTENSION_CONFIG_NAME) || !object.at(EXTENSION_CONFIG_NAME).is_array()) { + cJSON *itemObject = cJSON_GetObjectItem(object, EXTENSION_CONFIG_NAME); + if (itemObject == nullptr || !cJSON_IsArray(itemObject)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "extension config null"); return; } - - for (auto &item : object.at(EXTENSION_CONFIG_NAME).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(EXTENSION_TYPE_NAME) || !jsonObject.at(EXTENSION_TYPE_NAME).is_string()) { + int size = cJSON_GetArraySize(itemObject); + for (int i = 0; i < size; i++) { + cJSON *jsonObject = cJSON_GetArrayItem(jsonObject, i); + cJSON *typeNameItem = cJSON_GetObjectItem(jsonObject, EXTENSION_TYPE_NAME); + if (typeNameItem == nullptr || !cJSON_IsString(typeNameItem)) { continue; } std::lock_guard lock(configMapMutex_); - std::string extensionTypeName = jsonObject.at(EXTENSION_TYPE_NAME).get(); + std::string extensionTypeName = typeNameItem->valuestring; LoadExtensionAutoDisconnectTime(jsonObject, extensionTypeName); bool hasAbilityAccess = LoadExtensionAbilityAccess(jsonObject, extensionTypeName); if (!hasAbilityAccess) { @@ -135,59 +139,58 @@ void ExtensionConfig::LoadExtensionConfig(const nlohmann::json &object) } } -void ExtensionConfig::LoadExtensionAutoDisconnectTime(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionAutoDisconnectTime(const cJSON *object, const std::string &extensionTypeName) { - if (!object.contains(EXTENSION_AUTO_DISCONNECT_TIME) || - !object.at(EXTENSION_AUTO_DISCONNECT_TIME).is_number()) { + cJSON *itemObject = cJSON_GetObjectItem(object, EXTENSION_AUTO_DISCONNECT_TIME); + if (itemObject == nullptr || !cJSON_IsNumber(itemObject)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "auto disconnect time config null"); return; } - int32_t extensionAutoDisconnectTime = object.at(EXTENSION_AUTO_DISCONNECT_TIME).get(); + int32_t extensionAutoDisconnectTime = static_cast(itemObject->valuedouble); configMap_[extensionTypeName].extensionAutoDisconnectTime = extensionAutoDisconnectTime; } -void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const nlohmann::json &object, - std::string extensionTypeName) +void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const cJSON *object, std::string extensionTypeName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); - if (!object.contains(EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME) || - !object.at(EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME).is_boolean()) { + cJSON *itemObject = cJSON_GetObjectItem(object, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME); + if (itemObject == nullptr || !cJSON_IsBool(itemObject)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "third Party config null"); return; } - bool flag = object.at(EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME).get(); + bool flag = itemObject->type == cJSON_True ? true : false; configMap_[extensionTypeName].thirdPartyAppEnableFlag = flag; TAG_LOGD(AAFwkTag::ABILITYMGR, "The %{public}s extension's third party app blocked flag is %{public}d", extensionTypeName.c_str(), flag); } -void ExtensionConfig::LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeName) +void ExtensionConfig::LoadExtensionServiceBlockedList(const cJSON *object, std::string extensionTypeName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); - if (!object.contains(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG) || - !object.at(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG).is_boolean()) { + cJSON *startupEnableFlagItem = cJSON_GetObjectItem(object, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG); + if (startupEnableFlagItem == nullptr || !cJSON_IsBool(startupEnableFlagItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "service enable config null"); return; } - bool serviceEnableFlag = object.at(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG).get(); + bool serviceEnableFlag = startupEnableFlagItem->type == cJSON_True ? true : false; if (!serviceEnableFlag) { configMap_[extensionTypeName].serviceEnableFlag = serviceEnableFlag; TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s Service startup is blocked.", extensionTypeName.c_str()); return; } - if (!object.contains(EXTENSION_SERVICE_BLOCKED_LIST_NAME) || - !object.at(EXTENSION_SERVICE_BLOCKED_LIST_NAME).is_array()) { + cJSON *blockedListNameItem = cJSON_GetObjectItem(object, EXTENSION_SERVICE_BLOCKED_LIST_NAME); + if (blockedListNameItem == nullptr || !cJSON_IsArray(blockedListNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "service config null"); return; } std::unordered_set serviceBlockedList; - for (auto &item : object.at(EXTENSION_SERVICE_BLOCKED_LIST_NAME).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.is_string()) { + int size = cJSON_GetArraySize(blockedListNameItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(blockedListNameItem, i); + if (childItem == nullptr || !cJSON_IsString(childItem)) { continue; } - std::string serviceUri = jsonObject.get(); + std::string serviceUri = childItem->valuestring; if (CheckExtensionUriValid(serviceUri)) { serviceBlockedList.emplace(serviceUri); } @@ -197,17 +200,17 @@ void ExtensionConfig::LoadExtensionServiceBlockedList(const nlohmann::json &obje extensionTypeName.c_str(), serviceBlockedList.size()); } -bool ExtensionConfig::LoadExtensionAbilityAccess(const nlohmann::json &object, const std::string &extensionTypeName) +bool ExtensionConfig::LoadExtensionAbilityAccess(const cJSON *object, const std::string &extensionTypeName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); - if (!object.contains(ABILITY_ACCESS) || !object.at(ABILITY_ACCESS).is_object()) { + cJSON *accessJson = cJSON_GetObjectItem(object, ABILITY_ACCESS); + if (accessJson == nullptr || !cJSON_IsObject(accessJson)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "parse ability_access failed"); configMap_[extensionTypeName].hasAbilityAccess = false; return false; } configMap_[extensionTypeName].hasAbilityAccess = true; - const nlohmann::json &accessJson = object.at(ABILITY_ACCESS); auto &abilityAccess = configMap_[extensionTypeName].abilityAccess; auto &jsonUtils = JsonUtils::GetInstance(); abilityAccess.thirdPartyAppAccessFlag = jsonUtils.JsonToOptionalBool(accessJson, THIRD_PARTY_APP_ACCESS_FLAG); @@ -233,50 +236,52 @@ std::string ExtensionConfig::FormatAccessFlag(const std::optional &flag) return flag.value() ? "true" : "false"; } -void ExtensionConfig::LoadExtensionAllowOrBlockedList(const nlohmann::json &object, const std::string &key, +void ExtensionConfig::LoadExtensionAllowOrBlockedList(const cJSON *object, const std::string &key, std::unordered_set &list) { TAG_LOGD(AAFwkTag::ABILITYMGR, "LoadExtensionAllowOrBlockedList."); - if (!object.contains(key) || !object.at(key).is_array()) { + cJSON *itemObject = cJSON_GetObjectItem(object, key.c_str()); + if (itemObject == nullptr || !cJSON_IsArray(itemObject)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s config null", key.c_str()); return; } list.clear(); - for (auto &item : object.at(key).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.is_string()) { + int size = cJSON_GetArraySize(itemObject); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(itemObject, i); + if (childItem == nullptr || !cJSON_IsString(childItem)) { continue; } - std::string serviceUri = jsonObject.get(); + std::string serviceUri = childItem->valuestring; if (CheckExtensionUriValid(serviceUri)) { list.emplace(serviceUri); } } } -void ExtensionConfig::LoadExtensionNetworkEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionNetworkEnable(const cJSON *object, const std::string &extensionTypeName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "LoadExtensionNetworkEnable call"); - if (!object.contains(NETWORK_ACCESS_ENABLE_FLAG) || !object.at(NETWORK_ACCESS_ENABLE_FLAG).is_boolean()) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "network enable flag null"); + cJSON *itemObject = cJSON_GetObjectItem(object, NETWORK_ACCESS_ENABLE_FLAG); + if (itemObject == nullptr || !cJSON_IsBool(itemObject)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "network enable flag null"); return; } - bool flag = object.at(NETWORK_ACCESS_ENABLE_FLAG).get(); + bool flag = itemObject->type == cJSON_True ? true : false; configMap_[extensionTypeName].networkEnableFlag = flag; TAG_LOGD(AAFwkTag::ABILITYMGR, "The %{public}s extension's network enable flag is %{public}d", extensionTypeName.c_str(), flag); } -void ExtensionConfig::LoadExtensionSAEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionSAEnable(const cJSON *object, const std::string &extensionTypeName) { TAG_LOGD(AAFwkTag::ABILITYMGR, "LoadExtensionSAEnable call"); - if (!object.contains(SA_ACCESS_ENABLE_FLAG) || !object.at(SA_ACCESS_ENABLE_FLAG).is_boolean()) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "sa enable flag null"); + cJSON *itemObject = cJSON_GetObjectItem(object, SA_ACCESS_ENABLE_FLAG); + if (itemObject == nullptr || !cJSON_IsBool(itemObject)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sa enable flag null"); return; } - bool flag = object.at(SA_ACCESS_ENABLE_FLAG).get(); + bool flag = itemObject->type == cJSON_True ? true : false; configMap_[extensionTypeName].saEnableFlag = flag; TAG_LOGD(AAFwkTag::ABILITYMGR, "The %{public}s extension's sa enable flag is %{public}d", extensionTypeName.c_str(), flag); @@ -408,7 +413,7 @@ bool ExtensionConfig::IsExtensionSAEnable(const std::string &extensionTypeName) return EXTENSION_SA_ENABLE_FLAG_DEFAULT; } -bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf) { if (access(filePath.c_str(), F_OK) != 0) { TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s, not existed", filePath.c_str()); @@ -434,9 +439,11 @@ bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::js } in.seekg(0, std::ios::beg); - jsonBuf = nlohmann::json::parse(in, nullptr, false); + std::string fileContent((std::istreambuf_iterator(in)), std::istreambuf_iterator()); in.close(); - if (jsonBuf.is_discarded()) { + + jsonBuf = cJSON_Parse(fileContent.c_str()); + if (jsonBuf == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bad profile file"); return false; } diff --git a/services/abilitymgr/src/inner_mission_info.cpp b/services/abilitymgr/src/inner_mission_info.cpp index bdbad01a8ed7b9791fc08aa5b81bf719e392445f..28b26617234319cf07cec79c6e1a6cce4bea3700 100644 --- a/services/abilitymgr/src/inner_mission_info.cpp +++ b/services/abilitymgr/src/inner_mission_info.cpp @@ -16,6 +16,7 @@ #include "inner_mission_info.h" #include "hilog_tag_wrapper.h" +#include "json_utils.h" namespace OHOS { namespace AAFwk { @@ -39,107 +40,163 @@ const std::string KEY_HAS_RECONER_INFO = "hasRecoverInfo"; } std::string InnerMissionInfo::ToJsonStr() const { - nlohmann::json value; - value[KEY_MISSION_NAME] = missionName; - value[KEY_LAUNCH_MODE] = launchMode; - value[KEY_IS_TEMPORARY] = isTemporary; - value[KEY_BUNDLE_NAME] = bundleName; - value[KEY_START_METHOD] = startMethod; - value[KEY_UID] = uid; - value[KEY_SPEC_FLAG] = specifiedFlag; - value[KEY_MISSION_ID] = missionInfo.id; - value[KEY_RUNNING_STATE] = missionInfo.runningState; - value[KEY_LOCKED_STATE] = missionInfo.lockedState; - value[KEY_CONTINUABLE] = missionInfo.continuable; - value[KEY_TIME] = missionInfo.time; - value[KEY_LABEL] = missionInfo.label; - value[KEY_ICON_PATH] = missionInfo.iconPath; - value[KEY_WANT] = missionInfo.want.ToUri(); - value[KEY_HAS_RECONER_INFO] = hasRecoverInfo; - - return value.dump(); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return ""; + } + cJSON_AddStringToObject(jsonObject, KEY_MISSION_NAME.c_str(), missionName.c_str()); + cJSON_AddNumberToObject(jsonObject, KEY_LAUNCH_MODE.c_str(), static_cast(launchMode)); + cJSON_AddBoolToObject(jsonObject, KEY_IS_TEMPORARY.c_str(), isTemporary); + cJSON_AddStringToObject(jsonObject, KEY_BUNDLE_NAME.c_str(), bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, KEY_START_METHOD.c_str(), static_cast(startMethod)); + cJSON_AddNumberToObject(jsonObject, KEY_UID.c_str(), static_cast(uid)); + cJSON_AddStringToObject(jsonObject, KEY_SPEC_FLAG.c_str(), specifiedFlag.c_str()); + cJSON_AddNumberToObject(jsonObject, KEY_MISSION_ID.c_str(), static_cast(missionInfo.id)); + cJSON_AddNumberToObject(jsonObject, KEY_RUNNING_STATE.c_str(), static_cast(missionInfo.runningState)); + cJSON_AddBoolToObject(jsonObject, KEY_LOCKED_STATE.c_str(), missionInfo.lockedState); + cJSON_AddBoolToObject(jsonObject, KEY_CONTINUABLE.c_str(), missionInfo.continuable); + cJSON_AddStringToObject(jsonObject, KEY_TIME.c_str(), missionInfo.time.c_str()); + cJSON_AddStringToObject(jsonObject, KEY_LABEL.c_str(), missionInfo.label.c_str()); + cJSON_AddStringToObject(jsonObject, KEY_ICON_PATH.c_str(), missionInfo.iconPath.c_str()); + cJSON_AddStringToObject(jsonObject, KEY_WANT.c_str(), missionInfo.want.ToUri().c_str()); + cJSON_AddBoolToObject(jsonObject, KEY_HAS_RECONER_INFO.c_str(), hasRecoverInfo); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + return jsonStr; } bool InnerMissionInfo::FromJsonStr(const std::string &jsonStr) { - // Do not throw exceptions in nlohmann::json::parse if (jsonStr.empty()) { return false; } - nlohmann::json value = nlohmann::json::parse(jsonStr, nullptr, false); - if (value.is_discarded()) { + + cJSON *value = cJSON_Parse(jsonStr.c_str()); + if (value == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "json failed: %{private}s", jsonStr.c_str()); return false; } - if (!CheckJsonNode(value, KEY_MISSION_NAME, JsonType::STRING)) { + cJSON *missionNameItem = cJSON_GetObjectItem(value, KEY_MISSION_NAME.c_str()); + if (missionNameItem == nullptr || !cJSON_IsString(missionNameItem)) { + cJSON_Delete(value); return false; } - missionName = value[KEY_MISSION_NAME].get(); + missionName = missionNameItem->valuestring; - if (!CheckJsonNode(value, KEY_LAUNCH_MODE, JsonType::NUMBER)) { + cJSON *launchModeItem = cJSON_GetObjectItem(value, KEY_LAUNCH_MODE.c_str()); + if (launchModeItem == nullptr || !cJSON_IsNumber(launchModeItem)) { + cJSON_Delete(value); return false; } - launchMode = value[KEY_LAUNCH_MODE].get(); - if (!CheckJsonNode(value, KEY_IS_TEMPORARY, JsonType::BOOLEAN)) { + launchMode = static_cast(launchModeItem->valuedouble); + + cJSON *isTemporaryItem = cJSON_GetObjectItem(value, KEY_IS_TEMPORARY.c_str()); + if (isTemporaryItem == nullptr || !cJSON_IsBool(isTemporaryItem)) { + cJSON_Delete(value); return false; } - isTemporary = value[KEY_IS_TEMPORARY].get(); - if (!CheckJsonNode(value, KEY_START_METHOD, JsonType::NUMBER)) { + isTemporary = isTemporaryItem->type == cJSON_True ? true : false; + + cJSON *startMethodItem = cJSON_GetObjectItem(value, KEY_START_METHOD.c_str()); + if (startMethodItem == nullptr || !cJSON_IsNumber(startMethodItem)) { + cJSON_Delete(value); return false; } - startMethod = value[KEY_START_METHOD].get(); - if (!CheckJsonNode(value, KEY_BUNDLE_NAME, JsonType::STRING)) { + startMethod = static_cast(startMethodItem->valuedouble); + + cJSON *bundleNameItem = cJSON_GetObjectItem(value, KEY_BUNDLE_NAME.c_str()); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { + cJSON_Delete(value); return false; } - bundleName = value[KEY_BUNDLE_NAME].get(); - if (!CheckJsonNode(value, KEY_UID, JsonType::NUMBER)) { + bundleName = bundleNameItem->valuestring; + + cJSON *uidItem = cJSON_GetObjectItem(value, KEY_UID.c_str()); + if (uidItem == nullptr || !cJSON_IsNumber(uidItem)) { + cJSON_Delete(value); return false; } - uid = value[KEY_UID].get(); - if (!CheckJsonNode(value, KEY_SPEC_FLAG, JsonType::STRING)) { + uid = static_cast(uidItem->valuedouble); + + cJSON *specifiedFlagItem = cJSON_GetObjectItem(value, KEY_SPEC_FLAG.c_str()); + if (specifiedFlagItem == nullptr || !cJSON_IsString(specifiedFlagItem)) { + cJSON_Delete(value); return false; } - specifiedFlag = value[KEY_SPEC_FLAG].get(); - if (!CheckJsonNode(value, KEY_MISSION_ID, JsonType::NUMBER)) { + specifiedFlag = specifiedFlagItem->valuestring; + + cJSON *missionIdItem = cJSON_GetObjectItem(value, KEY_MISSION_ID.c_str()); + if (missionIdItem == nullptr || !cJSON_IsNumber(missionIdItem)) { + cJSON_Delete(value); return false; } - missionInfo.id = value[KEY_MISSION_ID].get(); - if (!CheckJsonNode(value, KEY_RUNNING_STATE, JsonType::NUMBER)) { + missionInfo.id = static_cast(missionIdItem->valuedouble); + + cJSON *runningStateItem = cJSON_GetObjectItem(value, KEY_RUNNING_STATE.c_str()); + if (runningStateItem == nullptr || !cJSON_IsNumber(runningStateItem)) { + cJSON_Delete(value); return false; } - missionInfo.runningState = value[KEY_RUNNING_STATE].get(); - if (!CheckJsonNode(value, KEY_LOCKED_STATE, JsonType::BOOLEAN)) { + missionInfo.runningState = static_cast(runningStateItem->valuedouble); + + cJSON *lockedStateItem = cJSON_GetObjectItem(value, KEY_LOCKED_STATE.c_str()); + if (lockedStateItem == nullptr || !cJSON_IsBool(lockedStateItem)) { + cJSON_Delete(value); return false; } - missionInfo.lockedState = value[KEY_LOCKED_STATE].get(); - if (!CheckJsonNode(value, KEY_CONTINUABLE, JsonType::BOOLEAN)) { + missionInfo.lockedState = lockedStateItem->type == cJSON_True ? true : false; + + cJSON *continuableItem = cJSON_GetObjectItem(value, KEY_CONTINUABLE.c_str()); + if (continuableItem == nullptr || !cJSON_IsBool(continuableItem)) { + cJSON_Delete(value); return false; } - missionInfo.continuable = value[KEY_CONTINUABLE].get(); - if (!CheckJsonNode(value, KEY_TIME, JsonType::STRING)) { + missionInfo.continuable = continuableItem->type == cJSON_True ? true : false; + + cJSON *timeItem = cJSON_GetObjectItem(value, KEY_TIME.c_str()); + if (timeItem == nullptr || !cJSON_IsString(timeItem)) { + cJSON_Delete(value); return false; } - missionInfo.time = value[KEY_TIME].get(); - if (!CheckJsonNode(value, KEY_LABEL, JsonType::STRING)) { + missionInfo.time = timeItem->valuestring; + + cJSON *labelItem = cJSON_GetObjectItem(value, KEY_LABEL.c_str()); + if (labelItem == nullptr || !cJSON_IsString(labelItem)) { + cJSON_Delete(value); return false; } - missionInfo.label = value[KEY_LABEL].get(); - if (!CheckJsonNode(value, KEY_ICON_PATH, JsonType::STRING)) { + missionInfo.label = labelItem->valuestring; + + cJSON *iconPathItem = cJSON_GetObjectItem(value, KEY_ICON_PATH.c_str()); + if (iconPathItem == nullptr || !cJSON_IsString(iconPathItem)) { + cJSON_Delete(value); return false; } - missionInfo.iconPath = value[KEY_ICON_PATH].get(); - if (!CheckJsonNode(value, KEY_WANT, JsonType::STRING)) { + missionInfo.iconPath = iconPathItem->valuestring; + + cJSON *hasRecoverInfoItem = cJSON_GetObjectItem(value, KEY_HAS_RECONER_INFO.c_str()); + if (hasRecoverInfoItem == nullptr || !cJSON_IsBool(hasRecoverInfoItem)) { + cJSON_Delete(value); return false; } - if (!CheckJsonNode(value, KEY_HAS_RECONER_INFO, JsonType::BOOLEAN)) { + hasRecoverInfo = hasRecoverInfoItem->type == cJSON_True ? true : false; + + cJSON *wantItem = cJSON_GetObjectItem(value, KEY_WANT.c_str()); + if (wantItem == nullptr || !cJSON_IsString(wantItem)) { + cJSON_Delete(value); return false; } - hasRecoverInfo = value[KEY_HAS_RECONER_INFO].get(); - Want* want = Want::ParseUri(value[KEY_WANT].get()); + std::string wantStr = wantItem->valuestring; + + Want* want = Want::ParseUri(wantStr); if (want) { missionInfo.want = *want; } + + cJSON_Delete(value); return true; } @@ -165,21 +222,22 @@ void InnerMissionInfo::Dump(std::vector &info) const info.push_back(dumpInfo); } -bool InnerMissionInfo::CheckJsonNode(nlohmann::json &value, const std::string &node, JsonType jsonType) +bool InnerMissionInfo::CheckJsonNode(cJSON *value, const std::string &node, JsonType jsonType) { - if (value.find(node) == value.end()) { + cJSON *item = cJSON_GetObjectItem(value, node.c_str()); + if (item == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "node %{private}s null", node.c_str()); return false; } if (jsonType == JsonType::NUMBER) { - return value[node].is_number(); + return cJSON_IsNumber(item); } if (jsonType == JsonType::STRING) { - return value[node].is_string(); + return cJSON_IsString(item); } if (jsonType == JsonType::BOOLEAN) { - return value[node].is_boolean(); + return cJSON_IsBool(item); } return false; } diff --git a/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp b/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp index 4fcfb556e77e52ac00c5ad00aece26bbfb3bcfac..690951b7390ad37274bedc968c952a515289cc4f 100644 --- a/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp +++ b/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp @@ -16,13 +16,11 @@ #include "extract_insight_intent_profile.h" #include "hilog_tag_wrapper.h" -#include "json_util.h" +#include "insight_intent_json_util.h" +#include "json_utils.h" namespace OHOS { namespace AbilityRuntime { -using JsonType = AppExecFwk::JsonType; -using ArrayType = AppExecFwk::ArrayType; - namespace { int32_t g_extraParseResult = ERR_OK; std::mutex g_extraMutex; @@ -89,205 +87,78 @@ const std::map executeModeMap = { }; } // namespace -void from_json(const nlohmann::json &jsonObject, LinkIntentParamProfileMapping ¶mMapping) +void from_json(const cJSON *jsonObject, LinkIntentParamProfileMapping ¶mMapping) { TAG_LOGD(AAFwkTag::INTENT, "LinkIntentParamProfileMapping from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PARAM_NAME, - paramMapping.paramName, - true, - g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PARAM_MAPPING_NAME, - paramMapping.paramMappingName, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PARAM_NAME, paramMapping.paramName, true, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PARAM_MAPPING_NAME, paramMapping.paramMappingName, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PARAM_CATEGORY, - paramMapping.paramCategory, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PARAM_CATEGORY, paramMapping.paramCategory, false, g_extraParseResult); } -void from_json(const nlohmann::json &jsonObject, ExtractInsightIntentProfileInfo &insightIntentInfo) +void from_json(const cJSON *jsonObject, ExtractInsightIntentProfileInfo &insightIntentInfo) { TAG_LOGD(AAFwkTag::INTENT, "ExtractInsightIntentProfileInfo from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DECORETOR_FILE, - insightIntentInfo.decoratorFile, - true, - g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DECORETOR_CLASS, - insightIntentInfo.decoratorClass, - true, - g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DECORETOR_TYPE, - insightIntentInfo.decoratorType, - true, - g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_BUNDLE_NAME, - insightIntentInfo.bundleName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DECORETOR_FILE, insightIntentInfo.decoratorFile, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_MODULE_NAME, - insightIntentInfo.moduleName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DECORETOR_CLASS, insightIntentInfo.decoratorClass, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAME, - insightIntentInfo.intentName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DECORETOR_TYPE, insightIntentInfo.decoratorType, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DOMAIN, - insightIntentInfo.domain, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_BUNDLE_NAME, insightIntentInfo.bundleName, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_VERSION, - insightIntentInfo.intentVersion, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_MODULE_NAME, insightIntentInfo.moduleName, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DISPLAY_NAME, - insightIntentInfo.displayName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAME, insightIntentInfo.intentName, true, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DOMAIN, insightIntentInfo.domain, true, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_VERSION, insightIntentInfo.intentVersion, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DISPLAY_DESCRIPTION, - insightIntentInfo.displayDescription, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DISPLAY_NAME, insightIntentInfo.displayName, true, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_SCHEMA, - insightIntentInfo.schema, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DISPLAY_DESCRIPTION, insightIntentInfo.displayDescription, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ICON, - insightIntentInfo.icon, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_SCHEMA, insightIntentInfo.schema, false, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ICON, insightIntentInfo.icon, false, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_LLM_DESCRIPTION, insightIntentInfo.llmDescription, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_LLM_DESCRIPTION, - insightIntentInfo.llmDescription, - false, + GetStringValuesIfFindKey(jsonObject, INSIGHT_INTENT_KEYWORDS, insightIntentInfo.keywords, false, g_extraParseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_KEYWORDS, - insightIntentInfo.keywords, - JsonType::ARRAY, - false, - g_extraParseResult, - ArrayType::STRING); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_EXAMPLE, - insightIntentInfo.example, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_EXAMPLE, insightIntentInfo.example, false, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_URI, insightIntentInfo.uri, false, g_extraParseResult); + GetObjectValuesIfFindKey(jsonObject, INSIGHT_INTENT_PARAM_MAPPING, insightIntentInfo.paramMapping, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_URI, - insightIntentInfo.uri, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_UI_ABILITY, insightIntentInfo.uiAbility, false, g_extraParseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PARAM_MAPPING, - insightIntentInfo.paramMapping, - JsonType::ARRAY, - false, - g_extraParseResult, - ArrayType::OBJECT); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_UI_ABILITY, - insightIntentInfo.uiAbility, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PAGE_ROUTE_NAME, insightIntentInfo.pagePath, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PAGE_ROUTE_NAME, - insightIntentInfo.pagePath, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAVIGATION_ID, insightIntentInfo.navigationId, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAVIGATION_ID, - insightIntentInfo.navigationId, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAV_DESTINATION_NAME, insightIntentInfo.navDestinationName, + false, g_extraParseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY_NAME, insightIntentInfo.abilityName, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAV_DESTINATION_NAME, - insightIntentInfo.navDestinationName, - false, + GetStringValuesIfFindKey(jsonObject, INSIGHT_INTENT_EXECUTE_MODE, insightIntentInfo.executeMode, false, g_extraParseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY_NAME, - insightIntentInfo.abilityName, - false, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_FUNCTION_NAME, insightIntentInfo.functionName, false, g_extraParseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_EXECUTE_MODE, - insightIntentInfo.executeMode, - JsonType::ARRAY, - false, - g_extraParseResult, - ArrayType::STRING); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_FUNCTION_NAME, - insightIntentInfo.functionName, - false, + GetStringValuesIfFindKey(jsonObject, INSIGHT_INTENT_FUNCTION_PARAMS, insightIntentInfo.functionParams, false, g_extraParseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_FUNCTION_PARAMS, - insightIntentInfo.functionParams, - JsonType::ARRAY, - false, - g_extraParseResult, - ArrayType::STRING); - - if (jsonObject.find(INSIGHT_INTENT_PARAMETERS) != jsonObjectEnd) { - if (jsonObject.at(INSIGHT_INTENT_PARAMETERS).is_object()) { - insightIntentInfo.parameters = jsonObject[INSIGHT_INTENT_PARAMETERS].dump(); + + cJSON *insightIntentParametersItem = cJSON_GetObjectItem(jsonObject, INSIGHT_INTENT_PARAMETERS.c_str()); + if (insightIntentParametersItem != nullptr) { + if (cJSON_IsObject(insightIntentParametersItem)) { + insightIntentInfo.parameters = AAFwk::JsonUtils::GetInstance().ToString(insightIntentParametersItem); } else { TAG_LOGE(AAFwkTag::INTENT, "type error: parameters not object"); g_extraParseResult = ERR_INVALID_VALUE; } } - if (jsonObject.find(INSIGHT_INTENT_RESULT) != jsonObjectEnd) { - if (jsonObject.at(INSIGHT_INTENT_RESULT).is_object()) { - insightIntentInfo.result = jsonObject[INSIGHT_INTENT_RESULT].dump(); + cJSON *insightIntentResultItem = cJSON_GetObjectItem(jsonObject, INSIGHT_INTENT_RESULT.c_str()); + if (insightIntentResultItem != nullptr) { + if (cJSON_IsObject(insightIntentResultItem)) { + insightIntentInfo.result = AAFwk::JsonUtils::GetInstance().ToString(insightIntentResultItem); } else { TAG_LOGE(AAFwkTag::INTENT, "type error: result not object"); g_extraParseResult = ERR_INVALID_VALUE; @@ -295,80 +166,111 @@ void from_json(const nlohmann::json &jsonObject, ExtractInsightIntentProfileInfo } } -void from_json(const nlohmann::json &jsonObject, ExtractInsightIntentProfileInfoVec &infos) +void from_json(const cJSON *jsonObject, ExtractInsightIntentProfileInfoVec &infos) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENTS, - infos.insightIntents, - JsonType::ARRAY, - false, - g_extraParseResult, - ArrayType::OBJECT); + GetObjectValuesIfFindKey(jsonObject, INSIGHT_INTENTS, infos.insightIntents, false, g_extraParseResult); } -void to_json(nlohmann::json& jsonObject, const LinkIntentParamProfileMapping &info) +bool to_json(cJSON *jsonObject, const LinkIntentParamProfileMapping &info) { TAG_LOGI(AAFwkTag::INTENT, "call to link mapping"); - jsonObject = nlohmann::json { - {"paramName", info.paramName}, - {"paramMappingName", info.paramMappingName}, - {"paramCategory", info.paramCategory} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGI(AAFwkTag::INTENT, "create jsonObject failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, "paramName", info.paramName.c_str()); + cJSON_AddStringToObject(jsonObject, "paramMappingName", info.paramMappingName.c_str()); + cJSON_AddStringToObject(jsonObject, "paramCategory", info.paramCategory.c_str()); + return true; } -void to_json(nlohmann::json& jsonObject, const ExtractInsightIntentProfileInfo& info) +bool to_json(cJSON *jsonObject, const ExtractInsightIntentProfileInfo& info) { TAG_LOGI(AAFwkTag::INTENT, "call to ExtractInsightIntentProfileInfo"); + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGI(AAFwkTag::INTENT, "create jsonObject failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DECORETOR_FILE.c_str(), info.decoratorFile.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DECORETOR_CLASS.c_str(), info.decoratorClass.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DECORETOR_TYPE.c_str(), info.decoratorType.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_BUNDLE_NAME.c_str(), info.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_MODULE_NAME.c_str(), info.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_NAME.c_str(), info.intentName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DOMAIN.c_str(), info.domain.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_VERSION.c_str(), info.intentVersion.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DISPLAY_NAME.c_str(), info.displayName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DISPLAY_DESCRIPTION.c_str(), info.displayDescription.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_SCHEMA.c_str(), info.schema.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_ICON.c_str(), info.icon.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_LLM_DESCRIPTION.c_str(), info.llmDescription.c_str()); + + cJSON *keywordsItem = nullptr; + if (!to_json(keywordsItem, info.keywords)) { + TAG_LOGI(AAFwkTag::INTENT, "to_json keywords failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_KEYWORDS.c_str(), keywordsItem); - jsonObject = nlohmann::json { - {INSIGHT_INTENT_DECORETOR_FILE, info.decoratorFile}, - {INSIGHT_INTENT_DECORETOR_CLASS, info.decoratorClass}, - {INSIGHT_INTENT_DECORETOR_TYPE, info.decoratorType}, - {INSIGHT_INTENT_BUNDLE_NAME, info.bundleName}, - {INSIGHT_INTENT_MODULE_NAME, info.moduleName}, - {INSIGHT_INTENT_NAME, info.intentName}, - {INSIGHT_INTENT_DOMAIN, info.domain}, - {INSIGHT_INTENT_VERSION, info.intentVersion}, - {INSIGHT_INTENT_DISPLAY_NAME, info.displayName}, - {INSIGHT_INTENT_DISPLAY_DESCRIPTION, info.displayDescription}, - {INSIGHT_INTENT_SCHEMA, info.schema}, - {INSIGHT_INTENT_ICON, info.icon}, - {INSIGHT_INTENT_LLM_DESCRIPTION, info.llmDescription}, - {INSIGHT_INTENT_KEYWORDS, info.keywords}, - {INSIGHT_INTENT_EXAMPLE, info.example}, - {INSIGHT_INTENT_URI, info.uri}, - {INSIGHT_INTENT_PARAM_MAPPING, info.paramMapping}, - {INSIGHT_INTENT_UI_ABILITY, info.uiAbility}, - {INSIGHT_INTENT_PAGE_ROUTE_NAME, info.pagePath}, - {INSIGHT_INTENT_NAVIGATION_ID, info.navigationId}, - {INSIGHT_INTENT_NAV_DESTINATION_NAME, info.navDestinationName}, - {INSIGHT_INTENT_ABILITY_NAME, info.abilityName}, - {INSIGHT_INTENT_EXECUTE_MODE, info.executeMode}, - {INSIGHT_INTENT_FUNCTION_NAME, info.functionName}, - {INSIGHT_INTENT_FUNCTION_PARAMS, info.functionParams} - }; + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_EXAMPLE.c_str(), info.example.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_URI.c_str(), info.uri.c_str()); + + cJSON *paramMappingItem = nullptr; + if (!to_json(paramMappingItem, info.paramMapping)) { + TAG_LOGI(AAFwkTag::INTENT, "to_json paramMapping failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_PARAM_MAPPING.c_str(), paramMappingItem); + + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_UI_ABILITY.c_str(), info.uiAbility.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_PAGE_ROUTE_NAME.c_str(), info.pagePath.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_NAVIGATION_ID.c_str(), info.navigationId.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_NAV_DESTINATION_NAME.c_str(), info.navDestinationName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_ABILITY_NAME.c_str(), info.abilityName.c_str()); + + cJSON *executeModeItem = nullptr; + if (!to_json(executeModeItem, info.executeMode)) { + TAG_LOGI(AAFwkTag::INTENT, "to_json executeMode failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_EXECUTE_MODE.c_str(), executeModeItem); + + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_FUNCTION_NAME.c_str(), info.functionName.c_str()); + + cJSON *functionParamsItem = nullptr; + if (!to_json(functionParamsItem, info.functionParams)) { + TAG_LOGI(AAFwkTag::INTENT, "to_json functionParams failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_FUNCTION_PARAMS.c_str(), functionParamsItem); if (!info.parameters.empty()) { - auto parameters = nlohmann::json::parse(info.parameters, nullptr, false); - if (parameters.is_discarded()) { - TAG_LOGE(AAFwkTag::INTENT, "discarded parameters"); - return; + cJSON *parametersItem = cJSON_Parse(info.parameters.c_str()); + if (parametersItem == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "parameters error"); + cJSON_Delete(jsonObject); + return false; } - - jsonObject[INSIGHT_INTENT_PARAMETERS] = parameters; + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_PARAMETERS.c_str(), parametersItem); } if (!info.result.empty()) { - auto result = nlohmann::json::parse(info.result, nullptr, false); - if (result.is_discarded()) { - TAG_LOGE(AAFwkTag::INTENT, "discarded result"); - return; + cJSON *resultItem = cJSON_Parse(info.result.c_str()); + if (resultItem == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "result error"); + cJSON_Delete(jsonObject); + return false; } - - jsonObject[INSIGHT_INTENT_RESULT] = result; + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_RESULT.c_str(), resultItem); } + + return true; } bool CheckProfileSubIntentInfo(const ExtractInsightIntentProfileInfo &insightIntent) @@ -522,15 +424,16 @@ bool ExtractInsightIntentProfile::TransformTo(const std::string &profileStr, ExtractInsightIntentProfileInfoVec &intentInfos) { TAG_LOGD(AAFwkTag::INTENT, "transform profileStr: %{public}s", profileStr.c_str()); - auto jsonObject = nlohmann::json::parse(profileStr, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(profileStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::INTENT, "discarded jsonObject"); return false; } std::lock_guard lock(g_extraMutex); g_extraParseResult = ERR_OK; - intentInfos = jsonObject.get(); + from_json(jsonObject, intentInfos); + cJSON_Delete(jsonObject); if (g_extraParseResult != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "parse result: %{public}d", g_extraParseResult); g_extraParseResult = ERR_OK; @@ -547,17 +450,32 @@ bool ExtractInsightIntentProfile::TransformTo(const std::string &profileStr, return true; } -bool ExtractInsightIntentProfile::ToJson(const ExtractInsightIntentProfileInfo &info, nlohmann::json &jsonObject) +bool ExtractInsightIntentProfile::ToJson(const ExtractInsightIntentProfileInfo &info, cJSON *jsonObject) { TAG_LOGD(AAFwkTag::INTENT, "to json"); - nlohmann::json subJsonObject = info; - if (subJsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::INTENT, "bad insight intent info"); + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGD(AAFwkTag::INTENT, "create json object failed"); + return false; + } + cJSON *subJsonObject = nullptr; + if (!to_json(subJsonObject, info)) { + TAG_LOGD(AAFwkTag::INTENT, "to_json extractInsightIntentProfileInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON *jsonArray = cJSON_CreateArray(); + if (jsonArray == nullptr) { + cJSON_Delete(subJsonObject); + cJSON_Delete(jsonObject); + jsonObject = nullptr; return false; } + cJSON_AddItemToArray(jsonArray, subJsonObject); + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENTS.c_str(), jsonArray); - jsonObject[INSIGHT_INTENTS] = nlohmann::json::array({ subJsonObject }); - TAG_LOGD(AAFwkTag::INTENT, "json string: %{public}s", jsonObject.dump().c_str()); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + TAG_LOGD(AAFwkTag::INTENT, "json string: %{public}s", jsonStr.c_str()); return true; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp b/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp index 9f5447a430f6acb8b06d4664a2c0ca41f857a6a8..cbe6f6ad869ff9dcd8b469d72bf2e34e856139ee 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp @@ -17,12 +17,11 @@ #include "string_wrapper.h" #include "hilog_tag_wrapper.h" -#include "json_util.h" +#include "insight_intent_json_util.h" +#include "json_utils.h" namespace OHOS { namespace AbilityRuntime { -using JsonType = AppExecFwk::JsonType; -using ArrayType = AppExecFwk::ArrayType; namespace { int32_t g_parseResult = ERR_OK; std::mutex g_extraMutex; @@ -41,91 +40,82 @@ const std::map STRING_EXECUTE_MODE_MAP = { }; } -void from_json(const nlohmann::json &jsonObject, LinkInfoForQuery &linkInfo) +void from_json(const cJSON *jsonObject, LinkInfoForQuery &linkInfo) { TAG_LOGD(AAFwkTag::INTENT, "LinkInfoForQuery from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENTS_URI, - linkInfo.uri, - true, - g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENTS_URI, linkInfo.uri, true, g_parseResult); } -void to_json(nlohmann::json& jsonObject, const LinkInfoForQuery &info) +bool to_json(cJSON * jsonObject, const LinkInfoForQuery &info) { TAG_LOGD(AAFwkTag::INTENT, "LinkInfoForQuery to json"); - jsonObject = nlohmann::json { - {INSIGHT_INTENTS_URI, info.uri} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENTS_URI, info.uri.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, PageInfoForQuery &pageInfo) +void from_json(const cJSON *jsonObject, PageInfoForQuery &pageInfo) { TAG_LOGD(AAFwkTag::INTENT, "PageInfoForQuery from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_UI_ABILITY, - pageInfo.uiAbility, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PAGE_PATH, - pageInfo.pagePath, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAVIGATION_ID, - pageInfo.navigationId, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAV_DESTINATION_NAME, - pageInfo.navDestinationName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_UI_ABILITY, pageInfo.uiAbility, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PAGE_PATH, pageInfo.pagePath, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAVIGATION_ID, pageInfo.navigationId, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAV_DESTINATION_NAME, pageInfo.navDestinationName, true, g_parseResult); } -void to_json(nlohmann::json& jsonObject, const PageInfoForQuery &info) +bool to_json(cJSON *jsonObject, const PageInfoForQuery &info) { TAG_LOGD(AAFwkTag::INTENT, "PageInfoForQuery to json"); - jsonObject = nlohmann::json { - {INSIGHT_INTENT_UI_ABILITY, info.uiAbility}, - {INSIGHT_INTENT_PAGE_PATH, info.pagePath}, - {INSIGHT_INTENT_NAVIGATION_ID, info.navigationId}, - {INSIGHT_INTENT_NAV_DESTINATION_NAME, info.navDestinationName} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_UI_ABILITY, info.uiAbility.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_PAGE_PATH, info.pagePath.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_NAVIGATION_ID, info.navigationId.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_NAV_DESTINATION_NAME, info.navDestinationName.c_str()); + return true; } -void from_json(const nlohmann::json &jsonObject, EntryInfoForQuery &entryInfo) +void GetExecuteModesFromJson(const cJSON *jsonObject, std::vector executeModes) { - TAG_LOGD(AAFwkTag::INTENT, "EntryInfoForQuery from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY_NAME, - entryInfo.abilityName, - true, - g_parseResult); - if (jsonObject.find(INSIGHT_INTENT_EXECUTE_MODE) != jsonObjectEnd) { - const auto &modeArray = jsonObject[INSIGHT_INTENT_EXECUTE_MODE]; - for (const auto &modeStr : modeArray) { - auto it = STRING_EXECUTE_MODE_MAP.find(modeStr.get()); + if (jsonObject == nullptr || !cJSON_IsArray(jsonObject)) { + return; + } + int size = cJSON_GetArraySize(jsonObject); + for (int i = 0; i < size; i++) { + cJSON *modeItem = cJSON_GetArrayItem(jsonObject, i); + if (modeItem != nullptr && cJSON_IsString(modeItem)) { + std::string modeStr = modeItem->valuestring; + auto it = STRING_EXECUTE_MODE_MAP.find(modeStr); if (it != STRING_EXECUTE_MODE_MAP.end()) { - entryInfo.executeMode.push_back(it->second); + executeModes.push_back(it->second); } else { - TAG_LOGW(AAFwkTag::INTENT, "Unknown ExecuteMode: %{public}s", modeStr.dump().c_str()); + TAG_LOGW(AAFwkTag::INTENT, "Unknown ExecuteMode: %{public}s", modeStr.c_str()); } + } else { + TAG_LOGW(AAFwkTag::INTENT, "ExecuteMode is null or not string type"); } } } -void to_json(nlohmann::json& jsonObject, const EntryInfoForQuery &info) +void from_json(const cJSON *jsonObject, EntryInfoForQuery &entryInfo) +{ + TAG_LOGD(AAFwkTag::INTENT, "EntryInfoForQuery from json"); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY_NAME, entryInfo.abilityName, true, g_parseResult); + cJSON *executeModeItem = cJSON_GetObjectItem(jsonObject, INSIGHT_INTENT_EXECUTE_MODE); + if (executeModeItem != nullptr && cJSON_IsArray(executeModeItem)) { + GetExecuteModesFromJson(executeModeItem, entryInfo.executeMode); + } +} + +bool to_json(cJSON *jsonObject, const EntryInfoForQuery &info) { TAG_LOGD(AAFwkTag::INTENT, "EntryInfoForQuery to json"); std::vector modeStrings; @@ -137,155 +127,109 @@ void to_json(nlohmann::json& jsonObject, const EntryInfoForQuery &info) modeStrings.push_back("UNKNOWN"); } } - jsonObject = nlohmann::json { - {INSIGHT_INTENT_ABILITY_NAME, info.abilityName}, - {INSIGHT_INTENT_EXECUTE_MODE, modeStrings} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_ABILITY_NAME, info.abilityName.c_str()); + cJSON *modeItem = nullptr; + if (!to_json(modeItem, modeStrings)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_EXECUTE_MODE, modeItem); + return true; } -void from_json(const nlohmann::json &jsonObject, InsightIntentInfoForQuery &insightIntentInfo) +void from_json(const cJSON *jsonObject, InsightIntentInfoForQuery &insightIntentInfo) { TAG_LOGD(AAFwkTag::INTENT, "InsightIntentInfoForQuery from json"); - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_BUNDLE_NAME, - insightIntentInfo.bundleName, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_MODULE_NAME, - insightIntentInfo.moduleName, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_INTENT_NAME, - insightIntentInfo.intentName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_BUNDLE_NAME, insightIntentInfo.bundleName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_MODULE_NAME, insightIntentInfo.moduleName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_INTENT_NAME, insightIntentInfo.intentName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DOMAIN, insightIntentInfo.domain, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_INTENT_VERSION, insightIntentInfo.intentVersion, true, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DOMAIN, - insightIntentInfo.domain, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DISPLAY_NAME, insightIntentInfo.displayName, true, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_INTENT_VERSION, - insightIntentInfo.intentVersion, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DISPLAY_DESCRIPTION, insightIntentInfo.displayDescription, false, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DISPLAY_NAME, - insightIntentInfo.displayName, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_SCHEMA, insightIntentInfo.schema, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ICON, insightIntentInfo.icon, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_LLM_DESCRIPTION, insightIntentInfo.llmDescription, false, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DISPLAY_DESCRIPTION, - insightIntentInfo.displayDescription, - false, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_SCHEMA, - insightIntentInfo.schema, - false, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ICON, - insightIntentInfo.icon, - false, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_LLM_DESCRIPTION, - insightIntentInfo.llmDescription, - false, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_INTENT_TYPE, - insightIntentInfo.intentType, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PARAMETERS, - insightIntentInfo.parameters, - false, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_RESULT, - insightIntentInfo.result, - false, - g_parseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_KEYWORDS, - insightIntentInfo.keywords, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::STRING); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_INTENT_TYPE, insightIntentInfo.intentType, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_PARAMETERS, insightIntentInfo.parameters, false, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_RESULT, insightIntentInfo.result, false, g_parseResult); + GetStringValuesIfFindKey(jsonObject, INSIGHT_INTENT_KEYWORDS, insightIntentInfo.keywords, false, g_parseResult); if (insightIntentInfo.intentType == INSIGHT_INTENTS_TYPE_LINK) { - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_LINK_INFO, - insightIntentInfo.linkInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_LINK_INFO, insightIntentInfo.linkInfo, false, g_parseResult); } else if (insightIntentInfo.intentType == INSIGHT_INTENTS_TYPE_PAGE) { - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_PAGE_INFO, - insightIntentInfo.pageInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_PAGE_INFO, insightIntentInfo.pageInfo, false, g_parseResult); } else if (insightIntentInfo.intentType == INSIGHT_INTENTS_TYPE_ENTRY) { - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ENTRY_INFO, - insightIntentInfo.entryInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_ENTRY_INFO, insightIntentInfo.entryInfo, false, + g_parseResult); } } -void to_json(nlohmann::json& jsonObject, const InsightIntentInfoForQuery &info) +bool to_json(cJSON *jsonObject, const InsightIntentInfoForQuery &info) { TAG_LOGD(AAFwkTag::INTENT, "InsightIntentInfoForQuery to json"); - jsonObject = nlohmann::json { - {INSIGHT_INTENT_BUNDLE_NAME, info.bundleName}, - {INSIGHT_INTENT_MODULE_NAME, info.moduleName}, - {INSIGHT_INTENT_INTENT_NAME, info.intentName}, - {INSIGHT_INTENT_DOMAIN, info.domain}, - {INSIGHT_INTENT_INTENT_VERSION, info.intentVersion}, - {INSIGHT_INTENT_DISPLAY_NAME, info.displayName}, - {INSIGHT_INTENT_DISPLAY_DESCRIPTION, info.displayDescription}, - {INSIGHT_INTENT_SCHEMA, info.schema}, - {INSIGHT_INTENT_ICON, info.icon}, - {INSIGHT_INTENT_LLM_DESCRIPTION, info.llmDescription}, - {INSIGHT_INTENT_INTENT_TYPE, info.intentType}, - {INSIGHT_INTENT_PARAMETERS, info.parameters}, - {INSIGHT_INTENT_RESULT, info.result}, - {INSIGHT_INTENT_KEYWORDS, info.keywords}, - {INSIGHT_INTENT_LINK_INFO, info.linkInfo}, - {INSIGHT_INTENT_PAGE_INFO, info.pageInfo}, - {INSIGHT_INTENT_ENTRY_INFO, info.entryInfo} - }; + jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json object failed"); + return false; + } + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_BUNDLE_NAME, info.bundleName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_MODULE_NAME, info.moduleName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_INTENT_NAME, info.intentName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DOMAIN, info.domain.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_INTENT_VERSION, info.intentVersion.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DISPLAY_NAME, info.displayName.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_DISPLAY_DESCRIPTION, info.displayDescription.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_SCHEMA, info.schema.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_ICON, info.icon.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_LLM_DESCRIPTION, info.llmDescription.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_INTENT_TYPE, info.intentType.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_PARAMETERS, info.parameters.c_str()); + cJSON_AddStringToObject(jsonObject, INSIGHT_INTENT_RESULT, info.result.c_str()); + + cJSON *keywordsItem = nullptr; + if (!to_json(keywordsItem, info.keywords)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json keywords failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_KEYWORDS, keywordsItem); + + cJSON *linkInfoItem = nullptr; + if (!to_json(linkInfoItem, info.linkInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json linkInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_LINK_INFO, linkInfoItem); + + cJSON *pageInfoItem = nullptr; + if (!to_json(pageInfoItem, info.pageInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json pageInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_LINK_INFO, pageInfoItem); + + cJSON *entryInfoItem = nullptr; + if (!to_json(entryInfoItem, info.entryInfo)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "to_json entryInfo failed"); + cJSON_Delete(jsonObject); + return false; + } + cJSON_AddItemToObject(jsonObject, INSIGHT_INTENT_LINK_INFO, entryInfoItem); + + return true; } bool InsightIntentInfoForQuery::ReadFromParcel(Parcel &parcel) @@ -306,14 +250,15 @@ bool InsightIntentInfoForQuery::ReadFromParcel(Parcel &parcel) TAG_LOGE(AAFwkTag::INTENT, "Fail read raw length = %{public}d", length); return false; } - nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(data); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::INTENT, "failed to parse BundleInfo"); return false; } std::lock_guard lock(g_extraMutex); g_parseResult = ERR_OK; - *this = jsonObject.get(); + from_json(jsonObject, *this); + cJSON_Delete(jsonObject); if (g_parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "parse result: %{public}d", g_parseResult); g_parseResult = ERR_OK; @@ -329,8 +274,13 @@ bool InsightIntentInfoForQuery::Marshalling(Parcel &parcel) const TAG_LOGE(AAFwkTag::INTENT, "Conversion failed"); return false; } - nlohmann::json jsonObject = *this; - std::string str = jsonObject.dump(); + cJSON *jsonObject = nullptr; + if (!to_json(jsonObject, *this)) { + TAG_LOGE(AAFwkTag::INTENT, "to_json insightIntentInfoForQuery failed"); + return false; + } + std::string str = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); TAG_LOGD(AAFwkTag::INTENT, "Marshalling str: %{public}s", str.c_str()); if (!messageParcel->WriteUint32(str.size() + 1)) { TAG_LOGE(AAFwkTag::INTENT, "Write intent info size failed"); diff --git a/services/abilitymgr/src/insight_intent/insight_intent_json_util.cpp b/services/abilitymgr/src/insight_intent/insight_intent_json_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9236704ff9f8e92ec3f9cbc82513f748609b2e1 --- /dev/null +++ b/services/abilitymgr/src/insight_intent/insight_intent_json_util.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2023-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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "insight_intent_json_util.h" + +namespace OHOS { +namespace AbilityRuntime { + +bool to_json(cJSON *jsonObject, const std::string &value) +{ + jsonObject = cJSON_CreateString(value.c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create string json failed"); + return false; + } + return true; +} + +bool to_json(cJSON *jsonObject, const int &value) +{ + jsonObject = cJSON_CreateNumber(static_cast(value)); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create number json failed"); + return false; + } + return true; +} + +bool to_json(cJSON *jsonObject, const bool &value) +{ + jsonObject = cJSON_CreateBool(value); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create bool json failed"); + return false; + } + return true; +} + +void from_json(const cJSON *jsonObject, std::string &value) +{ + if (jsonObject == nullptr || !cJSON_IsString(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not string"); + return; + } + value = jsonObject->valuestring; +} + +void from_json(const cJSON *jsonObject, int &value) +{ + if (jsonObject == nullptr || !cJSON_IsNumber(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not string"); + return; + } + value = static_cast(jsonObject->valuedouble); +} + +void from_json(const cJSON *jsonObject, bool &value) +{ + if (jsonObject == nullptr || !cJSON_IsBool(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type not bool"); + return; + } + value = jsonObject->type == cJSON_True ? true : false; +} + +void GetStringValueIfFindKey(const cJSON *jsonObject, + const std::string &key, std::string &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsString(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not string", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + data = item->valuestring; +} + +void GetStringValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsString(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not string list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string value = childItem->valuestring; + data.push_back(value); + } +} + +void GetBoolValueIfFindKey(const cJSON *jsonObject, + const std::string &key, bool &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsBool(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + data = item->type == cJSON_True ? true : false; +} + +void GetBoolValuesIfFindKey(const cJSON *jsonObject, + const std::string &key, std::vector &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + bool value = childItem->type == cJSON_True ? true : false; + data.push_back(value); + } +} + +void GetBoolValueMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + bool value = childItem->type == cJSON_True ? true : false; + data.emplace(key, value); + } +} + +void GetBoolValuesMapIfFindKey(const cJSON *jsonObject, + const std::string &key, std::map> &data, + bool isNecessary, int32_t &parseResult) +{ + if (parseResult) { + return; + } + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item == nullptr) { + if (isNecessary) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } + return; + } + if (!cJSON_IsArray(item)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + int size = cJSON_GetArraySize(item); + for (int i = 0; i < size; i++) { + cJSON* childItem = cJSON_GetArrayItem(item, i); + if (childItem == nullptr || !cJSON_IsBool(childItem)) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "type:%{public}s not bool list", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + return; + } + std::string key = childItem->string == nullptr ? "" : childItem->string; + std::vector value; + from_json(childItem, value); + data.emplace(key, value); + } +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/insight_intent/insight_intent_profile.cpp b/services/abilitymgr/src/insight_intent/insight_intent_profile.cpp index 624a6c9460094820e9dd7f0084f59eb8bff86666..18edb5d3f6d476af747d4976fccd2167fe194497 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_profile.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_profile.cpp @@ -16,13 +16,10 @@ #include "insight_intent_profile.h" #include "hilog_tag_wrapper.h" -#include "json_util.h" +#include "insight_intent_json_util.h" namespace OHOS { namespace AbilityRuntime { -using JsonType = AppExecFwk::JsonType; -using ArrayType = AppExecFwk::ArrayType; - namespace { int32_t g_parseResult = ERR_OK; std::mutex g_mutex; @@ -78,136 +75,46 @@ struct InsightIntentProfileInfoVec { std::vector insightIntents {}; }; -void from_json(const nlohmann::json &jsonObject, UIAbilityProfileInfo &info) +void from_json(const cJSON *jsonObject, UIAbilityProfileInfo &info) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY, - info.abilityName, - true, - g_parseResult); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_EXECUTE_MODE, - info.supportExecuteMode, - JsonType::ARRAY, - true, - g_parseResult, - ArrayType::STRING); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY, info.abilityName, true, g_parseResult); + GetStringValuesIfFindKey(jsonObject, INSIGHT_INTENT_EXECUTE_MODE, info.supportExecuteMode, true, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, UIExtensionProfileInfo &info) +void from_json(const cJSON *jsonObject, UIExtensionProfileInfo &info) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY, - info.abilityName, - true, - g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY, info.abilityName, true, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, ServiceExtensionProfileInfo &info) +void from_json(const cJSON *jsonObject, ServiceExtensionProfileInfo &info) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY, - info.abilityName, - true, - g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY, info.abilityName, true, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, FormProfileInfo &info) +void from_json(const cJSON *jsonObject, FormProfileInfo &info) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_ABILITY, - info.abilityName, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_FORM_NAME, - info.formName, - true, - g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_ABILITY, info.abilityName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_FORM_NAME, info.formName, true, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, InsightIntentProfileInfo &insightIntentInfo) +void from_json(const cJSON *jsonObject, InsightIntentProfileInfo &insightIntentInfo) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_NAME, - insightIntentInfo.intentName, - true, - g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_DOMAIN, - insightIntentInfo.intentDomain, - true, + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_NAME, insightIntentInfo.intentName, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_DOMAIN, insightIntentInfo.intentDomain, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_VERSION, insightIntentInfo.intentVersion, true, g_parseResult); + GetStringValueIfFindKey(jsonObject, INSIGHT_INTENT_SRC_ENTRY, insightIntentInfo.srcEntry, true, g_parseResult); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_UI_ABILITY, insightIntentInfo.uiAbilityProfileInfo, false, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_VERSION, - insightIntentInfo.intentVersion, - true, + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_UI_EXTENSION, insightIntentInfo.uiExtensionProfileInfo, false, g_parseResult); - AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_SRC_ENTRY, - insightIntentInfo.srcEntry, - true, - g_parseResult); - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_UI_ABILITY, - insightIntentInfo.uiAbilityProfileInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_UI_EXTENSION, - insightIntentInfo.uiExtensionProfileInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_SERVICE_EXTENSION, - insightIntentInfo.serviceExtensionProfileInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); - AppExecFwk::GetValueIfFindKey(jsonObject, - jsonObjectEnd, - INSIGHT_INTENT_FORM, - insightIntentInfo.formProfileInfo, - JsonType::OBJECT, - false, - g_parseResult, - ArrayType::NOT_ARRAY); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_SERVICE_EXTENSION, insightIntentInfo.serviceExtensionProfileInfo, + false, g_parseResult); + GetObjectValueIfFindKey(jsonObject, INSIGHT_INTENT_FORM, insightIntentInfo.formProfileInfo, false, g_parseResult); } -void from_json(const nlohmann::json &jsonObject, InsightIntentProfileInfoVec &infos) +void from_json(const cJSON *jsonObject, InsightIntentProfileInfoVec &infos) { - const auto &jsonObjectEnd = jsonObject.end(); - AppExecFwk::GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - INSIGHT_INTENTS, - infos.insightIntents, - JsonType::ARRAY, - false, - g_parseResult, - ArrayType::OBJECT); + GetObjectValuesIfFindKey(jsonObject, INSIGHT_INTENTS, infos.insightIntents, false, g_parseResult); } bool TransformToInsightIntentInfo(const InsightIntentProfileInfo &insightIntent, InsightIntentInfo &info) @@ -258,8 +165,8 @@ bool TransformToInfos(const InsightIntentProfileInfoVec &profileInfos, std::vect bool InsightIntentProfile::TransformTo(const std::string &profileStr, std::vector &intentInfos) { TAG_LOGD(AAFwkTag::INTENT, "called"); - auto jsonObject = nlohmann::json::parse(profileStr, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(profileStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::INTENT, "discarded jsonObject"); return false; } @@ -268,16 +175,17 @@ bool InsightIntentProfile::TransformTo(const std::string &profileStr, std::vecto { std::lock_guard lock(g_mutex); g_parseResult = ERR_OK; - profileInfos = jsonObject.get(); + from_json(jsonObject, profileInfos); if (g_parseResult != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "g_parseResult :%{public}d", g_parseResult); int32_t ret = g_parseResult; // need recover parse result to ERR_OK g_parseResult = ERR_OK; + cJSON_Delete(jsonObject); return ret; } } - + cJSON_Delete(jsonObject); return TransformToInfos(profileInfos, intentInfos); } } // namespace AbilityRuntime diff --git a/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp b/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp index ece07907c4cbcd9ef150541597be58ec170c3862..1a881e544d816ecee189a9f1611cf0da7d0dd0e7 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp @@ -14,7 +14,7 @@ */ #include "insight_intent_rdb_storage_mgr.h" -#include "nlohmann/json.hpp" +#include "json_utils.h" namespace OHOS { namespace AbilityRuntime { @@ -108,12 +108,14 @@ int32_t InsightRdbStorageMgr::SaveStorageInsightIntentData(const std::string &bu for (auto profileInfo : profileInfos.insightIntents) { std::string key = std::to_string(userId).append("/").append(bundleName).append("/") .append(moduleName).append("/").append(profileInfo.intentName); - nlohmann::json jsonObject; + cJSON *jsonObject = nullptr; if (!ExtractInsightIntentProfile::ToJson(profileInfo, jsonObject)) { TAG_LOGE(AAFwkTag::INTENT, "Transform error, key: %{private}s", key.c_str()); return ERR_INVALID_VALUE; } - bool result = DelayedSingleton::GetInstance()->InsertData(key, jsonObject.dump()); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + bool result = DelayedSingleton::GetInstance()->InsertData(key, jsonStr); if (!result) { TAG_LOGE(AAFwkTag::INTENT, "InsertData error, key: %{private}s", key.c_str()); } diff --git a/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp b/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp index 36e2bf028311b374ad9a2f49757aa876a370db94..b25010b60edd614ff5bfbe55a644dfb8c16d8376 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp @@ -17,6 +17,7 @@ #include +#include "cJSON.h" #include "hilog_tag_wrapper.h" #include "json_utils.h" @@ -300,10 +301,15 @@ int32_t AbilityKeepAliveDataManager::QueryKeepAliveApplications( DistributedKv::Value AbilityKeepAliveDataManager::ConvertKeepAliveStatusToValue(KeepAliveSetter setter) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_SETTER, setter }, - }; - DistributedKv::Value value(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "create jsonObject failed"); + return DistributedKv::Value(); + } + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SETTER.c_str(), static_cast(setter)); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Value value(jsonStr); TAG_LOGD(AAFwkTag::KEEP_ALIVE, "value: %{public}s", value.ToString().c_str()); return value; } @@ -311,25 +317,32 @@ DistributedKv::Value AbilityKeepAliveDataManager::ConvertKeepAliveStatusToValue( void AbilityKeepAliveDataManager::ConvertKeepAliveStatusFromValue(const DistributedKv::Value &value, KeepAliveSetter &setter) { - nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject fail"); + cJSON *jsonObject = cJSON_Parse(value.ToString().c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject failed"); return; } - if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) { - setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get()); + cJSON *setterItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_SETTER.c_str()); + if (setterItem != nullptr && cJSON_IsNumber(setterItem)) { + setter = KeepAliveSetter(static_cast(setterItem->valuedouble)); } + cJSON_Delete(jsonObject); } DistributedKv::Key AbilityKeepAliveDataManager::ConvertKeepAliveDataToKey(const KeepAliveInfo &info) { - nlohmann::json jsonObject = nlohmann::json { - { JSON_KEY_BUNDLE_NAME, info.bundleName }, - { JSON_KEY_USERID, info.userId }, - { JSON_KEY_APP_TYPE, info.appType }, - { JSON_KEY_SETTER, info.setter }, - }; - DistributedKv::Key key(jsonObject.dump()); + cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "create jsonObject failed"); + return DistributedKv::Key(); + } + cJSON_AddStringToObject(jsonObject, JSON_KEY_BUNDLE_NAME.c_str(), info.bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_USERID.c_str(), static_cast(info.userId)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_APP_TYPE.c_str(), static_cast(info.appType)); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SETTER.c_str(), static_cast(info.setter)); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jsonObject); + cJSON_Delete(jsonObject); + DistributedKv::Key key(jsonStr); TAG_LOGD(AAFwkTag::KEEP_ALIVE, "key: %{public}s", key.ToString().c_str()); return key; } @@ -337,53 +350,58 @@ DistributedKv::Key AbilityKeepAliveDataManager::ConvertKeepAliveDataToKey(const KeepAliveInfo AbilityKeepAliveDataManager::ConvertKeepAliveInfoFromKey(const DistributedKv::Key &key) { KeepAliveInfo info; - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject fail"); + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject failed"); return info; } - - if (jsonObject.contains(JSON_KEY_BUNDLE_NAME) && jsonObject[JSON_KEY_BUNDLE_NAME].is_string()) { - info.bundleName = jsonObject.at(JSON_KEY_BUNDLE_NAME).get(); + cJSON *bundleNameItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_BUNDLE_NAME.c_str()); + if (bundleNameItem != nullptr && cJSON_IsString(bundleNameItem)) { + info.bundleName = bundleNameItem->valuestring; } - - if (jsonObject.contains(JSON_KEY_USERID) && jsonObject[JSON_KEY_USERID].is_number()) { - info.userId = jsonObject.at(JSON_KEY_USERID).get(); + cJSON *userIdItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_USERID.c_str()); + if (userIdItem != nullptr && cJSON_IsNumber(userIdItem)) { + info.userId = static_cast(userIdItem->valuedouble); } - - if (jsonObject.contains(JSON_KEY_APP_TYPE) && jsonObject[JSON_KEY_APP_TYPE].is_number()) { - info.appType = KeepAliveAppType(jsonObject.at(JSON_KEY_APP_TYPE).get()); + cJSON *appTypeItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_APP_TYPE.c_str()); + if (appTypeItem != nullptr && cJSON_IsNumber(appTypeItem)) { + info.appType = static_cast(static_cast(appTypeItem->valuedouble)); } - - if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) { - info.setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get()); + cJSON *setterItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_SETTER.c_str()); + if (setterItem != nullptr && cJSON_IsNumber(setterItem)) { + info.setter = static_cast(static_cast(setterItem->valuedouble)); } - + cJSON_Delete(jsonObject); return info; } bool AbilityKeepAliveDataManager::IsEqual(const DistributedKv::Key &key, const KeepAliveInfo &info) { - nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject fail"); + cJSON *jsonObject = cJSON_Parse(key.ToString().c_str()); + if (jsonObject == nullptr) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject failed"); return false; } if (!AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_USERID, info.userId)) { + cJSON_Delete(jsonObject); return false; } if (!info.bundleName.empty() && !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_BUNDLE_NAME, info.bundleName)) { + cJSON_Delete(jsonObject); return false; } if (info.appType != KeepAliveAppType::UNSPECIFIED && !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_APP_TYPE, static_cast(info.appType))) { + cJSON_Delete(jsonObject); return false; } + cJSON_Delete(jsonObject); + return true; } } // namespace AbilityRuntime diff --git a/services/abilitymgr/src/mission/mission_info_mgr.cpp b/services/abilitymgr/src/mission/mission_info_mgr.cpp index 719d3c25594ac394edb129d0d7545dd33898b929..7f61a4b90136e62380c7bdf2854d1a4c6286f538 100644 --- a/services/abilitymgr/src/mission/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission/mission_info_mgr.cpp @@ -19,7 +19,6 @@ #include "ability_manager_service.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" -#include "nlohmann/json.hpp" #ifdef SUPPORT_GRAPHICS #include "pixel_map.h" #include "securec.h" diff --git a/services/abilitymgr/src/rdb/parser_util.cpp b/services/abilitymgr/src/rdb/parser_util.cpp index dbfddcc1031a830ff91755208244397914b55c83..a6ac2580f9c338dc16ce944bf34d661cccbbc5ef 100644 --- a/services/abilitymgr/src/rdb/parser_util.cpp +++ b/services/abilitymgr/src/rdb/parser_util.cpp @@ -20,6 +20,7 @@ #include "config_policy_utils.h" #include "hilog_tag_wrapper.h" +#include "json_utils.h" namespace OHOS { namespace AbilityRuntime { @@ -55,33 +56,34 @@ void ParserUtil::GetResidentProcessRawData(std::vector> &list) { - nlohmann::json jsonBuf; + cJSON *jsonBuf = nullptr; if (!ReadFileIntoJson(filePath, jsonBuf)) { return; } - if (jsonBuf.is_discarded()) { + if (jsonBuf == nullptr) { return; } FilterInfoFromJson(jsonBuf, list); + + cJSON_Delete(jsonBuf); } bool ParserUtil::FilterInfoFromJson( - nlohmann::json &jsonBuf, std::vector> &list) + cJSON *jsonBuf, std::vector> &list) { - if (jsonBuf.is_discarded()) { + if (jsonBuf == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "format error"); return false; } - if (jsonBuf.find(INSTALL_LIST) == jsonBuf.end()) { + cJSON *arrays = cJSON_GetObjectItem(jsonBuf, INSTALL_LIST); + if (arrays == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "installList absent"); return false; } - - auto arrays = jsonBuf.at(INSTALL_LIST); - if (!arrays.is_array() || arrays.empty()) { + if (!cJSON_IsArray(arrays)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "not found"); return false; } @@ -89,31 +91,36 @@ bool ParserUtil::FilterInfoFromJson( std::string bundleName; std::string KeepAliveEnable = "1"; std::string KeepAliveConfiguredList; - for (const auto &array : arrays) { - if (!array.is_object()) { + int size = cJSON_GetArraySize(arrays); + for (int i = 0; i < size; i++) { + cJSON *array = cJSON_GetArrayItem(arrays, i); + if (array == nullptr || !cJSON_IsObject(array)) { continue; } // Judgment logic exists, not found, not bool, not resident process - if (!(array.find(KEEP_ALIVE) != array.end() && array.at(KEEP_ALIVE).is_boolean() && - array.at(KEEP_ALIVE).get())) { + cJSON *keepAliveItem = cJSON_GetObjectItem(array, KEEP_ALIVE); + if (keepAliveItem == nullptr || !cJSON_IsBool(keepAliveItem) || keepAliveItem->type != cJSON_True) { continue; } - if (!(array.find(BUNDLE_NAME) != array.end() && array.at(BUNDLE_NAME).is_string())) { + cJSON *bundleNameItem = cJSON_GetObjectItem(array, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { continue; } - bundleName = array.at(BUNDLE_NAME).get(); + bundleName = bundleNameItem->valuestring; - if (array.find(KEEP_ALIVE_ENABLE) != array.end() && array.at(KEEP_ALIVE_ENABLE).is_boolean()) { - auto val = array.at(KEEP_ALIVE_ENABLE).get(); + cJSON *keepAliveEnableItem = cJSON_GetObjectItem(array, KEEP_ALIVE_ENABLE); + if (keepAliveEnableItem != nullptr || cJSON_IsBool(keepAliveEnableItem)) { + bool val = keepAliveEnableItem->type == cJSON_True ? true : false; KeepAliveEnable = std::to_string(val); } - if (array.find(KEEP_ALIVE_CONFIGURED_LIST) != array.end() && array.at(KEEP_ALIVE_CONFIGURED_LIST).is_array()) { + cJSON *keepAliveConfiguredListItem = cJSON_GetObjectItem(array, KEEP_ALIVE_CONFIGURED_LIST); + if (keepAliveConfiguredListItem != nullptr || cJSON_IsArray(keepAliveConfiguredListItem)) { // Save directly in the form of an array and parse it when in use - KeepAliveConfiguredList = array.at(KEEP_ALIVE_CONFIGURED_LIST).dump(); + KeepAliveConfiguredList = AAFwk::JsonUtils::GetInstance().ToString(keepAliveConfiguredListItem); } list.emplace_back(std::make_tuple(bundleName, KeepAliveEnable, KeepAliveConfiguredList)); @@ -144,7 +151,7 @@ void ParserUtil::GetPreInstallRootDirList(std::vector &rootDirList) } } -bool ParserUtil::ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool ParserUtil::ReadFileIntoJson(const std::string &filePath, cJSON *jsonBuf) { if (access(filePath.c_str(), F_OK) != 0) { TAG_LOGE(AAFwkTag::ABILITYMGR, "path not exist"); @@ -177,9 +184,11 @@ bool ParserUtil::ReadFileIntoJson(const std::string &filePath, nlohmann::json &j } fin.seekg(0, std::ios::beg); - jsonBuf = nlohmann::json::parse(fin, nullptr, false); + std::string fileContent((std::istreambuf_iterator(fin)), std::istreambuf_iterator()); fin.close(); - if (jsonBuf.is_discarded()) { + + jsonBuf = cJSON_Parse(fileContent.c_str()); + if (jsonBuf == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bad profile"); return false; } diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index b8d3613b12f0ec458e839672e8767db7e2bc54b4..d6d45ac5d267c4f89f21a20a4a33ea9303ad09f5 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -21,6 +21,7 @@ #include "display_info.h" #include "display_manager.h" #include "hitrace_meter.h" +#include "json_utils.h" #include "scene_board_judgement.h" #include "ui_extension_utils.h" @@ -127,11 +128,17 @@ Want SystemDialogScheduler::GetTipsDialogWant(const sptr &callerT DialogPosition position; GetDialogPositionAndSize(DialogType::DIALOG_TIPS, position); - nlohmann::json jsonObj; - jsonObj[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); - const std::string params = jsonObj.dump(); - AAFwk::Want want; + cJSON *jsonObj = cJSON_CreateObject(); + if (jsonObj == nullptr) { + TAG_LOGE(AAFwkTag::DIALOG, "create json object failed"); + return want; + } + cJSON_AddBoolToObject(jsonObj, IS_DEFAULT_SELECTOR.c_str(), + AppUtils::GetInstance().IsSelectorDialogDefaultPossion()); + std::string params = AAFwk::JsonUtils::GetInstance().ToString(jsonObj); + cJSON_Delete(jsonObj); + want.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_TIPS_DIALOG); want.SetParam(DIALOG_POSITION, GetDialogPositionParams(position)); want.SetParam(DIALOG_PARAMS, params); @@ -149,12 +156,18 @@ Want SystemDialogScheduler::GetJumpInterceptorDialogWant(Want &targetWant) DialogPosition position; GetDialogPositionAndSize(DialogType::DIALOG_JUMP_INTERCEPTOR, position); - nlohmann::json jsonObj; - jsonObj[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); - jsonObj["bundleName"] = targetWant.GetElement().GetBundleName(); - jsonObj["abilityName"] = targetWant.GetElement().GetAbilityName(); - jsonObj["moduleName"] = targetWant.GetElement().GetModuleName(); - const std::string params = jsonObj.dump(); + cJSON *jsonObj = cJSON_CreateObject(); + if (jsonObj == nullptr) { + TAG_LOGE(AAFwkTag::DIALOG, "create json object failed"); + return targetWant; + } + cJSON_AddBoolToObject(jsonObj, IS_DEFAULT_SELECTOR.c_str(), + AppUtils::GetInstance().IsSelectorDialogDefaultPossion()); + cJSON_AddStringToObject(jsonObj, "bundleName", targetWant.GetElement().GetBundleName().c_str()); + cJSON_AddStringToObject(jsonObj, "abilityName", targetWant.GetElement().GetAbilityName().c_str()); + cJSON_AddStringToObject(jsonObj, "moduleName", targetWant.GetElement().GetModuleName().c_str()); + std::string params = AAFwk::JsonUtils::GetInstance().ToString(jsonObj); + cJSON_Delete(jsonObj); targetWant.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_JUMP_INTERCEPTOR_DIALOG); targetWant.SetParam(DIALOG_POSITION, GetDialogPositionParams(position)); @@ -328,25 +341,42 @@ const std::string SystemDialogScheduler::GetSelectorParams(const std::vector &dialogAppInfos, Want &requestWant, @@ -373,33 +403,46 @@ const std::string SystemDialogScheduler::GetPcSelectorParams(const std::vector &dialogAppInfos, @@ -446,13 +489,19 @@ int SystemDialogScheduler::GetSelectorDialogWantCommon(const std::vector(position.offsetX)); + cJSON_AddNumberToObject(dialogPositionData, OFF_SET_Y.c_str(), static_cast(position.offsetY)); + cJSON_AddNumberToObject(dialogPositionData, WIDTH.c_str(), static_cast(position.width)); + cJSON_AddNumberToObject(dialogPositionData, HEIGHT.c_str(), static_cast(position.height)); + cJSON_AddBoolToObject(dialogPositionData, OVERSIZE_HEIGHT.c_str(), position.oversizeHeight); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(dialogPositionData); + cJSON_Delete(dialogPositionData); + return jsonStr; } void SystemDialogScheduler::InitDialogPosition(DialogType type, DialogPosition &position) const diff --git a/services/abilitymgr/src/utils/modal_system_dialog_util.cpp b/services/abilitymgr/src/utils/modal_system_dialog_util.cpp index 8451b89dc0c02b9d58f6e7bd257554f7fd0347e8..d72698cfeb492f3216ec53d8f31ca95fef2d6a04 100644 --- a/services/abilitymgr/src/utils/modal_system_dialog_util.cpp +++ b/services/abilitymgr/src/utils/modal_system_dialog_util.cpp @@ -15,6 +15,7 @@ #include "ability_util.h" #include "hilog_tag_wrapper.h" +#include "json_utils.h" #include "modal_system_dialog/modal_system_dialog_ui_extension.h" #include "parameters.h" #include "utils/modal_system_dialog_util.h" @@ -45,21 +46,30 @@ void ModalSystemDialogUtil::ShowDeveloperModeDialog( CHECK_POINTER(bms); std::string labelString = IN_PROCESS_CALL(bms->GetStringById(bundleName, moduleName, labelId, userId)); - nlohmann::json infoObject; - infoObject["appName"] = labelString.c_str(); - infoObject["title"] = RESOURCE_ID_DEVELOPER_DIALOG_TITLE; - infoObject["content"] = RESOURCE_ID_DEVELOPER_DIALOG_CONTENT; - infoObject["button"] = RESOURCE_ID_GENERAL_GET_IT; + cJSON *infoObject = cJSON_CreateObject(); + if (infoObject == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } + cJSON_AddStringToObject(infoObject, "appName", labelString.c_str()); + cJSON_AddStringToObject(infoObject, "title", RESOURCE_ID_DEVELOPER_DIALOG_TITLE); + cJSON_AddStringToObject(infoObject, "content", RESOURCE_ID_DEVELOPER_DIALOG_CONTENT); + cJSON_AddStringToObject(infoObject, "button", RESOURCE_ID_GENERAL_GET_IT); - nlohmann::json param; - param["extraInfo"] = infoObject; + cJSON *param = cJSON_CreateObject(); + if (param == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + cJSON_Delete(infoObject); + return; + } + cJSON_AddItemToObject(param, "extraInfo", infoObject); - std::string paramStr = param.dump(); + std::string paramStr = AAFwk::JsonUtils::GetInstance().ToString(param); + cJSON_Delete(param); auto connection = std::make_shared(); if (connection && connection->CreateModalUIExtension(paramStr)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "create modal ui extension failed"); } } - } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index ade83eb7a01b176365192a96036d9f218c33b6cb..72eb1bc366a085736ac095c4a2782b0a9f700987 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -140,7 +140,6 @@ ohos_shared_library("libappms") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "memmgr:memmgrclient", "memory_utils:libmeminfo", diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index f31f769389cc3a56158a846e435b41eb5738809d..b2e30d8a2e9fe815323cde3d3ca5aefdf2d71434 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include diff --git a/services/appmgr/src/app_native_spawn_manager.cpp b/services/appmgr/src/app_native_spawn_manager.cpp index aafb5b1018b9d23a94b9bd982e00b134e786cb06..df05497fbdab7ab3a2857686236902de3645b081 100644 --- a/services/appmgr/src/app_native_spawn_manager.cpp +++ b/services/appmgr/src/app_native_spawn_manager.cpp @@ -15,12 +15,12 @@ #include "app_native_spawn_manager.h" -#include #include #include "ability_manager_errors.h" #include "appspawn.h" #include "c/executor_task.h" +#include "cJSON.h" #include "ffrt.h" #include "ffrt_inner.h" #include "hilog_tag_wrapper.h" @@ -165,26 +165,32 @@ static void ProcessSignalData(void *token, uint32_t event) std::string bundleName = ""; std::string bufferStr = buffer; TAG_LOGD(AAFwkTag::APPMGR, "buffer read: %{public}s", bufferStr.c_str()); - nlohmann::json jsonObject = nlohmann::json::parse(bufferStr, nullptr, false); - if (jsonObject.is_discarded()) { + cJSON *jsonObject = cJSON_Parse(bufferStr.c_str()); + if (jsonObject == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "parse json string failed"); return; } - if (!jsonObject.contains("pid") || !jsonObject.contains("signal") || !jsonObject.contains("uid") - || !jsonObject.contains("bundleName")) { + cJSON *pidItem = cJSON_GetObjectItem(jsonObject, "pid"); + cJSON *signalItem = cJSON_GetObjectItem(jsonObject, "signal"); + cJSON *uidItem = cJSON_GetObjectItem(jsonObject, "uid"); + cJSON *bundleNameItem = cJSON_GetObjectItem(jsonObject, "bundleName"); + if (pidItem == nullptr || signalItem == nullptr || uidItem == nullptr || bundleNameItem == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "info lost!"); + cJSON_Delete(jsonObject); return; } - if (!jsonObject["pid"].is_number_integer() || !jsonObject["signal"].is_number_integer() || - !jsonObject["uid"].is_number_integer() || !jsonObject["bundleName"].is_string()) { + if (!cJSON_IsNumber(pidItem) || !cJSON_IsNumber(signalItem) || !cJSON_IsNumber(uidItem) || + !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::APPMGR, "info type err!"); + cJSON_Delete(jsonObject); return; } - pid = jsonObject["pid"]; - signal = jsonObject["signal"]; - uid = jsonObject["uid"]; - bundleName = jsonObject["bundleName"]; + pid = static_cast(pidItem->valuedouble); + signal = static_cast(signalItem->valuedouble); + uid = static_cast(uidItem->valuedouble); + bundleName = bundleNameItem->valuestring; + cJSON_Delete(jsonObject); if (signal == 0) { TAG_LOGD(AAFwkTag::APPMGR, "ignore signal 0, pid: %{public}d", pid); return; diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 071b974a3a4b3f6339cbdf288799838e92a6878b..01b2016c851f983fd2a01511c33b2dbc18b3687b 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -16,9 +16,10 @@ #include +#include "cJSON.h" #include "hitrace_meter.h" #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" +#include "json_utils.h" #include "securec.h" #include "time_util.h" @@ -133,65 +134,166 @@ AppSpawnClientHandle AppSpawnClient::GetAppSpawnClientHandle() const static std::string DumpDataGroupInfoListToJson(const DataGroupInfoList &dataGroupInfoList, bool isScreenLockDataProtect) { TAG_LOGD(AAFwkTag::APPMGR, "dataGroupInfoList size: %{public}zu", dataGroupInfoList.size()); - nlohmann::json dataGroupInfoListJson; + cJSON *dataGroupInfoListJson = cJSON_CreateArray(); + if (dataGroupInfoListJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json array failed"); + return {}; + } + for (auto& dataGroupInfo : dataGroupInfoList) { - nlohmann::json dataGroupInfoJson; - dataGroupInfoJson[DATAGROUPINFOLIST_DATAGROUPID] = dataGroupInfo.dataGroupId; - dataGroupInfoJson[DATAGROUPINFOLIST_GID] = std::to_string(dataGroupInfo.gid); - dataGroupInfoJson[DATAGROUPINFOLIST_UUID] = dataGroupInfo.uuid; + cJSON *dataGroupInfoJson = cJSON_CreateObject(); + if (dataGroupInfoJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_DATAGROUPID, dataGroupInfo.dataGroupId.c_str()); + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_GID, std::to_string(dataGroupInfo.gid).c_str()); + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_UUID, dataGroupInfo.uuid.c_str()); std::string dir = std::to_string(dataGroupInfo.userId) + JSON_GROUP + dataGroupInfo.uuid; - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL2 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL3 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); + cJSON *dataGroupInfoJsonEl2 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl2 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el2Dir = std::string(JSON_DATA_APP_DIR_EL2) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl2, DATAGROUPINFOLIST_DIR, el2Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl2); + + cJSON *dataGroupInfoJsonEl3 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl3 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el3Dir = std::string(JSON_DATA_APP_DIR_EL3) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl3, DATAGROUPINFOLIST_DIR, el3Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl3); + + cJSON *dataGroupInfoJsonEl4 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl4 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el4Dir = std::string(JSON_DATA_APP_DIR_EL4) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl4, DATAGROUPINFOLIST_DIR, el4Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl4); - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL4 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); if (isScreenLockDataProtect) { - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL5 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); + cJSON *dataGroupInfoJsonEl5 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl5 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el5Dir = std::string(JSON_DATA_APP_DIR_EL5) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl5, DATAGROUPINFOLIST_DIR, el5Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl5); } + + cJSON_Delete(dataGroupInfoJson); } - TAG_LOGD(AAFwkTag::APPMGR, "dataGroupInfoListJson %{public}s", dataGroupInfoListJson.dump().c_str()); - return dataGroupInfoListJson.dump(); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(dataGroupInfoListJson); + cJSON_Delete(dataGroupInfoListJson); + TAG_LOGD(AAFwkTag::APPMGR, "dataGroupInfoListJson %{public}s", jsonStr.c_str()); + return jsonStr; } static std::string DumpHspListToJson(const HspList &hspList) { - nlohmann::json hspListJson; + cJSON *hspListJson = cJSON_CreateObject(); + if (hspListJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + return {}; + } + cJSON *bundlesItem = cJSON_CreateArray(); + cJSON *modulesItem = cJSON_CreateArray(); + cJSON *versionsItem = cJSON_CreateArray(); + if (bundlesItem == nullptr || modulesItem == nullptr || versionsItem == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json array failed"); + cJSON_Delete(bundlesItem); + cJSON_Delete(modulesItem); + cJSON_Delete(versionsItem); + cJSON_Delete(hspListJson); + return {}; + } + for (auto& hsp : hspList) { - hspListJson[HSPLIST_BUNDLES].emplace_back(hsp.bundleName); - hspListJson[HSPLIST_MODULES].emplace_back(hsp.moduleName); - hspListJson[HSPLIST_VERSIONS].emplace_back(VERSION_PREFIX + std::to_string(hsp.versionCode)); + cJSON_AddItemToArray(bundlesItem, cJSON_CreateString(hsp.bundleName.c_str())); + cJSON_AddItemToArray(modulesItem, cJSON_CreateString(hsp.moduleName.c_str())); + std::string version = VERSION_PREFIX + std::to_string(hsp.versionCode); + cJSON_AddItemToArray(versionsItem, cJSON_CreateString(version.c_str())); } - return hspListJson.dump(); + + cJSON_AddItemToObject(hspListJson, HSPLIST_BUNDLES, bundlesItem); + cJSON_AddItemToObject(hspListJson, HSPLIST_MODULES, modulesItem); + cJSON_AddItemToObject(hspListJson, HSPLIST_VERSIONS, versionsItem); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(hspListJson); + cJSON_Delete(hspListJson); + return jsonStr; } static std::string DumpAppEnvToJson(const std::map &appEnv) { - nlohmann::json appEnvJson; + cJSON *appEnvJson = cJSON_CreateObject(); + if (appEnvJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + return {}; + } + for (const auto &[envName, envValue] : appEnv) { - appEnvJson[envName] = envValue; + cJSON_AddStringToObject(appEnvJson, envName.c_str(), envValue.c_str()); } - return appEnvJson.dump(); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(appEnvJson); + cJSON_Delete(appEnvJson); + return jsonStr; } static std::string DumpJITPermissionListToJson(const JITPermissionsMap &jitPermissionsMap) { - nlohmann::json jitPermissionsListJson; - jitPermissionsListJson[JITPERMISSIONSLIST_NAME] = JITPERMISSIONSLIST_NAME_VALUE; - jitPermissionsListJson[JITPERMISSIONSLIST_COUNT] = jitPermissionsMap.size(); + cJSON *jitPermissionsListJson = cJSON_CreateObject(); + if (jitPermissionsListJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + return {}; + } + cJSON_AddStringToObject(jitPermissionsListJson, JITPERMISSIONSLIST_NAME, JITPERMISSIONSLIST_NAME_VALUE); + cJSON_AddNumberToObject(jitPermissionsListJson, JITPERMISSIONSLIST_COUNT, + static_cast(jitPermissionsMap.size())); + + cJSON *permissionsItem = cJSON_CreateArray(); + if (permissionsItem == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json array failed"); + cJSON_Delete(jitPermissionsListJson); + return {}; + } + for (const auto &[permissionName, permissionValue] : jitPermissionsMap) { - nlohmann::json temp; - if (permissionValue.empty()) { - temp[permissionName] = true; - } else { - temp[permissionName] = permissionValue; - } - jitPermissionsListJson[JITPERMISSIONSLIST_PERMISSIONS_NAME].emplace_back(temp); - } - return jitPermissionsListJson.dump(); + cJSON *tempItem = cJSON_CreateObject(); + if (tempItem == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create temp json object failed"); + cJSON_Delete(jitPermissionsListJson); + cJSON_Delete(permissionsItem); + return ""; + } + std::string value = permissionValue.empty() ? "true" : permissionValue; + cJSON_AddStringToObject(tempItem, permissionName.c_str(), value.c_str()); + cJSON_AddItemToArray(permissionsItem, tempItem); + } + cJSON_AddItemToObject(jitPermissionsListJson, JITPERMISSIONSLIST_PERMISSIONS_NAME, permissionsItem); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(jitPermissionsListJson); + cJSON_Delete(jitPermissionsListJson); + return jsonStr; } int32_t AppSpawnClient::SetDacInfo(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle) diff --git a/services/appmgr/src/app_spawn_msg_wrapper.cpp b/services/appmgr/src/app_spawn_msg_wrapper.cpp index 167ef9121c2c4efc8b675f979c12184eddf5fafc..6bc04a037d615222ffa79f6e1af596b72992e68c 100644 --- a/services/appmgr/src/app_spawn_msg_wrapper.cpp +++ b/services/appmgr/src/app_spawn_msg_wrapper.cpp @@ -17,8 +17,8 @@ #include "securec.h" +#include "cJSON.h" #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" namespace OHOS { namespace AppExecFwk { @@ -49,48 +49,129 @@ AppSpawnMsgWrapper::~AppSpawnMsgWrapper() static std::string DumpToJson(const HspList &hspList) { - nlohmann::json hspListJson; + cJSON *hspListJson = cJSON_CreateObject(); + if (hspListJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + return {}; + } + cJSON *bundlesItem = cJSON_CreateArray(); + cJSON *modulesItem = cJSON_CreateArray(); + cJSON *versionsItem = cJSON_CreateArray(); + if (bundlesItem == nullptr || modulesItem == nullptr || versionsItem == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json array failed"); + cJSON_Delete(bundlesItem); + cJSON_Delete(modulesItem); + cJSON_Delete(versionsItem); + cJSON_Delete(hspListJson); + return {}; + } + for (auto& hsp : hspList) { - hspListJson[HSPLIST_BUNDLES].emplace_back(hsp.bundleName); - hspListJson[HSPLIST_MODULES].emplace_back(hsp.moduleName); - hspListJson[HSPLIST_VERSIONS].emplace_back(VERSION_PREFIX + std::to_string(hsp.versionCode)); + cJSON_AddItemToArray(bundlesItem, cJSON_CreateString(hsp.bundleName.c_str())); + cJSON_AddItemToArray(modulesItem, cJSON_CreateString(hsp.moduleName.c_str())); + std::string version = VERSION_PREFIX + std::to_string(hsp.versionCode); + cJSON_AddItemToArray(versionsItem, cJSON_CreateString(version.c_str())); } - return hspListJson.dump(); + + cJSON_AddItemToObject(hspListJson, HSPLIST_BUNDLES, bundlesItem); + cJSON_AddItemToObject(hspListJson, HSPLIST_MODULES, modulesItem); + cJSON_AddItemToObject(hspListJson, HSPLIST_VERSIONS, versionsItem); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(hspListJson); + cJSON_Delete(hspListJson); + return jsonStr; } static std::string DumpToJson(const DataGroupInfoList &dataGroupInfoList, bool isScreenLockDataProtect) { - nlohmann::json dataGroupInfoListJson; + cJSON *dataGroupInfoListJson = cJSON_CreateArray(); + if (dataGroupInfoListJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json array failed"); + return {}; + } + for (auto& dataGroupInfo : dataGroupInfoList) { - nlohmann::json dataGroupInfoJson; - dataGroupInfoJson[DATAGROUPINFOLIST_DATAGROUPID] = dataGroupInfo.dataGroupId; - dataGroupInfoJson[DATAGROUPINFOLIST_GID] = std::to_string(dataGroupInfo.gid); - dataGroupInfoJson[DATAGROUPINFOLIST_UUID] = dataGroupInfo.uuid; + cJSON *dataGroupInfoJson = cJSON_CreateObject(); + if (dataGroupInfoJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_DATAGROUPID, dataGroupInfo.dataGroupId.c_str()); + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_GID, std::to_string(dataGroupInfo.gid).c_str()); + cJSON_AddStringToObject(dataGroupInfoJson, DATAGROUPINFOLIST_UUID, dataGroupInfo.uuid.c_str()); std::string dir = std::to_string(dataGroupInfo.userId) + JSON_GROUP + dataGroupInfo.uuid; - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL2 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL3 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); + cJSON *dataGroupInfoJsonEl2 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl2 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el2Dir = std::string(JSON_DATA_APP_DIR_EL2) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl2, DATAGROUPINFOLIST_DIR, el2Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl2); + + cJSON *dataGroupInfoJsonEl3 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl3 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el3Dir = std::string(JSON_DATA_APP_DIR_EL3) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl3, DATAGROUPINFOLIST_DIR, el3Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl3); + + cJSON *dataGroupInfoJsonEl4 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl4 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el4Dir = std::string(JSON_DATA_APP_DIR_EL4) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl4, DATAGROUPINFOLIST_DIR, el4Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl4); - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL4 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); if (isScreenLockDataProtect) { - dataGroupInfoJson[DATAGROUPINFOLIST_DIR] = JSON_DATA_APP_DIR_EL5 + dir; - dataGroupInfoListJson.emplace_back(dataGroupInfoJson); + cJSON *dataGroupInfoJsonEl5 = cJSON_Duplicate(dataGroupInfoJson, 1); + if (dataGroupInfoJsonEl5 == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "duplicate json object failed"); + cJSON_Delete(dataGroupInfoJson); + cJSON_Delete(dataGroupInfoListJson); + return {}; + } + std::string el5Dir = std::string(JSON_DATA_APP_DIR_EL5) + dir; + cJSON_AddStringToObject(dataGroupInfoJsonEl5, DATAGROUPINFOLIST_DIR, el5Dir.c_str()); + cJSON_AddItemToArray(dataGroupInfoListJson, dataGroupInfoJsonEl5); } + + cJSON_Delete(dataGroupInfoJson); } - TAG_LOGD(AAFwkTag::APPMGR, "dataGroupInfoListJson %{public}s", dataGroupInfoListJson.dump().c_str()); - return dataGroupInfoListJson.dump(); + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(dataGroupInfoListJson); + cJSON_Delete(dataGroupInfoListJson); + TAG_LOGD(AAFwkTag::APPMGR, "dataGroupInfoListJson %{public}s", jsonStr.c_str()); + return jsonStr; } static std::string DumpAppEnvToJson(const std::map &appEnv) { - nlohmann::json appEnvJson; + cJSON *appEnvJson = cJSON_CreateObject(); + if (appEnvJson == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create json object failed"); + return {}; + } + for (const auto &[envName, envValue] : appEnv) { - appEnvJson[envName] = envValue; + cJSON_AddStringToObject(appEnvJson, envName.c_str(), envValue.c_str()); } - return appEnvJson.dump(); + + std::string jsonStr = AAFwk::JsonUtils::GetInstance().ToString(appEnvJson); + cJSON_Delete(appEnvJson); + return jsonStr; } bool AppSpawnMsgWrapper::AssembleMsg(const AppSpawnStartMsg &startMsg) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index 4e28abf4b8054f7d940f50078e2a93d031c53460..dd1ca7bb9a94e36222cf7f19bf49206b393982ad 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -197,11 +197,16 @@ void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityConnec TAG_LOGE(AAFwkTag::ABILITYMGR, "write parameters failed"); return; } - nlohmann::json param; - param[UIEXTENSION_TYPE_KEY.c_str()] = want_.GetStringParam(UIEXTENSION_TYPE_KEY); - param[APP_FREEZE_PID.c_str()] = want_.GetStringParam(APP_FREEZE_PID); - param[START_BUNDLE_NAME.c_str()] = want_.GetStringParam(START_BUNDLE_NAME); - std::string paramStr = param.dump(); + cJSON *param = cJSON_CreateObject(); + if (param == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "create json object failed"); + return; + } + cJSON_AddStringToObject(param, UIEXTENSION_TYPE_KEY.c_str(), want_.GetStringParam(UIEXTENSION_TYPE_KEY).c_str()); + cJSON_AddStringToObject(param, APP_FREEZE_PID.c_str(), want_.GetStringParam(APP_FREEZE_PID).c_str()); + cJSON_AddStringToObject(param, START_BUNDLE_NAME.c_str(), want_.GetStringParam(START_BUNDLE_NAME).c_str()); + std::string paramStr = AAFwk::JsonUtils::GetInstance().ToString(param); + cJSON_Delete(param); if (!data.WriteString16(Str8ToStr16(paramStr))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write paramStr failed"); return; diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index df47a684901ad9a759f0ef9f30e1f6e14ebfabdf..050686d7029aedba9ed2bd7d636db6633a8d61a9 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -139,6 +139,7 @@ ohos_shared_library("app_util") { external_deps = [ "c_utils:utils", + "cJSON:cjson", "config_policy:configpolicy_util", "hicollie:libhicollie", "hilog:libhilog", diff --git a/services/common/include/json_utils.h b/services/common/include/json_utils.h index 66dc39898d36000d17c925c8c6b6bd130f6b55cc..455d9465a19fd40bf211e2b539e7fb0dece6aad5 100644 --- a/services/common/include/json_utils.h +++ b/services/common/include/json_utils.h @@ -20,7 +20,7 @@ #include #include -#include "nlohmann/json.hpp" +#include "cJSON.h" #include "singleton.h" namespace OHOS { @@ -56,7 +56,7 @@ public: * @param defaultPath The default output path. * @return Whether or not the load operation succeeds. */ - bool LoadConfiguration(const std::string& path, nlohmann::json& jsonBuf, const std::string& defaultPath = ""); + bool LoadConfiguration(const std::string& path, cJSON *jsonBuf, const std::string& defaultPath = ""); /** * IsEqual, check if json object contains certain key. @@ -67,8 +67,7 @@ public: * @param checkEmpty The flag indicates whether the value can be empty. * @return Whether or not the json object contains certain key. */ - bool IsEqual(nlohmann::json &jsonObject, const std::string &key, - const std::string &value, bool checkEmpty = false); + bool IsEqual(cJSON *jsonObject, const std::string &key, const std::string &value, bool checkEmpty = false); /** * IsEqual, check if json object contains certain key. @@ -78,7 +77,7 @@ public: * @param value The int32_t value. * @return Whether or not the json object contains certain key. */ - bool IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value); + bool IsEqual(cJSON *jsonObject, const std::string &key, int32_t value); /** * parse json to optional bool. @@ -87,11 +86,13 @@ public: * @param key The key. * @return optional boolean value. */ - std::optional JsonToOptionalBool(const nlohmann::json &jsonObject, const std::string &key); + std::optional JsonToOptionalBool(const cJSON *jsonObject, const std::string &key); + + std::string ToString(const cJSON *jsonObject); private: std::string GetConfigPath(const std::string& path, const std::string& defaultPath); - bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); + bool ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf); JsonUtils() = default; DISALLOW_COPY_AND_MOVE(JsonUtils); }; diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index cfcf6e7c6c498046b1c6fec7c9e55c76aaab6b3f..f52c7844a5e08a4ceeab00cf7b5eb368ba894416 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -15,9 +15,9 @@ #include "app_utils.h" #include +#include "cJSON.h" #include "json_utils.h" #include "hilog_tag_wrapper.h" -#include "nlohmann/json.hpp" #include "parameter.h" #include "parameters.h" #ifdef SUPPORT_GRAPHICS @@ -330,79 +330,123 @@ bool AppUtils::IsRequireBigMemoryProcess(const std::string &bundleName) void AppUtils::LoadProcessProhibitedFromRestarting() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(CONFIG_PATH, object)) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "process prohibited invalid"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "process prohibited invalid"); return; } - if (!object.contains(PROCESS_PROHIBITED_FROM_RESTARTING) || - !object.at(PROCESS_PROHIBITED_FROM_RESTARTING).is_array()) { + if (object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "object is null"); + return; + } + cJSON *processItem = cJSON_GetObjectItem(object, PROCESS_PROHIBITED_FROM_RESTARTING); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "process prohibited invalid."); + cJSON_Delete(object); return; } - for (auto &item : object.at(PROCESS_PROHIBITED_FROM_RESTARTING).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load bundleName failed"); + cJSON_Delete(object); return; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; processProhibitedFromRestarting_.value.emplace_back(bundleName); } + cJSON_Delete(object); } void AppUtils::LoadRequireBigMemoryApp() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(CONFIG_PATH, object)) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "process prohibited invalid"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "process prohibited invalid"); return; } - if (!object.contains(REQUIRE_BIGMEMORY_APP) || - !object.at(REQUIRE_BIGMEMORY_APP).is_array()) { + if (object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "object is null"); + return; + } + cJSON *processItem = cJSON_GetObjectItem(object, REQUIRE_BIGMEMORY_APP); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "process prohibited invalid."); + cJSON_Delete(object); return; } - for (auto &item : object.at(REQUIRE_BIGMEMORY_APP).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load bundleName failed"); + cJSON_Delete(object); return; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; requireBigMemoryApp_.value.emplace_back(bundleName); } + cJSON_Delete(object); } void AppUtils::LoadResidentProcessInExtremeMemory() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(CONFIG_PATH, object)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process failed"); return; } - if (!object.contains(RESIDENT_PROCESS_IN_EXTREME_MEMORY) || - !object.at(RESIDENT_PROCESS_IN_EXTREME_MEMORY).is_array()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process invalid"); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "object is null"); + return; + } + cJSON *processItem = cJSON_GetObjectItem(object, RESIDENT_PROCESS_IN_EXTREME_MEMORY); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process invalid."); + cJSON_Delete(object); return; } - for (auto &item : object.at(RESIDENT_PROCESS_IN_EXTREME_MEMORY).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load bundleName failed"); + cJSON_Delete(object); return; } - if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { + cJSON *abilityNameItem = cJSON_GetObjectItem(childItem, ABILITY_NAME); + if (abilityNameItem == nullptr || !cJSON_IsString(abilityNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load abilityName failed"); + cJSON_Delete(object); return; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); - std::string abilityName = jsonObject.at(ABILITY_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; + std::string abilityName = abilityNameItem->valuestring; residentProcessInExtremeMemory_.value.emplace_back(std::make_pair(bundleName, abilityName)); } + cJSON_Delete(object); } bool AppUtils::IsAllowNativeChildProcess(const std::string &appIdentifier) @@ -419,26 +463,39 @@ bool AppUtils::IsAllowNativeChildProcess(const std::string &appIdentifier) void AppUtils::LoadAllowNativeChildProcessApps() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(ALLOW_NATIVE_CHILD_PROCESS_APPS_CONFIG_PATH, object)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load child process config failed"); return; } - if (!object.contains(KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS) || - !object.at(KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS).is_array()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "get key invalid"); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "object is null"); return; } - - for (auto &item : object.at(KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(KEY_IDENTIFIER) || !jsonObject.at(KEY_IDENTIFIER).is_string()) { + cJSON *processItem = cJSON_GetObjectItem(object, KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "get key invalid."); + cJSON_Delete(object); + return; + } + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *identifierItem = cJSON_GetObjectItem(childItem, KEY_IDENTIFIER); + if (identifierItem == nullptr || !cJSON_IsString(identifierItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load identifier failed"); + cJSON_Delete(object); return; } - std::string identifier = jsonObject.at(KEY_IDENTIFIER).get(); + std::string identifier = identifierItem->valuestring; allowStartNativeProcessApps_.value.emplace_back(identifier); } + cJSON_Delete(object); } int32_t AppUtils::GetLimitMaximumExtensionsPerProc() @@ -495,32 +552,48 @@ bool AppUtils::IsAllowStartAbilityWithoutCallerToken(const std::string& bundleNa void AppUtils::LoadStartAbilityWithoutCallerToken() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration( START_ABILITY_WITHOUT_CALLERTOKEN_PATH, object, START_ABILITY_WITHOUT_CALLERTOKEN)) { TAG_LOGE(AAFwkTag::DEFAULT, "token list failed"); return; } - if (!object.contains(START_ABILITY_WITHOUT_CALLERTOKEN_TITLE) || - !object.at(START_ABILITY_WITHOUT_CALLERTOKEN_TITLE).is_array()) { - TAG_LOGE(AAFwkTag::DEFAULT, "token config invalid"); + if (object == nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "object is null"); + return; + } + cJSON *processItem = cJSON_GetObjectItem(object, START_ABILITY_WITHOUT_CALLERTOKEN_TITLE); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "token config invalid."); + cJSON_Delete(object); return; } - for (auto &item : object.at(START_ABILITY_WITHOUT_CALLERTOKEN_TITLE).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { - TAG_LOGE(AAFwkTag::DEFAULT, "load bundleName failed"); + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "load bundleName failed"); + cJSON_Delete(object); return; } - if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { - TAG_LOGE(AAFwkTag::DEFAULT, "load abilityName failed"); + cJSON *abilityNameItem = cJSON_GetObjectItem(childItem, ABILITY_NAME); + if (abilityNameItem == nullptr || !cJSON_IsString(abilityNameItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "load abilityName failed"); + cJSON_Delete(object); return; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); - std::string abilityName = jsonObject.at(ABILITY_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; + std::string abilityName = abilityNameItem->valuestring; startAbilityWithoutCallerToken_.value.emplace_back(std::make_pair(bundleName, abilityName)); } + cJSON_Delete(object); } std::string AppUtils::GetBrokerDelegateBundleName() @@ -635,31 +708,47 @@ bool AppUtils::IsCacheAbilityEnabled() void AppUtils::LoadCacheAbilityList() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(CACHE_ABILITY_LIST_PATH, object)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "load cache_ability file failed"); return; } - if (!object.contains(CACHE_PROCESS_NAME) || - !object.at(CACHE_PROCESS_NAME).is_array()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "cache_ability file invalid"); + if (object == nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "object is null"); + return; + } + cJSON *processItem = cJSON_GetObjectItem(object, CACHE_PROCESS_NAME); + if (processItem == nullptr || !cJSON_IsArray(processItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "cache_ability file invalid."); + cJSON_Delete(object); return; } - for (auto &item : object.at(CACHE_PROCESS_NAME).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + int size = cJSON_GetArraySize(processItem); + for (int i = 0; i < size; i++) { + cJSON *childItem = cJSON_GetArrayItem(processItem, i); + if (childItem == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "item is null"); + cJSON_Delete(object); + return; + } + cJSON *bundleNameItem = cJSON_GetObjectItem(childItem, BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load cache_ability bundleName failed"); + cJSON_Delete(object); return; } - if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { + cJSON *abilityNameItem = cJSON_GetObjectItem(childItem, ABILITY_NAME); + if (abilityNameItem == nullptr || !cJSON_IsString(abilityNameItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load cache_ability abilityName failed"); + cJSON_Delete(object); return; } - std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); - std::string abilityName = jsonObject.at(ABILITY_NAME).get(); + std::string bundleName = bundleNameItem->valuestring; + std::string abilityName = abilityNameItem->valuestring; cacheAbilityList_.value.emplace_back(std::make_pair(bundleName, abilityName)); } + cJSON_Delete(object); } bool AppUtils::IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName) @@ -688,24 +777,25 @@ bool AppUtils::IsCacheExtensionAbilityByList(const std::string& bundleName, cons void AppUtils::LoadResidentWhiteList() { - nlohmann::json object; + cJSON *object = nullptr; if (!JsonUtils::GetInstance().LoadConfiguration(RESIDENT_WHITE_LIST_PATH, object)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "load resident white list file failed"); return; } - if (!object.contains(NORMAL_RESIDENT_APPS) || - !object.at(NORMAL_RESIDENT_APPS).is_array()) { + cJSON *normalResidentAppsItem = cJSON_GetObjectItem(object, NORMAL_RESIDENT_APPS); + if (normalResidentAppsItem == nullptr || !cJSON_IsArray(normalResidentAppsItem)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "resident white list file invalid"); return; } - - for (auto &item : object.at(NORMAL_RESIDENT_APPS).items()) { - const nlohmann::json& jsonObject = item.value(); - if (!jsonObject.is_string()) { + int size = cJSON_GetArraySize(normalResidentAppsItem); + for (int i = 0; i < size; i++) { + cJSON *jsonObject = cJSON_GetArrayItem(normalResidentAppsItem, i); + if (jsonObject == nullptr || !cJSON_IsString(jsonObject)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "load resident white bundleName failed"); return; } - residentWhiteList_.value.emplace_back(jsonObject.get()); + std::string jsonStr = jsonObject->valuestring; + residentWhiteList_.value.emplace_back(jsonStr); } } diff --git a/services/common/src/json_utils.cpp b/services/common/src/json_utils.cpp index ba5c58594b74152eed6109010bdd105476f01dec..bfd2822ff6e5a6ccb130db6d664dad512bebb87f 100644 --- a/services/common/src/json_utils.cpp +++ b/services/common/src/json_utils.cpp @@ -24,8 +24,7 @@ namespace OHOS { namespace AAFwk { -bool JsonUtils::LoadConfiguration(const std::string& path, nlohmann::json& jsonBuf, - const std::string& defaultPath) +bool JsonUtils::LoadConfiguration(const std::string& path, cJSON *jsonBuf, const std::string& defaultPath) { std::string configPath = GetConfigPath(path, defaultPath); TAG_LOGD(AAFwkTag::ABILITYMGR, "config path is: %{public}s", configPath.c_str()); @@ -45,7 +44,7 @@ std::string JsonUtils::GetConfigPath(const std::string& path, const std::string& return configPath; } -bool JsonUtils::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool JsonUtils::ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf) { if (access(filePath.c_str(), F_OK) != 0) { TAG_LOGE(AAFwkTag::ABILITYMGR, "deepLink config not exist"); @@ -82,9 +81,10 @@ bool JsonUtils::ReadFileInfoJson(const std::string &filePath, nlohmann::json &js } in.seekg(0, std::ios::beg); - jsonBuf = nlohmann::json::parse(in, nullptr, false); + std::string fileContent((std::istreambuf_iterator(in)), std::istreambuf_iterator()); in.close(); - if (jsonBuf.is_discarded()) { + jsonBuf = cJSON_Parse(fileContent.c_str()); + if (jsonBuf == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bad profile file"); return false; } @@ -92,10 +92,11 @@ bool JsonUtils::ReadFileInfoJson(const std::string &filePath, nlohmann::json &js return true; } -bool JsonUtils::IsEqual(nlohmann::json &jsonObject, const std::string &key, const std::string &value, bool checkEmpty) +bool JsonUtils::IsEqual(cJSON *jsonObject, const std::string &key, const std::string &value, bool checkEmpty) { - if (jsonObject.contains(key) && jsonObject[key].is_string()) { - std::string jsonValue = jsonObject.at(key).get(); + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item != nullptr && cJSON_IsString(item)) { + std::string jsonValue = item->valuestring; if (checkEmpty && !jsonValue.empty() && jsonValue != value) { return false; } else if (value != jsonValue) { @@ -105,22 +106,40 @@ bool JsonUtils::IsEqual(nlohmann::json &jsonObject, const std::string &key, cons return true; } -bool JsonUtils::IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value) +bool JsonUtils::IsEqual(cJSON *jsonObject, const std::string &key, int32_t value) { - if (jsonObject.contains(key) && jsonObject[key].is_number()) { - if (value != jsonObject.at(key).get()) { + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item != nullptr && cJSON_IsNumber(item)) { + int32_t jsonValue = static_cast(item->valuedouble); + if (value != jsonValue) { return false; } } return true; } -std::optional JsonUtils::JsonToOptionalBool(const nlohmann::json &jsonObject, const std::string &key) +std::optional JsonUtils::JsonToOptionalBool(const cJSON *jsonObject, const std::string &key) { - if (jsonObject.contains(key) && jsonObject[key].is_boolean()) { - return jsonObject[key].get(); + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (item != nullptr && cJSON_IsBool(item)) { + return item->type == cJSON_True ? true : false; } return std::nullopt; } + +std::string JsonUtils::ToString(const cJSON *jsonObject) +{ + if (jsonObject == nullptr) { + return {}; + } + char *str = cJSON_PrintUnformatted(jsonObject); + if (str == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY_SIM, "create json string failed"); + return {}; + } + std::string jsonStr(str); + cJSON_free(str); + return jsonStr; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/dataobsmgr/BUILD.gn b/services/dataobsmgr/BUILD.gn index db27dae56ae4df55983b31858c9fd5d28fc0baa3..3ff3d3072b5958c125109bd6cbddb168c4760c0f 100644 --- a/services/dataobsmgr/BUILD.gn +++ b/services/dataobsmgr/BUILD.gn @@ -57,7 +57,6 @@ ohos_shared_library("dataobsms") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", - "json:nlohmann_json_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] @@ -100,7 +99,6 @@ ohos_static_library("dataobsms_static") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", - "json:nlohmann_json_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/quickfixmgr/include/quick_fix_manager_apply_task.h b/services/quickfixmgr/include/quick_fix_manager_apply_task.h index ee2cf72cd2fec47b5a4fd8665f9e96183ceed885..d9c78b5c4eb3494c95fce519363468511f01dbe8 100644 --- a/services/quickfixmgr/include/quick_fix_manager_apply_task.h +++ b/services/quickfixmgr/include/quick_fix_manager_apply_task.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_APPLY_TASK_H #include "app_mgr_interface.h" +#include "cJSON.h" #include "event_handler.h" #include "quick_fix_result_info.h" #include "quick_fix/quick_fix_manager_interface.h" @@ -44,7 +45,7 @@ public: void HandlePatchDeleted(); bool SetQuickFixInfo(const std::shared_ptr &result); - bool ExtractQuickFixDataFromJson(nlohmann::json& resultJson); + bool ExtractQuickFixDataFromJson(cJSON *resultJson); bool GetRunningState(); void RemoveTimeoutTask(); diff --git a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp index 86d3df61dedc32091e3f3a4f346294cb7a5f116d..c3160f615364bb5ce708fe8c563bb1d25e8b6e23 100644 --- a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp @@ -531,69 +531,79 @@ void QuickFixManagerApplyTask::RemoveTimeoutTask() eventHandler_->RemoveTask(TIMEOUT_TASK_NAME); } -bool QuickFixManagerApplyTask::ExtractQuickFixDataFromJson(nlohmann::json& resultJson) +bool QuickFixManagerApplyTask::ExtractQuickFixDataFromJson(cJSON *resultJson) { - if (!resultJson.contains(QUICK_FIX_BUNDLE_NAME) || !resultJson.at(QUICK_FIX_BUNDLE_NAME).is_string()) { + cJSON *bundleNameItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_BUNDLE_NAME); + if (bundleNameItem == nullptr || !cJSON_IsString(bundleNameItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid bundleName"); return false; } - bundleName_ = resultJson.at(QUICK_FIX_BUNDLE_NAME).get(); + bundleName_ = bundleNameItem->valuestring; - if (!resultJson.contains(QUICK_FIX_BUNDLE_VERSION_CODE) || - !resultJson.at(QUICK_FIX_BUNDLE_VERSION_CODE).is_number()) { + cJSON *bundleVersionCodeItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_BUNDLE_VERSION_CODE); + if (bundleVersionCodeItem == nullptr || !cJSON_IsNumber(bundleVersionCodeItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid bundle version code"); return false; } - bundleVersionCode_ = resultJson.at(QUICK_FIX_BUNDLE_VERSION_CODE).get(); + bundleVersionCode_ = static_cast(bundleVersionCodeItem->valuedouble); - if (!resultJson.contains(QUICK_FIX_PATCH_VERSION_CODE) || - !resultJson.at(QUICK_FIX_PATCH_VERSION_CODE).is_number()) { + cJSON *patchVersionCodeItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_PATCH_VERSION_CODE); + if (patchVersionCodeItem == nullptr || !cJSON_IsNumber(patchVersionCodeItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid patch version code"); return false; } - patchVersionCode_ = resultJson.at(QUICK_FIX_PATCH_VERSION_CODE).get(); + patchVersionCode_ = static_cast(patchVersionCodeItem->valuedouble); - if (!resultJson.contains(QUICK_FIX_IS_SO_CONTAINED) || !resultJson.at(QUICK_FIX_IS_SO_CONTAINED).is_boolean()) { + cJSON *isSoContainedItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_IS_SO_CONTAINED); + if (isSoContainedItem == nullptr || !cJSON_IsBool(isSoContainedItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid so status"); return false; } - isSoContained_ = resultJson.at(QUICK_FIX_IS_SO_CONTAINED).get(); + isSoContained_ = isSoContainedItem->type == cJSON_True ? true : false; - if (!resultJson.contains(QUICK_FIX_TYPE) || !resultJson.at(QUICK_FIX_TYPE).is_number()) { + cJSON *typeItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_TYPE); + if (typeItem == nullptr || !cJSON_IsNumber(typeItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid quickfix type"); return false; } - type_ = static_cast(resultJson.at(QUICK_FIX_TYPE).get()); + type_ = static_cast(static_cast(typeItem->valuedouble)); return true; } bool QuickFixManagerApplyTask::SetQuickFixInfo(const std::shared_ptr &result) { - auto resultJson = nlohmann::json::parse(result->ToString(), nullptr, false); - if (resultJson.is_discarded()) { + cJSON *resultJson = cJSON_Parse(result->ToString().c_str()); + if (resultJson == nullptr) { TAG_LOGE(AAFwkTag::QUICKFIX, "failed to parse json sting"); return false; } if (ExtractQuickFixDataFromJson(resultJson) != true) { + cJSON_Delete(resultJson); return false; } if (type_ != AppExecFwk::QuickFixType::PATCH && type_ != AppExecFwk::QuickFixType::HOT_RELOAD) { TAG_LOGE(AAFwkTag::QUICKFIX, "quick fix type invalid"); + cJSON_Delete(resultJson); return false; } - if (!resultJson.contains(QUICK_FIX_MODULE_NAME) || !resultJson.at(QUICK_FIX_MODULE_NAME).is_array()) { + cJSON *moduleNameItem = cJSON_GetObjectItem(resultJson, QUICK_FIX_MODULE_NAME); + if (moduleNameItem == nullptr || !cJSON_IsArray(moduleNameItem)) { TAG_LOGE(AAFwkTag::QUICKFIX, "Invalid moduleName"); + cJSON_Delete(resultJson); return false; } moduleNames_.clear(); - auto size = resultJson[QUICK_FIX_MODULE_NAME].size(); - for (size_t i = 0; i < size; i++) { - if (resultJson[QUICK_FIX_MODULE_NAME][i].is_string()) { - moduleNames_.emplace_back(resultJson[QUICK_FIX_MODULE_NAME][i]); + int size = cJSON_GetArraySize(moduleNameItem); + for (int i = 0; i < size; i++) { + cJSON *subModuleNameItem = cJSON_GetArrayItem(moduleNameItem, i); + if (subModuleNameItem != nullptr && cJSON_IsString(subModuleNameItem)) { + std::string moduleName = subModuleNameItem->valuestring; + moduleNames_.emplace_back(moduleName); } } + cJSON_Delete(resultJson); TAG_LOGI(AAFwkTag::QUICKFIX, "bundleName: %{public}s, bundleVersion: %{public}d, patchVersion: %{public}d," "soContained: %{public}d, ""type: %{public}d", bundleName_.c_str(), bundleVersionCode_, patchVersionCode_, isSoContained_, static_cast(type_)); diff --git a/test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn b/test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn index ed4f64e3b8a9260418a81023cdebf7d6a3d93691..be7e3a267f03c43113244ea8cf9ffe8a03cd4855 100644 --- a/test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("AbilityAppDebugManagerFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", diff --git a/test/fuzztest/abilityautostartupdatamanager_fuzzer/abilityautostartupdatamanager_fuzzer.cpp b/test/fuzztest/abilityautostartupdatamanager_fuzzer/abilityautostartupdatamanager_fuzzer.cpp index 7baf75ac4814d7a76c272a83e485181c144ed1ab..f8ada406c27d1c80f5e06c35dd04280482f1893c 100644 --- a/test/fuzztest/abilityautostartupdatamanager_fuzzer/abilityautostartupdatamanager_fuzzer.cpp +++ b/test/fuzztest/abilityautostartupdatamanager_fuzzer/abilityautostartupdatamanager_fuzzer.cpp @@ -68,7 +68,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) abilityAutoStartupDataManager->ConvertAutoStartupStatusFromValue(value, isAutoStartup, isEdmForce); abilityAutoStartupDataManager->ConvertAutoStartupDataToKey(info); abilityAutoStartupDataManager->ConvertAutoStartupInfoFromKeyAndValue(key, value); - nlohmann::json jsonObject; std::string keys(data, size); std::string values(data, size); bool checkEmpty = *data % ENABLE; diff --git a/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/BUILD.gn index 48fe044932b40310f8be41b16aea5fed5243f93d..4667abcae116bc819643e0ef363c4942a5251c16 100755 --- a/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/BUILD.gn @@ -60,13 +60,13 @@ ohos_fuzztest("AbilityAutoStartupDataManagerbFuzzTest") { "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", "input:libmmi-client", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "napi:ace_napi", "os_account:os_account_innerkits", diff --git a/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/abilityautostartupdatamanagerb_fuzzer.cpp b/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/abilityautostartupdatamanagerb_fuzzer.cpp index d59ec4339f128b0410620438c54f8b34f96779c0..67bb1d56a9c7df2bf97cd228c575d54e4dcaa120 100755 --- a/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/abilityautostartupdatamanagerb_fuzzer.cpp +++ b/test/fuzztest/abilityautostartupdatamanagerb_fuzzer/abilityautostartupdatamanagerb_fuzzer.cpp @@ -99,7 +99,8 @@ void AbilityAutoStartupDataManagerFuzztest1(bool boolParam, std::string &stringP dataMgr->ConvertAutoStartupInfoFromKeyAndValue(key2, value2Illegal); dataMgr->ConvertAutoStartupInfoFromKeyAndValue(key2, value3); - nlohmann::json jsonObject = nlohmann::json::parse(key1.ToString(), nullptr, false); + cJSON *jsonObject = cJSON_Parse(key1.ToString().c_str()); + cJSON_Delete(jsonObject); dataMgr->IsEqual(key1, info); dataMgr->IsEqual(key2, info); dataMgr->IsEqual(key1Illegal, info); diff --git a/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn b/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn index 0cd33d13cc8d1d73d43b2f47763cf03c9222c8e4..81bdd15b9f542957d8b8424a1447f291a9c67755 100755 --- a/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn @@ -47,6 +47,7 @@ ohos_fuzztest("AbilityEventHandlerFuzzTest") { "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", "//third_party/jsoncpp:jsoncpp", ] @@ -55,6 +56,7 @@ ohos_fuzztest("AbilityEventHandlerFuzzTest") { "ability_base:zuri", "bundle_framework:appexecfwk_base", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp index 5aa50d5c533790b731d204cdf6a2b5c4d2836b83..6c5cd810d816fd08d0afdf367638582a5feefb2d 100755 --- a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp +++ b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp @@ -168,11 +168,11 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AmsConfigurationParameter::GetInstance().GetMaxRestartNum(true); AmsConfigurationParameter::GetInstance().GetDeviceType(); AmsConfigurationParameter::GetInstance().GetBootAnimationTimeoutTime(); - nlohmann::json Object; + cJSON *Object = cJSON_CreateObject(); AmsConfigurationParameter::GetInstance().LoadAppConfigurationForStartUpService(Object); AmsConfigurationParameter::GetInstance().LoadAppConfigurationForMemoryThreshold(Object); AmsConfigurationParameter::GetInstance().LoadSystemConfiguration(Object); - + cJSON_Delete(Object); return true; } } diff --git a/test/fuzztest/abilitymgrinsightintentexecutemanager_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrinsightintentexecutemanager_fuzzer/BUILD.gn index 7b83bb29563b2fe8ea1a281645a8ca5dabe2d01f..99bf9aeaf011738f87cbdad084b41d630e0c26fa 100644 --- a/test/fuzztest/abilitymgrinsightintentexecutemanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrinsightintentexecutemanager_fuzzer/BUILD.gn @@ -63,6 +63,7 @@ ohos_fuzztest("AbilityMgrInsightIntentExecuteManagerFuzzTest") { "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", ] @@ -76,6 +77,7 @@ ohos_fuzztest("AbilityMgrInsightIntentExecuteManagerFuzzTest") { "bundle_framework:appexecfwk_core", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", "ffrt:libffrt", diff --git a/test/fuzztest/abilitymgrinsightintentutils_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrinsightintentutils_fuzzer/BUILD.gn index 1878dc4b04f7998c233a2ee8d3da7ca901871961..7200739257cef2e6ed6ccfa1d69e398b2c03ea2d 100644 --- a/test/fuzztest/abilitymgrinsightintentutils_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrinsightintentutils_fuzzer/BUILD.gn @@ -58,6 +58,7 @@ ohos_fuzztest("AbilityMgrInsightIntentUtilsFuzzTest") { "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", ] diff --git a/test/fuzztest/abilitymgrrdbparserutil_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrrdbparserutil_fuzzer/BUILD.gn index be18a998b05a85f86d3436fa737506b25fd9e52e..f2fc435572b7b8705b45871d98529e4183b47f29 100644 --- a/test/fuzztest/abilitymgrrdbparserutil_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrrdbparserutil_fuzzer/BUILD.gn @@ -58,6 +58,7 @@ ohos_fuzztest("AbilityMgrRdbParserUtilFuzzTest") { "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", ] @@ -66,6 +67,7 @@ ohos_fuzztest("AbilityMgrRdbParserUtilFuzzTest") { "ability_base:zuri", "ability_runtime:ability_deps_wrapper", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "dsoftbus:softbus_client", @@ -73,7 +75,6 @@ ohos_fuzztest("AbilityMgrRdbParserUtilFuzzTest") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "libjpeg-turbo:turbojpeg", "napi:ace_napi", diff --git a/test/fuzztest/abilitymgrrdbparserutil_fuzzer/abilitymgrrdbparserutil_fuzzer.cpp b/test/fuzztest/abilitymgrrdbparserutil_fuzzer/abilitymgrrdbparserutil_fuzzer.cpp index feb86954571165f80c15dc5c97715ff63eb803e1..9b6cd61522266e0823b022269c07b566516aafd5 100644 --- a/test/fuzztest/abilitymgrrdbparserutil_fuzzer/abilitymgrrdbparserutil_fuzzer.cpp +++ b/test/fuzztest/abilitymgrrdbparserutil_fuzzer/abilitymgrrdbparserutil_fuzzer.cpp @@ -71,9 +71,10 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) instance.ParsePreInstallAbilityConfig(jsonStr, list); std::vector rootDirList; instance.GetPreInstallRootDirList(rootDirList); - nlohmann::json jsonBuf; + cJSON *jsonBuf = nullptr; instance.ReadFileIntoJson(jsonStr, jsonBuf); instance.FilterInfoFromJson(jsonBuf, list); + cJSON_Delete(jsonBuf); return true; } } diff --git a/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn index ce5b88b18bb347d8f0ba57efe1490949bd479fd2..bb60c91c8f05f9b5cf92fd43899665209db4c2b1 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("AbilityMgrRestFuzzTest") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:app_util", ] external_deps = [ @@ -52,6 +53,7 @@ ohos_fuzztest("AbilityMgrRestFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp index c4493e5bdc27f8aa0e310ce37138b1767b28de09..90b69fbe0e56cd9beee205ffd2ff344d66a4dd00 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp +++ b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp @@ -64,10 +64,12 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) innerMissionInfo.FromJsonStr(jsonStr); std::vector info; innerMissionInfo.Dump(info); - nlohmann::json value; + cJSON *value = cJSON_CreateObject(); std::string node(data, size); JsonType jsonType = JsonType::STRING; - return innerMissionInfo.CheckJsonNode(value, node, jsonType); + bool result = innerMissionInfo.CheckJsonNode(value, node, jsonType); + cJSON_Delete(value); + return result; } } diff --git a/test/fuzztest/deeplinkreserveconfig_fuzzer/BUILD.gn b/test/fuzztest/deeplinkreserveconfig_fuzzer/BUILD.gn index f87728545349120d60ceb4ef882e16c76b4e80eb..69adae46ee7755b5d897421533c8e35cee45457a 100644 --- a/test/fuzztest/deeplinkreserveconfig_fuzzer/BUILD.gn +++ b/test/fuzztest/deeplinkreserveconfig_fuzzer/BUILD.gn @@ -30,9 +30,15 @@ ohos_fuzztest("DeepLinkReserveConfigFuzzTest") { configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] cflags = [] - deps = [ "${ability_runtime_services_path}/abilitymgr:abilityms" ] + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + ] } ############################################################################### diff --git a/test/fuzztest/deeplinkreserveconfig_fuzzer/deeplinkreserveconfig_fuzzer.cpp b/test/fuzztest/deeplinkreserveconfig_fuzzer/deeplinkreserveconfig_fuzzer.cpp index b95b81c85242960ffd2d1d4c8af31f93dd51993d..a0a008b4d2529212bc6a1d9760e4bf939481f36c 100644 --- a/test/fuzztest/deeplinkreserveconfig_fuzzer/deeplinkreserveconfig_fuzzer.cpp +++ b/test/fuzztest/deeplinkreserveconfig_fuzzer/deeplinkreserveconfig_fuzzer.cpp @@ -25,7 +25,6 @@ #include "deeplink_reserve_config.h" #undef private -using json = nlohmann::json; using namespace OHOS::AAFwk; namespace OHOS { namespace { @@ -86,23 +85,24 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) reservedUri.pathRegex = strParam; deepLinkReserveConfig.IsUriMatched(reservedUri, link); std::vector uriList; - json jsonUriObject; - jsonUriObject["SCHEME_NAME"] = SCHEME_NAME; + cJSON *jsonUriObject = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonUriObject, "SCHEME_NAME", SCHEME_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["HOST_NAME"] = HOST_NAME; + cJSON_AddStringToObject(jsonUriObject, "HOST_NAME", HOST_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["PORT_NAME"] = PORT_NAME; + cJSON_AddStringToObject(jsonUriObject, "PORT_NAME", PORT_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["PATH_NAME"] = PATH_NAME; + cJSON_AddStringToObject(jsonUriObject, "PATH_NAME", PATH_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["PATH_START_WITH_NAME"] = PATH_START_WITH_NAME; + cJSON_AddStringToObject(jsonUriObject, "PATH_START_WITH_NAME", PATH_START_WITH_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["PATH_REGEX_NAME"] = PATH_REGEX_NAME; + cJSON_AddStringToObject(jsonUriObject, "PATH_REGEX_NAME", PATH_REGEX_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["TYPE_NAME"] = TYPE_NAME; + cJSON_AddStringToObject(jsonUriObject, "TYPE_NAME", TYPE_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); - jsonUriObject["UTD_NAME"] = UTD_NAME; + cJSON_AddStringToObject(jsonUriObject, "UTD_NAME", UTD_NAME.c_str()); deepLinkReserveConfig.LoadReservedUrilItem(jsonUriObject, uriList); + cJSON_Delete(jsonUriObject); return true; } @@ -110,22 +110,44 @@ bool DoSomethingInterestingWithMyAPIOne(const char* data, size_t size) { auto &deepLinkReserveConfig1 = DeepLinkReserveConfig::GetInstance(); std::string filePath(data, size); - json jsonBuf; + cJSON *jsonBuf = nullptr; deepLinkReserveConfig1.ReadFileInfoJson(filePath, jsonBuf); - json object; + cJSON_Delete(jsonBuf); + + cJSON *object = cJSON_CreateObject(); deepLinkReserveConfig1.LoadReservedUriList(object); - object["DEEPLINK_RESERVED_URI_NAME"] = DEEPLINK_RESERVED_URI_NAME; + + cJSON_AddStringToObject(object, "DEEPLINK_RESERVED_URI_NAME", DEEPLINK_RESERVED_URI_NAME.c_str()); deepLinkReserveConfig1.LoadReservedUriList(object); + int32_t userId = static_cast(GetU32Data(data)); - object["BUNDLE_NAME"] = userId; + cJSON_AddNumberToObject(object, "BUNDLE_NAME", userId); deepLinkReserveConfig1.LoadReservedUriList(object); - object["BUNDLE_NAME"] = BUNDLE_NAME; + + cJSON *oldBundleNameItem = cJSON_GetObjectItem(object, "BUNDLE_NAME"); + if (oldBundleNameItem != nullptr) { + cJSON_DetachItemViaPointer(object, oldBundleNameItem); + cJSON_Delete(oldBundleNameItem); + } + cJSON_AddStringToObject(object, "BUNDLE_NAME", BUNDLE_NAME.c_str()); deepLinkReserveConfig1.LoadReservedUriList(object); - json uriArray = { "uri1", "uri2", "uri3" }; - object["URIS_NAME"] = uriArray; + + cJSON *uriArray = cJSON_CreateArray(); + cJSON_AddItemToArray(uriArray, cJSON_CreateString("uri1")); + cJSON_AddItemToArray(uriArray, cJSON_CreateString("uri2")); + cJSON_AddItemToArray(uriArray, cJSON_CreateString("uri3")); + cJSON_AddItemToObject(object, "URIS_NAME", uriArray); deepLinkReserveConfig1.LoadReservedUriList(object); - object["URIS_NAME"] = URIS_NAME; + + cJSON *oldUriNameItem = cJSON_GetObjectItem(object, "URIS_NAME"); + if (oldUriNameItem != nullptr) { + cJSON_DetachItemViaPointer(object, oldUriNameItem); + cJSON_Delete(oldUriNameItem); + } + cJSON_AddStringToObject(object, "URIS_NAME", URIS_NAME.c_str()); deepLinkReserveConfig1.LoadReservedUriList(object); + + cJSON_Delete(object); return true; } } diff --git a/test/fuzztest/extensionconfig_fuzzer/BUILD.gn b/test/fuzztest/extensionconfig_fuzzer/BUILD.gn index 3fd0cd5a50a96ef0a6dc6be959db50b221fb537d..e7ef57b2eb8245870bbfc6c1c2e28aa528c2f051 100644 --- a/test/fuzztest/extensionconfig_fuzzer/BUILD.gn +++ b/test/fuzztest/extensionconfig_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("ExtensionConfigFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "ffrt:libffrt", diff --git a/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp index baeff74603d51c210fcd72720c79fb259935f714..1bb6f0caee374776689f4d9ce539819783e3380c 100644 --- a/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp +++ b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp @@ -61,7 +61,7 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) extensionConfig->IsExtensionStartServiceEnableNew(strParam, strParam); extensionConfig->IsExtensionStartThirdPartyAppEnableNew(strParam, strParam); extensionConfig->IsExtensionStartDefaultEnable(strParam, strParam); - nlohmann::json object; + cJSON *object = cJSON_CreateObject(); extensionConfig->LoadExtensionConfig(object); extensionConfig->ReadFileInfoJson(strParam, object); extensionConfig->GetExtensionConfigPath(); @@ -70,6 +70,7 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) extensionConfig->LoadExtensionServiceBlockedList(object, strParam); extensionConfig->LoadExtensionAbilityAccess(object, strParam); extensionConfig->CheckExtensionUriValid(strParam); + cJSON_Delete(object); return true; } } // namespace OHOS diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 3161ba06e735c383313582b78e9dd95e02329e33..3c81e50811afcc550417d93872b5d1ad58abada2 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -26,7 +26,6 @@ config("aafwk_module_test_config") { include_dirs = [ "${ability_runtime_test_path}/moduletest/mock/include", - "//third_party/jsoncpp/include", ] } @@ -73,7 +72,6 @@ group("moduletest") { external_deps = [ "icu:shared_icuuc", - "jsoncpp:jsoncpp", ] } } diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index b4490926194952e358e5ce407f1018596267669a..0bd733d6898be342f2c99e9afc949d959070ac88 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -81,7 +81,6 @@ ohos_moduletest("ability_moduletest") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", @@ -142,8 +141,6 @@ ohos_moduletest("ability_conetxt_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -184,7 +181,6 @@ ohos_moduletest("ability_thread_call_request_module_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "samgr:samgr_proxy", ] @@ -231,8 +227,6 @@ ohos_moduletest("data_ability_operation_moduletest") { "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -289,7 +283,6 @@ ohos_moduletest("data_ability_helper_module_test") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -336,7 +329,6 @@ ohos_moduletest("ability_post_event_timeout_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index d8fd1131d1588aa2c078e7113894722c28368a57..afd91bca7acfadffe2df0ba8d49cfdc0fd364614 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_moduletest("call_ability_service_module_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "safwk:api_cache_manager", ] diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 5d190174c84dc3491eded7b33cb172f46f3de7d8..05566e91b2ae99c57edc58f45780bb0ce2f45acf 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -64,7 +64,6 @@ ohos_source_set("appmgr_mst_source") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", ] public_external_deps = [ diff --git a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp index 2c746036a49d81a4a0a9d9c68bf9b026f8fca17b..8093d4d422ac89d61cede9723c1c4066a5550102 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp +++ b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp b/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp index 965510d9812259494c976de33ee566981ef01432..772adda7ebd5a7034d4456bc8ed777dca85d9ed5 100644 --- a/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp +++ b/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp @@ -88,13 +88,18 @@ ErrCode UIServiceMgrClient::ShowDialog(const std::string& name, const std::strin isCallBack_ = false; if (code_ == EVENT_MULT_APP_CHOOSE) { params_ = params; - auto jsonObj = nlohmann::json::parse(params, nullptr, false); - auto hapListObj = nlohmann::json::array(); - hapListObj = jsonObj["hapList"]; - auto aObj = hapListObj[0]; - std::string callbackParams = aObj["bundle"].dump() + ";" + aObj["ability"].dump(); - callback(0, EVENT_CHOOSE_CODE, callbackParams); - return ERR_OK; + cJSON *jsonObj = cJSON_Parse(params.c_str()); + cJSON *hapListObj = cJSON_GetObjectItem(jsonObj, "hapList"); + if (cJSON_GetArraySize > 0) { + cJSON *aObj = cJSON_GetArrayItem(hapListObj, 0); + cJSON *bundleItem = cJSON_GetObjectItem(aObj, "bundle"); + cJSON *abilityItem = cJSON_GetObjectItem(aObj, "ability"); + std::string bundle = bundleItem->valuestring; + std::string ability = abilityItem->valuestring; + std::string callbackParams = bundle + ";" + ability; + callback(0, EVENT_CHOOSE_CODE, callbackParams); + return ERR_OK; + } } if (code_ == EVENT_MULT_APP_CLOSE) { diff --git a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp index 82cb2a1de86dcbbe81b7f9aad2658b087be196de..02bd83ca5ddb98ac835816ee5f1e3c44a5d8a225 100644 --- a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp +++ b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/test/moduletest/start_ability_implicit_module_test/BUILD.gn b/test/moduletest/start_ability_implicit_module_test/BUILD.gn index a6197b7bb989cfe75498b35c06a15a2ee8c6fb6a..6d0465928e350b60fbd04e36395b32084ff70d94 100644 --- a/test/moduletest/start_ability_implicit_module_test/BUILD.gn +++ b/test/moduletest/start_ability_implicit_module_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_moduletest("start_ability_implicit_module_test") { "${ace_engine_path}/adapter/ohos/services/uiservice/include", "${windowmanager_path}/interfaces/innerkits", "${multimodalinput_path}/interfaces/native/innerkits/event/include", - "//third_party/jsoncpp/include", ] sources = [ "start_ability_implicit_module_test.cpp" ] @@ -60,7 +59,6 @@ ohos_moduletest("start_ability_implicit_module_test") { "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", "//third_party/icu/icu4c:shared_icuuc", - "//third_party/jsoncpp:jsoncpp", ] if (ability_runtime_graphics) { @@ -91,6 +89,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 76f6c6c462ad5af271f23131913a2ae20234c4d2..3e8ea0e4880aaea4f9679e23a2cb176dbc26a632 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -79,7 +79,6 @@ ohos_source_set("appmgr_test_source") { "hitrace:hitrace_meter", "i18n:intl_util", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "samgr:samgr_proxy", @@ -259,7 +258,6 @@ ohos_source_set("abilityms_test_source") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/unittest/ability_bundle_event_callback_test/BUILD.gn b/test/unittest/ability_bundle_event_callback_test/BUILD.gn index b59638976588616ce35a4eea9b3865b2149e87ef..6ff5c9bbf8c102c810d771b36b8f604fb721673c 100644 --- a/test/unittest/ability_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/ability_bundle_event_callback_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ability_bundle_event_callback_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", diff --git a/test/unittest/ability_debug_response_proxy_test/BUILD.gn b/test/unittest/ability_debug_response_proxy_test/BUILD.gn index be3c9c4a66c6d74b25e2e58daaaa3eec381e1256..2e8d40a8e2de1db492ebe0d46f2551ffa776a50a 100644 --- a/test/unittest/ability_debug_response_proxy_test/BUILD.gn +++ b/test/unittest/ability_debug_response_proxy_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("ability_debug_response_proxy_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } diff --git a/test/unittest/ability_debug_response_stub_test/BUILD.gn b/test/unittest/ability_debug_response_stub_test/BUILD.gn index 3d1481bf29740f46aaf112942d1f416c1b58c2ea..4d7bb1cd4d9e62389646a772f3615a83b47f193a 100644 --- a/test/unittest/ability_debug_response_stub_test/BUILD.gn +++ b/test/unittest/ability_debug_response_stub_test/BUILD.gn @@ -48,7 +48,6 @@ ohos_unittest("ability_debug_response_stub_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } diff --git a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp index 51c1ff047189c3d992d38ee95fbda1d8e981673f..69271e2fe6dd856d14533435dad75f3435413065 100644 --- a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp +++ b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp @@ -24,7 +24,6 @@ using namespace testing; using namespace testing::ext; -using json = nlohmann::json; namespace { constexpr const char* EXTENSION_CONFIG_NAME = "extension_config_name"; constexpr const char* EXTENSION_TYPE_NAME = "extension_type_name"; @@ -66,8 +65,9 @@ void AbilityExtensionConfigTest::TearDown() void AbilityExtensionConfigTest::LoadTestConfig(const std::string &configStr) { - nlohmann::json jsonConfig = nlohmann::json::parse(configStr); + cJSON *jsonConfig = cJSON_Parse(configStr.c_str()); extensionConfig_->LoadExtensionConfig(jsonConfig); + cJSON_Delete(jsonConfig); } /* @@ -92,15 +92,30 @@ HWTEST_F(AbilityExtensionConfigTest, GetExtensionConfigPath_001, TestSize.Level1 */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionServiceBlockedList_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = false; + + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, false); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; + + cJSON *item = cJSON_GetObjectItem(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG); + if (item != nullptr) { + cJSON_DetachItemViaPointer(jsOnFile, item); + cJSON_Delete(item); + } + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb"}; + + cJSON *arraysItem = cJSON_CreateArray(); + cJSON *array1Item = cJSON_CreateString("aa"); + cJSON *array2Item = cJSON_CreateString("bb"); + cJSON_AddItemToArray(arraysItem, array1Item); + cJSON_AddItemToArray(arraysItem, array2Item); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, arraysItem); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -110,14 +125,23 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionServiceBlockedList_001, TestSi */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionThirdPartyAppBlockedList_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); std::string extensionTypeName = "aa"; extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME] = false; + + cJSON_AddBoolToObject(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME, false); extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME] = true; + + cJSON *item = cJSON_GetObjectItem(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME); + if (item != nullptr) { + cJSON_DetachItemViaPointer(jsOnFile, item); + cJSON_Delete(item); + } + cJSON_AddBoolToObject(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME, true); extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -127,12 +151,16 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionThirdPartyAppBlockedList_001, */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionAutoDisconnectTime_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); + std::string extensionTypeName = "aa"; extensionConfig_->LoadExtensionAutoDisconnectTime(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_AUTO_DISCONNECT_TIME] = 100; + + cJSON_AddNumberToObject(jsOnFile, EXTENSION_AUTO_DISCONNECT_TIME, 100); extensionConfig_->LoadExtensionAutoDisconnectTime(jsOnFile, extensionTypeName); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -142,15 +170,25 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionAutoDisconnectTime_001, TestSi */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionConfig_001, TestSize.Level1) { - json jsOnFile; - json jsOnItem; - json jsOnItem2; + cJSON *jsOnFile = cJSON_CreateObject(); + + cJSON *jsOnItems = cJSON_CreateArray(); + cJSON *jsOnItem = cJSON_CreateObject(); + cJSON *jsOnItem2 = cJSON_CreateObject(); + cJSON *jsOnItem3 = cJSON_CreateObject(); extensionConfig_->LoadExtensionConfig(jsOnFile); - jsOnItem[EXTENSION_TYPE_NAME] = "aa"; - jsOnItem2[EXTENSION_TYPE_NAME] = "bb"; - jsOnFile[EXTENSION_CONFIG_NAME] = {jsOnItem, jsOnItem2, "cc"}; + + cJSON_AddStringToObject(jsOnItem, EXTENSION_TYPE_NAME, "aa"); + cJSON_AddStringToObject(jsOnItem2, EXTENSION_TYPE_NAME, "bb"); + cJSON_AddStringToObject(jsOnItem3, EXTENSION_TYPE_NAME, "cc"); + cJSON_AddItemToArray(jsOnItems, jsOnItem); + cJSON_AddItemToArray(jsOnItems, jsOnItem2); + cJSON_AddItemToArray(jsOnItems, jsOnItem3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_CONFIG_NAME, jsOnItems); extensionConfig_->LoadExtensionConfig(jsOnFile); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -190,14 +228,22 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_002, TestSize */ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_003, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); auto extType = "form"; - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb", "/bundle/module/ability"}; + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); + cJSON *items = cJSON_CreateArray(); + cJSON *item1 = cJSON_CreateString("aa"); + cJSON *item2 = cJSON_CreateString("bb"); + cJSON *item3 = cJSON_CreateString("/bundle/module/ability"); + cJSON_AddItemToArray(items, item1); + cJSON_AddItemToArray(items, item2); + cJSON_AddItemToArray(items, item3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, items); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, extType); // uri not valid bool enable = extensionConfig_->IsExtensionStartServiceEnable(extType, "bb"); EXPECT_EQ(enable, true); + cJSON_Delete(jsOnFile); } /* @@ -207,14 +253,22 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_003, TestSize */ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_004, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); auto extType = "form"; - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb", "/bundle/module/ability"}; + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); + cJSON *items = cJSON_CreateArray(); + cJSON *item1 = cJSON_CreateString("aa"); + cJSON *item2 = cJSON_CreateString("bb"); + cJSON *item3 = cJSON_CreateString("/bundle/module/ability"); + cJSON_AddItemToArray(items, item1); + cJSON_AddItemToArray(items, item2); + cJSON_AddItemToArray(items, item3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, items); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, extType); // uri is valid bool enable = extensionConfig_->IsExtensionStartServiceEnable(extType, "/bundle/module/ability"); EXPECT_EQ(enable, false); + cJSON_Delete(jsOnFile); } /* @@ -224,9 +278,10 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_004, TestSize */ HWTEST_F(AbilityExtensionConfigTest, ReadFileInfoJson_001, TestSize.Level1) { - nlohmann::json jsOne; + cJSON *jsOne = nullptr; auto result = extensionConfig_->ReadFileInfoJson("d://dddd", jsOne); EXPECT_EQ(result, false); + cJSON_Delete(jsOne); } /* diff --git a/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp b/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp index 8757e1e182c751a9597fe941e7ef7ada141040cd..a1c7c04ca95ca0f593ccac81e55a59db7d9225d3 100644 --- a/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp +++ b/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp @@ -153,8 +153,11 @@ HWTEST_F(AbilityMgrServiceDialogTest, AbilityMgrServiceDialog_0500, TestSize.Lev }; std::vector dialogAppInfos = { dialogAppInfo }; auto params = systemDialogScheduler_->GetSelectorParams(dialogAppInfos); - nlohmann::json jsonObj = nlohmann::json::parse(params); - EXPECT_EQ(jsonObj["hapList"].size(), 1); + cJSON *jsonObj = cJSON_Parse(params.c_str()); + cJSON *hapListItem = cJSON_GetObjectItem(jsonObj, "hapList"); + EXPECT_TRUE(hapListItem != nullptr && cJSON_IsArray(hapListItem)); + EXPECT_EQ(cJSON_GetArraySize(hapListItem), 1); + cJSON_Delete(jsonObj); TAG_LOGI(AAFwkTag::TEST, "AbilityMgrServiceDialog_0500 end"); } diff --git a/test/unittest/ability_manager_service_fourth_test/BUILD.gn b/test/unittest/ability_manager_service_fourth_test/BUILD.gn index e1d04cc859261b2dbdcc526826679d0cec394796..51875e02867bcc8af3e261275b5f1ab287c5b358 100644 --- a/test/unittest/ability_manager_service_fourth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourth_test/BUILD.gn @@ -49,6 +49,7 @@ ohos_unittest("ability_manager_service_fourth_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_connect_callback_stub.cpp", @@ -107,6 +108,7 @@ ohos_unittest("ability_manager_service_fourth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_dataability", "safwk:api_cache_manager", diff --git a/test/unittest/ability_manager_service_mock_test/BUILD.gn b/test/unittest/ability_manager_service_mock_test/BUILD.gn index 103a35904541dbbec0c24d0fd078b0b6c71ba62f..42c5adb7d3d95b5837a3eeafc04bafbb47352376 100644 --- a/test/unittest/ability_manager_service_mock_test/BUILD.gn +++ b/test/unittest/ability_manager_service_mock_test/BUILD.gn @@ -111,7 +111,6 @@ ohos_unittest("ability_manager_service_mock_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "qos_manager:concurrent_task_client", diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 045ec42a83b1a48eae0f131dacd52d0737ec0e06..a96f458a041bb432ed808f63d5f50e96ecf14c93 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -69,6 +69,7 @@ ohos_unittest("ability_manager_service_second_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "safwk:api_cache_manager", "selinux_adapter:librestorecon", ] diff --git a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index baa53693076c0d468a4647fcb38f76b18e0f79f6..2a8f478322f558dface4954c8be63a1cf8ee5849 100644 --- a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp +++ b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp @@ -1818,7 +1818,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, ParseJsonFromBoot_001, TestSize.Level1 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest ParseJsonFromBoot_001 start"); auto abilityMs_ = std::make_shared(); const std::string file = "/etc/efficiency_manager/prevent_startability_whitelist.json"; - nlohmann::json whiteListJsonObj; abilityMs_->ParseJsonFromBoot(file); EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest ParseJsonFromBoot_001 end"); diff --git a/test/unittest/ability_manager_service_tenth_test/BUILD.gn b/test/unittest/ability_manager_service_tenth_test/BUILD.gn index 755be9065ec246f90d0091914ff0ab6f820a99e7..86eb68adaa8289f46bd8bee766ac0f530e8a929f 100644 --- a/test/unittest/ability_manager_service_tenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_tenth_test/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("ability_manager_service_tenth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "safwk:api_cache_manager", "selinux_adapter:librestorecon", diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 02ccc39f94bfae4d4f50e562317692959b24a8d0..b865454b7dee0f537b1529ff1d944c904adbc0ad 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("ability_manager_service_third_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_cache_manager.cpp", diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index d429c069a805c406a1c207c9e4b42852fb0e6e01..5612e514df8c72d23291897ca54f26e42e961ff7 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -2425,8 +2425,9 @@ HWTEST_F(AbilityManagerServiceThirdTest, ParseJsonValueFromFile_001, TestSize.Le EXPECT_NE(abilityMs_, nullptr); std::string filePath = "hello"; - nlohmann::json value; + cJSON *value = nullptr; abilityMs_->ParseJsonValueFromFile(value, filePath); + cJSON_Delete(value); } /* diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index ea88cb70833b1dc153c75a8449ddeaa01d85c014..f73eb1b9c55146b4e2d5208e5099f2892d2a6ceb 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -126,6 +126,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/inner_mission_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_utils.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", diff --git a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn index 76e492cf15f1a3dc8e134481ecaf607109010ec5..e10db0db2db2721053d92fbca43c5054e58de948 100644 --- a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn @@ -107,6 +107,7 @@ ohos_unittest("ability_manager_service_twelfth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_dataability", "safwk:api_cache_manager", diff --git a/test/unittest/ability_permission_util_test/BUILD.gn b/test/unittest/ability_permission_util_test/BUILD.gn index c095171d09468e967402fd526121dfec1e23e50c..1dff9b2b11193a3045b94d4aadc517efd4eca4fb 100644 --- a/test/unittest/ability_permission_util_test/BUILD.gn +++ b/test/unittest/ability_permission_util_test/BUILD.gn @@ -74,7 +74,6 @@ ohos_unittest("ability_permission_util_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "memory_utils:libmeminfo", diff --git a/test/unittest/ability_stage_context_test/BUILD.gn b/test/unittest/ability_stage_context_test/BUILD.gn index 73a3326a352d8c2c12fa1f2e8b6a152cb2f23006..eb360c6e93813505907a73541c9760da205e5dc5 100644 --- a/test/unittest/ability_stage_context_test/BUILD.gn +++ b/test/unittest/ability_stage_context_test/BUILD.gn @@ -60,7 +60,6 @@ ohos_unittest("ability_stage_context_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", diff --git a/test/unittest/ams_app_state_callback_test/BUILD.gn b/test/unittest/ams_app_state_callback_test/BUILD.gn index 42801229395b397b8394cd607cf01f81ff7e4ebb..71772aadcc9478e4cc92c67dce3a1699b268ec22 100644 --- a/test/unittest/ams_app_state_callback_test/BUILD.gn +++ b/test/unittest/ams_app_state_callback_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("AmsAppStateCallbackTest") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "json:nlohmann_json_static", ] } diff --git a/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn b/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn index 5ba95e059265e77e4f3ab1cebf2d7ccb18463ce5..81b565ef14b34ed23704a31a0ff0337705b2ef6e 100644 --- a/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn +++ b/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn @@ -34,6 +34,8 @@ ohos_unittest("app_exit_reason_data_manager_new_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_exit_reason_data_manager_new_test.cpp", ] @@ -47,6 +49,8 @@ ohos_unittest("app_exit_reason_data_manager_new_test") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "cJSON:cjson", + "config_policy:configpolicy_util", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", diff --git a/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp b/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp index 9aff32eaf103d67099e26975aa0560770803ca2c..13b86f37fcbce2df1c55ae401f06214b30857f9a 100644 --- a/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp +++ b/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp @@ -17,6 +17,7 @@ #include "gmock/gmock.h" #include #include +#include "cJSON.h" #define private public #define protected public #include "app_exit_reason_data_manager.h" @@ -205,10 +206,12 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro { bool withKillMsg = false; std::string killMsg = "test_value"; - nlohmann::json jsonObject = nlohmann::json{{ "kill_msg", killMsg }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObject, "kill_msg", killMsg.c_str()); AAFwk::ExitReason exitReason = {AAFwk::REASON_JS_ERROR, "Js Error."}; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); + cJSON_Delete(jsonObject); EXPECT_EQ(withKillMsg, true); } @@ -384,11 +387,13 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_SetAppExitReason HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_002, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_REASON, AAFwk::Reason::REASON_NORMAL }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_REASON.c_str(), AAFwk::Reason::REASON_NORMAL); AAFwk::ExitReason exitReason; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.reason, AAFwk::Reason::REASON_NORMAL); + cJSON_Delete(jsonObject); } /* * @@ -399,12 +404,14 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_003, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_SUB_KILL_REASON, 0 }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SUB_KILL_REASON.c_str(), 0); AAFwk::ExitReason exitReason; exitReason.subReason = -1; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.subReason, 0); + cJSON_Delete(jsonObject); } /* * @@ -415,11 +422,13 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_004, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_EXIT_MSG, "exitMsg" }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObject, JSON_KEY_EXIT_MSG.c_str(), "exitMsg"); AAFwk::ExitReason exitReason; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.exitMsg, "exitMsg"); + cJSON_Delete(jsonObject); } /* * @@ -514,17 +523,17 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertAppExitRe { std::string extensionListName = "testExtensionListName"; bool withKillMsg = true; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_REASON, AAFwk::Reason::REASON_NORMAL }}; AAFwk::ExitReason exitReason; exitReason.exitMsg = "exitMsg"; AppExecFwk::RunningProcessInfo processInfo; auto result = DelayedSingleton::GetInstance() ->ConvertAppExitReasonInfoToValueOfExtensionName(extensionListName, exitReason, processInfo, withKillMsg); std::string jsonString = result.ToString(); - jsonObject = nlohmann::json::parse(jsonString); - ASSERT_TRUE(jsonObject.contains(JSON_KEY_EXIT_MSG)); - ASSERT_TRUE(jsonObject[JSON_KEY_EXIT_MSG].is_string()); - auto exitMsg = jsonObject.at(JSON_KEY_EXIT_MSG).get(); + cJSON *jsonObject = cJSON_Parse(jsonString.c_str()); + cJSON *exitMsgItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_EXIT_MSG.c_str()); + ASSERT_TRUE(exitMsgItem != nullptr); + ASSERT_TRUE(cJSON_IsString(exitMsgItem) && exitMsgItem->type == cJSON_String); + std::string exitMsg = exitMsgItem->valuestring; EXPECT_EQ(exitMsg, exitReason.exitMsg); } } // namespace AbilityRuntime diff --git a/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn b/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn index dd01857b0cd4f4c4f0880c3e0b8db262b2433f43..9cdc8c1ca97b48dd06750550e8a4ceb9a0064890 100644 --- a/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn +++ b/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn @@ -34,6 +34,8 @@ ohos_unittest("app_exit_reason_data_manager_second_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_exit_reason_data_manager_second_test.cpp", ] @@ -47,6 +49,7 @@ ohos_unittest("app_exit_reason_data_manager_second_test") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "config_policy:configpolicy_util", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", diff --git a/test/unittest/app_mgr_service_inner_second_test/BUILD.gn b/test/unittest/app_mgr_service_inner_second_test/BUILD.gn index 4642c2ac9f2c042c325e9d23e4d0dd908d933973..e2c66ac7c893fd829786c700d9a5c6effe95e30d 100644 --- a/test/unittest/app_mgr_service_inner_second_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_second_test/BUILD.gn @@ -88,7 +88,6 @@ ohos_unittest("AppMgrServiceInnerSecondTest") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn index 6bd784b776aecc6881cd42b3f6b1a5f9a67d6f5e..01f544f3a0b9929f0ebabf91d887dccb437f37d9 100644 --- a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn @@ -80,7 +80,6 @@ ohos_unittest("app_mgr_service_inner_sixth_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn index 7522b16500de71c37a04d86b78deedf27d50af55..d7ce998940c8eec94bbf12978eae1b5b42f50766 100644 --- a/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn @@ -70,7 +70,6 @@ ohos_unittest("app_mgr_service_inner_tdd_third_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index da926badd805db9c63b51253c43ff974fdbcfd4f..a73ace4ed7a74e217cd02de54d2ae32a92033080 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("AppSpawnClientTest") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", ] diff --git a/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn b/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn index 46683c947c6c8ff94bd058cbb20c7a0b984987b1..1b2f5dafea53fd4c46f238edf86c3f3788e8aed2 100644 --- a/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn +++ b/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("assert_fault_callback_death_mgr_test") { "${ability_runtime_services_path}/abilitymgr/src/assert_fault_callback_death_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/assert_fault_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/state_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "assert_fault_callback_death_mgr_test.cpp", ] @@ -74,6 +75,7 @@ ohos_unittest("assert_fault_callback_death_mgr_test") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "ffrt:libffrt", "googletest:gmock_main", diff --git a/test/unittest/cache_process_manager_second_test/BUILD.gn b/test/unittest/cache_process_manager_second_test/BUILD.gn index 265643796ce9d3918c89f20ea845f5e5609aae3c..71c8e8c9ad850490f57d8154bfb73ce6b46189ef 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -142,8 +142,8 @@ ohos_unittest("cache_process_manager_second_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", + # "json:nlohmann_json_static", + # "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "memmgr:memmgrclient", "memory_utils:libmeminfo", diff --git a/test/unittest/cj_test_runner_object_test/BUILD.gn b/test/unittest/cj_test_runner_object_test/BUILD.gn index 9db58566e5ae24718162e46bcb6c04aff34f6a6f..12d4fde5914d5f9ca964d0d78d4d10cf9b198c1b 100644 --- a/test/unittest/cj_test_runner_object_test/BUILD.gn +++ b/test/unittest/cj_test_runner_object_test/BUILD.gn @@ -58,7 +58,6 @@ ohos_unittest("cj_test_runner_object_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/cj_test_runner_test/BUILD.gn b/test/unittest/cj_test_runner_test/BUILD.gn index 891969d72a3e67733e68d16af93d1baee100d99f..80f3ad7fc071d4259a86244fab1a7b5978b1926e 100644 --- a/test/unittest/cj_test_runner_test/BUILD.gn +++ b/test/unittest/cj_test_runner_test/BUILD.gn @@ -92,7 +92,6 @@ ohos_unittest("cj_test_runner_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "napi:cj_bind_native", "resource_management:global_resmgr", diff --git a/test/unittest/deeplink_reserve_config_test/BUILD.gn b/test/unittest/deeplink_reserve_config_test/BUILD.gn index 1a399d3cc53d3ecb5e986d6fa16fa75c30a6d9ca..583e3bbc828ac87528ce13981417a1daf19f4cba 100644 --- a/test/unittest/deeplink_reserve_config_test/BUILD.gn +++ b/test/unittest/deeplink_reserve_config_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("deeplink_reserve_config_test") { external_deps = [ "c_utils:utils", + "cJSON:cjson", "googletest:gmock_main", ] } diff --git a/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp b/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp index bd096fce00e26e265ab5042048a436f35af5e0ed..973516524767b54799367405cf6d314d8e01d6c9 100644 --- a/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp +++ b/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp @@ -56,7 +56,7 @@ HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0200, TestSi { GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 start"; DeepLinkReserveConfig deepLinkReserveConfig; - const nlohmann::json DEFAULT_CONFIG = R"( + const std::string jsonStr = R"( { "deepLinkReservedUri": [ { @@ -76,12 +76,14 @@ HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0200, TestSi } ] } - )"_json; + )"; + cJSON *DEFAULT_CONFIG = cJSON_Parse(jsonStr.c_str()); deepLinkReserveConfig.LoadReservedUriList(DEFAULT_CONFIG); std::string linkString = "http://www.xxx.com:80/pathRegex"; std::string bundleName = "just a test"; auto ans = deepLinkReserveConfig.IsLinkReserved(linkString, bundleName); EXPECT_EQ(ans, true); + cJSON_Delete(DEFAULT_CONFIG); GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 end"; } diff --git a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn index 087d5d57b38146af3db0f6aa15ffed295f768cb9..8093c24e58a7522bcd327761b6c3d4212d68a2c5 100644 --- a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn @@ -101,7 +101,6 @@ ohos_unittest("appfreeze_inner_test") { "init:libbegetutil", "input:libmmi-client", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "safwk:system_ability_fwk", diff --git a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn index ec4b5e6b4b9be3790fa638990b5a25a3775868c3..e2144d9979d5dcb78d74ce5ce697b1a32c51124a 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn @@ -85,7 +85,6 @@ ohos_unittest("appfreeze_manager_test") { "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", - "json:nlohmann_json_static", ] } diff --git a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn index 642724b8179cbc30aa40f81d78a091996deee606..d326c77672a03b4917a39e952f1d811572d8d18d 100644 --- a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn @@ -98,7 +98,6 @@ ohos_unittest("appfreeze_state_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/test/unittest/dfr_test/watchdog_test/BUILD.gn b/test/unittest/dfr_test/watchdog_test/BUILD.gn index 34307b9758d67f34b6fc64b567987bf2fc61c0fc..df1a445c991159937f5ec54fca2bd9964e5ad72e 100644 --- a/test/unittest/dfr_test/watchdog_test/BUILD.gn +++ b/test/unittest/dfr_test/watchdog_test/BUILD.gn @@ -81,7 +81,6 @@ ohos_unittest("watchdog_test") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "napi:ace_napi", ] diff --git a/test/unittest/dump_utils_test/BUILD.gn b/test/unittest/dump_utils_test/BUILD.gn index d451d9ef2a63a1b6807f4f91094c2cdf567fb1e6..8f01abafc5321207beb2de5b542bd8b2b4380bbc 100644 --- a/test/unittest/dump_utils_test/BUILD.gn +++ b/test/unittest/dump_utils_test/BUILD.gn @@ -60,7 +60,6 @@ ohos_unittest("dump_utils_test") { "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "window_manager:libdm", "window_manager:libwsutils", diff --git a/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp b/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp index f8a09da780541cb1b8fd5d5a5f81652b1d5f4db8..0111fb339d4d93000bbb3c077069f08877ed272d 100644 --- a/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp +++ b/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp @@ -74,29 +74,27 @@ bool ExtensionConfig::IsExtensionStartServiceEnable(const std::string &extension return StatusSingleton::GetInstance().isExtensionStartServiceEnable_; } -void ExtensionConfig::LoadExtensionConfig(const nlohmann::json &object) +void ExtensionConfig::LoadExtensionConfig(const cJSON *object) { return; } -void ExtensionConfig::LoadExtensionAutoDisconnectTime(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionAutoDisconnectTime(const cJSON *object, const std::string &extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const nlohmann::json &object, - std::string extensionTypeName) +void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const cJSON *object, std::string extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeName) +void ExtensionConfig::LoadExtensionServiceBlockedList(const cJSON *object, std::string extensionTypeName) { return; } -bool ExtensionConfig::LoadExtensionAbilityAccess(const nlohmann::json &object, const std::string &extensionTypeName) +bool ExtensionConfig::LoadExtensionAbilityAccess(const cJSON *object, const std::string &extensionTypeName) { return true; } @@ -109,20 +107,18 @@ std::string ExtensionConfig::FormatAccessFlag(const std::optional &flag) return flag.value() ? "true" : "false"; } -void ExtensionConfig::LoadExtensionAllowOrBlockedList(const nlohmann::json &object, const std::string &key, +void ExtensionConfig::LoadExtensionAllowOrBlockedList(const cJSON *object, const std::string &key, std::unordered_set &list) { return; } -void ExtensionConfig::LoadExtensionNetworkEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionNetworkEnable(const cJSON *object, const std::string &extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionSAEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionSAEnable(const cJSON *object, const std::string &extensionTypeName) { return; } @@ -194,7 +190,7 @@ bool ExtensionConfig::IsExtensionSAEnable(const std::string &extensionTypeName) return EXTENSION_SA_ENABLE_FLAG_DEFAULT; } -bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf) { return true; } diff --git a/test/unittest/extension_record_factory_test/BUILD.gn b/test/unittest/extension_record_factory_test/BUILD.gn index 1b43641f6246e76da6c77bc4f80282ccbf9faa92..36d7224ea626a03d06baf67daf5c42d71bd71268 100644 --- a/test/unittest/extension_record_factory_test/BUILD.gn +++ b/test/unittest/extension_record_factory_test/BUILD.gn @@ -94,7 +94,6 @@ ohos_unittest("extension_record_factory_test") { "i18n:intl_util", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "napi:ace_napi", diff --git a/test/unittest/extract_insight_intent_profile_test/BUILD.gn b/test/unittest/extract_insight_intent_profile_test/BUILD.gn index b4399a10398b16a04851aba4d483bce6da7dd150..2fac2255aa74778eb2bd56634cfe287c7b53f80f 100644 --- a/test/unittest/extract_insight_intent_profile_test/BUILD.gn +++ b/test/unittest/extract_insight_intent_profile_test/BUILD.gn @@ -31,7 +31,11 @@ ohos_unittest("extract_insight_intent_profile_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", ] - sources = [ "extract_insight_intent_profile_test.cpp" ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "extract_insight_intent_profile_test.cpp", + ] deps = [ "${ability_runtime_abilitymgr_path}/:abilityms" ] @@ -43,6 +47,7 @@ ohos_unittest("extract_insight_intent_profile_test") { "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp b/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp index 93e063191680770ffeda7de38d8bfd7189604832..72f1f8745297cf1fcbf2570fa58e92a6de5d8a3a 100644 --- a/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp +++ b/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp @@ -348,29 +348,38 @@ HWTEST_F(ExtractInsightIntentProfileTest, TransformTo_0200, TestSize.Level0) EXPECT_EQ(profileInfos.insightIntents[1].example, "exampleBBB"); EXPECT_NE(profileInfos.insightIntents[1].result, ""); - nlohmann::json jsonObject1; + cJSON *jsonObject1 = nullptr; result = ExtractInsightIntentProfile::ToJson(profileInfos.insightIntents[0], jsonObject1); EXPECT_EQ(result, true); ExtractInsightIntentProfileInfoVec profileInfos1; - result = ExtractInsightIntentProfile::TransformTo(jsonObject1.dump(), profileInfos1); + char *str1 = cJSON_PrintUnformatted(jsonObject1); + std::string jsonStr1 = (str1 == nullptr) ? "" : str1; + cJSON_free(str1); + result = ExtractInsightIntentProfile::TransformTo(jsonStr1, profileInfos1); EXPECT_EQ(result, true); - TAG_LOGI(AAFwkTag::TEST, "jsonObject1 dump: %{public}s", jsonObject1.dump().c_str()); + TAG_LOGI(AAFwkTag::TEST, "jsonObject1 dump: %{public}s", jsonStr1.c_str()); EXPECT_EQ(profileInfos1.insightIntents.size(), 1); EXPECT_EQ(profileInfos1.insightIntents[0].decoratorType, "@InsightIntentLink"); EXPECT_EQ(profileInfos1.insightIntents[0].intentName, "123"); EXPECT_EQ(profileInfos1.insightIntents[0].example, "exampleAAA"); + cJSON_Delete(jsonObject1); - nlohmann::json jsonObject2; + + cJSON *jsonObject2 = nullptr; result = ExtractInsightIntentProfile::ToJson(profileInfos.insightIntents[1], jsonObject2); EXPECT_EQ(result, true); ExtractInsightIntentProfileInfoVec profileInfos2; - result = ExtractInsightIntentProfile::TransformTo(jsonObject2.dump(), profileInfos2); + char *str2 = cJSON_PrintUnformatted(jsonObject1); + std::string jsonStr2 = (str2 == nullptr) ? "" : str2; + cJSON_free(str2); + result = ExtractInsightIntentProfile::TransformTo(jsonStr2, profileInfos2); EXPECT_EQ(result, true); - TAG_LOGI(AAFwkTag::TEST, "jsonObject2 dump: %{public}s", jsonObject2.dump().c_str()); + TAG_LOGI(AAFwkTag::TEST, "jsonObject2 dump: %{public}s", jsonStr2.c_str()); EXPECT_EQ(profileInfos2.insightIntents.size(), 1); EXPECT_EQ(profileInfos2.insightIntents[0].decoratorType, "@InsightIntentLink"); EXPECT_EQ(profileInfos2.insightIntents[0].intentName, "InsightIntent2"); EXPECT_EQ(profileInfos2.insightIntents[0].example, "exampleBBB"); + cJSON_Delete(jsonObject2); ExtractInsightIntentInfo info1; result = ExtractInsightIntentProfile::ProfileInfoFormat(profileInfos1.insightIntents[0], info1); diff --git a/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp b/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp index d3eb9c00525e1dc4ae4bdd990ce11bb91791b977..f7c053d76fefc35a0d835e4ab4433b4c0b868dc6 100644 --- a/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp @@ -1443,9 +1443,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayShort_0100, Function | MediumT GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayShort_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayShort(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayShort_0100 end"; @@ -1462,9 +1463,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayInt_0100, Function | MediumTes GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayInt_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayInt(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayInt_0100 end"; @@ -1481,9 +1483,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayLong_0100, Function | MediumTe GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayLong_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayLong(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayLong_0100 end"; @@ -1500,9 +1503,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayByte_0100, Function | MediumTe GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayByte_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayByte(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayByte_0100 end"; @@ -1519,9 +1523,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayBoolean_0100, Function | Mediu GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayBoolean_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayBoolean(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayBoolean_0100 end"; @@ -1538,9 +1543,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayFloat_0100, Function | MediumT GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayFloat_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayFloat(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayFloat_0100 end"; @@ -1557,9 +1563,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayDouble_0100, Function | Medium GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayDouble_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayDouble(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayDouble_0100 end"; @@ -1576,9 +1583,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayString_0100, Function | Medium GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayString_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayString(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayString_0100 end"; @@ -1594,9 +1602,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ParseJson_0100, Function | MediumTest | L { GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ParseJson_0100 start"; - Json::Value data; + cJSON *data = nullptr; PacMapList mapList; bool result = pacmap_->ParseJson(data, mapList); + cJSON_Delete(data); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ParseJson_0100 end"; @@ -1614,8 +1623,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayShort_0100, Function | MediumT PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayShort(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayShort_0100 end"; @@ -1633,8 +1643,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayInteger_0100, Function | Mediu PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayInteger(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayInteger_0100 end"; @@ -1652,8 +1663,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayLong_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayLong(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayLong_0100 end"; @@ -1671,8 +1683,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayChar_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayChar_0100 end"; @@ -1690,19 +1703,25 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayChar_0200, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; - item["data"] = "test"; + cJSON *item = cJSON_CreateObject(); + cJSON_AddStringToObject(item, "data", "test"); auto result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); EXPECT_EQ(result, true); - Json::Value courses(Json::arrayValue); - courses.append('a'); - courses.append(1); - courses.append("first"); - courses.append("second"); - courses.append("third"); - item["data"] = courses; + cJSON *courses = cJSON_CreateArray(); + cJSON *courses1 = cJSON_CreateNumber(static_cast('a')); + cJSON *courses2 = cJSON_CreateNumber(static_cast(1)); + cJSON *courses3 = cJSON_CreateString("first"); + cJSON *courses4 = cJSON_CreateString("second"); + cJSON *courses5 = cJSON_CreateString("third"); + cJSON_AddItemToArray(courses, courses1); + cJSON_AddItemToArray(courses, courses2); + cJSON_AddItemToArray(courses, courses3); + cJSON_AddItemToArray(courses, courses4); + cJSON_AddItemToArray(courses, courses5); + cJSON_AddItemToObject(item, "data", courses); result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayChar_0200 end"; @@ -1720,8 +1739,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayByte_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayByte(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayByte_0100 end"; @@ -1739,8 +1759,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayBoolean_0100, Function | Mediu PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayBoolean(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayBoolean_0100 end"; @@ -1758,8 +1779,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayFloat_0100, Function | MediumT PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayFloat(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayFloat_0100 end"; @@ -1777,8 +1799,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayDouble_0100, Function | Medium PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayDouble(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayDouble_0100 end"; @@ -1796,8 +1819,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayString_0100, Function | Medium PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayString(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayString_0100 end"; @@ -1815,8 +1839,9 @@ HWTEST_F(PacMapTest, AppExecFwk_InnerPutObjectValue_0100, Function | MediumTest PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->InnerPutObjectValue(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_InnerPutObjectValue_0100 end"; @@ -1834,8 +1859,9 @@ HWTEST_F(PacMapTest, AppExecFwk_InnerPutPacMapValue_0100, Function | MediumTest PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->InnerPutPacMapValue(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_InnerPutPacMapValue_0100 end"; diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 0baadfbaedab2dd43ad33c44b0ace15b45890149..94a34f34e47362d6350b79277dc3cb07c3c371d2 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -1022,6 +1022,7 @@ ohos_unittest("idle_time_test") { "graphic_2d:librender_service_client", "hilog:libhilog", "ipc:ipc_core", + # "json:nlohmann_json_static", "napi:ace_napi", ] } @@ -1057,7 +1058,6 @@ ohos_unittest("dump_runtime_helper_second_test") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", "ffrt:libffrt", "storage_service:storage_manager_acl", @@ -1096,7 +1096,6 @@ ohos_unittest("native_lib_util_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } @@ -1125,6 +1124,7 @@ ohos_unittest("startup_manager_test") { "${ability_runtime_native_path}/appkit/app_startup/startup_manager.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_task.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_startup_task_matcher_test.cpp", "startup_manager_test.cpp", "startup_utils_test.cpp", @@ -1144,6 +1144,7 @@ ohos_unittest("startup_manager_test") { "ability_base:zuri", "ability_runtime:runtime", "c_utils:utils", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "faultloggerd:libfaultloggerd", "googletest:gtest_main", @@ -1151,7 +1152,6 @@ ohos_unittest("startup_manager_test") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } @@ -1185,6 +1185,7 @@ ohos_unittest("startup_manager_mock_test") { "${ability_runtime_native_path}/appkit/app_startup/startup_listener.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_manager.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_task.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "${ability_runtime_test_path}/mock/start_up_and_intent/src/mock_extractor.cpp", "${ability_runtime_test_path}/mock/start_up_and_intent/src/mock_native_module_manager.cpp", "startup_manager_mock_test.cpp", @@ -1203,6 +1204,7 @@ ohos_unittest("startup_manager_mock_test") { "ability_base:zuri", "ability_runtime:runtime", "c_utils:utils", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "faultloggerd:libfaultloggerd", "googletest:gtest_main", @@ -1210,7 +1212,6 @@ ohos_unittest("startup_manager_mock_test") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } diff --git a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp index 5b4b2f3d5bfe6c44a9500b0d1e07da9d05144733..f58773b55171d24c6dc51818aa77c8ff20c01977 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp @@ -618,31 +618,38 @@ HWTEST_F(StartupManagerTest, AnalyzeStartupConfig_0100, Function | MediumTest | ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, false); - const nlohmann::json startupConfig_json = R"( - { - "startupConfig" : [ - { - "srcEntry" : "test_entry", - "name" : "test_name" - } - ] - } - )"_json; - startupConfig = startupConfig_json.dump(); + std::string jsonStr = R"({ + "startupConfig" : [ + { + "srcEntry" : "test_entry", + "name" : "test_name" + } + ] + })"; + cJSON *startupConfig_json = cJSON_Parse(jsonStr.c_str()); + char *str = cJSON_PrintUnformatted(startupConfig_json); + startupConfig = (str == nullptr) ? "" : str; ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, true); + cJSON_Delete(startupConfig_json); + cJSON_free(str); info.moduleType_ = AppExecFwk::ModuleType::ENTRY; - nlohmann::json startupConfigJson = { - {"startupConfig", { - {"configEntry", "test_configEntry"} - }} - }; - startupConfig = startupConfigJson.dump(); + cJSON *item1 = cJSON_CreateObject(); + cJSON *item2 = cJSON_CreateArray(); + cJSON *array1 = cJSON_CreateString("configEntry"); + cJSON *array2 = cJSON_CreateString("test_configEntry"); + cJSON_AddItemToArray(item2, array1); + cJSON_AddItemToArray(item2, array2); + cJSON_AddItemToObject(item1, "startupConfig", item2); + char *str1 = cJSON_PrintUnformatted(item1); + startupConfig = (str1 == nullptr) ? "" : str1; ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, false); + cJSON_Delete(item1); + cJSON_free(str1); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeStartupConfig_0100 end"; } @@ -659,14 +666,16 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json startupTasksJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *startupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(startupTasksJson); - nlohmann::json startupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "startupTasks": [ { @@ -675,11 +684,13 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(startupTasksJson2); - nlohmann::json startupTasksJson3 = R"( + const std::string jsonStr3 = R"( { "startupTasks": [ { @@ -687,9 +698,11 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(startupTasksJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTask_0100 end"; } @@ -706,7 +719,7 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json startupTasksJson = R"( + const std::string jsonStr = R"( { "startupTasks": [ { @@ -714,11 +727,13 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(startupTasksJson); - nlohmann::json startupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "startupTasks": [ { @@ -727,7 +742,8 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTask_0200 end"; @@ -746,14 +762,16 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadHintStartupTasksJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson, preloadSoStartupTasks); EXPECT_EQ(ret, true); + cJSON_Delete(preloadHintStartupTasksJson); - nlohmann::json preloadHintStartupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "appPreloadHintStartupTasks": [ { @@ -762,11 +780,13 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson2); - nlohmann::json preloadHintStartupTasksJson3 = R"( + const std::string jsonStr3 = R"( { "appPreloadHintStartupTasks": [ { @@ -774,9 +794,11 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson3, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTask_0100 end"; } @@ -793,7 +815,7 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadHintStartupTasksJson = R"( + const std::string jsonStr = R"( { "appPreloadHintStartupTasks": [ { @@ -801,11 +823,13 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson); - nlohmann::json preloadHintStartupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "appPreloadHintStartupTasks": [ { @@ -814,9 +838,11 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTask_0200 end"; } @@ -833,36 +859,45 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTaskInner_0100, Function | MediumT std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json appStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *appStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson); - nlohmann::json appStartupTaskInnerJson1 = R"( + const std::string jsonStr1 = R"( { "srcEntry": "test_entry", "name": "test_name" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson1 = cJSON_Parse(jsonStr1.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson1, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(appStartupTaskInnerJson1); - nlohmann::json appStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "srcEntry": [] } - )"_json; + )"; + cJSON *appStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); - nlohmann::json appStartupTaskInnerJson3 = R"( + cJSON_Delete(appStartupTaskInnerJson2); + + const std::string jsonStr3 = R"( { "srcEntry": "test_entry" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTaskInner_0100 end"; } @@ -879,32 +914,38 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTaskInner_0200, Function | MediumT std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json appStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { "srcEntry": "test_entry", "name": [] } - )"_json; + )"; + cJSON *appStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson); - nlohmann::json appStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "srcEntry": "", "name": "test_name" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson2); - nlohmann::json appStartupTaskInnerJson3 = R"( + const std::string jsonStr3 = R"( { "srcEntry": "test_entry", "name": "" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTaskInner_0200 end"; } @@ -921,32 +962,38 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTaskInner_0100, Function | M std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadSoStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson); - nlohmann::json preloadSoStartupTaskInnerJson1 = R"( + const std::string jsonStr1 = R"( { "ohmurl": "test_ohmurl", "name": "test_name" } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson1 = cJSON_Parse(jsonStr1.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson1, preloadSoStartupTasks); EXPECT_EQ(ret, true); + cJSON_Delete(preloadSoStartupTaskInnerJson1); - nlohmann::json preloadSoStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "ohmurl": [] } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTaskInner_0100 end"; } @@ -963,24 +1010,28 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTaskInner_0200, Function | M std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadSoStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { "ohmurl": "test_ohmurl" } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson); - nlohmann::json preloadSoStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "ohmurl": "test_ohmurl", "name": [] } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTaskInner_0200 end"; } diff --git a/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp index 4c73807487561cdf50bce221d974d02995211cec..b73febdab9ebac953ead13dcf35bc54efb9f1bd2 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include -#include #include "startup_utils.h" @@ -60,7 +59,7 @@ HWTEST_F(StartupUtilsTest, ParseJsonStringArray_001, TestSize.Level1) "nonArray" : "nonArray", "nonString": [1] })"; - nlohmann::json json = nlohmann::json::parse(jsonStr); + cJSON *json = cJSON_Parse(jsonStr.c_str()); std::vector arr; StartupUtils::ParseJsonStringArray(json, "nonExist", arr); @@ -78,6 +77,8 @@ HWTEST_F(StartupUtilsTest, ParseJsonStringArray_001, TestSize.Level1) StartupUtils::ParseJsonStringArray(json, "actions", arr3); EXPECT_EQ(arr3.size(), 2); GTEST_LOG_(INFO) << "ParseJsonStringArray_001 end"; + + cJSON_Delete(json); } } } \ No newline at end of file diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn index 83f137e6c1d208785d5b1910fe76a51cbc6b7832..ad1f29f40d65c29e0eb80e62b91c929c14e24100 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("insight_intent_execute_manager_second_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_execute_manager_mock.cpp", "insight_intent_execute_manager_second_test.cpp", ] @@ -61,6 +62,7 @@ ohos_unittest("insight_intent_execute_manager_second_test") { "ability_runtime:ability_manager", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn index f86d59785574d28fa7ae878e2963229cc194a98b..6bb611fd629acb3472c437681426fb994106d00a 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("insight_intent_execute_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_execute_manager_test.cpp", "insight_intent_utils_mock.cpp", ] @@ -54,6 +55,7 @@ ohos_unittest("insight_intent_execute_manager_test") { "ability_runtime:ability_manager", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/insight_intent_profile_test/BUILD.gn b/test/unittest/insight_intent_profile_test/BUILD.gn index 2b09abb2b66b4f51731a0cadb945c5bd065e82da..18e96be0f92bc59ef31a529139bfc3fd6200444c 100644 --- a/test/unittest/insight_intent_profile_test/BUILD.gn +++ b/test/unittest/insight_intent_profile_test/BUILD.gn @@ -30,7 +30,10 @@ ohos_unittest("insight_intent_profile_test") { "${ability_runtime_abilitymgr_path}/src", ] - sources = [ "insight_intent_profile_test.cpp" ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "insight_intent_profile_test.cpp", + ] deps = [ "${ability_runtime_abilitymgr_path}/:abilityms" ] diff --git a/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn b/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn index 7ec5e9bc14c9dc1b4910c7fd8499936de82e9514..837bd7927b26da47cd259207254ddb793631e881 100644 --- a/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn +++ b/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("insight_intent_rdb_storage_mgr_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_rdb_storage_mgr_test.cpp", "mock_insight_intent_rdb_data_mgr.cpp", ] @@ -48,6 +49,7 @@ ohos_unittest("insight_intent_rdb_storage_mgr_test") { "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/js_auto_fill_extension_test/BUILD.gn b/test/unittest/js_auto_fill_extension_test/BUILD.gn index b1fdcd9108103130b1362d2d9f699a4af443c5c0..78faa4bfef4b6cb436133eb8067b7f38aad18dad 100644 --- a/test/unittest/js_auto_fill_extension_test/BUILD.gn +++ b/test/unittest/js_auto_fill_extension_test/BUILD.gn @@ -61,7 +61,6 @@ ohos_unittest("js_auto_fill_extension_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/js_service_extension_test/BUILD.gn b/test/unittest/js_service_extension_test/BUILD.gn index 62484ae5ad5760cc46a5a7cc07aa4395013a858d..a8314ef4b7c6a8be464aa1c5854f6298fde50da7 100644 --- a/test/unittest/js_service_extension_test/BUILD.gn +++ b/test/unittest/js_service_extension_test/BUILD.gn @@ -62,7 +62,6 @@ ohos_unittest("js_service_extension_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/keep_alive_utils_test/BUILD.gn b/test/unittest/keep_alive_utils_test/BUILD.gn index 697a333ccf91a11a283493ab54e1e417895773eb..ce67e1733f784cf9b142ca16fd50f081e6e4be95 100644 --- a/test/unittest/keep_alive_utils_test/BUILD.gn +++ b/test/unittest/keep_alive_utils_test/BUILD.gn @@ -70,7 +70,6 @@ ohos_unittest("keep_alive_utils_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "memory_utils:libmeminfo", diff --git a/test/unittest/native_runtime_test/js_runtime_lite_test.cpp b/test/unittest/native_runtime_test/js_runtime_lite_test.cpp index 65cf157481d0459e534fef6f62b94d562fe55880..10b4128009004606281fa0a5f28f62e0ac8cf1f1 100644 --- a/test/unittest/native_runtime_test/js_runtime_lite_test.cpp +++ b/test/unittest/native_runtime_test/js_runtime_lite_test.cpp @@ -288,13 +288,14 @@ HWTEST_F(JsRuntimeLiteTest, InitLoop_0100, TestSize.Level1) */ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0100, TestSize.Level1) { - nlohmann::json itemObject; - itemObject["key"] = "value"; + cJSON *itemObject = cJSON_CreateObject(); + cJSON_AddStringToObject(itemObject, "key", "value"); std::string key = "key"; std::vector items = {}; JsRuntimeLite::GetInstance().ParsePkgContextInfoJsonString(itemObject, key, items); auto rBeginIt = items.rbegin(); EXPECT_EQ(*rBeginIt, "value"); + cJSON_Delete(itemObject); } /** @@ -304,13 +305,14 @@ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0100, TestSize.Level1) */ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0200, TestSize.Level1) { - nlohmann::json itemObject; - itemObject["key"] = "value"; + cJSON *itemObject = cJSON_CreateObject(); + cJSON_AddStringToObject(itemObject, "key", "value"); std::string key = "FakeKey"; std::vector items = {}; JsRuntimeLite::GetInstance().ParsePkgContextInfoJsonString(itemObject, key, items); auto rBeginIt = items.rbegin(); EXPECT_EQ(*rBeginIt, ""); + cJSON_Delete(itemObject); } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/service_router_mgr_service_test/BUILD.gn b/test/unittest/service_router_mgr_service_test/BUILD.gn index f5dd91b4c2b932b301e9ecebf7190af6ab2ebded..fda63091c40274a23913337a5428c06bc2eb3017 100644 --- a/test/unittest/service_router_mgr_service_test/BUILD.gn +++ b/test/unittest/service_router_mgr_service_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("service_router_mgr_service_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", + # "json:nlohmann_json_static", "safwk:api_cache_manager", ] } diff --git a/test/unittest/status_bar_delegate_manager_test/BUILD.gn b/test/unittest/status_bar_delegate_manager_test/BUILD.gn index 53bcb6ce0817368e3d4be97dff5611705e36e905..0515b3d1679673544be132d083c68b3cba179ed0 100644 --- a/test/unittest/status_bar_delegate_manager_test/BUILD.gn +++ b/test/unittest/status_bar_delegate_manager_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("status_bar_delegate_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/timeout_state_utils.cpp", diff --git a/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn index ad6b0a0c3d9e2fa7cb1ce5ef3d0931962a7b5a4a..06efa28e061a9eabf1f9efe6b19bcedf2b749d2c 100644 --- a/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("ui_ability_lifecycle_manager_second_test") { "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", "${ability_runtime_services_path}/abilitymgr/src/hidden_start_observer_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/timeout_state_utils.cpp", diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 71428d24e0c18129c70afc5e7ae29fd08e960826..3d73b55cdc4e4b8aca14bc6577ec2b46d3dfba59 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/hidden_start_observer_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", diff --git a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp index 54d90f68e6697752843351cf9e074d18cb7c8028..1fcae30920fc492c3a3e29f268c1ddc79c2b40a2 100644 --- a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp @@ -770,46 +770,57 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_3500, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_3600, Function | MediumTest | Level1) { std::vector flagsVec; - nlohmann::json jsonObject; - jsonObject["flags"] = -1; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(-1)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); EXPECT_EQ(flagsVec.size(), 0); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 1111000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(1111000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator oneTimeIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::ONE_TIME_FLAG); EXPECT_EQ(oneTimeIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator cancelPresentIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::CANCEL_PRESENT_FLAG); EXPECT_EQ(cancelPresentIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator updateResentIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); EXPECT_EQ(updateResentIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator constantIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::CONSTANT_FLAG); EXPECT_EQ(constantIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 1000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(1000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator noBuildIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::NO_BUILD_FLAG); EXPECT_EQ(noBuildIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); } /* diff --git a/test/unittest/window_options_utils_test/BUILD.gn b/test/unittest/window_options_utils_test/BUILD.gn index eb654bbaa19133894a3ebf77c019ef3f99a5b3aa..4166d02a4780da5e2a57cdff459e2240d6a3e370 100644 --- a/test/unittest/window_options_utils_test/BUILD.gn +++ b/test/unittest/window_options_utils_test/BUILD.gn @@ -61,7 +61,6 @@ ohos_unittest("window_options_utils_test") { "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "window_manager:libdm", "window_manager:libwsutils", diff --git a/tools/aa/src/shell_command_config_loader.cpp b/tools/aa/src/shell_command_config_loader.cpp index 48f5dd5709965b843e8a110efc0b9450891ac96f..f751910f1435b9adb509129604149a13ea281268 100644 --- a/tools/aa/src/shell_command_config_loader.cpp +++ b/tools/aa/src/shell_command_config_loader.cpp @@ -16,11 +16,10 @@ #include "shell_command_config_loader.h" #include #include -#include #include +#include "cJSON.h" #include "hilog_tag_wrapper.h" -using json = nlohmann::json; namespace OHOS { namespace AAFwk { namespace { @@ -55,51 +54,59 @@ bool ShellCommandConfigLoader::ReadConfig(const std::string &filePath) TAG_LOGI(AAFwkTag::AA_TOOL, "read aa config error"); return false; } - - json aaJson; - inFile >> aaJson; + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); inFile.close(); - if (aaJson.is_discarded()) { - TAG_LOGI(AAFwkTag::AA_TOOL, "json discarded error"); + + cJSON *aaJson = cJSON_Parse(fileContent.c_str()); + if (aaJson == nullptr) { + TAG_LOGI(AAFwkTag::AA_TOOL, "json parse error"); return false; } - if (aaJson.is_null() || aaJson.empty()) { + if (cJSON_IsNull(aaJson) || !cJSON_IsObject(aaJson)) { TAG_LOGI(AAFwkTag::AA_TOOL, "invalid jsonObj"); return false; } - if (!aaJson.contains(AA_TOOL_COMMAND_LIST)) { + cJSON *commonListItem = cJSON_GetObjectItem(aaJson, AA_TOOL_COMMAND_LIST); + if (commonListItem == nullptr) { TAG_LOGI(AAFwkTag::AA_TOOL, "config not contains the key"); + cJSON_Delete(aaJson); return false; } - if (aaJson[AA_TOOL_COMMAND_LIST].is_null() || !aaJson[AA_TOOL_COMMAND_LIST].is_array() || - aaJson[AA_TOOL_COMMAND_LIST].empty()) { + if (!cJSON_IsArray(commonListItem)) { + TAG_LOGI(AAFwkTag::AA_TOOL, "invalid command obj"); + cJSON_Delete(aaJson); + return false; + } + int commonListSize = cJSON_GetArraySize(commonListItem); + if (commonListSize <= 0) { TAG_LOGI(AAFwkTag::AA_TOOL, "invalid command obj size"); + cJSON_Delete(aaJson); return false; } - - if (aaJson[AA_TOOL_COMMAND_LIST].size() > COMMANDS_MAX_SIZE) { + if (commonListSize > COMMANDS_MAX_SIZE) { TAG_LOGI(AAFwkTag::AA_TOOL, "command obj size overflow"); + cJSON_Delete(aaJson); return false; } std::lock_guard lock(mtxRead_); - for (size_t i = 0; i < aaJson[AA_TOOL_COMMAND_LIST].size(); i++) { - if (aaJson[AA_TOOL_COMMAND_LIST][i].is_null() || !aaJson[AA_TOOL_COMMAND_LIST][i].is_string()) { + for (int i = 0; i < commonListSize; i++) { + cJSON *cmdItem = cJSON_GetArrayItem(commonListItem, i); + if (cmdItem == nullptr || !cJSON_IsString(cmdItem)) { continue; } - std::string cmd = aaJson[AA_TOOL_COMMAND_LIST][i].get(); + std::string cmd = cmdItem->valuestring; TAG_LOGD(AAFwkTag::AA_TOOL, "add cmd: %{public}s", cmd.c_str()); commands_.emplace(cmd); } - aaJson.clear(); + cJSON_Delete(aaJson); TAG_LOGI(AAFwkTag::AA_TOOL, "read config success"); configState_ = true; return true; } - } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/tools/test/systemtest/aa/BUILD.gn b/tools/test/systemtest/aa/BUILD.gn index 5fb4b5be113d64d06de46b1b63c5bc7e194a7a54..a6ddf203a27887dc2f5c28808995f8bc7760929e 100644 --- a/tools/test/systemtest/aa/BUILD.gn +++ b/tools/test/systemtest/aa/BUILD.gn @@ -49,7 +49,6 @@ ohos_systemtest("aa_command_start_system_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } @@ -81,7 +80,6 @@ ohos_systemtest("aa_command_stop_service_system_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } @@ -115,7 +113,6 @@ ohos_systemtest("aa_command_dump_system_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } diff --git a/tools/test/unittest/aa/BUILD.gn b/tools/test/unittest/aa/BUILD.gn index d7e204c7a6b2ca63b61967dc26b3b8416086c784..efafa2e652556092c2c49b9b2043bd17cd94dadf 100644 --- a/tools/test/unittest/aa/BUILD.gn +++ b/tools/test/unittest/aa/BUILD.gn @@ -353,7 +353,6 @@ if (accessibility_enable) { "cJSON:cjson", "googletest:gmock_main", "hilog:libhilog", - "jsoncpp:jsoncpp", "selinux_adapter:librestorecon", ] }