diff --git a/wifi/base/BUILD.gn b/wifi/base/BUILD.gn index 11394351255f7e30fb7ef51e85ed2b29d142d6e1..c062a0a23bf9d02923cddfc3d491f5955719a422 100644 --- a/wifi/base/BUILD.gn +++ b/wifi/base/BUILD.gn @@ -116,12 +116,12 @@ if (defined(ohos_lite)) { external_deps = [ "ability_runtime:extension_manager", "c_utils:utils", + "cJSON:cjson", "data_share:datashare_common", "data_share:datashare_consumer", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "openssl:libcrypto_shared", "openssl:libssl_shared", diff --git a/wifi/base/shared_util/wifi_notification_util.cpp b/wifi/base/shared_util/wifi_notification_util.cpp index 318d828ac62f9f3731e7b75112377c999160bc3c..cb0491d5c4390dbd7ced1cc4d8f079af287422f1 100644 --- a/wifi/base/shared_util/wifi_notification_util.cpp +++ b/wifi/base/shared_util/wifi_notification_util.cpp @@ -14,6 +14,7 @@ */ #include "ability_manager_ipc_interface_code.h" +#include "cJSON.h" #include "extension_manager_client.h" #include "iservice_registry.h" #include "message_parcel.h" @@ -155,25 +156,36 @@ void WifiNotificationUtil::ShowDialog(WifiDialogType type, std::string comInfo) std::string bundleName = "com.ohos.sceneboard"; std::string abilityName = "com.ohos.sceneboard.systemdialog"; want.SetElementName(bundleName, abilityName); - nlohmann::json param; - param["ability.want.params.uiExtensionType"] = "sysDialog/common"; - param["wifiDialogType"] = static_cast(type); + cJSON *param = cJSON_CreateObject(); + if (param == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(param, "ability.want.params.uiExtensionType", "sysDialog/common"); + cJSON_AddNumberToObject(param, "wifiDialogType", static_cast(type)); switch (type) { case AUTO_IDENTIFY_CONN: case SETTINGS_AUTO_IDENTIFY_CONN: - param["wifi5gSsid"] = comInfo; + cJSON_AddStringToObject(param, "wifi5gSsid", comInfo.c_str()); break; case P2P_WSC_PBC_DIALOG: - param["p2pDeviceName"] = comInfo; + cJSON_AddStringToObject(param, "p2pDeviceName", comInfo.c_str()); break; case CANDIDATE_CONNECT: - param["targetSsid"] = comInfo; + cJSON_AddStringToObject(param, "targetSsid", comInfo.c_str()); break; - default: { + default: break; - } } - std::string cmdData = param.dump(); + char *cjsonStr = cJSON_PrintUnformatted(param); + if (cjsonStr == nullptr) { + WIFI_LOGE("Failed to print cJSON object"); + cJSON_Delete(param); + return; + } + std::string cmdData(cjsonStr); + free(cjsonStr); + cJSON_Delete(param); sptr connection( new (std::nothrow) UIExtensionAbilityConnection(cmdData, "com.ohos.locationdialog", "WifiUIExtAbility")); if (connection == nullptr) { @@ -194,9 +206,21 @@ void WifiNotificationUtil::ShowSettingsDialog(WifiDialogType type, std::string s std::string bundleName = "com.ohos.sceneboard"; std::string abilityName = "com.ohos.sceneboard.systemdialog"; want.SetElementName(bundleName, abilityName); - nlohmann::json param; - param["ability.want.params.uiExtensionType"] = "sysDialog/common"; - std::string cmdData = param.dump(); + cJSON *param = cJSON_CreateObject(); + if (param == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(param, "ability.want.params.uiExtensionType", "sysDialog/common"); + char *cjsonStr = cJSON_PrintUnformatted(param); + if (cjsonStr == nullptr) { + WIFI_LOGE("Failed to print cJSON object"); + cJSON_Delete(param); + return; + } + std::string cmdData(cjsonStr); + free(cjsonStr); + cJSON_Delete(param); if (settings.empty()) { WIFI_LOGI("settings name is null"); return; diff --git a/wifi/bundle.json b/wifi/bundle.json index cacf470affa88ce7fbf94faf43afb763f974a7f9..39f34086ab593f9fd3c7991dfd59a2b0dface5fe 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -123,7 +123,6 @@ "power_manager", "time_service", "bounds_checking_function", - "jsoncpp", "libxml2", "asset", "runtime_core", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn index d1513fa8892b63d327441a7e5764ab9b3a8f5bfe..dba359ce7156671ef2fdcbaac309118c962c2c53 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn @@ -596,6 +596,7 @@ if (defined(ohos_lite)) { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "cJSON:cjson", "data_share:datashare_common", "data_share:datashare_consumer", "dhcp:dhcp_sdk", @@ -609,7 +610,6 @@ if (defined(ohos_lite)) { "samgr:samgr_proxy", "time_service:time_client", "window_manager:libdm_lite", - "jsoncpp:jsoncpp", ] if (wifi_feature_with_encryption || wifi_feature_with_local_random_mac) { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn index 32d256254d0eda50f7de7f67a39fa1c9780fad32..166e4aed551ac4657042f849b7a2b5b1137ece49 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn @@ -100,12 +100,12 @@ ohos_static_library("wifi_pro") { external_deps = [ "ability_runtime:app_manager", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_core", "dhcp:dhcp_sdk", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", - "jsoncpp:jsoncpp", "netmanager_base:net_conn_manager_if", "netmanager_base:net_stats_manager_if", "netmanager_base:netsys_controller", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.cpp index df66edee86ed00253a41532b5c3abe5583691e31..2d1fb03cccc01405206d5ac57a49e1cbfc70e454 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.cpp @@ -19,7 +19,7 @@ #include "wifi_settings.h" #include "wifi_hisysevent.h" #include "hisysevent.h" -#include "json/json.h" +#include "cJSON.h" namespace OHOS { namespace Wifi { DEFINE_WIFILOG_LABEL("WifiProChr"); @@ -248,44 +248,84 @@ void WifiProChr::RecordCountWiFiPro(bool isValid) void WifiProChr::WriteWifiProSysEvent() { WIFI_LOGI("WriteWifiProSysEvent enter"); - Json::Value root; - Json::FastWriter writer; - root["FAST_SCAN_CNT"] = fastScanCnt_; - root["FULL_SCAN_CNT"] = fullScanCnt_; - root["WIFIPRO_POOR_LINK_CNT"] = poorLinkCnt_; - root["WIFIPRO_NONET_CNT"] = noNetCnt_; - root["WIFIPRO_QOE_SLOW_CNT"] = qoeSlowCnt_; - root["POOR_LINK_SELECT_NET_SUCC_CNT"] = selectNetResultCnt_[WifiProEventResult::POORLINK_SUCC]; - root["NONET_SELECT_NET_SUCC_CNT"] = selectNetResultCnt_[WifiProEventResult::NONET_SUCC]; - root["QOE_SLOW_SELECT_NET_SUCC_CNT"] = selectNetResultCnt_[WifiProEventResult::QOE_SUCCC]; - root["POOR_LINK_SELECT_NET_FAILED_CNT"] = selectNetResultCnt_[WifiProEventResult::POORLINK_FAILED]; - root["NONET_SELECT_NET_FAILED_CNT"] = selectNetResultCnt_[WifiProEventResult::NONET_FAILED]; - root["QOE_SLOW_SELECT_NET_FAILED_CNT"] = selectNetResultCnt_[WifiProEventResult::QOESLOW_FAILED]; - root["POOR_LINK_SWITCH_SUCC_CNT"] = wifiProResultCnt_[WifiProEventResult::POORLINK_SUCC]; - root["NONET_SWITCH_SUCC_CNT"] = wifiProResultCnt_[WifiProEventResult::NONET_SUCC]; - root["QOE_SLOW_SWITCH_SUCC_CNT"] = wifiProResultCnt_[WifiProEventResult::QOE_SUCCC]; - root["POOR_LINK_SWITCH_FAILED_CNT"] = wifiProResultCnt_[WifiProEventResult::POORLINK_FAILED]; - root["NONET_SWITCH_FAILED_CNT"] = wifiProResultCnt_[WifiProEventResult::NONET_FAILED]; - root["QOE_SLOW_SWITCH_FAILED_CNT"] = wifiProResultCnt_[WifiProEventResult::QOESLOW_FAILED]; - root["TIME_LEVEL1_CNT"] = wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL1]; - root["TIME_LEVEL2_CNT"] = wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL2]; - root["TIME_LEVEL3_CNT"] = wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL3]; - root["TIME_START_TO_CONNECT_LEVEL1_CNT"] = wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL1]; - root["TIME_START_TO_CONNECT_LEVEL2_CNT"] = wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL2]; - root["TIME_START_TO_CONNECT_LEVEL3_CNT"] = wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL3]; - root["TIME_CONNECT_TO_SUCC_LEVEL1_CNT"] = wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL1]; - root["TIME_CONNECT_TO_SUCC_LEVEL2_CNT"] = wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL2]; - root["TIME_CONNECT_TO_SUCC_LEVEL3_CNT"] = wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL3]; - root["REASON_NOT_SWTICH_SWITCHING"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SWITCHING]; - root["REASON_NOT_SWTICH_SELFCURING"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SELFCURING]; - root["REASON_NOT_SWTICH_NONET_BEFORE"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_NONET_BEFORE_CONNECT]; - root["REASON_NOT_SWTICH_SIGNAL_BRIDGE"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SIGNAL_BRIDGE_ON]; - root["REASON_NOT_SWTICH_AP_STA_ON"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_AP_STA_ON]; - root["REASON_NOT_SWTICH_APP_WLISTS"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_APP_WHITE_LISTS]; - root["REASON_NOT_SWTICH_ISCALLING"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_ISCALLING]; - root["REASON_NOT_SWTICH_NOT_AUTOSWITCH"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_NOT_ALLOW_AUTOSWITCH]; - root["REASON_NOT_SWTICH_DISABLED"] = reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_DISABLED]; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_PRO_STATISTICS", "EVENT_VALUE", writer.write(root)); + cJSON *root = FillWifiProStatisticsJson(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_PRO_STATISTICS", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); +} + +cJSON *WifiProChr::FillWifiProStatisticsJson() +{ + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return nullptr; + } + cJSON_AddNumberToObject(root, "FAST_SCAN_CNT", fastScanCnt_); + cJSON_AddNumberToObject(root, "FULL_SCAN_CNT", fullScanCnt_); + cJSON_AddNumberToObject(root, "WIFIPRO_POOR_LINK_CNT", poorLinkCnt_); + cJSON_AddNumberToObject(root, "WIFIPRO_NONET_CNT", noNetCnt_); + cJSON_AddNumberToObject(root, "WIFIPRO_QOE_SLOW_CNT", qoeSlowCnt_); + cJSON_AddNumberToObject( + root, "POOR_LINK_SELECT_NET_SUCC_CNT", selectNetResultCnt_[WifiProEventResult::POORLINK_SUCC]); + cJSON_AddNumberToObject(root, "NONET_SELECT_NET_SUCC_CNT", selectNetResultCnt_[WifiProEventResult::NONET_SUCC]); + cJSON_AddNumberToObject(root, "QOE_SLOW_SELECT_NET_SUCC_CNT", selectNetResultCnt_[WifiProEventResult::QOE_SUCCC]); + cJSON_AddNumberToObject( + root, "POOR_LINK_SELECT_NET_FAILED_CNT", selectNetResultCnt_[WifiProEventResult::POORLINK_FAILED]); + cJSON_AddNumberToObject(root, "NONET_SELECT_NET_FAILED_CNT", selectNetResultCnt_[WifiProEventResult::NONET_FAILED]); + cJSON_AddNumberToObject( + root, "QOE_SLOW_SELECT_NET_FAILED_CNT", selectNetResultCnt_[WifiProEventResult::QOESLOW_FAILED]); + cJSON_AddNumberToObject(root, "POOR_LINK_SWITCH_SUCC_CNT", wifiProResultCnt_[WifiProEventResult::POORLINK_SUCC]); + cJSON_AddNumberToObject(root, "NONET_SWITCH_SUCC_CNT", wifiProResultCnt_[WifiProEventResult::NONET_SUCC]); + cJSON_AddNumberToObject(root, "QOE_SLOW_SWITCH_SUCC_CNT", wifiProResultCnt_[WifiProEventResult::QOE_SUCCC]); + cJSON_AddNumberToObject( + root, "POOR_LINK_SWITCH_FAILED_CNT", wifiProResultCnt_[WifiProEventResult::POORLINK_FAILED]); + + FillWifiProStatisticsJsons(root); + return root; +} + +void WifiProChr::FillWifiProStatisticsJsons(cJSON *root) +{ + cJSON_AddNumberToObject(root, "NONET_SWITCH_FAILED_CNT", wifiProResultCnt_[WifiProEventResult::NONET_FAILED]); + cJSON_AddNumberToObject(root, "QOE_SLOW_SWITCH_FAILED_CNT", wifiProResultCnt_[WifiProEventResult::QOESLOW_FAILED]); + cJSON_AddNumberToObject(root, "TIME_LEVEL1_CNT", wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL1]); + cJSON_AddNumberToObject(root, "TIME_LEVEL2_CNT", wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL2]); + cJSON_AddNumberToObject(root, "TIME_LEVEL3_CNT", wifiProSwitchTimeCnt_[SWITCH_TIME_LEVEL3]); + cJSON_AddNumberToObject(root, "TIME_START_TO_CONNECT_LEVEL1_CNT", wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL1]); + cJSON_AddNumberToObject(root, "TIME_START_TO_CONNECT_LEVEL2_CNT", wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL2]); + cJSON_AddNumberToObject(root, "TIME_START_TO_CONNECT_LEVEL3_CNT", wifiProSwitchTimeCnt_[START_TO_CONNECT_LEVEL3]); + cJSON_AddNumberToObject(root, "TIME_CONNECT_TO_SUCC_LEVEL1_CNT", wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL1]); + cJSON_AddNumberToObject(root, "TIME_CONNECT_TO_SUCC_LEVEL2_CNT", wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL2]); + cJSON_AddNumberToObject(root, "TIME_CONNECT_TO_SUCC_LEVEL3_CNT", wifiProSwitchTimeCnt_[CONNECT_TO_SUCC_LEVEL3]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_SWITCHING", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SWITCHING]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_SELFCURING", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SELFCURING]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_NONET_BEFORE", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_NONET_BEFORE_CONNECT]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_SIGNAL_BRIDGE", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_SIGNAL_BRIDGE_ON]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_AP_STA_ON", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_AP_STA_ON]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_APP_WLISTS", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_APP_WHITE_LISTS]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_ISCALLING", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_ISCALLING]); + cJSON_AddNumberToObject( + root, "REASON_NOT_SWITCH_NOT_AUTOSWITCH", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_NOT_ALLOW_AUTOSWITCH]); + cJSON_AddNumberToObject(root, "REASON_NOT_SWITCH_DISABLED", reasonNotSwitchCnt_[ReasonNotSwitch::WIFIPRO_DISABLED]); } } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.h index 8509cbe14b019b95e18d3950cd270e849a3e0e9b..3ec25fa0d32b009eb472f6ec0f4ae42996e10170 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_chr.h @@ -18,6 +18,7 @@ #include #include #include +#include "cJSON.h" #include "wifi_logger.h" #include "wifi_pro_common.h" #include "wifi_msg.h" @@ -78,6 +79,8 @@ public: void RecordWifiProSwitchSuccTime(); void RecordCountWiFiPro(bool isValid); void WriteWifiProSysEvent(); + cJSON *FillWifiProStatisticsJson(); + void FillWifiProStatisticsJsons(cJSON *root); private: int64_t wifiProStartTime_ = 0; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.cpp index 97a4368ce04cd4158cbf325c1e477a40ce498e25..aca8395c9bbfbf184e05f028054e75fd6b8cc894 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.cpp @@ -15,7 +15,7 @@ #ifdef WIFI_SECURITY_DETECT_ENABLE #include -#include "json/json.h" +#include "cJSON.h" #include "ip_tools.h" #include "wifi_security_detect.h" #include "wifi_security_detect_observer.h" @@ -248,25 +248,29 @@ void WifiSecurityDetect::UnRegisterSecurityDetectObserver() ErrCode WifiSecurityDetect::SecurityModelJsonResult(SecurityModelResult model, bool &result) { - Json::Value root; - Json::Reader reader; - bool parsingSuccess = reader.parse(model.result, root); - if (!parsingSuccess) { + cJSON *root = cJSON_Parse(model.result.c_str()); + if (root == nullptr) { WIFI_LOGE("model.result is null"); return WIFI_OPT_FAILED; } - - if (root["status"].isInt() && root["status"].asInt() != 0) { - WIFI_LOGE("RequestSecurityModelResultSync status error= %{public}d", root["status"].asInt()); + + cJSON *statusItem = cJSON_GetObjectItem(root, "status"); + if (statusItem && cJSON_IsNumber(statusItem) && statusItem->valueint != 0) { + WIFI_LOGE("RequestSecurityModelResultSync status error= %d", statusItem->valueint); + cJSON_Delete(root); return WIFI_OPT_FAILED; } + + cJSON *resultItem = cJSON_GetObjectItem(root, "result"); std::string SecurityResult; - if (root["result"].isString()) { - SecurityResult = root["result"].asString(); + if (resultItem && cJSON_IsString(resultItem)) { + SecurityResult = resultItem->valuestring; } else { - WIFI_LOGE("The result is not string"); - return WIFI_OPT_FAILED; + SecurityResult = ""; } + + cJSON_Delete(root); + if (CheckDataLegal(SecurityResult) == 0) { WIFI_LOGI("SG wifi result is secure"); result = true; @@ -304,7 +308,7 @@ int32_t WifiSecurityDetect::AuthenticationConvert(std::string key) } } -void WifiSecurityDetect::ConverWifiLinkInfoToJson(const WifiLinkedInfo &info, Json::Value &root) +void WifiSecurityDetect::ConverWifiLinkInfoToJson(const WifiLinkedInfo &info, cJSON *root) { WifiDeviceConfig config; if (WifiSettings::GetInstance().GetDeviceConfig(info.networkId, config) != 0) { @@ -314,45 +318,53 @@ void WifiSecurityDetect::ConverWifiLinkInfoToJson(const WifiLinkedInfo &info, Js IpInfo wifiIpInfo; int32_t instId = 0; WifiConfigCenter::GetInstance().GetIpInfo(wifiIpInfo, instId); - switch (info.wifiStandard) { + + AddWifiStandardToJson(root, info.wifiStandard); + + cJSON_AddStringToObject(root, "ssid", config.ssid.c_str()); + cJSON_AddStringToObject(root, "bssid", config.bssid.c_str()); + cJSON_AddNumberToObject(root, "signalStrength", config.rssi); + cJSON_AddNumberToObject(root, "authentication", AuthenticationConvert(config.keyMgmt)); + if (config.frequency >= MIN_5G_FREQUENCY && config.frequency <= MAX_5G_FREQUENCY) { + cJSON_AddStringToObject(root, "frequencyBand", "5GHz"); + } else { + cJSON_AddStringToObject(root, "frequencyBand", "2.4GHz"); + } + cJSON_AddStringToObject(root, "gatewayIp", IpTools::ConvertIpv4Address(wifiIpInfo.ipAddress).c_str()); + cJSON_AddStringToObject(root, "gatewayMac", config.macAddress.c_str()); + cJSON_AddStringToObject(root, "primaryDns", IpTools::ConvertIpv4Address(wifiIpInfo.primaryDns).c_str()); + if (wifiIpInfo.secondDns == 0) { + cJSON_AddStringToObject(root, "secondDns", "0.0.0.0"); + } else { + cJSON_AddStringToObject(root, "secondDns", IpTools::ConvertIpv4Address(wifiIpInfo.secondDns).c_str()); + } +} + +void WifiSecurityDetect::AddWifiStandardToJson(cJSON *root, int wifiStandard) +{ + switch (wifiStandard) { case WireType::WIRE_802_11A: - root["wirelessType"] = "802.11a"; + cJSON_AddStringToObject(root, "wirelessType", "802.11a"); break; case WireType::WIRE_802_11B: - root["wirelessType"] = "802.11b"; + cJSON_AddStringToObject(root, "wirelessType", "802.11b"); break; case WireType::WIRE_802_11G: - root["wirelessType"] = "802.11g"; + cJSON_AddStringToObject(root, "wirelessType", "802.11g"); break; case WireType::WIRE_802_11N: - root["wirelessType"] = "802.11n"; + cJSON_AddStringToObject(root, "wirelessType", "802.11n"); break; case WireType::WIRE_802_11AC: - root["wirelessType"] = "802.11ac"; + cJSON_AddStringToObject(root, "wirelessType", "802.11ac"); break; case WireType::WIRE_802_11AX: - root["wirelessType"] = "802.11ax"; + cJSON_AddStringToObject(root, "wirelessType", "802.11ax"); break; default: WIFI_LOGE("wifi wirelessType is unknown"); - root["wirelessType"] = ""; - } - root["ssid"] = config.ssid; - root["bssid"] = config.bssid; - root["signalStrength"] = config.rssi; - root["authentication"] = AuthenticationConvert(config.keyMgmt); - if (config.frequency >= MIN_5G_FREQUENCY && config.frequency <= MAX_5G_FREQUENCY) { - root["frequencyBand"] = "5GHz"; - } else { - root["frequencyBand"] = "2.4GHz"; - } - root["gatewayIp"] = IpTools::ConvertIpv4Address(wifiIpInfo.ipAddress); - root["gatewayMac"] = config.macAddress; - root["primaryDns"] = IpTools::ConvertIpv4Address(wifiIpInfo.primaryDns); - if (wifiIpInfo.secondDns == 0) { - root["secondDns"] = "0.0.0.0"; - } else { - root["secondDns"] = IpTools::ConvertIpv4Address(wifiIpInfo.secondDns); + cJSON_AddStringToObject(root, "wirelessType", ""); + break; } } @@ -372,10 +384,18 @@ void WifiSecurityDetect::SecurityDetect(const WifiLinkedInfo &info) return; } - Json::Value root; - Json::FastWriter writer; + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } ConverWifiLinkInfoToJson(info, root); - model.param = writer.write(root); + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr != nullptr) { + model.param = jsonStr; + free(jsonStr); + } + cJSON_Delete(root); WIFI_LOGI( "ssid:%{public}s bssid:%{public}s", SsidAnonymize(config.ssid).c_str(), MacAnonymize(config.bssid).c_str()); securityDetectThread_->PostAsyncTask([=]() mutable -> int32_t { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.h index 5211df541652e722e4ce8759b9b0bb530d37baa3..3139f5c604177afff9af8b062b6fcd6e34098c2b 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_security_detect/wifi_security_detect.h @@ -15,7 +15,7 @@ #ifndef WIFI_SECURITY_DETECT_H #define WIFI_SECURITY_DETECT_H -#include "json/json.h" +#include "cJSON.h" #include "sta_service_callback.h" #include "wifi_event_handler.h" #include "wifi_datashare_utils.h" @@ -74,6 +74,7 @@ public: void SetChangeNetworkid(int networkid); void RegisterSecurityDetectObserver(); void SecurityDetect(const WifiLinkedInfo &info); + void AddWifiStandardToJson(cJSON *root, int wifiStandard); void PopupNotification(int status, int networkid); private: @@ -89,7 +90,7 @@ private: bool IsSecurityDetectTimeout(const int &networkId); ErrCode SecurityDetectResult(const std::string &devId, uint32_t modelId, const std::string ¶m, bool &result); ErrCode SecurityModelJsonResult(SecurityModelResult model, bool &result); - void ConverWifiLinkInfoToJson(const WifiLinkedInfo &info, Json::Value &root); + void ConverWifiLinkInfoToJson(const WifiLinkedInfo &info, cJSON *root); int32_t AuthenticationConvert(std::string key); void UnRegisterSecurityDetectObserver(); }; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/BUILD.gn index 5d884fbf1d09a851680b6e1f5d5681950841e612..27fd51abd046fc1da64a165e3e11e968105ae535 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/BUILD.gn @@ -158,6 +158,7 @@ if (defined(ohos_lite)) { external_deps = [ "ability_base:want", "c_utils:utils", + "cJSON:cjson", "certificate_manager:cert_manager_sdk", "common_event_service:cesfwk_innerkits", "dhcp:dhcp_sdk", @@ -166,7 +167,6 @@ if (defined(ohos_lite)) { "hilog:libhilog", "icu:shared_icuuc", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "samgr:samgr_proxy", "window_manager:libdm_lite", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp index 3654e3597a3b1d6298372f675d9c4c95720a7468..584606c79c83981ef48dd5d67b9ba8c8eb6f6293 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp @@ -27,7 +27,7 @@ #include "softap_parser.h" #include "package_parser.h" #include "wifi_backup_config.h" -#include "json/json.h" +#include "cJSON.h" #endif #ifdef SUPPORT_ClOUD_WIFI_ASSET #include "wifi_asset_manager.h" @@ -966,19 +966,42 @@ int WifiSettings::OnBackup(UniqueFd &fd, const std::string &backupInfo) std::string WifiSettings::SetBackupReplyCode(int replyCode) { - Json::Value root; - Json::Value resultInfo; - Json::Value errorInfo; - - errorInfo["type"] = "ErrorInfo"; - errorInfo["errorCode"] = std::to_string(replyCode); - errorInfo["errorInfo"] = ""; - - resultInfo.append(errorInfo); - root["resultInfo"] = resultInfo; - - Json::FastWriter writer; - return writer.write(root); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + LOGE("Failed to create cJSON object"); + return ""; + } + cJSON *resultInfo = cJSON_CreateArray(); + if (resultInfo == nullptr) { + LOGE("Failed to create cJSON Arr"); + cJSON_Delete(root); + return ""; + } + cJSON *errorInfo = cJSON_CreateObject(); + if (errorInfo == nullptr) { + LOGE("Failed to create cJSON object"); + cJSON_Delete(root); + return ""; + } + + cJSON_AddStringToObject(errorInfo, "type", "ErrorInfo"); + std::string codeStr = std::to_string(replyCode); + cJSON_AddStringToObject(errorInfo, "errorCode", codeStr.c_str()); + cJSON_AddStringToObject(errorInfo, "errorInfo", ""); + + cJSON_AddItemToArray(resultInfo, errorInfo); + + cJSON_AddItemToObject(root, "resultInfo", resultInfo); + + char *jsonStr = cJSON_PrintUnformatted(root); + std::string result; + if (jsonStr != nullptr) { + result = jsonStr; + free(jsonStr); + } + + cJSON_Delete(root); + return result; } void WifiSettings::RemoveBackupFile() diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp index f42b17f9ce6312914a7b2c53c839f2954b76b955..a00adb34cfefbb925713b74dd125f98e2de866b9 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp @@ -21,7 +21,7 @@ #include "wifi_common_util.h" #include "wifi_log.h" #ifndef OHOS_ARCH_LITE -#include "json/json.h" +#include "cJSON.h" #include "wifi_country_code_define.h" #endif #ifdef INIT_LIB_ENABLE @@ -613,22 +613,28 @@ bool IsSignalSmoothingEnable() } #ifndef OHOS_ARCH_LITE -bool ParseJsonKey(const Json::Value &jsonValue, const std::string &key, std::string &value) -{ - if (jsonValue.isArray()) { - int nSize = static_cast(jsonValue.size()); - for (int i = 0; i < nSize; i++) { - if (!jsonValue[i].isMember(key)) { - LOGW("ParseJsonKey JSON[%{public}d] has no member %{public}s.", nSize, key.c_str()); - return false; - } - if (jsonValue[i][key].isString()) { - value = jsonValue[i][key].asString(); - return true; - } else if (jsonValue[i][key].isInt()) { - value = std::to_string(jsonValue[i][key].asInt()); - return true; - } +bool ParseJsonKey(const cJSON *jsonValue, const std::string &key, std::string &value) +{ + if (!cJSON_IsArray(jsonValue)) { + return false; + } + int nSize = cJSON_GetArraySize(jsonValue); + for (int i = 0; i < nSize; ++i) { + cJSON *item = cJSON_GetArrayItem(jsonValue, i); + if (item == nullptr || !cJSON_IsObject(item)) { + return false; + } + cJSON *keyItem = cJSON_GetObjectItem(item, key.c_str()); + if (keyItem == nullptr) { + return false; + } + if (cJSON_IsString(keyItem) && keyItem->valuestring != nullptr) { + value = keyItem->valuestring; + return true; + } else if (cJSON_IsNumber(keyItem)) { + value = std::to_string(keyItem->valueint); + return true; + } else { return false; } } @@ -637,24 +643,31 @@ bool ParseJsonKey(const Json::Value &jsonValue, const std::string &key, std::str bool ParseJson(const std::string &jsonString, const std::string &type, const std::string &key, std::string &value) { - LOGI("ParseJson enter."); - Json::Value root; - Json::Reader reader; - bool success = reader.parse(jsonString, root); - if (!success) { + cJSON *root = cJSON_Parse(jsonString.c_str()); + if (root == nullptr) { LOGE("ParseJson failed to parse json data."); return false; } - int nSize = static_cast(root.size()); + if (!cJSON_IsArray(root)) { + cJSON_Delete(root); + return false; + } + int nSize = cJSON_GetArraySize(root); for (int i = 0; i < nSize; i++) { - if (!root[i].isMember(type)) { - LOGW("ParseJson JSON[%{public}d] has no member %{public}s.", nSize, type.c_str()); + cJSON *item = cJSON_GetArrayItem(root, i); + if (item == nullptr || !cJSON_IsObject(item)) { + continue; + } + cJSON *typeItem = cJSON_GetObjectItem(item, type.c_str()); + if (typeItem == nullptr) { continue; } - if (ParseJsonKey(root[i][type], key, value)) { + if (ParseJsonKey(typeItem, key, value)) { + cJSON_Delete(root); return true; } } + cJSON_Delete(root); return false; } diff --git a/wifi/test/fuzztest/wifi_sta/enablep2p_fuzzer/BUILD.gn b/wifi/test/fuzztest/wifi_sta/enablep2p_fuzzer/BUILD.gn index e5299b0f58cc57f08d8fc636a6a75c41ee5a17e8..20fd08d40f4a4ab2ce88c1907223cbc4aa7820b6 100644 --- a/wifi/test/fuzztest/wifi_sta/enablep2p_fuzzer/BUILD.gn +++ b/wifi/test/fuzztest/wifi_sta/enablep2p_fuzzer/BUILD.gn @@ -209,7 +209,6 @@ ohos_fuzztest("EnableP2pFuzzTest") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/fuzztest/wifi_sta/wifiap_fuzzer/BUILD.gn b/wifi/test/fuzztest/wifi_sta/wifiap_fuzzer/BUILD.gn index 29a2cd41017fadabeabfb7d76730ffb34a010e22..32e105c73525e3d9a671657c1b2abda86aec1ca2 100644 --- a/wifi/test/fuzztest/wifi_sta/wifiap_fuzzer/BUILD.gn +++ b/wifi/test/fuzztest/wifi_sta/wifiap_fuzzer/BUILD.gn @@ -105,11 +105,11 @@ ohos_fuzztest("WifiApFuzzTest") { "ability_base:base", "ability_base:want", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_core", "dhcp:dhcp_sdk", "hilog:libhilog", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "samgr:samgr_proxy", diff --git a/wifi/test/fuzztest/wifi_sta/wifistaserver_fuzzer/BUILD.gn b/wifi/test/fuzztest/wifi_sta/wifistaserver_fuzzer/BUILD.gn index 41f3236b6ff45492eccb41c2c0c6164422cf0d65..3b26f0e31eeb12bdb13d2a0f3d41da9c0999cc04 100644 --- a/wifi/test/fuzztest/wifi_sta/wifistaserver_fuzzer/BUILD.gn +++ b/wifi/test/fuzztest/wifi_sta/wifistaserver_fuzzer/BUILD.gn @@ -122,6 +122,7 @@ ohos_fuzztest("WifiStaServerFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "data_share:datashare_consumer", "dhcp:dhcp_sdk", "hilog:libhilog", diff --git a/wifi/test/fuzztest/wifi_sta/wifitoolkit_fuzzer/BUILD.gn b/wifi/test/fuzztest/wifi_sta/wifitoolkit_fuzzer/BUILD.gn index a332cd4d4c467bbe698e75d538c83870923024a8..0480b13854d4711c7fb9fd60a14d875ec073e8f7 100644 --- a/wifi/test/fuzztest/wifi_sta/wifitoolkit_fuzzer/BUILD.gn +++ b/wifi/test/fuzztest/wifi_sta/wifitoolkit_fuzzer/BUILD.gn @@ -77,11 +77,11 @@ ohos_fuzztest("WifiToolkitFuzzTest") { external_deps = [ "c_utils:utils", + "cJSON:cjson", "dhcp:dhcp_sdk", "dhcp:dhcp_utils", "hilog:libhilog", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netstack:http_client", "samgr:samgr_proxy", diff --git a/wifi/test/wifi_standard/non_mock/BUILD.gn b/wifi/test/wifi_standard/non_mock/BUILD.gn index 51397a349c17841ff6c05043375d3b4bde410b52..a6c1425f5c6ea68b2908d4797d91eee0505f6fe0 100644 --- a/wifi/test/wifi_standard/non_mock/BUILD.gn +++ b/wifi/test/wifi_standard/non_mock/BUILD.gn @@ -80,8 +80,8 @@ ohos_unittest("wifi_non_mock_unittest") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "cJSON:cjson", "hilog:libhilog", - "jsoncpp:jsoncpp", "libxml2:libxml2", "samgr:samgr_proxy", "time_service:time_client", diff --git a/wifi/test/wifi_standard/precompiled_macro/BUILD.gn b/wifi/test/wifi_standard/precompiled_macro/BUILD.gn index 735593485d49f5cc80a802bb26ae681876322b00..71a20587d1399983cbbc86c708be5d84bc796871 100644 --- a/wifi/test/wifi_standard/precompiled_macro/BUILD.gn +++ b/wifi/test/wifi_standard/precompiled_macro/BUILD.gn @@ -139,7 +139,6 @@ ohos_unittest("precompiled_macro_unittest") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/BUILD.gn index 273dbd3bdffcabba96a291828ae7998a071b6054..6d9d85796ceff9f75f7fe03c920a5963ed096f5d 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/BUILD.gn @@ -93,13 +93,13 @@ ohos_unittest("idl_client_unittest") { external_deps = [ "c_utils:utils", + "cJSON:cjson", "googletest:gmock_main", "googletest:gtest_main", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdi", "hdf_core:libpub_utils", "hilog:libhilog", - "jsoncpp:jsoncpp", "samgr:samgr_proxy", ] diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn index 6990a40e91828ee68409ca38be2edae8626677ef..00167c8808d824eadf816745868be30eeb298c82 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn @@ -203,6 +203,7 @@ ohos_unittest("manager_unittest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "data_share:datashare_common", "data_share:datashare_consumer", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_ap/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_ap/BUILD.gn index 6fa05fef2a0c31730b17d3f43b0c12229b0ef05f..942f3d686343308ec736546e1748a54ce9fe98f8 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_ap/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_ap/BUILD.gn @@ -140,6 +140,7 @@ ohos_unittest("WifiApServiceTest") { "ability_base:base", "ability_base:want", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "dhcp:dhcp_sdk", "googletest:gmock_main", @@ -147,7 +148,6 @@ ohos_unittest("WifiApServiceTest") { "hilog:libhilog", "ipc:ipc_single", "icu:shared_icuuc", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "samgr:samgr_proxy", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn index 283ce583e4d59b110ba050a4861f53b317bea39a..90d7fa12fec79b9dbe823b65fb7ae7e51d331505 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/BUILD.gn @@ -165,6 +165,7 @@ ohos_unittest("wifi_pro_unittest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "data_share:datashare_consumer", "dhcp:dhcp_sdk", "googletest:gmock_main", @@ -173,7 +174,6 @@ ohos_unittest("wifi_pro_unittest") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn index 36edeab6f0a83300ba41794338a980ea1a472933..e5f394d81ec8a5031d1db22670872bd874cbb4b6 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn @@ -153,6 +153,7 @@ ohos_unittest("wifi_scan_unittest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "common_event_service:cesfwk_innerkits", "data_share:datashare_common", "data_share:datashare_consumer", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn index 9a253b34db5e242ca782f1a77ae5fc429c3aedbe..74f6ca78d97f2eb6609435e7ea296ad16a847788 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn @@ -163,6 +163,7 @@ local_base_external_deps = [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "certificate_manager:cert_manager_sdk", "data_share:datashare_consumer", "dhcp:dhcp_sdk", @@ -173,7 +174,6 @@ local_base_external_deps = [ "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/BUILD.gn index d5dadbdafb60762c41273b95ccd5088e304cdc96..8cc40c1fa4421458a7a2b5bc5b03a0b207760145 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/BUILD.gn @@ -108,6 +108,7 @@ ohos_unittest("wifi_sta_ext_unittest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "certificate_manager:cert_manager_sdk", "data_share:datashare_consumer", "dhcp:dhcp_sdk", @@ -117,7 +118,6 @@ ohos_unittest("wifi_sta_ext_unittest") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.cpp index b18a03aafc9a687ae807c70a817f682e0483f98b..8aef676e78baa717367caf05e14db7b2104aafd3 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "json/json.h" +#include "cJSON.h" #include "wifi_security_detect_test.h" using namespace testing::ext; diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.h b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.h index f6e56f85ee2a9eed981fcfbf68a2b1941d8d0f8c..35ab2c7678fdbcced4673679cf5da8a709e86817 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.h +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_ext/wifi_security_detect_test.h @@ -17,7 +17,6 @@ #define OHOS_WIFI_SECURITY_DETECT_TEST_H #include #include "wifi_security_detect.h" -#include "json/json.h" #include "datashare_helper.h" #include "sta_service_callback.h" #include "wifi_event_handler.h" diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/BUILD.gn index 80a4504e4d355114404921876e32a3ecadffe772..29882b99f0eb8eccb3073a204cb6c6ae3377741f 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/BUILD.gn @@ -160,6 +160,7 @@ ohos_unittest("wifi_sub_manage_unittest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "data_share:datashare_consumer", "dhcp:dhcp_sdk", "googletest:gmock_main", @@ -167,7 +168,6 @@ ohos_unittest("wifi_sub_manage_unittest") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netmanager_base:net_conn_manager_if", "netmanager_base:net_native_manager_if", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/BUILD.gn index dc3d9b0bdae93fb40e9d91d5a58f427edf02e5de..ef4f9b3b27f6e3d391d6808e6118743d7e72e410 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/BUILD.gn @@ -124,6 +124,7 @@ ohos_unittest("toolkit_unittest") { ] external_deps = [ "c_utils:utils", + "cJSON:cjson", "certificate_manager:cert_manager_sdk", "dhcp:dhcp_sdk", "dhcp:dhcp_utils", @@ -133,7 +134,6 @@ ohos_unittest("toolkit_unittest") { "icu:shared_icuuc", "init:libbegetutil", "ipc:ipc_single", - "jsoncpp:jsoncpp", "libxml2:libxml2", "netstack:http_client", "samgr:samgr_proxy", diff --git a/wifi/test/wifi_utils/unittest/BUILD.gn b/wifi/test/wifi_utils/unittest/BUILD.gn index 7aba7aeb2ddc067d523c0072a146f85b8d3083e4..90e9f54ce28c9fb69652349ae32cc24985f282b8 100644 --- a/wifi/test/wifi_utils/unittest/BUILD.gn +++ b/wifi/test/wifi_utils/unittest/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("utils_unittest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", - "jsoncpp:jsoncpp", "openssl:libcrypto_shared", "openssl:libssl_shared", "samgr:samgr_proxy", diff --git a/wifi/utils/BUILD.gn b/wifi/utils/BUILD.gn index e07d0e094671f5eddcd56dadb506fd0298694368..3f019baa1a07189527b623f0417c3f0b12bf1122 100644 --- a/wifi/utils/BUILD.gn +++ b/wifi/utils/BUILD.gn @@ -90,10 +90,10 @@ if (defined(ohos_lite)) { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "cJSON:cjson", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", - "jsoncpp:jsoncpp", "openssl:libcrypto_shared", "openssl:libssl_shared", "samgr:samgr_proxy", diff --git a/wifi/utils/src/wifi_hisysevent.cpp b/wifi/utils/src/wifi_hisysevent.cpp index 3418dca71a01c5d41120cf61721d3471e3cb5324..0cf6eebcca668c9e2bd4fb65b5ea2aad900a94cd 100644 --- a/wifi/utils/src/wifi_hisysevent.cpp +++ b/wifi/utils/src/wifi_hisysevent.cpp @@ -18,7 +18,7 @@ #include "hisysevent.h" #include "sta_define.h" #include "wifi_logger.h" -#include "json/json.h" +#include "cJSON.h" #include namespace OHOS { @@ -61,11 +61,22 @@ void WriteWifiStateHiSysEvent(const std::string& serviceType, WifiOperType operT { WriteEvent("WIFI_STATE", "TYPE", serviceType, "OPER_TYPE", static_cast(operType)); - Json::Value root; - Json::FastWriter writer; - root["WIFI_STATE"] = static_cast(operType); - root["TYPE"] = serviceType; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_STATE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "WIFI_STATE", static_cast(operType)); + cJSON_AddStringToObject(root, "TYPE", serviceType.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_STATE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } void WriteWifiApStateHiSysEvent(int32_t state) @@ -110,252 +121,542 @@ void WriteWifiSignalHiSysEvent(int direction, int txPackets, int rxPackets) void WriteWifiOperateStateHiSysEvent(int operateType, int operateState) { - Json::Value root; - Json::FastWriter writer; - root["OPERATE_TYPE"] = operateType; - root["OPERATE_STATE"] = operateState; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_OPERATE_STATE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "OPERATE_TYPE", operateType); + cJSON_AddNumberToObject(root, "OPERATE_STATE", operateState); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_OPERATE_STATE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiAbnormalDisconnectHiSysEvent(int errorCode, int locallyGenerated) { - Json::Value root; - Json::FastWriter writer; - root["ERROR_CODE"] = errorCode; - root["IS_ACTIVE_DISCONNECT"] = locallyGenerated; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ABNORMAL_DISCONNECT", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ERROR_CODE", errorCode); + cJSON_AddNumberToObject(root, "IS_ACTIVE_DISCONNECT", locallyGenerated); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ABNORMAL_DISCONNECT", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiBeaconLostHiSysEvent(int32_t errorCode) { - Json::Value root; - Json::FastWriter writer; - root["ERROR_CODE"] = errorCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_BEACON_LOST", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ERROR_CODE", errorCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_BEACON_LOST", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiConnectionInfoHiSysEvent(int networkId) { - Json::Value root; - Json::FastWriter writer; - root["NETWORK_ID"] = networkId; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_CONNECTION_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "NETWORK_ID", networkId); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_CONNECTION_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiOpenAndCloseFailedHiSysEvent(int operateType, std::string failReason, int apState) { - Json::Value root; - Json::FastWriter writer; - root["OPERATE_TYPE"] = operateType; - root["FAIL_REASON"] = failReason; - root["AP_STATE"] = apState; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_OPEN_AND_CLOSE_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "OPERATE_TYPE", operateType); + cJSON_AddStringToObject(root, "FAIL_REASON", failReason.c_str()); + cJSON_AddNumberToObject(root, "AP_STATE", apState); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_OPEN_AND_CLOSE_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteSoftApOpenAndCloseFailedEvent(int operateType, std::string failReason) { WIFI_LOGE("WriteSoftApOpenAndCloseFailedEvent operateType=%{public}d", operateType); - Json::Value root; - Json::FastWriter writer; - root["OPERATE_TYPE"] = operateType; - root["FAIL_REASON"] = failReason; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_OPEN_AND_CLOSE_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "OPERATE_TYPE", operateType); + cJSON_AddStringToObject(root, "FAIL_REASON", failReason.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_OPEN_AND_CLOSE_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - -void WriteWifiAccessIntFailedHiSysEvent(int operateRes, int failCnt, int selfCureResetState, - std::string selfCureHistory) + +void WriteWifiAccessIntFailedHiSysEvent( + int operateRes, int failCnt, int selfCureResetState, std::string selfCureHistory) { - Json::Value root; - Json::FastWriter writer; - root["OPERATE_TYPE"] = operateRes; - root["FAIL_CNT"] = failCnt; - root["RESET_STATE"] = selfCureResetState; - root["SELF_CURE_HISTORY"] = selfCureHistory; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ACCESS_INTERNET_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "OPERATE_TYPE", operateRes); + cJSON_AddNumberToObject(root, "FAIL_CNT", failCnt); + cJSON_AddNumberToObject(root, "RESET_STATE", selfCureResetState); + cJSON_AddStringToObject(root, "SELF_CURE_HISTORY", selfCureHistory.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ACCESS_INTERNET_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiPnoScanHiSysEvent(int isStartScan, int suspendReason) { - Json::Value root; - Json::FastWriter writer; - root["IS_START"] = isStartScan; - root["SUSPEND_REASON"] = suspendReason; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_PNO_SCAN_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "IS_START", isStartScan); + cJSON_AddNumberToObject(root, "SUSPEND_REASON", suspendReason); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_PNO_SCAN_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteBrowserFailedForPortalHiSysEvent(int respCode, std::string &server) { - Json::Value root; - Json::FastWriter writer; - root["RESP_CODE"] = respCode; - root["SERVER"] = server; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "BROWSER_FAILED_FOR_PORTAL", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "RESP_CODE", respCode); + cJSON_AddStringToObject(root, "SERVER", server.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "BROWSER_FAILED_FOR_PORTAL", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteAuthFailHiSysEvent(const std::string &authFailReason, int subErrCode) { - Json::Value root; - Json::FastWriter writer; - root["FAIL_REASON"] = authFailReason; - root["SUB_ERR_CODE"] = subErrCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTH_FAIL_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "FAIL_REASON", authFailReason.c_str()); + cJSON_AddNumberToObject(root, "SUB_ERR_CODE", subErrCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTH_FAIL_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteAssocFailHiSysEvent(const std::string &assocFailReason, int subErrCode) { - Json::Value root; - Json::FastWriter writer; - root["FAIL_REASON"] = assocFailReason; - root["SUB_ERR_CODE"] = subErrCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ASSOC_FAIL_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "FAIL_REASON", assocFailReason.c_str()); + cJSON_AddNumberToObject(root, "SUB_ERR_CODE", subErrCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_ASSOC_FAIL_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } void WriteDhcpFailHiSysEvent(const std::string &dhcpFailReason, int subErrCode) { - Json::Value root; - Json::FastWriter writer; - root["FAIL_REASON"] = dhcpFailReason; - root["SUB_ERR_CODE"] = subErrCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_DHCP_FAIL_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "FAIL_REASON", dhcpFailReason.c_str()); + cJSON_AddNumberToObject(root, "SUB_ERR_CODE", subErrCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_DHCP_FAIL_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteScanLimitHiSysEvent(const std::string &scanInitiator, int scanLimitType, bool isForeground) { if (scanInitiator.empty()) { return; } - Json::Value root; - Json::FastWriter writer; - root["SCAN_INITIATOR"] = scanInitiator; - root["IS_FOREGROUND"] = isForeground; - root["SCAN_LIMIT_TYPE"] = scanLimitType; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_SCAN_LIMIT_STATISTICS", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "SCAN_INITIATOR", scanInitiator.c_str()); + cJSON_AddBoolToObject(root, "IS_FOREGROUND", isForeground); + cJSON_AddNumberToObject(root, "SCAN_LIMIT_TYPE", scanLimitType); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_SCAN_LIMIT_STATISTICS", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteAutoConnectFailEvent(const std::string &failReason, const std::string &subReason) { - Json::Value root; - Json::FastWriter writer; - root["FAIL_REASON"] = failReason; - root["SUB_REASON"] = subReason; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTO_RECONNECT_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "FAIL_REASON", failReason.c_str()); + cJSON_AddStringToObject(root, "SUB_REASON", subReason.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTO_RECONNECT_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteP2pKpiCountHiSysEvent(int eventType) { - Json::Value root; - Json::FastWriter writer; - root["EVENT_TYPE"] = eventType; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_CONNECT_STATICS", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "EVENT_TYPE", eventType); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_CONNECT_STATICS", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteP2pConnectFailedHiSysEvent(int errCode, int failRes) { - Json::Value root; - Json::FastWriter writer; - root["EVENT_TYPE"] = errCode; - root["FAIL_RES"] = failRes; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_CONNECT_FAIL", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "EVENT_TYPE", errCode); + cJSON_AddNumberToObject(root, "FAIL_RES", failRes); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_CONNECT_FAIL", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteP2pAbDisConnectHiSysEvent(int errCode, int failRes) { - Json::Value root; - Json::FastWriter writer; - root["EVENT_TYPE"] = errCode; - root["FAIL_RES"] = failRes; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_ABNORMAL_DISCONNECT", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "EVENT_TYPE", errCode); + cJSON_AddNumberToObject(root, "FAIL_RES", failRes); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "P2P_ABNORMAL_DISCONNECT", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteSoftApAbDisconnectHiSysEvent(int errorCode) { - Json::Value root; - Json::FastWriter writer; - root["ERROR_CODE"] = errorCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_ABNORMAL_DISCONNECT", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ERROR_CODE", errorCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_ABNORMAL_DISCONNECT", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteIsInternetHiSysEvent(int isInternet) { - Json::Value root; - Json::FastWriter writer; - root["IS_INTERNET"] = isInternet; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_KPI_INTERNET", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "IS_INTERNET", isInternet); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_KPI_INTERNET", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteSoftApConnectFailHiSysEvent(int errorCnt) { WIFI_LOGE("WriteSoftApConnectFailHiSysEvent errorCnt=%{public}d", errorCnt); - Json::Value root; - Json::FastWriter writer; - root["ERROR_CODE"] = errorCnt; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_CONNECT_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ERROR_CODE", errorCnt); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_CONNECT_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteSoftApClientAccessNetErrorHiSysEvent(int errorCode) { WIFI_LOGE("WriteSoftApClientAccessNetErrorHiSysEvent errorCode=%{public}d", errorCode); - Json::Value root; - Json::FastWriter writer; - root["ERROR_CODE"] = errorCode; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_CLIENT_ACCESS_NET_ERROR", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ERROR_CODE", errorCode); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "SOFTAP_CLIENT_ACCESS_NET_ERROR", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - -void WriteWifiScanApiFailHiSysEvent(const std::string& pkgName, const WifiScanFailReason failReason) + +void WriteWifiScanApiFailHiSysEvent(const std::string &pkgName, const WifiScanFailReason failReason) { #ifndef OHOS_ARCH_LITE - Json::Value root; - Json::FastWriter writer; - root["PKG_NAME"] = pkgName; - root["FAIL_REASON"] = static_cast(failReason); - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFISCANCONTROL_TRIGGER_API_FAIL", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "PKG_NAME", pkgName.c_str()); + cJSON_AddNumberToObject(root, "FAIL_REASON", static_cast(failReason)); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFISCANCONTROL_TRIGGER_API_FAIL", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); #endif } - -void WriteWifiEncryptionFailHiSysEvent(int event, const std::string& maskSsid, const std::string &keyMgmt, int encryptedModule) + +void WriteWifiEncryptionFailHiSysEvent( + int event, const std::string &maskSsid, const std::string &keyMgmt, int encryptedModule) { - Json::Value root; - Json::FastWriter writer; - root["ENCRY_OR_DECRY_EVENT"] = event; - root["SSID"] = maskSsid; - root["ENCRYKEYMANAGEMENT"] = keyMgmt; - root["ENCRYEVENTMODULE"] = encryptedModule; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFIENCRY_OR_DECRY_FAIL", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ENCRY_OR_DECRY_EVENT", event); + cJSON_AddStringToObject(root, "SSID", maskSsid.c_str()); + cJSON_AddStringToObject(root, "ENCRYKEYMANAGEMENT", keyMgmt.c_str()); + cJSON_AddNumberToObject(root, "ENCRYEVENTMODULE", encryptedModule); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFIENCRY_OR_DECRY_FAIL", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WritePortalStateHiSysEvent(int portalState) { - Json::Value root; - Json::FastWriter writer; - root["PORTAL_STATE"] = portalState; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_PORTAL_STATE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "PORTAL_STATE", portalState); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_PORTAL_STATE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteArpInfoHiSysEvent(uint64_t arpRtt, int32_t arpFailedCount, int32_t gatewayCnt) { - Json::Value root; - Json::FastWriter writer; - root["ARP_RTT"] = arpRtt; - root["ARP_FAILED_COUNT"] = arpFailedCount; - root["ARP_GWCOUNT"] = gatewayCnt; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_ARP_DETECTION_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "ARP_RTT", static_cast(arpRtt)); + cJSON_AddNumberToObject(root, "ARP_FAILED_COUNT", arpFailedCount); + cJSON_AddNumberToObject(root, "ARP_GWCOUNT", gatewayCnt); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_ARP_DETECTION_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteLinkInfoHiSysEvent(int signalLevel, int rssi, int band, int linkSpeed) { - Json::Value root; - Json::FastWriter writer; - root["LEVEL"] = signalLevel; - root["BAND"] = band; - root["RSSI"] = rssi; - root["LINKSPEED"] = linkSpeed; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_LINK_INFO", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "LEVEL", signalLevel); + cJSON_AddNumberToObject(root, "BAND", band); + cJSON_AddNumberToObject(root, "RSSI", rssi); + cJSON_AddNumberToObject(root, "LINKSPEED", linkSpeed); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_LINK_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteConnectTypeHiSysEvent(int connectType, bool isFirstConnect) { - Json::Value root; - Json::FastWriter writer; + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } std::string connectTypeStr = ""; if (g_connectTypeTransMap.find(connectType) != g_connectTypeTransMap.end()) { connectTypeStr = g_connectTypeTransMap.at(connectType); @@ -363,167 +664,297 @@ void WriteConnectTypeHiSysEvent(int connectType, bool isFirstConnect) if (isFirstConnect) { connectTypeStr = "FIRST_CONNECT"; } - root["CONNECT_TYPE"] = connectTypeStr; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_CONNECT_TYPE", "EVENT_VALUE", writer.write(root)); + cJSON_AddStringToObject(root, "CONNECT_TYPE", connectTypeStr.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "_CONNECT_TYPE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiLinkTypeHiSysEvent(const std::string &ssid, int32_t wifiLinkType, const std::string &triggerReason) { - Json::Value root; - Json::FastWriter writer; - root["SSID"] = ssid; - root["WIFI_LINK_TYPE"] = wifiLinkType; - root["TRIGGER_REASON"] = triggerReason; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_LINK_TYPE_UPDATE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "SSID", ssid.c_str()); + cJSON_AddNumberToObject(root, "WIFI_LINK_TYPE", wifiLinkType); + cJSON_AddStringToObject(root, "TRIGGER_REASON", triggerReason.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_LINK_TYPE_UPDATE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteEmlsrExitReasonHiSysEvent(const std::string &ssid, int32_t reason) { - Json::Value root; - Json::FastWriter writer; - root["SSID"] = ssid; - root["EMLSR_EXIT_REASON"] = reason; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_EMLSR_EXIT_REASON", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "SSID", ssid.c_str()); + cJSON_AddNumberToObject(root, "EMLSR_EXIT_REASON", reason); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WIFI_EMLSR_EXIT_REASON", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteStaConnectIface(const std::string &ifName) { - Json::Value root; - Json::FastWriter writer; - root["IFACE_NAME"] = ifName; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_STA_CONNECT_IFNAME", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "IFACE_NAME", ifName.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_STA_CONNECT_IFNAME", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiWpaStateHiSysEvent(int state) { - Json::Value root; - Json::FastWriter writer; - root["WPA_STATE"] = state; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WPA_STATE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "WPA_STATE", state); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "EVENT_WPA_STATE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - -void WritePortalAuthExpiredHisysevent(int respCode, int detectNum, time_t connTime, - time_t portalAuthTime, bool isNotificationClicked) + +void WritePortalAuthExpiredHisysevent( + int respCode, int detectNum, time_t connTime, time_t portalAuthTime, bool isNotificationClicked) { - Json::Value root; - Json::FastWriter writer; + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } time_t now = time(nullptr); if (now < 0) { now = 0; } - int64_t authDura = (now > 0 && portalAuthTime > 0 && now > portalAuthTime) ? now - portalAuthTime : 0; - int64_t connDura = (now > 0 && connTime > 0 && now > connTime) ? now - connTime : 0; + int64_t authDura = (now > 0 && portalAuthTime > 0 && now > portalAuthTime) ? (now - portalAuthTime) : 0; + int64_t connDura = (now > 0 && connTime > 0 && now > connTime) ? (now - connTime) : 0; int64_t authCostDura = - (portalAuthTime > 0 && connTime > 0 && portalAuthTime > connTime) ? portalAuthTime - connTime : 0; - root["RESP_CODE"] = respCode; - root["DURA"] = authDura; - root["CONN_DURA"] = connDura; - root["AUTH_COST_DURA"] = authCostDura; - root["DET_NUM"] = detectNum; - root["IS_NOTIFICA_CLICKED"] = isNotificationClicked ? 1 : 0; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "PORTAL_AUTH_EXPIRED", "EVENT_VALUE", writer.write(root)); + (portalAuthTime > 0 && connTime > 0 && portalAuthTime > connTime) ? (portalAuthTime - connTime) : 0; + cJSON_AddNumberToObject(root, "RESP_CODE", respCode); + cJSON_AddNumberToObject(root, "DURA", authDura); + cJSON_AddNumberToObject(root, "CONN_DURA", connDura); + cJSON_AddNumberToObject(root, "AUTH_COST_DURA", authCostDura); + cJSON_AddNumberToObject(root, "DET_NUM", detectNum); + cJSON_AddBoolToObject(root, "IS_NOTIFICA_CLICKED", isNotificationClicked); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "PORTAL_AUTH_EXPIRED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteWifiSelfcureHisysevent(int type) { - Json::Value root; - Json::FastWriter writer; - root["WIFI_SELFCURE_TYPE"] = type; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_SELFCURE", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "WIFI_SELFCURE_TYPE", type); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_SELFCURE", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void Write3VapConflictHisysevent(int type) { - Json::Value root; - Json::FastWriter writer; - root["WIFI_3VAP_CONFLICT_TYPE"] = type; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_3VAP_CONFLICT", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "WIFI_3VAP_CONFLICT_TYPE", type); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_3VAP_CONFLICT", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void Write5gPrefFailedHisysevent(Pref5gStatisticsInfo &info) { int64_t conDuration = 0; if (info.isIn5gPref && !info.has5gPrefSwitch) { if (info.noInternetTime != std::chrono::steady_clock::time_point::min()) { - info.durationNoInternet += std::chrono::duration_cast(std::chrono::steady_clock::now() - - info.noInternetTime).count(); + info.durationNoInternet += + std::chrono::duration_cast(std::chrono::steady_clock::now() - info.noInternetTime) + .count(); } if (info.connectTime != std::chrono::steady_clock::time_point::min()) { - conDuration = std::chrono::duration_cast(std::chrono::steady_clock::now() - - info.connectTime).count(); + conDuration = + std::chrono::duration_cast(std::chrono::steady_clock::now() - info.connectTime) + .count(); + } + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; } - Json::Value root; - Json::FastWriter writer; - root["BSSID"] = info.bssid; - root["SSID"] = info.ssid; - root["FREQ"] = info.freq; - root["CON_DURATION"] = conDuration; - root["DURATION_NO_INTERNET"] = info.durationNoInternet; - root["ENTER_MONITOR_NUM"] = info.enterMonitorNum; - root["MONITOR_ACTIVE_SCAN_NUM"] = info.monitorActiveScanNum; - root["RELA_5G_NUM"] = info.rela5gNum; - root["NOT_ADJ_5g_NUM"] = info.notAdj5gNum; - root["NOT_INTERNET_RELA_5G_NUM"] = info.notInternetRela5gNum; - root["ALL_RELA_5G_IN_BLOCK_LIST_NUM"] = info.allRela5gInBlockListNum; - root["SATISFY_NO_SELECTED_NUM"] = info.satisfySwitchRssiNoSelectedNum; - root["IS_USER_CONNECTED"] = (info.isUserConnected) ? 1 : 0; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_5G_PREF_FAILED", "EVENT_VALUE", writer.write(root)); + cJSON_AddStringToObject(root, "BSSID", info.bssid.c_str()); + cJSON_AddStringToObject(root, "SSID", info.ssid.c_str()); + cJSON_AddNumberToObject(root, "FREQ", info.freq); + cJSON_AddNumberToObject(root, "CON_DURATION", conDuration); + cJSON_AddNumberToObject(root, "DURATION_NO_INTERNET", info.durationNoInternet); + cJSON_AddNumberToObject(root, "ENTER_MONITOR_NUM", info.enterMonitorNum); + cJSON_AddNumberToObject(root, "MONITOR_ACTIVE_SCAN_NUM", info.monitorActiveScanNum); + cJSON_AddNumberToObject(root, "RELA_5G_NUM", info.rela5gNum); + cJSON_AddNumberToObject(root, "NOT_ADJ_5g_NUM", info.notAdj5gNum); + cJSON_AddNumberToObject(root, "NOT_INTERNET_RELA_5G_NUM", info.notInternetRela5gNum); + cJSON_AddNumberToObject(root, "ALL_RELA_5G_IN_BLOCK_LIST_NUM", info.allRela5gInBlockListNum); + cJSON_AddNumberToObject(root, "SATISFY_NO_SELECTED_NUM", info.satisfySwitchRssiNoSelectedNum); + cJSON_AddNumberToObject(root, "IS_USER_CONNECTED", info.isUserConnected ? 1 : 0); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_5G_PREF_FAILED", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } } - -void WriteAutoSelectHiSysEvent(int selectType, const std::string &selectedInfo, - const std::string &filteredReason, const std::string &savedResult) + +void WriteAutoSelectHiSysEvent( + int selectType, const std::string &selectedInfo, const std::string &filteredReason, const std::string &savedResult) { - Json::Value root; - Json::FastWriter writer; - root["AUTO_SELECT_TYPE"] = selectType; - root["AUTO_SELECT_RESULT"] = selectedInfo; - root["AUTO_SELECT_FILTER"] = filteredReason; - root["SAVED_NETWORK_IN_SCAN"] = savedResult; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTO_SELECT_STATISTIC", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "AUTO_SELECT_TYPE", selectType); + cJSON_AddStringToObject(root, "AUTO_SELECT_RESULT", selectedInfo.c_str()); + cJSON_AddStringToObject(root, "AUTO_SELECT_FILTER", filteredReason.c_str()); + cJSON_AddStringToObject(root, "SAVED_NETWORK_IN_SCAN", savedResult.c_str()); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_AUTO_SELECT_STATISTIC", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteDhcpInfoHiSysEvent(const IpInfo &ipInfo, const IpV6Info &ipv6Info) { - Json::Value root; - Json::FastWriter writer; - root["IPV4_IPADDRESS"] = Ipv4IntAnonymize(ipInfo.ipAddress); - root["IPV4_GATEWAY"] = Ipv4IntAnonymize(ipInfo.gateway); - root["IPV4_NETMASK"] = Ipv4IntAnonymize(ipInfo.netmask); - root["IPV4_PRIMARYDNS"] = Ipv4IntAnonymize(ipInfo.primaryDns); - root["IPV4_SECONDDNS"] = Ipv4IntAnonymize(ipInfo.secondDns); - root["IPV4_SERVERIP"] = Ipv4IntAnonymize(ipInfo.serverIp); - root["IPV4_LEASE"] = ipInfo.leaseDuration; - root["IPV4_DNS_VEC_SIZE"] = static_cast(ipInfo.dnsAddr.size()); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddStringToObject(root, "IPV4_IPADDRESS", Ipv4IntAnonymize(ipInfo.ipAddress).c_str()); + cJSON_AddStringToObject(root, "IPV4_GATEWAY", Ipv4IntAnonymize(ipInfo.gateway).c_str()); + cJSON_AddStringToObject(root, "IPV4_NETMASK", Ipv4IntAnonymize(ipInfo.netmask).c_str()); + cJSON_AddStringToObject(root, "IPV4_PRIMARYDNS", Ipv4IntAnonymize(ipInfo.primaryDns).c_str()); + cJSON_AddStringToObject(root, "IPV4_SECONDDNS", Ipv4IntAnonymize(ipInfo.secondDns).c_str()); + cJSON_AddStringToObject(root, "IPV4_SERVERIP", Ipv4IntAnonymize(ipInfo.serverIp).c_str()); + cJSON_AddNumberToObject(root, "IPV4_LEASE", ipInfo.leaseDuration); + cJSON_AddNumberToObject(root, "IPV4_DNS_VEC_SIZE", static_cast(ipInfo.dnsAddr.size())); for (size_t i = 0; i < ipInfo.dnsAddr.size(); i++) { if (i >= MAX_DNS_NUM) { WIFI_LOGE("ipInfo.dnsAddr size over limit"); break; } std::string keyString = "IPV4_DNS" + std::to_string(i); - root[keyString] = Ipv4IntAnonymize(ipInfo.dnsAddr[i]); - } - root["IPV6_LINKIPV6ADDR"] = Ipv6Anonymize(ipv6Info.linkIpV6Address); - root["IPV6_GLOBALIPV6ADDR"] = Ipv6Anonymize(ipv6Info.globalIpV6Address); - root["IPV6_RANDGLOBALIPV6ADDR"] = Ipv6Anonymize(ipv6Info.randGlobalIpV6Address); - root["IPV6_GATEWAY"] = Ipv6Anonymize(ipv6Info.gateway); - root["IPV6_NETMASK"] = Ipv6Anonymize(ipv6Info.netmask); - root["IPV6_PRIMARYDNS"] = Ipv6Anonymize(ipv6Info.primaryDns); - root["IPV6_SECONDDNS"] = Ipv6Anonymize(ipv6Info.secondDns); - root["IPV6_UNIQUELOCALADDR1"] = Ipv6Anonymize(ipv6Info.uniqueLocalAddress1); - root["IPV6_UNIQUELOCALADDR2"] = Ipv6Anonymize(ipv6Info.uniqueLocalAddress2); - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_DHCP_INFO", "EVENT_VALUE", writer.write(root)); + cJSON_AddStringToObject(root, keyString.c_str(), Ipv4IntAnonymize(ipInfo.dnsAddr[i]).c_str()); + } + cJSON_AddStringToObject(root, "IPV6_LINKIPV6ADDR", Ipv6Anonymize(ipv6Info.linkIpV6Address).c_str()); + cJSON_AddStringToObject(root, "IPV6_GLOBALIPV6ADDR", Ipv6Anonymize(ipv6Info.globalIpV6Address).c_str()); + cJSON_AddStringToObject(root, "IPV6_RANDGLOBALIPV6ADDR", Ipv6Anonymize(ipv6Info.randGlobalIpV6Address).c_str()); + cJSON_AddStringToObject(root, "IPV6_GATEWAY", Ipv6Anonymize(ipv6Info.gateway).c_str()); + cJSON_AddStringToObject(root, "IPV6_NETMASK", Ipv6Anonymize(ipv6Info.netmask).c_str()); + cJSON_AddStringToObject(root, "IPV6_PRIMARYDNS", Ipv6Anonymize(ipv6Info.primaryDns).c_str()); + cJSON_AddStringToObject(root, "IPV6_SECONDDNS", Ipv6Anonymize(ipv6Info.secondDns).c_str()); + cJSON_AddStringToObject(root, "IPV6_UNIQUELOCALADDR1", Ipv6Anonymize(ipv6Info.uniqueLocalAddress1).c_str()); + cJSON_AddStringToObject(root, "IPV6_UNIQUELOCALADDR2", Ipv6Anonymize(ipv6Info.uniqueLocalAddress2).c_str()); + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_DHCP_INFO", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } - + void WriteIodHiSysEvent(const IodStatisticInfo &iodStatisticInfo) { - Json::Value root; - Json::FastWriter writer; - root["OUTDOORFILTERCNT"] = iodStatisticInfo.outdoorFilterCnt; - root["OUTDOORSELECTWIFICNT"] = iodStatisticInfo.outdoorAutoSelectCnt; - root["INTOOUTDOORCNT"] = iodStatisticInfo.in2OutCnt; - root["OUTTOINDOORCNT"] = iodStatisticInfo.out2InCnt; - WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_IOD_STATISTIC", "EVENT_VALUE", writer.write(root)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + WIFI_LOGE("Failed to create cJSON object"); + return; + } + cJSON_AddNumberToObject(root, "OUTDOORFILTERCNT", iodStatisticInfo.outdoorFilterCnt); + cJSON_AddNumberToObject(root, "OUTDOORSELECTWIFICNT", iodStatisticInfo.outdoorAutoSelectCnt); + cJSON_AddNumberToObject(root, "INTOOUTDOORCNT", iodStatisticInfo.in2OutCnt); + cJSON_AddNumberToObject(root, "OUTTOINDOORCNT", iodStatisticInfo.out2InCnt); + + char *jsonStr = cJSON_PrintUnformatted(root); + if (jsonStr == nullptr) { + cJSON_Delete(root); + return; + } + WriteEvent("WIFI_CHR_EVENT", "EVENT_NAME", "WIFI_IOD_STATISTIC", "EVENT_VALUE", std::string(jsonStr)); + free(jsonStr); + cJSON_Delete(root); } } // namespace Wifi } // namespace OHOS \ No newline at end of file