From 816e8a126cea74d33f75d3f69ddebeee329969e6 Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Thu, 4 Sep 2025 22:59:17 +0800 Subject: [PATCH] getAbilityResourceInfo_part1 Signed-off-by: lanhaoyu --- .../include/appexecfwk_errors.h | 1 + .../launcher_ability_resource_info.h | 3 +- .../launcher_ability_resource_info.cpp | 4 +- ...bundle_framework_core_ipc_interface_code.h | 1 + .../include/bundlemgr/bundle_mgr_host.h | 9 + .../include/bundlemgr/bundle_mgr_interface.h | 6 + .../src/bundlemgr/bundle_mgr_host.cpp | 22 ++ interfaces/kits/native/bundle/BUILD.gn | 1 + .../bundle/include/ability_resource_info.h | 195 +++++++++++ .../bundle/include/bundle_manager_common.h | 72 ++++ .../bundle/include/bundle_mgr_proxy_native.h | 15 +- .../bundle/include/native_interface_bundle.h | 18 +- .../kits/native/bundle/libbundle.ndk.json | 40 +++ .../bundle/src/ability_resource_info.cpp | 330 ++++++++++++++++++ .../bundle/src/bundle_mgr_proxy_native.cpp | 144 +++++++- .../bundle/src/native_interface_bundle.cpp | 57 +++ services/bundlemgr/include/bundle_data_mgr.h | 2 + .../bundlemgr/include/bundle_mgr_host_impl.h | 9 + services/bundlemgr/include/bundle_util.h | 3 +- services/bundlemgr/src/bundle_data_mgr.cpp | 35 ++ .../bundlemgr/src/bundle_mgr_host_impl.cpp | 103 ++++++ services/bundlemgr/src/bundle_util.cpp | 24 ++ .../bms_bundle_manager_test_three.cpp | 106 ++++++ .../bms_bundle_permission_false_test.cpp | 29 ++ .../bms_bundle_mgr_host_test.cpp | 15 + 25 files changed, 1237 insertions(+), 7 deletions(-) create mode 100644 interfaces/kits/native/bundle/include/ability_resource_info.h create mode 100644 interfaces/kits/native/bundle/include/bundle_manager_common.h create mode 100644 interfaces/kits/native/bundle/src/ability_resource_info.cpp diff --git a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h index e8c520bdc2..3c7d645126 100644 --- a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h +++ b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h @@ -361,6 +361,7 @@ enum { ERR_BUNDLE_MANAGER_GET_ACCOUNT_INFO_FAILED = 8521258, ERR_BUNDLE_MANAGER_BUNDLE_DISABLED = 8521259, ERR_BUNDLE_MANAGER_ACCESS_TOKENID_NOT_EXIST = 8521260, + ERR_BUNDLE_MANAGER_ABILITY_INFO_NOT_FOUND = 8521261, // zlib errcode ERR_ZLIB_SRC_FILE_DISABLED = 8521240, ERR_ZLIB_DEST_FILE_DISABLED = 8521241, diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_resource/launcher_ability_resource_info.h b/interfaces/inner_api/appexecfwk_base/include/bundle_resource/launcher_ability_resource_info.h index 075c5ffa37..a51ca3575c 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_resource/launcher_ability_resource_info.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_resource/launcher_ability_resource_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -25,6 +25,7 @@ namespace AppExecFwk { struct LauncherAbilityResourceInfo : Parcelable { int32_t appIndex = 0; int32_t extensionAbilityType = -1; + bool isDefaultApp = false; std::string bundleName; std::string moduleName; std::string abilityName; diff --git a/interfaces/inner_api/appexecfwk_base/src/bundle_resource/launcher_ability_resource_info.cpp b/interfaces/inner_api/appexecfwk_base/src/bundle_resource/launcher_ability_resource_info.cpp index f95ffe8f6a..d34ca151c4 100644 --- a/interfaces/inner_api/appexecfwk_base/src/bundle_resource/launcher_ability_resource_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/bundle_resource/launcher_ability_resource_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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,7 @@ bool LauncherAbilityResourceInfo::ReadFromParcel(Parcel &parcel) } READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDefaultApp); return true; } @@ -77,6 +78,7 @@ bool LauncherAbilityResourceInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8Unaligned, parcel, data); } WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDefaultApp); return true; } diff --git a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h index c75fc0c7ee..24288a3345 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h @@ -227,6 +227,7 @@ enum class BundleMgrInterfaceCode : uint32_t { CLEAN_BUNDLE_CACHE_FILES_FOR_SELF = 201, IS_DEBUGGABLE_APPLICATION = 202, GET_ALL_BUNDLE_NAMES = 203, + GET_ABILITY_RESOURCE_INFO = 204, }; /* SAID: 401-85 Interface No.85 subservice also provides the following interfaces */ diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h index 34f2d5a3a0..d63e75a68e 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h @@ -940,6 +940,15 @@ private: ErrCode HandleGetAllShortcutInfoForSelf(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetPluginInfo(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetTestRunner(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Obtain a list of applications that support opening files in a certain format. + * @param fileType Indicates the file type. + * @param abilityResourceInfo Indicates the ability resource array. + * @param size Indicates the ability resource array size. + * @return Returns ERR_OK if called successfully; returns error code otherwise. + */ + ErrCode HandleGetAbilityResourceInfo(MessageParcel &data, MessageParcel &reply); private: /** * @brief Write a parcelabe vector objects to the proxy node. diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index fe27220db9..b2968a5969 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -1884,6 +1884,12 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } + + virtual ErrCode GetAbilityResourceInfo(const std::string &fileType, + std::vector &launcherAbilityResourceInfos) + { + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } }; #define WRITE_PARCEL(func) \ diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index e263f4e6e0..302dba69b6 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -719,6 +719,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(BundleMgrInterfaceCode::GET_ALL_BUNDLE_NAMES): errCode = HandleGetAllBundleNames(data, reply); break; + case static_cast(BundleMgrInterfaceCode::GET_ABILITY_RESOURCE_INFO): + errCode = HandleGetAbilityResourceInfo(data, reply); + break; default : APP_LOGW("bundleMgr host receives unknown code %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -5009,5 +5012,24 @@ ErrCode BundleMgrHost::HandleGetAllBundleNames(MessageParcel &data, MessageParce } return ERR_OK; } + +ErrCode BundleMgrHost::HandleGetAbilityResourceInfo(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + std::string fileType = data.ReadString(); + std::vector launcherAbilityResourceInfos; + ErrCode ret = GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); + if (!reply.WriteInt32(ret)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (ret == ERR_OK) { + if (!WriteVectorToParcelIntelligent(launcherAbilityResourceInfos, reply)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/native/bundle/BUILD.gn b/interfaces/kits/native/bundle/BUILD.gn index a0e85f64e9..1043a4700d 100644 --- a/interfaces/kits/native/bundle/BUILD.gn +++ b/interfaces/kits/native/bundle/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("bundle_ndk") { "LOG_DOMAIN = 0xD001120", ] sources = [ + "src/ability_resource_info.cpp", "src/bundle_mgr_proxy_native.cpp", "src/native_interface_bundle.cpp", ] diff --git a/interfaces/kits/native/bundle/include/ability_resource_info.h b/interfaces/kits/native/bundle/include/ability_resource_info.h new file mode 100644 index 0000000000..122f8f5b7b --- /dev/null +++ b/interfaces/kits/native/bundle/include/ability_resource_info.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * @addtogroup Native_Bundle + * @{ + * + * @brief Describe the functions of AbilityResourceInfo. + * + * @since 21 + */ + +/** + * @file ability_resource_info.h + * + * @brief Defines the OH_NativeBundle_AbilityResourceInfo APIs. + * + * @library libbundle_ndk.z.so + * @kit AbilityKit + * @syscap SystemCapability.BundleManager.BundleFramework.Core + * @since 21 + */ + +#ifndef ABILITY_RESOURCE_INFO_H +#define ABILITY_RESOURCE_INFO_H + +#include +#include +#include "bundle_manager_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Indicates ability resource info. + * + * @since 21 + */ +struct OH_NativeBundle_AbilityResourceInfo; +typedef struct OH_NativeBundle_AbilityResourceInfo OH_NativeBundle_AbilityResourceInfo; + +/** +* @brief Get the bundle name of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param bundleName The bundle name obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetBundleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** bundleName); + +/** +* @brief Get the module name of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param moduleName The module name obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetModuleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** moduleName); + +/** +* @brief Get the ability name of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param abilityName The ability name obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetAbilityName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** abilityName); + +/** +* @brief Get the icon of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param icon The icon obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetIcon( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** icon); + +/** +* @brief Get the label of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param label The label obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetLabel( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** label); + +/** +* @brief Get the appIndex of the abilityResourceInfo. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param appIndex The appIndex obtained from abilityResourceInfo. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetAppIndex( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, int* appIndex); + +/** +* @brief Check whether abilityResourceInfo is the default application. + * + * @param abilityResourceInfo The ability resource info that has been obtained. + * @param isDefault Check whether abilityResourceInfo is the default application. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_CheckDefaultApp( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, bool* isDefault); + +/** +* @brief Destroy the ability resource info. + * + * @param abilityResourceInfo The ability resource info to be deleted. + * @param count Indicates the ability resource array size. + * @return The error code. + * {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID} if the abilityResourceInfo is invalid. + * @since 21 + */ +BundleManager_ErrorCode OH_AbilityResourceInfo_Destroy( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, size_t count); + +/** +* @brief Get the size of ability resource info. + * + * @return The size of ability resource info. + * + * @since 21 + */ +int OH_NativeBundle_GetSize(); + +OH_NativeBundle_AbilityResourceInfo* OH_AbilityResourceInfo_Create(size_t elementSize); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_AppIndex( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, int appIndex); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_IsDefaultApp( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, bool isDefaultApp); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_BundleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* bundleName); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_ModuleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* moduleName); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_AbilityName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* abilityName); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_Label( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* label); + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_Icon( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* icon); +#ifdef __cplusplus +} // extern "C" +#endif + +/** @} */ +#endif // ABILITY_RESOURCE_INFO_H \ No newline at end of file diff --git a/interfaces/kits/native/bundle/include/bundle_manager_common.h b/interfaces/kits/native/bundle/include/bundle_manager_common.h new file mode 100644 index 0000000000..91f3124f4a --- /dev/null +++ b/interfaces/kits/native/bundle/include/bundle_manager_common.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * @addtogroup Native_Bundle + * @{ + * + * @brief Describes the Native Bundle. + * + * @since 21 + * @version 1.0 + */ + +/** + * @file bundle_manager_common.h + * + * @brief Declare the common types for the native BundleManager. + * + * @library libbundle_ndk.z.so + * @kit AbilityKit + * @syscap SystemCapability.BundleManager.BundleFramework.Core + * @since 21 + */ + +#ifndef BUNDLE_MANAGER_COMMON_H +#define BUNDLE_MANAGER_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the error codes. + * + * @since 21 + */ +typedef enum { + /** + * @error No error. + * @since 21 + */ + BUNDLE_MANAGER_ERROR_CODE_NO_ERROR = 0, + /** + * @error permission denied. + * @since 21 + */ + BUNDLE_MANAGER_ERROR_CODE_PERMISSION_DENIED = 201, + /** + * @error param invalid. + * @since 21 + */ + BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID = 401, +} BundleManager_ErrorCode; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif // BUNDLE_MANAGER_COMMON_H \ No newline at end of file diff --git a/interfaces/kits/native/bundle/include/bundle_mgr_proxy_native.h b/interfaces/kits/native/bundle/include/bundle_mgr_proxy_native.h index bd970468ef..166045d8d3 100644 --- a/interfaces/kits/native/bundle/include/bundle_mgr_proxy_native.h +++ b/interfaces/kits/native/bundle/include/bundle_mgr_proxy_native.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -20,6 +20,7 @@ #include "application_info.h" #include "bundle_info.h" +#include "launcher_ability_resource_info.h" #include "iremote_broker.h" #include "iremote_object.h" @@ -42,15 +43,25 @@ public: bool GetCompatibleDeviceTypeNative(std::string &deviceType); + ErrCode GetLauncherAbilityResourceInfoNative(std::string &fileType, + std::vector &launcherAbilityResourceInfoArr); + enum { GET_BUNDLE_INFO_FOR_SELF_NATIVE = 98, - GET_COMPATIBLED_DEVICE_TYPE_NATIVE = 166 + GET_COMPATIBLED_DEVICE_TYPE_NATIVE = 166, + GET_LAUNCHER_ABILITY_RESOURE_INFO_NATIVE = 204 }; private: sptr GetBmsProxy(); template bool GetParcelableInfo(uint32_t code, MessageParcel &data, T &parcelableInfo); bool SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply); + template + ErrCode GetVectorFromParcelIntelligentWithErrCode(uint32_t code, MessageParcel &data, + std::vector &parcelableInfos); + template + ErrCode InnerGetVectorFromParcelIntelligent(MessageParcel &reply, std::vector &parcelableInfos); + ErrCode GetParcelInfoFromAshMem(MessageParcel &reply, void *&data); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/native/bundle/include/native_interface_bundle.h b/interfaces/kits/native/bundle/include/native_interface_bundle.h index 65f9ccafc1..9a956a68c1 100644 --- a/interfaces/kits/native/bundle/include/native_interface_bundle.h +++ b/interfaces/kits/native/bundle/include/native_interface_bundle.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -39,6 +39,8 @@ #include #include +#include "ability_resource_info.h" + #ifdef __cplusplus extern "C" { #endif @@ -225,6 +227,20 @@ bool OH_NativeBundle_IsDebugMode(bool* isDebugMode); * @since 20 */ OH_NativeBundle_ModuleMetadata* OH_NativeBundle_GetModuleMetadata(size_t* size); + +/** + * @brief Obtain a list of applications that support opening files in a certain format. + * + * @permisssion {@code ohos.permission.GET_ABILITY_INFO}. + * @param fileType Indicates the file type. + * @param abilityResourceInfo Indicates the ability resource array. + * @param size Indicates the ability resource array size. + * @return Returns {@link BUNDLE_MANAGER_ERROR_CODE_NO_ERROR} if the call is successful. + * Returns {@link BUNDLE_MANAGER_ERROR_CODE_PERMISSION_DENIED} if the caller has no correct permission. + * @since 21 + */ +BundleManager_ErrorCode OH_NativeBundle_GetAbilityResourceInfo(char* fileType, + OH_NativeBundle_AbilityResourceInfo** abilityResourceInfo, size_t* size); #ifdef __cplusplus }; #endif diff --git a/interfaces/kits/native/bundle/libbundle.ndk.json b/interfaces/kits/native/bundle/libbundle.ndk.json index 7c05eef7bb..a21ec32445 100644 --- a/interfaces/kits/native/bundle/libbundle.ndk.json +++ b/interfaces/kits/native/bundle/libbundle.ndk.json @@ -26,5 +26,45 @@ { "first_introduced": "20", "name": "OH_NativeBundle_GetModuleMetadata" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetAbilityResourceInfo" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetBundleName" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetModuleName" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetAbilityName" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetIcon" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetLabel" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetAppIndex" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_CheckDefaultApp" + }, + { + "first_introduced": "21", + "name": "OH_AbilityResourceInfo_Destroy" + }, + { + "first_introduced": "21", + "name": "OH_NativeBundle_GetSize" } ] diff --git a/interfaces/kits/native/bundle/src/ability_resource_info.cpp b/interfaces/kits/native/bundle/src/ability_resource_info.cpp new file mode 100644 index 0000000000..021da7901c --- /dev/null +++ b/interfaces/kits/native/bundle/src/ability_resource_info.cpp @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2025 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 +#include +#include +#include + +#include "ability_resource_info.h" +#include "app_log_wrapper.h" +#include "securec.h" + +struct OH_NativeBundle_AbilityResourceInfo { + int appIndex; + bool isDefaultApp; + char *bundleName; + char *moduleName; + char *abilityName; + char *label; + char *icon; +}; + +// Helper function to release char* memory +static void ReleaseChar(char* &str) +{ + if (str != nullptr) { + free(str); + str = nullptr; + } +} + +bool CopyChar(char* &name, char* value) +{ + if (value == nullptr) { + APP_LOGE("value is null"); + } + size_t length = strlen(value); + if (length == 0) { + APP_LOGE("failed due to the length of value is empty or too long"); + return false; + } + name = static_cast(malloc(length + 1)); + if (name == nullptr) { + APP_LOGE("failed due to malloc error"); + return false; + } + if (strcpy_s(name, length + 1, value) != EOK) { + APP_LOGE("failed due to strcpy_s error"); + ReleaseChar(name); + return false; + } + return true; +} + +bool CopyConstChar(char* &name, const char* value) +{ + if (value == nullptr) { + APP_LOGE("value is null"); + } + size_t length = strlen(value); + if (length == 0) { + APP_LOGE("failed due to the length of value is empty or too long"); + return false; + } + name = static_cast(malloc(length + 1)); + if (name == nullptr) { + APP_LOGE("failed due to malloc error"); + return false; + } + if (strcpy_s(name, length + 1, value) != EOK) { + APP_LOGE("failed due to strcpy_s error"); + ReleaseChar(name); + return false; + } + return true; +} + +void ResetResourceInfo(OH_NativeBundle_AbilityResourceInfo* resourceInfo, size_t count) +{ + if (resourceInfo == nullptr || count == 0) { + return; + } + for (size_t i = 0; i < count; ++i) { + resourceInfo[i].appIndex = 0; + resourceInfo[i].isDefaultApp = false; + resourceInfo[i].bundleName = nullptr; + resourceInfo[i].moduleName = nullptr; + resourceInfo[i].abilityName = nullptr; + resourceInfo[i].label = nullptr; + resourceInfo[i].icon = nullptr; + } +} + +void ReleaseResourceInfo(OH_NativeBundle_AbilityResourceInfo* resourceInfo, size_t count) +{ + if (resourceInfo == nullptr) { + return; + } + for (size_t i = 0; i < count; ++i) { + ReleaseChar(resourceInfo[i].bundleName); + ReleaseChar(resourceInfo[i].moduleName); + ReleaseChar(resourceInfo[i].abilityName); + ReleaseChar(resourceInfo[i].label); + ReleaseChar(resourceInfo[i].icon); + } + free(resourceInfo); +} + +OH_NativeBundle_AbilityResourceInfo* OH_AbilityResourceInfo_Create(size_t elementSize) +{ + if (elementSize == 0) { + APP_LOGE("failed due to the length of value is 0"); + return nullptr; + } + + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo = static_cast( + malloc(elementSize * sizeof(OH_NativeBundle_AbilityResourceInfo))); + if (abilityResourceInfo == nullptr) { + APP_LOGE("failed to allocate memory for OH_AbilityResourceInfo_Create"); + return nullptr; + } + ResetResourceInfo(abilityResourceInfo, elementSize); + + return abilityResourceInfo; +} + +BundleManager_ErrorCode OH_AbilityResourceInfo_Destroy(OH_NativeBundle_AbilityResourceInfo* resourceInfo, size_t count) +{ + ReleaseResourceInfo(resourceInfo, count); + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_AppIndex( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, int appIndex) +{ + if (abilityResourceInfo == nullptr) { + APP_LOGE("null abilityResourceInfo"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + abilityResourceInfo->appIndex = appIndex; + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetAppIndex( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, int* appIndex) +{ + if (abilityResourceInfo == nullptr || appIndex == nullptr) { + APP_LOGE("abilityResourceInfo or appIndex is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + *appIndex = abilityResourceInfo->appIndex; + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_IsDefaultApp( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, bool isDefaultApp) +{ + if (abilityResourceInfo == nullptr) { + APP_LOGE("abilityResourceInfo is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + abilityResourceInfo->isDefaultApp = isDefaultApp; + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_CheckDefaultApp( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, bool* isDefault) +{ + if (abilityResourceInfo == nullptr || isDefault == nullptr) { + APP_LOGE("abilityResourceInfo or appIndex is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + *isDefault = abilityResourceInfo->isDefaultApp; + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +int OH_NativeBundle_GetSize() +{ + return sizeof(OH_NativeBundle_AbilityResourceInfo); +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_BundleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* bundleName) +{ + if (abilityResourceInfo == nullptr || bundleName == nullptr) { + APP_LOGE("abilityResourceInfo or bundleName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyConstChar(abilityResourceInfo->bundleName, bundleName)) { + APP_LOGE("copy bundleName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetBundleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** bundleName) +{ + if (abilityResourceInfo == nullptr || bundleName == nullptr) { + APP_LOGE("abilityResourceInfo or bundleName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyChar(*bundleName, abilityResourceInfo->bundleName)) { + APP_LOGE("copy bundleName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_ModuleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* moduleName) +{ + if (abilityResourceInfo == nullptr || moduleName == nullptr) { + APP_LOGE("abilityResourceInfo or moduleName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyConstChar(abilityResourceInfo->moduleName, moduleName)) { + APP_LOGE("copy moduleName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetModuleName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** moduleName) +{ + if (abilityResourceInfo == nullptr || moduleName == nullptr) { + APP_LOGE("abilityResourceInfo or moduleName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyChar(*moduleName, abilityResourceInfo->moduleName)) { + APP_LOGE("copy moduleName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_AbilityName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* abilityName) +{ + if (abilityResourceInfo == nullptr || abilityName == nullptr) { + APP_LOGE("abilityResourceInfo or abilityName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyConstChar(abilityResourceInfo->abilityName, abilityName)) { + APP_LOGE("copy abilityName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetAbilityName( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** abilityName) +{ + if (abilityResourceInfo == nullptr || abilityName == nullptr) { + APP_LOGE("abilityResourceInfo or abilityName is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyChar(*abilityName, abilityResourceInfo->abilityName)) { + APP_LOGE("copy abilityName failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_Label( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* label) +{ + if (abilityResourceInfo == nullptr || label == nullptr) { + APP_LOGE("abilityResourceInfo or label is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyConstChar(abilityResourceInfo->label, label)) { + APP_LOGE("copy label failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetLabel(OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** label) +{ + if (abilityResourceInfo == nullptr || label == nullptr) { + APP_LOGE("abilityResourceInfo or label is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyChar(*label, abilityResourceInfo->label)) { + APP_LOGE("copy label failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_SetAbilityResourceInfo_Icon( + OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, const char* icon) +{ + if (abilityResourceInfo == nullptr || icon == nullptr) { + APP_LOGE("abilityResourceInfo or icon is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyConstChar(abilityResourceInfo->icon, icon)) { + APP_LOGE("copy icon failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} + +BundleManager_ErrorCode OH_NativeBundle_GetIcon(OH_NativeBundle_AbilityResourceInfo* abilityResourceInfo, char** icon) +{ + if (abilityResourceInfo == nullptr || icon == nullptr) { + APP_LOGE("abilityResourceInfo or icon is nullptr"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + if (!CopyChar(*icon, abilityResourceInfo->icon)) { + APP_LOGE("copy icon failed"); + return BUNDLE_MANAGER_ERROR_CODE_PARAM_INVALID; + } + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; +} \ No newline at end of file diff --git a/interfaces/kits/native/bundle/src/bundle_mgr_proxy_native.cpp b/interfaces/kits/native/bundle/src/bundle_mgr_proxy_native.cpp index b508402efb..cd32dcae67 100644 --- a/interfaces/kits/native/bundle/src/bundle_mgr_proxy_native.cpp +++ b/interfaces/kits/native/bundle/src/bundle_mgr_proxy_native.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -20,6 +20,8 @@ #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "parcel_macro.h" +#include "securec.h" #include "string_ex.h" #include "system_ability_definition.h" @@ -27,6 +29,30 @@ namespace OHOS { namespace AppExecFwk { namespace { const std::u16string BMS_PROXY_INTERFACE_TOKEN = u"ohos.appexecfwk.BundleMgr"; + constexpr size_t MAX_PARCEL_CAPACITY = 1024 * 1024 * 1024; // allow max 1GB resource size + constexpr size_t MAX_IPC_REWDATA_SIZE = 120 * 1024 * 1024; // max ipc size 120MB +bool GetData(void *&buffer, size_t size, const void *data) +{ + if (data == nullptr) { + APP_LOGE("GetData failed due to null data"); + return false; + } + if (size == 0 || size > MAX_PARCEL_CAPACITY) { + APP_LOGE("GetData failed due to zero size"); + return false; + } + buffer = malloc(size); + if (buffer == nullptr) { + APP_LOGE("GetData failed due to malloc buffer failed"); + return false; + } + if (memcpy_s(buffer, size, data, size) != EOK) { + free(buffer); + APP_LOGE("GetData failed due to memcpy_s failed"); + return false; + } + return true; +} } sptr BundleMgrProxyNative::GetBmsProxy() @@ -81,6 +107,24 @@ bool BundleMgrProxyNative::GetCompatibleDeviceTypeNative(std::string &deviceType return true; } +ErrCode BundleMgrProxyNative::GetLauncherAbilityResourceInfoNative( + std::string &fileType, std::vector &launcherAbilityResourceInfoArr) +{ + LOG_I(BMS_TAG_QUERY, "begin to get Launcher Ability Resource Info"); + MessageParcel data; + if (!data.WriteInterfaceToken(BMS_PROXY_INTERFACE_TOKEN)) { + LOG_E(BMS_TAG_QUERY, "fail to GetLauncherAbilityResourceInfoNative due to write InterfaceToken fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteString(fileType)) { + LOG_E(BMS_TAG_QUERY, "fail to GetLauncherAbilityResourceInfoNative due to write flag fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + ErrCode ret = GetVectorFromParcelIntelligentWithErrCode( + GET_LAUNCHER_ABILITY_RESOURE_INFO_NATIVE, data, launcherAbilityResourceInfoArr); + return ret; +} + bool BundleMgrProxyNative::SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply) { MessageOption option(MessageOption::TF_SYNC); @@ -120,5 +164,103 @@ bool BundleMgrProxyNative::GetParcelableInfo(uint32_t code, MessageParcel &data, APP_LOGD("get parcelable info success"); return true; } + +template +ErrCode BundleMgrProxyNative::GetVectorFromParcelIntelligentWithErrCode( + uint32_t code, MessageParcel &data, std::vector &parcelableInfos) +{ + MessageParcel reply; + if (!SendTransactCmd(code, data, reply)) { + APP_LOGE("SendTransactCmd failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + ErrCode res = reply.ReadInt32(); + if (res != ERR_OK) { + return res; + } + + return InnerGetVectorFromParcelIntelligent(reply, parcelableInfos); +} + +template +ErrCode BundleMgrProxyNative::InnerGetVectorFromParcelIntelligent( + MessageParcel &reply, std::vector &parcelableInfos) +{ + size_t dataSize = static_cast(reply.ReadInt32()); + if (dataSize == 0) { + APP_LOGW("Parcel no data"); + return ERR_OK; + } + + void *buffer = nullptr; + if (dataSize > MAX_IPC_REWDATA_SIZE) { + APP_LOGI("dataSize is too large, use ashmem"); + if (GetParcelInfoFromAshMem(reply, buffer) != ERR_OK) { + APP_LOGE("read data from ashmem fail, length %{public}zu", dataSize); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } else { + if (!GetData(buffer, dataSize, reply.ReadRawData(dataSize))) { + APP_LOGE("Fail read raw data length %{public}zu", dataSize); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + + MessageParcel tempParcel; + if (!tempParcel.ParseFrom(reinterpret_cast(buffer), dataSize)) { + APP_LOGE("Fail to ParseFrom"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t infoSize = tempParcel.ReadInt32(); + CONTAINER_SECURITY_VERIFY(tempParcel, infoSize, &parcelableInfos); + for (int32_t i = 0; i < infoSize; i++) { + std::unique_ptr info(tempParcel.ReadParcelable()); + if (info == nullptr) { + APP_LOGE("Read Parcelable infos failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + parcelableInfos.emplace_back(*info); + } + + return ERR_OK; +} + +ErrCode BundleMgrProxyNative::GetParcelInfoFromAshMem(MessageParcel &reply, void *&data) +{ + sptr ashMem = reply.ReadAshmem(); + if (ashMem == nullptr) { + APP_LOGE("Ashmem is nullptr"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!ashMem->MapReadOnlyAshmem()) { + APP_LOGE("MapReadOnlyAshmem failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + int32_t ashMemSize = ashMem->GetAshmemSize(); + int32_t offset = 0; + const void* ashDataPtr = ashMem->ReadFromAshmem(ashMemSize, offset); + if (ashDataPtr == nullptr) { + APP_LOGE("ashDataPtr is nullptr"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if ((ashMemSize == 0) || ashMemSize > static_cast(MAX_PARCEL_CAPACITY)) { + APP_LOGE("failed due to wrong size"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + data = malloc(ashMemSize); + if (data == nullptr) { + APP_LOGE("failed due to malloc data failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (memcpy_s(data, ashMemSize, ashDataPtr, ashMemSize) != EOK) { + free(data); + APP_LOGE("failed due to memcpy_s failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/native/bundle/src/native_interface_bundle.cpp b/interfaces/kits/native/bundle/src/native_interface_bundle.cpp index b25d6e20a6..8c5434ffdc 100644 --- a/interfaces/kits/native/bundle/src/native_interface_bundle.cpp +++ b/interfaces/kits/native/bundle/src/native_interface_bundle.cpp @@ -31,6 +31,7 @@ namespace { const size_t CHAR_MIN_LENGTH = 1; const size_t CHAR_MAX_LENGTH = 10240; const size_t MAX_ALLOWED_SIZE = 1024 * 1024; +const size_t ARRAY_MAX_LENGTH = 1024; } // Helper function to release char* memory @@ -540,4 +541,60 @@ OH_NativeBundle_ModuleMetadata* OH_NativeBundle_GetModuleMetadata(size_t* size) *size = bundleInfo.applicationInfo.metadata.size(); APP_LOGD("OH_NativeBundle_GetModuleMetadata success"); return moduleMetadata; +} + +BundleManager_ErrorCode OH_NativeBundle_GetAbilityResourceInfo( + char* fileType, OH_NativeBundle_AbilityResourceInfo** abilityResourceInfo, size_t* size) +{ + if (fileType == nullptr || size == nullptr || abilityResourceInfo == nullptr) { + APP_LOGE("invalid param"); + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; + } + *size = 0; + std::string fileTypeStr(fileType); + OHOS::AppExecFwk::BundleMgrProxyNative bundleMgrProxyNative; + std::vector launcherAbilityResourceInfoArr; + + if (bundleMgrProxyNative.GetLauncherAbilityResourceInfoNative(fileTypeStr, launcherAbilityResourceInfoArr) == + BUNDLE_MANAGER_ERROR_CODE_PERMISSION_DENIED) { + APP_LOGE("failed to get launcher Ability Resource Info Arr because of permission denied"); + return BUNDLE_MANAGER_ERROR_CODE_PERMISSION_DENIED; + } + + size_t abilityResourceInfoSize = launcherAbilityResourceInfoArr.size(); + if (abilityResourceInfoSize == 0 || abilityResourceInfoSize > ARRAY_MAX_LENGTH) { + APP_LOGW("failed due to the length of value is empty or too long"); + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; + } + + *abilityResourceInfo = OH_AbilityResourceInfo_Create(abilityResourceInfoSize); + if (*abilityResourceInfo == nullptr) { + APP_LOGE("failed to allocate memory for OH_NativeBundle_ModuleMetadata"); + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; + } + + size_t i = 0; + for (auto &info : launcherAbilityResourceInfoArr) { + auto p = + (OH_NativeBundle_AbilityResourceInfo *)((char *)(*abilityResourceInfo) + OH_NativeBundle_GetSize() * i); + if (OH_NativeBundle_SetAbilityResourceInfo_AppIndex(p, info.appIndex) != BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_IsDefaultApp(p, info.isDefaultApp) != + BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_BundleName(p, info.bundleName.c_str()) != + BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_ModuleName(p, info.moduleName.c_str()) != + BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_AbilityName(p, info.abilityName.c_str()) != + BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_Label(p, info.label.c_str()) != BUNDLE_MANAGER_ERROR_CODE_NO_ERROR || + OH_NativeBundle_SetAbilityResourceInfo_Icon(p, info.icon.c_str()) != BUNDLE_MANAGER_ERROR_CODE_NO_ERROR) { + APP_LOGE("failed to set ability resource info"); + OH_AbilityResourceInfo_Destroy(*abilityResourceInfo, i + 1); + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; + } + ++i; + } + + *size = abilityResourceInfoSize; + return BUNDLE_MANAGER_ERROR_CODE_NO_ERROR; } \ No newline at end of file diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 488462aa33..f473cfd14d 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1187,6 +1187,8 @@ public: const int32_t userId, PluginBundleInfo &pluginBundleInfo); bool SetBundleUserInfoRemovable(const std::string bundleName, int32_t userId, bool removable); ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner); + ErrCode ImplicitQueryAbilityInfosWithDefault(const Want &want, int32_t flags, int32_t userId, + std::vector &abilityInfos, AbilityInfo &defaultAbilityInfo, bool &findDefaultApp); private: /** diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index f3ad23960e..08a625633b 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1195,6 +1195,8 @@ public: const int32_t userId, PluginBundleInfo &pluginBundleInfo) override; virtual ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner) override; + virtual ErrCode GetAbilityResourceInfo(const std::string &fileType, + std::vector &launcherAbilityResourceInfos) override; private: bool GetLabelByBundleName(const std::string &bundleName, int32_t userId, std::string &label); @@ -1257,6 +1259,13 @@ private: bool SendQueryBundleInfoEvent(QueryEventInfo &query, int64_t intervalTime, bool reportNow); bool GetCallingInfo(int32_t callingUid, std::string &callingBundleName, std::string &callingAppId); + bool GetAbilityResourceInfoWithAbilityInfo(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, int32_t appIndex, + const std::vector &launcherAbilityResourceInfos, + LauncherAbilityResourceInfo &resultAbilityResourceInfo); + ErrCode ImplicitQueryAbilityInfosWithDefault(const std::string &normalizedType, + std::vector &launcherAbilityResourceInfos); + std::atomic isBrokerServiceExisted_ = false; }; } // namespace AppExecFwk diff --git a/services/bundlemgr/include/bundle_util.h b/services/bundlemgr/include/bundle_util.h index aab49944db..78e90e93b2 100644 --- a/services/bundlemgr/include/bundle_util.h +++ b/services/bundlemgr/include/bundle_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -245,6 +245,7 @@ public: static bool StrToUint32(const std::string &str, uint32_t &value); static std::string ExtractStringFromJson(nlohmann::json &jsonObject, const std::string &key); static std::unordered_map ParseMapFromJson(const std::string &jsonStr); + static std::vector FileTypeNormalize(const std::string &fileType); private: static std::mutex g_mutex; }; diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index d4c4232c84..ba58194c3c 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -11407,5 +11407,40 @@ ErrCode BundleDataMgr::GetTestRunner(const std::string &bundleName, const std::s BundleParser bundleParser; return bundleParser.ParseTestRunner(moduleInfo->hapPath, testRunner); } +ErrCode BundleDataMgr::ImplicitQueryAbilityInfosWithDefault(const Want &want, int32_t flags, int32_t userId, + std::vector &abilityInfos, AbilityInfo &defaultAbilityInfo, bool &findDefaultApp) +{ + (void)ImplicitQueryAbilityInfos(want, flags, userId, abilityInfos); + ImplicitQueryCloneAbilityInfos(want, flags, userId, abilityInfos); + if(abilityInfos.empty()) { + return ERR_BUNDLE_MANAGER_ABILITY_INFO_NOT_FOUND; + } +#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP + std::string identity = IPCSkeleton::ResetCallingIdentity(); + std::vector defaultAbilityInfos; + std::vector backupAbilityInfos; + std::vector extensionInfos; + if (DefaultAppMgr::GetInstance().GetDefaultApplication(want, userId, defaultAbilityInfos, extensionInfos)) { + if (!defaultAbilityInfos.empty()) { + APP_LOGI("find default ability"); + findDefaultApp = true; + defaultAbilityInfo = defaultAbilityInfos[0]; + IPCSkeleton::SetCallingIdentity(identity); + return ERR_OK; + } + } + if (DefaultAppMgr::GetInstance().GetDefaultApplication(want, userId, backupAbilityInfos, extensionInfos, true)) { + if (!backupAbilityInfos.empty()) { + APP_LOGI("find backup default ability"); + findDefaultApp = true; + defaultAbilityInfo = backupAbilityInfos[0]; + IPCSkeleton::SetCallingIdentity(identity); + return ERR_OK; + } + } + IPCSkeleton::SetCallingIdentity(identity); +#endif + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 2a42a0e1d4..42df40ea52 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -83,6 +83,7 @@ const std::string AUTH_TITLE = " "; const std::string BUNDLE_NAME = "bundleName"; const std::string LABEL = "label"; const std::string NEW_LINE = "\n"; +const std::string ACTION_VIEW_DATA = "ohos.want.action.viewData"; const std::string RESOURCE_NOT_SUPPORT = "warning: dump label failed due to the device not supporting bundle resource!"; const uint8_t JSON_INDENTATION = 4; @@ -6153,5 +6154,107 @@ ErrCode BundleMgrHostImpl::GetTestRunner(const std::string &bundleName, const st } return dataMgr->GetTestRunner(bundleName, moduleName, testRunner); } + +bool BundleMgrHostImpl::GetAbilityResourceInfoWithAbilityInfo(const std::string &bundleName, + const std::string &moduleName, const std::string &abilityName, int32_t appIndex, + const std::vector &launcherAbilityResourceInfos, + LauncherAbilityResourceInfo &resultAbilityResourceInfo) +{ + for (auto &launcherAbilityResourceInfo : launcherAbilityResourceInfos) { + if (launcherAbilityResourceInfo.bundleName == bundleName + && launcherAbilityResourceInfo.moduleName == moduleName + && launcherAbilityResourceInfo.abilityName == abilityName + && launcherAbilityResourceInfo.appIndex == appIndex) { + resultAbilityResourceInfo = launcherAbilityResourceInfo; + return true; + } + } + return false; +} + +ErrCode BundleMgrHostImpl::ImplicitQueryAbilityInfosWithDefault(const std::string &normalizedType, + std::vector &launcherAbilityResourceInfos) +{ +#ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + Want want; + want.SetType(normalizedType); + want.SetAction(ACTION_VIEW_DATA); + int32_t abilityInfoflags = static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_DEFAULT); + auto uid = IPCSkeleton::GetCallingUid(); + int32_t userId = BundleUtil::GetUserIdByUid(uid); + std::vector abilityInfos; + AbilityInfo defaultAbilityInfo; + bool findDefaultApp = false; + // query ability info and default ability info + auto res = dataMgr->ImplicitQueryAbilityInfosWithDefault(want, abilityInfoflags, userId, abilityInfos, + defaultAbilityInfo, findDefaultApp); + if (res != ERR_OK) { + APP_LOGE("ImplicitQueryAbilityInfosWithDefault failed"); + return res; + } + auto manager = DelayedSingleton::GetInstance(); + if (manager == nullptr) { + APP_LOGE("manager is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + uint32_t resourceInfoflags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); + std::vector tmpResourceInfoVector; + LauncherAbilityResourceInfo tmpResourceInfo; + for (auto &abilityInfo : abilityInfos) { + tmpResourceInfoVector = {}; + // get launcher ability resource info by ability info + if (!manager->GetLauncherAbilityResourceInfo(abilityInfo.bundleName, resourceInfoflags, + tmpResourceInfoVector, abilityInfo.appIndex)) { + APP_LOGW("get resource failed -n %{public}s -f %{public}u", abilityInfo.bundleName.c_str(), + resourceInfoflags); + continue; + } + if (!GetAbilityResourceInfoWithAbilityInfo(abilityInfo.bundleName, abilityInfo.moduleName, + abilityInfo.name, abilityInfo.appIndex, tmpResourceInfoVector, tmpResourceInfo)) { + continue; + } + // update default app flag in tmpResourceInfo + if (findDefaultApp && defaultAbilityInfo.bundleName == abilityInfo.bundleName + && defaultAbilityInfo.appIndex == abilityInfo.appIndex && defaultAbilityInfo.name == abilityInfo.name) { + findDefaultApp = false; + tmpResourceInfo.isDefaultApp = true; + } + launcherAbilityResourceInfos.push_back(tmpResourceInfo); + } +#else + APP_LOGI("bundle resource not support"); +#endif + return ERR_OK; +} + +ErrCode BundleMgrHostImpl::GetAbilityResourceInfo(const std::string &fileType, + std::vector &launcherAbilityResourceInfos) +{ + APP_LOGD("start GetLauncherAbilityResourceInfo, fileType: %{public}s", fileType.c_str()); + if (fileType.empty()) { + APP_LOGW("fileType is empty"); + return ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE; + } + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_ABILITY_INFO)) { + APP_LOGE("verify permission failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + std::vector normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); + APP_LOGI("normalized:%{public}s", BundleUtil::ToString(normalizedTypeVector).c_str()); + if (normalizedTypeVector.empty()) { + APP_LOGW("normalizedTypeVector empty"); + return ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE; + } + for (const std::string& normalizedType : normalizedTypeVector) { + (void)ImplicitQueryAbilityInfosWithDefault(normalizedType, launcherAbilityResourceInfos); + } + APP_LOGI("GetAbilityResourceInfo end, size: %{public}zu", launcherAbilityResourceInfos.size()); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_util.cpp b/services/bundlemgr/src/bundle_util.cpp index 95e60f22f3..da6cb47dde 100644 --- a/services/bundlemgr/src/bundle_util.cpp +++ b/services/bundlemgr/src/bundle_util.cpp @@ -33,6 +33,7 @@ #include "hitrace_meter.h" #include "installd_client.h" #include "ipc_skeleton.h" +#include "mime_type_mgr.h" #include "parameter.h" #include "string_ex.h" #ifdef BUNDLE_FRAMEWORK_UDMF_ENABLED @@ -1222,5 +1223,28 @@ bool BundleUtil::GetBitValue(const uint8_t num, const uint8_t pos) { return (num & (1U << pos)) != 0; } + +std::vector BundleUtil::FileTypeNormalize(const std::string &fileType) +{ +#ifdef BUNDLE_FRAMEWORK_UDMF_ENABLED + if (BundleUtil::IsUtd(fileType)) { + return {fileType}; + } + if (fileType[0] == '.') { + std::vector utdVector; + if (!MimeTypeMgr::GetUtdVectorByUri(fileType, utdVector)) { + APP_LOGW("GetUtdVectorByUri failed"); + return {}; + } else { + return utdVector; + } + } else { + return BundleUtil::GetUtdVectorByMimeType(fileType); + } +#else + APP_LOGI("UDMF not support"); + return {}; +#endif +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp index 1017d5e36b..6db3cc0235 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp @@ -2101,4 +2101,110 @@ HWTEST_F(BmsBundleManagerTest3, GetTestRunner_0100, Function | MediumTest | Leve UnInstallBundle(BUNDLE_BACKUP_NAME); } + +/** + * @tc.number: FileTypeNormalize_0001 + * @tc.name: test FileTypeNormalize + * @tc.desc: 1.test FileTypeNormalize + 2.fileType + */ +HWTEST_F(BmsBundleManagerTest3, FileTypeNormalize_0001, Function | MediumTest | Level1) +{ + std::string fileType = "general.png"; + std::vector expectedTypeVector = {"general.png"}; + std::vector normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); + EXPECT_EQ(normalizedTypeVector, expectedTypeVector); + + fileType = ".png"; + normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); + EXPECT_EQ(normalizedTypeVector, expectedTypeVector); + + fileType = "image/png"; + normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); + EXPECT_EQ(normalizedTypeVector, expectedTypeVector); +} + +/** + * @tc.number: GetAbilityResourceInfo_0001 + * @tc.name: test GetAbilityResourceInfo + * @tc.desc: 1.test GetAbilityResourceInfo + 2.empty fileType + */ +HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfo_0001, Function | MediumTest | Level1) +{ + auto hostImpl = std::make_unique(); + std::string fileType = ""; + std::vector launcherAbilityResourceInfos; + auto testRet = hostImpl->GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); + EXPECT_EQ(testRet, ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE); + EXPECT_TRUE(launcherAbilityResourceInfos.empty()); +} + +/** + * @tc.number: GetAbilityResourceInfo_0002 + * @tc.name: test GetAbilityResourceInfo + * @tc.desc: 1.test GetAbilityResourceInfo + 2.text fileType + */ +HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfo_0002, Function | MediumTest | Level1) +{ + auto hostImpl = std::make_unique(); + std::string fileType = "text/html"; + std::vector launcherAbilityResourceInfos; + auto testRet = hostImpl->GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); + EXPECT_EQ(testRet, ERR_OK); +} + +/** + * @tc.number: GetAbilityResourceInfoWithAbilityInfo_0001 + * @tc.name: test GetAbilityResourceInfoWithAbilityInfo + * @tc.desc: 1.test GetAbilityResourceInfoWithAbilityInfo + */ +HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfoWithAbilityInfo_0001, Function | MediumTest | Level1) +{ + auto hostImpl = std::make_unique(); + std::string bundleName1 = "bundleName1"; + std::string moduleName1 = "moduleName1"; + std::string abilityName1 = "abilityName1"; + int32_t appIndex1 = 0; + std::vector launcherAbilityResourceInfos; + LauncherAbilityResourceInfo resultAbilityResourceInfo; + bool res = hostImpl->GetAbilityResourceInfoWithAbilityInfo(bundleName1, moduleName1, abilityName1, appIndex1, + launcherAbilityResourceInfos, resultAbilityResourceInfo); + EXPECT_FALSE(res); + LauncherAbilityResourceInfo launcherAbilityResourceInfo; + launcherAbilityResourceInfo.bundleName = "bundleName"; + launcherAbilityResourceInfo.moduleName = "moduleName"; + launcherAbilityResourceInfo.abilityName = "abilityName"; + launcherAbilityResourceInfo.appIndex = 0; + launcherAbilityResourceInfos.push_back(launcherAbilityResourceInfo); + launcherAbilityResourceInfo.bundleName = "bundleName1"; + launcherAbilityResourceInfo.moduleName = "moduleName1"; + launcherAbilityResourceInfo.abilityName = "abilityName1"; + launcherAbilityResourceInfo.appIndex = 0; + launcherAbilityResourceInfos.push_back(launcherAbilityResourceInfo); + res = hostImpl->GetAbilityResourceInfoWithAbilityInfo(bundleName1, moduleName1, abilityName1, appIndex1, + launcherAbilityResourceInfos, resultAbilityResourceInfo); + EXPECT_TRUE(res); + EXPECT_EQ(launcherAbilityResourceInfo.bundleName, resultAbilityResourceInfo.bundleName); +} + +/** + * @tc.number: ImplicitQueryAbilityInfosWithDefault_0001 + * @tc.name: test ImplicitQueryAbilityInfosWithDefault + * @tc.desc: 1.system run normally + * 2.want param is empty +*/ +HWTEST_F(BmsBundleManagerTest3, ImplicitQueryAbilityInfosWithDefault_0001, Function | SmallTest | Level1) +{ + AAFwk::Want want; + want.SetUri(""); + want.SetType(""); + std::vector abilityInfos; + AbilityInfo defaultAbilityInfo; + bool findDefaultApp = false; + auto testRet = GetBundleDataMgr()->ImplicitQueryAbilityInfosWithDefault( + want, 0, USERID, abilityInfos, defaultAbilityInfo, findDefaultApp); + EXPECT_EQ(testRet, ERR_BUNDLE_MANAGER_ABILITY_INFO_NOT_FOUND); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp index 2489ec3188..0fba46759c 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp @@ -1968,4 +1968,33 @@ HWTEST_F(BmsBundlePermissionFalseTest, GetShortcutInfoByAppIndex_0001, Function EXPECT_EQ(testRet, ERR_BUNDLE_MANAGER_PERMISSION_DENIED); EXPECT_TRUE(shortcutInfos.empty()); } + +/** + * @tc.number: GetAbilityResourceInfo_0001 + * @tc.name: test GetAbilityResourceInfo + * @tc.desc: test GetAbilityResourceInfo + */ +HWTEST_F(BmsBundlePermissionFalseTest, GetAbilityResourceInfo_0001, Function | SmallTest | Level1) +{ + std::string fileType = "general.png"; + std::vector launcherAbilityResourceInfos; + auto testRet = bundleMgrHostImpl_->GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); + EXPECT_EQ(testRet, ERR_BUNDLE_MANAGER_PERMISSION_DENIED); + EXPECT_TRUE(launcherAbilityResourceInfos.empty()); +} + +/** + * @tc.number: GetAbilityResourceInfo_0002 + * @tc.name: test GetAbilityResourceInfo + * @tc.desc: test GetAbilityResourceInfo + */ +HWTEST_F(BmsBundlePermissionFalseTest, GetAbilityResourceInfo_0002, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + std::string fileType = "general.png"; + data.WriteString(fileType); + ErrCode res = bundleMgrHostImpl_->HandleGetAbilityResourceInfo(data, reply); + EXPECT_EQ(res, ERR_OK); +} } // OHOS \ No newline at end of file diff --git a/test/systemtest/common/bms/bms_bundle_mgr_host_test/bms_bundle_mgr_host_test.cpp b/test/systemtest/common/bms/bms_bundle_mgr_host_test/bms_bundle_mgr_host_test.cpp index b4936dd0e8..d62f112bea 100644 --- a/test/systemtest/common/bms/bms_bundle_mgr_host_test/bms_bundle_mgr_host_test.cpp +++ b/test/systemtest/common/bms/bms_bundle_mgr_host_test/bms_bundle_mgr_host_test.cpp @@ -2246,5 +2246,20 @@ HWTEST_F(BmsBundleMgrHostTest, HandleGetPluginInfo_0001, Function | MediumTest | ErrCode res = bundleMgrHost.HandleGetPluginInfo(data, reply); EXPECT_EQ(res, ERR_OK); } + + /** + * @tc.number: HandleGetAbilityResourceInfo_0001 + * @tc.name: test the HandleGetAbilityResourceInfo + * @tc.desc: 1. system running normally + * 2. test HandleGetAbilityResourceInfo + */ +HWTEST_F(BmsBundleMgrHostTest, HandleGetAbilityResourceInfo_0001, Function | MediumTest | Level1) +{ + BundleMgrHost bundleMgrHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = bundleMgrHost.HandleGetAbilityResourceInfo(data, reply); + EXPECT_EQ(res, ERR_OK); +} } // AppExecFwk } // OHOS \ No newline at end of file -- Gitee