mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
+3
-6
@@ -169,12 +169,9 @@ ani_object CreateEtsAgentAppInfo(ani_env *env, const AgentAppInfo &appInfo)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (!appInfo.deviceTypes.empty()) {
|
||||
status = env->Object_SetPropertyByName_Ref(object, "deviceTypes", GetAniString(env, appInfo.deviceTypes));
|
||||
if (status != ANI_OK) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "set deviceTypes failed: %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
if (appInfo.deviceTypes.size() > 0 && !SetStringArrayProperty(env, object, "deviceTypes", appInfo.deviceTypes)) {
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "set deviceTypes failed");
|
||||
return nullptr;
|
||||
}
|
||||
if (!appInfo.minAppVersion.empty()) {
|
||||
status = env->Object_SetPropertyByName_Ref(object, "minAppVersion", GetAniString(env, appInfo.minAppVersion));
|
||||
|
||||
@@ -27,7 +27,7 @@ export interface AgentAppInfo {
|
||||
bundleName?: string;
|
||||
moduleName?: string;
|
||||
abilityName?: string;
|
||||
deviceTypes?: string;
|
||||
deviceTypes?: Array<string>;
|
||||
minAppVersion?: string;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class AgentAppInfoImpl implements AgentAppInfo {
|
||||
public bundleName?: string;
|
||||
public moduleName?: string;
|
||||
public abilityName?: string;
|
||||
public deviceTypes?: string;
|
||||
public deviceTypes?: Array<string>;
|
||||
public minAppVersion?: string;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ napi_value CreateJsAgentAppInfo(napi_env env, const AgentAppInfo &appInfo)
|
||||
napi_set_named_property(env, object, "abilityName", CreateJsValue(env, appInfo.abilityName));
|
||||
}
|
||||
if (!appInfo.deviceTypes.empty()) {
|
||||
napi_set_named_property(env, object, "deviceTypes", CreateJsValue(env, appInfo.deviceTypes));
|
||||
napi_set_named_property(env, object, "deviceTypes", CreateNativeArray(env, appInfo.deviceTypes));
|
||||
}
|
||||
if (!appInfo.minAppVersion.empty()) {
|
||||
napi_set_named_property(env, object, "minAppVersion", CreateJsValue(env, appInfo.minAppVersion));
|
||||
|
||||
@@ -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 = "";
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ int32_t AgentCardMgr::HandleBundleInstall(const std::string &bundleName, int32_t
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "Get Bundle Info fail");
|
||||
return -1;
|
||||
}
|
||||
std::vector<AgentCard> cards;
|
||||
std::map<std::string, AgentCard> cards;
|
||||
for (auto const &extensionInfo : bundleInfo.extensionInfos) {
|
||||
if (extensionInfo.type != ExtensionAbilityType::AGENT) {
|
||||
continue;
|
||||
@@ -81,11 +81,15 @@ int32_t AgentCardMgr::HandleBundleInstall(const std::string &bundleName, int32_t
|
||||
card.appInfo->bundleName = bundleName;
|
||||
card.appInfo->moduleName = extensionInfo.moduleName;
|
||||
card.appInfo->abilityName = extensionInfo.name;
|
||||
cards.push_back(card);
|
||||
cards[card.agentId] = card;
|
||||
}
|
||||
}
|
||||
}
|
||||
return AgentCardDbMgr::GetInstance().InsertData(bundleName, userId, cards);
|
||||
std::vector<AgentCard> cardVec;
|
||||
for (const auto& [key, value] : cards) {
|
||||
cardVec.push_back(value);
|
||||
}
|
||||
return AgentCardDbMgr::GetInstance().InsertData(bundleName, userId, cardVec);
|
||||
}
|
||||
|
||||
int32_t AgentCardMgr::HandleBundleUpdate(const std::string &bundleName, int32_t userId)
|
||||
|
||||
Reference in New Issue
Block a user