未验证 提交 7ac51b30 编写于 作者: O openharmony_ci 提交者: Gitee

!20947 [翻译完成】#I7HDO3 (20308+20371+20375+20109+20413+20070+20585+20649)

Merge pull request !20947 from Annie_wang/PR20293
......@@ -28,19 +28,19 @@ The preference persistent file of an application is stored in the application sa
## Available APIs
The following table lists the APIs used for preferences data persistence. Most of the APIs are executed asynchronously, using a callback or promise to return the result. The following table uses the callback-based APIs as an example. For more information about the APIs, see [User Preferences](../reference/apis/js-apis-data-preferences.md).
The following table lists the APIs used for persisting user preference data. For more information about the APIs, see [User Preferences](../reference/apis/js-apis-data-preferences.md).
| API| Description|
| -------- | -------- |
| getPreferences(context: Context, name: string, callback: AsyncCallback<Preferences>): void | Obtain a **Preferences** instance.|
| put(key: string, value: ValueType, callback: AsyncCallback<void>): void | Writes data to the Preferences instance. You can use **flush()** to persist the **Preferences** instance data.|
| has(key: string, callback: AsyncCallback<boolean>): void | Checks whether the **Preferences** instance contains a KV pair with the given key. The key cannot be empty.|
| get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void | Obtains the value of the specified key. If the value is null or not of the default value type, **defValue** is returned.|
| delete(key: string, callback: AsyncCallback<void>): void | Deletes the KV pair with the given key from the **Preferences** instance.|
| flush(callback: AsyncCallback<void>): void | Flushes the data of this **Preferences** instance to a file for data persistence.|
| on(type: 'change', callback: Callback<{ key : string }>): void | Subscribes to data changes of the specified key. When the value of the specified key is changed and saved by **flush()**, a callback will be invoked to return the new data.|
| off(type: 'change', callback?: Callback<{ key : string }>): void | Unsubscribes from data changes.|
| deletePreferences(context: Context, name: string, callback: AsyncCallback<void>): void | Deletes a **Preferences** instance from memory. If the **Preferences** instance has a persistent file, this API also deletes the persistent file.|
| API | Description |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| getPreferences(context: Context, name: string, callback: AsyncCallback<Preferences>): void | Obtain a **Preferences** instance. |
| putSync(key: string, value: ValueType): void | Writes data to the Preferences instance. You can use **flush()** to persist the **Preferences** instance data. An asynchronous API is also provided. |
| hasSync(key: string): void | Checks whether the **Preferences** instance contains a KV pair with the given key. The key cannot be empty. An asynchronous API is also provided. |
| getSync(key: string, defValue: ValueType): void | Obtains the value of the specified key. If the value is null or not of the default value type, **defValue** is returned. An asynchronous API is also provided. |
| deleteSync(key: string): void | Deletes the KV pair with the given key from the **Preferences** instance. An asynchronous API is also provided. |
| flush(callback: AsyncCallback<void>): void | Flushes the data of this **Preferences** instance to a file for data persistence. |
| on(type: 'change', callback: Callback<{ key : string }>): void | Subscribes to data changes of the specified key. When the value of the specified key is changed and saved by **flush()**, a callback will be invoked to return the new data. |
| off(type: 'change', callback?: Callback<{ key : string }>): void | Unsubscribes from data changes. |
| deletePreferences(context: Context, name: string, callback: AsyncCallback<void>): void | Deletes a **Preferences** instance from memory. If the **Preferences** instance has a persistent file, this API also deletes the persistent file.|
## How to Develop
......@@ -102,40 +102,24 @@ The following table lists the APIs used for preferences data persistence. Most o
3. Write data.
Use **put()** to write data to the **Preferences** instance. After data is written, you can use **flush()** to persist the **Preferences** instance data to a file if necessary.
Use **putSync()** to write data to the cached **Preferences** instance. After data is written, you can use **flush()** to persist the **Preferences** instance data to a file if necessary.
> **NOTE**
>
> If the specified key already exists, the **put()** method changes the value. To prevent a value from being changed by mistake, you can use **has()** to check whether the KV pair exists.
> If the specified key already exists, the **putSync()** method changes the value. You can use **hasSync()** to check whether the KV pair exists.
Example:
```js
try {
preferences.has('startup', function (err, val) {
if (err) {
console.error(`Failed to check the key 'startup'. Code:${err.code}, message:${err.message}`);
return;
}
if (val) {
console.info("The key 'startup' is contained.");
} else {
console.info("The key 'startup' does not contain.");
// Add a KV pair.
try {
preferences.put('startup', 'auto', (err) => {
if (err) {
console.error(`Failed to put data. Code:${err.code}, message:${err.message}`);
return;
}
console.info('Succeeded in putting data.');
})
} catch (err) {
console.error(`Failed to put data. Code: ${err.code},message:${err.message}`);
}
}
})
if (preferences.hasSync('startup')) {
console.info("The key 'startup' is contained.");
} else {
console.info("The key 'startup' does not contain.");
// Add a KV pair.
preferences.putSync('startup', 'auto');
}
} catch (err) {
console.error(`Failed to check the key 'startup'. Code:${err.code}, message:${err.message}`);
}
......@@ -143,17 +127,12 @@ The following table lists the APIs used for preferences data persistence. Most o
4. Read data.
Use **get()** to obtain the value of the specified key. If the value is null or is not of the default value type, the default data is returned. Example:
Use **getSync()** to obtain the value of the specified key. If the value is null or is not of the default value type, the default data is returned. Example:
```js
try {
preferences.get('startup', 'default', (err, val) => {
if (err) {
console.error(`Failed to get value of 'startup'. Code:${err.code}, message:${err.message}`);
return;
}
console.info(`Succeeded in getting value of 'startup'. val: ${val}.`);
})
let val = preferences.getSync('startup', 'default');
console.info(`Succeeded in getting value of 'startup'. val: ${val}.`);
} catch (err) {
console.error(`Failed to get value of 'startup'. Code:${err.code}, message:${err.message}`);
}
......@@ -161,18 +140,12 @@ The following table lists the APIs used for preferences data persistence. Most o
5. Delete data.
Use delete() to delete a KV pair.<br>Example:
Use **deleteSync()** to delete a KV pair.<br>Example:
```js
try {
preferences.delete('startup', (err) => {
if (err) {
console.error(`Failed to delete the key 'startup'. Code:${err.code}, message:${err.message}`);
return;
}
console.info("Succeeded in deleting the key 'startup'.");
})
preferences.deleteSync('startup');
} catch (err) {
console.error(`Failed to delete the key 'startup'. Code:${err.code}, message:${err.message}`);
}
......@@ -248,4 +221,3 @@ The following table lists the APIs used for preferences data persistence. Most o
console.error(`Failed to delete preferences. Code:${err.code}, message:${err.message}`);
}
```
......@@ -18,7 +18,7 @@ import cloudData from '@ohos.data.cloudData';
## Action
Enumerates the actions for clearing the cloud information about the local data.
Enumerates the actions to take to clear the downloaded cloud data locally.
**System API**: This is a system API.
......@@ -26,8 +26,8 @@ Enumerates the actions for clearing the cloud information about the local data.
| Name | Description |
| --------- | ---------------------------- |
| CLEAR_CLOUD_INFO | Clear the cloud ID information.|
| CLEAR_CLOUD_DATA_AND_INFO |Clear all cloud data, including cloud ID information and data downloaded from the cloud (excluding the data modified or generated locally). |
| CLEAR_CLOUD_INFO | Clear only the cloud identifier of the data downloaded from the cloud. The related data is still stored as local data.|
| CLEAR_CLOUD_DATA_AND_INFO |Clear the data downloaded from the cloud, excluding the cloud data that has been modified locally. |
## Config
......@@ -49,7 +49,7 @@ Enables device-cloud synergy. This API uses an asynchronous callback to return t
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| accountId | string | Yes | ID of the target cloud. |
| accountId | string | Yes | ID of the cloud account. |
| switches | {[bundleName: string]: boolean} | Yes | Device-cloud synergy switches for applications. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
......@@ -87,7 +87,7 @@ Enables device-cloud synergy. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| accountId | string | Yes | ID of the target cloud. |
| accountId | string | Yes | ID of the cloud account. |
| switches | {[bundleName: string]: boolean} | Yes | Device-cloud synergy switches for applications. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
**Return value**
......@@ -126,10 +126,10 @@ Disables device-cloud synergy. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------------- |
| accountId | string | Yes | ID of the cloud account.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -162,9 +162,9 @@ Disables device-cloud synergy. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------- |
| accountId | string | Yes | ID of the cloud account.|
**Return value**
......@@ -203,8 +203,8 @@ Changes the device-cloud synergy switch for an application. This API uses an asy
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ---------------------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName| string | Yes | Name of the target application.|
| accountId | string | Yes | ID of the cloud account.|
| bundleName| string | Yes | Bundle name of the application.|
| status | boolean | Yes | Setting of the device-cloud synergy switch for the application. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
......@@ -242,8 +242,8 @@ Changes the device-cloud synergy switch for an application. This API uses a prom
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ---------------------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName| string | Yes | Name of the target application.|
| accountId | string | Yes | ID of the cloud account.|
| bundleName| string | Yes | Bundle name of the application.|
| status | boolean | Yes | Setting of the device-cloud synergy switch for the application. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
**Return value**
......@@ -282,11 +282,11 @@ Notifies the data changes in the cloud. This API uses an asynchronous callback t
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName | string | Yes | Name of the target application. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | -------------------- |
| accountId | string | Yes | ID of the cloud account.|
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -320,10 +320,10 @@ Notifies the data changes in the cloud. This API uses a promise to return the re
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName | string | Yes | Name of the target application. |
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------------- |
| accountId | string | Yes | ID of the cloud account.|
| bundleName | string | Yes | Bundle name of the application. |
**Return value**
......@@ -346,3 +346,88 @@ try {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### clean
static clean(accountId: string, appActions: {[bundleName: string]: Action}, callback: AsyncCallback&lt;void&gt;):void
Clears the cloud data locally. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------- | ---- | -------------------------------- |
| accountId | string | Yes | ID of the cloud account. |
| appActions | {[bundleName: string]: [Action](#action)} | Yes | Information about the application whose data is to be cleared and the action to take.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let action = cloudData.Action;
let account = "test_id";
let bundleName1 = "test_bundleName1";
let bundleName2 = "test_bundleName2";
let appActions = { [bundleName1]: action.CLEAR_CLOUD_INFO, [bundleName2]: action.CLEAR_CLOUD_DATA_AND_INFO };
try {
cloudData.Config.clean(account, appActions, function (err) {
if (err === undefined) {
console.info('Succeeding in cleaning cloud data');
} else {
console.error(`Failed to clean cloud data. Code: ${err.code}, message: ${err.message}`);
}
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### clean
static clean(accountId: string, appActions: {[bundleName: string]: Action}): Promise&lt;void&gt;
Clears the cloud data locally. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------- | ---- | -------------------------------- |
| accountId | string | Yes | ID of the cloud account. |
| appActions | {[bundleName: string]: [Action](#action)} | Yes | Information about the application whose data is to be cleared and the action to take.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let action = cloudData.Action;
let account = "test_id";
let bundleName1 = "test_bundleName1";
let bundleName2 = "test_bundleName2";
let appActions = { [bundleName1]: action.CLEAR_CLOUD_INFO, [bundleName2]: action.CLEAR_CLOUD_DATA_AND_INFO };
try {
cloudData.Config.clean(account, appActions).then(() => {
console.info('Succeeding in cleaning cloud data');
}).catch((err) => {
console.error(`Failed to clean cloud data. Code: ${err.code}, message: ${err.message}`);
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
# @ohos.data.preferences (User Preferences)
The **user preferences** module provides APIs for processing data in the form of key-value (KV) pairs and supports persistence of the KV pairs when required.
The **Preferences** module provides APIs for processing data in the form of key-value (KV) pairs, and supports persistence of the KV pairs when required, as well as modification and query of the data.
The key is of the string type, and the value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.
......@@ -40,7 +40,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance. |
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.|
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and the **Preferences** instance obtained is returned. Otherwise, **err** is an error code.|
**Example**
......@@ -310,7 +310,7 @@ class EntryAbility extends UIAbility {
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
Removes a **Preferences** instance from the memory. This API uses an asynchronous callback to return the result.
Removes a **Preferences** instance from the cache. This API uses an asynchronous callback to return the result.
The removed **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
......@@ -373,7 +373,7 @@ class EntryAbility extends UIAbility {
removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
Removes a **Preferences** instance from the memory. This API uses a promise to return the result.
Removes a **Preferences** instance from the cache. This API uses a promise to return the result.
The removed **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
......@@ -434,9 +434,58 @@ class EntryAbility extends UIAbility {
}
```
## data_preferences.removePreferencesFromCacheSync<sup>10+</sup>
removePreferencesFromCacheSync(context: Context, name: string): void
Synchronously removes a **Preferences** instance from the cache.
The deleted **Preferences** instance cannot be used to perform data operations. Otherwise, data inconsistency will be caused.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance.|
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
try {
data_preferences.removePreferencesFromCacheSync(context, 'mystore');
} catch(err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
try {
data_preferences.removePreferencesFromCacheSync(this.context, 'mystore');
} catch(err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
}
}
}
```
## Preferences
Provides methods for obtaining and modifying data.
Provides APIs for obtaining and modifying the stored data.
Before calling any method of **Preferences**, you must obtain a **Preferences** instance by using [data_preferences.getPreferences](#data_preferencesgetpreferences).
......@@ -445,7 +494,7 @@ Before calling any method of **Preferences**, you must obtain a **Preferences**
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
Obtains the value corresponding to the specified key from the cached **Preferences** instance. This API uses an asynchronous callback to return the result. If the value is null or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -478,7 +527,7 @@ try {
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
Obtains the value corresponding to the specified key from the cached **Preferences** instance. This API uses a promise to return the result. If the value is null or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -510,11 +559,43 @@ try {
}
```
### getSync<sup>10+</sup>
getSync(key: string, defValue: ValueType): ValueType
Synchronously obtains the value corresponding to the specified key from the cached **Preferences** instance. If the value is null or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data to obtain. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
**Return value**
| Type | Description |
| ----------------------------------- | ----------------------------- |
| [ValueType](#valuetype) | Returns the value obtained.|
**Example**
```js
try {
let value = preferences.getSync('startup', 'default');
console.info("Obtained the value of 'startup'. Data: " + value);
} catch(err) {
console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
### getAll
getAll(callback: AsyncCallback&lt;Object&gt;): void;
Obtains an **Object** instance that contains all KV pairs. This API uses an asynchronous callback to return the result.
Obtains all KV pairs from the cached **Preferences** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -522,7 +603,7 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;Object&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **value** is the **Object** instance obtained. Otherwise, **err** is an error code.|
| callback | AsyncCallback&lt;Object&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **value** provides all KV pairs obtained. Otherwise, **err** is an error code.|
**Example**
......@@ -547,7 +628,7 @@ try {
getAll(): Promise&lt;Object&gt;
Obtains an **Object** instance that contains all KV pairs. This API uses a promise to return the result.
Obtains all KV pairs from the cached **Preferences** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -555,7 +636,7 @@ Obtains an **Object** instance that contains all KV pairs. This API uses a promi
| Type | Description |
| --------------------- | ------------------------------------------- |
| Promise&lt;Object&gt; | Promise used to return the **Object** instance obtained.|
| Promise&lt;Object&gt; | Promise used to return the KV pairs obtained.|
**Example**
......@@ -574,11 +655,38 @@ try {
}
```
### getAllSync<sup>10+</sup>
getAllSync(): Object
Synchronously obtains all KV pairs from the cached **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value**
| Type | Description |
| --------------------- | ------------------------------------------- |
| Object | Returns all KV pairs obtained.|
**Example**
```js
try {
let value = preferences.getAllSync();
let allKeys = Object.keys(value);
console.info('getAll keys = ' + allKeys);
console.info("getAll object = " + JSON.stringify(value));
} catch (err) {
console.info("Failed to obtain all KV pairs. code =" + err.code + ", message =" + err.message);
}
```
### put
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
Writes data to this **Preferences** instance. This API uses an asynchronous callback to return the result. You can use [flush](#flush) to make the **Preferences** instance persistent.
Writes data to the cached **Preferences** instance. This API uses an asynchronous callback to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -611,7 +719,7 @@ try {
put(key: string, value: ValueType): Promise&lt;void&gt;
Writes data to this **Preferences** instance. This API uses a promise to return the result. You can use [flush](#flush) to make the **Preferences** instance persistent.
Writes data to the cached **Preferences** instance. This API uses a promise to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -644,11 +752,37 @@ try {
```
### putSync<sup>10+</sup>
putSync(key: string, value: ValueType): void
Synchronously writes data to the cached **Preferences** instance. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | Value to write. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
**Example**
```js
try {
preferences.putSync('startup', 'auto');
} catch(err) {
console.info("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message);
}
```
### has
has(key: string, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.
Checks whether the cached **Preferences** instance contains the KV pair of the given key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -684,7 +818,7 @@ try {
has(key: string): Promise&lt;boolean&gt;
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.
Checks whether the cached **Preferences** instance contains the KV pair of the given key. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -720,11 +854,47 @@ try {
```
### hasSync<sup>10+</sup>
hasSync(key: string): boolean
Synchronously checks whether the cached **Preferences** instance contains the KV pair of the given key.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data to check. It cannot be empty.|
**Return value**
| Type | Description |
| ---------------------- | ------------------------------------------------------------ |
| boolean | If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.|
**Example**
```js
try {
let isExist = preferences.hasSync('startup');
if (isExist) {
console.info("The key 'startup' is contained.");
} else {
console.info("The key 'startup' is not contained.");
}
} catch(err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}
```
### delete
delete(key: string, callback: AsyncCallback&lt;void&gt;): void
Deletes a KV pair from this **Preferences** instance based on the specified key. This API uses an asynchronous callback to return the result.
Deletes a KV pair from the cached **Preferences** instance based on the specified key. This API uses an asynchronous callback to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -756,7 +926,7 @@ try {
delete(key: string): Promise&lt;void&gt;
Deletes a KV pair from this **Preferences** instance. This API uses a promise to return the result.
Deletes a KV pair from the cached **Preferences** instance based on the specified key. This API uses a promise to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -788,11 +958,36 @@ try {
```
### deleteSync<sup>10+</sup>
deleteSync(key: string): void
Synchronously deletes a KV pair from the cached **Preferences** instance based on the specified key. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the KV pair to delete. It cannot be empty.|
**Example**
```js
try {
preferences.deleteSync('startup');
} catch(err) {
console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}
```
### flush
flush(callback: AsyncCallback&lt;void&gt;): void
Saves the data of this **Preferences** instance to a file asynchronously. This API uses an asynchronous callback to return the result.
Flushes the data in the cached **Preferences** instance to the persistent file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -823,7 +1018,7 @@ try {
flush(): Promise&lt;void&gt;
Saves the data of this **Preferences** instance to a file asynchronously. This API uses a promise to return the result.
Flushes the data in the cached **Preferences** instance to the persistent file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -853,7 +1048,7 @@ try {
clear(callback: AsyncCallback&lt;void&gt;): void
Clears this **Preferences** instance. This API uses an asynchronous callback to return the result.
Clears all data in the cached **Preferences** instance. This API uses an asynchronous callback to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -884,7 +1079,7 @@ try {
clear(): Promise&lt;void&gt;
Clears this **Preferences** instance. This API uses a promise to return the result.
Clears all data in the cached **Preferences** instance. This API uses a promise to return the result. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -910,6 +1105,25 @@ try {
```
### clearSync<sup>10+</sup>
clearSync(): void
Synchronously clears all data in the cached **Preferences** instance. You can use [flush](#flush) to persist the **Preferences** instance.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Example**
```js
try {
preferences.clearSync();
} catch(err) {
console.info("Failed to clear. code =" + err.code + ", message =" + err.message);
}
```
### on('change')
on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
......
......@@ -8,8 +8,6 @@ The **DataStorage** module provides applications with data processing capability
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.preferences](js-apis-data-preferences.md).
>
> - The APIs of this module can be used only in the FA model.
## Modules to Import
......@@ -188,7 +186,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -230,7 +228,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
| Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -295,7 +293,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -337,7 +335,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
| Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -490,7 +488,7 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
| -------- | ------------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -524,7 +522,7 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -672,7 +670,7 @@ Deletes data with the specified key from this storage object. This API uses an a
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
......@@ -705,7 +703,7 @@ Deletes data with the specified key from this storage object. This API uses a pr
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -746,7 +744,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
......@@ -773,7 +771,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -814,7 +812,7 @@ Clears this **Storage** object. This API uses an asynchronous callback to return
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
......@@ -840,7 +838,7 @@ Clears this **Storage** object. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......
......@@ -267,7 +267,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. |
| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
| 12100002 | The specified tokenID does not exist or refer to an application process. |
| 12100003 | The specified permission does not exist or is not an user_grant permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
......@@ -315,7 +315,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. |
| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
| 12100002 | The specified tokenID does not exist or refer to an application process. |
| 12100003 | The specified permission does not exist or is not an user_grant permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
......@@ -370,7 +370,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. |
| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
| 12100002 | The specified tokenID does not exist or refer to an application process. |
| 12100003 | The specified permission does not exist or is not an user_grant permission. |
| 12100004 | The interface is not used with |
......@@ -418,7 +418,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. |
| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
| 12100002 | The specified tokenID does not exist or refer to an application process. |
| 12100003 | The specified permission does not exist or is not an user_grant permission. |
| 12100004 | The interface is not used with |
......@@ -551,8 +551,8 @@ Represents the request for querying permission usage records.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| tokenId | number | No | Token ID of the application (invoker).<br>By default, all applications are queried. |
| isRemote | boolean | No | Whether to query the permission usage records of the remote device.<br> The default value is **false**, which means the permission usage records of the local device are queried by default.|
| deviceId | string | No | ID of the device hosting the target application.<br> The default value is the local device ID. |
| isRemote | boolean | No | Whether to query the permission usage records of the remote device.<br>The default value is **false**, which means the permission usage records of the local device are queried by default.|
| deviceId | string | No | ID of the device hosting the target application.<br>The default value is the local device ID. |
| bundleName | string | No | Bundle name of the target application.<br>By default, all applications are queried.|
| permissionNames | Array&lt;Permissions&gt; | No | Permissions to query.<br>By default, the usage records of all permissions are queried. |
| beginTime | number | No | Start time of the query, in ms.<br>The default value is **0**, which means the start time is not set.|
......
# App Access Control Subsystem ChangeLog
## cl.accessToken.1 Change of the Media and File Permission Group
The original Media and File permission group contains the following permissions:
- ohos.permission.MEDIA_LOCATION
- ohos.permission.READ_MEDIA
- ohos.permission.WRITE_MEDIA
Changed the permission group as follows:
- Added **ohos.permission.MEDIA_LOCATION** to the Image and Video permission group.
- Added **ohos.permission.READ_MEDIA** and **ohos.permission.WRITE_MEDIA** to the File permission group.
**Change Impact**
The permission dialog boxes are displayed by permission group.
- Before the change, if the three permissions are applied for an application, a dialog box for applying for the media and file permissions will be displayed only once.
- After the change, if the three permissions are applied for an application, a dialog box for applying for the image and video permissions and a dialog box for applying for the file permission will be displayed.
**Key API/Component Changes**
Permission group before the change:
| Permission | Permission Group |
| -------- | ---------------------------- |
| ohos.permission.MEDIA_LOCATION | Media and File|
| ohos.permission.READ_MEDIA | Media and File|
| ohos.permission.WRITE_MEDIA | Media and File|
Permission groups after the change:
| Permission | Permission Group |
| -------- | ---------------------------- |
| ohos.permission.MEDIA_LOCATION | Image and Video|
| ohos.permission.READ_MEDIA | File|
| ohos.permission.WRITE_MEDIA | File|
**Adaptation Guide**
N/A
# Security Subsystem Changelog
## cl.security.1 Addition of the @throws Tags for Exceptions Thrown in API Version 9
Added the @throws tags for the APIs of API version 9 in the JS document.
**Change Impact**
For released JS interfaces, the exception handling process may be affected, including synchronous and asynchronous exceptions. Check the exception handling process based on the latest @throws tags and make adaptation.
**Key API/Component Changes**
Before change:
```ts
interface Key {
/**
* Encode the key object to binary data.
*
* @returns { DataBlob } the binary data of the key object.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
getEncoded(): DataBlob;
}
interface AsyKeyGenerator {
/**
* Used to generate asymmetric key pair.
*
* @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
generateKeyPair(callback: AsyncCallback<KeyPair>): void;
/**
* Used to generate asymmetric key pair.
*
* @returns { Promise<KeyPair> } the promise used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
generateKeyPair(): Promise<KeyPair>;
/**
* Used to convert asymmetric key data to key pair object.
*
* @param { DataBlob } pubKey - the public key data blob.
* @param { DataBlob } priKey - the private key data blob.
* @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void;
/**
* Used to convert asymmetric key data to key pair object.
*
* @param { DataBlob } pubKey - the public key data blob.
* @param { DataBlob } priKey - the private key data blob.
* @returns { Promise<KeyPair> } the promise used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>;
}
/**
* Provides the asymmetric key generator instance func.
*
* @param { string } algName - indicates the algorithm name.
* @returns { AsyKeyGenerator } the generator obj create by algName.
* @throws { BusinessError } 401 - invalid parameters.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createAsyKeyGenerator(algName: string): AsyKeyGenerator;
/**
* Create a cipher object for encryption and decryption operations according to the given specifications.
* Two different Cipher objects should be created when using RSA encryption and decryption,
* even with the same specifications.
*
* @param { string } transformation - indicates the description to be transformed to cipher specifications.
* @returns { Cipher } the cipher object returned by the function.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createCipher(transformation: string): Cipher;
/**
* Create sign class.
*
* @param { string } algName - indicates the algorithm name and params.
* @returns { Sign } the sign class.
* @throws { BusinessError } 401 - invalid parameters.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createSign(algName: string): Sign;
/**
* Create verify class.
*
* @param { string } algName - indicates the algorithm name and params.
* @returns { Verify } the verify class.
* @throws { BusinessError } 401 - invalid parameters.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createVerify(algName: string): Verify;
/**
* Create key agreement class.
*
* @param { string } algName - indicates the algorithm name and params.
* @returns { KeyAgreement } the key agreement class.
* @throws { BusinessError } 401 - invalid parameters.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createKeyAgreement(algName: string): KeyAgreement;
```
After change:
```ts
interface Key {
/**
* Encode the key object to binary data.
*
* @returns { DataBlob } the binary data of the key object.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @throws { BusinessError } 17630001 - crypto operation error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
getEncoded(): DataBlob;
}
interface AsyKeyGenerator {
/**
* Used to generate asymmetric keypair.
*
* @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @throws { BusinessError } 17630001 - crypto operation error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
generateKeyPair(callback: AsyncCallback<KeyPair>): void;
/**
* Used to generate asymmetric keypair.
*
* @returns { Promise<KeyPair> } the promise used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @throws { BusinessError } 17630001 - crypto operation error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
generateKeyPair(): Promise<KeyPair>;
/**
* Used to convert asymmetric key data to keypair object.
*
* @param { DataBlob } pubKey - the public key data blob.
* @param { DataBlob } priKey - the private key data blob.
* @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @throws { BusinessError } 17630001 - crypto operation error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void;
/**
* Used to convert asymmetric key data to keypair object.
*
* @param { DataBlob } pubKey - the public key data blob.
* @param { DataBlob } priKey - the private key data blob.
* @returns { Promise<KeyPair> } the promise used to return keypair.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 17620001 - memory error.
* @throws { BusinessError } 17630001 - crypto operation error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>;
}
/**
* Create the asymmetric key generator instance according to the given algorithm name.
*
* @param { string } algName - indicates the algorithm name.
* @returns { AsyKeyGenerator } the asymmetric key generator instance.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createAsyKeyGenerator(algName: string): AsyKeyGenerator;
/**
* Create a cipher object for encryption and decryption operations according to the given specifications.
* Two different Cipher objects should be created when using RSA encryption and decryption,
* even with the same specifications.
*
* @param { string } transformation - indicates the description to be transformed to cipher specifications.
* @returns { Cipher } the cipher object returned by the function.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createCipher(transformation: string): Cipher;
/**
* Create a sign object for generating signatures.
*
* @param { string } algName - indicates the algorithm name and params.
* @returns { Sign } the sign class.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createSign(algName: string): Sign;
/**
* Create a verify object for verifying signatures.
*
* @param { string } algName - indicates the algorithm name and the parameters.
* @returns { Verify } the verify class.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createVerify(algName: string): Verify;
/**
* Create a key agreement object.
*
* @param { string } algName - indicates the algorithm name and params.
* @returns { KeyAgreement } the key agreement object.
* @throws { BusinessError } 401 - invalid parameters.
* @throws { BusinessError } 801 - this operation is not supported.
* @throws { BusinessError } 17620001 - memory error.
* @syscap SystemCapability.Security.CryptoFramework
* @since 9
*/
function createKeyAgreement(algName: string): KeyAgreement;
```
**Adaptation Guide**
Check the exception handling process based on the latest @throws tags and modify the code as required.
- For synchronization methods, such as **createSign**, use try/catch to process error information.
- For asynchronous methods, such as **convertKey**, use try/catch to process synchronous parameter errors and use the **error** object to obtain asynchronous parameter errors and service execution errors.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册