openharmony 鸿蒙 js-apis-asset

2025-06-12 浏览 (1)

@ohos.security.asset (Asset Store Service)

The asset store service (ASSET) provides secure storage and management of sensitive data less than 1024 bytes in size, including passwords, app tokens, and other critical data (such as bank card numbers).

NOTE

The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { asset } from '@kit.AssetStoreKit';

asset.add

add(attributes: AssetMap): Promise<void>

Add an asset. This API uses a promise to return the result.

To set IS_PERSISTENT, the application must have the ohos.permission.STORE_PERSISTENT_DATA permission.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
attributesAssetMapYesAttributes of the asset to add, including the asset plaintext, access control attributes, and custom data.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
201The caller doesn't have the permission.
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000003The asset already exists.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000014The file operation failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let attr: asset.AssetMap = new Map();
attr.set(asset.Tag.SECRET, stringToArray('demo_pwd'));
attr.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
attr.set(asset.Tag.ACCESSIBILITY, asset.Accessibility.DEVICE_FIRST_UNLOCKED);
attr.set(asset.Tag.DATA_LABEL_NORMAL_1, stringToArray('demo_label'));
try {
  asset.add(attr).then(() => {
    console.info(`Asset added successfully.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to add Asset. Code is ${err.code}, message is ${err.message}`);
  })
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to add Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.addSync12+

addSync(attributes: AssetMap): void

Add an asset. This API returns the result synchronously.

To set IS_PERSISTENT, the application must have the ohos.permission.STORE_PERSISTENT_DATA permission.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
attributesAssetMapYesAttributes of the asset to add, including the asset plaintext, access control attributes, and custom data.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
201The caller doesn't have the permission.
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000003The asset already exists.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000014The file operation failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let attr: asset.AssetMap = new Map();
attr.set(asset.Tag.SECRET, stringToArray('demo_pwd'));
attr.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
attr.set(asset.Tag.ACCESSIBILITY, asset.Accessibility.DEVICE_FIRST_UNLOCKED);
attr.set(asset.Tag.DATA_LABEL_NORMAL_1, stringToArray('demo_label'));
try {
  asset.addSync(attr);
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to add Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.remove

remove(query: AssetMap): Promise<void>

Removes one or more assets. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to remove, such as the asset alias, access control attributes, and custom data.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  asset.remove(query).then(() => {
    console.info(`Asset removed successfully.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`);
  });
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.removeSync12+

removeSync(query: AssetMap): void

Removes one or more assets. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to remove, such as the asset alias, access control attributes, and custom data.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  asset.removeSync(query);
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.update

update(query: AssetMap, attributesToUpdate: AssetMap): Promise<void>

Updates an asset. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to update, such as the asset alias, access control attributes, and custom data.
attributesToUpdateAssetMapYesNew attributes of the asset, such as the asset plaintext and custom data.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
let attrsToUpdate: asset.AssetMap = new Map();
attrsToUpdate.set(asset.Tag.SECRET, stringToArray('demo_pwd_new'));
try {
  asset.update(query, attrsToUpdate).then(() => {
    console.info(`Asset updated successfully.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to update Asset. Code is ${err.code}, message is ${err.message}`);
  });
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to update Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.updateSync12+

updateSync(query: AssetMap, attributesToUpdate: AssetMap): void

Updates an asset. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to update, such as the asset alias, access control attributes, and custom data.
attributesToUpdateAssetMapYesNew attributes of the asset, such as the asset plaintext and custom data.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000015Getting the system time failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
let attrsToUpdate: asset.AssetMap = new Map();
attrsToUpdate.set(asset.Tag.SECRET, stringToArray('demo_pwd_new'));
try {
  asset.updateSync(query, attrsToUpdate);
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to update Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.preQuery

preQuery(query: AssetMap): Promise<Uint8Array>

Performs preprocessing for the asset query. This API is used when user authentication is required for the access to the asset. After the user authentication is successful, call asset.query and asset.postQuery. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to query, such as the asset alias, access control attributes, and custom data.

Return value

TypeDescription
Promise<Uint8Array>Promise used to return a challenge value.
NOTE: The challenge value is used for subsequent user authentication.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000016The cache exceeds the limit.
24000017The capability is not supported.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  asset.preQuery(query).then((challenge: Uint8Array) => {
    console.info(`Succeeded in pre-querying Asset.`);
  }).catch ((err: BusinessError) => {
    console.error(`Failed to pre-query Asset. Code is ${err.code}, message is ${err.message}`);
  });
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to pre-query Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.preQuerySync12+

preQuerySync(query: AssetMap): Uint8Array

Performs preprocessing for the asset query. This API is used when user authentication is required for the access to the asset. After the user authentication is successful, call asset.querySync and asset.postQuerySync. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to query, such as the asset alias, access control attributes, and custom data.

Return value

TypeDescription
Uint8ArrayChallenge value.
NOTE: The challenge value is used for subsequent user authentication.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000016The cache exceeds the limit.
24000017The capability is not supported.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  let challenge: Uint8Array = asset.preQuerySync(query);
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to pre-query Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.query

query(query: AssetMap): Promise<Array<AssetMap>>

Queries one or more assets. If user authentication is required for the access to the asset, call asset.preQuery before this API and call asset.postQuery after this API. For details about the development procedure, see Querying an Asset with User Authentication. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to query, such as the asset alias, access control attributes, and custom data.

Return value

TypeDescription
Promise<Array<AssetMap>>Promise used to return the result obtained.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000004Access denied.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000017The capability is not supported.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  asset.query(query).then((res: Array<asset.AssetMap>) => {
    for (let i = 0; i < res.length; i++) {
      // parse the attribute.
      let accessibility: number = res[i].get(asset.Tag.ACCESSIBILITY) as number;
    }
    console.info(`Asset query succeeded.`);
  }).catch ((err: BusinessError) => {
    console.error(`Failed to query Asset. Code is ${err.code}, message is ${err.message}`);
  });
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to query Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.querySync12+

querySync(query: AssetMap): Array<AssetMap>

Queries one or more assets. If user authentication is required for the access to the asset, call asset.preQuerySync before this API and call asset.postQuerySync after this API. For details about the development procedure, see Querying an Asset with User Authentication. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
queryAssetMapYesAttributes of the asset to query, such as the asset alias, access control attributes, and custom data.

Return value

TypeDescription
Array<AssetMap>Array of query results.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Incorrect parameter types.
2. Parameter verification failed.
24000001The ASSET service is unavailable.
24000002The asset is not found.
24000004Access denied.
24000005The screen lock status does not match.
24000006Insufficient memory.
24000007The asset is corrupted.
24000008The database operation failed.
24000009The cryptography operation failed.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.
24000017The capability is not supported.

Example

import { asset } from '@kit.AssetStoreKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

function stringToArray(str: string): Uint8Array {
  let textEncoder = new util.TextEncoder();
  return textEncoder.encodeInto(str);
}

let query: asset.AssetMap = new Map();
query.set(asset.Tag.ALIAS, stringToArray('demo_alias'));
try {
  let res: Array<asset.AssetMap> = asset.querySync(query);
  let accessibility: number;
  for (let i = 0; i < res.length; i++) {
    // parse the attribute.
    if (res[i] != null) {
      accessibility = res[i].get(asset.Tag.ACCESSIBILITY) as number;
    }
  }
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to query Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.postQuery

postQuery(handle: AssetMap): Promise<void>

Performs postprocessing for the asset query. This API is used when user authentication is required for the access to the asset. This API must be used with asset.preQuery together. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
handleAssetMapYesHandle of the query operation, including the challenge value returned by asset.preQuery.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000006Insufficient memory.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { BusinessError } from '@kit.BasicServicesKit';

let handle: asset.AssetMap = new Map();
// The new Uint8Array(32) is only an example. Pass in the challenge value returned by asset.preQuery.
handle.set(asset.Tag.AUTH_CHALLENGE, new Uint8Array(32));
try {
  asset.postQuery(handle).then(() => {
    console.info(`Succeeded in post-querying Asset.`);
  }).catch ((err: BusinessError) => {
    console.error(`Failed to post-query Asset. Code is ${err.code}, message is ${err.message}`);
  });
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to post-query Asset. Code is ${err.code}, message is ${err.message}`);
}

asset.postQuerySync12+

postQuerySync(handle: AssetMap): void

Performs postprocessing for the asset query. This API is used when user authentication is required for the access to the asset. This API must be used with asset.preQuerySync together. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

Parameters

NameTypeMandatoryDescription
handleAssetMapYesHandle of the query operation, including the challenge value returned by asset.preQuerySync.

Error codes

For details about the error codes, see Asset Store Service Error Codes.

IDError Message
401Parameter error. Possible causes:
1. Mandatory parameters are left unspecified.
2. Incorrect parameter types.
3. Parameter verification failed.
24000001The ASSET service is unavailable.
24000006Insufficient memory.
24000010IPC failed.
24000011Calling the Bundle Manager service failed.
24000012Calling the OS Account service failed.
24000013Calling the Access Token service failed.

Example

import { asset } from '@kit.AssetStoreKit';
import { BusinessError } from '@kit.BasicServicesKit';

let handle: asset.AssetMap = new Map();
// The new Uint8Array(32) is only an example. Pass in the challenge value returned by asset.preQuerySync.
handle.set(asset.Tag.AUTH_CHALLENGE, new Uint8Array(32));
try {
  asset.postQuerySync(handle)
} catch (error) {
  let err = error as BusinessError;
  console.error(`Failed to post-query Asset. Code is ${err.code}, message is ${err.message}`);
}

TagType

Enumerates the asset attribute types.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
BOOL0x01 << 28Boolean.
NUMBER0x02 << 28Number.
BYTES0x03 << 28Byte array.

Tag

Enumerate the keys of asset attributes (AssetMap), which are in key-value (KV) pairs.

System capability: SystemCapability.Security.Asset

NOTE

The following table lists all enums of Tag. The specific tags and the value range of tag values vary with the API you use. For details, see Introduction to Asset Store Kit.

NameValueDescription
SECRETTagType.BYTES | 0x01Asset plaintext.
Atomic service API: This API can be used in atomic services since API version 14.
ALIASTagType.BYTES | 0x02Asset alias, which uniquely identifies an asset.
Atomic service API: This API can be used in atomic services since API version 14.
ACCESSIBILITYTagType.NUMBER | 0x03Access control based on the lock screen status.
Atomic service API: This API can be used in atomic services since API version 14.
REQUIRE_PASSWORD_SETTagType.BOOL &#124 0x04Whether the asset is accessible only when a lock screen password is set.
Atomic service API: This API can be used in atomic services since API version 14.
AUTH_TYPETagType.NUMBER | 0x05Type of user authentication required for accessing the asset.
Atomic service API: This API can be used in atomic services since API version 14.
AUTH_VALIDITY_PERIODTagType.NUMBER | 0x06Validity period of the user authentication.
Atomic service API: This API can be used in atomic services since API version 14.
AUTH_CHALLENGETagType.BYTES | 0x07Challenge for the user authentication.
Atomic service API: This API can be used in atomic services since API version 14.
AUTH_TOKENTagType.BYTES | 0x08Authorization token obtained after the user authentication is successful.
Atomic service API: This API can be used in atomic services since API version 14.
SYNC_TYPETagType.NUMBER | 0x10Asset sync type.
Atomic service API: This API can be used in atomic services since API version 14.
IS_PERSISTENTTagType.BOOL | 0x11Whether to retain the asset when the application is uninstalled.
DATA_LABEL_CRITICAL_1TagType.BYTES | 0x20Additional asset data customized by the service with integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_CRITICAL_2TagType.BYTES | 0x21Additional asset data customized by the service with integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_CRITICAL_3TagType.BYTES | 0x22Additional asset data customized by the service with integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_CRITICAL_4TagType.BYTES | 0x23Additional asset data customized by the service with integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_1TagType.BYTES | 0x30Additional asset data customized by the service without integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_2TagType.BYTES | 0x31Additional asset data customized by the service without integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_3TagType.BYTES | 0x32Additional asset data customized by the service without integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_4TagType.BYTES | 0x33Additional asset data customized by the service without integrity protection.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_LOCAL_112+TagType.BYTES | 0x34Local information about the asset. The value is assigned by the service without integrity protection and will not be synced.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_LOCAL_212+TagType.BYTES | 0x35Local information about the asset. The value is assigned by the service without integrity protection and will not be synced.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_LOCAL_312+TagType.BYTES | 0x36Local information about the asset. The value is assigned by the service without integrity protection and will not be synced.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_LABEL_NORMAL_LOCAL_412+TagType.BYTES | 0x37Local information about the asset. The value is assigned by the service without integrity protection and will not be synced.
Atomic service API: This API can be used in atomic services since API version 14.
RETURN_TYPETagType.NUMBER | 0x40Type of the asset query result to return.
Atomic service API: This API can be used in atomic services since API version 14.
RETURN_LIMITTagType.NUMBER | 0x41Maximum number of asset records to return.
Atomic service API: This API can be used in atomic services since API version 14.
RETURN_OFFSETTagType.NUMBER | 0x42Offset of the asset query result.
NOTE: This parameter specifies the starting asset record to return in batch asset query.
Atomic service API: This API can be used in atomic services since API version 14.
RETURN_ORDERED_BYTagType.NUMBER | 0x43Sorting order of the query results. Currently, the results can be sorted only by ASSET_TAG_DATA_LABEL.
NOTE: By default, assets are returned in the order in which they are added.
Atomic service API: This API can be used in atomic services since API version 14.
CONFLICT_RESOLUTIONTagType.NUMBER | 0x44Policy for resolving the conflict (for example, a duplicate alias).
Atomic service API: This API can be used in atomic services since API version 14.
UPDATE_TIME12+TagType.BYTES | 0x45Data update time, in timestamp.
Atomic service API: This API can be used in atomic services since API version 14.
OPERATION_TYPE12+TagType.NUMBER | 0x46Additional operation type.
REQUIRE_ATTR_ENCRYPTED14+TagType.BOOL | 0x47Whether to encrypt the additional asset information customized by the service.
Atomic service API: This API can be used in atomic services since API version 14.
GROUP_ID18+TagType.BYTES | 0x48Group to which the asset belongs.

Value

type Value = boolean|number|Uint8Array;

Represents the value of each attribute in AssetMap.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

TypeDescription
booleanThe value is a Boolean value, that is, true or false.
numberThe value is a number. It can be an enumerated value or a numeric value.
Uint8ArrayThe value is a byte array, and the content is defined by the service.

AssetMap

type AssetMap = Map<Tag, Value>

Represents a set of asset attributes in the form of KV pairs.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

TypeDescription
Map<Tag, Value>The value type is Map. For details about the range of the KV pair, see Tag and Value.

Accessibility

Enumerates the types of access control based on the lock screen status.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
DEVICE_POWERED_ON0The asset can be accessed after the device is powered on.
DEVICE_FIRST_UNLOCKED1The asset can be accessed only after the device is unlocked for the first time.
NOTE: If no lock screen password is set, this option is equivalent to DEVICE_POWERED_ON.
DEVICE_UNLOCKED2The asset can be accessed only when the device is unlocked.
NOTE: If no lock screen password is set, this option is equivalent to DEVICE_POWERED_ON.

AuthType

Enumerates the types of user authentication supported by an asset.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
NONE0x00No user authentication is required before the asset is accessed.
ANY0xFFThe asset can be accessed if any user authentication (such as PIN, facial, or fingerprint authentication) is successful.

SyncType

Enumerates the sync types supported by an asset.

NOTE

This field is an embedded parameter. Currently, asset sync is not supported.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
NEVER0Asset sync is not allowed.
THIS_DEVICE1 << 0Asset sync is allowed only on the local device, for example, in data restore on the local device.
TRUSTED_DEVICE1 << 1Asset sync is allowed only between trusted devices, for example, in the case of cloning.
TRUSTED_ACCOUNT12+1 << 2Asset sync is allowed only between the devices that are logged in with trusted accounts, for example, in cloud sync scenarios.

ReturnType

Enumerates the type of information returned by an asset query operation.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
ALL0The query result contains the asset plaintext and its attributes.
NOTE: Use this option when you need to query the plaintext of a single asset.
ATTRIBUTES1The query result contains only the asset attributes.
NOTE: Use this option when you need to query attributes of multiple assets.

ConflictResolution

Enumerates the policies for resolving conflicts (for example, a duplicate alias) when an asset is added.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Security.Asset

NameValueDescription
OVERWRITE0Overwrite the original asset.
THROW_ERROR1Throw an exception for the service to perform subsequent processing.

OperationType12+

Enumerates the types of additional operation to perform.

System capability: SystemCapability.Security.Asset

NameValueDescription
NEED_SYNC0Sync.
NEED_LOGOUT1Logout.

ErrorCode

Enumerates the error codes.

System capability: SystemCapability.Security.Asset

NameValueDescription
PERMISSION_DENIED201The caller does not have the permission.
NOT_SYSTEM_APPLICATION12+202The caller is not a system application.
INVALID_ARGUMENT401Incorrect parameters are detected.
Atomic service API: This API can be used in atomic services since API version 14.
SERVICE_UNAVAILABLE24000001The asset store service is unavailable.
Atomic service API: This API can be used in atomic services since API version 14.
NOT_FOUND24000002Failed to find the asset.
Atomic service API: This API can be used in atomic services since API version 14.
DUPLICATED24000003The specified asset already exists.
Atomic service API: This API can be used in atomic services since API version 14.
ACCESS_DENIED24000004The access to the asset is denied.
Atomic service API: This API can be used in atomic services since API version 14.
STATUS_MISMATCH24000005The screen lock status does not match.
Atomic service API: This API can be used in atomic services since API version 14.
OUT_OF_MEMORY24000006The system memory is insufficient.
Atomic service API: This API can be used in atomic services since API version 14.
DATA_CORRUPTED24000007The asset is corrupted.
Atomic service API: This API can be used in atomic services since API version 14.
DATABASE_ERROR24000008The database operation failed.
Atomic service API: This API can be used in atomic services since API version 14.
CRYPTO_ERROR24000009The crypto operation failed.
Atomic service API: This API can be used in atomic services since API version 14.
IPC_ERROR24000010IPC failed.
Atomic service API: This API can be used in atomic services since API version 14.
BMS_ERROR24000011The Bundle Manager service is abnormal.
Atomic service API: This API can be used in atomic services since API version 14.
ACCOUNT_ERROR24000012The account service is abnormal.
Atomic service API: This API can be used in atomic services since API version 14.
ACCESS_TOKEN_ERROR24000013The Access Token service is abnormal.
Atomic service API: This API can be used in atomic services since API version 14.
FILE_OPERATION_ERROR24000014The file operation failed.
Atomic service API: This API can be used in atomic services since API version 14.
GET_SYSTEM_TIME_ERROR24000015Failed to obtain the system time.
Atomic service API: This API can be used in atomic services since API version 14.
LIMIT_EXCEEDED24000016The number of cached records exceeds the upper limit.
Atomic service API: This API can be used in atomic services since API version 14.
UNSUPPORTED24000017The feature is not supported.
Atomic service API: This API can be used in atomic services since API version 14.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Asset Store Kit (Asset Store Service)

harmony 鸿蒙Asset_Attr

harmony 鸿蒙Asset_Blob

harmony 鸿蒙Asset_Result

harmony 鸿蒙Asset_ResultSet

harmony 鸿蒙AssetApi

harmony 鸿蒙AssetType

harmony 鸿蒙asset_api.h

harmony 鸿蒙asset_type.h

harmony 鸿蒙Asset Store Service Error Code

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