diff --git a/interfaces/inner_api/appexecfwk_base/src/extension_form_profile.cpp b/interfaces/inner_api/appexecfwk_base/src/extension_form_profile.cpp index 5fe16b408257d5fc3275f9aa2af9f0af30e1352a..668704309052b316982567687bc02a2585d8506b 100644 --- a/interfaces/inner_api/appexecfwk_base/src/extension_form_profile.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/extension_form_profile.cpp @@ -14,15 +14,18 @@ */ #include +#include #include + +#include"extension_form_profile.h" #include "json_util.h" #include "nlohmann/json.hpp" -#include "extension_form_profile.h" namespace OHOS { namespace AppExecFwk { namespace { -thread_local int32_t parseResult; +int32_t g_parseResult = ERR_OK; +std::mutex g_mutex; const int32_t MAX_FORM_NAME = 127; const std::map formColorModeMap = { @@ -91,7 +94,7 @@ void from_json(const nlohmann::json &jsonObject, Metadata &metadata) metadata.name, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -99,7 +102,7 @@ void from_json(const nlohmann::json &jsonObject, Metadata &metadata) metadata.value, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); } @@ -112,7 +115,7 @@ void from_json(const nlohmann::json &jsonObject, Window &window) window.designWidth, JsonType::NUMBER, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -120,7 +123,7 @@ void from_json(const nlohmann::json &jsonObject, Window &window) window.autoDesignWidth, JsonType::BOOLEAN, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); } @@ -133,7 +136,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.name, JsonType::STRING, true, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -141,7 +144,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.description, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -149,7 +152,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.src, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -157,7 +160,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.window, JsonType::OBJECT, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -165,7 +168,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.colorMode, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -173,7 +176,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.formConfigAbility, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -181,7 +184,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.type, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -189,7 +192,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.uiSyntax, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -197,7 +200,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.formVisibleNotify, JsonType::BOOLEAN, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -205,7 +208,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.isDefault, JsonType::BOOLEAN, true, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -213,7 +216,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.updateEnabled, JsonType::BOOLEAN, true, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -221,7 +224,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.scheduledUpdateTime, JsonType::STRING, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -229,7 +232,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.updateDuration, JsonType::NUMBER, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -237,7 +240,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.defaultDimension, JsonType::STRING, true, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey>(jsonObject, jsonObjectEnd, @@ -245,7 +248,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.supportDimensions, JsonType::ARRAY, true, - parseResult, + g_parseResult, ArrayType::STRING); GetValueIfFindKey>(jsonObject, jsonObjectEnd, @@ -253,7 +256,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.metadata, JsonType::ARRAY, false, - parseResult, + g_parseResult, ArrayType::OBJECT); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -261,7 +264,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.dataProxyEnabled, JsonType::BOOLEAN, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, @@ -269,7 +272,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfo &exten extensionFormProfileInfo.isDynamic, JsonType::BOOLEAN, false, - parseResult, + g_parseResult, ArrayType::NOT_ARRAY); } @@ -282,7 +285,7 @@ void from_json(const nlohmann::json &jsonObject, ExtensionFormProfileInfoVec &in infos.forms, JsonType::ARRAY, false, - parseResult, + g_parseResult, ArrayType::OBJECT); } @@ -404,13 +407,18 @@ ErrCode ExtensionFormProfile::TransformTo(const std::string &formProfile, std::v return ERR_APPEXECFWK_PARSE_BAD_PROFILE; } - auto forms = jsonObject.get(); - if (parseResult != ERR_OK) { - APP_LOGE("parseResult is %{public}d", parseResult); - int32_t ret = parseResult; - // need recover parse result to ERR_OK - parseResult = ERR_OK; - return ret; + ExtensionFormProfileInfoVec forms; + { + std::lock_guard lock(g_mutex); + g_parseResult = ERR_OK; + forms = jsonObject.get(); + if(g_parseResult != ERR_OK) { + APP_LOGE("g_parseResult is %{public}d", g_parseResult); + int32_t ret = g_parseResult; + // need recover parse result to ERR_OK + g_parseResult = ERR_OK; + return ret; + } } if (!TransformToInfos(forms, infos)) {