openharmony 鸿蒙 capi-asset-api-h

2026-08-25 浏览 (1)

asset_api.h

Overview

Defines the functions for accessing assets.

File to include: <asset/asset_api.h>

Library: libasset_ndk.z.so

System capability: SystemCapability.Security.Asset

Since: 11

Related module: AssetApi

Summary

Functions

NameDescription
int32_t OH_Asset_Add(const Asset_Attr *attributes, uint32_t attrCnt)Adds an asset.
To set the Asset_Tag.ASSET_TAG_IS_PERSISTENT attribute, request the ohos.permission.STORE_PERSISTENT_DATA permission.
int32_t OH_Asset_Remove(const Asset_Attr *query, uint32_t queryCnt)Removes one or more assets.
int32_t OH_Asset_Update(const Asset_Attr *query, uint32_t queryCnt, const Asset_Attr *attributesToUpdate, uint32_t updateCnt)Updates an asset.
int32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob *challenge)Performs preprocessing for the asset query. This function is used when user authentication is required for the access to the asset.
int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet)Queries one or more assets.
int32_t OH_Asset_PostQuery(const Asset_Attr *handle, uint32_t handleCnt)Performs postprocessing for the asset query. This function is used when user authentication is required for the access to the asset.
int32_t OH_Asset_QuerySyncResult(const Asset_Attr *query, uint32_t queryCnt, Asset_SyncResult *syncResult)Queries the sync result of an asset.
Asset_Attr *OH_Asset_ParseAttr(const Asset_Result *result, Asset_Tag tag)Parses the query result and obtains the specified attribute.
void OH_Asset_FreeBlob(Asset_Blob *blob)Releases the memory occupied by the challenge value.
void OH_Asset_FreeResultSet(Asset_ResultSet *resultSet)Releases the memory occupied by the query result.

Function Description

OH_Asset_Add()

int32_t OH_Asset_Add(const Asset_Attr *attributes, uint32_t attrCnt)

Description

Adds an asset.

To set the Asset_Tag.ASSET_TAG_IS_PERSISTENT attribute, request the ohos.permission.STORE_PERSISTENT_DATA permission.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *attributesAttributes of the asset to add.
uint32_t attrCntNumber of attributes of the asset to add.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_PERMISSION_DENIED = 201: The caller is not a system application.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. Mandatory parameters are left unspecified.
2. The parameter type is incorrect.
3. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_DUPLICATED = 24000003: The asset already exists.
ASSET_STATUS_MISMATCH = 24000005: The screen lock status is incorrect.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_DATA_CORRUPTED = 24000007: The asset is corrupted.
ASSET_DATABASE_ERROR = 24000008: The database operation failed.
ASSET_CRYPTO_ERROR = 24000009: The cryptographic operation failed.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_FILE_OPERATION_ERROR = 24000014: The file operation failed.
ASSET_GET_SYSTEM_TIME_ERROR = 24000015: Failed to obtain the system time.

OH_Asset_Remove()

int32_t OH_Asset_Remove(const Asset_Attr *query, uint32_t queryCnt)

Description

Removes one or more assets.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *queryAttributes of the asset to remove.
uint32_t queryCntNumber of attributes.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. The parameter type is incorrect.
2. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_NOT_FOUND = 24000002: The asset is not found.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_DATA_CORRUPTED = 24000007: The asset is corrupted.
ASSET_DATABASE_ERROR = 24000008: The database operation failed.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_GET_SYSTEM_TIME_ERROR = 24000015: Failed to obtain the system time.

OH_Asset_Update()

int32_t OH_Asset_Update(const Asset_Attr *query, uint32_t queryCnt,const Asset_Attr *attributesToUpdate, uint32_t updateCnt)

Description

Updates an asset.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *queryAttributes of the asset to update.
uint32_t queryCntNumber of attributes to update.
const Asset_Attr *attributesToUpdateNew attributes of the asset.
uint32_t updateCntNumber of new attributes.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. Mandatory parameters are left unspecified.
2. The parameter type is incorrect.
3. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_NOT_FOUND = 24000002: The asset is not found.
ASSET_STATUS_MISMATCH = 24000005: The screen lock status is incorrect.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_DATA_CORRUPTED = 24000007: The asset is corrupted.
ASSET_DATABASE_ERROR = 24000008: The database operation failed.
ASSET_CRYPTO_ERROR = 24000009: The cryptographic operation failed.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_GET_SYSTEM_TIME_ERROR = 24000015: Failed to obtain the system time.

OH_Asset_PreQuery()

int32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob *challenge)

Description

Performs preprocessing for the asset query. This API is used when user authentication is required for the access to the asset.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *queryAttributes of the asset to query.
uint32_t queryCntNumber of attributes.
Asset_Blob *challengeChallenge value, which is used when OH_Asset_Query is called.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. The parameter type is incorrect.
2. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_NOT_FOUND = 24000002: The asset is not found.
ASSET_STATUS_MISMATCH = 24000005: The screen lock status is incorrect.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_DATA_CORRUPTED = 24000007: The asset is corrupted.
ASSET_DATABASE_ERROR = 24000008: The database operation failed.
ASSET_CRYPTO_ERROR = 24000009: The cryptographic operation failed.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_LIMIT_EXCEEDED = 24000016: The number of cached assets reaches the limit.
ASSET_UNSUPPORTED = 24000017: This function is not supported.

OH_Asset_Query()

int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet)

Description

Queries one or more assets.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *queryAttributes of the asset to query.
uint32_t queryCntNumber of attributes.
Asset_ResultSet *resultSetArray of query results.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. The parameter type is incorrect.
2. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_NOT_FOUND = 24000002: The asset is not found.
ASSET_ACCESS_DENIED = 24000004: Access to the asset is denied.
ASSET_STATUS_MISMATCH = 24000005: The screen lock status is incorrect.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_DATA_CORRUPTED = 24000007: The asset is corrupted.
ASSET_DATABASE_ERROR = 24000008: The database operation failed.
ASSET_CRYPTO_ERROR = 24000009: The cryptographic operation failed.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_UNSUPPORTED = 24000017: This function is not supported.

OH_Asset_PostQuery()

int32_t OH_Asset_PostQuery(const Asset_Attr *handle, uint32_t handleCnt)

Description

Performs postprocessing for the asset query. This API is used when user authentication is required for the access to the asset.

Since: 11

Parameters

ParameterDescription
const Asset_Attr *handleHandle of the query operation, including the challenge value returned by OH_Asset_PreQuery.
uint32_t handleCntNumber of elements in the handle attribute set.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_INVALID_ARGUMENT = 401: invalid parameter. Possible causes:
1. Mandatory parameters are left unspecified.
2. The parameter type is incorrect.
3. Parameter verification failed.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.

OH_Asset_QuerySyncResult()

int32_t OH_Asset_QuerySyncResult(const Asset_Attr *query, uint32_t queryCnt, Asset_SyncResult *syncResult)

Description

Queries the sync result of an asset.

Since: 20

Parameters

ParameterDescription
const Asset_Attr *queryAttributes of the asset to query the sync result.
uint32_t queryCntNumber of attributes.
Asset_SyncResult *syncResultSync result of the queried asset.

Return value

TypeDescription
int32_tAsset_ResultCode:
ASSET_SUCCESS = 0: Operation succeeded.
ASSET_SERVICE_UNAVAILABLE = 24000001: The asset service is unavailable.
ASSET_OUT_OF_MEMORY = 24000006: The system memory is insufficient.
ASSET_IPC_ERROR = 24000010: The IPC failed.
ASSET_BMS_ERROR = 24000011: The bundle manager service is abnormal.
ASSET_ACCOUNT_ERROR = 24000012: The account service is abnormal.
ASSET_ACCESS_TOKEN_ERROR = 24000013: The access token service is abnormal.
ASSET_FILE_OPERATION_ERROR = 24000014: The file operation failed.
ASSET_PARAM_VERIFICATION_FAILED = 24000018: Parameter verification failed.

OH_Asset_ParseAttr()

Asset_Attr *OH_Asset_ParseAttr(const Asset_Result *result, Asset_Tag tag)

Description

Parses the query result and obtains the specified attribute.

Since: 11

Parameters

ParameterDescription
const Asset_Result *resultQuery result returned by OH_Asset_Query.
Asset_Tag tagKey of the attribute to obtain.

Return value

TypeDescription
Asset_AttrReturns Asset_Attr obtained if the operation is successful; returns NULL otherwise. The attribute does not need to be released by the service.

OH_Asset_FreeBlob()

void OH_Asset_FreeBlob(Asset_Blob *blob)

Description

Releases the memory occupied by the challenge value.

Since: 11

Parameters

ParameterDescription
Asset_Blob *blobChallenge value returned by OH_Asset_PreQuery.

OH_Asset_FreeResultSet()

void OH_Asset_FreeResultSet(Asset_ResultSet *resultSet)

Description

Releases the memory occupied by the query result.

Since: 11

Parameters

ParameterDescription
Asset_ResultSet *resultSetQuery result returned by OH_Asset_Query.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-asset-type-h

openharmony 鸿蒙 capi-assettype-asset-attr

openharmony 鸿蒙 capi-assettype-asset-blob

openharmony 鸿蒙 capi-assettype-asset-value

openharmony 鸿蒙 capi-assettype-asset-syncresult

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 capi-assettype-asset-resultset

openharmony 鸿蒙 capi-assettype

openharmony 鸿蒙 errorcode-asset

openharmony 鸿蒙 capi-assettype-asset-result

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/uW7pLaDk