[bm]:add cffi code

Signed-off-by: atreeof_wind <shaoyifan2@huawei.com>
This commit is contained in:
atreeof_wind 2024-04-28 14:40:38 +08:00
parent 6bf5b3f1ce
commit 3e56cfe389
13 changed files with 1440 additions and 0 deletions

View File

@ -20,6 +20,7 @@ group("bms_target") {
"interfaces/inner_api/appexecfwk_base:appexecfwk_base",
"interfaces/inner_api/appexecfwk_core:appexecfwk_core",
"interfaces/inner_api/bundlemgr_extension:bundlemgr_extension",
"interfaces/kits/cj:cj_bundle_manager",
"interfaces/kits/js:napi_packages",
"interfaces/kits/native/app_detail_ability:app_detail_ability",
"interfaces/kits/native/bundle:bundle_ndk",

View File

@ -25,6 +25,7 @@ if (vendor_config_exist) {
bundle_mgr_impl_include_dirs = []
}
arkui_path = "//foundation/arkui"
bundle_framework_path = "//foundation/bundlemanager/bundle_framework"
ecological_rule_mgr_path = "//foundation/bundlemanager/ecological_rule_mgr/interfaces/innerkits/include"
common_path = "${bundle_framework_path}/common"

View File

@ -0,0 +1,73 @@
# Copyright (c) 2024 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
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("../../../appexecfwk.gni")
ohos_shared_library("cj_bundle_manager") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
configs = [ "${arkui_path}/napi:ace_napi_config" ]
include_dirs = [
"src",
"${base_path}/include",
"${kits_path}/js/bundle_manager",
"${kits_path}/js/common",
]
if (!defined(defines)) {
defines = []
}
if (product_name != "ohos-sdk") {
sources = [
"src/bundle_manager.cpp",
"src/bundle_manager_convert.cpp",
"src/bundle_manager_ffi.cpp",
]
deps = [
"${base_path}:appexecfwk_base",
"${common_path}:libappexecfwk_common",
"${core_path}:appexecfwk_core",
"${kits_path}/js/common:bundle_napi_common",
]
external_deps = [
"ability_base:want",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_core",
"napi:cj_bind_ffi",
]
} else {
defines += [ "PREVIEWER" ]
sources = [ "src/bundle_manager_mock.cpp" ]
}
if (current_os == "ohos") {
defines += [ "OHOS_PLATFORM" ]
}
if (current_os == "mingw") {
defines += [ "WINDOWS_PLATFORM" ]
}
subsystem_name = "bundlemanager"
part_name = "bundle_framework"
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_BUNDLE_ERROR_H
#define OHOS_BUNDLE_ERROR_H
using ErrCode = int;
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
constexpr ErrCode SUCCESS_CODE = 0;
constexpr ErrCode ERROR_PERMISSION_DENIED_ERROR = 201;
constexpr ErrCode ERROR_NOT_SYSTEM_APP = 202;
constexpr ErrCode ERROR_PARAM_CHECK_ERROR = 401;
constexpr ErrCode ERROR_SYSTEM_ABILITY_NOT_FOUND = 801;
constexpr ErrCode ERROR_BUNDLE_NOT_EXIST = 17700001;
constexpr ErrCode ERROR_MODULE_NOT_EXIST = 17700002;
constexpr ErrCode ERROR_ABILITY_NOT_EXIST = 17700003;
constexpr ErrCode ERROR_INVALID_USER_ID = 17700004;
constexpr ErrCode ERROR_INVALID_APPID = 17700005;
constexpr ErrCode ERROR_PERMISSION_NOT_EXIST = 17700006;
constexpr ErrCode ERROR_DEVICE_ID_NOT_EXIST = 17700007;
constexpr ErrCode ERROR_INSTALL_PARSE_FAILED = 17700010;
constexpr ErrCode ERROR_INSTALL_VERIFY_SIGNATURE_FAILED = 17700011;
constexpr ErrCode ERROR_INSTALL_HAP_FILEPATH_INVALID = 17700012;
constexpr ErrCode ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT = 17700015;
constexpr ErrCode ERROR_INSTALL_NO_DISK_SPACE_LEFT = 17700016;
constexpr ErrCode ERROR_INSTALL_VERSION_DOWNGRADE = 17700017;
constexpr ErrCode ERROR_INSTALL_DEPENDENT_MODULE_NOT_EXIST = 17700018;
constexpr ErrCode ERROR_UNINSTALL_PREINSTALL_APP_FAILED = 17700020;
constexpr ErrCode ERROR_INVALID_UID = 17700021;
constexpr ErrCode ERROR_INVALID_HAP_PATH = 17700022;
constexpr ErrCode ERROR_DEFAULT_APP_NOT_EXIST = 17700023;
constexpr ErrCode ERROR_PROFILE_NOT_EXIST = 17700024;
constexpr ErrCode ERROR_INVALID_TYPE = 17700025;
constexpr ErrCode ERROR_BUNDLE_IS_DISABLED = 17700026;
constexpr ErrCode ERROR_DISTRIBUTED_SERVICE_NOT_RUNNING = 17700027;
constexpr ErrCode ERROR_ABILITY_AND_TYPE_MISMATCH = 17700028;
constexpr ErrCode ERROR_ABILITY_IS_DISABLED = 17700029;
constexpr ErrCode ERROR_CLEAR_CACHE_FILES_UNSUPPORTED = 17700030;
constexpr ErrCode ERROR_INSTALL_HAP_OVERLAY_CHECK_FAILED = 17700031;
constexpr ErrCode ERROR_SPECIFIED_BUNDLE_NOT_OVERLAY_BUNDLE = 17700032;
constexpr ErrCode ERROR_SPECIFIED_MODULE_NOT_OVERLAY_MODULE = 17700033;
constexpr ErrCode ERROR_SPECIFIED_MODULE_IS_OVERLAY_MODULE = 17700034;
constexpr ErrCode ERROR_SPECIFIED_BUNDLE_IS_OVERLAY_BUNDLE = 17700035;
constexpr ErrCode ERROR_INSTALL_SHARE_APP_LIBRARY_NOT_ALLOWED = 17700036;
constexpr ErrCode ERROR_UNINSTALL_SHARE_APP_LIBRARY_IS_RELIED = 17700037;
constexpr ErrCode ERROR_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST = 17700038;
constexpr ErrCode ERROR_INSTALL_FILE_IS_SHARED_LIBRARY = 17700039;
constexpr ErrCode ERROR_UNINSTALL_BUNDLE_IS_SHARED_BUNDLE = 17700040;
constexpr ErrCode ERROR_DISALLOW_INSTALL = 17700041;
constexpr ErrCode ERROR_INSTALL_WRONG_DATA_PROXY_URI = 17700042;
constexpr ErrCode ERROR_INSTALL_WRONG_DATA_PROXY_PERMISSION = 17700043;
constexpr ErrCode ERROR_INSTALL_WRONG_MODE_ISOLATION = 17700044;
constexpr ErrCode ERROR_DISALLOW_UNINSTALL = 17700045;
constexpr ErrCode ERROR_INSTALL_ALREADY_EXIST = 17700047;
constexpr ErrCode ERROR_INSTALL_CODE_SIGNATURE_FAILED = 17700048;
constexpr ErrCode ERROR_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME = 17700049;
constexpr ErrCode ERROR_INSTALL_ENTERPRISE_BUNDLE_NOT_ALLOWED = 17700050;
constexpr ErrCode ERROR_INSTALL_SELF_UPDATE_NOT_MDM = 17700051;
constexpr ErrCode ERROR_INSTALL_DEBUG_BUNDLE_NOT_ALLOWED = 17700052;
constexpr ErrCode ERROR_NOT_APP_GALLERY_CALL = 17700053;
// bundle service exception
constexpr ErrCode ERROR_BUNDLE_SERVICE_EXCEPTION = 17700101;
// verify abc
constexpr ErrCode ERROR_VERIFY_ABC = 17700201;
constexpr ErrCode ERROR_DELETE_ABC = 17700202;
// zlib errCode
constexpr ErrCode ERR_ZLIB_SRC_FILE_INVALID = 900001;
constexpr ErrCode ERR_ZLIB_DEST_FILE_INVALID = 900002;
constexpr ErrCode ERR_ZLIB_SRC_FILE_FORMAT_ERROR_OR_DAMAGED = 900003;
} // BundleManager
} // CJSystemapi
} // OHOS
#endif

View File

@ -0,0 +1,242 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vector>
#include <shared_mutex>
#include "bundle_manager.h"
#include "bundle_manager_log.h"
#include "bundle_info.h"
#include "bundle_mgr_proxy.h"
#include "common_func.h"
#include "bundle_error.h"
#include "bundle_manager_sync.h"
#include "extension_ability_info.h"
#include "ability_info.h"
#include "bundle_mgr_client.h"
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
AppExecFwk::BundleInfo BundleManagerImpl::GetBundleInfoForSelf(int32_t bundleFlags)
{
LOGI("BundleManagerImpl::GetBundleInfoForSelf inter");
auto iBundleMgr = AppExecFwk::CommonFunc::GetBundleMgr();
AppExecFwk::BundleInfo bundleInfo;
iBundleMgr->GetBundleInfoForSelf(bundleFlags, bundleInfo);
return bundleInfo;
}
int32_t BundleManagerImpl::VerifyAbc(std::vector<std::string> abcPaths, bool flag)
{
auto verifyManager = AppExecFwk::CommonFunc::GetVerifyManager();
if (verifyManager == nullptr) {
LOGE("iBundleMgr is null");
return ERROR_BUNDLE_SERVICE_EXCEPTION;
}
ErrCode ret = verifyManager->Verify(abcPaths);
if (ret == ERR_OK && flag) {
verifyManager->RemoveFiles(abcPaths);
}
return AppExecFwk::CommonFunc::ConvertErrCode(ret);
}
int32_t checkExtensionAbilityInfoExist(const std::string& abilityName,
const AppExecFwk::ExtensionAbilityInfo abilityInfo,
AppExecFwk::ExtensionAbilityInfo& targetAbilityInfo)
{
if (abilityInfo.name == abilityName) {
if (!abilityInfo.enabled) {
LOGI("ability disabled");
return ERROR_ABILITY_IS_DISABLED;
}
targetAbilityInfo = abilityInfo;
return ERR_OK;
}
return ERROR_ABILITY_NOT_EXIST;
}
std::tuple<bool, int32_t> checkExtensionName(const AppExecFwk::ExtensionAbilityInfo& extensionInfo,
const std::string& moduleName, const std::string& abilityName,
AppExecFwk::ExtensionAbilityInfo& targetExtensionInfo)
{
bool flag = false;
if (extensionInfo.moduleName == moduleName) {
flag = true;
int32_t res = checkExtensionAbilityInfoExist(abilityName, extensionInfo, targetExtensionInfo);
if (res != ERROR_ABILITY_NOT_EXIST) {
return {flag, res};
}
}
return {flag, ERROR_ABILITY_NOT_EXIST};
}
ErrCode CheckExtensionFromBundleInfo(const AppExecFwk::BundleInfo& bundleInfo, const std::string& abilityName,
const std::string& moduleName, AppExecFwk::ExtensionAbilityInfo& targetExtensionInfo)
{
bool flag = false;
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
for (const auto& extensionInfo : hapModuleInfo.extensionInfos) {
auto [flag, res] = checkExtensionName(extensionInfo, moduleName, abilityName, targetExtensionInfo);
if (flag == true && res != ERROR_ABILITY_NOT_EXIST) {
return res;
}
}
}
if (flag) {
return ERROR_ABILITY_NOT_EXIST;
} else {
return ERROR_MODULE_NOT_EXIST;
}
}
std::tuple<int32_t, std::vector<std::string>> BundleManagerImpl::GetProfileByExtensionAbility(
std::string moduleName, std::string extensionAbilityName, char* metadataName)
{
if (moduleName.empty()) {
LOGE("param failed due to empty moduleName");
return {ERROR_MODULE_NOT_EXIST, {}};
}
if (extensionAbilityName.empty()) {
LOGE("param failed due to empty extensionAbilityName");
return {ERROR_ABILITY_NOT_EXIST, {}};
}
auto naBundleMgr = AppExecFwk::CommonFunc::GetBundleMgr();
if (naBundleMgr == nullptr) {
return {ERROR_BUNDLE_SERVICE_EXCEPTION, {}};
}
auto baseFlag = static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) +
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) +
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE);
auto getExtensionFlag = baseFlag +
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY);
AppExecFwk::BundleInfo bundleInfo;
ErrCode ret = AppExecFwk::CommonFunc::ConvertErrCode(
naBundleMgr->GetBundleInfoForSelf(getExtensionFlag, bundleInfo));
if (ret != ERR_OK) {
LOGE("GetProfileByExAbilitySync failed");
return {ret, {}};
}
AppExecFwk::ExtensionAbilityInfo targetExtensionInfo;
ret = CheckExtensionFromBundleInfo(bundleInfo, extensionAbilityName, moduleName, targetExtensionInfo);
if (ret != ERR_OK) {
LOGE("GetProfileByExAbilitySync failed by CheckExtensionFromBundleInfo");
return {ret, {}};
}
AppExecFwk::BundleMgrClient client;
std::vector<std::string> profileVec;
if (!client.GetProfileFromExtension(targetExtensionInfo, metadataName, profileVec)) {
LOGE("GetProfileByExAbilitySync failed by GetProfileFromExtension");
return {ERROR_PROFILE_NOT_EXIST, {}};
}
return {SUCCESS_CODE, profileVec};
}
int32_t checkAbilityInfoExist(const std::string& abilityName, const AppExecFwk::AbilityInfo abilityInfo,
AppExecFwk::AbilityInfo& targetAbilityInfo)
{
if (abilityInfo.name == abilityName) {
if (!abilityInfo.enabled) {
LOGI("ability disabled");
return ERROR_ABILITY_IS_DISABLED;
}
targetAbilityInfo = abilityInfo;
return ERR_OK;
}
return ERROR_ABILITY_NOT_EXIST;
}
std::tuple<bool, int32_t> checkAbilityName(const AppExecFwk::AbilityInfo& abilityInfo, const std::string& moduleName,
const std::string& abilityName, AppExecFwk::AbilityInfo& targetAbilityInfo)
{
bool flag = false;
if (abilityInfo.moduleName == moduleName) {
flag = true;
int32_t res = checkAbilityInfoExist(abilityName, abilityInfo, targetAbilityInfo);
if (res != ERROR_ABILITY_NOT_EXIST) {
return {flag, res};
}
}
return {flag, ERROR_ABILITY_NOT_EXIST};
}
ErrCode CheckAbilityFromBundleInfo(const AppExecFwk::BundleInfo& bundleInfo, const std::string& abilityName,
const std::string& moduleName, AppExecFwk::AbilityInfo& targetAbilityInfo)
{
bool flag = false;
std::map<std::string, std::map<std::string, bool>> abilityInfos;
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
for (const auto& abilityInfo : hapModuleInfo.abilityInfos) {
auto [flag, res] = checkAbilityName(abilityInfo, moduleName, abilityName, targetAbilityInfo);
if (flag == true && res != ERROR_ABILITY_NOT_EXIST) {
return res;
}
}
}
if (flag) {
return ERROR_ABILITY_NOT_EXIST;
} else {
return ERROR_MODULE_NOT_EXIST;
}
}
std::tuple<int32_t, std::vector<std::string>> BundleManagerImpl::GetProfileByAbility(
std::string moduleName, std::string abilityName, char* metadataName)
{
LOGI("NAPI GetProfileByAbilitySync called");
if (moduleName.empty()) {
LOGE("param failed due to empty moduleName");
return {ERROR_MODULE_NOT_EXIST, {}};
}
if (abilityName.empty()) {
LOGE("param failed due to empty abilityName");
return {ERROR_ABILITY_NOT_EXIST, {}};
}
auto iBundleMgr = AppExecFwk::CommonFunc::GetBundleMgr();
if (iBundleMgr == nullptr) {
return {ERROR_BUNDLE_SERVICE_EXCEPTION, {}};
}
auto baseFlag = static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) +
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) +
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE);
auto getAbilityFlag = baseFlag + static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY);
AppExecFwk::BundleInfo bundleInfo;
ErrCode ret = AppExecFwk::CommonFunc::ConvertErrCode(iBundleMgr->GetBundleInfoForSelf(getAbilityFlag, bundleInfo));
if (ret != ERR_OK) {
LOGE("GetProfileByAbilitySync failed");
return {ret, {}};
}
AppExecFwk::AbilityInfo targetAbilityInfo;
ret = CheckAbilityFromBundleInfo(bundleInfo, abilityName, moduleName, targetAbilityInfo);
if (ret != ERR_OK) {
LOGE("GetProfileByAbilitySync failed by CheckAbilityFromBundleInfo");
return {ret, {}};
}
AppExecFwk::BundleMgrClient client;
std::vector<std::string> profileVec;
if (!client.GetProfileFromAbility(targetAbilityInfo, metadataName, profileVec)) {
LOGE("GetProfileByAbilitySync failed by GetProfileFromAbility");
return {ERROR_PROFILE_NOT_EXIST, {}};
}
return {SUCCESS_CODE, profileVec};
}
} // BundleManager
} // CJSystemapi
} // OHOS

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_BUNDLE_MANAGER_H
#define OHOS_BUNDLE_MANAGER_H
#include <cstdint>
#include <string>
#include "bundle_manager_utils.h"
#include "bundle_info.h"
#include "recoverable_application_info.h"
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
constexpr int UNSPECIFIED_USERID = -2;
constexpr int32_t BASE_USER_RANGE = 200000;
const std::string GET_BUNDLE_INFO = "GetBundleInfo";
class BundleManagerImpl {
public:
static AppExecFwk::BundleInfo GetBundleInfoForSelf(int32_t bundleFlags);
static int32_t VerifyAbc(std::vector<std::string> abcPaths, bool flag);
static std::tuple<int32_t, std::vector<std::string>> GetProfileByExtensionAbility(
std::string moduleName, std::string extensionAbilityName, char* metadataName);
static std::tuple<int32_t, std::vector<std::string>> GetProfileByAbility(
std::string moduleName, std::string abilityName, char* metadataName);
};
} // BundleManager
} // CJSystemapi
} // OHOS
#endif

View File

@ -0,0 +1,437 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdint>
#include <string>
#include "bundle_manager_utils.h"
#include "ipc_skeleton.h"
#include "bundle_info.h"
#include "bundle_mgr_proxy.h"
#include "common_func.h"
#include "bundle_manager_convert.h"
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
namespace Convert {
char *MallocCString(const std::string &origin)
{
if (origin.empty()) {
return nullptr;
}
auto len = origin.length() + 1;
char* res = (char*)malloc(sizeof(char) * len);
if (res == nullptr) {
return nullptr;
}
return std::char_traits<char>::copy(res, origin.c_str(), len);
}
CArrString g_convertArrString(std::vector<std::string> vecStr)
{
char **retValue = (char **)malloc(sizeof(char *) * vecStr.size());
if (vecStr.size() > 0) {
if (retValue != nullptr) {
for (int32_t i = 0; i < static_cast<int32_t>(vecStr.size()); i++) {
retValue[i] = MallocCString(vecStr[i]);
}
}
}
return {retValue, vecStr.size()};
}
RetUsedScene ConvertUsedScene(AppExecFwk::RequestPermissionUsedScene usedScence)
{
RetUsedScene uScene;
uScene.abilities = g_convertArrString(usedScence.abilities);
uScene.when = MallocCString(usedScence.when);
return uScene;
}
RetMetadata ConvertMetadata(AppExecFwk::Metadata cdata)
{
RetMetadata data;
data.name = MallocCString(cdata.name);
data.value = MallocCString(cdata.value);
data.resource = MallocCString(cdata.resource);
return data;
}
CResource ConvertResource(AppExecFwk::Resource cres)
{
CResource res;
res.bundleName = MallocCString(cres.bundleName);
res.moduleName = MallocCString(cres.moduleName);
res.id = cres.id;
return res;
}
CArrMetadata ConvertArrMetadata(std::vector<AppExecFwk::Metadata> cdata)
{
CArrMetadata data;
data.size = static_cast<int64_t>(cdata.size());
if (data.size > 0) {
RetMetadata *retValue = (RetMetadata *)malloc(sizeof(RetMetadata) * data.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < data.size; i++) {
retValue[i] = ConvertMetadata(cdata[i]);
}
data.head = retValue;
}
}
return data;
}
CArrMoMeta ConvertArrMoMeta(std::map<std::string, std::vector<AppExecFwk::Metadata>> metadata)
{
CArrMoMeta arrMdata;
arrMdata.size = static_cast<int64_t>(metadata.size());
if (arrMdata.size > 0) {
ModuleMetadata* retValue = (ModuleMetadata*)malloc(sizeof(ModuleMetadata) * arrMdata.size);
int32_t i = 0;
if (retValue != nullptr) {
for (const auto &item : metadata) {
retValue[i].moduleName = MallocCString(item.first);
retValue[i].metadata = ConvertArrMetadata(item.second);
i = i + 1;
}
}
arrMdata.head = retValue;
}
return arrMdata;
}
RetReqPermissionDetail ConvertRequestPermission(AppExecFwk::RequestPermission requestPermission)
{
RetReqPermissionDetail reqPer;
reqPer.name = MallocCString(requestPermission.name);
reqPer.moduleName = MallocCString(requestPermission.moduleName);
reqPer.reason = MallocCString(requestPermission.reason);
reqPer.reasonId = requestPermission.reasonId;
reqPer.usedScence = ConvertUsedScene(requestPermission.usedScene);
return reqPer;
}
RetApplicationInfo ConvertApplicationInfo(AppExecFwk::ApplicationInfo cAppInfo)
{
RetApplicationInfo appInfo;
appInfo.name = MallocCString(cAppInfo.name);
appInfo.description = MallocCString(cAppInfo.description);
appInfo.descriptionId = cAppInfo.descriptionId;
appInfo.enabled = cAppInfo.enabled;
appInfo.label = MallocCString(cAppInfo.label);
appInfo.labelId = cAppInfo.labelId;
appInfo.icon = MallocCString(cAppInfo.iconPath);
appInfo.iconId = cAppInfo.iconId;
appInfo.process = MallocCString(cAppInfo.process);
appInfo.permissions = g_convertArrString(cAppInfo.permissions);
appInfo.codePath = MallocCString(cAppInfo.codePath);
appInfo.metadataArray = ConvertArrMoMeta(cAppInfo.metadata);
appInfo.removable = cAppInfo.removable;
appInfo.accessTokenId = cAppInfo.accessTokenId;
appInfo.uid = cAppInfo.uid;
appInfo.iconResource = ConvertResource(cAppInfo.iconResource);
appInfo.labelResource = ConvertResource(cAppInfo.labelResource);
appInfo.descriptionResource = ConvertResource(cAppInfo.descriptionResource);
appInfo.appDistributionType = MallocCString(cAppInfo.appDistributionType);
appInfo.appProvisionType = MallocCString(cAppInfo.appProvisionType);
appInfo.systemApp = cAppInfo.isSystemApp;
appInfo.bundleType = static_cast<int32_t>(cAppInfo.bundleType);
appInfo.debug = cAppInfo.debug;
appInfo.dataUnclearable = !cAppInfo.userDataClearable;
return appInfo;
}
RetExtensionAbilityInfo ConvertExtensionAbilityInfo(AppExecFwk::ExtensionAbilityInfo extensionInfos)
{
RetExtensionAbilityInfo exInfo;
exInfo.bundleName = MallocCString(extensionInfos.bundleName);
exInfo.moduleName = MallocCString(extensionInfos.moduleName);
exInfo.name = MallocCString(extensionInfos.name);
exInfo.labelId = extensionInfos.labelId;
exInfo.descriptionId = extensionInfos.descriptionId;
exInfo.iconId = extensionInfos.iconId;
exInfo.exported = extensionInfos.visible;
exInfo.extensionAbilityType = static_cast<int32_t>(extensionInfos.type);
exInfo.permissions = g_convertArrString(extensionInfos.permissions);
exInfo.applicationInfo = ConvertApplicationInfo(extensionInfos.applicationInfo);
exInfo.metadata = ConvertArrMetadata(extensionInfos.metadata);
exInfo.enabled = extensionInfos.enabled;
exInfo.readPermission = MallocCString(extensionInfos.readPermission);
exInfo.writePermission = MallocCString(extensionInfos.writePermission);
exInfo.extensionAbilityTypeName = MallocCString(extensionInfos.extensionTypeName);
return exInfo;
}
CArrRetExtensionAbilityInfo ConvertArrExtensionAbilityInfo(
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos)
{
CArrRetExtensionAbilityInfo exAbInfo;
exAbInfo.size = static_cast<int64_t>(extensionInfos.size());
if (exAbInfo.size > 0) {
RetExtensionAbilityInfo *retValue = (RetExtensionAbilityInfo *)
malloc(sizeof(RetExtensionAbilityInfo) * exAbInfo.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < exAbInfo.size; i++) {
retValue[i] = ConvertExtensionAbilityInfo(extensionInfos[i]);
}
exAbInfo.head = retValue;
}
}
return exAbInfo;
}
RetSignatureInfo ConvertSignatureInfo(AppExecFwk::SignatureInfo cSignatureInfo)
{
RetSignatureInfo signatureInfo;
signatureInfo.appId = MallocCString(cSignatureInfo.appId);
signatureInfo.fingerprint = MallocCString(cSignatureInfo.fingerprint);
signatureInfo.appIdentifier = MallocCString(cSignatureInfo.appIdentifier);
return signatureInfo;
}
RetAbilityInfo ConvertAbilityInfo(AppExecFwk::AbilityInfo cAbilityInfos)
{
RetAbilityInfo abInfo;
abInfo.bundleName = MallocCString(cAbilityInfos.bundleName);
abInfo.moduleName = MallocCString(cAbilityInfos.moduleName);
abInfo.name = MallocCString(cAbilityInfos.name);
abInfo.label = MallocCString(cAbilityInfos.label);
abInfo.labelId = cAbilityInfos.labelId;
abInfo.description = MallocCString(cAbilityInfos.description);
abInfo.descriptionId = cAbilityInfos.descriptionId;
abInfo.icon = MallocCString(cAbilityInfos.iconPath);
abInfo.iconId = cAbilityInfos.iconId;
abInfo.process = MallocCString(cAbilityInfos.process);
abInfo.exported = cAbilityInfos.visible;
abInfo.orientation = static_cast<int32_t>(cAbilityInfos.orientation);
abInfo.launchType = static_cast<int32_t>(cAbilityInfos.launchMode);
abInfo.permissions = g_convertArrString(cAbilityInfos.permissions);
abInfo.deviceTypes = g_convertArrString(cAbilityInfos.deviceTypes);
abInfo.applicationInfo = ConvertApplicationInfo(cAbilityInfos.applicationInfo);
abInfo.metadata = ConvertArrMetadata(cAbilityInfos.metadata);
abInfo.enabled = cAbilityInfos.enabled;
abInfo.supportWindowModes.size = static_cast<int64_t>(cAbilityInfos.windowModes.size());
if (abInfo.supportWindowModes.size > 0) {
int32_t *retValue = (int32_t *)malloc(sizeof(int32_t) * abInfo.supportWindowModes.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < abInfo.supportWindowModes.size; i++) {
retValue[i] = static_cast<int32_t>(cAbilityInfos.windowModes[i]);
}
abInfo.supportWindowModes.head = retValue;
}
}
abInfo.windowSize.maxWindowRatio = cAbilityInfos.maxWindowRatio;
abInfo.windowSize.minWindowRatio = cAbilityInfos.minWindowRatio;
abInfo.windowSize.maxWindowWidth = cAbilityInfos.maxWindowWidth;
abInfo.windowSize.minWindowWidth = cAbilityInfos.minWindowWidth;
abInfo.windowSize.maxWindowHeight = cAbilityInfos.maxWindowHeight;
abInfo.windowSize.minWindowHeight = cAbilityInfos.minWindowHeight;
return abInfo;
}
CArrRetAbilityInfo ConvertArrAbilityInfo(std::vector<AppExecFwk::AbilityInfo> abilityInfos)
{
CArrRetAbilityInfo abInfo;
abInfo.size = static_cast<int64_t>(abilityInfos.size());
if (abInfo.size > 0) {
RetAbilityInfo *retValue = (RetAbilityInfo *)malloc(sizeof(RetAbilityInfo) * abInfo.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < abInfo.size; i++) {
retValue[i] = ConvertAbilityInfo(abilityInfos[i]);
}
abInfo.head = retValue;
}
}
return abInfo;
}
CArrRetPreloadItem ConvertPreloadItem(std::vector<AppExecFwk::PreloadItem> preloads)
{
CArrRetPreloadItem pLoad;
pLoad.size = static_cast<int64_t>(preloads.size());
if (pLoad.size > 0) {
RetPreloadItem *retValue = (RetPreloadItem *)malloc(sizeof(RetPreloadItem) * pLoad.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < pLoad.size; i++) {
retValue[i].moduleName = MallocCString(preloads[i].moduleName);
}
pLoad.head = retValue;
}
}
return pLoad;
}
CArrRetDependency ConvertDependency(std::vector<AppExecFwk::Dependency> dependencies)
{
CArrRetDependency dep;
dep.size = static_cast<int64_t>(dependencies.size());
if (dep.size > 0) {
RetDependency *retValue = (RetDependency *)malloc(sizeof(RetDependency) * dep.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < dep.size; i++) {
retValue[i].bundleName = MallocCString(dependencies[i].bundleName);
retValue[i].moduleName = MallocCString(dependencies[i].moduleName);
retValue[i].versionCode = dependencies[i].versionCode;
}
dep.head = retValue;
}
}
return dep;
}
RetHapModuleInfo ConvertHapModuleInfo(AppExecFwk::HapModuleInfo hapModuleInfo)
{
RetHapModuleInfo hapInfo;
hapInfo.name = MallocCString(hapModuleInfo.name);
hapInfo.icon = MallocCString(hapModuleInfo.iconPath);
hapInfo.iconId = hapModuleInfo.iconId;
hapInfo.label = MallocCString(hapModuleInfo.label);
hapInfo.labelId = hapModuleInfo.labelId;
hapInfo.description = MallocCString(hapModuleInfo.description);
hapInfo.descriptionId = hapModuleInfo.descriptionId;
hapInfo.mainElementName = MallocCString(hapModuleInfo.mainElementName);
hapInfo.abilitiesInfo = ConvertArrAbilityInfo(hapModuleInfo.abilityInfos);
hapInfo.extensionAbilitiesInfo = ConvertArrExtensionAbilityInfo(hapModuleInfo.extensionInfos);
hapInfo.metadata = ConvertArrMetadata(hapModuleInfo.metadata);
hapInfo.deviceTypes = g_convertArrString(hapModuleInfo.deviceTypes);
hapInfo.installationFree = hapModuleInfo.installationFree;
hapInfo.hashValue = MallocCString(hapModuleInfo.hashValue);
hapInfo.moduleType = static_cast<int32_t>(hapModuleInfo.moduleType);
hapInfo.preloads = ConvertPreloadItem(hapModuleInfo.preloads);
hapInfo.dependencies = ConvertDependency(hapModuleInfo.dependencies);
if (!hapModuleInfo.fileContextMenu.empty()) {
hapInfo.fileContextMenuConfig = MallocCString(hapModuleInfo.fileContextMenu);
}
return hapInfo;
}
CArrHapInfo ConvertArrHapInfo(std::vector<AppExecFwk::HapModuleInfo> hapModuleInfos)
{
CArrHapInfo hapInfos;
hapInfos.size = static_cast<int64_t>(hapModuleInfos.size());
RetHapModuleInfo *retValue = (RetHapModuleInfo *)malloc(sizeof(RetHapModuleInfo) * hapInfos.size);
if (retValue == nullptr) {
hapInfos.head = nullptr;
return hapInfos;
}
for (int32_t i = 0; i < hapInfos.size; i++) {
retValue[i] = ConvertHapModuleInfo(hapModuleInfos[i]);
}
hapInfos.head = retValue;
return hapInfos;
}
CArrReqPerDetail ConvertArrReqPerDetail(std::vector<AppExecFwk::RequestPermission> reqPermissionDetails)
{
CArrReqPerDetail perDetail;
perDetail.size = static_cast<int64_t>(reqPermissionDetails.size());
if (perDetail.size > 0) {
RetReqPermissionDetail *retValue = (RetReqPermissionDetail *)
malloc(sizeof(RetReqPermissionDetail) * perDetail.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < perDetail.size; i++) {
retValue[i] = ConvertRequestPermission(reqPermissionDetails[i]);
}
perDetail.head = retValue;
}
}
return perDetail;
}
RetBundleInfo ConvertBundleInfo(AppExecFwk::BundleInfo cBundleInfo, int32_t flags)
{
RetBundleInfo bundleInfo;
bundleInfo.name = MallocCString(cBundleInfo.name);
bundleInfo.vendor = MallocCString(cBundleInfo.vendor);
bundleInfo.versionCode = cBundleInfo.versionCode;
bundleInfo.versionName = MallocCString(cBundleInfo.versionName);
bundleInfo.minCompatibleVersionCode = cBundleInfo.minCompatibleVersionCode;
bundleInfo.targetVersion = cBundleInfo.targetVersion;
if ((static_cast<uint32_t>(flags) &
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION))
== static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) {
bundleInfo.appInfo = ConvertApplicationInfo(cBundleInfo.applicationInfo);
}
bundleInfo.hapInfo = ConvertArrHapInfo(cBundleInfo.hapModuleInfos);
bundleInfo.perDetail = ConvertArrReqPerDetail(cBundleInfo.reqPermissionDetails);
bundleInfo.state.size = static_cast<int64_t>(cBundleInfo.reqPermissionStates.size());
if (bundleInfo.state.size > 0) {
int32_t *retValue = (int32_t *)malloc(sizeof(int32_t) * bundleInfo.state.size);
if (retValue != nullptr) {
for (int32_t i = 0; i < bundleInfo.state.size; i++) {
retValue[i] = static_cast<int32_t>(cBundleInfo.reqPermissionStates[i]);
}
bundleInfo.state.head = retValue;
}
}
if ((static_cast<uint32_t>(flags) &
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO))
== static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) {
bundleInfo.signInfo = ConvertSignatureInfo(cBundleInfo.signatureInfo);
}
bundleInfo.installTime = cBundleInfo.installTime;
bundleInfo.updateTime = cBundleInfo.updateTime;
return bundleInfo;
}
CRecoverableApplicationInfo CovertCRecoverableApplicationInfo(AppExecFwk::RecoverableApplicationInfo info)
{
CRecoverableApplicationInfo cinfo;
cinfo.bundleName = MallocCString(info.bundleName);
cinfo.moduleName = MallocCString(info.moduleName);
cinfo.labelId = info.labelId;
cinfo.iconId = info.iconId;
return cinfo;
}
CArrRecoverableApplicationInfo CovertCArrRecoverableApplicationInfo(
std::vector<AppExecFwk::RecoverableApplicationInfo> info)
{
CArrRecoverableApplicationInfo arr;
arr.size = static_cast<int64_t>(info.size());
for (int32_t i = 0; i< arr.size; i++) {
arr.head[i] = CovertCRecoverableApplicationInfo(info[i]);
}
return arr;
}
} // Convert
} // BundleManager
} // CJSystemapi
} // OHOS

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_BUNDLE_MANAGER_CONVERT_H
#define OHOS_BUNDLE_MANAGER_CONVERT_H
#include <cstdint>
#include <string>
#include "bundle_manager_utils.h"
#include "bundle_info.h"
#include "recoverable_application_info.h"
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
namespace Convert {
RetBundleInfo ConvertBundleInfo(AppExecFwk::BundleInfo, int32_t);
} // Convert
} // BundleManager
} // CJSys
} // OHOS
#endif

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securec.h"
#include "bundle_manager_log.h"
#include "cj_common_ffi.h"
#include "bundle_manager_utils.h"
#include "bundle_manager.h"
#include "bundle_info.h"
#include "ipc_skeleton.h"
#include "bundle_manager_convert.h"
using namespace OHOS::CJSystemapi::BundleManager::Convert;
using namespace OHOS::CJSystemapi::BundleManager;
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
std::vector<std::string> g_charPtrToVector(char** charPtr, int32_t size)
{
std::vector<std::string> result;
for (int32_t i = 0; i < size; i++) {
result.push_back(std::string(charPtr[i]));
}
return result;
}
CArrString g_vectorToCArrString(std::vector<std::string> &vec)
{
char** result = new char* [vec.size()];
for (size_t i = 0; i < vec.size(); i++) {
result[i] = new char[vec[i].length() + 1];
auto res = strcpy_s(result[i], vec[i].length() + 1, vec[i].c_str());
if (res != EOK) {
LOGE("failed to strcpy_s.")
}
}
return {result, vec.size()};
}
extern "C" {
RetBundleInfo FfiOHOSGetBundleInfoForSelf(int32_t bundleFlags)
{
LOGI("BundleManager::FfiOHOSGetBundleInfoForSelf");
AppExecFwk::BundleInfo bundleInfo = BundleManagerImpl::GetBundleInfoForSelf(bundleFlags);
RetBundleInfo cjInfo = ConvertBundleInfo(bundleInfo, bundleFlags);
LOGI("BundleManager::FfiOHOSGetBundleInfoForSelf success");
return cjInfo;
}
int32_t FfiOHOSVerifyAbc(CArrString cAbcPaths, bool deleteOriginalFiles)
{
LOGI("BundleManager::FfiOHOSVerifyAbc");
std::vector<std::string> abcPaths = g_charPtrToVector(cAbcPaths.head, cAbcPaths.size);
auto code = BundleManagerImpl::VerifyAbc(abcPaths, deleteOriginalFiles);
if (code != 0) {
LOGI("FfiOHOSVerifyAbc failed, code is %{public}d", code);
return code;
}
LOGI("BundleManager::FfiOHOSVerifyAbc success");
return code;
}
RetCArrString FfiGetProfileByExtensionAbility(char* moduleName, char* extensionAbilityName, char* metadataName)
{
LOGI("BundleManager::FfiGetProfileByExtensionAbility");
RetCArrString res = { .code = -1, .value = {}};
auto [status, extensionAbilityInfo] = BundleManagerImpl::GetProfileByExtensionAbility(
std::string(moduleName), std::string(extensionAbilityName), metadataName);
if (status != 0) {
LOGI("FfiGetProfileByExtensionAbility failed, code is %{public}d", status);
return {status, {}};
}
res.code = SUCCESS_CODE;
res.value = g_vectorToCArrString(extensionAbilityInfo);
LOGI("BundleManager::FfiGetProfileByExtensionAbility success");
return res;
}
RetCArrString FfiGetProfileByAbility(char* moduleName, char* extensionAbilityName, char* metadataName)
{
LOGI("BundleManager::FfiGetProfileByAbility");
RetCArrString res = { .code = -1, .value = {}};
auto [status, extensionAbilityInfo] = BundleManagerImpl::GetProfileByAbility(
std::string(moduleName), std::string(extensionAbilityName), metadataName);
if (status != 0) {
LOGI("FfiGetProfileByAbility failed, code is %{public}d", status);
return {status, {}};
}
res.code = SUCCESS_CODE;
res.value = g_vectorToCArrString(extensionAbilityInfo);
LOGI("BundleManager::FfiGetProfileByAbility success");
return res;
}
}
} // BundleManager
} // CJSystemapi
} // OHOS

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_BUNDLE_MANAGER_FFI_H
#define OHOS_BUNDLE_MANAGER_FFI_H
#include "native/ffi_remote_data.h"
#include "cj_common_ffi.h"
#include "bundle_manager_utils.h"
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
extern "C" {
FFI_EXPORT RetBundleInfo FfiOHOSGetBundleInfoForSelf(int32_t bundleFlags);
FFI_EXPORT int32_t FfiOHOSVerifyAbc(std::vector<std::string> abcPaths, bool deleteOriginalFiles);
FFI_EXPORT RetCArrString FfiGetProfileByExtensionAbility(
char* moduleName, char* extensionAbilityName, char* metadataName);
FFI_EXPORT RetCArrString FfiGetProfileByAbility(char* moduleName, char* extensionAbilityName, char* metadataName);
}
} // BundleManager
} // CJSystemapi
} // OHOS
#endif

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_BUNDLE_MANAGER_LOG_H
#define OHOS_BUNDLE_MANAGER_LOG_H
#include "hilog/log.h"
#ifdef LOG_DOMAIN
#undef LOG_DOMAIN
#endif
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_DOMAIN 0xD001100
#define LOG_TAG "BundleManager"
#define LOGI(...) \
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_INFO)) { \
HILOG_INFO(LOG_CORE, ##__VA_ARGS__); \
}
#define LOGE(...) \
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_ERROR)) { \
HILOG_ERROR(LOG_CORE, __VA_ARGS__); \
}
#endif

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cj_common_ffi.h"
extern "C" {
FFI_EXPORT int32_t FfiOHOSGetBundleInfoForSelf = 0;
FFI_EXPORT int32_t FfiOHOSVerifyAbc = 0;
FFI_EXPORT int32_t FfiGetProfileByExtensionAbility = 0;
FFI_EXPORT int32_t FfiGetProfileByAbility = 0;
}

View File

@ -0,0 +1,290 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef BUNDLE_MANAGER_UTILS_H
#define BUNDLE_MANAGER_UTILS_H
#include <cstdint>
namespace OHOS {
namespace CJSystemapi {
namespace BundleManager {
struct RetMetadata {
char* name;
char* value;
char* resource;
};
struct CArrMetadata {
RetMetadata* head;
int64_t size;
};
struct ModuleMetadata {
char* moduleName;
CArrMetadata metadata;
};
struct CArrMoMeta {
ModuleMetadata* head;
int64_t size;
};
struct CResource {
char* bundleName;
char* moduleName;
int32_t id;
};
struct CArrString {
char** head;
int64_t size;
};
struct RetApplicationInfo {
char* name;
char* description;
int64_t descriptionId;
bool enabled;
char* label;
int64_t labelId;
char* icon;
int64_t iconId;
char* process;
CArrString permissions;
char* codePath;
CArrMoMeta metadataArray;
bool removable;
int64_t accessTokenId;
int64_t uid;
CResource iconResource;
CResource labelResource;
CResource descriptionResource;
char* appDistributionType;
char* appProvisionType;
bool systemApp;
int32_t bundleType;
bool debug;
bool dataUnclearable;
};
struct CArrInt32 {
int32_t* head;
int64_t size;
};
struct RetWindowSize {
double maxWindowRatio;
double minWindowRatio;
uint32_t maxWindowWidth;
uint32_t minWindowWidth;
uint32_t maxWindowHeight;
uint32_t minWindowHeight;
};
struct RetAbilityInfo {
char* bundleName;
char* moduleName;
char* name;
char* label;
int64_t labelId;
char* description;
int64_t descriptionId;
char* icon;
int64_t iconId;
char* process;
bool exported;
int32_t orientation;
int32_t launchType;
CArrString permissions;
CArrString deviceTypes;
RetApplicationInfo applicationInfo;
CArrMetadata metadata;
bool enabled;
CArrInt32 supportWindowModes;
RetWindowSize windowSize;
};
struct CArrRetAbilityInfo {
RetAbilityInfo* head;
int64_t size;
};
struct RetExtensionAbilityInfo {
char* bundleName;
char* moduleName;
char* name;
int64_t labelId;
int64_t descriptionId;
int64_t iconId;
bool exported;
int32_t extensionAbilityType;
CArrString permissions;
RetApplicationInfo applicationInfo;
CArrMetadata metadata;
bool enabled;
char* readPermission;
char* writePermission;
char* extensionAbilityTypeName;
};
struct CArrRetExtensionAbilityInfo {
RetExtensionAbilityInfo* head;
int64_t size;
};
struct RetPreloadItem {
char* moduleName;
};
struct CArrRetPreloadItem {
RetPreloadItem* head;
int64_t size;
};
struct RetDependency {
char* bundleName;
char* moduleName;
uint32_t versionCode;
};
struct CArrRetDependency {
RetDependency* head;
int64_t size;
};
struct RetHapModuleInfo {
char* name;
char* icon;
int32_t iconId;
char* label;
int32_t labelId;
char* description;
int32_t descriptionId;
char* mainElementName;
CArrRetAbilityInfo abilitiesInfo;
CArrRetExtensionAbilityInfo extensionAbilitiesInfo;
CArrMetadata metadata;
CArrString deviceTypes;
bool installationFree;
char* hashValue;
int32_t moduleType;
CArrRetPreloadItem preloads;
CArrRetDependency dependencies;
char* fileContextMenuConfig;
};
struct CArrHapInfo {
RetHapModuleInfo* head;
int64_t size;
};
struct RetUsedScene {
CArrString abilities;
char* when;
};
struct RetReqPermissionDetail {
char* name;
char* moduleName;
char* reason;
int64_t reasonId;
RetUsedScene usedScence;
};
struct CArrReqPerDetail {
RetReqPermissionDetail* head;
int64_t size;
};
struct RetSignatureInfo {
char* appId;
char* fingerprint;
char* appIdentifier;
};
struct RetCArrString {
int32_t code;
CArrString value;
};
struct CRecoverableApplicationInfo {
char* bundleName;
char* moduleName;
int32_t labelId;
int32_t iconId;
};
struct CArrRecoverableApplicationInfo {
CRecoverableApplicationInfo* head;
int64_t size;
};
struct RetRecoverableApplicationInfo {
int32_t code;
CArrRecoverableApplicationInfo data;
};
struct RetBundleInfo {
char* name;
char* vendor;
int64_t versionCode;
char* versionName;
int64_t minCompatibleVersionCode;
int64_t targetVersion;
RetApplicationInfo appInfo;
CArrHapInfo hapInfo;
CArrReqPerDetail perDetail;
CArrInt32 state;
RetSignatureInfo signInfo;
int64_t installTime;
int64_t updateTime;
};
enum BundleFlag {
// get bundle info except abilityInfos
GET_BUNDLE_DEFAULT = 0x00000000,
// get bundle info include abilityInfos
GET_BUNDLE_WITH_ABILITIES = 0x00000001,
// get bundle info include request permissions
GET_BUNDLE_WITH_REQUESTED_PERMISSION = 0x00000010,
// get bundle info include extension info
GET_BUNDLE_WITH_EXTENSION_INFO = 0x00000020,
// get bundle info include hash value
GET_BUNDLE_WITH_HASH_VALUE = 0x00000030,
// get bundle info inlcude menu, only for dump usage
GET_BUNDLE_WITH_MENU = 0x00000040,
};
enum class GetBundleInfoFlag {
GET_BUNDLE_INFO_DEFAULT = 0x00000000,
GET_BUNDLE_INFO_WITH_APPLICATION = 0x00000001,
GET_BUNDLE_INFO_WITH_HAP_MODULE = 0x00000002,
GET_BUNDLE_INFO_WITH_ABILITY = 0x00000004,
GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY = 0x00000008,
GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION = 0x00000010,
GET_BUNDLE_INFO_WITH_METADATA = 0x00000020,
GET_BUNDLE_INFO_WITH_DISABLE = 0x00000040,
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO = 0x00000080,
GET_BUNDLE_INFO_WITH_MENU = 0x00000100,
};
} // BundleManager
} // CJSystemapi
} // OHOS
#endif