From 2e28ffabe07c4f5365fb32c30aa8eec3cb9338dd Mon Sep 17 00:00:00 2001 From: linjunjie Date: Wed, 11 Jun 2025 12:50:56 +0800 Subject: [PATCH] =?UTF-8?q?entity=E6=94=AF=E6=8C=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: linjunjie --- .../js_insight_intent_driver.cpp | 14 +- .../js_insight_intent_driver_utils.cpp | 31 +++ .../js_insight_intent_driver_utils.h | 2 + .../insight_intent/insight_intent_constant.h | 11 +- .../insight_intent_info_for_query.h | 9 + .../insight_intent/insight_intent_utils.h | 4 +- .../abilitymgr/src/ability_manager_proxy.cpp | 6 +- .../src/ability_manager_service.cpp | 74 ++++++- .../insight_intent_info_for_query.cpp | 59 +++++- .../insight_intent/insight_intent_utils.cpp | 33 +++- .../ability_manager_service_sixth_test.cpp | 181 ++++++++++++++++++ .../insight_intent_utils_test.cpp | 47 ++++- 12 files changed, 451 insertions(+), 20 deletions(-) diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp index 823c40e06e7..909deaa8da1 100644 --- a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp @@ -171,7 +171,9 @@ private: GetInsightIntentFlag flag; if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], flag) || (flag != GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT && - flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT)) { + flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT && + flag != (GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO) && + flag != (GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO))) { TAG_LOGE(AAFwkTag::INTENT, "Parse flag failed"); ThrowInvalidParamError(env, "Parse param flag failed, flag must be GetInsightIntentFlag."); return CreateJsUndefined(env); @@ -212,7 +214,9 @@ private: GetInsightIntentFlag flag; if (!ConvertFromJsValue(env, info.argv[INDEX_ONE], flag) || (flag != GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT && - flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT)) { + flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT && + flag != (GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO) && + flag != (GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO))) { TAG_LOGE(AAFwkTag::INTENT, "Parse flag failed"); ThrowInvalidParamError(env, "Parse param flag failed, flag must be GetInsightIntentFlag."); return CreateJsUndefined(env); @@ -266,7 +270,9 @@ private: GetInsightIntentFlag flag; if (!ConvertFromJsValue(env, info.argv[INDEX_THREE], flag) || (flag != GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT && - flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT)) { + flag != GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT && + flag != (GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO) && + flag != (GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | GetInsightIntentFlag::GET_ENTITY_INFO))) { TAG_LOGE(AAFwkTag::INTENT, "Parse flag failed"); ThrowInvalidParamError(env, "Parse param flag failed, flag must be GetInsightIntentFlag."); return CreateJsUndefined(env); @@ -332,6 +338,8 @@ static napi_value InitGetInsightIntentFlagObject(napi_env env) env, napiObject, "GET_FULL_INSIGHT_INTENT", GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT)); NAPI_CALL(env, SetEnumItem( env, napiObject, "GET_SUMMARY_INSIGHT_INTENT", GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT)); + NAPI_CALL(env, SetEnumItem( + env, napiObject, "GET_ENTITY_INFO", GetInsightIntentFlag::GET_ENTITY_INFO)); return napiObject; } diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp index ec80d58af69..0218e43c1a8 100644 --- a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp @@ -85,6 +85,36 @@ napi_value CreateFormInfoForQuery(napi_env env, const FormInfoForQuery &info) return objValue; } +napi_value CreateEntityInfoForArray(napi_env env, const std::vector &infos) +{ + napi_value arrayValue = nullptr; + napi_create_array_with_length(env, infos.size(), &arrayValue); + uint32_t index = 0; + for (const auto &info : infos) { + napi_set_element(env, arrayValue, index++, CreateJsEntityInfo(env, info)); + } + + return arrayValue; +} + +napi_value CreateJsEntityInfo(napi_env env, const EntityInfoForQuery &info) +{ + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "null obj"); + return nullptr; + } + + napi_set_named_property(env, objValue, "className", CreateJsValue(env, info.className)); + napi_set_named_property(env, objValue, "entityId", CreateJsValue(env, info.entityId)); + napi_set_named_property(env, objValue, "entityCategory", CreateJsValue(env, info.entityCategory)); + napi_set_named_property(env, objValue, "parameters", CreateInsightIntentInfoParam(env, info.parameters)); + napi_set_named_property(env, objValue, "parentClassName", CreateJsValue(env, info.parentClassName)); + + return objValue; +} + napi_value CreateInsightIntentInfoWithJson(napi_env env, const nlohmann::json &jsonObject) { if (jsonObject.is_object()) { @@ -173,6 +203,7 @@ napi_value CreateInsightIntentInfoForQuery(napi_env env, const InsightIntentInfo napi_set_named_property(env, objValue, "parameters", CreateInsightIntentInfoParam(env, info.parameters)); napi_set_named_property(env, objValue, "result", CreateInsightIntentInfoResult(env, info.result)); napi_set_named_property(env, objValue, "keywords", CreateNativeArray(env, info.keywords)); + napi_set_named_property(env, objValue, "entities", CreateEntityInfoForArray(env, info.entities)); if (info.intentType == INSIGHT_INTENTS_TYPE_LINK) { napi_set_named_property(env, objValue, "subIntentInfo", CreateLinkInfoForQuery(env, info.linkInfo)); } else if (info.intentType == INSIGHT_INTENTS_TYPE_PAGE) { diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h index 6eff220acad..d718809ce8c 100644 --- a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h @@ -34,6 +34,8 @@ napi_value CreateInsightIntentInfoParam(napi_env env, const std::string ¶mSt napi_value CreateInsightIntentInfoResult(napi_env env, const std::string &resultStr); napi_value CreateInsightIntentInfoForQuery(napi_env env, const InsightIntentInfoForQuery &info); napi_value CreateInsightIntentInfoForQueryArray(napi_env env, const std::vector &infos); +napi_value CreateJsEntityInfo(napi_env env, const EntityInfoForQuery &info); +napi_value CreateEntityInfoForArray(napi_env env, const std::vector &infos); } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_DRIVER_UTILS_H diff --git a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_constant.h b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_constant.h index 8514c2b40d8..2ce6285c7f5 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_constant.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_constant.h @@ -49,8 +49,14 @@ namespace OHOS::AbilityRuntime { constexpr char INSIGHT_INTENT_LINK_INFO[] = "linkInfo"; constexpr char INSIGHT_INTENT_PAGE_INFO[] = "pageInfo"; constexpr char INSIGHT_INTENT_ENTRY_INFO[] = "entryInfo"; + constexpr char INSIGHT_INTENT_ENTITY_INFO[] = "entities"; constexpr char INSIGHT_INTENT_FUNCTION_INFO[] = "functionInfo"; constexpr char INSIGHT_INTENT_FORM_INFO[] = "formInfo"; + constexpr char INSIGHT_INTENT_ENTITY_CLASS_NAME[] = "className"; + constexpr char INSIGHT_INTENT_ENTITY_CATEGORY[] = "entityCategory"; + constexpr char INSIGHT_INTENT_ENTITY_ID[] = "entityId"; + constexpr char INSIGHT_INTENT_ENTITY_PARENT_CLASS_NAME[] = "parentClassName"; + constexpr char INSIGHT_INTENT_ENTITY_PARAMETERS[] = "parameters"; enum class InsightIntentExecuteMode { UIABILITY_FOREGROUND, @@ -69,7 +75,10 @@ namespace OHOS::AbilityRuntime { enum GetInsightIntentFlag { GET_FULL_INSIGHT_INTENT = 1, - GET_SUMMARY_INSIGHT_INTENT + GET_SUMMARY_INSIGHT_INTENT, + GET_ENTITY_INFO = 4, + GET_FULL_INSIGHT_INTENT_ENTITY, + GET_SUMMARY_INSIGHT_INTENT_ENTITY, }; enum class InsightIntentType : uint8_t { diff --git a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_info_for_query.h b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_info_for_query.h index 758b12104e9..9466eca108f 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_info_for_query.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_info_for_query.h @@ -45,6 +45,14 @@ struct FunctionInfoForQuery {}; struct FormInfoForQuery {}; +struct EntityInfoForQuery { + std::string className; + std::string entityId; + std::string entityCategory; + std::string parameters; + std::string parentClassName; +}; + struct InsightIntentInfoForQuery : public Parcelable { std::string bundleName; std::string moduleName; @@ -65,6 +73,7 @@ struct InsightIntentInfoForQuery : public Parcelable { EntryInfoForQuery entryInfo; FunctionInfoForQuery functionInfo; FormInfoForQuery formInfo; + std::vector entities {}; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_utils.h b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_utils.h index 017f1444263..c2e251b242d 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_utils.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_utils.h @@ -33,7 +33,9 @@ public: static uint32_t ConvertExtractInsightIntentGenericInfo( ExtractInsightIntentGenericInfo &genericInfo, InsightIntentInfoForQuery &queryInfo); static uint32_t ConvertExtractInsightIntentInfo( - ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo); + ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo, bool getEntity); + static uint32_t ConvertExtractInsightIntentEntityInfo( + ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index a7aca2e9eff..a4aeafd9655 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -6468,7 +6468,7 @@ int32_t AbilityManagerProxy::GetAllInsightIntentInfo( TAG_LOGE(AAFwkTag::INTENT, "write flag fail"); return ERR_INVALID_VALUE; } - + int error = SendRequest( AbilityManagerInterfaceCode::GET_ALL_INSIGHT_INTENT_INFO, data, reply, option); if (error != NO_ERROR) { @@ -6510,7 +6510,7 @@ int32_t AbilityManagerProxy::GetInsightIntentInfoByBundleName( TAG_LOGE(AAFwkTag::INTENT, "write bundleName fail"); return ERR_INVALID_VALUE; } - + int error = SendRequest( AbilityManagerInterfaceCode::GET_INSIGHT_INTENT_INFO_BY_BUNDLE_NAME, data, reply, option); if (error != NO_ERROR) { @@ -6564,7 +6564,7 @@ int32_t AbilityManagerProxy::GetInsightIntentInfoByIntentName( TAG_LOGE(AAFwkTag::INTENT, "write intentName fail"); return ERR_INVALID_VALUE; } - + int error = SendRequest( AbilityManagerInterfaceCode::GET_INSIGHT_INTENT_INFO_BY_INTENT_NAME, data, reply, option); if (error != NO_ERROR) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a8e70944708..ef24fdb3239 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -14227,7 +14227,7 @@ int32_t AbilityManagerService::GetAllInsightIntentInfo( TAG_LOGD(AAFwkTag::INTENT, "not system app or permission denied"); return ret; } - if (flag == AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { std::vector intentInfos; const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; DelayedSingleton::GetInstance()->GetAllInsightIntentInfo(userId, intentInfos); @@ -14236,24 +14236,45 @@ int32_t AbilityManagerService::GetAllInsightIntentInfo( return ERR_OK; } TAG_LOGD(AAFwkTag::INTENT, "intentInfos size: %{public}zu", intentInfos.size()); + bool getEntity = (flag & AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO); for (auto &info : intentInfos) { InsightIntentInfoForQuery intentInfoQuery; - InsightIntentUtils::ConvertExtractInsightIntentInfo(info, intentInfoQuery); + InsightIntentUtils::ConvertExtractInsightIntentInfo(info, intentInfoQuery, getEntity); infos.emplace_back(intentInfoQuery); } - } else { + } else if (flag & AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT) { std::vector genericInfos; DelayedSingleton::GetInstance()->GetAllInsightIntentGenericInfo(genericInfos); if (genericInfos.empty()) { return ERR_OK; } TAG_LOGD(AAFwkTag::INTENT, "genericInfos size: %{public}zu", genericInfos.size()); + + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO) { + std::vector intentInfos; + const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + DelayedSingleton::GetInstance()->GetAllInsightIntentInfo(userId, intentInfos); + if (intentInfos.empty()) { + TAG_LOGI(AAFwkTag::INTENT, "extractInsightIntentInfos empty"); + return ERR_OK; + } + for (auto &info : intentInfos) { + InsightIntentInfoForQuery intentInfoQuery; + InsightIntentUtils::ConvertExtractInsightIntentEntityInfo(info, intentInfoQuery); + infos.emplace_back(intentInfoQuery); + } + return ERR_OK; + } + for (auto &info : genericInfos) { InsightIntentInfoForQuery intentInfoQuery; InsightIntentUtils::ConvertExtractInsightIntentGenericInfo(info, intentInfoQuery); infos.emplace_back(intentInfoQuery); } + } else { + TAG_LOGW(AAFwkTag::INTENT, "invalid flag: %{public}d", flag); } + return ERR_OK; } @@ -14268,7 +14289,7 @@ int32_t AbilityManagerService::GetInsightIntentInfoByBundleName( TAG_LOGD(AAFwkTag::INTENT, "not system app or permission denied"); return ret; } - if (flag == AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { std::vector intentInfos; const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; DelayedSingleton::GetInstance()->GetInsightIntentInfoByName( @@ -14278,12 +14299,13 @@ int32_t AbilityManagerService::GetInsightIntentInfoByBundleName( return ERR_OK; } TAG_LOGD(AAFwkTag::INTENT, "intentInfos size: %{public}zu", intentInfos.size()); + bool getEntity = (flag & AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO); for (auto &info : intentInfos) { InsightIntentInfoForQuery intentInfoQuery; - InsightIntentUtils::ConvertExtractInsightIntentInfo(info, intentInfoQuery); + InsightIntentUtils::ConvertExtractInsightIntentInfo(info, intentInfoQuery, getEntity); infos.emplace_back(intentInfoQuery); } - } else { + } else if (flag & AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT) { std::vector genericInfos; DelayedSingleton::GetInstance()->GetInsightIntentGenericInfoByName( bundleName, genericInfos); @@ -14291,11 +14313,30 @@ int32_t AbilityManagerService::GetInsightIntentInfoByBundleName( return ERR_OK; } TAG_LOGD(AAFwkTag::INTENT, "genericInfos size: %{public}zu", genericInfos.size()); + + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO) { + std::vector intentInfos; + const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + DelayedSingleton::GetInstance()->GetInsightIntentInfoByName( + bundleName, userId, intentInfos); + if (intentInfos.empty()) { + TAG_LOGI(AAFwkTag::INTENT, "extractInsightIntentInfos empty"); + return ERR_OK; + } + for (auto &info : intentInfos) { + InsightIntentInfoForQuery intentInfoQuery; + InsightIntentUtils::ConvertExtractInsightIntentEntityInfo(info, intentInfoQuery); + infos.emplace_back(intentInfoQuery); + } + return ERR_OK; + } for (auto &info : genericInfos) { InsightIntentInfoForQuery intentInfoQuery; InsightIntentUtils::ConvertExtractInsightIntentGenericInfo(info, intentInfoQuery); infos.emplace_back(intentInfoQuery); } + } else { + TAG_LOGW(AAFwkTag::INTENT, "invalid flag: %{public}d", flag); } return ERR_OK; } @@ -14313,17 +14354,32 @@ int32_t AbilityManagerService::GetInsightIntentInfoByIntentName( TAG_LOGD(AAFwkTag::INTENT, "not system app or permission denied"); return ret; } - if (flag == AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT) { ExtractInsightIntentInfo intentInfo; const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; DelayedSingleton::GetInstance()->GetInsightIntentInfo( bundleName, moduleName, intentName, userId, intentInfo); - InsightIntentUtils::ConvertExtractInsightIntentInfo(intentInfo, info); - } else { + bool getEntity = (flag & AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT); + InsightIntentUtils::ConvertExtractInsightIntentInfo(intentInfo, info, getEntity); + } else if (flag & AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT) { + + if (flag & AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO) { + ExtractInsightIntentInfo intentInfo; + const int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + DelayedSingleton::GetInstance()->GetInsightIntentInfo( + bundleName, moduleName, intentName, userId, intentInfo); + InsightIntentUtils::ConvertExtractInsightIntentEntityInfo(intentInfo, info); + + return ERR_OK; + } + ExtractInsightIntentGenericInfo genericInfo; DelayedSingleton::GetInstance()->GetInsightIntentGenericInfo( bundleName, moduleName, intentName, genericInfo); InsightIntentUtils::ConvertExtractInsightIntentGenericInfo(genericInfo, info); + + } else { + TAG_LOGW(AAFwkTag::INTENT, "invalid flag: %{public}d", flag); } return ERR_OK; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp b/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp index 9f5447a430f..0540ea2c71f 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_info_for_query.cpp @@ -143,6 +143,54 @@ void to_json(nlohmann::json& jsonObject, const EntryInfoForQuery &info) }; } +void from_json(const nlohmann::json &jsonObject, EntityInfoForQuery &entityInfo) +{ + TAG_LOGD(AAFwkTag::INTENT, "EntityInfoForQuery from json"); + const auto &jsonObjectEnd = jsonObject.end(); + AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_CLASS_NAME, + entityInfo.className, + true, + g_parseResult); + AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_ID, + entityInfo.entityId, + true, + g_parseResult); + AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_CATEGORY, + entityInfo.entityCategory, + true, + g_parseResult); + AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_PARAMETERS, + entityInfo.parameters, + true, + g_parseResult); + AppExecFwk::BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_PARENT_CLASS_NAME, + entityInfo.parentClassName, + true, + g_parseResult); +} + +void to_json(nlohmann::json& jsonObject, const EntityInfoForQuery &info) +{ + TAG_LOGD(AAFwkTag::INTENT, "EntityInfoForQuery to json"); + jsonObject = nlohmann::json { + {INSIGHT_INTENT_ENTITY_CLASS_NAME, info.className}, + {INSIGHT_INTENT_ENTITY_ID, info.entityId}, + {INSIGHT_INTENT_ENTITY_CATEGORY, info.entityCategory}, + {INSIGHT_INTENT_PARAMETERS, info.parameters}, + {INSIGHT_INTENT_ENTITY_PARENT_CLASS_NAME, info.parentClassName} + }; +} + void from_json(const nlohmann::json &jsonObject, InsightIntentInfoForQuery &insightIntentInfo) { TAG_LOGD(AAFwkTag::INTENT, "InsightIntentInfoForQuery from json"); @@ -233,6 +281,14 @@ void from_json(const nlohmann::json &jsonObject, InsightIntentInfoForQuery &insi false, g_parseResult, ArrayType::STRING); + AppExecFwk::GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + INSIGHT_INTENT_ENTITY_INFO, + insightIntentInfo.entities, + JsonType::ARRAY, + false, + g_parseResult, + ArrayType::OBJECT); if (insightIntentInfo.intentType == INSIGHT_INTENTS_TYPE_LINK) { AppExecFwk::GetValueIfFindKey(jsonObject, @@ -284,7 +340,8 @@ void to_json(nlohmann::json& jsonObject, const InsightIntentInfoForQuery &info) {INSIGHT_INTENT_KEYWORDS, info.keywords}, {INSIGHT_INTENT_LINK_INFO, info.linkInfo}, {INSIGHT_INTENT_PAGE_INFO, info.pageInfo}, - {INSIGHT_INTENT_ENTRY_INFO, info.entryInfo} + {INSIGHT_INTENT_ENTRY_INFO, info.entryInfo}, + {INSIGHT_INTENT_ENTITY_INFO, info.entities} }; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_utils.cpp b/services/abilitymgr/src/insight_intent/insight_intent_utils.cpp index 13543b8791d..15384d31794 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_utils.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_utils.cpp @@ -136,7 +136,7 @@ uint32_t InsightIntentUtils::ConvertExtractInsightIntentGenericInfo( } uint32_t InsightIntentUtils::ConvertExtractInsightIntentInfo( - ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo) + ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo, bool getEntity) { ConvertExtractInsightIntentGenericInfo(intentInfo.genericInfo, queryInfo); queryInfo.domain = intentInfo.domain; @@ -150,6 +150,37 @@ uint32_t InsightIntentUtils::ConvertExtractInsightIntentInfo( for (auto &keyword : intentInfo.keywords) { queryInfo.keywords.emplace_back(keyword); } + + if (getEntity) { + for (auto &entityInfo : intentInfo.entities) { + EntityInfoForQuery insightInfo; + insightInfo.className = entityInfo.className; + insightInfo.entityCategory = entityInfo.entityCategory; + insightInfo.entityId = entityInfo.entityId; + insightInfo.parameters = entityInfo.parameters; + insightInfo.parentClassName = entityInfo.parentClassName; + queryInfo.entities.emplace_back(insightInfo); + } + } + + return ERR_OK; +} + +uint32_t InsightIntentUtils::ConvertExtractInsightIntentEntityInfo( + ExtractInsightIntentInfo &intentInfo, InsightIntentInfoForQuery &queryInfo) +{ + ConvertExtractInsightIntentGenericInfo(intentInfo.genericInfo, queryInfo); + + for (auto &entityInfo : intentInfo.entities) { + EntityInfoForQuery insightInfo; + insightInfo.className = entityInfo.className; + insightInfo.entityCategory = entityInfo.entityCategory; + insightInfo.entityId = entityInfo.entityId; + insightInfo.parameters = entityInfo.parameters; + insightInfo.parentClassName = entityInfo.parentClassName; + queryInfo.entities.emplace_back(insightInfo); + } + return ERR_OK; } } // namespace AbilityRuntime diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index 225d192d90d..32dd38720ea 100644 --- a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp +++ b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp @@ -2049,6 +2049,62 @@ HWTEST_F(AbilityManagerServiceSixthTest, GetAllInsightIntentInfo_001, TestSize.L TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_001 end"); } +/* + * Feature: AbilityManagerService + * Function: GetAllInsightIntentInfo + * SubFunction: flag is GET_FULL_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetAllInsightIntentInfo + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetAllInsightIntentInfo_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_002 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::vector infos; + auto ret = abilityMs->GetAllInsightIntentInfo(flag, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_002 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetAllInsightIntentInfo + * SubFunction: flag is GET_SUMMARY_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetAllInsightIntentInfo + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetAllInsightIntentInfo_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_003 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::vector infos; + auto ret = abilityMs->GetAllInsightIntentInfo(flag, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_003 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetAllInsightIntentInfo + * SubFunction: invalid flag + * FunctionPoints: AbilityManagerService GetAllInsightIntentInfo + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetAllInsightIntentInfo_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_004 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::vector infos; + auto ret = abilityMs->GetAllInsightIntentInfo(flag, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetAllInsightIntentInfo_004 end"); +} + /* * Feature: AbilityManagerService * Function: GetInsightIntentInfoByBundleName @@ -2068,6 +2124,65 @@ HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByBundleName_001, T TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName end"); } +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByBundleName + * SubFunction: flag is GET_FULL_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByBundleName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByBundleName_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_002 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::vector infos; + auto ret = abilityMs->GetInsightIntentInfoByBundleName(flag, bundleName, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_002 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByBundleName + * SubFunction: flag is GET_SUMMARY_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByBundleName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByBundleName_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_003 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::vector infos; + auto ret = abilityMs->GetInsightIntentInfoByBundleName(flag, bundleName, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_003 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByBundleName + * SubFunction: invalid flag + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByBundleName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByBundleName_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_004 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::vector infos; + auto ret = abilityMs->GetInsightIntentInfoByBundleName(flag, bundleName, infos); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByBundleName_004 end"); +} + /* * Feature: AbilityManagerService * Function: GetInsightIntentInfoByIntentName @@ -2088,5 +2203,71 @@ HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByIntentName_001, T EXPECT_EQ(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_001 end"); } + +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByIntentName + * SubFunction: flag is GET_FULL_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByIntentName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByIntentName_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_002 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_FULL_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::string moduleName = "entry"; + std::string intentName = "test"; + InsightIntentInfoForQuery info; + auto ret = abilityMs->GetInsightIntentInfoByIntentName(flag, bundleName, moduleName, intentName, info); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_002 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByIntentName + * SubFunction: flag is GET_SUMMARY_INSIGHT_INTENT or GET_ENTITY_INFO + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByIntentName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByIntentName_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_003 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_SUMMARY_INSIGHT_INTENT | + AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::string moduleName = "entry"; + std::string intentName = "test"; + InsightIntentInfoForQuery info; + auto ret = abilityMs->GetInsightIntentInfoByIntentName(flag, bundleName, moduleName, intentName, info); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_003 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GetInsightIntentInfoByIntentName + * SubFunction: invalid flag + * FunctionPoints: AbilityManagerService GetInsightIntentInfoByIntentName + */ +HWTEST_F(AbilityManagerServiceSixthTest, GetInsightIntentInfoByIntentName_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_004 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + auto flag = AbilityRuntime::GetInsightIntentFlag::GET_ENTITY_INFO; + std::string bundleName = "com.example.bundleName"; + std::string moduleName = "entry"; + std::string intentName = "test"; + InsightIntentInfoForQuery info; + auto ret = abilityMs->GetInsightIntentInfoByIntentName(flag, bundleName, moduleName, intentName, info); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest GetInsightIntentInfoByIntentName_004 end"); +} + } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp index 534d251d720..672933b18c6 100644 --- a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp +++ b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp @@ -125,6 +125,9 @@ ExtractInsightIntentInfo TEST_INSIGHT_INTENT_INFO = [] { tmp.icon = "icon_test"; tmp.llmDescription = "llmDescription_test"; tmp.keywords = std::vector{ "keywords_test1", "keywords_test2" }; + tmp.entities = std::vector{ + { .className = "className_test", .entityId = "entityId_test", .entityCategory = "entityCategory_test", + .parameters = "parameters_test", .parentClassName = "parentClassName_test"}; tmp.genericInfo = TEST_INSIGHT_INTENT_GENERIC_INFO; return tmp; }(); @@ -328,11 +331,53 @@ HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentInfo_0100, TestSize. .WillRepeatedly(DoAll(SetArgReferee<3>(TEST_JSON_STR_ARRAY), Return(ERR_OK))); AbilityRuntime::InsightIntentUtils utils; InsightIntentInfoForQuery insightIntentInfoForQuery; - auto result = utils.ConvertExtractInsightIntentInfo(TEST_INSIGHT_INTENT_INFO, insightIntentInfoForQuery); + bool getEntity = false; + auto result = utils.ConvertExtractInsightIntentInfo(TEST_INSIGHT_INTENT_INFO, insightIntentInfoForQuery, getEntity); EXPECT_EQ(result, ERR_OK); Mock::VerifyAndClear(mockBundleMgr); testing::Mock::AllowLeak(mockBundleMgr); TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentInfo_0100 end."); } + +/** + * @tc.name: ConvertExtractInsightIntentInfo_0100 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentInfo_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentInfo_0200 start"); + EXPECT_CALL(*mockBundleMgr, GetJsonProfile(testing::_, testing::_, testing::_, testing::_, testing::_)) + .WillRepeatedly(DoAll(SetArgReferee<3>(TEST_JSON_STR_ARRAY), Return(ERR_OK))); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + bool getEntity = true; + auto result = utils.ConvertExtractInsightIntentInfo(TEST_INSIGHT_INTENT_INFO, insightIntentInfoForQuery, getEntity); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentInfo_0200 end."); +} + +/** + * @tc.name: ConvertExtractInsightIntentEntityInfo_0100 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentEntityInfo_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentInfo_0200 start"); + EXPECT_CALL(*mockBundleMgr, GetJsonProfile(testing::_, testing::_, testing::_, testing::_, testing::_)) + .WillRepeatedly(DoAll(SetArgReferee<3>(TEST_JSON_STR_ARRAY), Return(ERR_OK))); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + auto result = utils.ConvertExtractInsightIntentEntityInfo(TEST_INSIGHT_INTENT_INFO, insightIntentInfoForQuery); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentEntityInfo_0100 end."); +} + + } // namespace AAFwk } // namespace OHOS -- Gitee