!629 资源管理CAPI规范整改

Merge pull request !629 from 高超/rawfile_new
This commit is contained in:
openharmony_ci 2024-07-27 09:49:48 +00:00 committed by Gitee
commit c27a416152
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 250 additions and 13 deletions

View File

@ -80,9 +80,6 @@ ResourceManager_ErrorCode copyLocalInfo(const icu::Locale *localeInfo, ResourceM
if (region != nullptr) {
locale += std::string("_") + region;
}
if (configuration->locale != nullptr) {
free(configuration->locale);
}
configuration->locale = (char*)malloc(locale.size() + 1);
if (configuration->locale == nullptr) {
RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetConfiguration malloc error");
@ -116,6 +113,12 @@ ResourceManager_ErrorCode copyString(char **resultValue, string tempResultValue,
ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResourceManager *mgr, uint32_t resId,
char **resultValue, uint64_t *resultLen, uint32_t density)
{
return OH_ResourceManager_GetMediaBase64Data(mgr, resId, resultValue, resultLen, density);
}
ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64Data(const NativeResourceManager *mgr, uint32_t resId,
char **resultValue, uint64_t *resultLen, uint32_t density)
{
if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -145,6 +148,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResource
ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager *mgr,
const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density)
{
return OH_ResourceManager_GetMediaBase64DataByName(mgr, resName, resultValue, resultLen, density);
}
ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64DataByName(const NativeResourceManager *mgr,
const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density)
{
if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -175,6 +184,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeRe
ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManager *mgr, uint32_t resId,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
{
return OH_ResourceManager_GetMediaData(mgr, resId, resultValue, resultLen, density);
}
ResourceManager_ErrorCode OH_ResourceManager_GetMediaData(const NativeResourceManager *mgr, uint32_t resId,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
{
if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -202,6 +217,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManage
ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResourceManager *mgr, const char *resName,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
{
return OH_ResourceManager_GetMediaDataByName(mgr, resName, resultValue, resultLen, density);
}
ResourceManager_ErrorCode OH_ResourceManager_GetMediaDataByName(const NativeResourceManager *mgr, const char *resName,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
{
if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -229,6 +250,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResource
ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeResourceManager *mgr,
uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
{
return OH_ResourceManager_GetDrawableDescriptorData(mgr, resId, drawableDescriptor, density, type);
}
ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorData(const NativeResourceManager *mgr,
uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
{
if (mgr == nullptr || drawableDescriptor == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -260,6 +287,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeR
ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager *mgr,
const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
{
return OH_ResourceManager_GetDrawableDescriptorDataByName(mgr, resName, drawableDescriptor, density, type);
}
ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorDataByName(const NativeResourceManager *mgr,
const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
{
if (mgr == nullptr || drawableDescriptor == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
@ -338,6 +371,12 @@ ResourceManager_ErrorCode OH_ResourceManager_GetSymbolByName(const NativeResourc
ResourceManager_ErrorCode OH_ResourceManager_GetLocales(const NativeResourceManager *mgr, char ***resultValue,
uint32_t *resultLen, bool includeSystem)
{
return OH_ResourceManager_GetLocalesData(mgr, resultValue, resultLen, includeSystem);
}
ResourceManager_ErrorCode OH_ResourceManager_GetLocalesData(const NativeResourceManager *mgr, char ***resultValue,
uint32_t *resultLen, bool includeSystem)
{
if (mgr == nullptr || resultValue == nullptr) {
return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;

View File

@ -364,12 +364,17 @@ static bool GetRawFileDescriptorFromHap(const RawFile *rawFile, RawFileDescripto
}
bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor)
{
return OH_ResourceManager_GetRawFileDescriptorData(rawFile, &descriptor);
}
bool OH_ResourceManager_GetRawFileDescriptorData(const RawFile *rawFile, RawFileDescriptor *descriptor)
{
if (rawFile == nullptr || rawFile->actualOffset == nullptr) {
return false;
}
if (rawFile->resMgr != nullptr) {
return GetRawFileDescriptorFromHap(rawFile, descriptor);
return GetRawFileDescriptorFromHap(rawFile, *descriptor);
}
char paths[PATH_MAX] = {0};
#ifdef __WINNT__
@ -383,9 +388,9 @@ bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDesc
#endif
int fd = open(paths, O_RDONLY);
if (fd > 0) {
descriptor.fd = fd;
descriptor.length = static_cast<long>(rawFile->length);
descriptor.start = static_cast<long>(rawFile->actualOffset->offset);
descriptor->fd = fd;
descriptor->length = static_cast<long>(rawFile->length);
descriptor->start = static_cast<long>(rawFile->actualOffset->offset);
} else {
return false;
}
@ -394,8 +399,13 @@ bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDesc
bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor)
{
if (descriptor.fd > 0) {
return close(descriptor.fd) == 0;
return OH_ResourceManager_ReleaseRawFileDescriptorData(&descriptor);
}
bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor)
{
if (descriptor->fd > 0) {
return close(descriptor->fd) == 0;
}
return true;
}

View File

@ -64,6 +64,29 @@ extern "C" {
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 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. If this attribute is not required, set this parameter to 0.
* @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 - 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_GetMediaBase64Data(const NativeResourceManager *mgr, uint32_t resId,
char **resultValue, uint64_t *resultLen, uint32_t density);
/**
* @brief Obtains the Base64 code of the image resource.
*
@ -87,6 +110,29 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResource
ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager *mgr,
const char *resName, 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. If this attribute is not required, set this parameter to 0.
* @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 - 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_GetMediaBase64DataByName(const NativeResourceManager *mgr,
const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density);
/**
* @brief Obtains the content of the image resource.
*
@ -110,6 +156,29 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeRe
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 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. If this attribute is not required, set this parameter to 0.
* @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 - 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_GetMediaData(const NativeResourceManager *mgr, uint32_t resId,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density);
/**
* @brief Obtains the content of the image resource.
*
@ -133,6 +202,29 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManage
ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResourceManager *mgr, const char *resName,
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. If this attribute is not required, set this parameter to 0.
* @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 - 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_GetMediaDataByName(const NativeResourceManager *mgr, const char *resName,
uint8_t **resultValue, uint64_t *resultLen, uint32_t density);
/**
* @brief Obtains the DrawableDescriptor of the media file.
*
@ -155,6 +247,29 @@ ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResource
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 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. If this attribute is not required, set this parameter to 0.
* @param type The optional parameter means the media type, 0 means the normal media, 1 means the the theme style media.
* If this attribute is not required, set this parameter to 0.
* @param drawableDescriptor the result write to drawableDescriptor.
* @return {@link SUCCESS} 0 - Success.
* {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - 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_GetDrawableDescriptorData(const NativeResourceManager *mgr,
uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type);
/**
* @brief Obtains the DrawableDescriptor of the media file.
*
@ -177,6 +292,28 @@ ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeR
ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager *mgr,
const char *resName, 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. If this attribute is not required, set this parameter to 0.
* @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. If this attribute is not required, set this parameter to 0.
* @param drawableDescriptor the result write to drawableDescriptor.
* @return {@link SUCCESS} 0 - Success.
* {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - 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_GetDrawableDescriptorDataByName(const NativeResourceManager *mgr,
const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type);
/**
* @brief Obtains the symbol resource.
*
@ -237,6 +374,26 @@ ResourceManager_ErrorCode OH_ResourceManager_GetSymbolByName(const NativeResourc
ResourceManager_ErrorCode OH_ResourceManager_GetLocales(const NativeResourceManager *mgr, char ***resultValue,
uint32_t *resultLen, bool includeSystem = false);
/**
* @brief Obtains locales list.
*
* You need to call the OH_ResourceManager_ReleaseStringArray() method to release the memory of localinfo.
*
* @param mgr Indicates the pointer to {@link NativeResourceManager}
* {@link OH_ResourceManager_InitNativeResourceManager}.
* @param resultValue the result write to resultValue.
* @param resultLen the locales length write to resultLen.
* @param includeSystem the parameter controls whether to include system resources.
* If this attribute is not required, set this parameter to false.
* @return {@link SUCCESS} 0 - Success.
* {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - The input parameter invalid.
Possible causes: Incorrect parameter types.
* {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory.
* @since 12
*/
ResourceManager_ErrorCode OH_ResourceManager_GetLocalesData(const NativeResourceManager *mgr, char ***resultValue,
uint32_t *resultLen, bool includeSystem);
/**
* @brief Obtains the device configuration.
*

View File

@ -38,7 +38,9 @@
#ifndef GLOBAL_RAW_FILE_H
#define GLOBAL_RAW_FILE_H
#include <string>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
@ -196,9 +198,24 @@ long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile);
* @return Returns true: open the raw file descriptor successfully, false: the raw file is not allowed to access.
* @since 8
* @version 1.0
* @deprecated since 12
* @useinstead OH_ResourceManager_GetRawFileDescriptorData
*/
bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor);
/**
* @brief Obtains the file descriptor of a raw file based on the long offset and file length.
*
* The obtains raw file descriptor is used to read the raw file.
*
* @param rawFile Indicates the pointer to {@link RawFile}.
* @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
* @return Returns true: obtains the raw file descriptor successfully, false: the raw file is not allowed to access.
* @since 12
* @version 1.0
*/
bool OH_ResourceManager_GetRawFileDescriptorData(const RawFile *rawFile, RawFileDescriptor *descriptor);
/**
* @brief Closes the file descriptor of a raw file.
*
@ -208,9 +225,23 @@ bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDesc
* @return Returns true: closes the raw file descriptor successfully, false: closes the raw file descriptor failed.
* @since 8
* @version 1.0
* @deprecated since 12
* @useinstead OH_ResourceManager_ReleaseRawFileDescriptorData
*/
bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor);
/**
* @brief Release the file descriptor of a raw file.
*
* The opened raw file descriptor must be released after used to avoid the file descriptor leak.
*
* @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
* @return Returns true: release the raw file descriptor successfully, false: release the raw file descriptor failed.
* @since 12
* @version 1.0
*/
bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor);
/**
* @brief Reads a raw file.
*

View File

@ -148,7 +148,7 @@ typedef struct ResourceManager_Configuration {
/** Indicates the screen direction of the current device. */
ResourceManager_Direction direction;
/** Indicates the current system language, for example, zh-Hans-CN. */
char* locale = nullptr;
char* locale;
/** Indicates the device type. */
ResourceManager_DeviceType deviceType;
/** Indicates the screen density. */
@ -156,9 +156,9 @@ typedef struct ResourceManager_Configuration {
/** Indicates the color mode. */
ResourceManager_ColorMode colorMode;
/** Indicates the mcc. */
uint32_t mcc = 0;
uint32_t mcc;
/** Indicates the mnc. */
uint32_t mnc = 0;
uint32_t mnc;
/** Reserved attributes. */
uint32_t reserved[20];
} ResourceManager_Configuration;