diff --git a/bundle_framework_lite.gni b/bundle_framework_lite.gni index e8cbd1c551e49b0a1a1a9747fdd095a55819364e..7cc51aa23d699eee06c2aa9f76a7f8aabdcf6dec 100644 --- a/bundle_framework_lite.gni +++ b/bundle_framework_lite.gni @@ -26,4 +26,5 @@ utils_lite_path = "//commonlibrary/utils_lite" declare_args() { enable_ohos_bundle_manager_service = false enable_ohos_bundle_manager_service_permission = false + enable_ohos_bundle_manager_service_parse_metadata = false } diff --git a/frameworks/bundle_lite/BUILD.gn b/frameworks/bundle_lite/BUILD.gn index 85639d032de81f40008d85c6411fdb21fd1f1eb2..9f4c463088b2f381baeb0276c4a16012a374443e 100644 --- a/frameworks/bundle_lite/BUILD.gn +++ b/frameworks/bundle_lite/BUILD.gn @@ -31,6 +31,10 @@ lite_library("bundle") { if (ohos_kernel_type == "liteos_m") { target_type = "static_library" + if (enable_ohos_bundle_manager_service_parse_metadata == true) { + defines = [ "_MINI_BMS_PARSE_METADATA_" ] + } + sources = [ "src/ability_info.cpp", "src/ability_info_utils.cpp", diff --git a/frameworks/bundle_lite/include/ability_info_utils.h b/frameworks/bundle_lite/include/ability_info_utils.h index 21009f38a15280105b23bc1992ba978ffc72c263..1ea9401f779ed454c607c853b8ef094809a3174a 100644 --- a/frameworks/bundle_lite/include/ability_info_utils.h +++ b/frameworks/bundle_lite/include/ability_info_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,10 +17,16 @@ #define OHOS_ABILITYINFO_UTILS_H #include "ability_info.h" +#ifdef _MINI_BMS_PARSE_METADATA_ +#include "bundle_common.h" +#endif namespace OHOS { struct AbilityInfoUtils { static void CopyAbilityInfo(AbilityInfo *des, AbilityInfo src); +#ifdef _MINI_BMS_PARSE_METADATA_ + static void CopyBundleProfileToAbilityInfo(AbilityInfo *des, const BundleProfile &src); +#endif static bool SetAbilityInfoBundleName(AbilityInfo *abilityInfo, const char *bundleName); #ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER static bool SetAbilityInfoModuleName(AbilityInfo *abilityInfo, const char *moduleName); @@ -31,6 +37,12 @@ struct AbilityInfoUtils { static bool SetAbilityInfoLabel(AbilityInfo *abilityInfo, const char *label); #else static bool SetAbilityInfoSrcPath(AbilityInfo *abilityInfo, const char *srcPath); + static bool SetAbilityInfoMetaData(AbilityInfo *abilityInfo, MetaData **metaData, uint32_t numOfMetaData); + static bool SetAbilityInfoSkill(AbilityInfo *abilityInfo, Skill * const skills[]); + static void ClearStringArray(char *array[], int count); + static void CopyStringArray(char *dst[], char * const src[], int count); + static void ClearExtendedInfo(AbilityInfo *abilityInfo); + static void ClearAbilityInfoMetaData(MetaData **metaData, uint32_t numOfMetaData); #endif private: AbilityInfoUtils() = default; diff --git a/frameworks/bundle_lite/include/bundle_info_utils.h b/frameworks/bundle_lite/include/bundle_info_utils.h index 92af18583c51fd3cde4e86236818a58115133954..fb6499c70c8c442911ddb8a6f67ea6abc5119edd 100755 --- a/frameworks/bundle_lite/include/bundle_info_utils.h +++ b/frameworks/bundle_lite/include/bundle_info_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,9 @@ #define OHOS_BUNDLEINFO_UTILS_H #include "bundle_info.h" +#ifdef _MINI_BMS_PARSE_METADATA_ +#include "bundle_common.h" +#endif namespace OHOS { struct BundleInfoUtils { @@ -40,7 +43,11 @@ struct BundleInfoUtils { static void ClearAbilityInfos(AbilityInfo *abilityInfos, uint32_t numOfAbility); #else static bool SetBundleInfoSmallIconPath(BundleInfo *bundleInfo, const char *smallIconPath); - static bool SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, AbilityInfo abilityInfo); + static bool SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, const AbilityInfo &abilityInfo); +#ifdef _MINI_BMS_PARSE_METADATA_ + static bool SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, const AbilityInfo &abilityInfo, + const BundleProfile &bundleProfile); +#endif #endif private: BundleInfoUtils() = default; diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 8bfb2aecb5173483d36839f44941a6fdc79dc1b2..9b3faa22c87255e01cdfcc601001a1ae1b118a1d 100644 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -54,12 +54,18 @@ public: uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) const; + uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len) const; + PreAppList *InitPreAppInfo(void) const; void InsertPreAppInfo(const char *filePath, PreAppList *list) const; void SetPreAppInfo(PreAppList *list) const; + bool RegisterEvent(InstallerCallback installerCallback) const; + + bool UnregisterEvent(InstallerCallback installerCallback) const; + private: BundleMsClient() = default; diff --git a/frameworks/bundle_lite/src/ability_info.cpp b/frameworks/bundle_lite/src/ability_info.cpp index 6636b964d986eb96ce4bbcce0845143124b7cfbd..fa515e23e18278167fc619528a0be809ab94568a 100644 --- a/frameworks/bundle_lite/src/ability_info.cpp +++ b/frameworks/bundle_lite/src/ability_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,6 +14,7 @@ */ #include "ability_info.h" +#include "ability_info_utils.h" #include "utils.h" @@ -32,5 +33,6 @@ void ClearAbilityInfo(AbilityInfo *abilityInfo) AdapterFree(abilityInfo->label); #else AdapterFree(abilityInfo->srcPath); + OHOS::AbilityInfoUtils::ClearExtendedInfo(abilityInfo); #endif } \ No newline at end of file diff --git a/frameworks/bundle_lite/src/ability_info_utils.cpp b/frameworks/bundle_lite/src/ability_info_utils.cpp index 1077884fdb8f83a76026d256ba0f43db6fb5d9c9..1954af6b66fccf2be81024efd7e7f0aa5ec41123 100644 --- a/frameworks/bundle_lite/src/ability_info_utils.cpp +++ b/frameworks/bundle_lite/src/ability_info_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,9 +37,22 @@ void AbilityInfoUtils::CopyAbilityInfo(AbilityInfo *des, AbilityInfo src) SetAbilityInfoLabel(des, src.label); #else SetAbilityInfoSrcPath(des, src.srcPath); + SetAbilityInfoMetaData(des, src.metaData, METADATA_SIZE); + SetAbilityInfoSkill(des, src.skills); #endif } +#ifdef _MINI_BMS_PARSE_METADATA_ +void AbilityInfoUtils::CopyBundleProfileToAbilityInfo(AbilityInfo *des, const BundleProfile &src) +{ + if (des == nullptr) { + return; + } + SetAbilityInfoMetaData(des, src.abilityInfos->metaData, METADATA_SIZE); + SetAbilityInfoSkill(des, src.abilityInfos->skills); +} +#endif + bool AbilityInfoUtils::SetAbilityInfoBundleName(AbilityInfo *abilityInfo, const char *bundleName) { if (abilityInfo == nullptr || bundleName == nullptr) { @@ -128,5 +141,112 @@ bool AbilityInfoUtils::SetAbilityInfoSrcPath(AbilityInfo *abilityInfo, const cha abilityInfo->srcPath = Utils::Strdup(srcPath); return abilityInfo->srcPath != nullptr; } + +bool AbilityInfoUtils::SetAbilityInfoMetaData(AbilityInfo *abilityInfo, MetaData **metaData, uint32_t numOfMetaData) +{ + if (abilityInfo == nullptr || metaData == nullptr || numOfMetaData > METADATA_SIZE) { + return false; + } + ClearAbilityInfoMetaData(abilityInfo->metaData, METADATA_SIZE); + for (uint32_t i = 0; i < numOfMetaData; i++) { + if (metaData[i] != nullptr) { + abilityInfo->metaData[i] = reinterpret_cast(AdapterMalloc(sizeof(MetaData))); + if (abilityInfo->metaData[i] == nullptr || + memset_s(abilityInfo->metaData[i], sizeof(MetaData), 0, sizeof(MetaData)) != EOK) { + ClearAbilityInfoMetaData(abilityInfo->metaData, i); + return false; + } + if (metaData[i]->name != nullptr) { + abilityInfo->metaData[i]->name = Utils::Strdup(metaData[i]->name); + } + if (metaData[i]->value != nullptr) { + abilityInfo->metaData[i]->value = Utils::Strdup(metaData[i]->value); + } + if (metaData[i]->extra != nullptr) { + abilityInfo->metaData[i]->extra = Utils::Strdup(metaData[i]->extra); + } + if ((metaData[i]->name != nullptr && abilityInfo->metaData[i]->name == nullptr) || + (metaData[i]->value != nullptr && abilityInfo->metaData[i]->value == nullptr) || + (metaData[i]->extra != nullptr && abilityInfo->metaData[i]->extra == nullptr)) { + ClearAbilityInfoMetaData(abilityInfo->metaData, i); + return false; + } + } + } + return true; +} + +void AbilityInfoUtils::ClearStringArray(char *array[], int count) +{ + for (int i = 0; i < count; i++) { + if (array[i] == nullptr) { + continue; + } + AdapterFree(array[i]); + } +} + +void AbilityInfoUtils::CopyStringArray(char *dst[], char *const src[], int count) +{ + for (int i = 0; i < count; i++) { + dst[i] = Utils::Strdup(src[i]); + } +} + +bool AbilityInfoUtils::SetAbilityInfoSkill(AbilityInfo *abilityInfo, Skill * const skills[]) +{ + if (abilityInfo == nullptr || skills == nullptr) { + return false; + } + for (int i = 0; i < SKILL_SIZE; i++) { + if (abilityInfo->skills[i] != nullptr) { + ClearStringArray(abilityInfo->skills[i]->entities, MAX_SKILL_ITEM); + ClearStringArray(abilityInfo->skills[i]->actions, MAX_SKILL_ITEM); + AdapterFree(abilityInfo->skills[i]); + } + if (skills[i] == nullptr) { + return false; + } + abilityInfo->skills[i] = (Skill *)AdapterMalloc(sizeof(Skill)); + CopyStringArray(abilityInfo->skills[i]->entities, skills[i]->entities, MAX_SKILL_ITEM); + CopyStringArray(abilityInfo->skills[i]->actions, skills[i]->actions, MAX_SKILL_ITEM); + } + return true; +} + +void AbilityInfoUtils::ClearExtendedInfo(AbilityInfo *abilityInfo) +{ + for (int i = 0; i < METADATA_SIZE; i++) { + if(abilityInfo->metaData[i] == nullptr) { + continue; + } + AdapterFree(abilityInfo->metaData[i]->name); + AdapterFree(abilityInfo->metaData[i]->value); + AdapterFree(abilityInfo->metaData[i]->extra); + AdapterFree(abilityInfo->metaData[i]); + } + for (int i = 0; i < SKILL_SIZE; i++) { + if(abilityInfo->skills[i] == nullptr) { + continue; + } + ClearStringArray(abilityInfo->skills[i]->entities, MAX_SKILL_ITEM); + ClearStringArray(abilityInfo->skills[i]->actions, MAX_SKILL_ITEM); + AdapterFree(abilityInfo->skills[i]); + } +} +void AbilityInfoUtils::ClearAbilityInfoMetaData(MetaData **metaData, uint32_t numOfMetaData) +{ + if (metaData == nullptr || numOfMetaData > METADATA_SIZE) { + return; + } + for (uint32_t i = 0; i < numOfMetaData; i++) { + if (metaData[i] != nullptr) { + AdapterFree(metaData[i]->name); + AdapterFree(metaData[i]->value); + AdapterFree(metaData[i]->extra); + AdapterFree(metaData[i]); + } + } +} #endif } // OHOS \ No newline at end of file diff --git a/frameworks/bundle_lite/src/bundle_info_utils.cpp b/frameworks/bundle_lite/src/bundle_info_utils.cpp index 0f891eaf4386a7a8b730f4888ae26a888f4dd9fe..c2fd9e5134e85619baad9c3eedad67e4a37b6494 100755 --- a/frameworks/bundle_lite/src/bundle_info_utils.cpp +++ b/frameworks/bundle_lite/src/bundle_info_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -309,7 +309,7 @@ bool BundleInfoUtils::SetBundleInfoSmallIconPath(BundleInfo *bundleInfo, const c return bundleInfo->smallIconPath != nullptr; } -bool BundleInfoUtils::SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, AbilityInfo abilityInfo) +bool BundleInfoUtils::SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, const AbilityInfo &abilityInfo) { if (bundleInfo == nullptr) { return false; @@ -327,5 +327,26 @@ bool BundleInfoUtils::SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, AbilityIn AbilityInfoUtils::CopyAbilityInfo(bundleInfo->abilityInfo, abilityInfo); return true; } + +#ifdef _MINI_BMS_PARSE_METADATA_ +bool BundleInfoUtils::SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, const AbilityInfo &abilityInfo, + const BundleProfile &bundleProfile) +{ + if (bundleInfo == nullptr) { + return false; + } + ClearAbilityInfo(bundleInfo->abilityInfo); + AdapterFree(bundleInfo->abilityInfo); + bundleInfo->abilityInfo = reinterpret_cast(AdapterMalloc(sizeof(AbilityInfo))); + if (bundleInfo->abilityInfo ==nullptr || + memset_s(bundleInfo->abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)) != EOK) { + AdapterFree(bundleInfo->abilityInfo); + return false; + } + AbilityInfoUtils::CopyAbilityInfo(bundleInfo->abilityInfo, abilityInfo); + AbilityInfoUtils::CopyBundleProfileToAbilityInfo(bundleInfo->abilityInfo, bundleProfile); + return true; +} +#endif #endif } // OHOS \ No newline at end of file diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index cbae83426583b0e6bb19b0626ec0484c1be01f0c..172327e90680f2acda5de8f8b6ff9c404b8e6ccd 100644 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +44,21 @@ uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, i return OHOS::BundleMsClient::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); } +uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len) +{ + return OHOS::BundleMsClient::GetInstance().QueryAbilityInfos(want, abilityInfo, len); +} + +bool RegisterEvent(InstallerCallback installerCallback) +{ + return OHOS::BundleMsClient::GetInstance().RegisterEvent(installerCallback); +} + +bool UnregisterEvent(InstallerCallback installerCallback) +{ + return OHOS::BundleMsClient::GetInstance().UnregisterEvent(installerCallback); +} + PreAppList *InitPreAppInfo(void) { return OHOS::BundleMsClient::GetInstance().InitPreAppInfo(); diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index e9c51ecf10c12e66aeb30fb8e585ae902c0936c9..11a04951b7d050313b57df3664202ae0c06cbdd8 100644 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -229,6 +229,39 @@ uint8_t BundleMsClient::GetBundleInfosNoReplication (const int flags, BundleInfo return bmsProxy_->GetBundleInfosNoReplication(flags, bundleInfos, len); } +uint8_t BundleMsClient::QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len) const +{ + if (want == nullptr || (abilityInfo == nullptr)) { + return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; + } + if (!Initialize()) { + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; + } + return bmsProxy_->QueryAbilityInfos(want, abilityInfo, len); +} + +bool BundleMsClient::RegisterEvent(InstallerCallback installerCallback) const +{ + if (installerCallback == nullptr) { + return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; + } + if (!Initialize()) { + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; + } + return bmsProxy_->RegisterEvent(installerCallback); +} + +bool BundleMsClient::UnregisterEvent(InstallerCallback installerCallback) const +{ + if (installerCallback == nullptr) { + return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; + } + if (!Initialize()) { + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; + } + return bmsProxy_->UnregisterEvent(installerCallback); +} + PreAppList *BundleMsClient::InitPreAppInfo () const { if (!Initialize()) { diff --git a/interfaces/inner_api/bundlemgr_lite/bundle_service_interface.h b/interfaces/inner_api/bundlemgr_lite/bundle_service_interface.h index 4aa018139220221d3742c6b0be512760c4e68c35..ed63d9915f38ecb146c00a604aa8d021a71a8eaa 100644 --- a/interfaces/inner_api/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/inner_api/bundlemgr_lite/bundle_service_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -58,6 +58,9 @@ struct BmsSliteInterface { bool (*RegisterInstallerCallback)(InstallerCallback installerCallback); void (*UpdateBundleInfoList)(); uint8_t (*GetBundleInfosNoReplication)(const int flags, BundleInfo **bundleInfos, int32_t *len); + uint8_t (*QueryAbilityInfos)(const Want *want, AbilityInfo **abilityInfo, int32_t *len); + bool (*RegisterEvent)(InstallerCallback installerCallback); + bool (*UnregisterEvent)(InstallerCallback installerCallback); PreAppList *(*InitPreAppInfo)(void); void (*InsertPreAppInfo)(const char *filePath, PreAppList *list); void (*SetPreAppInfo)(PreAppList *list); diff --git a/interfaces/inner_api/bundlemgr_lite/slite/bundle_install_msg.h b/interfaces/inner_api/bundlemgr_lite/slite/bundle_install_msg.h index 81b4ea3b4f8e9276f44c8b2ccfed0d856f257155..5db3adf9c297d2c63bbb79885241767605c7b00d 100644 --- a/interfaces/inner_api/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/inner_api/bundlemgr_lite/slite/bundle_install_msg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +44,7 @@ typedef struct { char *bigIconPath; InstallState installState; uint8_t installProcess; + uint8_t actionService; } BundleInstallMsg; typedef struct { @@ -102,6 +103,32 @@ void UpdateBundleInfoList(void); */ uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); +/** + * @brief Query qualified abilityInfo according to want. + * + * @param want The want provided by ActivityManagerService contains the actions fiels you want to query. + * @param abilityInfo Qualified abilityInfo. + * @param len Indicates the pointer to the number of {@link abilityInfo} objects obtained. + * @return Returns {@link ERR_OK} if this function is successfully called; + */ +uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len); + +/** + * @brief Register an event callback to return the specified HCE tag. + * + * @param installerCallback callback function. + * @return Returns result if this function is successfully called; + */ +bool RegisterEvent(InstallerCallback installerCallback); + +/** + * @brief Unregister an event callback, which is used to cancel the RegisterEvent. + * + * @param installerCallback callback function. + * @return Returns result if this function is successfully called; + */ +bool UnregisterEvent(InstallerCallback installerCallback); + /** * @brief Initializing preset application information. * diff --git a/interfaces/kits/bundle_lite/ability_info.h b/interfaces/kits/bundle_lite/ability_info.h index 3292bdbeec92b2140be60515b345f9fc7092517b..e7dd8714eff7dbed2cdcd71283397a366ca1e0a2 100755 --- a/interfaces/kits/bundle_lite/ability_info.h +++ b/interfaces/kits/bundle_lite/ability_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -43,6 +43,7 @@ #include #include "stdint.h" +#include "module_info.h" #ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER /** @@ -97,6 +98,16 @@ typedef struct { #endif +#define MAX_SKILL_ITEM 4 +/** + * @brief Defines the skill information. + */ +typedef struct { + char *entities[MAX_SKILL_ITEM]; + char *actions[MAX_SKILL_ITEM]; +} Skill; +#define SKILL_SIZE 16 + /** * @brief Defines the ability information. */ @@ -140,6 +151,9 @@ typedef struct { #endif /** Pointer to the application bundle name */ char *bundleName; + /** metadata/skills for ablity info. */ + MetaData *metaData[METADATA_SIZE]; + Skill *skills[SKILL_SIZE]; } AbilityInfo; #ifdef __cplusplus diff --git a/interfaces/kits/bundle_lite/appexecfwk_errors.h b/interfaces/kits/bundle_lite/appexecfwk_errors.h index 9110f9687f05c396294c1ecc3e92457b694d8f9e..7dada8fff0e125032fa6657e62b46b8752b53fed 100755 --- a/interfaces/kits/bundle_lite/appexecfwk_errors.h +++ b/interfaces/kits/bundle_lite/appexecfwk_errors.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -279,6 +279,9 @@ enum AppexecfwkErrors { /** Failed to install the application due to a request sending error. */ ERR_APPEXECFWK_INSTALL_FAILED_SEND_REQUEST_ERROR, + /** Failed to parse the ability skill*/ + ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR, + /** Failed to uninstall the application due to an internal error. */ ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR = 90, diff --git a/interfaces/kits/bundle_lite/bundle_manager.h b/interfaces/kits/bundle_lite/bundle_manager.h index 39086ae6b95041242cec444df43dd225ba445415..3843a249cb6209bbb06be5206fd55913240a81d2 100755 --- a/interfaces/kits/bundle_lite/bundle_manager.h +++ b/interfaces/kits/bundle_lite/bundle_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -141,6 +141,32 @@ bool Uninstall(const char *bundleName, const InstallParam *installParam, Install */ uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); +/** + * @brief Query qualified abilityInfo according to want. + * + * @param want The want provided by ActivityManagerService contains the actions fiels you want to query. + * @param abilityInfo Qualified abilityInfo. + * @param len Indicates the pointer to the number of {@link abilityInfo} objects obtained. + * @return Returns {@link ERR_OK} if this function is successfully called; + */ +uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len); + +/** + * @brief Register an event callback to return the specified HCE tag. + * + * @param installerCallback callback function. + * @return Returns result if this function is successfully called; + */ +bool RegisterEvent(InstallerCallback installerCallback); + +/** + * @brief Unregister an event callback, which is used to cancel the RegisterEvent. + * + * @param installerCallback callback function. + * @return Returns result if this function is successfully called; + */ +bool UnregisterEvent(InstallerCallback installerCallback); + /** * @brief Obtains the {@link BundleInfo} of an application based on the specified bundle name. * diff --git a/services/bundlemgr_lite/BUILD.gn b/services/bundlemgr_lite/BUILD.gn index 4c52d73c6e0165fa0aba116ab028f2be922d9bb0..d40543b2679cb7f982c23c74098346bd6945fde5 100644 --- a/services/bundlemgr_lite/BUILD.gn +++ b/services/bundlemgr_lite/BUILD.gn @@ -45,6 +45,10 @@ if (ohos_kernel_type == "liteos_m") { ] } + if (enable_ohos_bundle_manager_service_parse_metadata == true) { + defines += [ "_MINI_BMS_PARSE_METADATA_" ] + } + deps = [ "${ace_engine_lite_path}/frameworks:ace_lite", "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", diff --git a/services/bundlemgr_lite/include/bundle_common.h b/services/bundlemgr_lite/include/bundle_common.h index 161dca9947121c99cc4f3560aa1c8aebe0fa48bc..e832a434fdcd635b478b0158209547436369548f 100644 --- a/services/bundlemgr_lite/include/bundle_common.h +++ b/services/bundlemgr_lite/include/bundle_common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,6 +31,7 @@ extern "C" { namespace OHOS { const char PROFILE_NAME[] = "config.json"; +const char SERVICE_NAME[] = "ohos.nfc.cardemulation.action.HOST_APDU_SERVICE"; const char JSON_SUFFIX[] = ".json"; const char PATH_SEPARATOR[] = "/"; const char FILE_DELIMITER[] = "_"; @@ -76,6 +77,9 @@ const char PROFILE_KEY_VERSION_NAME[] = "name"; const char PROFILE_KEY_APIVERSION[] = "apiVersion"; const char PROFILE_KEY_APIVERSION_COMPATIBLE[] = "compatible"; const char PROFILE_KEY_APIVERSION_TARGET[] = "target"; +const char PROFILE_KEY_SKILLS[] = "skills"; +const char PROFILE_KEY_SKILLS_ENTITIES[] = "entities"; +const char PROFILE_KEY_SKILLS_ACTIONS[] = "actions"; // deviceConfig const char PROFILE_KEY_DEVICECONFIG[] = "deviceConfig"; const char PROFILE_KEY_DEVICECONFIG_DEFAULT[] = "default"; @@ -240,10 +244,8 @@ struct BundleProfile { ProfileVersion profileVersion; ProfileApiVersion profileApiVersion; ModuleInfo moduleInfo; -#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER AbilityInfo *abilityInfos; uint32_t numOfAbility; -#endif }; struct Permissions { diff --git a/services/bundlemgr_lite/include/bundle_map.h b/services/bundlemgr_lite/include/bundle_map.h index 7a72cc1f886ac90c94b7e29925bbc2e3b34bea10..88d9ef75b81a802654eab0e831bd4920da50ae24 100644 --- a/services/bundlemgr_lite/include/bundle_map.h +++ b/services/bundlemgr_lite/include/bundle_map.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,7 @@ public: bool Update(BundleInfo *bundleInfo); BundleInfo *Get(const char *bundleName) const; uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; + uint8_t GetBundleInfosInner(List &bundleInfos) const; uint8_t GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const; void Erase(const char *bundleName); diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index 349ef9bb7f44c606d99c19ee636c1f1ed5c41a93..579e42859b38ae07d71d77a0e1e263f43f2f1536 100644 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -40,6 +40,9 @@ public: static bool RegisterInstallerCallback(InstallerCallback installerCallback); static void UpdateBundleInfoList(); static uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); + static uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len); + static bool RegisterEvent(InstallerCallback installerCallback); + static bool UnregisterEvent(InstallerCallback installerCallback); static PreAppList *InitPreAppInfo(); static void InsertPreAppInfo(const char *filePath, PreAppList *list); static void SetPreAppInfo(PreAppList *list); diff --git a/services/bundlemgr_lite/include/gt_bundle_extractor.h b/services/bundlemgr_lite/include/gt_bundle_extractor.h index 037a1565eab8e2bcc612f4919ccab7ab8641b382..eca82fbd613982ec546f990743eba9a32ce76df3 100644 --- a/services/bundlemgr_lite/include/gt_bundle_extractor.h +++ b/services/bundlemgr_lite/include/gt_bundle_extractor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,10 +27,14 @@ public: static char *ExtractHapProfile(int32_t fp, uint32_t totalFileSize); static uint8_t ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName); static uint8_t ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, - char **bigIconPath); + char **bigIconPath, uint8_t &actionService); + static uint8_t ParseBundleInfoGetActionService(const char *bundleName); + private: static uint8_t ExtractFileDataPos(int32_t fp, uint64_t &filePos); static bool ExtractResourceFile(const char *path, int32_t fp, uint32_t totalFileSize); + static uint8_t FindSkillService(AbilityInfo *abilityInfo); + static uint8_t CompareStringArray(char *actions[], int count); }; } // namespace OHOS #endif // OHOS_GT_BUNDLE_EXTRACTOR_H \ No newline at end of file diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index b01db917f8e5f359642520409066cbb40c892c93..75bd7033ed000d25bcb428ad2e55781623712d89 100644 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -43,6 +43,7 @@ typedef enum { BUNDLE_UPDATE, } BundleState; +void RegisterListenCallbackFunc(const uint8_t resultCode, const void *resultMessage); class GtManagerService { public: static GtManagerService &GetInstance() @@ -53,7 +54,8 @@ public: bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback); bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback); uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); - uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); + uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len); + uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo); uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); void ScanPackages(); @@ -68,16 +70,18 @@ public: void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); void AddNumOfThirdBundles(); void ReduceNumOfThirdBundles(); - int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState, - uint8_t process, InstallerCallback installerCallback); - int32_t ReportUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, - uint8_t process, InstallerCallback installerCallback); + int32_t ReportInstallCallback( + uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback); + int32_t ReportUninstallCallback( + uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process, InstallerCallback installerCallback); bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); uint32_t GetBundleSize(const char *bundleName); bool RegisterInstallerCallback(InstallerCallback installerCallback); PreAppList *InitPreAppInfo(void); void InsertPreAppInfo(const char *filePath, PreAppList *list); void SetPreAppInfo(PreAppList *list); + bool RegisterEvent(InstallerCallback installerCallback); + bool UnregisterEvent(InstallerCallback installerCallback); private: GtManagerService(); @@ -100,6 +104,12 @@ private: void InstallPreBundle(List systemPathList, InstallerCallback installerCallback); void QueryPreAppInfo(const char *appDir, PreAppList *list); void FreePreAppInfo(const PreAppList *list); + int32_t ReportHceInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process); + int32_t ReportHceUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process); + static bool MatchSkills(const Want *want, Skill *const skills[]); + static bool isMatchActions(const char *actions, char *const skillActions[]); + static bool isMatchEntities(const char *entities, char *const skillEntities[]); + static bool isMatch(const char *dst, const char *src); GtBundleInstaller *installer_; BundleMap *bundleMap_; @@ -111,6 +121,7 @@ private: PreAppList *preAppList_; bool updateFlag_; int32_t oldVersionCode_; + List *listenList_; }; } diff --git a/services/bundlemgr_lite/include/gt_bundle_parser.h b/services/bundlemgr_lite/include/gt_bundle_parser.h index d3b8d2745fc0e0d5e398d0a4bf60bc733010388d..f9599b6bfb502438ebf324843d20c0c3645a7f31 100644 --- a/services/bundlemgr_lite/include/gt_bundle_parser.h +++ b/services/bundlemgr_lite/include/gt_bundle_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -41,6 +41,11 @@ private: static uint8_t ParseAbilityInfo(const cJSON *abilityInfoObjects, BundleProfile &bundleProfile, BundleRes &bundleRes); static uint8_t ParseModuleMetaData(const cJSON *moduleObject, BundleProfile &bundleProfile); + static uint8_t ParseAllAbilityInfo(const cJSON *abilityObjects, BundleProfile &bundleProfile); + static uint8_t ParsePerAbilityInfo(const cJSON *abilityObjects, AbilityInfo &abilityInfo); + static uint8_t ParseMetaData(const cJSON *moduleObject, MetaData *metaData[], int maxCount); + static uint8_t ParseAbilitySkills(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo); + static uint8_t ParseOneSkill(const cJSON *skillObject, Skill &skill); static bool SetModuleInfos(const BundleProfile &bundleProfile, BundleInfo *bundleInfo); static uint8_t SaveBundleInfo(const BundleProfile &bundleProfile, const BundleRes &bundleRes, BundleInfo **bundleInfo); diff --git a/services/bundlemgr_lite/src/bundle_map.cpp b/services/bundlemgr_lite/src/bundle_map.cpp index 767ae113638636f8ec271e951175ad441028b959..e20bfe6586eb6316f8f2cdef2651ed5229e499ad 100755 --- a/services/bundlemgr_lite/src/bundle_map.cpp +++ b/services/bundlemgr_lite/src/bundle_map.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -204,6 +204,17 @@ uint8_t BundleMap::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32 return ERR_OK; } +uint8_t BundleMap::GetBundleInfosInner(List &bundleInfos) const +{ + if (bundleInfos_->IsEmpty()) { + return ERR_APPEXECFWK_QUERY_NO_INFOS; + } + for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { + bundleInfos.PushBack(node->value_); + } + return ERR_OK; +} + uint8_t BundleMap::GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const { if (bundleInfos == nullptr) { diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 2299561ced3297915a7c8b0bf8de0fb28e899b54..0706c9b6cc68681df37a265f88a6d33543155610 100644 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,9 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback, .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList, .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication, + .QueryAbilityInfos = BundleMgrSliteFeature::QueryAbilityInfos, + .RegisterEvent = BundleMgrSliteFeature::RegisterEvent, + .UnregisterEvent = BundleMgrSliteFeature::UnregisterEvent, .InitPreAppInfo = BundleMgrSliteFeature::InitPreAppInfo, .InsertPreAppInfo = BundleMgrSliteFeature::InsertPreAppInfo, .SetPreAppInfo = BundleMgrSliteFeature::SetPreAppInfo, @@ -148,6 +151,21 @@ uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, Bund return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); } +uint8_t BundleMgrSliteFeature::QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len) +{ + return OHOS::GtManagerService::GetInstance().QueryAbilityInfos(want, abilityInfo, len); +} + +bool BundleMgrSliteFeature::RegisterEvent(InstallerCallback installerCallback) +{ + return OHOS::GtManagerService::GetInstance().RegisterEvent(installerCallback); +} + +bool BundleMgrSliteFeature::UnregisterEvent(InstallerCallback installerCallback) +{ + return OHOS::GtManagerService::GetInstance().UnregisterEvent(installerCallback); +} + PreAppList *BundleMgrSliteFeature::InitPreAppInfo() { return OHOS::GtManagerService::GetInstance().InitPreAppInfo(); diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 70899cf5cfbbe25075228d4bdf1496a2f46ccb53..0b83466df46a60563d08de850099b1f2b60ccd1f 100644 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -183,8 +183,8 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32 return true; } -uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, - char **bigIconPath) +uint8_t GtBundleExtractor::ExtractInstallMsg( + const char *path, char **bundleName, char **label, char **smallIconPath, char **bigIconPath, uint8_t &actionService) { #ifdef _MINI_BMS_PERMISSION_ RefreshAllServiceTimeStamp(); @@ -227,6 +227,8 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName *label = Utils::Strdup(bundleInfo->label); *smallIconPath = Utils::Strdup(bundleInfo->smallIconPath); *bigIconPath = Utils::Strdup(bundleInfo->bigIconPath); + // find bundleInfo->abilityInfo->skills[i]->actions whether contain HOST_APDU_SERVICE + actionService = FindSkillService(bundleInfo->abilityInfo); if (*bundleName == nullptr || *label == nullptr || *smallIconPath == nullptr || *bigIconPath == nullptr) { BundleInfoUtils::FreeBundleInfo(bundleInfo); return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR; @@ -235,6 +237,46 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName return ERR_OK; } +uint8_t GtBundleExtractor::ParseBundleInfoGetActionService(const char *bundleName) +{ + if (bundleName == nullptr) { + return ERR_OK; + } + BundleInfo *bundleInfo = OHOS::GtManagerService::GetInstance().QueryBundleInfo(bundleName); + if (bundleInfo == nullptr) { + return ERR_OK; + } + // find bundleInfo->abilityInfo->skills[i]->actions whether contain HOST_APDU_SERVICE + uint8_t actionService = FindSkillService(bundleInfo->abilityInfo); + return actionService; +} +uint8_t GtBundleExtractor::FindSkillService(AbilityInfo *abilityInfo) +{ + if (abilityInfo == nullptr) { + return 0; + } + for (int i = 0; i < SKILL_SIZE; i++) { + if (abilityInfo->skills[i] != nullptr) { + if (CompareStringArray(abilityInfo->skills[i]->actions, MAX_SKILL_ITEM)) { + return 1; + } + } + } + return 0; +} +uint8_t GtBundleExtractor::CompareStringArray(char *actions[], int count) +{ + for (int i = 0; i < count; i++) { + if (actions[i] == nullptr) { + continue; + } + if (strcmp(actions[i], SERVICE_NAME) == 0) { + return 1; + } + } + return 0; +} + uint8_t GtBundleExtractor::ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName) { if (!BundleUtil::CheckRealPath(path)) { diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index beaea77459effae5c9d46b9c9d8f1851ed21df22..496ed055b06c6fe77581e07f67eaa40a028b12b7 100644 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -56,6 +56,7 @@ GtManagerService::GtManagerService() preAppList_ = nullptr; updateFlag_ = false; oldVersionCode_ = -1; + listenList_ = new List(); } GtManagerService::~GtManagerService() @@ -64,6 +65,8 @@ GtManagerService::~GtManagerService() installer_ = nullptr; delete bundleResList_; bundleResList_ = nullptr; + delete listenList_; + listenList_ = nullptr; } bool GtManagerService::Install(const char *hapPath, const InstallParam *installParam, @@ -101,11 +104,18 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP return false; } // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ - uint8_t ret = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName), - &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), - &(bundleInstallMsg_->bigIconPath)); + uint8_t ret = GtBundleExtractor::ExtractInstallMsg(path, + &(bundleInstallMsg_->bundleName), + &(bundleInstallMsg_->label), + &(bundleInstallMsg_->smallIconPath), + &(bundleInstallMsg_->bigIconPath), + bundleInstallMsg_->actionService); if (ret != 0) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Install extract install msg failed, ret is %{public}d", ret); + if (bundleInstallMsg_->actionService) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] install fail and actionService is on."); + (void)ReportHceInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED); + } char *name = strrchr(path, '/'); bundleInstallMsg_->bundleName = Utils::Strdup(name + 1); (void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); @@ -137,9 +147,17 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP #endif HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] Install ret is %d", ret); if (ret == 0) { - (void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback); + (void)ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback); + if (bundleInstallMsg_->actionService) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install success and actionService is on."); + (void)ReportHceInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED); + } } else { - (void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); + (void)ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); + if (bundleInstallMsg_->actionService) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install fail and actionService is on."); + (void)ReportHceInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED); + } } SetCurrentBundle(nullptr); ClearSystemBundleInstallMsg(); @@ -170,9 +188,10 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins return false; } SetCurrentBundle(innerBundleName); - - (void) ReportUninstallCallback(OPERATION_DOING, BUNDLE_UNINSTALL_DOING, innerBundleName, - BMS_UNINSTALLATION_START, installerCallback); + // obtain the skill.action whether contain HOST_APDU_SERVICE + uint8_t actionService = GtBundleExtractor::ParseBundleInfoGetActionService(innerBundleName); + (void) ReportUninstallCallback( + OPERATION_DOING, BUNDLE_UNINSTALL_DOING, innerBundleName, BMS_UNINSTALLATION_START, installerCallback); #ifdef _MINI_BMS_PERMISSION_ DisableServiceWdg(); RefreshAllServiceTimeStamp(); @@ -184,11 +203,19 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins #endif HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] Uninstall ret is %d", ret); if (ret == 0) { - (void) ReportUninstallCallback(ret, BUNDLE_UNINSTALL_OK, innerBundleName, - BMS_INSTALLATION_COMPLETED, installerCallback); + (void) ReportUninstallCallback( + ret, BUNDLE_UNINSTALL_OK, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback); + if (actionService != 0) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] uninstall success and actionService is on."); + (void) ReportHceUninstallCallback(ret, BUNDLE_UNINSTALL_OK, innerBundleName, BMS_INSTALLATION_COMPLETED); + } } else { - (void) ReportUninstallCallback(ret, BUNDLE_UNINSTALL_FAIL, innerBundleName, - BMS_INSTALLATION_COMPLETED, installerCallback); + (void) ReportUninstallCallback( + ret, BUNDLE_UNINSTALL_FAIL, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback); + if (actionService != 0) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] uninstall fail and actionService is on."); + (void) ReportHceUninstallCallback(ret, BUNDLE_UNINSTALL_FAIL, innerBundleName, BMS_INSTALLATION_COMPLETED); + } } SetCurrentBundle(nullptr); @@ -265,7 +292,99 @@ uint8_t GtManagerService::QueryAbilityInfo(const Want *want, AbilityInfo *abilit return 1; } -uint8_t GtManagerService::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo) +uint8_t GtManagerService::QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len) +{ + if (want == nullptr || abilityInfo == nullptr || want->actions == nullptr || bundleMap_ == nullptr) { + return 0; + } + int32_t abilityInfoLen = 0; + List *bundleInfos_ = new List(); + bundleMap_->GetBundleInfosInner(*bundleInfos_); + + for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { + BundleInfo *info = node->value_; + if (info == nullptr || info->abilityInfo == nullptr) { + continue; + } + // find bundleInfo->abilityInfo->skills[i]->actions whether contain target string + if (MatchSkills(want, info->abilityInfo->skills)) { + abilityInfoLen++; + } + } + // Request memory + AbilityInfo *infos = reinterpret_cast(AdapterMalloc(sizeof(AbilityInfo) * abilityInfoLen)); + if (infos == nullptr || + memset_s(infos, sizeof(AbilityInfo) * abilityInfoLen, 0, sizeof(AbilityInfo) * abilityInfoLen) != EOK) { + AdapterFree(infos); + return ERR_APPEXECFWK_QUERY_INFOS_INIT_ERROR; + } + *abilityInfo = infos; + // copy the abilityInfo from bundleInfos + for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { + BundleInfo *info = node->value_; + if (info == nullptr || info->abilityInfo == nullptr) { + continue; + } + // find bundleInfo->abilityInfo->skills[i]->actions whether contain HOST_APDU_SERVICE + if (MatchSkills(want, info->abilityInfo->skills)) { + OHOS::AbilityInfoUtils::CopyAbilityInfo(infos++, *(info->abilityInfo)); + } + } + *len = abilityInfoLen; + return 1; +} +bool GtManagerService::MatchSkills(const Want *want, Skill *const skills[]) +{ + if (skills == nullptr || want == nullptr) { + return false; + } + for (int32_t i = 0; i < SKILL_SIZE; i++) { + if (skills[i] == nullptr) { + return false; + } + if (isMatchActions(want->actions, skills[i]->actions) || isMatchEntities(want->entities, skills[i]->entities)) { + return true; + } + } + return false; +} +bool GtManagerService::isMatchActions(const char *actions, char *const skillActions[]) +{ + if (actions == nullptr && skillActions == nullptr) { + return true; + } + for (int32_t i = 0; i < MAX_SKILL_ITEM; i++) { + if (skillActions[i] == nullptr) { + return false; + } + if (isMatch(actions, skillActions[i])) { + return true; + } + } + return false; +} +bool GtManagerService::isMatchEntities(const char *entities, char *const skillEntities[]) +{ + if (entities == nullptr) { + return true; + } + for (int32_t i = 0; i < MAX_SKILL_ITEM; i++) { + if (skillEntities[i] == nullptr) { + return false; + } + if (isMatch(entities, skillEntities[i])) { + return true; + } + } + return false; +} +bool GtManagerService::isMatch(const char *dst, const char *src) +{ + // compare whether is ohos.nfc.cardemulation.action.HOST_APDU_SERVICE + return strcmp(dst, src) == 0; +} + +uint8_t GtManagerService::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) { if (bundleMap_ == nullptr) { return ERR_APPEXECFWK_OBJECT_NULL; @@ -876,14 +995,7 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ if (jsPath == nullptr) { return; } - if (!BundleUtil::IsDir(jsPath)) { - AdapterFree(jsPath); - char *newJsPathComp[] = {const_cast(codePath), const_cast(NEW_ASSET_JS_PATH)}; - jsPath = BundleUtil::Strscat(newJsPathComp, sizeof(newJsPathComp) / sizeof(char *)); - if (jsPath == nullptr) { - return; - } - } + EXECRES result = walk_directory(jsPath); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] transform js to bc, result is %d", result); if (result != EXCE_ACE_JERRY_EXEC_OK) { @@ -987,8 +1099,81 @@ void GtManagerService::ReduceNumOfThirdBundles() installedThirdBundleNum_--; } -int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t installState, - uint8_t process, InstallerCallback installerCallback) +bool GtManagerService::RegisterEvent(InstallerCallback listenCallback) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] RegisterListen RegisterEvent"); + if (listenCallback == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] RegisterListen is fail because is null"); + return false; + } + listenList_->PushBack(listenCallback); + return true; +} + +bool GtManagerService::UnregisterEvent(InstallerCallback listenCallback) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] UnregisterListen UnregisterEvent"); + if (listenCallback == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] UnregisterListen is fail because is null"); + return false; + } + for (auto node = listenList_->Begin(); node != listenList_->End(); node = node->next_) { + if (node == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] Listener not found"); + return false; + } + if ((*(node->value_)) == listenCallback) { + listenList_->Remove(node); + return true; + } + } + return false; +} +int32_t GtManagerService::ReportHceInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] reportListener ReportHceInstallCallback"); + BundleInstallMsg *bundleInstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (memset_s(bundleInstallMsg, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { + AdapterFree(bundleInstallMsg); + } + if (bundleInstallMsg == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] ReportHceInstallCallback is fail because bundleInstallMsg is null"); + return -1; + } + bundleInstallMsg_->installState = static_cast(installState); + bundleInstallMsg_->installProcess = process; + bundleInstallMsg->installState = bundleInstallMsg_->installState; + bundleInstallMsg->installProcess = bundleInstallMsg_->installProcess; + bundleInstallMsg->bundleName = bundleInstallMsg_->bundleName; + for (auto node = listenList_->Begin(); node != listenList_->End(); node = node->next_) { + (*(node->value_))(errCode, bundleInstallMsg); + } + return 0; +} + +int32_t GtManagerService::ReportHceUninstallCallback( + uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] unReportListener ReportHceUninstallCallback"); + BundleInstallMsg *bundleInstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (memset_s(bundleInstallMsg, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { + AdapterFree(bundleInstallMsg); + } + if (bundleInstallMsg == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] ReportHceUninstallCallback is fail because bundleInstallMsg is null"); + return -1; + } + bundleInstallMsg->installState = static_cast(installState); + bundleInstallMsg->installProcess = process; + bundleInstallMsg->bundleName = bundleName; + for (auto node = listenList_->Begin(); node != listenList_->End(); node = node->next_) { + (*(node->value_))(errCode, bundleInstallMsg); + } + return 0; +} + +int32_t GtManagerService::ReportInstallCallback( + uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback) { if (bundleInstallMsg_ == nullptr) { return -1; diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index 5c82938f975b8c2b3c7c16ed629f80851d4a3bda..6421a84018e070c2ca4ebfb284dd4fb750b97699 100644 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -307,7 +307,161 @@ uint8_t GtBundleParser::ParseAbilityInfo(const cJSON *abilityInfoObjects, Bundle bundleProfile.srcPath = ParseValue(firstAbilityJson, PROFILE_KEY_MODULE_ABILITY_SRC_PATH); CHECK_NULL(bundleProfile.srcPath, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_SRC_PATH_ERROR); } + return ParseAllAbilityInfo(abilityInfoObjects, bundleProfile); +} +uint8_t GtBundleParser::ParseAllAbilityInfo(const cJSON *abilityObjects, BundleProfile &bundleProfile) +{ + const uint32_t MAX_ABILITY_NUM = 16; + uint32_t abilityNum = cJSON_GetArraySize(abilityObjects); + if (abilityNum == 0) { + return ERR_OK; + } + if (abilityNum > MAX_ABILITY_NUM) { + HILOG_ERROR( + HILOG_MODULE_AAFWK, "too many abilityInfos, (cur:%{public}d/max:%{public}d", abilityNum, MAX_ABILITY_NUM); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR; + } + uint32_t sizeInByte = abilityNum * sizeof(AbilityInfo); + AbilityInfo *abilityInfoPtr = reinterpret_cast(AdapterMalloc(sizeInByte)); + if (abilityInfoPtr == nullptr || memset_s(abilityInfoPtr, sizeInByte, 0, sizeInByte) != EOK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "abilityInfos alloc memory fail"); + AdapterFree(abilityInfoPtr); + return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; + } + bundleProfile.numOfAbility = abilityNum; + bundleProfile.abilityInfos = abilityInfoPtr; + const cJSON *object = nullptr; + cJSON_ArrayForEach(object, abilityObjects) { + abilityInfoPtr->bundleName = bundleProfile.bundleName; + uint8_t errorCode = ParsePerAbilityInfo(object, *abilityInfoPtr++); + CHECK_IS_TRUE((errorCode == ERR_OK), errorCode); + } + return ERR_OK; +} +uint8_t GtBundleParser::ParsePerAbilityInfo(const cJSON *abilityObjects, AbilityInfo &abilityInfo) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] start parse skill and metadata"); + uint8_t errorCode = ParseAbilitySkills(abilityObjects, abilityInfo); + if (errorCode != ERR_OK) { + return errorCode; + } + return ParseMetaData(abilityObjects, abilityInfo.metaData, METADATA_SIZE); +} +uint8_t GtBundleParser::ParseMetaData(const cJSON *moduleObject, MetaData *metaData[], int maxCount) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] start parse metadata"); + cJSON *object = ParseValue(moduleObject, PROFILE_KEY_MODULE_METADATA, nullptr); + // if no metadata, return ERR_OK + if (object == nullptr || object->type == cJSON_NULL) { + return ERR_OK; + } + object = cJSON_GetObjectItem(object, PROFILE_KEY_MODULE_METADATA_CUSTOMIZEDATA); + if (object == nullptr || object->type == cJSON_NULL) { + return ERR_OK; + } + CHECK_IS_TRUE((cJSON_IsArray(object) && (cJSON_GetArraySize(object) <= maxCount)), + ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR); + + int32_t i = 0; + cJSON *objectItem = nullptr; + cJSON_ArrayForEach(objectItem, object) + { + metaData[i] = reinterpret_cast(AdapterMalloc(sizeof(MetaData))); + if (metaData[i] == nullptr || memset_s(metaData[i], sizeof(MetaData), 0, sizeof(MetaData)) != EOK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "mallco metadate fail"); + return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; + } + if (cJSON_HasObjectItem(objectItem, PROFILE_KEY_MODULE_METADATA_NAME)) { + metaData[i]->name = Utils::Strdup(ParseValue(objectItem, PROFILE_KEY_MODULE_METADATA_NAME)); + CHECK_NULL(metaData[i]->name, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR); + CHECK_LENGTH(strlen(metaData[i]->name), + MAX_METADATA_NAME, + ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_NAME_LENGTH_ERROR); + } + + if (cJSON_HasObjectItem(objectItem, PROFILE_KEY_MODULE_METADATA_VALUE)) { + metaData[i]->value = Utils::Strdup(ParseValue(objectItem, PROFILE_KEY_MODULE_METADATA_VALUE)); + CHECK_NULL(metaData[i]->value, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR); + CHECK_LENGTH(strlen(metaData[i]->value), + MAX_METADATA_VALUE, + ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_VALUE_LENGTH_ERROR); + } + + if (cJSON_HasObjectItem(objectItem, PROFILE_KEY_MODULE_METADATA_EXTRA)) { + metaData[i]->extra = Utils::Strdup(ParseValue(objectItem, PROFILE_KEY_MODULE_METADATA_EXTRA)); + CHECK_NULL(metaData[i]->extra, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR); + } + i++; + } + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] end parse metadata"); + return ERR_OK; +} +uint8_t GtBundleParser::ParseAbilitySkills(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] start parse skills"); + cJSON *skillsObject = ParseValue(abilityObjectItem, PROFILE_KEY_SKILLS, nullptr); + if (skillsObject == nullptr) { + return ERR_OK; + } + CHECK_IS_TRUE((cJSON_IsArray(skillsObject) && (cJSON_GetArraySize(skillsObject) <= SKILL_SIZE)), + ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR); + + int32_t i = 0; + cJSON *object = nullptr; + cJSON_ArrayForEach(object, skillsObject) + { + Skill *skillPtr = reinterpret_cast(AdapterMalloc(sizeof(Skill))); + if (skillPtr == nullptr || memset_s(skillPtr, sizeof(Skill), 0, sizeof(Skill)) != EOK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "mallco metadate fail"); + return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; + } + if (ParseOneSkill(object, *skillPtr) != ERR_OK) { + AdapterFree(skillPtr); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR; + } + abilityInfo.skills[i++] = skillPtr; + } + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] end parse skills"); + return ERR_OK; +} + +uint8_t GtBundleParser::ParseOneSkill(const cJSON *skillObject, Skill &skill) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] start parse one skill"); + cJSON *entities = ParseValue(skillObject, PROFILE_KEY_SKILLS_ENTITIES, nullptr); + cJSON *actions = ParseValue(skillObject, PROFILE_KEY_SKILLS_ACTIONS, nullptr); + if (entities == nullptr && actions == nullptr) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] entities and actions is invalid"); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR; + } + int entitiesCount = cJSON_GetArraySize(entities); + int actionsCount = cJSON_GetArraySize(actions); + if (entitiesCount > MAX_SKILL_ITEM || actionsCount > MAX_SKILL_ITEM) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] too many skills or actions configuredd"); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR; + } + int32_t i = 0; + cJSON *object = nullptr; + cJSON_ArrayForEach(object, entities) + { + if (!cJSON_IsString(object)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] a string is expected in entities"); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR; + } + skill.entities[i++] = Utils::Strdup(object->valuestring); + } + i = 0; + object = nullptr; + cJSON_ArrayForEach(object, actions) + { + if (!cJSON_IsString(object)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] a string is expected in actions"); + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_SKILLS_ERROR; + } + skill.actions[i++] = Utils::Strdup(object->valuestring); + } + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] end parse one skill"); return ERR_OK; } @@ -429,11 +583,19 @@ BundleInfo *GtBundleParser::CreateBundleInfo(const char *path, const BundleProfi // set abilityInfo AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = bundleInfo->bundleName}; +#ifdef _MINI_BMS_PARSE_METADATA_ + if (!BundleInfoUtils::SetBundleInfoAbilityInfo(bundleInfo, abilityInfo, bundleProfile)) { + AdapterFree(abilityInfo.srcPath); + BundleInfoUtils::FreeBundleInfo(bundleInfo); + return nullptr; + } +#else if (!BundleInfoUtils::SetBundleInfoAbilityInfo(bundleInfo, abilityInfo)) { AdapterFree(abilityInfo.srcPath); BundleInfoUtils::FreeBundleInfo(bundleInfo); return nullptr; } +#endif AdapterFree(abilityInfo.srcPath); return bundleInfo; } @@ -652,12 +814,21 @@ uint8_t GtBundleParser::SaveBundleInfo(const BundleProfile &bundleProfile, const AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = (*bundleInfo)->bundleName}; // set abilityInfo +#ifdef _MINI_BMS_PARSE_METADATA_ + if (!BundleInfoUtils::SetBundleInfoAbilityInfo(*bundleInfo, abilityInfo, bundleProfile)) { + AdapterFree(jsPath); + BundleInfoUtils::FreeBundleInfo(*bundleInfo); + *bundleInfo = nullptr; + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; + } +#else if (!BundleInfoUtils::SetBundleInfoAbilityInfo(*bundleInfo, abilityInfo)) { AdapterFree(jsPath); BundleInfoUtils::FreeBundleInfo(*bundleInfo); *bundleInfo = nullptr; return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } +#endif AdapterFree(jsPath); return ERR_OK; }