!256 轻鸿蒙特性回合

Merge pull request !256 from wangdengjia/0530appexecfwk
This commit is contained in:
openharmony_ci
2023-08-04 06:56:32 +00:00
committed by Gitee
27 changed files with 810 additions and 59 deletions
+1
View File
@@ -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
}
+4
View File
@@ -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",
@@ -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;
@@ -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;
@@ -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;
+3 -1
View File
@@ -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
}
@@ -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<MetaData *>(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
@@ -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<AbilityInfo *>(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
@@ -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();
@@ -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()) {
@@ -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);
@@ -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.
*
+15 -1
View File
@@ -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 <stdbool.h>
#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
@@ -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,
+27 -1
View File
@@ -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.
*
+4
View File
@@ -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",
@@ -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 {
+2 -1
View File
@@ -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<BundleInfo *> &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);
@@ -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);
@@ -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
@@ -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<ToBeInstalledApp *> 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<InstallerCallback> *listenList_;
};
}
@@ -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);
+12 -1
View File
@@ -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<BundleInfo *> &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) {
@@ -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();
@@ -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)) {
@@ -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<InstallerCallback>();
}
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<BundleInfo *> *bundleInfos_ = new List<BundleInfo *>();
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<AbilityInfo *>(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<char *>(codePath), const_cast<char *>(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<BundleInstallMsg *>(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>(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<BundleInstallMsg *>(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>(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;
@@ -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<AbilityInfo *>(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<MetaData *>(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<Skill *>(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;
}
@@ -656,12 +818,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;
}