diff --git a/global/resource_management/BUILD.gn b/global/resource_management/BUILD.gn index d5c9057ab122f1b8cc518c93dd92d85d06be1241..3db518153420630155c86f2a5b1705089047a8d4 100644 --- a/global/resource_management/BUILD.gn +++ b/global/resource_management/BUILD.gn @@ -22,8 +22,28 @@ ohos_ndk_library("librawfile_ndk") { ohos_ndk_headers("rawfile_header") { dest_dir = "$ndk_headers_out_dir/rawfile" sources = [ - "./include/raw_dir.h", - "./include/raw_file.h", - "./include/raw_file_manager.h", + "./include/rawfile/raw_dir.h", + "./include/rawfile/raw_file.h", + "./include/rawfile/raw_file_manager.h", + ] +} + +ohos_ndk_library("native_resmgr_ndk") { + ndk_description_file = "./libnative_resmgr.ndk.json" + min_compact_version = "12" + output_name = "ohresmgr" + output_extension = "so" + system_capability = "SystemCapability.Global.ResourceManager" + system_capability_headers = [ + "resourcemanager/ohresmgr.h", + "resourcemanager/resmgr_common.h", + ] +} + +ohos_ndk_headers("native_resmgr_header") { + dest_dir = "$ndk_headers_out_dir/resourcemanager" + sources = [ + "./include/resourcemanager/ohresmgr.h", + "./include/resourcemanager/resmgr_common.h", ] } diff --git a/global/resource_management/include/raw_dir.h b/global/resource_management/include/rawfile/raw_dir.h similarity index 100% rename from global/resource_management/include/raw_dir.h rename to global/resource_management/include/rawfile/raw_dir.h diff --git a/global/resource_management/include/raw_file.h b/global/resource_management/include/rawfile/raw_file.h similarity index 100% rename from global/resource_management/include/raw_file.h rename to global/resource_management/include/rawfile/raw_file.h diff --git a/global/resource_management/include/raw_file_manager.h b/global/resource_management/include/rawfile/raw_file_manager.h similarity index 100% rename from global/resource_management/include/raw_file_manager.h rename to global/resource_management/include/rawfile/raw_file_manager.h diff --git a/global/resource_management/include/resourcemanager/ohresmgr.h b/global/resource_management/include/resourcemanager/ohresmgr.h new file mode 100644 index 0000000000000000000000000000000000000000..5b07163738bf1df96e1e5a8a089ad42fca797279 --- /dev/null +++ b/global/resource_management/include/resourcemanager/ohresmgr.h @@ -0,0 +1,185 @@ +/* + * 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. + */ + +/** + * @addtogroup resourcemanager + * @{ + * + * @brief Provides the c interface to obtain resources, and relies on librawfile.z.so when used. + * + * @since 12 + */ + +/** + * @file ohresmgr.h + * + * @brief Provides the implementation of the interface. + * @syscap SystemCapability.Global.ResourceManager + * @library libohresmgr.so + * @since 12 + */ +#ifndef GLOBAL_OH_RESMGR_H +#define GLOBAL_OH_RESMGR_H + +#include "resmgr_common.h" +#include "../rawfile/raw_file_manager.h" +#include "../arkui/drawable_descriptor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Obtains the Base64 code of the image resource. + * + * Obtains the Base64 code of the image resource corresponding to the specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResourceManager *mgr, uint32_t resId, + char **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the Base64 code of the image resource. + * + * Obtains the Base64 code of the image resource corresponding to the specified resource name. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager *mgr, + const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the content of the image resource. + * + * Obtains the content of the specified screen density media file corresponding to a specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManager *mgr, uint32_t resId, + uint8_t **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the content of the image resource. + * + * Obtains the content of the specified screen density media file corresponding to a specified resource name. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResourceManager *mgr, const char *resName, + uint8_t **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the DrawableDescriptor of the media file. + * + * Obtains the DrawableDescriptor of the media file corresponding to a specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param type The optional parameter means the media type, 0 means the normal media, 1 means the the theme style media. + * @param drawableDescriptor the result write to drawableDescriptor. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeResourceManager *mgr, + uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density = 0, uint32_t type = 0); + +/** + * @brief Obtains the DrawableDescriptor of the media file. + * + * Obtains the DrawableDescriptor of the media file corresponding to a specified resource name. + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param type The optional parameter means the media type, 0 means the normal media, 1 means the the theme style media, + * 2 means the theme dynamic media. + * @param drawableDescriptor the result write to drawableDescriptor. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager *mgr, + const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density = 0, uint32_t type = 0); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_OH_RESMGR_H \ No newline at end of file diff --git a/global/resource_management/include/resourcemanager/resmgr_common.h b/global/resource_management/include/resourcemanager/resmgr_common.h new file mode 100644 index 0000000000000000000000000000000000000000..4e9289e83ef08602a8c60f18647c265ccb800874 --- /dev/null +++ b/global/resource_management/include/resourcemanager/resmgr_common.h @@ -0,0 +1,98 @@ +/* + * 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. + */ + +/** + * @addtogroup resourcemanager + * @{ + * + * @brief Provides the c interface to obtain resources, and relies on librawfile.z.so when used. + * + * @since 12 + */ + +/** + * @file resmgr_common.h + * + * @brief Provides the structure required by the interface. + * @syscap SystemCapability.Global.ResourceManager + * @library libohresmgr.so + * @since 12 + */ +#ifndef GLOBAL_RESMGR_COMMON_H +#define GLOBAL_RESMGR_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The error code of resource manager. + * + * @since 12 + */ +typedef enum ResourceManager_ErrorCode { + /** @error Success */ + SUCCESS = 0, + /** @error Invalid input parameter */ + ERROR_CODE_INVALID_INPUT_PARAMETER = 401, + /** @error Invalid resource ID */ + ERROR_CODE_RES_ID_NOT_FOUND = 9001001, + /** @error Invalid resource name */ + ERROR_CODE_RES_NOT_FOUND_BY_ID = 9001002, + /** @error No matching resource is found based on the resource ID */ + ERROR_CODE_RES_NAME_NOT_FOUND = 9001003, + /** @error No matching resource is found based on the resource name */ + ERROR_CODE_RES_NOT_FOUND_BY_NAME = 9001004, + /** @error Invalid relative path */ + ERROR_CODE_RES_PATH_INVALID = 9001005, + /** @error The resource is referenced cyclically */ + ERROR_CODE_RES_REF_TOO_MUCH = 9001006, + /** @error Failed to format the resource obtained based on the resource ID */ + ERROR_CODE_RES_ID_FORMAT_ERROR = 9001007, + /** @error Failed to format the resource obtained based on the resource Name */ + ERROR_CODE_RES_NAME_FORMAT_ERROR = 9001008, + /** @error Failed to access the system resource */ + ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED = 9001009, + /** @error Invalid overlay path */ + ERROR_CODE_OVERLAY_RES_PATH_INVALID = 9001010, + /** @error Out of memory */ + ERROR_CODE_OUT_OF_MEMORY = 9001100, +} ResourceManager_ErrorCode; + +/** + * @brief Enumerates screen density types. + * + * @since 12 + */ +typedef enum ScreenDensity { + /** Indicates small screen density. */ + SCREEN_SDPI = 120, + /** Indicates medium screen density. */ + SCREEN_MDPI = 160, + /** Indicates large screen density. */ + SCREEN_LDPI = 240, + /** Indicates extra-large screen density. */ + SCREEN_XLDPI = 320, + /** Indicates extra-extra-large screen density. */ + SCREEN_XXLDPI = 480, + /** Indicates extra-extra-extra-large screen density. */ + SCREEN_XXXLDPI = 640, +} ScreenDensity; +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_RESMGR_COMMON_H diff --git a/global/resource_management/libnative_resmgr.ndk.json b/global/resource_management/libnative_resmgr.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..3fbb2cf92a9fc3dfedf402f64b3f2803bb3ca6af --- /dev/null +++ b/global/resource_management/libnative_resmgr.ndk.json @@ -0,0 +1,26 @@ +[ + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaBase64" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaBase64ByName" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMedia" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaByName" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetDrawableDescriptor" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetDrawableDescriptorByName" + } +] \ No newline at end of file