mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
@@ -80,7 +80,7 @@ struct AgentAppInfo : public Parcelable {
|
||||
std::string bundleName;
|
||||
std::string moduleName;
|
||||
std::string abilityName;
|
||||
std::string deviceTypes;
|
||||
std::vector<std::string> deviceTypes;
|
||||
std::string minAppVersion;
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
@@ -31,9 +31,10 @@ constexpr uint32_t MAX_AGENT_CARD_COUNT = 200000;
|
||||
constexpr uint32_t LENGTH_32 = 32;
|
||||
constexpr uint32_t LENGTH_64 = 64;
|
||||
constexpr uint32_t LENGTH_128 = 128;
|
||||
constexpr uint32_t LENGTH_256 = 256;
|
||||
constexpr uint32_t LENGTH_512 = 512;
|
||||
constexpr uint32_t LENGTH_1280 = 1280;
|
||||
constexpr uint32_t LENGTH_51200 = 51200;
|
||||
constexpr uint32_t LENGTH_1024 = 1024;
|
||||
constexpr uint32_t LENGTH_5120 = 5120;
|
||||
|
||||
bool AgentProvider::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
@@ -168,7 +169,7 @@ AgentCapabilities AgentCapabilities::FromJson(const nlohmann::json &jsonObject)
|
||||
}
|
||||
if (jsonObject.contains("extension") && jsonObject["extension"].is_string()) {
|
||||
capabilities.extension = jsonObject["extension"];
|
||||
if (capabilities.extension.length() < 1 || capabilities.extension.length() > LENGTH_1280) {
|
||||
if (capabilities.extension.length() < 1 || capabilities.extension.length() > LENGTH_1024) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "extension length is invalid");
|
||||
capabilities.extension = "";
|
||||
}
|
||||
@@ -309,28 +310,40 @@ bool AgentSkill::FromJson(const nlohmann::json &jsonObject, AgentSkill &skill)
|
||||
}
|
||||
if (jsonObject.contains("examples") && jsonObject["examples"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("examples")) {
|
||||
if (element.is_string()) {
|
||||
skill.examples.push_back(element.get<std::string>());
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string exampleStr = element.get<std::string>();
|
||||
if (exampleStr.length() <= LENGTH_256 && exampleStr.length() > 0) {
|
||||
skill.examples.push_back(exampleStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("inputModes") && jsonObject["inputModes"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("inputModes")) {
|
||||
if (element.is_string()) {
|
||||
skill.inputModes.push_back(element.get<std::string>());
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string inputModeStr = element.get<std::string>();
|
||||
if (inputModeStr.length() <= LENGTH_64 && inputModeStr.length() > 0) {
|
||||
skill.inputModes.push_back(inputModeStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("outputModes") && jsonObject["outputModes"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("outputModes")) {
|
||||
if (element.is_string()) {
|
||||
skill.outputModes.push_back(element.get<std::string>());
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string outputModeStr = element.get<std::string>();
|
||||
if (outputModeStr.length() <= LENGTH_64 && outputModeStr.length() > 0) {
|
||||
skill.outputModes.push_back(outputModeStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("extension") && jsonObject["extension"].is_string()) {
|
||||
skill.extension = jsonObject["extension"];
|
||||
if (skill.extension.length() < 1 || skill.extension.length() > LENGTH_1280) {
|
||||
if (skill.extension.length() < 1 || skill.extension.length() > LENGTH_1024) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "extension length is invalid");
|
||||
skill.extension = "";
|
||||
}
|
||||
@@ -343,7 +356,10 @@ bool AgentAppInfo::ReadFromParcel(Parcel &parcel)
|
||||
bundleName = parcel.ReadString();
|
||||
moduleName = parcel.ReadString();
|
||||
abilityName = parcel.ReadString();
|
||||
deviceTypes = parcel.ReadString();
|
||||
if (!parcel.ReadStringVector(&deviceTypes)) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "read deviceTypes failed");
|
||||
return false;
|
||||
}
|
||||
minAppVersion = parcel.ReadString();
|
||||
return true;
|
||||
}
|
||||
@@ -362,7 +378,7 @@ bool AgentAppInfo::Marshalling(Parcel &parcel) const
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "write abilityName failed");
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString(deviceTypes)) {
|
||||
if (!parcel.WriteStringVector(deviceTypes)) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "write deviceTypes failed");
|
||||
return false;
|
||||
}
|
||||
@@ -406,12 +422,15 @@ bool AgentAppInfo::FromJson(const nlohmann::json &jsonObject, AgentAppInfo &appI
|
||||
if (jsonObject.contains("abilityName") && jsonObject["abilityName"].is_string()) {
|
||||
appInfo.abilityName = jsonObject["abilityName"];
|
||||
}
|
||||
if (jsonObject.contains("deviceTypes") && jsonObject["deviceTypes"].is_string()) {
|
||||
appInfo.deviceTypes = jsonObject["deviceTypes"];
|
||||
if (appInfo.deviceTypes.length() < 1 || appInfo.deviceTypes.length() > LENGTH_128) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "deviceTypes length is invalid");
|
||||
appInfo.deviceTypes = "";
|
||||
return false;
|
||||
if (jsonObject.contains("deviceTypes") && jsonObject["deviceTypes"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("deviceTypes")) {
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string deviceType = element.get<std::string>();
|
||||
if (deviceType.length() > 0 && deviceType.length() <= LENGTH_32) {
|
||||
appInfo.deviceTypes.push_back(deviceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("minAppVersion") && jsonObject["minAppVersion"].is_string()) {
|
||||
@@ -419,7 +438,6 @@ bool AgentAppInfo::FromJson(const nlohmann::json &jsonObject, AgentAppInfo &appI
|
||||
if (appInfo.minAppVersion.length() < 1 || appInfo.minAppVersion.length() > LENGTH_32) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "minAppVersion length is invalid");
|
||||
appInfo.minAppVersion = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -652,19 +670,40 @@ bool AgentCard::FromJson(nlohmann::json jsonObject, AgentCard &agentCard)
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonObject.contains("defaultInputModes") && jsonObject["defaultInputModes"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("defaultInputModes")) {
|
||||
if (element.is_string()) {
|
||||
agentCard.defaultInputModes.push_back(element.get<std::string>());
|
||||
}
|
||||
if (!jsonObject.contains("defaultInputModes") || !jsonObject["defaultInputModes"].is_array()) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "defaultInputModes is empty");
|
||||
return false;
|
||||
}
|
||||
for (const auto &element : jsonObject.at("defaultInputModes")) {
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string intputMode = element.get<std::string>();
|
||||
if (intputMode.length() >= 1 && intputMode.length() <= LENGTH_32) {
|
||||
agentCard.defaultInputModes.push_back(intputMode);
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("defaultOutputModes") && jsonObject["defaultOutputModes"].is_array()) {
|
||||
for (const auto &element : jsonObject.at("defaultOutputModes")) {
|
||||
if (element.is_string()) {
|
||||
agentCard.defaultOutputModes.push_back(element.get<std::string>());
|
||||
}
|
||||
if (agentCard.defaultInputModes.size() == 0) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "defaultInputModes is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!jsonObject.contains("defaultOutputModes") || !jsonObject["defaultOutputModes"].is_array()) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "defaultOutputModes is empty");
|
||||
return false;
|
||||
}
|
||||
for (const auto &element : jsonObject.at("defaultOutputModes")) {
|
||||
if (!element.is_string()) {
|
||||
continue;
|
||||
}
|
||||
std::string outputMode = element.get<std::string>();
|
||||
if (outputMode.length() >= 1 && outputMode.length() <= LENGTH_32) {
|
||||
agentCard.defaultOutputModes.push_back(outputMode);
|
||||
}
|
||||
}
|
||||
if (agentCard.defaultOutputModes.size() == 0) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "defaultInputModes is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Optional objects
|
||||
@@ -692,6 +731,10 @@ bool AgentCard::FromJson(nlohmann::json jsonObject, AgentCard &agentCard)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (agentCard.skills.size() == 0) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "skills is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Optional iconUrl field
|
||||
if (jsonObject.contains("iconUrl") && jsonObject["iconUrl"].is_string()) {
|
||||
@@ -705,7 +748,7 @@ bool AgentCard::FromJson(nlohmann::json jsonObject, AgentCard &agentCard)
|
||||
// Optional extension field
|
||||
if (jsonObject.contains("extension") && jsonObject["extension"].is_string()) {
|
||||
agentCard.extension = jsonObject["extension"];
|
||||
if (agentCard.extension.length() < 1 || agentCard.extension.length() > LENGTH_51200) {
|
||||
if (agentCard.extension.length() < 1 || agentCard.extension.length() > LENGTH_5120) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "extension length is invalid");
|
||||
agentCard.extension = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user