diff --git a/bundle.json b/bundle.json index fa3dc112239a677ea6e51d963f59b54934ce2a90..4e968f3897ac023b70a71ec9dc5fcd9f5770b62a 100644 --- a/bundle.json +++ b/bundle.json @@ -64,6 +64,7 @@ "battery_manager", "common_event_service", "config_policy", + "cJSON", "c_utils", "data_share", "display_manager", @@ -82,7 +83,6 @@ "input", "ipc", "image_framework", - "jsoncpp", "libxml2", "napi", "os_account", diff --git a/services/BUILD.gn b/services/BUILD.gn index c1495f03bdc426aee8679f3a5327bc4840913886..22e404ad59263f0da6b01dabdc922acfe68adcbc 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -107,6 +107,7 @@ ohos_shared_library("powermgrservice") { "ability_base:want", "ability_runtime:ability_connect_callback_stub", "bundle_framework:appexecfwk_core", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", @@ -123,7 +124,6 @@ ohos_shared_library("powermgrservice") { "image_framework:image_native", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "libxml2:libxml2", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/native/src/power_mode_policy.cpp b/services/native/src/power_mode_policy.cpp index 469871e99fee7fa5edff3d5b6e04b7cea9ea9ac7..3c41558d6ac8aa8c6e342fef9d348d0f00433d24 100644 --- a/services/native/src/power_mode_policy.cpp +++ b/services/native/src/power_mode_policy.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ +#include #include "power_mode_policy.h" #include "power_mgr_service.h" #include "power_log.h" #include "power_save_mode.h" #include "singleton.h" #include "setting_helper.h" -#include "json/json.h" using namespace std; namespace OHOS { @@ -68,20 +68,30 @@ void PowerModePolicy::ComparePowerModePolicy() bool PowerModePolicy::InitRecoverMap() { std::string jsonStr = SettingHelper::ReadPowerModeRecoverMap(); - Json::Value recoverJson; - Json::Reader reader; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), recoverJson)) { + + cJSON* recoverJson = cJSON_Parse(jsonStr.c_str()); + if (!recoverJson) { POWER_HILOGW(FEATURE_POWER_MODE, "parse recover json str error"); return false; } - for (const auto &member : recoverJson.getMemberNames()) { - int32_t key = std::stoi(member); - if (!recoverJson[member].isInt()) { + if (!cJSON_IsObject(recoverJson)) { + POWER_HILOGW(FEATURE_POWER_MODE, "recover json root is not an object"); + cJSON_Delete(recoverJson); + return false; + } + cJSON* item = nullptr; + cJSON_ArrayForEach(item, recoverJson) { + const char* keyStr = item->string; + if (!keyStr || !cJSON_IsNumber(item)) { continue; } - int32_t value = recoverJson[member].asInt(); + + int32_t key = std::stoi(keyStr); + int32_t value = static_cast(item->valueint); recoverMap_[key] = value; } + + cJSON_Delete(recoverJson); POWER_HILOGI(FEATURE_POWER_MODE, "init recover map succeed"); return true; } @@ -193,11 +203,27 @@ void PowerModePolicy::RemoveBackupMapSettingSwitch(uint32_t switchId) void PowerModePolicy::SavePowerModeRecoverMap() { - Json::Value recoverJson; + cJSON* recoverJson = cJSON_CreateObject(); + if (!recoverJson) { + POWER_HILOGE(FEATURE_POWER_MODE, "Failed to create cJSON object"); + return; + } + for (const auto& pair : recoverMap_) { - recoverJson[to_string(pair.first)] = pair.second; + std::string keyStr = std::to_string(pair.first); + cJSON_AddNumberToObject(recoverJson, keyStr.c_str(), pair.second); + } + + char* jsonStr = cJSON_Print(recoverJson); + if (!jsonStr) { + POWER_HILOGE(FEATURE_POWER_MODE, "Failed to print cJSON to string"); + cJSON_Delete(recoverJson); + return; } - SettingHelper::SavePowerModeRecoverMap(recoverJson.toStyledString()); + std::string jsonConfig = std::string(jsonStr); + SettingHelper::SavePowerModeRecoverMap(jsonConfig); + cJSON_free(jsonStr); + cJSON_Delete(recoverJson); } } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/shutdown/shutdown_dialog.cpp b/services/native/src/shutdown/shutdown_dialog.cpp index 536f8820a5a9222d231c9842c8e6955727278f5f..ab3d15c10e594b317c38d4b0681296555cbf210b 100644 --- a/services/native/src/shutdown/shutdown_dialog.cpp +++ b/services/native/src/shutdown/shutdown_dialog.cpp @@ -27,11 +27,10 @@ #include #include #endif +#include #include #include "config_policy_utils.h" -#include "json/reader.h" -#include "json/value.h" #include "power_log.h" #include "power_mgr_service.h" #include "power_vibrator.h" @@ -187,30 +186,41 @@ void ShutdownDialog::LoadDialogConfig() std::ifstream inputStream(configPath, std::ios::in | std::ios::binary); std::string contentStr(std::istreambuf_iterator {inputStream}, std::istreambuf_iterator {}); - Json::Reader reader; - Json::Value root; - if (!reader.parse(contentStr.data(), contentStr.data() + contentStr.size(), root)) { - POWER_HILOGE(COMP_UTILS, "json parse error"); + if (contentStr.empty()) { + POWER_HILOGE(COMP_UTILS, "json file is empty"); return; } - if (root.isNull() || !root.isObject()) { - POWER_HILOGE(COMP_UTILS, "json root invalid[%{public}s]", contentStr.c_str()); + cJSON* root = cJSON_Parse(contentStr.c_str()); + if (!root) { + POWER_HILOGE(COMP_UTILS, "json parse error[%{public}s]", contentStr.c_str()); return; } - - if (!root["bundleName"].isString() || - !root["abilityName"].isString() || !root["uiExtensionType"].isString()) { - POWER_HILOGE(COMP_UTILS, "json varibale not support"); + + if (!cJSON_IsObject(root)) { + POWER_HILOGE(COMP_UTILS, "json root invalid"); + cJSON_Delete(root); + return; + } + + cJSON* bundleNameItem = cJSON_GetObjectItemCaseSensitive(root, "bundleName"); + cJSON* abilityNameItem = cJSON_GetObjectItemCaseSensitive(root, "abilityName"); + cJSON* uiExtensionTypeItem = cJSON_GetObjectItemCaseSensitive(root, "uiExtensionType"); + if (!bundleNameItem || !cJSON_IsString(bundleNameItem) || + !abilityNameItem || !cJSON_IsString(abilityNameItem) || + !uiExtensionTypeItem || !cJSON_IsString(uiExtensionTypeItem)) { + POWER_HILOGE(COMP_UTILS, "json variable not supported"); + cJSON_Delete(root); return; } - bundleName_ = root["bundleName"].asString(); - abilityName_ = root["abilityName"].asString(); - uiExtensionType_ = root["uiExtensionType"].asString(); - dialogBundleName_ = root["bundleName"].asString(); + bundleName_ = bundleNameItem->valuestring; + abilityName_ = abilityNameItem->valuestring; + uiExtensionType_ = uiExtensionTypeItem->valuestring; + dialogBundleName_ = bundleNameItem->valuestring; dialogAbilityName_ = "com.ohos.sceneboard.systemdialog"; POWER_HILOGI(COMP_UTILS, "PowerOff variables have changed"); + cJSON_Delete(root); } void ShutdownDialog::DialogAbilityConnection::OnAbilityConnectDone( diff --git a/services/native/src/suspend/suspend_source_parser.cpp b/services/native/src/suspend/suspend_source_parser.cpp index 6d835c74594829e68f6a977678727ae7bcc521e7..66f9f7491cc22a80b2502a3daa358dad5392667d 100644 --- a/services/native/src/suspend/suspend_source_parser.cpp +++ b/services/native/src/suspend/suspend_source_parser.cpp @@ -18,11 +18,11 @@ #include #include +#include + #include "config_policy_utils.h" #include "power_log.h" #include "setting_helper.h" -#include "json/reader.h" -#include "json/value.h" #ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING #include "power_mgr_service.h" #endif @@ -152,36 +152,40 @@ bool SuspendSourceParser::GetTargetPath(std::string& targetPath) std::shared_ptr SuspendSourceParser::ParseSources(const std::string& jsonStr) { std::shared_ptr parseSources = std::make_shared(); - Json::Reader reader; - Json::Value root; - std::string errors; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { POWER_HILOGE(FEATURE_SUSPEND, "json parse error"); parseSources->SetParseErrorFlag(true); return parseSources; } - - if (root.isNull() || !root.isObject()) { + if (!cJSON_IsObject(root)) { POWER_HILOGE(FEATURE_SUSPEND, "json root invalid[%{public}s]", jsonStr.c_str()); parseSources->SetParseErrorFlag(true); + cJSON_Delete(root); return parseSources; } - Json::Value::Members members = root.getMemberNames(); - for (auto iter = members.begin(); iter != members.end(); iter++) { - std::string key = *iter; - Json::Value valueObj = root[key]; - bool ret = ParseSourcesProc(parseSources, valueObj, key); + cJSON* item = nullptr; + cJSON_ArrayForEach(item, root) { + const char* key = item->string; + if (!key) { + POWER_HILOGI(FEATURE_SUSPEND, "invalid key in json object"); + continue; + } + std::string keyStr = std::string(key); + bool ret = ParseSourcesProc(parseSources, item, keyStr); if (ret == false) { POWER_HILOGI(FEATURE_SUSPEND, "lost map config key"); continue; } } + + cJSON_Delete(root); return parseSources; } bool SuspendSourceParser::ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key) { if (parseSources == nullptr) { POWER_HILOGE(FEATURE_SUSPEND, "parseSources is nullptr"); @@ -195,12 +199,12 @@ bool SuspendSourceParser::ParseSourcesProc( uint32_t action = 0; uint32_t delayMs = 0; - if (!valueObj.isNull() && valueObj.isObject()) { - Json::Value actionValue = valueObj[SuspendSource::ACTION_KEY]; - Json::Value delayValue = valueObj[SuspendSource::DELAY_KEY]; - if (actionValue.isUInt() && delayValue.isUInt()) { - action = actionValue.asUInt(); - delayMs = delayValue.asUInt(); + if (valueObj && cJSON_IsObject(valueObj)) { + cJSON* actionValue = cJSON_GetObjectItemCaseSensitive(valueObj, SuspendSource::ACTION_KEY); + cJSON* delayValue = cJSON_GetObjectItemCaseSensitive(valueObj, SuspendSource::DELAY_KEY); + if (actionValue && cJSON_IsNumber(actionValue) && delayValue && cJSON_IsNumber(delayValue)) { + action = static_cast(actionValue->valueint); + delayMs = static_cast(delayValue->valueint); if (action >= ILLEGAL_ACTION) { action = 0; } diff --git a/services/native/src/suspend/suspend_source_parser.h b/services/native/src/suspend/suspend_source_parser.h index f209d4d6a894b9882b4f0d532027374885a77ac3..6b2e5b6591bab0aca77eaa0969ff8a2b5eb25245 100644 --- a/services/native/src/suspend/suspend_source_parser.h +++ b/services/native/src/suspend/suspend_source_parser.h @@ -19,8 +19,8 @@ #include #include +#include #include "suspend_sources.h" -#include "json/value.h" namespace OHOS { namespace PowerMgr { @@ -30,7 +30,7 @@ public: static std::shared_ptr ParseSources(const std::string& config); static bool GetTargetPath(std::string& targetPath); static bool ParseSourcesProc( - std::shared_ptr &parseSources, Json::Value& valueObj, std::string& key); + std::shared_ptr &parseSources, cJSON* valueObj, std::string& key); static const std::string GetSuspendSourcesByConfig(); }; } // namespace PowerMgr diff --git a/services/native/src/wakeup/wakeup_controller.cpp b/services/native/src/wakeup/wakeup_controller.cpp index bb2e2a1f76e0f8482a8db036cb753ae2ba2badd2..6e23002a3f0f2f210526604b614b11df08d10668 100644 --- a/services/native/src/wakeup/wakeup_controller.cpp +++ b/services/native/src/wakeup/wakeup_controller.cpp @@ -23,9 +23,9 @@ #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include #endif +#include #include #include -#include #include #include "permission.h" #include "power_errors.h" @@ -198,33 +198,46 @@ void WakeupController::ChangeWakeupSourceConfig(bool updateEnable) return; } POWER_HILOGI(COMP_SVC, "the origin ccmJson is: %{public}s", jsonStr.c_str()); - Json::Value root; - Json::Reader reader; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { POWER_HILOGE(COMP_SVC, "json parse error"); return; } - if (root["touchscreen"].isNull()) { - POWER_HILOGE(COMP_SVC, "this touchscreenNode is empty"); + if (!cJSON_IsObject(root)) { + POWER_HILOGW(COMP_SVC, "json root is not an object"); + cJSON_Delete(root); return; } - if (root["touchscreen"]["enable"].isNull()) { - POWER_HILOGE(COMP_SVC, "the touchscreenNode is empty"); + cJSON* touchscreenNode = cJSON_GetObjectItemCaseSensitive(root, "touchscreen"); + if (!touchscreenNode || !cJSON_IsObject(touchscreenNode)) { + POWER_HILOGE(COMP_SVC, "this touchscreenNode is empty"); + cJSON_Delete(root); return; } - if (!root["touchscreen"]["enable"].isBool()) { - POWER_HILOGE(COMP_SVC, "the origin touchscreenEnable value is invalid"); + cJSON* enableNode = cJSON_GetObjectItemCaseSensitive(touchscreenNode, "enable"); + if (!enableNode || !cJSON_IsBool(enableNode)) { + POWER_HILOGE(COMP_SVC, "the touchscreenNode enable value is invalid"); + cJSON_Delete(root); return; } - bool originEnable = root["touchscreen"]["enable"].asBool(); + bool originEnable = cJSON_IsTrue(enableNode); if (originEnable == updateEnable) { POWER_HILOGI(COMP_SVC, "no need change jsonConfig value"); + cJSON_Delete(root); return; } - - root["touchscreen"]["enable"] = updateEnable; - POWER_HILOGI(COMP_SVC, "the new doubleJsonConfig is: %{public}s", root.toStyledString().c_str()); - SettingHelper::SetSettingWakeupSources(root.toStyledString()); + enableNode->valueint = updateEnable ? 1 : 0; + char* jsonUpdatedStr = cJSON_Print(root); + if (!jsonUpdatedStr) { + POWER_HILOGI(COMP_SVC, "Failed to print cJSON to string"); + cJSON_Delete(root); + return; + } + POWER_HILOGI(COMP_SVC, "the new doubleJsonConfig is: %{public}s", jsonUpdatedStr); + std::string jsonConfig = std::string(jsonUpdatedStr); + SettingHelper::SetSettingWakeupSources(jsonConfig); + cJSON_free(jsonUpdatedStr); + cJSON_Delete(root); } static const char* POWER_MANAGER_EXT_PATH = "libpower_manager_ext.z.so"; @@ -307,33 +320,46 @@ void WakeupController::ChangePickupWakeupSourceConfig(bool updataEnable) return; } POWER_HILOGI(COMP_SVC, "%{public}s(%{public}d)", __func__, updataEnable); - Json::Value root; - Json::Reader reader; - reader.parse(jsonStr, root); - if (!reader.parse(jsonStr, root)) { + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { POWER_HILOGE(COMP_SVC, "Failed to parse json string"); return; } - if (root["pickup"].isNull()) { - POWER_HILOGE(COMP_SVC, "this pickNode is empty"); + if (!cJSON_IsObject(root)) { + POWER_HILOGW(COMP_SVC, "json root is not an object"); + cJSON_Delete(root); return; } - if (root["pickup"]["enable"].isNull()) { - POWER_HILOGE(COMP_SVC, "the pickupNode is empty"); + cJSON* pickupNode = cJSON_GetObjectItemCaseSensitive(root, "pickup"); + if (!pickupNode || !cJSON_IsObject(pickupNode)) { + POWER_HILOGE(COMP_SVC, "this pickNode is empty"); + cJSON_Delete(root); return; } - if (!root["pickup"]["enable"].isBool()) { - POWER_HILOGE(COMP_SVC, "the origin pickupEnable value is invalid"); + cJSON* enableNode = cJSON_GetObjectItemCaseSensitive(pickupNode, "enable"); + if (!enableNode || !cJSON_IsBool(enableNode)) { + POWER_HILOGE(COMP_SVC, "the pickupNode enable value is invalid"); + cJSON_Delete(root); return; } - bool originEnable = root["pickup"]["enable"].asBool(); + bool originEnable = cJSON_IsTrue(enableNode); if (originEnable == updataEnable) { POWER_HILOGI(COMP_SVC, "no need change jsonconfig_value"); + cJSON_Delete(root); return; } - root["pickup"]["enable"] = updataEnable; - POWER_HILOGI(COMP_SVC, "the new pickupJsonConfig is: %{public}s", root.toStyledString().c_str()); - SettingHelper::SetSettingWakeupSources(root.toStyledString()); + enableNode->valueint = updataEnable ? 1 : 0; + char* jsonUpdatedStr = cJSON_Print(root); + if (!jsonUpdatedStr) { + POWER_HILOGI(COMP_SVC, "Failed to print cJSON to string"); + cJSON_Delete(root); + return; + } + POWER_HILOGI(COMP_SVC, "the new pickupJsonConfig is: %{public}s", jsonUpdatedStr); + std::string jsonConfig = std::string(jsonUpdatedStr); + SettingHelper::SetSettingWakeupSources(jsonConfig); + cJSON_free(jsonUpdatedStr); + cJSON_Delete(root); } #endif @@ -342,29 +368,49 @@ void WakeupController::ChangeLidWakeupSourceConfig(bool updataEnable) std::lock_guard lock(sourceUpdateMutex_); std::string jsonStr = SettingHelper::GetSettingWakeupSources(); POWER_HILOGI(FEATURE_POWER_STATE, "%{public}s", jsonStr.c_str()); - Json::Value root; - Json::Reader reader; - reader.parse(jsonStr, root); - if (!reader.parse(jsonStr, root)) { + + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { POWER_HILOGE(FEATURE_POWER_STATE, "Failed to parse json string"); return; } + if (!cJSON_IsObject(root)) { + POWER_HILOGW(FEATURE_POWER_STATE, "json root is not an object"); + cJSON_Delete(root); + return; + } + cJSON* lidNode = cJSON_GetObjectItemCaseSensitive(root, "lid"); + if (!lidNode || !cJSON_IsObject(lidNode)) { + POWER_HILOGE(FEATURE_POWER_STATE, "this lidNode is empty or not an object"); + cJSON_Delete(root); + return; + } bool originEnable = true; - if (root["lid"]["enable"].isBool()) { - originEnable = root["lid"]["enable"].asBool(); + cJSON* enableNode = cJSON_GetObjectItemCaseSensitive(lidNode, "enable"); + if (enableNode && cJSON_IsBool(enableNode)) { + originEnable = cJSON_IsTrue(enableNode); } - if (originEnable == updataEnable) { POWER_HILOGI(FEATURE_POWER_STATE, "no need change jsonConfig value"); + cJSON_Delete(root); return; } - if (root["lid"]["enable"].isBool()) { - root["lid"]["enable"] = updataEnable; + + if (enableNode && cJSON_IsBool(enableNode)) { + enableNode->valueint = updataEnable ? 1 : 0; + } + char* jsonUpdatedStr = cJSON_Print(root); + if (!jsonUpdatedStr) { + POWER_HILOGI(COMP_SVC, "Failed to print cJSON to string"); + cJSON_Delete(root); + return; } - SettingHelper::SetSettingWakeupSources(root.toStyledString()); + std::string jsonConfig = std::string(jsonUpdatedStr); + SettingHelper::SetSettingWakeupSources(jsonConfig); + cJSON_free(jsonUpdatedStr); + cJSON_Delete(root); } - void WakeupController::ExecWakeupMonitorByReason(WakeupDeviceType reason) { FFRTUtils::SubmitTask([this, reason] { diff --git a/services/native/src/wakeup/wakeup_source_parser.cpp b/services/native/src/wakeup/wakeup_source_parser.cpp index 9df7dad1633122af173087b84ebab6d2d6eea8a3..337a787f06d7be391db24345caa25b1daf2c5d76 100644 --- a/services/native/src/wakeup/wakeup_source_parser.cpp +++ b/services/native/src/wakeup/wakeup_source_parser.cpp @@ -16,12 +16,11 @@ #include #include +#include #include "config_policy_utils.h" #include "power_log.h" #include "setting_helper.h" #include "wakeup_source_parser.h" -#include "json/reader.h" -#include "json/value.h" namespace OHOS { namespace PowerMgr { @@ -109,51 +108,54 @@ bool WakeupSourceParser::GetTargetPath(std::string& targetPath) std::shared_ptr WakeupSourceParser::ParseSources(const std::string& jsonStr) { std::shared_ptr parseSources = std::make_shared(); - Json::Reader reader; - Json::Value root; - std::string errors; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { POWER_HILOGE(FEATURE_WAKEUP, "json parse error"); parseSources->SetParseErrorFlag(true); return parseSources; } - if (root.isNull() || !root.isObject()) { + if (!cJSON_IsObject(root)) { POWER_HILOGE(FEATURE_WAKEUP, "json root invalid[%{public}s]", jsonStr.c_str()); parseSources->SetParseErrorFlag(true); + cJSON_Delete(root); return parseSources; } - Json::Value::Members members = root.getMemberNames(); - for (auto iter = members.begin(); iter != members.end(); iter++) { - std::string key = *iter; - Json::Value valueObj = root[key]; - - bool ret = ParseSourcesProc(parseSources, valueObj, key); + cJSON* item = nullptr; + cJSON_ArrayForEach(item, root) { + const char* key = item->string; + if (!key) { + POWER_HILOGI(FEATURE_WAKEUP, "invalid key in json object"); + continue; + } + std::string keyStr = std::string(key); + bool ret = ParseSourcesProc(parseSources, item, keyStr); if (ret == false) { POWER_HILOGI(FEATURE_WAKEUP, "lost map config key"); continue; } } + cJSON_Delete(root); return parseSources; } bool WakeupSourceParser::ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key) { bool enable = true; uint32_t click = DOUBLE_CLICK; WakeupDeviceType wakeupDeviceType = WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN; - if (!valueObj.isNull() && valueObj.isObject()) { - Json::Value enableValue = valueObj[WakeupSource::ENABLE_KEY]; - Json::Value clickValue = valueObj[WakeupSource::KEYS_KEY]; - if (!clickValue.isNull() && clickValue.isUInt()) { - click = (clickValue.asUInt() == SINGLE_CLICK || clickValue.asUInt() == DOUBLE_CLICK) ? clickValue.asUInt() : - DOUBLE_CLICK; + if (valueObj && cJSON_IsObject(valueObj)) { + cJSON* enableValue = cJSON_GetObjectItemCaseSensitive(valueObj, WakeupSource::ENABLE_KEY); + if (enableValue && cJSON_IsBool(enableValue)) { + enable = cJSON_IsTrue(enableValue); } - if (enableValue.isBool()) { - enable = enableValue.asBool(); + cJSON* clickValue = cJSON_GetObjectItemCaseSensitive(valueObj, WakeupSource::KEYS_KEY); + if (clickValue && cJSON_IsNumber(clickValue)) { + uint32_t clickInt = static_cast(clickValue->valueint); + click = (clickInt == SINGLE_CLICK || clickInt == DOUBLE_CLICK) ? clickInt : DOUBLE_CLICK; } } diff --git a/services/native/src/wakeup/wakeup_source_parser.h b/services/native/src/wakeup/wakeup_source_parser.h index d5ff08ec9aa637baa999d9c76fb3ae80a1acead1..8e1953296ef8f9ff90ebd7af5be812297cf3ab3e 100644 --- a/services/native/src/wakeup/wakeup_source_parser.h +++ b/services/native/src/wakeup/wakeup_source_parser.h @@ -21,7 +21,7 @@ #include #include -#include "json/value.h" +#include namespace OHOS { namespace PowerMgr { @@ -30,7 +30,7 @@ public: static std::shared_ptr ParseSources(); static std::shared_ptr ParseSources(const std::string& config); static bool ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key); + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key); static bool GetTargetPath(std::string& targetPath); static void SetSettingsToDatabase(WakeupDeviceType type, bool enable); static const std::string GetWakeupSourcesByConfig(); diff --git a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp index 9ea264050c9ac487b4908a579fb281395cc354b1..5cf07df32f0b7ba3ce13578b2096ada72d0a283d 100644 --- a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp +++ b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp @@ -18,10 +18,9 @@ #include #include +#include #include "config_policy_utils.h" #include "power_log.h" -#include "json/reader.h" -#include "json/value.h" namespace OHOS { namespace PowerMgr { @@ -79,46 +78,52 @@ bool WakeupActionSourceParser::GetTargetPath(std::string& targetPath) std::shared_ptr WakeupActionSourceParser::ParseSources(const std::string& jsonStr) { std::shared_ptr parseSources = std::make_shared(); - Json::Reader reader; - Json::Value root; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { - POWER_HILOGE(FEATURE_WAKEUP_ACTION, "json parse error"); + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { + POWER_HILOGE(FEATURE_WAKEUP_ACTION, "json parse error[%{public}s]", jsonStr.c_str()); return parseSources; } - if (root.isNull() || !root.isObject()) { - POWER_HILOGE(FEATURE_WAKEUP_ACTION, "json root invalid[%{public}s]", jsonStr.c_str()); + if (!cJSON_IsObject(root)) { + POWER_HILOGE(FEATURE_WAKEUP_ACTION, "json root invalid"); + cJSON_Delete(root); return parseSources; } - - Json::Value::Members members = root.getMemberNames(); - for (auto iter = members.begin(); iter != members.end(); iter++) { - std::string key = *iter; - Json::Value valueObj = root[key]; - POWER_HILOGI(FEATURE_WAKEUP_ACTION, "key=%{public}s", key.c_str()); - bool ret = ParseSourcesProc(parseSources, valueObj, key); + + cJSON* item = nullptr; + cJSON_ArrayForEach(item, root) { + const char* key = item->string; + if (!key) { + POWER_HILOGI(FEATURE_WAKEUP_ACTION, "invalid key in json object"); + continue; + } + POWER_HILOGI(FEATURE_WAKEUP_ACTION, "key=%{public}s", key); + std::string keyStr = std::string(key); + bool ret = ParseSourcesProc(parseSources, item, keyStr); if (ret == false) { POWER_HILOGI(FEATURE_WAKEUP_ACTION, "lost map config key"); continue; } } + + cJSON_Delete(root); return parseSources; } bool WakeupActionSourceParser::ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key) { std::string scene{""}; uint32_t action = 0; - if (!valueObj.isNull() && valueObj.isObject()) { - Json::Value sceneValue = valueObj[WakeupActionSource::SCENE_KEY]; - Json::Value actionValue = valueObj[WakeupActionSource::ACTION_KEY]; - if (sceneValue.isString()) { - scene = sceneValue.asString(); + if (valueObj && cJSON_IsObject(valueObj)) { + cJSON* sceneValue = cJSON_GetObjectItemCaseSensitive(valueObj, WakeupActionSource::SCENE_KEY); + if (sceneValue && cJSON_IsString(sceneValue)) { + scene = sceneValue->valuestring; POWER_HILOGI(FEATURE_WAKEUP_ACTION, "scene=%{public}s", scene.c_str()); } - if (actionValue.isUInt()) { - action = actionValue.asUInt(); + cJSON* actionValue = cJSON_GetObjectItemCaseSensitive(valueObj, WakeupActionSource::ACTION_KEY); + if (actionValue && cJSON_IsNumber(actionValue)) { + action = static_cast(actionValue->valueint); POWER_HILOGI(FEATURE_WAKEUP_ACTION, "action=%{public}u", action); if (action >= ILLEGAL_ACTION) { action = 0; diff --git a/services/native/src/wakeup_action/wakeup_action_source_parser.h b/services/native/src/wakeup_action/wakeup_action_source_parser.h index b7f13063b8a252f1cd9b69c92f79c55db0ab0a87..2203ecbf422b299d63b58a81fdc93ffbb05fe76c 100644 --- a/services/native/src/wakeup_action/wakeup_action_source_parser.h +++ b/services/native/src/wakeup_action/wakeup_action_source_parser.h @@ -19,8 +19,8 @@ #include #include +#include #include "wakeup_action_sources.h" -#include "json/value.h" namespace OHOS { namespace PowerMgr { @@ -30,7 +30,7 @@ public: static std::shared_ptr ParseSources(const std::string& jsonStr); static bool GetTargetPath(std::string& targetPath); static bool ParseSourcesProc( - std::shared_ptr &parseSources, Json::Value& valueObj, std::string& key); + std::shared_ptr &parseSources, cJSON* valueObj, std::string& key); }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp b/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp index 15b28b767cee35f86f2e831154c520bc3e8827da..14558709bab6bfcf54a88263e373d963ee1b53fc 100644 --- a/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp +++ b/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp @@ -15,7 +15,7 @@ #include "customized_screen_event_rules.h" #ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES -#include "json/json.h" +#include #include "power_ext_intf_wrapper.h" #endif diff --git a/test/apitest/inner_api/shutdown/BUILD.gn b/test/apitest/inner_api/shutdown/BUILD.gn index d1e798e3380e916d901888af0a259b9ad401f4d3..32ae2602dfc9de2d624d9666bf635183da904fe7 100644 --- a/test/apitest/inner_api/shutdown/BUILD.gn +++ b/test/apitest/inner_api/shutdown/BUILD.gn @@ -45,6 +45,7 @@ deps_ex = [ "ability_base:base", "ability_base:want", "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", diff --git a/test/fuzztest/asyncshutdowncallback_fuzzer/BUILD.gn b/test/fuzztest/asyncshutdowncallback_fuzzer/BUILD.gn index 99ce3f02f9a3160c9511ef532973a03d89bf0617..e1b464e5e088e33456b43c5fbb5c7e8ce19dbcd5 100644 --- a/test/fuzztest/asyncshutdowncallback_fuzzer/BUILD.gn +++ b/test/fuzztest/asyncshutdowncallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("AsyncShutdownCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/createrunninglock_fuzzer/BUILD.gn b/test/fuzztest/createrunninglock_fuzzer/BUILD.gn index 613c2053d0ae01c03ee316374c170f73c1352fc4..88bf822b3f471254b8453a5f7336d56aaeacdf6f 100644 --- a/test/fuzztest/createrunninglock_fuzzer/BUILD.gn +++ b/test/fuzztest/createrunninglock_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("CreateRunningLockFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/forcesuspenddevice_fuzzer/BUILD.gn b/test/fuzztest/forcesuspenddevice_fuzzer/BUILD.gn index 56d43b6456fd6478745508a1c2054955e56ed362..2c8d1a3a7842ea83efe8414be0cffc18dc4231df 100644 --- a/test/fuzztest/forcesuspenddevice_fuzzer/BUILD.gn +++ b/test/fuzztest/forcesuspenddevice_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ForceSuspendDeviceFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/getsetdevicemode_fuzzer/BUILD.gn b/test/fuzztest/getsetdevicemode_fuzzer/BUILD.gn index b271f91ddaefeb8d331c8fbc30760eb6cca24d04..70eda90dcd7d4637af6b8c2f9ddc524b5d6ac243 100644 --- a/test/fuzztest/getsetdevicemode_fuzzer/BUILD.gn +++ b/test/fuzztest/getsetdevicemode_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("GetSetDeviceModeFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/getstate_fuzzer/BUILD.gn b/test/fuzztest/getstate_fuzzer/BUILD.gn index 78a57d7b8fd6ead12246d2eb8b93b4d82381a5d5..14049f5d3768acaa617bf91ae39bf02a1523c807 100644 --- a/test/fuzztest/getstate_fuzzer/BUILD.gn +++ b/test/fuzztest/getstate_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("GetStateFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/hibernate_fuzzer/BUILD.gn b/test/fuzztest/hibernate_fuzzer/BUILD.gn index c18fe1fa55632c0f8b83922a496c1d610de5c7da..c8822fadc2cd235a0cc91760051f394b8297dc47 100644 --- a/test/fuzztest/hibernate_fuzzer/BUILD.gn +++ b/test/fuzztest/hibernate_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("HibernateFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/iscollaborationscreenon_fuzzer/BUILD.gn b/test/fuzztest/iscollaborationscreenon_fuzzer/BUILD.gn index 12fae5893535276e7ed70d76c8d76795cbdde410..7f46109f303575f5192bbb065ba2ac36d73b2614 100644 --- a/test/fuzztest/iscollaborationscreenon_fuzzer/BUILD.gn +++ b/test/fuzztest/iscollaborationscreenon_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("IsCollaborationScreenOnFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/isfoldscreenon_fuzzer/BUILD.gn b/test/fuzztest/isfoldscreenon_fuzzer/BUILD.gn index 3353870577a0868b7471cf1bbd73d80c487253a6..d5f0a9c764f091bb0a7993f1463d06692cab5c86 100644 --- a/test/fuzztest/isfoldscreenon_fuzzer/BUILD.gn +++ b/test/fuzztest/isfoldscreenon_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("IsFoldScreenOnFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/isrunninglocktypesupported_fuzzer/BUILD.gn b/test/fuzztest/isrunninglocktypesupported_fuzzer/BUILD.gn index 8af4f6b1f8e4763a8e4f20c79c1cf055486421d1..8816956d6bd4ae606ee05582d53ebd0aa62acbd1 100644 --- a/test/fuzztest/isrunninglocktypesupported_fuzzer/BUILD.gn +++ b/test/fuzztest/isrunninglocktypesupported_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("IsRunningLockTypeSupportedFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/isscreenon_fuzzer/BUILD.gn b/test/fuzztest/isscreenon_fuzzer/BUILD.gn index 92caaaeaed4f2e706707b8a0cfc7b5e0b8f353b8..b9e9d0f31e29020ae725810b80d3900e76d606b9 100644 --- a/test/fuzztest/isscreenon_fuzzer/BUILD.gn +++ b/test/fuzztest/isscreenon_fuzzer/BUILD.gn @@ -55,12 +55,12 @@ ohos_fuzztest("IsScreenOnFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", "c_utils:utils", + "cJSON:cjson", "ffrt:libffrt", "hilog:libhilog", "input:libmmi-client", diff --git a/test/fuzztest/isstandby_fuzzer/BUILD.gn b/test/fuzztest/isstandby_fuzzer/BUILD.gn index 44ca320f52058b12812ef669deddb5cc8c33fad3..b9ed4b7c0e7f952fe0722716e1b59567b0a1b7dc 100644 --- a/test/fuzztest/isstandby_fuzzer/BUILD.gn +++ b/test/fuzztest/isstandby_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("IsStandbyFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/lockscreenaftertimingout_fuzzer/BUILD.gn b/test/fuzztest/lockscreenaftertimingout_fuzzer/BUILD.gn index f99f36ff134bb3f3ae3422af65abe2e87c5c9b35..1b2a35f8c2ecc9e4bd707b608ce14aeae04d7451 100644 --- a/test/fuzztest/lockscreenaftertimingout_fuzzer/BUILD.gn +++ b/test/fuzztest/lockscreenaftertimingout_fuzzer/BUILD.gn @@ -60,12 +60,12 @@ ohos_fuzztest("LockScreenAfterTimingOutFuzzTest") { external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", "input:libmmi-client", "ipc:ipc_core", - "jsoncpp:jsoncpp", "libxml2:libxml2", "power_manager:power_ffrt", "safwk:system_ability_fwk", diff --git a/test/fuzztest/lockunlockisused_fuzzer/BUILD.gn b/test/fuzztest/lockunlockisused_fuzzer/BUILD.gn index aaf55df976f49f4dee1fa237426ac2f950109bb9..0531119237c1b8b53b765401b80a2f1960815303 100644 --- a/test/fuzztest/lockunlockisused_fuzzer/BUILD.gn +++ b/test/fuzztest/lockunlockisused_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("LockUnLockIsUsedFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/overridescreenofftime_fuzzer/BUILD.gn b/test/fuzztest/overridescreenofftime_fuzzer/BUILD.gn index be8a9d7033eeddb964a5b59df7b649470b68a00e..aaeb5c7d9465cfb014e637f65b901766103ea1ce 100644 --- a/test/fuzztest/overridescreenofftime_fuzzer/BUILD.gn +++ b/test/fuzztest/overridescreenofftime_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("OverrideScreenOffTimeFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/powermodecallback_fuzzer/BUILD.gn b/test/fuzztest/powermodecallback_fuzzer/BUILD.gn index 05e624bcfb96a612908d4bb32906d1842870477f..8f8896125ca35c51bde4bd0940944f74a721609c 100644 --- a/test/fuzztest/powermodecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/powermodecallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("PowerModeCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/powerstatecallback_fuzzer/BUILD.gn b/test/fuzztest/powerstatecallback_fuzzer/BUILD.gn index 99631610458fba318cdf9f8a1cabc20dc73ba3f9..3f267ada9824f0ab06a3f7244b1dfe698aa13fd2 100644 --- a/test/fuzztest/powerstatecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/powerstatecallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("PowerStateCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/proxyrunninglock_fuzzer/BUILD.gn b/test/fuzztest/proxyrunninglock_fuzzer/BUILD.gn index 0d7ec59c2849fe53b3358fd067934867a5ced7be..f9da0f0b9baa7a5805c5e95ea644538ed6f369d2 100644 --- a/test/fuzztest/proxyrunninglock_fuzzer/BUILD.gn +++ b/test/fuzztest/proxyrunninglock_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ProxyRunningLockFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/proxyrunninglocks_fuzzer/BUILD.gn b/test/fuzztest/proxyrunninglocks_fuzzer/BUILD.gn index cc75a3c7430614f036fbd74270681c8bed03a140..d595909b58e32179e8488f5e0f280d8e96f6cddb 100644 --- a/test/fuzztest/proxyrunninglocks_fuzzer/BUILD.gn +++ b/test/fuzztest/proxyrunninglocks_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ProxyRunningLocksFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/queryrunninglocklists_fuzzer/BUILD.gn b/test/fuzztest/queryrunninglocklists_fuzzer/BUILD.gn index 87da87850fa7cf76f97165149cb54c4f2863d66e..e606441dd241ebf2744a43e3870780aecaf04abb 100644 --- a/test/fuzztest/queryrunninglocklists_fuzzer/BUILD.gn +++ b/test/fuzztest/queryrunninglocklists_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("QueryRunningLockListsFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/rebootdevice_fuzzer/BUILD.gn b/test/fuzztest/rebootdevice_fuzzer/BUILD.gn index 35dbb3df38cc24cc26561f5f888fb15747956f9c..fc9bc91b559a3540cfe84e7488dc4af4b95c25c9 100644 --- a/test/fuzztest/rebootdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/rebootdevice_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("RebootDeviceFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/refreshactivity_fuzzer/BUILD.gn b/test/fuzztest/refreshactivity_fuzzer/BUILD.gn index f0b99caff9ce0f42f15bfa9c96e6aa67f0198775..eb4b205150bf2d9e86ff1e6a1870e4afb0e628e1 100644 --- a/test/fuzztest/refreshactivity_fuzzer/BUILD.gn +++ b/test/fuzztest/refreshactivity_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("RefreshActivityFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/releaserunninglock_fuzzer/BUILD.gn b/test/fuzztest/releaserunninglock_fuzzer/BUILD.gn index f0e581a84a2d37604d381a487e4736602df5c66d..c0e92730e3d71e53c38677eeaff85364b2c1631b 100644 --- a/test/fuzztest/releaserunninglock_fuzzer/BUILD.gn +++ b/test/fuzztest/releaserunninglock_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ReleaseRunningLockFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/resetrunninglocks_fuzzer/BUILD.gn b/test/fuzztest/resetrunninglocks_fuzzer/BUILD.gn index 99b237fba44ea06b766a3a1eb774b7080e8a9582..5042f7f92eb56d9879aeb8e7abc6463e8b6fd167 100644 --- a/test/fuzztest/resetrunninglocks_fuzzer/BUILD.gn +++ b/test/fuzztest/resetrunninglocks_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ResetRunningLocksFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/runninglockcallback_fuzzer/BUILD.gn b/test/fuzztest/runninglockcallback_fuzzer/BUILD.gn index 06c7d790e583834b9d207d391c7851038d0f20d5..4f79f85a7ac611cd6fe006045131308a1f46f508 100644 --- a/test/fuzztest/runninglockcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/runninglockcallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("RunningLockCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/screenstatecallback_fuzzer/BUILD.gn b/test/fuzztest/screenstatecallback_fuzzer/BUILD.gn index f8bb769704656fc3dbd3e1cce039037836277b99..404ea65f34b205bd7aebf8e8fec1b993d606fdec 100644 --- a/test/fuzztest/screenstatecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/screenstatecallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("ScreenStateCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/setdisplaysuspend_fuzzer/BUILD.gn b/test/fuzztest/setdisplaysuspend_fuzzer/BUILD.gn index 98e7ad487129db24bf0ad32adac366db1179736c..14e9056d3eaafd064e735dbfb713ab414a75ae10 100644 --- a/test/fuzztest/setdisplaysuspend_fuzzer/BUILD.gn +++ b/test/fuzztest/setdisplaysuspend_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("SetDisplaySuspendFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/setforcetimingout_fuzzer/BUILD.gn b/test/fuzztest/setforcetimingout_fuzzer/BUILD.gn index 5d9d5a1e8fff8df8d13f3a1dd571de7a364d2b9b..a789cdc0e7e1475d4a19ea97ac9fa66aebf786c9 100644 --- a/test/fuzztest/setforcetimingout_fuzzer/BUILD.gn +++ b/test/fuzztest/setforcetimingout_fuzzer/BUILD.gn @@ -60,12 +60,12 @@ ohos_fuzztest("SetForceTimingOutFuzzTest") { external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", "input:libmmi-client", "ipc:ipc_core", - "jsoncpp:jsoncpp", "libxml2:libxml2", "power_manager:power_ffrt", "safwk:system_ability_fwk", diff --git a/test/fuzztest/setsuspendtag_fuzzer/BUILD.gn b/test/fuzztest/setsuspendtag_fuzzer/BUILD.gn index 7b5936deccd05d3e7c16fbd9f3abcba4ac8fafe1..909e6c3fdf6ae664ffb75deada85a54d0cee38e4 100644 --- a/test/fuzztest/setsuspendtag_fuzzer/BUILD.gn +++ b/test/fuzztest/setsuspendtag_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("SetSuspendTagFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/shelldump_fuzzer/BUILD.gn b/test/fuzztest/shelldump_fuzzer/BUILD.gn index e9a299171507dacb7f43240108f4a5610a44bf4e..6cd02553aebaeca9048b5d98f4c80fe7d2ef8723 100644 --- a/test/fuzztest/shelldump_fuzzer/BUILD.gn +++ b/test/fuzztest/shelldump_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("ShellDumpFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/shutdowndevice_fuzzer/BUILD.gn b/test/fuzztest/shutdowndevice_fuzzer/BUILD.gn index 3347d1af13da0b8348a115e2146930339a1e96fc..0baf9e917e7a0bb797ec3e390187297cdba78842 100644 --- a/test/fuzztest/shutdowndevice_fuzzer/BUILD.gn +++ b/test/fuzztest/shutdowndevice_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("ShutDownDeviceFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/suspenddevice_fuzzer/BUILD.gn b/test/fuzztest/suspenddevice_fuzzer/BUILD.gn index c1060f4e38a41161949dfa54f2b4268d6fd9573e..280be3cadaecdf8607b22271487236527059d2ef 100644 --- a/test/fuzztest/suspenddevice_fuzzer/BUILD.gn +++ b/test/fuzztest/suspenddevice_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("SuspendDeviceFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/synchibernatecallback_fuzzer/BUILD.gn b/test/fuzztest/synchibernatecallback_fuzzer/BUILD.gn index bcf4fc42ff23a7b364d5da83b0be4702ef13d6f0..8b3c7f1eca51bdfe44768cb42c9801ca003605b3 100644 --- a/test/fuzztest/synchibernatecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/synchibernatecallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("SyncHibernateCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/syncshutdowncallback_fuzzer/BUILD.gn b/test/fuzztest/syncshutdowncallback_fuzzer/BUILD.gn index 434bbde60c7ab39aa5972cb78f7fd8f1c0b0473a..faff00c53a08d5e394acb27e575241981c6c6d37 100644 --- a/test/fuzztest/syncshutdowncallback_fuzzer/BUILD.gn +++ b/test/fuzztest/syncshutdowncallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("SyncShutdownCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/syncsleepcallback_fuzzer/BUILD.gn b/test/fuzztest/syncsleepcallback_fuzzer/BUILD.gn index b5f014b7d5b2802ff1b6bcb4a1c273da4e3571e8..f936cee1c5dd97c6b09c06fd73de2f963f5cd338 100644 --- a/test/fuzztest/syncsleepcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/syncsleepcallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("SyncSleepCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/takeovershutdowncallback_fuzzer/BUILD.gn b/test/fuzztest/takeovershutdowncallback_fuzzer/BUILD.gn index 924e544b165cf4d6694af1531c08d4db4add2619..02130828238f7d04966deb13e094ce61b7be7049 100644 --- a/test/fuzztest/takeovershutdowncallback_fuzzer/BUILD.gn +++ b/test/fuzztest/takeovershutdowncallback_fuzzer/BUILD.gn @@ -56,11 +56,11 @@ ohos_fuzztest("TakeOverShutdownCallbackFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/fuzztest/wakeupdevice_fuzzer/BUILD.gn b/test/fuzztest/wakeupdevice_fuzzer/BUILD.gn index e3a62225b9d824373b64ecbfe357a438d41c7520..62db1f4b46e12c33ea3ea45192be08503991e19f 100644 --- a/test/fuzztest/wakeupdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/wakeupdevice_fuzzer/BUILD.gn @@ -55,11 +55,11 @@ ohos_fuzztest("WakeupDeviceFuzzTest") { "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", - "//third_party/jsoncpp:jsoncpp", ] external_deps = [ "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index b5b9d977beeb8f068d2d1358664e3ab9f1922cef..f4d4d47e2a233ada1a4f1c8ef714c8a6a44bc59f 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -43,6 +43,7 @@ deps_ex = [ "ability_runtime:ability_manager", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index c0587a5cb68352c666e13ccdb1bd07d6c877d303..db48d9cf15febef7aaf98a779ce0a302e89dcfce 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -61,6 +61,7 @@ deps_ex = [ "ability_base:base", "ability_base:want", "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", @@ -70,7 +71,6 @@ deps_ex = [ "hilog:libhilog", "input:libmmi-client", "ipc:ipc_core", - "jsoncpp:jsoncpp", "libxml2:libxml2", "power_manager:power_ffrt", "safwk:system_ability_fwk", diff --git a/test/unittest/src/interface_test/power_wakeup_controller_test.cpp b/test/unittest/src/interface_test/power_wakeup_controller_test.cpp index aa598bce751f1248881851e0c53ae7ad13ebfe23..6389ced392b8efb5bf0990268669d0710755d48a 100644 --- a/test/unittest/src/interface_test/power_wakeup_controller_test.cpp +++ b/test/unittest/src/interface_test/power_wakeup_controller_test.cpp @@ -16,7 +16,7 @@ #include #include #include - +#include #include "axis_event.h" #include "input_device.h" #include "pointer_event.h" @@ -28,7 +28,6 @@ #include "power_mgr_service.h" #include "power_state_machine.h" #include "setting_helper.h" -#include "json/reader.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -380,19 +379,30 @@ HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest011, TestSize.Level "false},\"lid\": {\"enable\": false},\"switch\": {\"enable\": true},\"xxx\": {\"enable\": false}}"; std::shared_ptr parseSources = std::make_shared(); - Json::Reader reader; - Json::Value root; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: json parse error"; + return; + } + if (!cJSON_IsObject(root)) { + GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: root is not object"; + cJSON_Delete(root); + return; } - Json::Value::Members members = root.getMemberNames(); - for (auto iter = members.begin(); iter != members.end(); iter++) { - std::string key = *iter; - Json::Value valueObj = root[key]; - WakeupSourceParser::ParseSourcesProc(parseSources, valueObj, key); + cJSON* item = NULL; + cJSON_ArrayForEach(item, root) { + const char* key = item->string; + if (!key) { + continue; + } + std::string keyStr = std::string(key); + WakeupSourceParser::ParseSourcesProc(parseSources, item, keyStr); } + + cJSON_Delete(root); + EXPECT_TRUE(parseSources->GetSourceList().size() != 0); GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: end"; POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest011 function end!"); diff --git a/test/unittest/src/power_parsesources_mock_test.cpp b/test/unittest/src/power_parsesources_mock_test.cpp index 36408109d5b67527a6b98756b49ccc4c6794b4b7..9aad63d6c55b9475c2aad51fa28d1bf8aaf0f491 100644 --- a/test/unittest/src/power_parsesources_mock_test.cpp +++ b/test/unittest/src/power_parsesources_mock_test.cpp @@ -38,13 +38,13 @@ bool SettingHelper::IsSuspendSourcesSettingValid() } bool SuspendSourceParser::ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key) { return false; } bool WakeupSourceParser::ParseSourcesProc( - std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) + std::shared_ptr& parseSources, cJSON* valueObj, std::string& key) { return false; } diff --git a/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp b/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp index 4a527fcd705febebde42c5125602f1e8782101d0..9e4e9992f68d9640cf73e641b90410b9f443a221 100644 --- a/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp +++ b/test/unittest/src/scenario_test/wakeup_suspend/power_wakeup_test.cpp @@ -16,7 +16,7 @@ #include #include #include - +#include #include "axis_event.h" #include "input_device.h" #include "pointer_event.h" @@ -27,7 +27,6 @@ #include "power_mgr_client.h" #include "power_state_machine.h" #include "setting_helper.h" -#include "json/reader.h" using namespace testing::ext; using namespace OHOS::PowerMgr; diff --git a/test/unittest/src/servicetest/BUILD.gn b/test/unittest/src/servicetest/BUILD.gn index e1b4b1da264be7bd572a201216c6c3c77e2c0e9d..6e0ae1fcdb76d310de31d8572237a1473bebff1e 100644 --- a/test/unittest/src/servicetest/BUILD.gn +++ b/test/unittest/src/servicetest/BUILD.gn @@ -52,6 +52,7 @@ deps_ex = [ "ability_base:base", "ability_base:want", "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "common_event_service:cesfwk_innerkits", "ffrt:libffrt", diff --git a/utils/vibrator/BUILD.gn b/utils/vibrator/BUILD.gn index 8fc1dc9ac36072219cb2dbccea261352fa42261f..fa13dcbeaab5f50acc8cae6ef6d21953a0e8d836 100644 --- a/utils/vibrator/BUILD.gn +++ b/utils/vibrator/BUILD.gn @@ -35,10 +35,10 @@ ohos_shared_library("power_vibrator") { public_configs = [ ":public_config" ] external_deps = [ + "cJSON:cjson", "c_utils:utils", "config_policy:configpolicy_util", "hilog:libhilog", - "jsoncpp:jsoncpp", ] if (defined(global_parts_info) && defined(global_parts_info.sensors_miscdevice)) { diff --git a/utils/vibrator/include/vibrator_source_parser.h b/utils/vibrator/include/vibrator_source_parser.h index d2cad83bdcac98aa3c41be18ad71119ab9ebda55..6e3b10da9618a16d1507193187386ef34acdcbb3 100644 --- a/utils/vibrator/include/vibrator_source_parser.h +++ b/utils/vibrator/include/vibrator_source_parser.h @@ -18,7 +18,7 @@ #include #include -#include "json/value.h" +#include namespace OHOS { namespace PowerMgr { @@ -56,7 +56,7 @@ private: std::vector ParseSources(const std::string& config); void GetTargetPath(std::string& targetPath, const std::string& etcPath, const std::string& vendorPath, const std::string& systemPath); - void ParseSourcesProc(std::vector& sources, Json::Value& valueObj, std::string& key); + void ParseSourcesProc(std::vector& sources, cJSON* valueObj, std::string& key); }; } // namespace PowerMgr } // namespace OHOS diff --git a/utils/vibrator/src/vibrator_source_parser.cpp b/utils/vibrator/src/vibrator_source_parser.cpp index 20f4e4b86af1cfdbb9e752d0b5f7f39ee702828a..51f594fad2baaa035d18f592c8b1866f5abd5d82 100644 --- a/utils/vibrator/src/vibrator_source_parser.cpp +++ b/utils/vibrator/src/vibrator_source_parser.cpp @@ -18,10 +18,9 @@ #include #include #include +#include #include "config_policy_utils.h" #include "power_log.h" -#include "json/reader.h" -#include "json/value.h" namespace OHOS { namespace PowerMgr { @@ -71,37 +70,64 @@ void VibratorSourceParser::GetTargetPath( std::vector VibratorSourceParser::ParseSources(const std::string& jsonStr) { std::vector sources; - Json::Reader reader; - Json::Value root; - if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) { - POWER_HILOGE(COMP_UTILS, "json parse error"); + + if (jsonStr.empty()) { + POWER_HILOGE(COMP_UTILS, "Input JSON string is empty"); return sources; } - Json::Value::Members members = root.getMemberNames(); - for (auto iter = members.begin(); iter != members.end(); iter++) { - std::string key = *iter; - Json::Value valueObj = root[key]; - POWER_HILOGI(COMP_UTILS, "key=%{public}s", key.c_str()); - ParseSourcesProc(sources, valueObj, key); + + cJSON* root = cJSON_Parse(jsonStr.c_str()); + if (!root) { + POWER_HILOGE(COMP_UTILS, "JSON parse error"); + return sources; + } + if (!cJSON_IsObject(root)) { + POWER_HILOGE(COMP_UTILS, "JSON root is not object"); + cJSON_Delete(root); + return sources; } + + cJSON* item = nullptr; + cJSON_ArrayForEach(item, root) { + const char* key = item->string; + if (!key) { + POWER_HILOGE(COMP_UTILS, "invalid key in json object"); + continue; + } + std::string keyStr = std::string(key); + POWER_HILOGI(COMP_UTILS, "key=%{public}s", keyStr.c_str()); + ParseSourcesProc(sources, item, keyStr); + } + + cJSON_Delete(root); return sources; } void VibratorSourceParser::ParseSourcesProc( - std::vector& sources, Json::Value& valueObj, std::string& key) + std::vector& sources, cJSON* valueObj, std::string& key) { - if (!valueObj.isObject()) { + if (!cJSON_IsObject(valueObj)) { + POWER_HILOGE(COMP_UTILS, "ValueObj is not a json object."); return; } - std::string type; + bool enable = false; - Json::Value enableValue = valueObj[VibratorSource::ENABLE_KEY]; - Json::Value typeValue = valueObj[VibratorSource::TYPE_KEY]; - if (!typeValue.isString() || !enableValue.isBool()) { + std::string type; + + cJSON* enableItem = cJSON_GetObjectItemCaseSensitive(valueObj, VibratorSource::ENABLE_KEY); + if (!enableItem || !cJSON_IsBool(enableItem)) { + POWER_HILOGE(COMP_UTILS, "Parse enable error."); return; } - enable = enableValue.asBool(); - type = typeValue.asString(); + enable = cJSON_IsTrue(enableItem); + + cJSON* typeItem = cJSON_GetObjectItemCaseSensitive(valueObj, VibratorSource::TYPE_KEY); + if (!typeItem || !cJSON_IsString(typeItem)) { + POWER_HILOGE(COMP_UTILS, "Parse type error."); + return; + } + type = typeItem->valuestring; + if (!enable || type.empty()) { return; }